Skip to content

Commit

Permalink
fix: Works correctly with --frozen-intrinsics (#15626)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicol貌 Ribaudo <nicolo.ribaudo@gmail.com>
  • Loading branch information
liuxingbaoyu and nicolo-ribaudo committed Jun 13, 2023
1 parent be8fccd commit 5fed5af
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
6 changes: 4 additions & 2 deletions packages/babel-core/src/errors/rewrite-stack-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@

const ErrorToString = Function.call.bind(Error.prototype.toString);

const SUPPORTED = !!Error.captureStackTrace;
const SUPPORTED =
!!Error.captureStackTrace &&
Object.getOwnPropertyDescriptor(Error, "stackTraceLimit")?.writable === true;

const START_HIDING = "startHiding - secret - don't use this - v1";
const STOP_HIDING = "stopHiding - secret - don't use this - v1";

type CallSite = Parameters<typeof Error.prepareStackTrace>[1][number];
type CallSite = NodeJS.CallSite;

const expectedErrors = new WeakSet<Error>();
const virtualFrames = new WeakMap<Error, CallSite[]>();
Expand Down
36 changes: 29 additions & 7 deletions packages/babel-core/test/errors-stacks.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as babel from "../lib/index.js";

import { fileURLToPath } from "url";
import { commonJS, itGte } from "$repo-utils";
import path from "path";
import { spawnSync } from "child_process";

const { __dirname } = commonJS(import.meta.url);

const replaceAll = "".replaceAll
? Function.call.bind("".replaceAll)
Expand Down Expand Up @@ -70,12 +73,7 @@ function expectError(run) {
throw new Error("It should have thrown an error.");
}

const fixture = name =>
path.join(
path.dirname(fileURLToPath(import.meta.url)),
"fixtures/errors",
name,
);
const fixture = name => path.join(__dirname, "fixtures/errors", name);

describe("@babel/core errors", function () {
it("error inside config function", function () {
Expand Down Expand Up @@ -283,4 +281,28 @@ describe("@babel/core errors", function () {
at ... internal jest frames ..."
`);
});

itGte("12.0.0")(
"should not throw in `node --frozen-intrinsics`",
function () {
expect(
spawnSync(
process.execPath,
[
"--frozen-intrinsics",
"--input-type=module",
"-e",
`
import * as babel from "../lib/index.js";
babel.parseSync("foo;", {
root: String.raw\`${fixture("valid")}\`,
});
console.log("%done%");
`,
],
{ cwd: __dirname },
).output + "",
).toContain("%done%");
},
);
});

0 comments on commit 5fed5af

Please sign in to comment.