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

Problem bundling compiled grammars with rollup #351

Open
download13 opened this issue Apr 8, 2017 · 5 comments
Open

Problem bundling compiled grammars with rollup #351

download13 opened this issue Apr 8, 2017 · 5 comments

Comments

@download13
Copy link

I'm trying to build a library that depends on a library that uses jison to generate a grammar.

Unfortunately while building with rollup I get the following error:

Error loading C:\Users\download\code\modules\swkit\node_modules\route-parser\lib\route\compiled-grammar.js: Invalid labeled declaration (163:8) in C:\Users\download\code\modules\swkit\node_modules\route-parser\lib\route\compiled-grammar.js
SyntaxError: Error loading C:\Users\download\code\modules\swkit\node_modules\route-parser\lib\route\compiled-grammar.js: Invalid labeled declaration (163:8) in C:\Users\download\code\modules\swkit\node_modules\route-parser\lib\route\compiled-grammar.js
    at Parser.pp$4.raise (C:\Users\download\code\modules\swkit\node_modules\acorn\dist\acorn.js:2488:13)
    at Parser.pp$1.parseLabeledStatement (C:\Users\download\code\modules\swkit\node_modules\acorn\dist\acorn.js:1017:10)
    at Parser.pp$1.parseStatement (C:\Users\download\code\modules\swkit\node_modules\acorn\dist\acorn.js:779:19)
    at Parser.pp$1.parseBlock (C:\Users\download\code\modules\swkit\node_modules\acorn\dist\acorn.js:1040:23)
    at Parser.pp$3.parseFunctionBody (C:\Users\download\code\modules\swkit\node_modules\acorn\dist\acorn.js:2362:22)
    at Parser.pp$1.parseFunction (C:\Users\download\code\modules\swkit\node_modules\acorn\dist\acorn.js:1132:8)
    at Parser.pp$3.parseExprAtom (C:\Users\download\code\modules\swkit\node_modules\acorn\dist\acorn.js:1999:17)
    at Parser.pp$3.parseExprSubscripts (C:\Users\download\code\modules\swkit\node_modules\acorn\dist\acorn.js:1872:19)
    at Parser.pp$3.parseMaybeUnary (C:\Users\download\code\modules\swkit\node_modules\acorn\dist\acorn.js:1849:17)
    at Parser.pp$3.parseExprOps (C:\Users\download\code\modules\swkit\node_modules\acorn\dist\acorn.js:1791:19)
Type rollup --help for help, or visit https://github.com/rollup/rollup/wiki

The files concerned can be seen here.

Do you know why this bit is considered to be invalid javascript? The whole file looks a little odd to me.

Is there something that can be changed to make the file pass validation?

@download13
Copy link
Author

I think I found the problem.

According to this, labeled function declarations are not allowed in strict mode, which is how all ES modules are treated. Since rollup only operates on ES modules the labeled function declaration is considered invalid.

I see that the label is used as a marker for where to add a function into the file.

@download13
Copy link
Author

Nevermind. I just realized that this is already fixed in #285. I'll close this.

@download13 download13 reopened this Apr 8, 2017
@download13
Copy link
Author

Nevermind nevermind. Apparently #285 did not fix this issue.

For some reason addTokenStack is never called and so never has the chance to remove the _token_stack: label. It looks like addTokenStack only runs if the option token-stack has been provided, but the actual token stack label is in the code regardless of whether the option is present.

Is there some way to ensure that the _token_stack: line is always removed from the output?

@download13
Copy link
Author

#352 fixes this.

A more correct way to do it would be replacing the LabeledStatement in the AST with the contents of it's body property, but the string replacement method works fine for now.

@Glavin001
Copy link

Glavin001 commented May 30, 2017

I am experiencing this issue as well with https://github.com/knsv/mermaid (see mermaid-js/mermaid#277 (comment) ).

My solution was to remove all occurrences of _token_stack: from the generated code. It looks like you found the same problem and solution!

Why is #352 not merged yet? I see the current workaround is the post-process the generated code and strip the _token_stack: parts out: rcs/route-parser#26
This is laughable since the fix should be upstream in jison 😜 , however I am glad we at least this workaround.

Jison team, is there anything we can do to help you get this merged?

GerHobbelt added a commit to GerHobbelt/route-parser that referenced this issue Sep 5, 2017
// Remove _token_stack label manually until fixed in jison:
// zaach/jison#351
// zaach/jison#352
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

2 participants