fix: read the parse goal an embedded JavaScript body is handed out with - #726
Merged
Conversation
`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 detectedLatest commit: 7a49c5d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
asnames which production of a language an embedded body is written in — astyle=""arrives ascsswithas: "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, swcunknown fieldas``, esbuildTransform 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.jsbeside the minimizers themselves:as: "script") — read as one, so awithstatement is not a strict-mode syntax error.as: "module") — read as the engine's ownmoduleoption, so an inline<script type="module">holding a top-levelawaitis minified rather than reported as a build error.as: "event-handler") —onclick=""holds a function body, the production thereturncancelling 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
javascriptstill receivesasand decides, as one claimingcssdoes today.What kind of change does this PR introduce?
fix
Did you add tests for your changes?
Yes —
test/embedded-protocol.test.jsdrives all three productions through all four built-ins: a classic body whosewithstatement only parses as a classic script, a module body with a top-levelawait, and a handler body whose top-levelreturnreaches 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.
aspreviously 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.mdgains the JavaScript half of theasparagraph, 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
renderEmbeddedSourcedispatcher, measured each engine's response toasand tomodulebefore and after the change, wrote the tests and the README paragraphs, and rannpm run lintand the full suite (592 tests, green). Coverage was checked againstmainin a worktree with the same command rather than read off a mid-run report. I reviewed the diff and the measurements.