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

Jison no longer produces strict output #285

Closed
bramp opened this issue May 17, 2015 · 7 comments
Closed

Jison no longer produces strict output #285

bramp opened this issue May 17, 2015 · 7 comments

Comments

@bramp
Copy link

bramp commented May 17, 2015

Since d1d8ae9 jison has been producing code that contains:

    function popStack(n) {
        stack.length = stack.length - 2 * n;
        vstack.length = vstack.length - n;
        lstack.length = lstack.length - n;
    }
    _token_stack:
        function lex() {
            var token;
            token = lexer.lex() || EOF;
            if (typeof token !== 'number') {
                token = self.symbols_[token] || token;
            }
            return token;
        }

I include the generated jison code within a "use strict" block. When loading this file with nodejs, I get the following error:

/Users/bramp/personal/js-sequence-diagrams/build/sequence-diagram.js:271
        function lex() {
        ^^^^^^^^
SyntaxError: In strict mode code, functions can only be declared at top level or immediately within another function.
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

If I remove the "_token_stack:" label, the error disappears. Additionally, it seems the _token_stack label is not actually used in my generated file, so I'm unsure if it's safe to delete.

@Alxandr
Copy link

Alxandr commented Aug 26, 2015

This is causing some rather annoying results, as it (for instance) does not allow me to use some ES6 code in io.js given that it requires strict mode.

@mbektimirov
Copy link

Any progress on this issue? For now it is impossible to use generated parser with Babel in strict mode. Blacklisting strict mode is not preferable solution here.

@hannupekka
Copy link

Also having this with browserify.

@GerHobbelt
Copy link
Contributor

For the ones who need this badly: https://github.com/GerHobbelt/jison
though be warned: I fixed that by kicking out Esprima and replacing that with a few extra labels and regex-based code block removals

(jison used Esprima to tweak the core of the generated parsers, but it effed up the core and action code comments which help me to diag/debug grammars in the wild 👎 -- another @GerHobbelt feature where the grammar rule gets printed as a comment with the $$... action code in the output; handy when you're debugging through the bugger)

@blake-regalia
Copy link

Seems to have been fixed in b9d5673

@somethingnew2-0
Copy link

Confirmed b9d5673 fixes it. @zaach could you push a release to npm to close this out?

@zaach
Copy link
Owner

zaach commented Jan 11, 2016

Aye, 0.4.16 has been published. Thanks y'all!

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

8 participants