Skip to content

Optimize WCC to only use Acorn when necessary #188

@briangrider

Description

@briangrider

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.

Metadata

Metadata

Assignees

Labels

enhancementImprovement to existing functionality

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions