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

Things imported from the helper are not defined #3

Open
zkuang opened this issue Aug 10, 2017 · 5 comments
Open

Things imported from the helper are not defined #3

zkuang opened this issue Aug 10, 2017 · 5 comments

Comments

@zkuang
Copy link

zkuang commented Aug 10, 2017

sjs try to compile the cond example says "isKeyword is not defined"

@zkuang
Copy link
Author

zkuang commented Aug 10, 2017

evalmachine.:8
if (isKeyword(stx) && unwrap(stx).value === "case") {
^
ReferenceError: isKeyword is not defined
at evalmachine.:8:11

@gabejohnson
Copy link
Member

@zkuang can you provide your sjs version and a larger sample of your code?

@joom
Copy link

joom commented Nov 20, 2018

I have the same issue. The code is here: https://www.sweetjs.org/doc/tutorial.html#sweet-cond

I have just installed sjs.

@stevef51
Copy link

stevef51 commented May 9, 2019

Does sweet-js have a future ? I just found it and looks exactly what I need to support our "modified Javascript" language, however I am having the same basic issue, "isKeyword is not defined" even though my first line is to import ..

import { unwrap, isKeyword } from '@sweet-js/helpers' for syntax;

syntax lingo = function(ctx) {
    let body = ctx.contextify(ctx.next().value);
    let result = #``;
    for(let s of body) {
        if (isKeyword(s) && unwrap(s).value === 'present') {

        } else {
            result = result.concat(s);
        }
    }
    return result;
}

lingo {
    var x = 0;

    present Section.One;
}

@nilslindemann
Copy link

nilslindemann commented Dec 9, 2022

Same here.

What I try to do:

// test.sjs

import { isStringLiteral } from '@sweet-js/helpers' for syntax;  // like the docs say
// import { isStringLiteral } from '@sweet-js/helpers/helpers.js' for syntax; // also tried this

syntax query = function (ctx) {
  let selector = ctx.next().value
  if (isStringLiteral(selector)) {   // <-- using it here
    return #`document.querySelector(${selector})`
  } else {
    let node = selector
    let selector = ctx.next().value
    return #`${node}.querySelector(${selector})`
  }
}
let body = query "body"
let main = query body "main"

Then I do

sjs test.sjs --no-babel --out-file test.js

And then it logs the following:

skipping module @sweet-js/helpers/helpers.js:1
evalmachine.<anonymous>:6
    if (isStringLiteral(selector_2)) {
    ^

ReferenceError: isStringLiteral is not defined
    at evalmachine.<anonymous>:6:5
    at Enforester.expandMacro (C:\Users\Nils-Hero\AppData\Roaming\npm\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\enforester.js:1981:87)
    at Enforester.enforestAssignmentExpression (C:\Users\Nils-Hero\AppData\Roaming\npm\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\enforester.js:1114:12)
    at Enforester.enforestExpressionLoop (C:\Users\Nils-Hero\AppData\Roaming\npm\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\enforester.js:1076:23)
    at Enforester.enforest (C:\Users\Nils-Hero\AppData\Roaming\npm\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\enforester.js:107:21)
    at Enforester.enforestVariableDeclarator (C:\Users\Nils-Hero\AppData\Roaming\npm\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\enforester.js:1013:18)
    at Enforester.enforestVariableDeclaration (C:\Users\Nils-Hero\AppData\Roaming\npm\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\enforester.js:970:23)
    at Enforester.enforestStatement (C:\Users\Nils-Hero\AppData\Roaming\npm\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\enforester.js:412:27)
    at Enforester.enforestModuleItem (C:\Users\Nils-Hero\AppData\Roaming\npm\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\enforester.js:136:17)
    at Enforester.enforestBody (C:\Users\Nils-Hero\AppData\Roaming\npm\node_modules\@sweet-js\cli\node_modules\@sweet-js\core\dist\enforester.js:123:17)

Notice the first line:

skipping module @sweet-js/helpers/helpers.js:1

Why does it skip this module?

For the records, I (re)installed Sweet.js and the helpers today doing ...

$ npm install -g @sweet-js/cli @sweet-js/helpers

... and the modules are actually installed globally, I checked it in the file system. The function isStringLiteral is also defined in @sweet-js/helpers/helpers.js.

The @sweet-js\cli\package.json gives 3.0.13 as version, the @sweet-js\helpers\package.json gives 4.0.1 as version.

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

5 participants