Skip to content

Commit

Permalink
Warn in @babel/plugin-proposal-private-property-in-object fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jun 6, 2023
1 parent 8814619 commit d9bf65c
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 42 deletions.
6 changes: 6 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,10 @@ releaseTool:
unsafeHttpWhitelist:
- localhost

packageExtensions:
jest-snapshot@*:
dependencies:
# It doesn't support Prettier 3 yet
prettier: "^2.0.0"

yarnPath: .yarn/releases/yarn-3.6.0.cjs
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = {
"/node_modules/",
"/test/fixtures/",
"/test/debug-fixtures/",
"/babel-preset-env/test/regressions/",
"/babel-parser/test/expressions/",
"/test/tmp/",
"/test/__data__/",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"husky": "^7.0.4",
"import-meta-resolve": "^3.0.0",
"jest": "^29.5.0",
"jest-light-runner": "^0.4.1",
"jest-light-runner": "^0.5.0",
"jest-worker": "^29.5.0",
"lint-staged": "^13.0.3",
"mergeiterator": "^1.4.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-preset-env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@babel/helper-validator-option": "workspace:^",
"@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": "workspace:^",
"@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": "workspace:^",
"@babel/plugin-proposal-private-property-in-object": "^7.21.0",
"@babel/plugin-proposal-private-property-in-object": "condition:BABEL_8_BREAKING ? : 7.21.0-placeholder-for-preset-env.1",
"@babel/plugin-syntax-async-generators": "^7.8.4",
"@babel/plugin-syntax-class-properties": "^7.12.13",
"@babel/plugin-syntax-class-static-block": "^7.14.5",
Expand Down
106 changes: 73 additions & 33 deletions packages/babel-preset-env/test/regressions.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,90 @@
import * as babel7_12 from "@babel/core-7.12";
import * as babel from "@babel/core";
import env from "../lib/index.js";
import path from "path";
import { fileURLToPath } from "url";

const itBabel7 = process.env.BABEL_8_BREAKING ? it.skip : it;

describe("#12880", () => {
afterEach(() => {
jest.spyOn(process, "cwd").mockRestore();
});

describe("regressions", () => {
it("empty", () => {
// TODO(Babel 8): Delete this file
});

itBabel7(
"read the .browserslistrc file when using @babel/core < 7.13.0",
() => {
const root = path.join(
path.dirname(fileURLToPath(import.meta.url)),
"regressions",
);

// Unfortunatly, when loading the browserslist config through
// @babel/preset-env, it's resolved from process.cwd() and not
// from root. Mock it to isolate this test.
const spy = jest.spyOn(process, "cwd").mockReturnValue(root);

try {
// The browserslistrc file contains "firefox 50".
// a ** b is supported starting from firefox 52;
// a => b is supported starting from firefox 45.
const out = babel7_12.transformSync("a ** b; a => b;", {
describe("#12880", () => {
afterEach(() => {
jest.spyOn(process, "cwd").mockRestore();
});

itBabel7(
"read the .browserslistrc file when using @babel/core < 7.13.0",
() => {
const root = path.join(
path.dirname(fileURLToPath(import.meta.url)),
"regressions",
);

// Unfortunatly, when loading the browserslist config through
// @babel/preset-env, it's resolved from process.cwd() and not
// from root. Mock it to isolate this test.
const spy = jest.spyOn(process, "cwd").mockReturnValue(root);

try {
// The browserslistrc file contains "firefox 50".
// a ** b is supported starting from firefox 52;
// a => b is supported starting from firefox 45.
const out = babel7_12.transformSync("a ** b; a => b;", {
configFile: false,
presets: [[env, { modules: false }]],
filename: path.join(root, "input.js"),
root,
});

expect(out.code).toMatchInlineSnapshot(`
"Math.pow(a, b);
a => b;"
`);
} finally {
spy.mockRestore();
}
},
);
});

describe("create-reat-app missing dependency fallback", () => {
let consoleWarn;
beforeEach(() => {
jest.useFakeTimers();
consoleWarn = jest.spyOn(console, "warn").mockImplementation(() => {});
});
afterEach(() => {
jest.useRealTimers();
consoleWarn.mockRestore();
});

itBabel7(
"proposal-private-property-in-object should warn and fallback to transform-...",
async () => {
const out = babel.transformSync("class A { #a; x = #a in this }", {
configFile: false,
presets: [[env, { modules: false }]],
filename: path.join(root, "input.js"),
root,
presets: [
(await import("./regressions/babel-preset-react-app/index.js"))
.default,
],
});

jest.advanceTimersByTime(5000);
expect(consoleWarn).toHaveBeenCalled();

expect(out.code).toMatchInlineSnapshot(`
"Math.pow(a, b);
a => b;"
"function _checkInRHS(value) { if (Object(value) !== value) throw TypeError(\\"right-hand side of 'in' should be an object, got \\" + (null !== value ? typeof value : \\"null\\")); return value; }
var _aBrandCheck = /*#__PURE__*/new WeakSet();
class A {
#a = void _aBrandCheck.add(this);
x = _aBrandCheck.has(_checkInRHS(this));
}"
`);
} finally {
spy.mockRestore();
}
},
);
},
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable no-restricted-globals */

module.exports = function () {
return {
plugins: [require("@babel/plugin-proposal-private-property-in-object")],
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "type": "commonjs" }
42 changes: 35 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,24 @@ __metadata:
languageName: unknown
linkType: soft

"@babel/plugin-proposal-private-property-in-object-BABEL_8_BREAKING-false@npm:@babel/plugin-proposal-private-property-in-object@7.21.0-placeholder-for-preset-env.1":
version: 7.21.0-placeholder-for-preset-env.1
resolution: "@babel/plugin-proposal-private-property-in-object@npm:7.21.0-placeholder-for-preset-env.1"
peerDependencies:
"@babel/core": ^7.0.0-0
checksum: 34ee9fee925efe5271ea7652dc65c0218210f2313e64f69d516a31fbdd4757e0ab58140283f8702a5920e82ffed438541a83badec8bcc2101feadb58b29d8014
languageName: node
linkType: hard

"@babel/plugin-proposal-private-property-in-object@condition:BABEL_8_BREAKING ? : 7.21.0-placeholder-for-preset-env.1":
version: 0.0.0-condition-c1180e
resolution: "@babel/plugin-proposal-private-property-in-object@condition:BABEL_8_BREAKING?:7.21.0-placeholder-for-preset-env.1#c1180e"
dependencies:
"@babel/plugin-proposal-private-property-in-object-BABEL_8_BREAKING-false": "npm:@babel/plugin-proposal-private-property-in-object@7.21.0-placeholder-for-preset-env.1"
checksum: db920fe1b3349424e856d9b02d96bb4aa2d5608b224edb28c8942b42bddd2d281ecc207ce65978e0b71f70244980110a69405c57576278c19e9fbd1bc698cf28
languageName: node
linkType: hard

"@babel/plugin-proposal-private-property-in-object@npm:^7.21.0":
version: 7.21.0
resolution: "@babel/plugin-proposal-private-property-in-object@npm:7.21.0"
Expand Down Expand Up @@ -3541,7 +3559,7 @@ __metadata:
"@babel/helper-validator-option": "workspace:^"
"@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": "workspace:^"
"@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": "workspace:^"
"@babel/plugin-proposal-private-property-in-object": ^7.21.0
"@babel/plugin-proposal-private-property-in-object": "condition:BABEL_8_BREAKING ? : 7.21.0-placeholder-for-preset-env.1"
"@babel/plugin-syntax-async-generators": ^7.8.4
"@babel/plugin-syntax-class-properties": ^7.12.13
"@babel/plugin-syntax-class-static-block": ^7.14.5
Expand Down Expand Up @@ -4163,7 +4181,7 @@ __metadata:
languageName: node
linkType: hard

"@jest/fake-timers@npm:^29.5.0":
"@jest/fake-timers@npm:^29.2.2, @jest/fake-timers@npm:^29.5.0":
version: 29.5.0
resolution: "@jest/fake-timers@npm:29.5.0"
dependencies:
Expand Down Expand Up @@ -6269,7 +6287,7 @@ __metadata:
husky: ^7.0.4
import-meta-resolve: ^3.0.0
jest: ^29.5.0
jest-light-runner: ^0.4.1
jest-light-runner: ^0.5.0
jest-worker: ^29.5.0
lint-staged: ^13.0.3
mergeiterator: ^1.4.4
Expand Down Expand Up @@ -10861,11 +10879,12 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"jest-light-runner@npm:^0.4.1":
version: 0.4.1
resolution: "jest-light-runner@npm:0.4.1"
"jest-light-runner@npm:^0.5.0":
version: 0.5.0
resolution: "jest-light-runner@npm:0.5.0"
dependencies:
"@jest/expect": ^29.0.1
"@jest/fake-timers": ^29.2.2
jest-circus: ^29.0.1
jest-each: ^29.0.1
jest-mock: ^29.0.1
Expand All @@ -10874,7 +10893,7 @@ fsevents@^1.2.7:
supports-color: ^9.2.1
peerDependencies:
jest: ^27.5.0 || ^28.0.0 || ^29.0.0
checksum: e1a3019e9d3cd03627f85e2a7cfd10f89c6b34e88f6fbd8496575fe995cad1e333a7aed476137612cbd2f2de0474c4bc6c5191a28c4db8b231c9ea957d09d07b
checksum: 9a572e175ccadaaa67073ea6e3caf02c20e937f4e6a1dc7c4f8ccafcbed47b475375694f1f87e980da85af79d120830ff133f73831f294439f3125f9eb5f93a7
languageName: node
linkType: hard

Expand Down Expand Up @@ -13209,6 +13228,15 @@ fsevents@^1.2.7:
languageName: node
linkType: hard

"prettier@npm:^2.0.0":
version: 2.8.8
resolution: "prettier@npm:2.8.8"
bin:
prettier: bin-prettier.js
checksum: b49e409431bf129dd89238d64299ba80717b57ff5a6d1c1a8b1a28b590d998a34e083fa13573bc732bb8d2305becb4c9a4407f8486c81fa7d55100eb08263cf8
languageName: node
linkType: hard

"pretty-format@npm:^29.0.0, pretty-format@npm:^29.5.0":
version: 29.5.0
resolution: "pretty-format@npm:29.5.0"
Expand Down

0 comments on commit d9bf65c

Please sign in to comment.