Skip to content

[webpack-plugin-utilities] Add evaluateConstantEstreeExpression#5848

Merged
iclanton merged 1 commit into
microsoft:mainfrom
iclanton:evaluate-constant-estree-expression
Jun 26, 2026
Merged

[webpack-plugin-utilities] Add evaluateConstantEstreeExpression#5848
iclanton merged 1 commit into
microsoft:mainfrom
iclanton:evaluate-constant-estree-expression

Conversation

@iclanton

Copy link
Copy Markdown
Member

Summary

Reworks the evaluateAcornNode helper in @rushstack/webpack-plugin-utilities:

  • Renamed evaluateAcornNodeevaluateConstantEstreeExpression (the previous name referenced the parser rather than the node shape it operates on).
  • Removed the hand-rolled IAcornNode interface in favor of the existing @types/estree types. This surfaced and fixed a few latent correctness gaps that the old any-ish casts hid:
    • object SpreadElements ({ ...other }) are now explicitly rejected instead of silently mis-evaluated,
    • computed / non-identifier property keys are handled via proper narrowing,
    • sparse array holes ([1, , 3]) now evaluate to null instead of being passed into the recursion.
  • Expanded supported node types for constant values:
    • UnaryExpression — notably negative numbers like -1, which parse as a unary - applied to a literal and previously threw. Also supports +, !, ~.
    • TemplateLiteral with no ${...} substitutions.
  • Added a TSDoc comment describing intended usage (reading literal call arguments inside webpack parser hooks), the supported node types, and limitations.
  • Added unit tests covering every supported node type, nesting, sparse holes, and all error paths (computed keys, non-identifier keys, object spreads, unsupported operators / node types). This enables the test phase for the package, which previously had none.
  • Updated the hashed-folder-copy-plugin consumer to the new name.

Details

  • The package previously had no Jest setup; test / _phase:test scripts were added (the rig already provides the test phase + config).
  • All 23 tests pass and the build is clean (API report regenerated).

How it was tested

rush build and rush test for @rushstack/webpack-plugin-utilities, plus a build of the hashed-folder-copy-plugin consumer.

Rename evaluateAcornNode to evaluateConstantEstreeExpression and remove
the hand-rolled IAcornNode interface in favor of @types/estree types.

- Use proper ESTree types, handling object spread elements, private/
  computed property keys, and sparse array holes correctly.
- Support UnaryExpression (e.g. negative numbers like -1) and
  no-substitution TemplateLiteral nodes.
- Add a TSDoc comment describing usage, supported nodes, and limitations.
- Add unit tests covering all supported node types and error paths.
- Update the hashed-folder-copy-plugin consumer accordingly.
@iclanton iclanton merged commit 9fe7c47 into microsoft:main Jun 26, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from Needs triage to Closed in Bug Triage Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

2 participants