Import not working
brandonmack111 opened this issue · 6 comments
brandonmack111 commented
I can use sweet.js fine for most use cases, but any time I try to use imports from standard libraries, it fails to work. Here's an example from the documentation:
import { isStringLiteral } from '@sweet-js/helpers' for syntax;
syntax m = ctx => {
return isStringLiteral(ctx.next().value) ? #`'a string'` : #`'not a string'`;
};
m 'foo'
the error I get when I try to complie:
evalmachine.<anonymous>:5
return isStringLiteral(ctx_1.next().value) ? syntaxTemplate(1) : syntaxTemplate(2);
^
ReferenceError: isStringLiteral is not defined
at ctx_1 (evalmachine.<anonymous>:5:5)
at Enforester.expandMacro (/usr/local/lib/node_modules/@sweet-js/cli/node_modules/@sweet-js/core/dist/enforester.js:1981:87)
at Enforester.enforestStatement (/usr/local/lib/node_modules/@sweet-js/cli/node_modules/@sweet-js/core/dist/enforester.js:349:12)
at Enforester.enforestModuleItem (/usr/local/lib/node_modules/@sweet-js/cli/node_modules/@sweet-js/core/dist/enforester.js:136:17)
at Enforester.enforestBody (/usr/local/lib/node_modules/@sweet-js/cli/node_modules/@sweet-js/core/dist/enforester.js:123:17)
at Enforester.enforestModule (/usr/local/lib/node_modules/@sweet-js/cli/node_modules/@sweet-js/core/dist/enforester.js:119:17)
at Enforester.enforest (/usr/local/lib/node_modules/@sweet-js/cli/node_modules/@sweet-js/core/dist/enforester.js:109:21)
at TokenExpander.expand (/usr/local/lib/node_modules/@sweet-js/cli/node_modules/@sweet-js/core/dist/token-expander.js:133:37)
at Compiler.compile (/usr/local/lib/node_modules/@sweet-js/cli/node_modules/@sweet-js/core/dist/compiler.js:50:26)
at NodeLoader.compileSource (/usr/local/lib/node_modules/@sweet-js/cli/node_modules/@sweet-js/core/dist/sweet-loader.js:211:53)
Getfree commented
I have the same problem with the unwrap
import.
import { unwrap } from '@sweet-js/helpers' for syntax ;
syntax x2 = function(ctx){
let nextToken = ctx.next().value ;
return #`${unwrap(nextToken).value} ${unwrap(nextToken).value}`
}
x2 [1, 2, 3] ;
The output is:
skipping module @sweet-js/helpers:1
evalmachine.<anonymous>:5
return syntaxTemplate(1, unwrap(nextToken_2).value, unwrap(nextToken_2).value);
^
ReferenceError: unwrap is not defined
at evalmachine.<anonymous>:5:5
at Enforester.expandMacro (A:\App files\Node.js v8.12.0\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\enforester.js:1981:87)
at Enforester.enforestStatement (A:\App files\Node.js v8.12.0\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\enforester.js:349:12)
at Enforester.enforestModuleItem (A:\App files\Node.js v8.12.0\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\enforester.js:136:17)
at Enforester.enforestBody (A:\App files\Node.js v8.12.0\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\enforester.js:123:17)
at Enforester.enforestModule (A:\App files\Node.js v8.12.0\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\enforester.js:119:17)
at Enforester.enforest (A:\App files\Node.js v8.12.0\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\enforester.js:109:21)
at TokenExpander.expand (A:\App files\Node.js v8.12.0\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\token-expander.js:133:37)
at Compiler.compile (A:\App files\Node.js v8.12.0\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\compiler.js:50:26)
at NodeLoader.compileSource (A:\App files\Node.js v8.12.0\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\sweet-loader.js:211:53)
Getfree commented
By the way, that example I've just posted doesn't work in the online editor either.
rdking commented
It's still a problem.
File: foo.js
'lang sweet.js'
import { unwrap } from '@sweet-js/helpers' for syntax;
export syntax foo = (ctx) => {
console.log(`unwrap = ${typeof(unwrap)}`);
return #`let x;`;
File index.js
import { foo } from './foo.js';
foo;
console -> unwrap = undefined
nirajpandkar commented
Did they find a solution to this? I'm having the exact same problem :/
lilactown commented
The fix is to install the sweet helpers package inside your project
npm install @sweet-js/helpers