ProjectEvergreen / ProjectEvergreen/wcc
Optimize WCC to only use Acorn when necessary
@briangrider is already working on this.
Since Jan 21, 2025.
- Dominant language
- JavaScript
- Stars
- 126
- Forks
- 17
- PR merge metrics
- No merged PRs in 30d
Description
Summary
Currently, WCC uses Acorn to parse every component, even when it isn't necessary. Regex can be used to locate imports and customElements definitions for .js files with more efficiency. Removing Acorn from wcc.js so it is only a dependency of the JSX loader means that eventually modularizing the JSX loader becomes a simpler task. Separating these concerns seems worthwhile.
Proposal:
https://github.com/ProjectEvergreen/wcc/tree/enhancement/optimization-reducing-dependencies
Currently passing all tests
Dependencies for wcc.js are reduced to:
import { getParse } from './dom-shim.js';
import { generateParsedJsx } from './jsx-loader.js';
import { serialize } from 'parse5';
import fs from 'fs';
And if the JSX loader is made to be a module in a future PR, the only dependencies for WCC core as a whole would be parse5 and fs.
Optimizations
- Removed all Acorn parsing from wcc.js unless using the JSX loader
- Made parsing calls conditional on whether a file has a .jsx or .ts extension
- Removed redundant processing when the same module is imported twice
- Import regex doesn't run unless an import statement is found in a file
- customElements.define regex doesn't run unless "customElements.define" is found in a file
- Reduced number of readFileSync calls by reusing moduleContents for getTagName
Numerous other small improvements and a number of added tests.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.