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

espree may break acorn. #250

Closed
mysticatea opened this issue Feb 15, 2016 · 3 comments · Fixed by #252
Closed

espree may break acorn. #250

mysticatea opened this issue Feb 15, 2016 · 3 comments · Fixed by #252

Comments

@mysticatea
Copy link
Member

$ npm install acorn@2.7 espree
$ node test.js
this would succeed
import espree
this would fail
TypeError: Cannot read property 'ecmaFeatures' of undefined
    at Parser.parseTopLevel (C:\Users\t-nagashima.AD\Documents\GitHub\sand2\node_modules\espree\espree.js:271:18)
    at Parser.parse (C:\Users\t-nagashima.AD\Documents\GitHub\sand2\node_modules\acorn\dist\acorn.js:1636:17)
    at parse (C:\Users\t-nagashima.AD\Documents\GitHub\sand2\node_modules\acorn\dist\acorn.js:905:44)
    at Object.<anonymous> (C:\Users\t-nagashima.AD\Documents\GitHub\sand2\test.js:17:5)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function.Module.runMain (module.js:442:10)
    at startup (node.js:136:18)

test.js

'use strict';

const aparse = require('acorn').parse;

//------------------------------------
console.log("this would succeed")
try {
    aparse('var foo = bar /*world*/;');  // Success!
} catch (e) {
    console.dir(e);
}

//------------------------------------
console.log("import espree")
require('espree');

//------------------------------------
console.log("this would fail")
try {
    aparse('var foo = bar /*world*/;');  // TypeError: Cannot read property 'ecmaFeatures' of undefined
} catch (e) {
    console.dir(e);
}

After require('espree');, acorn changes the behavior.
This might break tools which are using acorn (e.g. browserify).
Could espree override acorn's methods on an instance instead of the prototype? (similar to acorn-jsx)

If accepted, I'm happy to work on this.


node v4.3.0
npm v3.5.0

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@mysticatea
Copy link
Member Author

https://gist.github.com/ukatama/44cd29fbd67a315b12f9

@ukatama created a broken case of gulp + browserify + eslint.
Thank you very much!

@nzakas
Copy link
Member

nzakas commented Feb 15, 2016

Yikes, that's not good. Definitely appreciate a patch!

mysticatea added a commit to mysticatea/espree that referenced this issue Feb 18, 2016
nzakas added a commit that referenced this issue Feb 18, 2016
Fix: use the plugins feature of acorn (fixes #250)
@yyx990803
Copy link

Just ran into this today - Jade is breaking because it depends on a module which in turn depends on Acorn (which is monkey-patched by espree), would appreciate a quick release :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants