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

Warn in @babel/plugin-proposal-private-property-in-object fallback #15687

Merged
merged 8 commits into from
Jun 8, 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: 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.2",

Choose a reason for hiding this comment

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

Could this ternary require two values?

Copy link
Member Author

Choose a reason for hiding this comment

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

This ternary is just to make sure that the dependency will be automatically removed in Babel 8, in the published package it's being resolved to 7.21.0-placeholder-for-preset-env.2

"@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
57 changes: 48 additions & 9 deletions packages/babel-preset-env/test/regressions.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
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";
import { USE_ESM, commonJS } from "$repo-utils";

const itBabel7 = process.env.BABEL_8_BREAKING ? it.skip : it;
const { require } = commonJS(import.meta.url);

describe("#12880", () => {
afterEach(() => {
jest.spyOn(process, "cwd").mockRestore();
});
const itBabel7 = process.env.BABEL_8_BREAKING ? it.skip : it;
const itBabel7Node14plusCjs =
process.env.BABEL_8_BREAKING ||
parseInt(process.versions.node) < 14 ||
USE_ESM
? it.skip
: it;

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

itBabel7(
"read the .browserslistrc file when using @babel/core < 7.13.0",
"#12880 - read the .browserslistrc file when using @babel/core < 7.13.0",
() => {
const root = path.join(
path.dirname(fileURLToPath(import.meta.url)),
Expand All @@ -39,12 +45,45 @@ describe("#12880", () => {
});

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

// create-reat-app missing dependency fallback
// jest fake timers only work in the Jest version we are using for Node.js 14+
itBabel7Node14plusCjs(
"proposal-private-property-in-object should warn and fallback to transform-...",
() => {
jest.useFakeTimers();
const consoleWarn = jest
.spyOn(console, "warn")
.mockImplementation(() => {});
try {
const out = babel.transformSync("class A { #a; x = #a in this }", {
configFile: false,
presets: [require("./regressions/babel-preset-react-app/index.js")],
});

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

expect(out.code).toMatchInlineSnapshot(`
"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 {
jest.useRealTimers();
consoleWarn.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.2":
version: 7.21.0-placeholder-for-preset-env.2
resolution: "@babel/plugin-proposal-private-property-in-object@npm:7.21.0-placeholder-for-preset-env.2"
peerDependencies:
"@babel/core": ^7.0.0-0
checksum: d97745d098b835d55033ff3a7fb2b895b9c5295b08a5759e4f20df325aa385a3e0bc9bd5ad8f2ec554a44d4e6525acfc257b8c5848a1345cb40f26a30e277e91
languageName: node
linkType: hard

"@babel/plugin-proposal-private-property-in-object@condition:BABEL_8_BREAKING ? : 7.21.0-placeholder-for-preset-env.2":
version: 0.0.0-condition-87b572
resolution: "@babel/plugin-proposal-private-property-in-object@condition:BABEL_8_BREAKING?:7.21.0-placeholder-for-preset-env.2#87b572"
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.2"
checksum: 3eb1935da93425f15865962e434f3574cf05510f4ed72be4e3ffa6242ea1e75efc98a906fa90e178debc915cae8dc5f03691b780ab2f5fc27d7911bfcdfa1b26
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.2"
"@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