1{"version":3,"file":"fetchThenEval.js","sourceRoot":"","sources":["../../src/async-require/fetchThenEval.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,6CAA0C;AAM1C;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,GAAW;IAC5C,OAAO,IAAA,uBAAU,EAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE;QAChD,IACE,OAAO,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,IAAI,IAAI;YACtC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAE,CAAC,QAAQ,CAAC,kBAAkB,CAAC,EACzD;YACA,+BAA+B;YAC/B,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,IAAI,2BAA2B,GAAG,GAAG,CAAC,CAAC;SAChF;QAED,gFAAgF;QAEhF,oEAAoE;QACpE,qEAAqE;QACrE,IAAI,MAAM,CAAC,uBAAuB,EAAE;YAClC,MAAM,CAAC,uBAAuB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;SAC3C;aAAM;YACL,mCAAmC;YACnC,IAAI,CAAC,IAAI,CAAC,CAAC;SACZ;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AArBD,gDAqBC","sourcesContent":["/**\n * Copyright © 2022 650 Industries.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\nimport { fetchAsync } from './fetchAsync';\n\ndeclare let global: {\n globalEvalWithSourceUrl?: any;\n};\n\n/**\n * Load a bundle for a URL using fetch + eval on native and script tag injection on web.\n *\n * @param bundlePath Given a statement like `import('./Bacon')` `bundlePath` would be `Bacon`.\n */\nexport function fetchThenEvalAsync(url: string): Promise<void> {\n return fetchAsync(url).then(({ body, headers }) => {\n if (\n headers?.has?.('Content-Type') != null &&\n headers.get('Content-Type')!.includes('application/json')\n ) {\n // Errors are returned as JSON.\n throw new Error(JSON.parse(body).message || `Unknown error fetching '${url}'`);\n }\n\n // NOTE(EvanBacon): All of this code is ignored in development mode at the root.\n\n // Some engines do not support `sourceURL` as a comment. We expose a\n // `globalEvalWithSourceUrl` function to handle updates in that case.\n if (global.globalEvalWithSourceUrl) {\n global.globalEvalWithSourceUrl(body, url);\n } else {\n // eslint-disable-next-line no-eval\n eval(body);\n }\n });\n}\n"]}