Skip to content

Commit

Permalink
fix(build): work around swc bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
wessberg committed Mar 9, 2021
1 parent 445b6e0 commit 3071cda
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/build/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ import {transform} from "@swc/core";
import {REGENERATOR_SOURCE} from "../constant/regenerator-source";

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

/**
* TODO: Remove this when https://github.com/swc-project/swc/issues/1227 has been resolved
*/
function workAroundSwcBug1227(str: string): string {
const unicodeEscape = /(\\+)u\{([0-9a-fA-F]+)\}/g;

function escape(code: any) {
let str = code.toString(16);
// Sigh, node 6 doesn't have padStart
Expand Down Expand Up @@ -119,11 +118,6 @@ export async function build({paths, features, featuresRequested, ecmaVersion, co
ecmaVersion = "es2019";
}

// TODO: Remove this when https://github.com/swc-project/swc/issues/1227 has been resolved
if (code.includes("\\u{")) {
code = workAroundSwcBug1227(code);
}

({code, map} = await transform(code, {
sourceMaps: sourcemap ? "inline" : false,
inputSourceMap: map,
Expand All @@ -134,6 +128,11 @@ export async function build({paths, features, featuresRequested, ecmaVersion, co
}
}));

// TODO: Remove this when https://github.com/swc-project/swc/issues/1227 has been resolved
if (code.includes("\\u{")) {
code = workAroundSwcBug1227(code);
}

// TODO: Remove this when https://github.com/swc-project/swc/issues/1461 has been resolved
if (code.includes(swcBug1461String)) {
code = workAroundSwcBug1461(code);
Expand Down
1 change: 1 addition & 0 deletions test/server/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ test("Will correctly escape unicode escape sequences. #1", async t => {
t.false("The API didn't have a body");
} else {
t.false(result.body.toString().includes(`u{1e950}`));
t.false(result.body.toString().includes(`u{660}`));
}
});

Expand Down

0 comments on commit 3071cda

Please sign in to comment.