Skip to content

Commit 9e136cd

Browse files
committed
fix: proper way for inner declaration of a function. webpack#7263
Use a varaible declaration outside a condition block instead, according to https://eslint.org/docs/rules/no-inner-declarations
1 parent 67fa81f commit 9e136cd

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
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
}

0 commit comments

Comments
 (0)