2020-07-31 18:13:30 +08:00
|
|
|
import { moduleId, setToString, toString, abc, a, $1, __1 } from "./module";
|
2019-12-22 03:26:41 +08:00
|
|
|
const moduleId2 = require("./commonjs").moduleId;
|
|
|
|
const toString2 = require("./commonjs").toString;
|
2020-07-31 18:13:30 +08:00
|
|
|
const setToString2 = require("./commonjs").setToString;
|
2019-12-22 03:26:41 +08:00
|
|
|
const abc2 = require("./commonjs").abc;
|
2020-07-31 18:13:30 +08:00
|
|
|
const a2 = require("./commonjs").a;
|
|
|
|
const equals2 = require("./commonjs")["="];
|
|
|
|
const $12 = require("./commonjs").$1;
|
|
|
|
const __12 = require("./commonjs").__1;
|
2019-12-22 03:26:41 +08:00
|
|
|
|
|
|
|
it("should mangle names and remove exports even with toString named export (ESM)", () => {
|
|
|
|
expect(abc).toBe("abc");
|
2020-07-31 18:13:30 +08:00
|
|
|
expect(toString).toBe(undefined);
|
|
|
|
setToString();
|
2019-12-22 03:26:41 +08:00
|
|
|
expect(toString()).toBe("toString");
|
2020-07-31 18:13:30 +08:00
|
|
|
expect(a).toBe("single char");
|
|
|
|
expect($1).toBe("double char");
|
|
|
|
expect(__1).toBe("3 chars");
|
2019-12-22 03:26:41 +08:00
|
|
|
expect(
|
|
|
|
Object.keys(require.cache[moduleId].exports)
|
|
|
|
.map(p => p.length)
|
|
|
|
.sort()
|
2020-07-31 18:13:30 +08:00
|
|
|
).toEqual(
|
|
|
|
OPTIMIZATION === "deterministic"
|
2024-02-02 03:21:24 +08:00
|
|
|
? [1, 2, 2, 2, 2, 2, 2]
|
2020-07-31 18:13:30 +08:00
|
|
|
: [1, 1, 1, 1, 1, 1, 1]
|
|
|
|
);
|
2019-12-22 03:26:41 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
it("should mangle names and remove exports even with toString named export (CJS)", () => {
|
|
|
|
expect(abc2).toBe("abc");
|
2020-07-31 18:13:30 +08:00
|
|
|
expect(toString2).toBe(Object.prototype.toString);
|
|
|
|
setToString2();
|
|
|
|
const toString3 = require("./commonjs").toString;
|
|
|
|
expect(toString3()).toBe("toString");
|
|
|
|
expect(a2).toBe("single char");
|
|
|
|
expect(equals2).toBe("single char non-identifier");
|
|
|
|
expect($12).toBe("double char");
|
|
|
|
expect(__12).toBe("3 chars");
|
2019-12-22 03:26:41 +08:00
|
|
|
expect(
|
|
|
|
Object.keys(require.cache[moduleId2].exports)
|
|
|
|
.map(p => p.length)
|
|
|
|
.sort()
|
2020-07-31 18:13:30 +08:00
|
|
|
).toEqual(
|
|
|
|
OPTIMIZATION === "deterministic"
|
2024-02-02 03:21:24 +08:00
|
|
|
? [1, 2, 2, 2, 2, 2, 2, 8]
|
2020-07-31 18:13:30 +08:00
|
|
|
: [1, 1, 1, 1, 1, 1, 1, 8]
|
|
|
|
);
|
2019-12-22 03:26:41 +08:00
|
|
|
});
|