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

Set decoratorsBeforeExport to true, to match the default configuration for Ember projects #74

Merged
merged 2 commits into from
Sep 16, 2023

Conversation

ijlee2
Copy link
Owner

@ijlee2 ijlee2 commented Sep 16, 2023

Background

@codemod-utils/ast-javascript's configurations for @babel/parser had been copied from jscodeshift. The reason was, @codemod-utils/ast-javascript could work like jscodeshift without bringing in unnecessary dependencies.

From a recent fork, I realized that it's better to set decoratorsBeforeExport to true, because it matches the default configuration for Ember projects.

According to Babel:

This option:

  • is disallowed when using version: "legacy", version: "2022-03", version: "2023-01", or version: "2023-05";
  • is required when using version: "2018-09";
  • is optional and defaults to false when using version: "2021-12".
// decoratorsBeforeExport: false
export @decorator class Bar {}

// decoratorsBeforeExport: true
@decorator
export class Foo {}

This option was originally added to help tc39 collect feedback from the community by allowing experimentation with the proposed syntaxes. The proposal has now settled on allowing decorators either before or after export.

Notes

Changing the decoratorsBeforeExport to true may affect codemods that look at JavaScript files. In practice, however, I don't think this will occur often enough that I'd need to consider this pull request a breaking change.

For all of my codemods that depend on @codemod-utils/ast-javascript, the tests continued to pass after I patched the package by setting decoratorsBeforeExport to true.

  • ember-codemod-args-to-signature
  • ember-codemod-remove-ember-css-modules
  • ember-codemod-rename-test-modules

However, it's worth noting that none of these codemods have something to do with decorators.

@ijlee2 ijlee2 added the enhance: code Issue asks for new feature or refactor label Sep 16, 2023
@ijlee2 ijlee2 marked this pull request as ready for review September 16, 2023 09:46
@ijlee2 ijlee2 merged commit 111a0e9 into main Sep 16, 2023
2 checks passed
@ijlee2 ijlee2 deleted the set-decoratorsBeforeExport-to-true branch September 16, 2023 09:47
@ijlee2 ijlee2 linked an issue Sep 20, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhance: code Issue asks for new feature or refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

decoratorsBeforeExport error when parsing JS files
1 participant