Skip to content

Commit 5756d9a

Browse files
test: build the annotation matcher without hand-rolled escaping
CodeQL flagged the escape set for omitting backslashes. Spell the pieces out already escaped for a regexp instead, which drops the replace entirely. Refs #17121
1 parent 75a3d89 commit 5756d9a

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

  • test/configCases/side-effects/pure-annotation-minified

‎test/configCases/side-effects/pure-annotation-minified/index.js‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ export function times(a, b) {
77
it("should keep the annotation through minification", () => {
88
const fs = require("fs");
99
const source = fs.readFileSync(__filename, "utf-8");
10-
// Spelled out in pieces, so this assertion is not itself a hit.
11-
const annotation = ["/*#", "__PURE__", "*/"].join("");
10+
// Spelled out in pieces, already escaped for a regexp, so this assertion is
11+
// not itself a hit.
12+
const annotation = ["/\\*#", "__PURE__", "\\*/"].join("");
1213

1314
// Terser strips annotations unless the library defaults ask it not to, so the
1415
// one in front of the side-effect-free module's instantiation must still be here.
15-
expect(source).toMatch(
16-
new RegExp(`${annotation.replace(/[*/]/g, "\\$&")}\\w+\\(`)
17-
);
16+
expect(source).toMatch(new RegExp(`${annotation}\\w+\\(`));
1817
expect(times(6, 7)).toBe(42);
1918
});

0 commit comments

Comments
 (0)