index.browser.mjs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. import { declare } from '@babel/helper-plugin-utils';
  2. import _getTargets, { prettifyTargets, getInclusionReasons, isRequired } from '@babel/helper-compilation-targets';
  3. import * as babel from '@babel/core';
  4. const {
  5. types: t$1,
  6. template
  7. } = babel.default || babel;
  8. function intersection(a, b) {
  9. const result = new Set();
  10. a.forEach(v => b.has(v) && result.add(v));
  11. return result;
  12. }
  13. function has$1(object, key) {
  14. return Object.prototype.hasOwnProperty.call(object, key);
  15. }
  16. function getType(target) {
  17. return Object.prototype.toString.call(target).slice(8, -1);
  18. }
  19. function resolveId(path) {
  20. if (path.isIdentifier() && !path.scope.hasBinding(path.node.name,
  21. /* noGlobals */
  22. true)) {
  23. return path.node.name;
  24. }
  25. const {
  26. deopt
  27. } = path.evaluate();
  28. if (deopt && deopt.isIdentifier()) {
  29. return deopt.node.name;
  30. }
  31. }
  32. function resolveKey(path, computed = false) {
  33. const {
  34. node,
  35. parent,
  36. scope
  37. } = path;
  38. if (path.isStringLiteral()) return node.value;
  39. const {
  40. name
  41. } = node;
  42. const isIdentifier = path.isIdentifier();
  43. if (isIdentifier && !(computed || parent.computed)) return name;
  44. if (computed && path.isMemberExpression() && path.get("object").isIdentifier({
  45. name: "Symbol"
  46. }) && !scope.hasBinding("Symbol",
  47. /* noGlobals */
  48. true)) {
  49. const sym = resolveKey(path.get("property"), path.node.computed);
  50. if (sym) return "Symbol." + sym;
  51. }
  52. if (!isIdentifier || scope.hasBinding(name,
  53. /* noGlobals */
  54. true)) {
  55. const {
  56. value
  57. } = path.evaluate();
  58. if (typeof value === "string") return value;
  59. }
  60. }
  61. function resolveSource(obj) {
  62. if (obj.isMemberExpression() && obj.get("property").isIdentifier({
  63. name: "prototype"
  64. })) {
  65. const id = resolveId(obj.get("object"));
  66. if (id) {
  67. return {
  68. id,
  69. placement: "prototype"
  70. };
  71. }
  72. return {
  73. id: null,
  74. placement: null
  75. };
  76. }
  77. const id = resolveId(obj);
  78. if (id) {
  79. return {
  80. id,
  81. placement: "static"
  82. };
  83. }
  84. const {
  85. value
  86. } = obj.evaluate();
  87. if (value !== undefined) {
  88. return {
  89. id: getType(value),
  90. placement: "prototype"
  91. };
  92. } else if (obj.isRegExpLiteral()) {
  93. return {
  94. id: "RegExp",
  95. placement: "prototype"
  96. };
  97. } else if (obj.isFunction()) {
  98. return {
  99. id: "Function",
  100. placement: "prototype"
  101. };
  102. }
  103. return {
  104. id: null,
  105. placement: null
  106. };
  107. }
  108. function getImportSource({
  109. node
  110. }) {
  111. if (node.specifiers.length === 0) return node.source.value;
  112. }
  113. function getRequireSource({
  114. node
  115. }) {
  116. if (!t$1.isExpressionStatement(node)) return;
  117. const {
  118. expression
  119. } = node;
  120. const isRequire = t$1.isCallExpression(expression) && t$1.isIdentifier(expression.callee) && expression.callee.name === "require" && expression.arguments.length === 1 && t$1.isStringLiteral(expression.arguments[0]);
  121. if (isRequire) return expression.arguments[0].value;
  122. }
  123. function hoist(node) {
  124. node._blockHoist = 3;
  125. return node;
  126. }
  127. function createUtilsGetter(cache) {
  128. return path => {
  129. const prog = path.findParent(p => p.isProgram());
  130. return {
  131. injectGlobalImport(url) {
  132. cache.storeAnonymous(prog, url, (isScript, source) => {
  133. return isScript ? template.statement.ast`require(${source})` : t$1.importDeclaration([], source);
  134. });
  135. },
  136. injectNamedImport(url, name, hint = name) {
  137. return cache.storeNamed(prog, url, name, (isScript, source, name) => {
  138. const id = prog.scope.generateUidIdentifier(hint);
  139. return {
  140. node: isScript ? hoist(template.statement.ast`
  141. var ${id} = require(${source}).${name}
  142. `) : t$1.importDeclaration([t$1.importSpecifier(id, name)], source),
  143. name: id.name
  144. };
  145. });
  146. },
  147. injectDefaultImport(url, hint = url) {
  148. return cache.storeNamed(prog, url, "default", (isScript, source) => {
  149. const id = prog.scope.generateUidIdentifier(hint);
  150. return {
  151. node: isScript ? hoist(template.statement.ast`var ${id} = require(${source})`) : t$1.importDeclaration([t$1.importDefaultSpecifier(id)], source),
  152. name: id.name
  153. };
  154. });
  155. }
  156. };
  157. };
  158. }
  159. const {
  160. types: t
  161. } = babel.default || babel;
  162. class ImportsCache {
  163. constructor(resolver) {
  164. this._imports = new WeakMap();
  165. this._anonymousImports = new WeakMap();
  166. this._lastImports = new WeakMap();
  167. this._resolver = resolver;
  168. }
  169. storeAnonymous(programPath, url, // eslint-disable-next-line no-undef
  170. getVal) {
  171. const key = this._normalizeKey(programPath, url);
  172. const imports = this._ensure(this._anonymousImports, programPath, Set);
  173. if (imports.has(key)) return;
  174. const node = getVal(programPath.node.sourceType === "script", t.stringLiteral(this._resolver(url)));
  175. imports.add(key);
  176. this._injectImport(programPath, node);
  177. }
  178. storeNamed(programPath, url, name, getVal) {
  179. const key = this._normalizeKey(programPath, url, name);
  180. const imports = this._ensure(this._imports, programPath, Map);
  181. if (!imports.has(key)) {
  182. const {
  183. node,
  184. name: id
  185. } = getVal(programPath.node.sourceType === "script", t.stringLiteral(this._resolver(url)), t.identifier(name));
  186. imports.set(key, id);
  187. this._injectImport(programPath, node);
  188. }
  189. return t.identifier(imports.get(key));
  190. }
  191. _injectImport(programPath, node) {
  192. let lastImport = this._lastImports.get(programPath);
  193. if (lastImport && lastImport.node && // Sometimes the AST is modified and the "last import"
  194. // we have has been replaced
  195. lastImport.parent === programPath.node && lastImport.container === programPath.node.body) {
  196. lastImport = lastImport.insertAfter(node);
  197. } else {
  198. lastImport = programPath.unshiftContainer("body", node);
  199. }
  200. lastImport = lastImport[lastImport.length - 1];
  201. this._lastImports.set(programPath, lastImport);
  202. /*
  203. let lastImport;
  204. programPath.get("body").forEach(path => {
  205. if (path.isImportDeclaration()) lastImport = path;
  206. if (
  207. path.isExpressionStatement() &&
  208. isRequireCall(path.get("expression"))
  209. ) {
  210. lastImport = path;
  211. }
  212. if (
  213. path.isVariableDeclaration() &&
  214. path.get("declarations").length === 1 &&
  215. (isRequireCall(path.get("declarations.0.init")) ||
  216. (path.get("declarations.0.init").isMemberExpression() &&
  217. isRequireCall(path.get("declarations.0.init.object"))))
  218. ) {
  219. lastImport = path;
  220. }
  221. });*/
  222. }
  223. _ensure(map, programPath, Collection) {
  224. let collection = map.get(programPath);
  225. if (!collection) {
  226. collection = new Collection();
  227. map.set(programPath, collection);
  228. }
  229. return collection;
  230. }
  231. _normalizeKey(programPath, url, name = "") {
  232. const {
  233. sourceType
  234. } = programPath.node; // If we rely on the imported binding (the "name" parameter), we also need to cache
  235. // based on the sourceType. This is because the module transforms change the names
  236. // of the import variables.
  237. return `${name && sourceType}::${url}::${name}`;
  238. }
  239. }
  240. const presetEnvSilentDebugHeader = "#__secret_key__@babel/preset-env__don't_log_debug_header_and_resolved_targets";
  241. function stringifyTargetsMultiline(targets) {
  242. return JSON.stringify(prettifyTargets(targets), null, 2);
  243. }
  244. function patternToRegExp(pattern) {
  245. if (pattern instanceof RegExp) return pattern;
  246. try {
  247. return new RegExp(`^${pattern}$`);
  248. } catch {
  249. return null;
  250. }
  251. }
  252. function buildUnusedError(label, unused) {
  253. if (!unused.length) return "";
  254. return ` - The following "${label}" patterns didn't match any polyfill:\n` + unused.map(original => ` ${String(original)}\n`).join("");
  255. }
  256. function buldDuplicatesError(duplicates) {
  257. if (!duplicates.size) return "";
  258. return ` - The following polyfills were matched both by "include" and "exclude" patterns:\n` + Array.from(duplicates, name => ` ${name}\n`).join("");
  259. }
  260. function validateIncludeExclude(provider, polyfills, includePatterns, excludePatterns) {
  261. let current;
  262. const filter = pattern => {
  263. const regexp = patternToRegExp(pattern);
  264. if (!regexp) return false;
  265. let matched = false;
  266. for (const polyfill of polyfills) {
  267. if (regexp.test(polyfill)) {
  268. matched = true;
  269. current.add(polyfill);
  270. }
  271. }
  272. return !matched;
  273. }; // prettier-ignore
  274. const include = current = new Set();
  275. const unusedInclude = Array.from(includePatterns).filter(filter); // prettier-ignore
  276. const exclude = current = new Set();
  277. const unusedExclude = Array.from(excludePatterns).filter(filter);
  278. const duplicates = intersection(include, exclude);
  279. if (duplicates.size > 0 || unusedInclude.length > 0 || unusedExclude.length > 0) {
  280. throw new Error(`Error while validating the "${provider}" provider options:\n` + buildUnusedError("include", unusedInclude) + buildUnusedError("exclude", unusedExclude) + buldDuplicatesError(duplicates));
  281. }
  282. return {
  283. include,
  284. exclude
  285. };
  286. }
  287. function applyMissingDependenciesDefaults(options, babelApi) {
  288. const {
  289. missingDependencies = {}
  290. } = options;
  291. if (missingDependencies === false) return false;
  292. const caller = babelApi.caller(caller => caller?.name);
  293. const {
  294. log = "deferred",
  295. inject = caller === "rollup-plugin-babel" ? "throw" : "import",
  296. all = false
  297. } = missingDependencies;
  298. return {
  299. log,
  300. inject,
  301. all
  302. };
  303. }
  304. var usage = (callProvider => {
  305. function property(object, key, placement, path) {
  306. return callProvider({
  307. kind: "property",
  308. object,
  309. key,
  310. placement
  311. }, path);
  312. }
  313. return {
  314. // Symbol(), new Promise
  315. ReferencedIdentifier(path) {
  316. const {
  317. node: {
  318. name
  319. },
  320. scope
  321. } = path;
  322. if (scope.getBindingIdentifier(name)) return;
  323. callProvider({
  324. kind: "global",
  325. name
  326. }, path);
  327. },
  328. MemberExpression(path) {
  329. const key = resolveKey(path.get("property"), path.node.computed);
  330. if (!key || key === "prototype") return;
  331. const object = path.get("object");
  332. const binding = object.scope.getBinding(object.node.name);
  333. if (binding && binding.path.isImportNamespaceSpecifier()) return;
  334. const source = resolveSource(object);
  335. return property(source.id, key, source.placement, path);
  336. },
  337. ObjectPattern(path) {
  338. const {
  339. parentPath,
  340. parent
  341. } = path;
  342. let obj; // const { keys, values } = Object
  343. if (parentPath.isVariableDeclarator()) {
  344. obj = parentPath.get("init"); // ({ keys, values } = Object)
  345. } else if (parentPath.isAssignmentExpression()) {
  346. obj = parentPath.get("right"); // !function ({ keys, values }) {...} (Object)
  347. // resolution does not work after properties transform :-(
  348. } else if (parentPath.isFunction()) {
  349. const grand = parentPath.parentPath;
  350. if (grand.isCallExpression() || grand.isNewExpression()) {
  351. if (grand.node.callee === parent) {
  352. obj = grand.get("arguments")[path.key];
  353. }
  354. }
  355. }
  356. let id = null;
  357. let placement = null;
  358. if (obj) ({
  359. id,
  360. placement
  361. } = resolveSource(obj));
  362. for (const prop of path.get("properties")) {
  363. if (prop.isObjectProperty()) {
  364. const key = resolveKey(prop.get("key"));
  365. if (key) property(id, key, placement, prop);
  366. }
  367. }
  368. },
  369. BinaryExpression(path) {
  370. if (path.node.operator !== "in") return;
  371. const source = resolveSource(path.get("right"));
  372. const key = resolveKey(path.get("left"), true);
  373. if (!key) return;
  374. callProvider({
  375. kind: "in",
  376. object: source.id,
  377. key,
  378. placement: source.placement
  379. }, path);
  380. }
  381. };
  382. });
  383. var entry = (callProvider => ({
  384. ImportDeclaration(path) {
  385. const source = getImportSource(path);
  386. if (!source) return;
  387. callProvider({
  388. kind: "import",
  389. source
  390. }, path);
  391. },
  392. Program(path) {
  393. path.get("body").forEach(bodyPath => {
  394. const source = getRequireSource(bodyPath);
  395. if (!source) return;
  396. callProvider({
  397. kind: "import",
  398. source
  399. }, bodyPath);
  400. });
  401. }
  402. }));
  403. function resolve(dirname, moduleName, absoluteImports) {
  404. if (absoluteImports === false) return moduleName;
  405. throw new Error(`"absoluteImports" is not supported in bundles prepared for the browser.`);
  406. } // eslint-disable-next-line no-unused-vars
  407. function has(basedir, name) {
  408. return true;
  409. } // eslint-disable-next-line no-unused-vars
  410. function logMissing(missingDeps) {} // eslint-disable-next-line no-unused-vars
  411. function laterLogMissing(missingDeps) {}
  412. const PossibleGlobalObjects = new Set(["global", "globalThis", "self", "window"]);
  413. function createMetaResolver(polyfills) {
  414. const {
  415. static: staticP,
  416. instance: instanceP,
  417. global: globalP
  418. } = polyfills;
  419. return meta => {
  420. if (meta.kind === "global" && globalP && has$1(globalP, meta.name)) {
  421. return {
  422. kind: "global",
  423. desc: globalP[meta.name],
  424. name: meta.name
  425. };
  426. }
  427. if (meta.kind === "property" || meta.kind === "in") {
  428. const {
  429. placement,
  430. object,
  431. key
  432. } = meta;
  433. if (object && placement === "static") {
  434. if (globalP && PossibleGlobalObjects.has(object) && has$1(globalP, key)) {
  435. return {
  436. kind: "global",
  437. desc: globalP[key],
  438. name: key
  439. };
  440. }
  441. if (staticP && has$1(staticP, object) && has$1(staticP[object], key)) {
  442. return {
  443. kind: "static",
  444. desc: staticP[object][key],
  445. name: `${object}$${key}`
  446. };
  447. }
  448. }
  449. if (instanceP && has$1(instanceP, key)) {
  450. return {
  451. kind: "instance",
  452. desc: instanceP[key],
  453. name: `${key}`
  454. };
  455. }
  456. }
  457. };
  458. }
  459. const getTargets = _getTargets.default || _getTargets;
  460. function resolveOptions(options, babelApi) {
  461. const {
  462. method,
  463. targets: targetsOption,
  464. ignoreBrowserslistConfig,
  465. configPath,
  466. debug,
  467. shouldInjectPolyfill,
  468. absoluteImports,
  469. ...providerOptions
  470. } = options;
  471. let methodName;
  472. if (method === "usage-global") methodName = "usageGlobal";else if (method === "entry-global") methodName = "entryGlobal";else if (method === "usage-pure") methodName = "usagePure";else if (typeof method !== "string") {
  473. throw new Error(".method must be a string");
  474. } else {
  475. throw new Error(`.method must be one of "entry-global", "usage-global"` + ` or "usage-pure" (received ${JSON.stringify(method)})`);
  476. }
  477. if (typeof shouldInjectPolyfill === "function") {
  478. if (options.include || options.exclude) {
  479. throw new Error(`.include and .exclude are not supported when using the` + ` .shouldInjectPolyfill function.`);
  480. }
  481. } else if (shouldInjectPolyfill != null) {
  482. throw new Error(`.shouldInjectPolyfill must be a function, or undefined` + ` (received ${JSON.stringify(shouldInjectPolyfill)})`);
  483. }
  484. if (absoluteImports != null && typeof absoluteImports !== "boolean" && typeof absoluteImports !== "string") {
  485. throw new Error(`.absoluteImports must be a boolean, a string, or undefined` + ` (received ${JSON.stringify(absoluteImports)})`);
  486. }
  487. let targets;
  488. if ( // If any browserslist-related option is specified, fallback to the old
  489. // behavior of not using the targets specified in the top-level options.
  490. targetsOption || configPath || ignoreBrowserslistConfig) {
  491. const targetsObj = typeof targetsOption === "string" || Array.isArray(targetsOption) ? {
  492. browsers: targetsOption
  493. } : targetsOption;
  494. targets = getTargets(targetsObj, {
  495. ignoreBrowserslistConfig,
  496. configPath
  497. });
  498. } else {
  499. targets = babelApi.targets();
  500. }
  501. return {
  502. method,
  503. methodName,
  504. targets,
  505. absoluteImports: absoluteImports ?? false,
  506. shouldInjectPolyfill,
  507. debug: !!debug,
  508. providerOptions: providerOptions
  509. };
  510. }
  511. function instantiateProvider(factory, options, missingDependencies, dirname, debugLog, babelApi) {
  512. const {
  513. method,
  514. methodName,
  515. targets,
  516. debug,
  517. shouldInjectPolyfill,
  518. providerOptions,
  519. absoluteImports
  520. } = resolveOptions(options, babelApi);
  521. const getUtils = createUtilsGetter(new ImportsCache(moduleName => resolve(dirname, moduleName, absoluteImports))); // eslint-disable-next-line prefer-const
  522. let include, exclude;
  523. let polyfillsSupport;
  524. let polyfillsNames;
  525. let filterPolyfills;
  526. const depsCache = new Map();
  527. const api = {
  528. babel: babelApi,
  529. getUtils,
  530. method: options.method,
  531. targets,
  532. createMetaResolver,
  533. shouldInjectPolyfill(name) {
  534. if (polyfillsNames === undefined) {
  535. throw new Error(`Internal error in the ${factory.name} provider: ` + `shouldInjectPolyfill() can't be called during initialization.`);
  536. }
  537. if (!polyfillsNames.has(name)) {
  538. console.warn(`Internal error in the ${provider.name} provider: ` + `unknown polyfill "${name}".`);
  539. }
  540. if (filterPolyfills && !filterPolyfills(name)) return false;
  541. let shouldInject = isRequired(name, targets, {
  542. compatData: polyfillsSupport,
  543. includes: include,
  544. excludes: exclude
  545. });
  546. if (shouldInjectPolyfill) {
  547. shouldInject = shouldInjectPolyfill(name, shouldInject);
  548. if (typeof shouldInject !== "boolean") {
  549. throw new Error(`.shouldInjectPolyfill must return a boolean.`);
  550. }
  551. }
  552. return shouldInject;
  553. },
  554. debug(name) {
  555. debugLog().found = true;
  556. if (!debug || !name) return;
  557. if (debugLog().polyfills.has(provider.name)) return;
  558. debugLog().polyfills.set(name, polyfillsSupport && name && polyfillsSupport[name]);
  559. },
  560. assertDependency(name, version = "*") {
  561. if (missingDependencies === false) return;
  562. if (absoluteImports) {
  563. // If absoluteImports is not false, we will try resolving
  564. // the dependency and throw if it's not possible. We can
  565. // skip the check here.
  566. return;
  567. }
  568. const dep = version === "*" ? name : `${name}@^${version}`;
  569. const found = missingDependencies.all ? false : mapGetOr(depsCache, `${name} :: ${dirname}`, () => has());
  570. if (!found) {
  571. debugLog().missingDeps.add(dep);
  572. }
  573. }
  574. };
  575. const provider = factory(api, providerOptions, dirname);
  576. if (typeof provider[methodName] !== "function") {
  577. throw new Error(`The "${provider.name || factory.name}" provider doesn't ` + `support the "${method}" polyfilling method.`);
  578. }
  579. if (Array.isArray(provider.polyfills)) {
  580. polyfillsNames = new Set(provider.polyfills);
  581. filterPolyfills = provider.filterPolyfills;
  582. } else if (provider.polyfills) {
  583. polyfillsNames = new Set(Object.keys(provider.polyfills));
  584. polyfillsSupport = provider.polyfills;
  585. filterPolyfills = provider.filterPolyfills;
  586. } else {
  587. polyfillsNames = new Set();
  588. }
  589. ({
  590. include,
  591. exclude
  592. } = validateIncludeExclude(provider.name || factory.name, polyfillsNames, providerOptions.include || [], providerOptions.exclude || []));
  593. return {
  594. debug,
  595. method,
  596. targets,
  597. provider,
  598. callProvider(payload, path) {
  599. const utils = getUtils(path); // $FlowIgnore
  600. provider[methodName](payload, utils, path);
  601. }
  602. };
  603. }
  604. function definePolyfillProvider(factory) {
  605. return declare((babelApi, options, dirname) => {
  606. babelApi.assertVersion(7);
  607. const {
  608. traverse
  609. } = babelApi;
  610. let debugLog;
  611. const missingDependencies = applyMissingDependenciesDefaults(options, babelApi);
  612. const {
  613. debug,
  614. method,
  615. targets,
  616. provider,
  617. callProvider
  618. } = instantiateProvider(factory, options, missingDependencies, dirname, () => debugLog, babelApi);
  619. const createVisitor = method === "entry-global" ? entry : usage;
  620. const visitor = provider.visitor ? traverse.visitors.merge([createVisitor(callProvider), provider.visitor]) : createVisitor(callProvider);
  621. if (debug && debug !== presetEnvSilentDebugHeader) {
  622. console.log(`${provider.name}: \`DEBUG\` option`);
  623. console.log(`\nUsing targets: ${stringifyTargetsMultiline(targets)}`);
  624. console.log(`\nUsing polyfills with \`${method}\` method:`);
  625. }
  626. return {
  627. name: "inject-polyfills",
  628. visitor,
  629. pre() {
  630. debugLog = {
  631. polyfills: new Map(),
  632. found: false,
  633. providers: new Set(),
  634. missingDeps: new Set()
  635. }; // $FlowIgnore - Flow doesn't support optional calls
  636. provider.pre?.apply(this, arguments);
  637. },
  638. post() {
  639. // $FlowIgnore - Flow doesn't support optional calls
  640. provider.post?.apply(this, arguments);
  641. if (missingDependencies !== false) {
  642. if (missingDependencies.log === "per-file") {
  643. logMissing(debugLog.missingDeps);
  644. } else {
  645. laterLogMissing(debugLog.missingDeps);
  646. }
  647. }
  648. if (!debug) return;
  649. if (this.filename) console.log(`\n[${this.filename}]`);
  650. if (debugLog.polyfills.size === 0) {
  651. console.log(method === "entry-global" ? debugLog.found ? `Based on your targets, the ${provider.name} polyfill did not add any polyfill.` : `The entry point for the ${provider.name} polyfill has not been found.` : `Based on your code and targets, the ${provider.name} polyfill did not add any polyfill.`);
  652. return;
  653. }
  654. if (method === "entry-global") {
  655. console.log(`The ${provider.name} polyfill entry has been replaced with ` + `the following polyfills:`);
  656. } else {
  657. console.log(`The ${provider.name} polyfill added the following polyfills:`);
  658. }
  659. for (const [name, support] of debugLog.polyfills) {
  660. if (support) {
  661. const filteredTargets = getInclusionReasons(name, targets, support);
  662. const formattedTargets = JSON.stringify(filteredTargets).replace(/,/g, ", ").replace(/^\{"/, '{ "').replace(/"\}$/, '" }');
  663. console.log(` ${name} ${formattedTargets}`);
  664. } else {
  665. console.log(` ${name}`);
  666. }
  667. }
  668. }
  669. };
  670. });
  671. }
  672. function mapGetOr(map, key, getDefault) {
  673. let val = map.get(key);
  674. if (val === undefined) {
  675. val = getDefault();
  676. map.set(key, val);
  677. }
  678. return val;
  679. }
  680. export default definePolyfillProvider;
  681. //# sourceMappingURL=index.browser.mjs.map