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

how can I add @babel/plugin-proposal-private-methods to jscodeshift ? #560

Closed
sibelius opened this issue May 23, 2023 · 5 comments · Fixed by #568
Closed

how can I add @babel/plugin-proposal-private-methods to jscodeshift ? #560

sibelius opened this issue May 23, 2023 · 5 comments · Fixed by #568

Comments

@sibelius
Copy link
Contributor

node_modules/write-file-atomic/node_modules/signal-exit/dist/cjs/index.js: Class private methods are not enabled. Please add @babel/plugin-proposal-private-methods to your configuration.
210 | this.#emitter.count -= 1;

@ElonVolo
Copy link
Collaborator

ElonVolo commented May 25, 2023

Two recommendations:

(DISCLAIMER: Don't take this as a verbatim, literal answer, and I don't suspect it to run without considerable tweaking. I copy-pasted from source code for the babylon parser options in jscodeshift and GPT'ed it into JSON)

Make use of the --parser-config command line option and pass it the path a JSON file with babel parser configuration.

e.g. a file named custom_parser_config.json

{
  "sourceType": "module",
  "allowImportExportEverywhere": true,
  "allowReturnOutsideFunction": true,
  "startLine": 1,
  "tokens": true,
  "plugins": [
    ["flow", {"all": true}],
    "flowComments",
    "jsx",
    "asyncGenerators",
    "bigInt",
    "classProperties",
    "classPrivateProperties",
    "classPrivateMethods",
    ["decorators", {"decoratorsBeforeExport": false}],
    "doExpressions",
    "dynamicImport",
    "exportDefaultFrom",
    "exportNamespaceFrom",
    "functionBind",
    "functionSent",
    "importMeta",
    "logicalAssignment",
    "nullishCoalescingOperator",
    "numericSeparator",
    "objectRestSpread",
    "optionalCatchBinding",
    "optionalChaining",
     "plugin-proposal-private-methods",
    ["pipelineOperator", {"proposal": "minimal"}],
    "throwExpressions"
  ]
}

Then run a command like:

jscodeshift --parser-config custom_parser_config.json -t my_jscodshift_transform.js my_file_to_be_transformed.js

Incidentially, there's two takeaways I have from this issue:

  1. The documentation around custom babel configuration and custom parsers needs to be fleshed out with more real world, stem-to-stern examples.

  2. IMAO, the latest preset-env needs to be the default for jscodeshift. Simple utility is probably more important than minimalism for probably 99% of the people using this library. If we had the ES2022 preset-env baked into the library, @sibelius wouldn't even need to be making this into an issue on github because the functionality would already be there.

  3. I'm fine with the second item being an evcodeshift thing and seeing how well this works in the real world, as Facebook tends to be conservative about changes to jscodeshift.

@sibelius
Copy link
Contributor Author

this custom parser didn't worked for me

@NoMoreTickets
Copy link

Did you also install the node module for the plugin?

@Daniel15
Copy link
Member

the latest preset-env needs to be the default for jscodeshift

+1
This seems like a reasonable change to me.

@sibelius
Copy link
Contributor Author

where can I change this ?

sibelius added a commit to sibelius/jscodeshift that referenced this issue Sep 18, 2023
Daniel15 pushed a commit that referenced this issue Oct 9, 2023
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 a pull request may close this issue.

4 participants