Skip to content

Commit ad35c26

Browse files
test: hold the module script in minimize-embedded-script-productions to its production
Its unused top-level binding only goes when terser reads the body as a module, so the exact output now fails if the plugin hands it over as a classic script. Claude-Session: https://claude.ai/code/session_01Vszf1WJhCqatsMQ2xZLF9x
1 parent 30af8d0 commit ad35c26

4 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎test/configCases/html/minimize-embedded-script-productions/__snapshots__/ConfigCacheTest.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`ConfigCacheTestCases html minimize-embedded-script-productions minimize-embedded-script-productions should compile 1`] = `
4-
"<!doctype html><html lang=en><head><title>x</title><script>(()=>{if(localStorage&&window.matchMedia){const e=window.matchMedia(\\"(prefers-color-scheme: dark)\\").matches;document.documentElement.dataset.theme=e?\\"dark\\":\\"light\\"}})();</script><script type=module>window.moduleRan=!0;</script></head><body>
4+
"<!doctype html><html lang=en><head><title>x</title><script>(()=>{if(localStorage&&window.matchMedia){const e=window.matchMedia(\\"(prefers-color-scheme: dark)\\").matches;document.documentElement.dataset.theme=e?\\"dark\\":\\"light\\"}})();</script><script type=module>import.meta.url,window.moduleRan=!0;</script></head><body>
55
<button onclick=if(a)return!1;b() style=color:red;margin:0>x</button>
66
77

‎test/configCases/html/minimize-embedded-script-productions/__snapshots__/ConfigTest.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`ConfigTestCases html minimize-embedded-script-productions minimize-embedded-script-productions should compile 1`] = `
4-
"<!doctype html><html lang=en><head><title>x</title><script>(()=>{if(localStorage&&window.matchMedia){const e=window.matchMedia(\\"(prefers-color-scheme: dark)\\").matches;document.documentElement.dataset.theme=e?\\"dark\\":\\"light\\"}})();</script><script type=module>window.moduleRan=!0;</script></head><body>
4+
"<!doctype html><html lang=en><head><title>x</title><script>(()=>{if(localStorage&&window.matchMedia){const e=window.matchMedia(\\"(prefers-color-scheme: dark)\\").matches;document.documentElement.dataset.theme=e?\\"dark\\":\\"light\\"}})();</script><script type=module>import.meta.url,window.moduleRan=!0;</script></head><body>
55
<button onclick=if(a)return!1;b() style=color:red;margin:0>x</button>
66
77

‎test/configCases/html/minimize-embedded-script-productions/page.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
})() ;
1212
</script>
1313
<script type="module">
14-
const unused = 1 ;
14+
const unused = import.meta.url ;
1515
window.moduleRan = true ;
1616
</script>
1717
</head>

‎test/configCases/html/minimize-embedded-script-productions/test.config.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ module.exports = {
1111
);
1212

1313
expect(page).toMatchSnapshot();
14-
// Each production terser was handed: a classic script, a module (whose
15-
// unused binding it may drop) and an event handler's function body.
14+
// Each production terser was handed: a classic script, a module (only read
15+
// as one does its unused top-level binding go) and an event handler's body.
1616
expect(page).toContain(
1717
'<script>(()=>{if(localStorage&&window.matchMedia){const e=window.matchMedia("(prefers-color-scheme: dark)").matches;document.documentElement.dataset.theme=e?"dark":"light"}})();</script>'
1818
);
19-
expect(page).toContain("<script type=module>window.moduleRan=!0;</script>");
19+
expect(page).toContain(
20+
"<script type=module>import.meta.url,window.moduleRan=!0;</script>"
21+
);
2022
expect(page).toContain("onclick=if(a)return!1;b()");
2123
expect(page).toContain("style=color:red;margin:0");
2224
}

0 commit comments

Comments
 (0)