Skip to content

Commit 999e945

Browse files
authored
Add test for inadvertent extra strict mode declarations (#33)
1 parent 8afe5c7 commit 999e945

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

test/goodbye.spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const CHUNK_CHECKS = { goodbye: 1, parent: 2 } as const;
1818
const numMatchesTest = (file: string, pattern: RegExp, nMatches: number) =>
1919
async function () {
2020
const code = await readFile(file, "utf-8");
21-
expect(code.match(new RegExp(pattern, "g"))?.length).to.equal(nMatches);
21+
const globalPattern = new RegExp(pattern, "g");
22+
expect(code.match(globalPattern)?.length ?? 0).to.equal(nMatches);
2223
};
2324

2425
for (const runtime of [false, { version: devDependencies["@babel/runtime"] }]) {
@@ -74,6 +75,7 @@ for (const runtime of [false, { version: devDependencies["@babel/runtime"] }]) {
7475

7576
for (const [name, nMatches] of Object.entries(CHUNK_CHECKS)) {
7677
const outChunk = join(outDir, `src_${name}_js.cjs`);
78+
let nStrict = 0; // only one at top chunk level
7779
if (nodeVersion < 7.6) {
7880
it(
7981
`Transpiles the async function to a generator in the ${name} chunk`,
@@ -85,6 +87,7 @@ for (const runtime of [false, { version: devDependencies["@babel/runtime"] }]) {
8587
nMatches,
8688
),
8789
);
90+
if (runtime) nStrict = nMatches; // because helper is included in chunk
8891
} else {
8992
it(
9093
`Contains async arrow function in the ${name} chunk`,
@@ -106,7 +109,12 @@ for (const runtime of [false, { version: devDependencies["@babel/runtime"] }]) {
106109
nMatches,
107110
),
108111
);
112+
nStrict = 0; // because asyncToGenerator hlper is split to separate chunk
109113
}
114+
it(
115+
`Does not add extra strict mode in the ${name} chunk`,
116+
numMatchesTest(outChunk, /\n"use strict";/, nStrict),
117+
);
110118
}
111119

112120
for (const name of ENTRY_NAMES) {

0 commit comments

Comments
 (0)