Skip to content

Commit

Permalink
fix(polyfill): add string detection for minified output
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed Mar 9, 2021
1 parent 8e46590 commit 441d6d4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {unlinkSync, writeFileSync} from "fs";
import {transform} from "@swc/core";
import {REGENERATOR_SOURCE} from "../constant/regenerator-source";

const swcBug1461String = `var regeneratorRuntime = require("regenerator-runtime");`;
const swcBug1461Match = /var regeneratorRuntime\s*=\s*require\(["'`]regenerator-runtime["'`]\);/;
const unicodeEscape = /(\\+)u\{([0-9a-fA-F]+)\}/g;

/**
Expand Down Expand Up @@ -45,7 +45,7 @@ function workAroundSwcBug1227(str: string): string {
* TODO: Remove this when https://github.com/swc-project/swc/issues/1461 has been resolved
*/
function workAroundSwcBug1461(str: string): string {
return str.replace(swcBug1461String, REGENERATOR_SOURCE);
return str.replace(swcBug1461Match, REGENERATOR_SOURCE);
}

function stringifyPolyfillFeature(feature: IPolyfillFeature): string {
Expand Down Expand Up @@ -134,7 +134,7 @@ export async function build({paths, features, featuresRequested, ecmaVersion, co
}

// TODO: Remove this when https://github.com/swc-project/swc/issues/1461 has been resolved
if (code.includes(swcBug1461String)) {
if (swcBug1461Match.test(code)) {
code = workAroundSwcBug1461(code);
}
}
Expand Down

0 comments on commit 441d6d4

Please sign in to comment.