Skip to content

fix: read the parse goal an embedded JavaScript body is handed out with - #726

Merged
alexander-akait merged 5 commits into
mainfrom
fix/embedded-javascript-parse-goal
Sep 6, 2026
Merged

fix: read the parse goal an embedded JavaScript body is handed out with#726
alexander-akait merged 5 commits into
mainfrom
fix/embedded-javascript-parse-goal

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Sep 5, 2026

Copy link
Copy Markdown
Member

Summary

as names which production of a language an embedded body is written in — a style="" arrives as css with as: "block-contents". JavaScript has more than one production too, and the word reached the minimizer's options untranslated, where every built-in JavaScript engine rejects an unknown key outright: terser and uglify-js answer `as` is not a supported option, swc unknown field as``, esbuild Transform failed. So `as` could not be sent for JavaScript at all.

The four built-in JavaScript minimizers now read all three of its productions, in utils.js beside the minimizers themselves:

  • A classic script (as: "script") — read as one, so a with statement is not a strict-mode syntax error.
  • A module (as: "module") — read as the engine's own module option, so an inline <script type="module"> holding a top-level await is minified rather than reported as a build error.
  • An event handler (as: "event-handler") — onclick="" holds a function body, the production the return cancelling an event is written in. No JavaScript engine here parses one on its own, so each minimizer minifies the function that body belongs to and answers with the body back out of it. This is the half webpack used to do for us: it wrapped the body before offering it, which decided for every minimizer how its engine reads a function body. feat(html): name the JavaScript production each embedded body is offered as webpack#21987 stops wrapping and hands the production over instead.

The engine is never handed the word itself. A minify function of your own claiming javascript still receives as and decides, as one claiming css does today.

What kind of change does this PR introduce?

fix

Did you add tests for your changes?

Yes — test/embedded-protocol.test.js drives all three productions through all four built-ins: a classic body whose with statement only parses as a classic script, a module body with a top-level await, and a handler body whose top-level return reaches each engine and comes back as a body. Plus the existing cases for a module body handed out as a classic script (reported as the syntax error it is, not as an unsupported option), one with no production named, and the wrap and read-back on their own, including every answer shape that is declined.

Does this PR introduce a breaking change?

No. as previously threw for JavaScript, so nothing depended on the old behaviour.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

Documented in this PR — the Embedded source section of README.md gains the JavaScript half of the as paragraph, for both the module and the event-handler production.

Use of AI

Claude Code was used, driven by me. It read the four option builders and the renderEmbeddedSource dispatcher, measured each engine's response to as and to module before and after the change, wrote the tests and the README paragraphs, and ran npm run lint and the full suite (592 tests, green). Coverage was checked against main in a worktree with the same command rather than read off a mid-run report. I reviewed the diff and the measurements.

`as` names which production of JavaScript a body is written in, the way it
already names which production of CSS a `style=""` holds. The four built-in
JavaScript minimizers now read it as their own `module` option, so a module
script is not read as a classic one — and none of their engines is handed a
word it would reject outright.
@changeset-bot

changeset-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7a49c5d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
minimizer-webpack-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.24%. Comparing base (a27c7fd) to head (7a49c5d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #726      +/-   ##
==========================================
+ Coverage   94.91%   95.24%   +0.33%     
==========================================
  Files           4        4              
  Lines        1120     1347     +227     
  Branches      391      492     +101     
==========================================
+ Hits         1063     1283     +220     
- Misses         50       56       +6     
- Partials        7        8       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

`as: "event-handler"` names a function body — the production the `return`
cancelling an event is written in. No JavaScript engine here parses one on its
own, so each built-in minimizer minifies the function that body belongs to and
answers with the body back out of it, rather than a caller shaping the source
for an engine it cannot see.
The wrap and the read-back move into `utils.js` beside the four minimizers, and
the three productions JavaScript is handed out in are named there: a classic
script, a module, and the function body an event handler holds. A minify
function reaches a worker as its source, so each still requires them rather
than reading this module's scope.
Each of the four now gets a classic body only a script may hold, a module body,
a handler body, one no engine can read back, and a check that none of the three
words reaches an engine as an option of its own.
@alexander-akait
alexander-akait merged commit 57d6d3b into main Sep 6, 2026
31 checks passed
@alexander-akait
alexander-akait deleted the fix/embedded-javascript-parse-goal branch September 6, 2026 11:49
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.

1 participant