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

fix: use injected acorn instance #10

Closed
wants to merge 1 commit into from
Closed

Conversation

pemrouz
Copy link
Contributor

@pemrouz pemrouz commented Mar 8, 2020

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

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) {
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Member

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 :)

@yangwao
Copy link

yangwao commented Mar 19, 2020

Would like to see this merged, prolly could help me out ezolenko/rollup-plugin-typescript2#217 🤔

@0biWanKenobi
Copy link

in rollup, meanwhile, you can do this evil thing:

step 1:

const acorn = require("acorn")

const myAcornPlugin = () => {
    return acorn.Parser
}

step 2, within acorn config:

...
  acornInjectPlugins: [ myAcornPlugin, acornPrivateFields ],
...

@LongTengDao
Copy link

LongTengDao commented Mar 25, 2020

in rollup, meanwhile, you can do this evil thing:

step 1:

const acorn = require("acorn")

const myAcornPlugin = () => {
    return acorn.Parser
}

step 2, within acorn config:

...
  acornInjectPlugins: [ myAcornPlugin, acornPrivateFields ],
...

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

@nitsky nitsky mentioned this pull request Apr 16, 2020
@adrianheine
Copy link
Member

I just published 0.2.3 with 4cab928. Thanks for your work!

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

Successfully merging this pull request may close these issues.

6 participants