Skip to content

feat: add syntax replacements using web-features-codemods#207

Open
alieron wants to merge 33 commits intoe18e:mainfrom
alieron:feat/syntax-replacement
Open

feat: add syntax replacements using web-features-codemods#207
alieron wants to merge 33 commits intoe18e:mainfrom
alieron:feat/syntax-replacement

Conversation

@alieron
Copy link
Copy Markdown

@alieron alieron commented Apr 6, 2026

Looking to help close #128 eventually.

For now, this PR adds a fixable-syntax-replacement.ts file and a generator script, similar to how module replacements are handled in the existing project.

I've also added a simple plugin that checks the source files for possible syntax replacements when the analyze command is run, to see if this aligns with what you have planned.

I'll continue working on this PR but I have a couple of things to clarify:

  1. Is my approach good so far? should I continue keeping syntax replacements and module replacements separate or should I put them both under fixable replacements?
  2. Currently, I have it check all .js and .ts in the cwd, but should we only check in the src directory? Are there plans to let the user choose this when running the command?

Any other feedback is appreciated since I'm new to this codebase.

@43081j
Copy link
Copy Markdown
Contributor

43081j commented Apr 6, 2026

once #182 lands, we have a new sources option to let the user specify where their sources live. there's also a default glob in there (which we should move to a shared file).

im not sure we need any code generation here as everything we need is already available from the package itself as far as i can tell. in that all exported codemods of web-features-codemods are applicable, so we can just put them into a usable shape at runtime.

it looks like the fixable replacements script may be wrong and/or broken right now too outside of this as it writes to lib/ rather than src/ (iirc its meant to be a committed thing).

i think keeping this separate from module replacements makes sense as long as it happens as part of the analyze command

@alieron
Copy link
Copy Markdown
Author

alieron commented Apr 6, 2026

Got it, shall I close this PR for now then?

I will be happy to approach this once again once #182 is merged.

@43081j
Copy link
Copy Markdown
Contributor

43081j commented Apr 6, 2026

feel free to leave it open and we can catch up from main once the other PR lands (should be soon).

you could also rebase onto that branch for now so you can resolve the other things meanwhile

dependabot Bot and others added 3 commits May 10, 2026 16:05
Bumps the production-dependencies group with 1 update: [module-replacements](https://github.com/es-tooling/module-replacements).


Updates `module-replacements` from 3.0.0-beta.0 to 3.0.0-beta.4
- [Release notes](https://github.com/es-tooling/module-replacements/releases)
- [Commits](e18e/module-replacements@3.0.0-beta.0...3.0.0-beta.4)

---
updated-dependencies:
- dependency-name: module-replacements
  dependency-version: 3.0.0-beta.4
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: production-dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
We moved the module-replacements repo to e18e now, so these links need
updating.
@alieron alieron force-pushed the feat/syntax-replacement branch from 119f35a to 4990e4d Compare May 10, 2026 09:45
@alieron
Copy link
Copy Markdown
Author

alieron commented May 10, 2026

@43081j
I've rebased my PR onto the #182 branch and made the changes you requested:

  1. Removed code generation for the web features codemods
  2. Added the web features check to happen during the analyze command

I will be working on tests next so any inputs on potential test cases will be appreciated.

On a side note, it looks like we can get rid of code generation for the module replacement codemods too, unless there is another reason its being done this way currently?

Comment on lines +11 to +18
const SOURCE_GLOB = ['**/*.{js,ts,mjs,cjs,jsx,tsx}'];
const SOURCE_IGNORE = [
'**/node_modules/**',
'**/dist/**',
'**/build/**',
'**/coverage/**',
'**/lib/**'
];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should de-dupe these into a shared util the corejs analysis can use too

import * as webFeatureCodemodExports from '@e18e/web-features-codemods';
import type {AnalysisContext, ReportPluginResult} from '../types.js';

interface WebFeatureCodemod {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can probably import Codemod from @e18e/web-features-codemods/lib/shared.js but really should be exporting that upstream in the codemods package too.

i will fix that meanwhile

@43081j
Copy link
Copy Markdown
Contributor

43081j commented May 10, 2026

i caught up from main for you

dont worry about rebasing it all if its a pain as we will squash it anyway in the end.

left a couple of comments too. for tests, we should at least have:

  • a file with no matches
  • a file with a match
  • a file with multiple matches
  • a file path that lives outside the root is ignored

in all cases, just use expect(messages).toMatchSnapshot()

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.

Add web-features-codemods

3 participants