Skip to content

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

Open
alexander-akait wants to merge 1 commit into
mainfrom
fix/embedded-javascript-parse-goal
Open

fix: read the parse goal an embedded JavaScript body is handed out with#726
alexander-akait wants to merge 1 commit into
mainfrom
fix/embedded-javascript-parse-goal

Conversation

@alexander-akait

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 two productions too, but the word reached the minimizer's options untranslated, and 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, and an inline `<script type="module">` was read as a classic script — a top-level `await` then being a build error rather than something to minify.

The four built-in JavaScript minimizers now read as as their own module option and strip it, so a module script is read as one and no engine is handed the word. A minify function of your own claiming javascript still receives it, 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 gains a describe covering all four built-ins: a body handed out as a module is minified by each, one handed out as a classic script is reported as the syntax error it is (rather than as an unsupported option), and one handed out with no goal named is left to the minimizer's own default.

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.

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 paragraph, and ran npm run lint and the full suite (579 tests, 825 snapshots, green). I reviewed the diff and the measurements.


Generated by Claude Code

`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: 9c1b9fc

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.00%. Comparing base (a27c7fd) to head (9c1b9fc).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #726      +/-   ##
==========================================
+ Coverage   94.91%   95.00%   +0.08%     
==========================================
  Files           4        4              
  Lines        1120     1120              
  Branches      391      391              
==========================================
+ Hits         1063     1064       +1     
+ Misses         50       49       -1     
  Partials        7        7              

☔ 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.

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