Skip to content

Commit 1e09650

Browse files
authored
Merge pull request webpack#7411 from aleen42/master
fix: unsupported function defined inside a condition block. webpack#7263
2 parents b756012 + 24072ab commit 1e09650

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

lib/web/JsonpMainTemplatePlugin.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class JsonpMainTemplatePlugin {
154154

155155
return Template.asString([
156156
"var script = document.createElement('script');",
157+
"var onScriptComplete;",
157158
jsonpScriptType
158159
? `script.type = ${JSON.stringify(jsonpScriptType)};`
159160
: "",
@@ -168,12 +169,7 @@ class JsonpMainTemplatePlugin {
168169
),
169170
"}",
170171
"script.src = jsonpScriptSrc(chunkId);",
171-
"var timeout = setTimeout(function(){",
172-
Template.indent([
173-
"onScriptComplete({ type: 'timeout', target: script });"
174-
]),
175-
`}, ${chunkLoadTimeout});`,
176-
"function onScriptComplete(event) {",
172+
"onScriptComplete = function (event) {",
177173
Template.indent([
178174
"// avoid mem leaks in IE.",
179175
"script.onerror = script.onload = null;",
@@ -196,6 +192,11 @@ class JsonpMainTemplatePlugin {
196192
"}"
197193
]),
198194
"};",
195+
"var timeout = setTimeout(function(){",
196+
Template.indent([
197+
"onScriptComplete({ type: 'timeout', target: script });"
198+
]),
199+
`}, ${chunkLoadTimeout});`,
199200
"script.onerror = script.onload = onScriptComplete;"
200201
]);
201202
}

test/__snapshots__/StatsTestCases.test.js.snap

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Child fitting:
88
Built at: Thu Jan 01 1970 00:00:00 GMT
99
Asset Size Chunks Chunk Names
1010
9ac13fb7087e9ff1b93e.js 1.05 KiB 0 [emitted]
11-
f2e891598128a57b072c.js 10.2 KiB 1 [emitted]
11+
f2e891598128a57b072c.js 10.3 KiB 1 [emitted]
1212
d1ba53816ff760e185b0.js 1.94 KiB 2 [emitted]
1313
7b5b0a943e9362bc88c6.js 1.94 KiB 3 [emitted]
1414
Entrypoint main = d1ba53816ff760e185b0.js 7b5b0a943e9362bc88c6.js f2e891598128a57b072c.js
@@ -34,7 +34,7 @@ Child content-change:
3434
Built at: Thu Jan 01 1970 00:00:00 GMT
3535
Asset Size Chunks Chunk Names
3636
9ac13fb7087e9ff1b93e.js 1.05 KiB 0 [emitted]
37-
f2e891598128a57b072c.js 10.2 KiB 1 [emitted]
37+
f2e891598128a57b072c.js 10.3 KiB 1 [emitted]
3838
d1ba53816ff760e185b0.js 1.94 KiB 2 [emitted]
3939
7b5b0a943e9362bc88c6.js 1.94 KiB 3 [emitted]
4040
Entrypoint main = d1ba53816ff760e185b0.js 7b5b0a943e9362bc88c6.js f2e891598128a57b072c.js
@@ -71,7 +71,7 @@ d6418937dfae4b3ee922.js 1 KiB 1 [emitted]
7171
685acdc95ff4af957f47.js 1 KiB 7 [emitted]
7272
606f48c13070850338b1.js 1.94 KiB 8 [emitted]
7373
c5a8eae840969538f450.js 1.94 KiB 9 [emitted]
74-
c69b2f79fdf6e98907c4.js 8.68 KiB 10 [emitted] main
74+
c69b2f79fdf6e98907c4.js 8.71 KiB 10 [emitted] main
7575
fcdf398c8972e4dcf788.js 1.94 KiB 11 [emitted]
7676
Entrypoint main = c69b2f79fdf6e98907c4.js
7777
chunk {0} fd868baa40dab4fc30fd.js 1.76 KiB <{10}> ={1}= ={2}= ={3}= ={7}= ={9}= [recorded] aggressive splitted
@@ -498,7 +498,7 @@ Built at: Thu Jan 01 1970 00:00:00 GMT
498498
Asset Size Chunks Chunk Names
499499
0.bundle.js 152 bytes 0 [emitted]
500500
1.bundle.js 289 bytes 1 [emitted]
501-
bundle.js 7.27 KiB 2 [emitted] main
501+
bundle.js 7.31 KiB 2 [emitted] main
502502
3.bundle.js 227 bytes 3 [emitted]
503503
Entrypoint main = bundle.js
504504
chunk {0} 0.bundle.js 22 bytes <{2}> [rendered]
@@ -537,7 +537,7 @@ Built at: Thu Jan 01 1970 00:00:00 GMT
537537
0.bundle.js 433 bytes 0 [emitted]
538538
1.bundle.js 297 bytes 1 [emitted]
539539
2.bundle.js 588 bytes 2 [emitted]
540-
bundle.js 7.65 KiB main [emitted] main
540+
bundle.js 7.68 KiB main [emitted] main
541541
Entrypoint main = bundle.js
542542
chunk {main} bundle.js (main) 73 bytes >{0}< >{1}< [entry] [rendered]
543543
> ./index main
@@ -985,7 +985,7 @@ Built at: Thu Jan 01 1970 00:00:00 GMT
985985
0.js 305 bytes 0 [emitted]
986986
1.js 314 bytes 1 [emitted]
987987
2.js 308 bytes 2 [emitted]
988-
entry.js 8.07 KiB 3 [emitted] entry
988+
entry.js 8.11 KiB 3 [emitted] entry
989989
Entrypoint entry = entry.js
990990
[0] ./templates/bar.js 38 bytes {0} [optional] [built]
991991
[1] ./templates/baz.js 38 bytes {1} [optional] [built]
@@ -1000,7 +1000,7 @@ Time: Xms
10001000
Built at: Thu Jan 01 1970 00:00:00 GMT
10011001
Asset Size Chunks Chunk Names
10021002
0.js 149 bytes 0 [emitted]
1003-
entry.js 8.06 KiB 1 [emitted] entry
1003+
entry.js 8.1 KiB 1 [emitted] entry
10041004
Entrypoint entry = entry.js
10051005
[0] ./modules/b.js 22 bytes {0} [built]
10061006
[1] ./entry.js 120 bytes {1} [built]
@@ -1029,7 +1029,7 @@ Child 2 chunks:
10291029
Built at: Thu Jan 01 1970 00:00:00 GMT
10301030
Asset Size Chunks Chunk Names
10311031
0.bundle.js 1 KiB 0 [emitted]
1032-
bundle.js 7.46 KiB 1 [emitted] main
1032+
bundle.js 7.49 KiB 1 [emitted] main
10331033
Entrypoint main = bundle.js
10341034
chunk {0} 0.bundle.js 118 bytes <{0}> <{1}> >{0}< [rendered]
10351035
[0] ./d.js 22 bytes {0} [built]
@@ -1046,7 +1046,7 @@ Child 3 chunks:
10461046
Asset Size Chunks Chunk Names
10471047
0.bundle.js 886 bytes 0 [emitted]
10481048
1.bundle.js 245 bytes 1 [emitted]
1049-
bundle.js 7.46 KiB 2 [emitted] main
1049+
bundle.js 7.49 KiB 2 [emitted] main
10501050
Entrypoint main = bundle.js
10511051
chunk {0} 0.bundle.js 74 bytes <{0}> <{2}> >{0}< >{1}< [rendered]
10521052
[0] ./d.js 22 bytes {0} [built]
@@ -1065,7 +1065,7 @@ Child 4 chunks:
10651065
0.bundle.js 236 bytes 0 [emitted]
10661066
1.bundle.js 245 bytes 1 [emitted]
10671067
2.bundle.js 715 bytes 2 [emitted]
1068-
bundle.js 7.46 KiB 3 [emitted] main
1068+
bundle.js 7.49 KiB 3 [emitted] main
10691069
Entrypoint main = bundle.js
10701070
chunk {0} 0.bundle.js 44 bytes <{2}> <{3}> [rendered]
10711071
[0] ./d.js 22 bytes {0} [built]
@@ -1157,9 +1157,9 @@ exports[`StatsTestCases should print correct stats for module-deduplication 1`]
11571157
3.js 661 bytes 3 [emitted]
11581158
4.js 661 bytes 4 [emitted]
11591159
5.js 661 bytes 5 [emitted]
1160-
e1.js 8.4 KiB 6 [emitted] e1
1161-
e2.js 8.43 KiB 7 [emitted] e2
1162-
e3.js 8.45 KiB 8 [emitted] e3
1160+
e1.js 8.44 KiB 6 [emitted] e1
1161+
e2.js 8.46 KiB 7 [emitted] e2
1162+
e3.js 8.48 KiB 8 [emitted] e3
11631163
Entrypoint e1 = e1.js
11641164
Entrypoint e2 = e2.js
11651165
Entrypoint e3 = e3.js
@@ -1203,9 +1203,9 @@ exports[`StatsTestCases should print correct stats for module-deduplication-name
12031203
async3.js 818 bytes 0 [emitted] async3
12041204
async1.js 818 bytes 1 [emitted] async1
12051205
async2.js 818 bytes 2 [emitted] async2
1206-
e1.js 8.29 KiB 3 [emitted] e1
1207-
e2.js 8.31 KiB 4 [emitted] e2
1208-
e3.js 8.33 KiB 5 [emitted] e3
1206+
e1.js 8.33 KiB 3 [emitted] e1
1207+
e2.js 8.35 KiB 4 [emitted] e2
1208+
e3.js 8.37 KiB 5 [emitted] e3
12091209
Entrypoint e1 = e1.js
12101210
Entrypoint e2 = e2.js
12111211
Entrypoint e3 = e3.js
@@ -1337,7 +1337,7 @@ Built at: Thu Jan 01 1970 00:00:00 GMT
13371337
Asset Size Chunks Chunk Names
13381338
chunk-containing-__a_js.js 509 bytes chunk-containing-__a_js [emitted]
13391339
chunk-containing-__b_js.js 173 bytes chunk-containing-__b_js [emitted]
1340-
entry.js 7.55 KiB entry [emitted] entry
1340+
entry.js 7.59 KiB entry [emitted] entry
13411341
Entrypoint entry = entry.js
13421342
[0] ./modules/b.js 22 bytes {chunk-containing-__b_js} [built]
13431343
[1] ./modules/a.js 37 bytes {chunk-containing-__a_js} [built]
@@ -1375,7 +1375,7 @@ Built at: Thu Jan 01 1970 00:00:00 GMT
13751375
ab.js 183 bytes 1 [emitted] ab
13761376
abd.js 277 bytes 2, 1 [emitted] abd
13771377
cir2.js 299 bytes 3 [emitted] cir2
1378-
main.js 8.07 KiB 4 [emitted] main
1378+
main.js 8.11 KiB 4 [emitted] main
13791379
cir2 from cir1.js 359 bytes 5, 3 [emitted] cir2 from cir1
13801380
chunk.js 190 bytes 6, 7 [emitted] chunk
13811381
ac in ab.js 130 bytes 7 [emitted] ac in ab
@@ -1672,7 +1672,7 @@ exports[`StatsTestCases should print correct stats for prefetch 1`] = `
16721672
normal.js 130 bytes 1 [emitted] normal
16731673
prefetched2.js 127 bytes 2 [emitted] prefetched2
16741674
prefetched3.js 130 bytes 3 [emitted] prefetched3
1675-
main.js 9.69 KiB 4 [emitted] main
1675+
main.js 9.72 KiB 4 [emitted] main
16761676
inner.js 136 bytes 5 [emitted] inner
16771677
inner2.js 201 bytes 6 [emitted] inner2
16781678
Entrypoint main = main.js (prefetch: prefetched2.js prefetched.js prefetched3.js)
@@ -1705,7 +1705,7 @@ exports[`StatsTestCases should print correct stats for preload 1`] = `
17051705
normal.js 130 bytes 1 [emitted] normal
17061706
preloaded2.js 127 bytes 2 [emitted] preloaded2
17071707
preloaded3.js 130 bytes 3 [emitted] preloaded3
1708-
main.js 9.81 KiB 4 [emitted] main
1708+
main.js 9.85 KiB 4 [emitted] main
17091709
inner.js 136 bytes 5 [emitted] inner
17101710
inner2.js 201 bytes 6 [emitted] inner2
17111711
Entrypoint main = main.js (preload: preloaded2.js preloaded.js preloaded3.js)
@@ -1725,7 +1725,7 @@ Built at: Thu Jan 01 1970 00:00:00 GMT
17251725
Asset Size Chunks Chunk Names
17261726
0.js 152 bytes 0 [emitted]
17271727
1.js 289 bytes 1 [emitted]
1728-
main.js 7.28 KiB 2 [emitted] main
1728+
main.js 7.31 KiB 2 [emitted] main
17291729
3.js 227 bytes 3 [emitted]
17301730
Entrypoint main = main.js
17311731
chunk {0} 0.js 22 bytes <{2}> [rendered]
@@ -1784,7 +1784,7 @@ Built at: Thu Jan 01 1970 00:00:00 GMT
17841784
Asset Size Chunks Chunk Names
17851785
0.js 152 bytes 0 [emitted]
17861786
1.js 289 bytes 1 [emitted]
1787-
main.js 7.28 KiB 2 [emitted] main
1787+
main.js 7.31 KiB 2 [emitted] main
17881788
3.js 227 bytes 3 [emitted]
17891789
Entrypoint main = main.js
17901790
[0] ./d.js 22 bytes {3} [built]
@@ -1862,7 +1862,7 @@ Built at: Thu Jan 01 1970 00:00:00 GMT
18621862
Asset Size Chunks Chunk Names
18631863
0.js 152 bytes 0 [emitted]
18641864
1.js 289 bytes 1 [emitted]
1865-
main.js 7.28 KiB 2 [emitted] main
1865+
main.js 7.31 KiB 2 [emitted] main
18661866
3.js 227 bytes 3 [emitted]
18671867
Entrypoint main = main.js
18681868
chunk {0} 0.js 22 bytes <{2}> [rendered]
@@ -1953,7 +1953,7 @@ exports[`StatsTestCases should print correct stats for runtime-chunk-integration
19531953
Asset Size Chunks Chunk Names
19541954
0.js 719 bytes 0 [emitted]
19551955
main1.js 542 bytes 1 [emitted] main1
1956-
runtime.js 7.73 KiB 2 [emitted] runtime
1956+
runtime.js 7.77 KiB 2 [emitted] runtime
19571957
Entrypoint main1 = runtime.js main1.js
19581958
[0] ./b.js 20 bytes {0} [built]
19591959
[1] ./c.js 20 bytes {0} [built]
@@ -1962,7 +1962,7 @@ exports[`StatsTestCases should print correct stats for runtime-chunk-integration
19621962
Child manifest is named entry:
19631963
Asset Size Chunks Chunk Names
19641964
0.js 719 bytes 0 [emitted]
1965-
manifest.js 8.04 KiB 1 [emitted] manifest
1965+
manifest.js 8.08 KiB 1 [emitted] manifest
19661966
main1.js 542 bytes 2 [emitted] main1
19671967
Entrypoint main1 = manifest.js main1.js
19681968
Entrypoint manifest = manifest.js

0 commit comments

Comments
 (0)