-
Notifications
You must be signed in to change notification settings - Fork 13
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
fix: use injected acorn instance #10
Conversation
Since rollup bundles it's own version of acorn `require("acorn")` will never be the same as `Parser.acorn` and you always gets the error "acorn-private-class-elements does not support mixing different acorn copies". If this change looks good, I can make a similar one for acorn-class-fields (and also bump it to use latest version of this module).
module.exports = function(Parser) { | ||
const acorn = Parser.acorn | ||
if (acorn.version.indexOf("6.") != 0 && acorn.version.indexOf("6.0.") == 0 && acorn.version.indexOf("7.") != 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this check needs to be changed to simply if (!acorn) {
. For versions older than 6.4.0 or 7.1.0 Parser.acorn is undefined. In this case the peerDependency in package.json needs to be updated to ^6.4.0 || ^7.1.0
.
Alternatively the line before could be const acorn = Parser.acorn || require('acorn')
- this would maintain compatibility with all versions of acorn currently allowed by the peerDependency. If this were done then the check Parser being from the same acorn as tt
would need to be restored.
As I'm not a maintainer of this module I cannot say which change is prefered, I can only say the current version check will not give the expected error, it will simply fail on read of acorn.version
when acorn is undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer @coreyfarrell's (second) suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you plan to implement that, please also consider #13 :)
Would like to see this merged, prolly could help me out ezolenko/rollup-plugin-typescript2#217 🤔 |
in rollup, meanwhile, you can do this evil thing: step 1:
step 2, within acorn config:
|
@0biWanKenobi Great solution! I had handly rmdir the node_modules of acorn-class-fields, acorn-private-methods and acorn-static-class-features to force them depend on acorn-private-class-elements v0.2.0 to resolve the version error, but the mix error stuck me. Thank you! |
I just published 0.2.3 with 4cab928. Thanks for your work! |
Since rollup bundles it's own version of acorn,
require("acorn")
will never be the same asParser.acorn
and you always gets the error "acorn-private-class-elements does not support mixing different acorn copies". If this change looks good, I can make a similar one foracorn-class-fields
(and also bump it to use latest version of this module).