Skip to content

Commit

Permalink
fix: log error when eval code
Browse files Browse the repository at this point in the history
  • Loading branch information
ClarkXia committed May 19, 2020
1 parent 5224a57 commit fbba13f
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions packages/icestark-module/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,27 @@ export default class ModuleLoader {
const { name } = starkModule;
let libraryExport = '';
// excute script in order
sources.forEach((source, index) => {
const lastScript = index === sources.length - 1;
if (lastScript) {
noteGlobalProps(globalWindow);
}
// check sandbox
if (sandbox?.execScriptInSandbox) {
sandbox.execScriptInSandbox(source);
} else {
// https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/eval
// eslint-disable-next-line no-eval
(0, eval)(source);
}
if (lastScript) {
libraryExport = getGlobalProp(globalWindow);
}
});
try {
sources.forEach((source, index) => {
const lastScript = index === sources.length - 1;
if (lastScript) {
noteGlobalProps(globalWindow);
}
// check sandbox
if (sandbox?.execScriptInSandbox) {
sandbox.execScriptInSandbox(source);
} else {
// https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/eval
// eslint-disable-next-line no-eval
(0, eval)(source);
}
if (lastScript) {
libraryExport = getGlobalProp(globalWindow);
}
});
} catch (err) {
console.error(err);
}
const moduleInfo = libraryExport ? (globalWindow as any)[libraryExport] : ((globalWindow as any)[name] || {});
// remove moduleInfo from globalWindow in case of excute multi module in globalWindow
if ((globalWindow as any)[libraryExport]) {
Expand Down

0 comments on commit fbba13f

Please sign in to comment.