n-riesco / jp-babel

jp-babel is a babel kernel for the Jupyter notebook
Other
86 stars 16 forks source link

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

Open n-riesco opened 7 years ago

n-riesco commented 7 years ago

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

Moved from https://github.com/n-riesco/jp-babel/issues/13#issuecomment-294376267 .

n-riesco commented 7 years ago

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)
Announcement commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

https://github.com/cherow/cherow/

Developer27149 commented 5 years ago

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 commented 5 years ago

@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.

Developer27149 commented 5 years ago

@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.