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

Babel's parser (babylon) doesn't distinguish invalid code from incomplete code #14

Open
n-riesco opened this issue Apr 17, 2017 · 7 comments

Comments

@n-riesco
Copy link
Owner

n-riesco commented Apr 17, 2017

Invalid code should return is_complete_reply.status: 'invalid'.

Moved from #13 (comment) .

@n-riesco
Copy link
Owner Author

Babel's parser doesn't detect incomplete code:

> require("babel-core").transform("{");

SyntaxError: unknown: Unexpected token (1:1)
> 1 | {
    |  ^
    at Parser.pp$5.raise (/home/user/node_modules/babel-core/node_modules/babylon/lib/index.js:4373:13)
    at Parser.pp.unexpected (/home/user/node_modules/babel-core/node_modules/babylon/lib/index.js:1716:8)
    at Parser.pp$3.parseExprAtom (/home/user/node_modules/babel-core/node_modules/babylon/lib/index.js:3683:12)
    at Parser.pp$3.parseExprSubscripts (/home/user/node_modules/babel-core/node_modules/babylon/lib/index.js:3427:19)
    at Parser.pp$3.parseMaybeUnary (/home/user/node_modules/babel-core/node_modules/babylon/lib/index.js:3407:19)
    at Parser.pp$3.parseExprOps (/home/user/node_modules/babel-core/node_modules/babylon/lib/index.js:3337:19)
    at Parser.pp$3.parseMaybeConditional (/home/user/node_modules/babel-core/node_modules/babylon/lib/index.js:3314:19)
    at Parser.pp$3.parseMaybeAssign (/home/user/node_modules/babel-core/node_modules/babylon/lib/index.js:3277:19)
    at Parser.pp$3.parseExpression (/home/user/node_modules/babel-core/node_modules/babylon/lib/index.js:3239:19)
    at Parser.pp$1.parseStatement (/home/user/node_modules/babel-core/node_modules/babylon/lib/index.js:1861:19)

@n-riesco n-riesco changed the title Invalid code should return is_complete_reply.status: 'invalid' Babel's parser (babylon) doesn't distinguish invalid code from incomplete code Apr 17, 2017
@Announcement
Copy link
Contributor

What exactly are you asking o.p.?
If you want a solution which is what I think you want please reference a solid point of entry to get started (=

@n-riesco
Copy link
Owner Author

n-riesco commented Aug 2, 2017

@Announcement The issue is described in the comment linked above (and here for your convenience).

By default, babel uses the parser babylon, which throws the same type of error for invalid and incomplete expressions. See:

> var babylon = require("babylon");

> babylon.parse("{")
SyntaxError: Unexpected token (1:1)

> babylon.parse("}")
SyntaxError: Unexpected token (1:0)

Other parsers, e.g. esprima, throw different type of errors:

> var exprima = require("exprima");

> esprima.parse("{")
Error: Line 1: Unexpected end of input

> esprima.parse("}")
Error: Line 1: Unexpected token }

Anyway, I'm going to remove the label help wanted since after some thought I have an idea for a workaround.

@n-riesco
Copy link
Owner Author

@AaronConlon
Copy link

Hi,Sir.I can not run it.The kernel dead.
error log:
Kernel started: 24cae8e1-a8e7-4bfd-960a-b629a2f7c99d
internal/modules/cjs/loader.js:605
throw err;
^

Error: Cannot find module '../build/Release/zmq.node'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
at Function.Module._load (internal/modules/cjs/loader.js:529:25)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object. (/usr/local/lib/node_modules/jp-babel/node_modules/zeromq/lib/index.js:6:11)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
[I 20:56:19.226 NotebookApp] KernelRestarter: restarting kernel (1/5)

Thanks

@n-riesco
Copy link
Owner Author

@youyiqin I'm guessing you've updated Node.js recently. If you did, then you need to reinstall IJavascript.

If reinstalling IJavascript doesn't fix the problem, please, open a new issue and include the commands you are running to install IJavascript.

@AaronConlon
Copy link

@n-riesco Thanks!! Yes,I have updated nodejs and npm.And I also reinstalled ijavascript.It works well unless new create a jp-babel work page.

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

3 participants