(urlAndGlobal, runtimeTemplate)
| 664 | * @returns {SourceData} the generated source |
| 665 | */ |
| 666 | const getSourceForScriptExternal = (urlAndGlobal, runtimeTemplate) => { |
| 667 | if (typeof urlAndGlobal === "string") { |
| 668 | urlAndGlobal = extractUrlAndGlobal(urlAndGlobal); |
| 669 | } |
| 670 | const url = urlAndGlobal[0]; |
| 671 | const globalName = urlAndGlobal[1]; |
| 672 | return { |
| 673 | init: `${runtimeTemplate.renderConst()} __webpack_error__ = new Error();`, |
| 674 | expression: `new Promise(${runtimeTemplate.basicFunction( |
| 675 | "resolve, reject", |
| 676 | [ |
| 677 | `if(typeof ${globalName} !== "undefined") return resolve();`, |
| 678 | `${RuntimeGlobals.loadScript}(${JSON.stringify( |
| 679 | url |
| 680 | )}, ${runtimeTemplate.basicFunction("event", [ |
| 681 | `if(typeof ${globalName} !== "undefined") return resolve();`, |
| 682 | `${runtimeTemplate.renderConst()} errorType = event && (event.type === 'load' ? 'missing' : event.type);`, |
| 683 | `${runtimeTemplate.renderConst()} realSrc = event && event.target && event.target.src;`, |
| 684 | "__webpack_error__.message = 'Loading script failed.\\n(' + errorType + ': ' + realSrc + ')';", |
| 685 | "__webpack_error__.name = 'ScriptExternalLoadError';", |
| 686 | "__webpack_error__.type = errorType;", |
| 687 | "__webpack_error__.request = realSrc;", |
| 688 | "reject(__webpack_error__);" |
| 689 | ])}, ${JSON.stringify(globalName)});` |
| 690 | ] |
| 691 | )}).then(${runtimeTemplate.returningFunction( |
| 692 | `${globalName}${propertyAccess(urlAndGlobal, 2)}` |
| 693 | )})`, |
| 694 | runtimeRequirements: RUNTIME_REQUIREMENTS_FOR_SCRIPT |
| 695 | }; |
| 696 | }; |
| 697 | |
| 698 | /** |
| 699 | * Checks external variable. |
no test coverage detected