Skip to content

Commit

Permalink
fix: proper way for inner declaration of a function. #7263
Browse files Browse the repository at this point in the history
Use a varaible declaration outside a condition block instead, according to https://eslint.org/docs/rules/no-inner-declarations
  • Loading branch information
aleen42 committed May 29, 2018
1 parent 67fa81f commit 9e136cd
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/web/JsonpMainTemplatePlugin.js
Expand Up @@ -154,6 +154,7 @@ class JsonpMainTemplatePlugin {

return Template.asString([
"var script = document.createElement('script');",
"var onScriptComplete;",
jsonpScriptType
? `script.type = ${JSON.stringify(jsonpScriptType)};`
: "",
Expand All @@ -168,12 +169,7 @@ class JsonpMainTemplatePlugin {
),
"}",
"script.src = jsonpScriptSrc(chunkId);",
"var timeout = setTimeout(function(){",
Template.indent([
"onScriptComplete({ type: 'timeout', target: script });"
]),
`}, ${chunkLoadTimeout});`,
"function onScriptComplete(event) {",
"onScriptComplete = function (event) {",
Template.indent([
"// avoid mem leaks in IE.",
"script.onerror = script.onload = null;",
Expand All @@ -196,6 +192,11 @@ class JsonpMainTemplatePlugin {
"}"
]),
"};",
"var timeout = setTimeout(function(){",
Template.indent([
"onScriptComplete({ type: 'timeout', target: script });"
]),
`}, ${chunkLoadTimeout});`,
"script.onerror = script.onload = onScriptComplete;"
]);
}
Expand Down

0 comments on commit 9e136cd

Please sign in to comment.