mirror of
https://github.com/hanzoai/swc.git
synced 2026-10-30 19:42:53 +00:00
**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.
32 lines
806 B
JavaScript
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);");
|
|
});
|