Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Works correctly with --frozen-intrinsics #15626

Merged
merged 5 commits into from Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/babel-core/src/errors/rewrite-stack-trace.ts
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
@@ -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")(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to see a PR using itGte in more places :)

"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%");
},
);
});