Skip to content

Commit 14d8fa8

Browse files
committed
fix: all tests cases
1 parent 96fe32b commit 14d8fa8

File tree

13 files changed

+39
-52
lines changed

13 files changed

+39
-52
lines changed
Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
import { value as v1 } from "./module1";
2-
const v2 = require("./module2")
3-
const module3Inc = require("./module3")
1+
import { value as value1 } from './module1'
2+
const value2 = require('./module2')
3+
const value3 = require('./module3')
44

5-
const index_value = 10;
6-
let value = 42;
5+
let value = 42
6+
let src_value = 43
7+
let src_src_value = 44
78

8-
function inc() {
9-
value++;
10-
}
11-
12-
it("single inlined module should not be wrapped in IIFE", () => {
13-
expect(value).toBe(42);
14-
expect(v1).toBe(undefined);
15-
expect(v2).toBe(undefined);
16-
expect(module3Inc).toBe(undefined);
17-
inc();
18-
expect(value).toBe(43);
19-
expect(index_value).toBe(10);
20-
});
9+
it('inlined module should not leak to non-inlined modules', () => {
10+
expect(value1).toBe(undefined)
11+
expect(value).toBe(42)
12+
expect(src_value).toBe(43)
13+
expect(src_src_value).toBe(44)
14+
expect(value2).toBe("undefined") // should not touch leaked `value` variable
15+
expect(value3).toBe("undefined") // should not touch leaked `src_value` variable
16+
})
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
let value;
1+
let value
22

3-
export { value };
3+
export { value }
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
let value
2-
3-
module.exports = value
1+
module.exports = typeof value
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
let inc
2-
3-
module.exports = inc
1+
module.exports = typeof src_value
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
module.exports = 'foo'
1+
module.exports = 42;
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
1-
import foo from './foo.cjs'
1+
import foo from './foo.cjs';
2+
3+
let answer
4+
5+
try {
6+
delete Object.prototype; // will throw error in strict mode
7+
answer = 'no';
8+
} catch {
9+
answer = 'yes';
10+
}
11+
12+
it("multiple inlined modules should be wrapped in IIFE to isolate from other inlined modules and chunk modules", () => {
13+
expect(answer).toBe("yes"); // the code should throw in strict mode
14+
});

test/configCases/output-module/iife-multiple-entry-modules/index-1.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

test/configCases/output-module/iife-multiple-entry-modules/index-2.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
it("multiple inlined modules should be wrapped in IIFE to isolate from other inlined modules and chunk modules", () => {
3+
expect(typeof value).toBe("undefined"); // `value` in index2 should not leak to index1
4+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var value = 42

0 commit comments

Comments
 (0)