-
Notifications
You must be signed in to change notification settings - Fork 4
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
Support complete babel options #28
Comments
Hmmm, yeah, I think it would be better to provide full Are there any particular use-cases you have in mind? What would the new codemod API look like? (e.g. would codemod = {
getBabelTransformOptions({filePath, fileContents}) {
}
} The thing I can think of as being a little tricky is where jscodemod is coupled to the babel transform options, which I think comes entirely from the necessity of configuring the options a certain way to use Recast: jscodemod/src/run-codemod-on-file.ts Lines 139 to 159 in 7192578
I would want to avoid any surprising API behavior there, like "the codemod can pass |
Honestly, going the I wouldn't worry about things being "overly-coupled"; the primary benefit of this software is the ability to use Babel, so embracing it while also trying to avoid appearances of being coupled to it seem a bit contradictory. I would instead lean into transparency. |
Currently, you can pass in
presets
to help parse the code to transform, but this is inherently limiting.babelCore.transformSync
supports a well-documented set of options, and ideally all would be supported.A couple of ideas:
presets
, provide ababelTransformOptions
option, which is a static object that is merged internally with the native options.getBabelOptions
option, which accepts a callback which receives the default parameters and returns the merged options to use.Of the two, I prefer (1) because it is approachable (for most people, just copy-and-paste their
.babelrc
/babel.config.js
) and clear (an object withpresets
as the only property instead of justpresets
provides parity with current implementation, and is still easy to grok). It also maintains complete control over how those options are merged. The only reason I offered (2) is because it allows conditional options building on a per-file basis, which may be something desirable for large-scale codebases that want to build a central utility for disparate codemods.If you like the idea, I can put together a PR.
The text was updated successfully, but these errors were encountered: