-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn in
@babel/plugin-proposal-private-property-in-object
fallback
- Loading branch information
1 parent
8814619
commit d9bf65c
Showing
8 changed files
with
125 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}, | ||
); | ||
}, | ||
); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/babel-preset-env/test/regressions/babel-preset-react-app/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")], | ||
}; | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/babel-preset-env/test/regressions/babel-preset-react-app/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "type": "commonjs" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters