Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import not working #751

Open
brandonmack111 opened this issue Jul 18, 2018 · 6 comments
Open

Import not working #751

brandonmack111 opened this issue Jul 18, 2018 · 6 comments

Comments

@brandonmack111
Copy link

brandonmack111 commented Jul 18, 2018

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
Copy link

Getfree commented Sep 16, 2018

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
Copy link

Getfree commented Sep 16, 2018

By the way, that example I've just posted doesn't work in the online editor either.

@rdking
Copy link

rdking commented Jul 7, 2019

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
Copy link

Did they find a solution to this? I'm having the exact same problem :/

@lilactown
Copy link

The fix is to install the sweet helpers package inside your project

npm install @sweet-js/helpers

@ryancdotorg
Copy link

Installing the helpers locally rather than globally does seem to do the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants