Files
swc/packages/minifier/tests/extract-comments.test.cjs
Donny/강동윤andGitHub 8f2b127b89 fix(es/minifier): Support full ES version parsing in minify (#11800)
**Description:**

This updates minify's `ecma` parsing so it accepts the full set of
ECMAScript versions already modeled by SWC instead of stopping at 2020.

It expands terser `ecma` parsing to accept:
- terser numeric forms like `3`, `5`, `6`, and `2015+`
- numeric strings like `"2023"`
- named values already understood by SWC like `es2023` and `esnext`

The compiler minify path, the transform `jsc.minify` path, and the Node
minifier binding all now accept those newer values as well.

Invalid `ecma` values keep the previous panic-style behavior; this PR
only broadens the set of accepted versions.
2026-04-17 21:36:04 +01:00

32 lines
806 B
JavaScript

const test = require("node:test");
const assert = require("node:assert/strict");
const minifier = require("../index.js");
test("minifySync exposes extractedComments", () => {
const result = minifier.minifySync(
`/*!
* @license MIT
*/
console.log("minifier");`,
{
compress: false,
mangle: false,
extractComments: true,
}
);
assert.equal(result.code, 'console.log("minifier");');
assert.deepEqual(result.extractedComments, ["/*!\n * @license MIT\n */"]);
});
test("minifySync accepts ecma 2023", () => {
const result = minifier.minifySync("const foo = 1; console.log(foo);", {
ecma: 2023,
compress: false,
mangle: false,
});
assert.equal(result.code, "const foo=1;console.log(foo);");
});