ProjectEvergreen / ProjectEvergreen/wcc

Optimize WCC to only use Acorn when necessary

Open
#188 3 comments 2 reactions 1 assignee View on GitHub

@briangrider is already working on this.

Since Jan 21, 2025.

enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.