GithubHelp home page GithubHelp logo

Comments (5)

ElonVolo avatar ElonVolo commented on April 28, 2024 2

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.

from jscodeshift.

sibelius avatar sibelius commented on April 28, 2024

this custom parser didn't worked for me

from jscodeshift.

NoMoreTickets avatar NoMoreTickets commented on April 28, 2024

Did you also install the node module for the plugin?

from jscodeshift.

Daniel15 avatar Daniel15 commented on April 28, 2024

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

+1
This seems like a reasonable change to me.

from jscodeshift.

sibelius avatar sibelius commented on April 28, 2024

where can I change this ?

from jscodeshift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.