diff --git a/.gitignore b/.gitignore index 45afd8fef7f0..37c66b084feb 100644 --- a/.gitignore +++ b/.gitignore @@ -70,6 +70,8 @@ packages/babel-standalone/babel.min.js /eslint/*/LICENSE !/packages/babel-eslint-plugin/LICENSE /.vscode +# local directory for VSCode Extension - https://marketplace.visualstudio.com/items?itemName=xyz.local-history +/.history /dts diff --git a/eslint/babel-eslint-parser/src/configuration.cjs b/eslint/babel-eslint-parser/src/configuration.cjs index 5cf2e5cc4fa4..11da9fc6c4bf 100644 --- a/eslint/babel-eslint-parser/src/configuration.cjs +++ b/eslint/babel-eslint-parser/src/configuration.cjs @@ -11,7 +11,7 @@ exports.normalizeESLintConfig = function (options) { return { babelOptions: { cwd: process.cwd(), ...babelOptions }, - ecmaVersion, + ecmaVersion: ecmaVersion === "latest" ? 1e8 : ecmaVersion, sourceType, allowImportExportEverywhere, requireConfigFile, diff --git a/eslint/babel-eslint-tests/test/integration/eslint/config.js b/eslint/babel-eslint-tests/test/integration/eslint/config.js index 989e9a8287d0..f0a406d251ee 100644 --- a/eslint/babel-eslint-tests/test/integration/eslint/config.js +++ b/eslint/babel-eslint-tests/test/integration/eslint/config.js @@ -21,4 +21,23 @@ describe("ESLint config", () => { }); expect(messages.length).toEqual(0); }); + + it('should allow ecmaVersion to be "latest"', () => { + const linter = new eslint.Linter(); + linter.defineParser("@babel/eslint-parser", parser); + // ImportDeclarations result in a parser error if ecmaVersion < 2015 and sourceType != "module". + const messages = linter.verify('import { hello } from "greetings"', { + parser: "@babel/eslint-parser", + parserOptions: { + ecmaVersion: "latest", + babelOptions: { + configFile: path.resolve( + path.dirname(fileURLToPath(import.meta.url)), + "../../../../babel-eslint-shared-fixtures/config/babel.config.js", + ), + }, + }, + }); + expect(messages.length).toEqual(0); + }); }); diff --git a/jest.config.js b/jest.config.js index 2a03ce4e4202..276e156144d9 100644 --- a/jest.config.js +++ b/jest.config.js @@ -21,6 +21,7 @@ module.exports = { "/test/helpers/", "/test/warning\\.js", "/build/", + "/.history/", // local directory for VSCode Extension - https://marketplace.visualstudio.com/items?itemName=xyz.local-history "_browser\\.js", ], testEnvironment: "node", diff --git a/packages/babel-helper-compilation-targets/src/index.ts b/packages/babel-helper-compilation-targets/src/index.ts index c4077623583b..2919080b86d7 100644 --- a/packages/babel-helper-compilation-targets/src/index.ts +++ b/packages/babel-helper-compilation-targets/src/index.ts @@ -154,8 +154,11 @@ function generateTargets(inputTargets: InputTargets): Targets { return input as any as Targets; } -function resolveTargets(queries: Browsers): Targets { - const resolved = browserslist(queries, { mobileToDesktop: true }); +function resolveTargets(queries: Browsers, env?: string): Targets { + const resolved = browserslist(queries, { + mobileToDesktop: true, + env, + }); return getLowestVersions(resolved); } @@ -217,7 +220,7 @@ export default function getTargets( } if (browsers) { - const queryBrowsers = resolveTargets(browsers); + const queryBrowsers = resolveTargets(browsers, options.browserslistEnv); if (esmodules === "intersect") { for (const browser of Object.keys(queryBrowsers)) { diff --git a/packages/babel-helper-compilation-targets/test/browserslist-extends/browserslist-extends.spec.js b/packages/babel-helper-compilation-targets/test/browserslist-extends/browserslist-extends.spec.js new file mode 100644 index 000000000000..876f30777eb0 --- /dev/null +++ b/packages/babel-helper-compilation-targets/test/browserslist-extends/browserslist-extends.spec.js @@ -0,0 +1,37 @@ +import { dirname, resolve } from "path"; +import { fileURLToPath } from "url"; +import getTargets from "../../lib"; + +const currentDir = dirname(fileURLToPath(import.meta.url)); + +const oldEnv = process.env.BROWSERSLIST_DANGEROUS_EXTEND; + +beforeAll(() => { + process.env.BROWSERSLIST_DANGEROUS_EXTEND = true; +}); + +afterAll(() => { + process.env.BROWSERSLIST_DANGEROUS_EXTEND = oldEnv; +}); + +it("pass env to configs used with extends", async () => { + const actual = getTargets( + { + browsers: [ + `extends ${resolve( + currentDir, + "fixtures", + "@babel", + "browserslist-config-fixture.cjs", + )}`, + "chrome >= 71", + ], + }, + { + configPath: currentDir, + browserslistEnv: "custom", + }, + ); + + expect(actual).toEqual({ chrome: "71.0.0", firefox: "75.0.0" }); +}); diff --git a/packages/babel-helper-compilation-targets/test/browserslist-extends/fixtures/@babel/browserslist-config-fixture.cjs b/packages/babel-helper-compilation-targets/test/browserslist-extends/fixtures/@babel/browserslist-config-fixture.cjs new file mode 100644 index 000000000000..b6108c2910f3 --- /dev/null +++ b/packages/babel-helper-compilation-targets/test/browserslist-extends/fixtures/@babel/browserslist-config-fixture.cjs @@ -0,0 +1,4 @@ +module.exports = { + custom: ["firefox >= 75"], + defaults: ["chrome >= 5"], +}; diff --git a/packages/babel-helper-create-class-features-plugin/package.json b/packages/babel-helper-create-class-features-plugin/package.json index a217735112f6..a5a0f3e36148 100644 --- a/packages/babel-helper-create-class-features-plugin/package.json +++ b/packages/babel-helper-create-class-features-plugin/package.json @@ -31,6 +31,7 @@ "devDependencies": { "@babel/core": "workspace:*", "@babel/helper-plugin-test-runner": "workspace:*", + "@babel/plugin-syntax-class-static-block": "^7.14.5", "@babel/preset-env": "workspace:*" }, "engines": { diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index 695979cdd11f..9d8b386aa91f 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -1,6 +1,6 @@ import { template, traverse, types as t } from "@babel/core"; import type { File } from "@babel/core"; -import type { NodePath, Visitor } from "@babel/traverse"; +import type { NodePath, Visitor, Scope } from "@babel/traverse"; import ReplaceSupers, { environmentVisitor, } from "@babel/helper-replace-supers"; @@ -58,7 +58,7 @@ export function buildPrivateNamesMap(props: PropPath[]) { export function buildPrivateNamesNodes( privateNamesMap: PrivateNamesMap, privateFieldsAsProperties: boolean, - state, + state: File, ) { const initNodes: t.Statement[] = []; @@ -165,6 +165,7 @@ interface PrivateNameState { classRef: t.Identifier; file: File; noDocumentAll: boolean; + innerBinding?: t.Identifier; } const privateNameVisitor = privateNameVisitorFactory< @@ -188,9 +189,28 @@ const privateNameVisitor = privateNameVisitorFactory< }, }); +// rename all bindings that shadows innerBinding +function unshadow( + name: string, + scope: Scope, + innerBinding: t.Identifier | undefined, +) { + // in some cases, scope.getBinding(name) === undefined + // so we check hasBinding to avoid keeping looping + // see: https://github.com/babel/babel/pull/13656#discussion_r686030715 + while ( + scope?.hasBinding(name) && + !scope.bindingIdentifierEquals(name, innerBinding) + ) { + scope.rename(name); + scope = scope.parent; + } +} + const privateInVisitor = privateNameVisitorFactory<{ classRef: t.Identifier; file: File; + innerBinding?: t.Identifier; }>({ BinaryExpression(path) { const { operator, left, right } = path.node; @@ -204,6 +224,10 @@ const privateInVisitor = privateNameVisitorFactory<{ if (!privateNamesMap.has(name)) return; if (redeclared && redeclared.includes(name)) return; + // if there are any local variable shadowing classRef, unshadow it + // see #12960 + unshadow(this.classRef.name, path.scope, this.innerBinding); + if (privateFieldsAsProperties) { const { id } = privateNamesMap.get(name); path.replaceWith(template.expression.ast` @@ -255,7 +279,7 @@ const privateNameHandlerSpec: Handler & Receiver = }, get(member) { - const { classRef, privateNamesMap, file } = this; + const { classRef, privateNamesMap, file, innerBinding } = this; const { name } = (member.node.property as t.PrivateName).id; const { id, @@ -273,6 +297,10 @@ const privateNameHandlerSpec: Handler & Receiver = ? "classStaticPrivateMethodGet" : "classStaticPrivateFieldSpecGet"; + // if there are any local variable shadowing classRef, unshadow it + // see #12960 + unshadow(classRef.name, member.scope, innerBinding); + return t.callExpression(file.addHelper(helperName), [ this.receiver(member), t.cloneNode(classRef), @@ -463,8 +491,8 @@ export function transformPrivateNamesUsage( ref: t.Identifier, path: NodePath, privateNamesMap: PrivateNamesMap, - { privateFieldsAsProperties, noDocumentAll }, - state, + { privateFieldsAsProperties, noDocumentAll, innerBinding }, + state: File, ) { if (!privateNamesMap.size) return; @@ -479,12 +507,14 @@ export function transformPrivateNamesUsage( file: state, ...handler, noDocumentAll, + innerBinding, }); body.traverse(privateInVisitor, { privateNamesMap, classRef: ref, file: state, privateFieldsAsProperties, + innerBinding, }); } @@ -510,16 +540,31 @@ function buildPrivateInstanceFieldInitSpec( ref: t.Expression, prop: NodePath, privateNamesMap: PrivateNamesMap, + state, ) { const { id } = privateNamesMap.get(prop.node.key.id.name); const value = prop.node.value || prop.scope.buildUndefinedNode(); - return template.statement.ast`${t.cloneNode(id)}.set(${ref}, { - // configurable is always false for private elements - // enumerable is always false for private elements - writable: true, - value: ${value}, - })`; + if (!process.env.BABEL_8_BREAKING) { + if (!state.availableHelper("classPrivateFieldInitSpec")) { + return template.statement.ast`${t.cloneNode(id)}.set(${ref}, { + // configurable is always false for private elements + // enumerable is always false for private elements + writable: true, + value: ${value}, + })`; + } + } + + const helper = state.addHelper("classPrivateFieldInitSpec"); + return template.statement.ast`${helper}( + ${t.thisExpression()}, + ${t.cloneNode(id)}, + { + writable: true, + value: ${value} + }, + )`; } function buildPrivateStaticFieldInitSpec( @@ -602,27 +647,87 @@ function buildPrivateInstanceMethodInitSpec( ref: t.Expression, prop: NodePath, privateNamesMap: PrivateNamesMap, + state, ) { const privateName = privateNamesMap.get(prop.node.key.id.name); - const { id, getId, setId, initAdded } = privateName; + const { getId, setId, initAdded } = privateName; if (initAdded) return; const isAccessor = getId || setId; if (isAccessor) { - privateNamesMap.set(prop.node.key.id.name, { - ...privateName, - initAdded: true, - }); + return buildPrivateAccessorInitialization( + ref, + prop, + privateNamesMap, + state, + ); + } - return template.statement.ast` + return buildPrivateInstanceMethodInitalization( + ref, + prop, + privateNamesMap, + state, + ); +} + +function buildPrivateAccessorInitialization( + ref: t.Expression, + prop: NodePath, + privateNamesMap: PrivateNamesMap, + state, +) { + const privateName = privateNamesMap.get(prop.node.key.id.name); + const { id, getId, setId } = privateName; + + privateNamesMap.set(prop.node.key.id.name, { + ...privateName, + initAdded: true, + }); + + if (!process.env.BABEL_8_BREAKING) { + if (!state.availableHelper("classPrivateFieldInitSpec")) { + return template.statement.ast` ${id}.set(${ref}, { get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} }); `; + } } - return template.statement.ast`${id}.add(${ref})`; + + const helper = state.addHelper("classPrivateFieldInitSpec"); + return template.statement.ast`${helper}( + ${t.thisExpression()}, + ${t.cloneNode(id)}, + { + get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, + set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} + }, + )`; +} + +function buildPrivateInstanceMethodInitalization( + ref: t.Expression, + prop: NodePath, + privateNamesMap: PrivateNamesMap, + state, +) { + const privateName = privateNamesMap.get(prop.node.key.id.name); + const { id } = privateName; + + if (!process.env.BABEL_8_BREAKING) { + if (!state.availableHelper("classPrivateMethodInitSpec")) { + return template.statement.ast`${id}.add(${ref})`; + } + } + + const helper = state.addHelper("classPrivateMethodInitSpec"); + return template.statement.ast`${helper}( + ${t.thisExpression()}, + ${t.cloneNode(id)} + )`; } function buildPublicFieldInitLoose( @@ -770,7 +875,7 @@ const thisContextVisitor = traverse.visitors.merge([ ]); const innerReferencesVisitor = { - ReferencedIdentifier(path, state) { + ReferencedIdentifier(path: NodePath, state) { if ( path.scope.bindingIdentifierEquals(path.node.name, state.innerBinding) ) { @@ -831,7 +936,7 @@ export function buildFieldsInitNodes( superRef: t.Expression | undefined, props: PropPath[], privateNamesMap: PrivateNamesMap, - state, + state: File, setPublicClassFields: boolean, privateFieldsAsProperties: boolean, constantSuper: boolean, @@ -927,6 +1032,7 @@ export function buildFieldsInitNodes( // @ts-expect-error checked in switch prop, privateNamesMap, + state, ), ); break; @@ -955,6 +1061,7 @@ export function buildFieldsInitNodes( // @ts-expect-error checked in switch prop, privateNamesMap, + state, ), ); pureStaticNodes.push( diff --git a/packages/babel-helper-create-class-features-plugin/src/index.ts b/packages/babel-helper-create-class-features-plugin/src/index.ts index 24546834a122..57c7595a158d 100644 --- a/packages/babel-helper-create-class-features-plugin/src/index.ts +++ b/packages/babel-helper-create-class-features-plugin/src/index.ts @@ -1,4 +1,5 @@ import { types as t } from "@babel/core"; +import type { File } from "@babel/core"; import type { NodePath } from "@babel/traverse"; import nameFunction from "@babel/helper-function-name"; import splitExportDeclaration from "@babel/helper-split-export-declaration"; @@ -92,7 +93,7 @@ export function createClassFeaturePlugin({ }, visitor: { - Class(path: NodePath, state) { + Class(path: NodePath, state: File) { if (this.file.get(versionKey) !== version) return; verifyUsedFeatures(path, this.file); @@ -198,6 +199,7 @@ export function createClassFeaturePlugin({ { privateFieldsAsProperties: privateFieldsAsProperties ?? loose, noDocumentAll, + innerBinding, }, state, ); diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/input.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/input.js new file mode 100644 index 000000000000..8bc707067391 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/input.js @@ -0,0 +1,19 @@ +class Base { + constructor(obj) { + return obj; + } +} + +class Derived extends Base { + get #foo() { + return 'bar'; + } + + set #foo(value) { + this.#foo = value; + } + + static get(obj) { + return obj.#foo(); + } +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/options.json b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/options.json new file mode 100644 index 000000000000..608f30af0eb3 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/options.json @@ -0,0 +1,6 @@ +{ + "presets": [["env", { "shippedProposals": true }]], + "targets": { + "chrome": "75" + } +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/output.js new file mode 100644 index 000000000000..f1710074613f --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/output.js @@ -0,0 +1,31 @@ +class Base { + constructor(obj) { + return obj; + } + +} + +var _foo = /*#__PURE__*/new WeakMap(); + +class Derived extends Base { + constructor(...args) { + super(...args); + babelHelpers.classPrivateFieldInitSpec(this, _foo, { + get: _get_foo, + set: _set_foo + }); + } + + static get(obj) { + return babelHelpers.classPrivateFieldGet(obj, _foo).call(obj); + } + +} + +function _get_foo() { + return 'bar'; +} + +function _set_foo(value) { + babelHelpers.classPrivateFieldSet(this, _foo, value); +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/input.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/input.js new file mode 100644 index 000000000000..902695e4e932 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/input.js @@ -0,0 +1,13 @@ +class Base { + constructor(obj) { + return obj; + } +} + +let counter = 0; +class Derived extends Base { + #foo = ++counter; + static get(obj) { + return obj.#foo; + } +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/options.json b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/options.json new file mode 100644 index 000000000000..608f30af0eb3 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/options.json @@ -0,0 +1,6 @@ +{ + "presets": [["env", { "shippedProposals": true }]], + "targets": { + "chrome": "75" + } +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/output.js new file mode 100644 index 000000000000..59fe05cc06db --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/output.js @@ -0,0 +1,25 @@ +class Base { + constructor(obj) { + return obj; + } + +} + +let counter = 0; + +var _foo = /*#__PURE__*/new WeakMap(); + +class Derived extends Base { + constructor(...args) { + super(...args); + babelHelpers.classPrivateFieldInitSpec(this, _foo, { + writable: true, + value: ++counter + }); + } + + static get(obj) { + return babelHelpers.classPrivateFieldGet(obj, _foo); + } + +} \ No newline at end of file diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/input.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/input.js new file mode 100644 index 000000000000..1d6529040694 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/input.js @@ -0,0 +1,15 @@ +class Base { + constructor(obj) { + return obj; + } +} + +class Derived extends Base { + #foo() { + return 'bar'; + } + + static get(obj) { + return obj.#foo(); + } +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/options.json b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/options.json new file mode 100644 index 000000000000..608f30af0eb3 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/options.json @@ -0,0 +1,6 @@ +{ + "presets": [["env", { "shippedProposals": true }]], + "targets": { + "chrome": "75" + } +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/output.js new file mode 100644 index 000000000000..f5dd07cc5ed5 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/output.js @@ -0,0 +1,24 @@ +class Base { + constructor(obj) { + return obj; + } + +} + +var _foo = /*#__PURE__*/new WeakSet(); + +class Derived extends Base { + constructor(...args) { + super(...args); + babelHelpers.classPrivateMethodInitSpec(this, _foo); + } + + static get(obj) { + return babelHelpers.classPrivateMethodGet(obj, _foo, _foo2).call(obj); + } + +} + +function _foo2() { + return 'bar'; +} \ No newline at end of file diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/missing-class-static-blocks-plugin/basic/options.json b/packages/babel-helper-create-class-features-plugin/test/fixtures/missing-class-static-blocks-plugin/basic/options.json index 04ef00ef4b69..3f0630235cee 100644 --- a/packages/babel-helper-create-class-features-plugin/test/fixtures/missing-class-static-blocks-plugin/basic/options.json +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/missing-class-static-blocks-plugin/basic/options.json @@ -1,4 +1,7 @@ { - "plugins": ["proposal-class-properties", "syntax-class-static-block"], + "plugins": [ + "proposal-class-properties", + "@babel/plugin-syntax-class-static-block" + ], "throws": "Static class blocks are not enabled. Please add `@babel/plugin-proposal-class-static-block` to your configuration." } diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/output.js index 6e921bc9e05b..c74df0f555e0 100644 --- a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/output.js +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/output.js @@ -2,7 +2,7 @@ var _privateMethod = /*#__PURE__*/new WeakSet(); class X { constructor() { - _privateMethod.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _privateMethod); } } diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/replace-supers/method/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/replace-supers/method/output.js index af58f2d3c9a8..07429bb7b2d2 100644 --- a/packages/babel-helper-create-class-features-plugin/test/fixtures/replace-supers/method/output.js +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/replace-supers/method/output.js @@ -3,8 +3,7 @@ var _foo = /*#__PURE__*/new WeakSet(); class A extends B { constructor(...args) { super(...args); - - _foo.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _foo); } } diff --git a/packages/babel-helpers/src/helpers.ts b/packages/babel-helpers/src/helpers.ts index 7385e63a714d..0911aee76651 100644 --- a/packages/babel-helpers/src/helpers.ts +++ b/packages/babel-helpers/src/helpers.ts @@ -2022,6 +2022,32 @@ helpers.classPrivateMethodGet = helper("7.1.6")` } `; +helpers.checkPrivateRedeclaration = helper("7.14.1")` + export default function _checkPrivateRedeclaration(obj, privateCollection) { + if (privateCollection.has(obj)) { + throw new TypeError("Cannot initialize the same private elements twice on an object"); + } + } +`; + +helpers.classPrivateFieldInitSpec = helper("7.14.1")` + import checkPrivateRedeclaration from "checkPrivateRedeclaration"; + + export default function _classPrivateFieldInitSpec(obj, privateMap, value) { + checkPrivateRedeclaration(obj, privateMap); + privateMap.set(obj, value); + } +`; + +helpers.classPrivateMethodInitSpec = helper("7.14.1")` + import checkPrivateRedeclaration from "checkPrivateRedeclaration"; + + export default function _classPrivateMethodInitSpec(obj, privateSet) { + checkPrivateRedeclaration(obj, privateSet); + privateSet.add(obj); + } +`; + if (!process.env.BABEL_8_BREAKING) { // Use readOnlyError instead helpers.classPrivateMethodSet = helper("7.1.6")` diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-blocks/input.js b/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-blocks/input.js new file mode 100644 index 000000000000..5cf4a422ebf1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-blocks/input.js @@ -0,0 +1,4 @@ +let moduleBlock = module { + export let y = 1; +}; +let moduleExports = await import(moduleBlock); diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-blocks/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-blocks/options.json new file mode 100644 index 000000000000..45ff422e6d5a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-blocks/options.json @@ -0,0 +1,3 @@ +{ + "throws": "This experimental syntax requires enabling the parser plugin: 'moduleBlocks' (1:18)" +} \ No newline at end of file diff --git a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration-optional-chaining/output.mjs b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration-optional-chaining/output.mjs index b9c029038b14..982de805006b 100644 --- a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration-optional-chaining/output.mjs +++ b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration-optional-chaining/output.mjs @@ -4,11 +4,10 @@ class C { constructor() { var _babelHelpers$classPr; - _m.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _m, { writable: true, value: void 0 }); - const o = null; const n = this; const p = o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldGet(o, _m).call(o, ...c, 1); diff --git a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration/output.mjs b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration/output.mjs index b9c029038b14..982de805006b 100644 --- a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration/output.mjs +++ b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration/output.mjs @@ -4,11 +4,10 @@ class C { constructor() { var _babelHelpers$classPr; - _m.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _m, { writable: true, value: void 0 }); - const o = null; const n = this; const p = o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldGet(o, _m).call(o, ...c, 1); diff --git a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.test.js b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.test.js index 52f4008fcf08..c6937fcc798e 100644 --- a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.test.js +++ b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/util.test.js @@ -15,6 +15,7 @@ function getPath(input, parserOpts = {}) { ...parserOpts, }, filename: "example.js", + configFile: false, }), { "OptionalMemberExpression|OptionalCallExpression"(path) { diff --git a/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/output.js b/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/output.js index edaf639ec2f7..92c4e90b13c8 100644 --- a/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/output.js +++ b/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/output.js @@ -2,7 +2,7 @@ var _g = /*#__PURE__*/new WeakSet(); class C { constructor() { - _g.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _g); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/exec.js new file mode 100644 index 000000000000..101547f13cee --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/exec.js @@ -0,0 +1,15 @@ +class Test { + + static #x = 1 + + static method() { + const Test = 2; + const func = () => { + const Test = 3; + return this.#x + Test; + } + return func() + Test; + } +} + +expect(Test.method()).toBe(6) diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/input.js new file mode 100644 index 000000000000..5f5ffa0b2343 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/input.js @@ -0,0 +1,13 @@ +class Test { + + static #x = 1 + + static method() { + const Test = 2; + const func = () => { + const Test = 3; + return this.#x + Test; + } + return func() + Test; + } +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/options.json new file mode 100644 index 000000000000..19ed5174f545 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/output.js new file mode 100644 index 000000000000..8b03caa83f92 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/static-shadow/output.js @@ -0,0 +1,18 @@ +class Test { + static method() { + const _Test2 = 2; + + const func = () => { + const _Test = 3; + return babelHelpers.classStaticPrivateFieldSpecGet(this, Test, _x) + _Test; + }; + + return func() + _Test2; + } + +} + +var _x = { + writable: true, + value: 1 +}; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/1-helpermemberexpressionfunction/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/1-helpermemberexpressionfunction/output.js index 89ad20142e0e..ff85bfa4598f 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/1-helpermemberexpressionfunction/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/1-helpermemberexpressionfunction/output.js @@ -5,8 +5,7 @@ var D = /*#__PURE__*/function () { function D() { babelHelpers.classCallCheck(this, D); - - _arr.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _arr, { writable: true, value: void 0 }); @@ -30,8 +29,7 @@ var C = /*#__PURE__*/function () { function C() { babelHelpers.classCallCheck(this, C); - - _p.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _p, { writable: true, value: void 0 }); @@ -55,8 +53,7 @@ var E = /*#__PURE__*/function () { function E() { babelHelpers.classCallCheck(this, E); - - _arr2.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _arr2, { writable: true, value: void 0 }); @@ -80,8 +77,7 @@ var F = /*#__PURE__*/function () { function F() { babelHelpers.classCallCheck(this, F); - - _ar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _ar, { writable: true, value: void 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/assignment/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/assignment/output.js index a7817db0ff01..e0c46183b855 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/assignment/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/assignment/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/call/output.js index 27947d1df63f..2b12c7ae9bac 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/call/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/call/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: function () { return this; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/canonical/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/canonical/output.js index e41035c44796..5fc50758bc10 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/canonical/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/canonical/output.js @@ -7,17 +7,14 @@ var Point = /*#__PURE__*/function () { function Point(x = 0, y = 0) { babelHelpers.classCallCheck(this, Point); - - _x.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _x, { writable: true, value: void 0 }); - - _y.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _y, { writable: true, value: void 0 }); - babelHelpers.classPrivateFieldSet(this, _x, +x); babelHelpers.classPrivateFieldSet(this, _y, +y); } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/constructor-collision/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/constructor-collision/output.js index 05d01f4911b9..134fb98bdedf 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/constructor-collision/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/constructor-collision/output.js @@ -6,11 +6,9 @@ var Foo = function Foo() { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: foo }); - var _foo = "foo"; }; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/declaration-order/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/declaration-order/output.js index b2c777ecc3ef..f3620fbdc887 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/declaration-order/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/declaration-order/output.js @@ -5,8 +5,7 @@ var C = function C() { babelHelpers.classCallCheck(this, C); babelHelpers.defineProperty(this, "y", babelHelpers.classPrivateFieldGet(this, _x)); - - _x.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _x, { writable: true, value: void 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived-multiple-supers/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived-multiple-supers/output.js index 06197e31d481..692b0bf2c253 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived-multiple-supers/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived-multiple-supers/output.js @@ -14,15 +14,13 @@ var Foo = /*#__PURE__*/function (_Bar) { if (condition) { _this = _super.call(this); - - _bar.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _bar, { writable: true, value: "foo" }); } else { _this = _super.call(this); - - _bar.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _bar, { writable: true, value: "foo" }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived/output.js index 97251962ae41..d21589418236 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived/output.js @@ -4,8 +4,7 @@ var Foo = function Foo() { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _prop.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _prop, { writable: true, value: "foo" }); @@ -25,12 +24,10 @@ var Bar = /*#__PURE__*/function (_Foo) { babelHelpers.classCallCheck(this, Bar); _this = _super.call(this, ...args); - - _prop2.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _prop2, { writable: true, value: "bar" }); - return _this; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-1/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-1/output.js index 1b13a2e595c3..f8813d3f0212 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-1/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-1/output.js @@ -4,12 +4,10 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - babelHelpers.classPrivateFieldSet(this, _client, 1); [this.x = babelHelpers.classPrivateFieldGet(this, _client), babelHelpers.classPrivateFieldDestructureSet(this, _client).value, this.y = babelHelpers.classPrivateFieldGet(this, _client)] = props; }; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-2/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-2/output.js index 2ace67a331c0..9f88740d8363 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-2/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-2/output.js @@ -4,11 +4,9 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - [x, ...babelHelpers.classPrivateFieldDestructureSet(this, _client).value] = props; }; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-3/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-3/output.js index 6b9882ec1bc7..091bdecc0da9 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-3/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-3/output.js @@ -4,11 +4,9 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - [babelHelpers.classPrivateFieldDestructureSet(this, _client).value = 5] = props; }; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern/output.js index ffeb7c001e44..eeae89405a83 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern/output.js @@ -4,11 +4,9 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - [babelHelpers.classPrivateFieldDestructureSet(this, _client).value] = props; }; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-1/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-1/output.js index bb48cc08e11b..2522895f077e 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-1/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-1/output.js @@ -4,12 +4,10 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - babelHelpers.classPrivateFieldSet(this, _client, 'foo'); ({ x: this.x = babelHelpers.classPrivateFieldGet(this, _client), diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-2/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-2/output.js index 1ffd2fe58ffa..94f7111188c4 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-2/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-2/output.js @@ -4,12 +4,10 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - ({ x, ...babelHelpers.classPrivateFieldDestructureSet(this, _client).value diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-3/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-3/output.js index 0c4192589582..071bae2f50d7 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-3/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-3/output.js @@ -4,12 +4,10 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - ({ x: babelHelpers.classPrivateFieldDestructureSet(this, _client).value = 5 } = props); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern/output.js index 7459b76bc979..6366d6e7f5a5 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern/output.js @@ -4,12 +4,10 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - ({ client: babelHelpers.classPrivateFieldDestructureSet(this, _client).value } = props); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/extracted-this/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/extracted-this/output.js index 1fb7de2ab41d..5bbb120d1a6a 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/extracted-this/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/extracted-this/output.js @@ -8,13 +8,11 @@ var Foo = function Foo(_foo) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: this }); - - _baz.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _baz, { writable: true, value: foo }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/foobar/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/foobar/output.js index 2ae9b573b32d..496503850a30 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/foobar/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/foobar/output.js @@ -12,14 +12,12 @@ var Child = /*#__PURE__*/function (_Parent) { babelHelpers.classCallCheck(this, Child); _this = _super.call(this); - - _scopedFunctionWithThis.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _scopedFunctionWithThis, { writable: true, value: () => { _this.name = {}; } }); - return _this; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance-undefined/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance-undefined/output.js index 8c8ba57dec55..dfa75cf39d8c 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance-undefined/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance-undefined/output.js @@ -4,8 +4,7 @@ var Foo = function Foo() { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: void 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance/output.js index c7208f4d74b2..c30d93994e22 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance/output.js @@ -4,8 +4,7 @@ var Foo = function Foo() { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: "foo" }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/logical-assignment/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/logical-assignment/output.js index e61da807cef9..012356bcec0c 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/logical-assignment/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/logical-assignment/output.js @@ -6,17 +6,15 @@ var _or = /*#__PURE__*/new WeakMap(); class Foo { constructor() { - _nullish.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _nullish, { writable: true, value: 0 }); - - _and.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _and, { writable: true, value: 0 }); - - _or.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _or, { writable: true, value: 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/multiple/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/multiple/output.js index fd609d445893..de23ee50d176 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/multiple/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/multiple/output.js @@ -6,13 +6,11 @@ var Foo = function Foo() { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _x.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _x, { writable: true, value: 0 }); - - _y.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _y, { writable: true, value: babelHelpers.classPrivateFieldGet(this, _x) }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/native-classes/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/native-classes/output.js index 98f497349993..cca3df0b1e97 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/native-classes/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/native-classes/output.js @@ -2,7 +2,7 @@ var _bar = /*#__PURE__*/new WeakMap(); class Foo { constructor() { - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: "bar" }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed-redeclared/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed-redeclared/output.js index 1dd4c23b4a31..1f1a88576bf3 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed-redeclared/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed-redeclared/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); @@ -24,8 +23,7 @@ var Foo = /*#__PURE__*/function () { var Nested = /*#__PURE__*/function (_babelHelpers$classPr2) { function Nested() { babelHelpers.classCallCheck(this, Nested); - - _foo2.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo2, { writable: true, value: 2 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed/output.js index e5d21a94663d..73762088ae78 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed-redeclared/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed-redeclared/output.js index 816f80cbeb00..05370b34fc85 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed-redeclared/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed-redeclared/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); @@ -31,12 +30,10 @@ var Foo = /*#__PURE__*/function () { babelHelpers.classCallCheck(this, Nested); _this = _super.call(this, ...args); - - _foo2.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _foo2, { writable: true, value: 3 }); - return _this; } @@ -44,12 +41,10 @@ var Foo = /*#__PURE__*/function () { }((_foo3 = /*#__PURE__*/new WeakMap(), _babelHelpers$classPr = babelHelpers.classPrivateFieldGet(this, _foo3), /*#__PURE__*/function () { function _class2() { babelHelpers.classCallCheck(this, _class2); - - _foo3.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo3, { writable: true, value: 2 }); - babelHelpers.defineProperty(this, _babelHelpers$classPr, 2); } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed/output.js index dddde36ed4d4..378e354e71d6 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); @@ -29,12 +28,10 @@ var Foo = /*#__PURE__*/function () { babelHelpers.classCallCheck(this, Nested); _this = _super.call(this, ...args); - - _foo2.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _foo2, { writable: true, value: 3 }); - return _this; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-other-redeclared/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-other-redeclared/output.js index 080795751a9a..134b4cab21c9 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-other-redeclared/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-other-redeclared/output.js @@ -7,13 +7,11 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); - - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: 1 }); @@ -27,8 +25,7 @@ var Foo = /*#__PURE__*/function () { var Nested = /*#__PURE__*/function () { function Nested() { babelHelpers.classCallCheck(this, Nested); - - _bar2.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar2, { writable: true, value: 2 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-redeclared/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-redeclared/output.js index 1030037c7a75..a507af4249b1 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-redeclared/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-redeclared/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); @@ -20,8 +19,7 @@ var Foo = /*#__PURE__*/function () { var Nested = /*#__PURE__*/function () { function Nested() { babelHelpers.classCallCheck(this, Nested); - - _foo2.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo2, { writable: true, value: 2 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class/output.js index 69123eded43d..df432fc79aa7 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-spread-arguments/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-spread-arguments/output.js index 593a5772ca7b..58e1533d26df 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-spread-arguments/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-spread-arguments/output.js @@ -2,7 +2,7 @@ var _m = /*#__PURE__*/new WeakMap(); class Foo { constructor() { - _m.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _m, { writable: true, value: void 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/private-in-derived/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/private-in-derived/output.js index 1e5799660027..f2c1dbcfb016 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/private-in-derived/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/private-in-derived/output.js @@ -4,8 +4,7 @@ var Outer = function Outer() { "use strict"; babelHelpers.classCallCheck(this, Outer); - - _outer.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _outer, { writable: true, value: void 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reevaluated/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reevaluated/output.js index 8c6a9554122f..6c22c5c9bf08 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reevaluated/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reevaluated/output.js @@ -3,7 +3,7 @@ function classFactory() { return _temp = (_foo = /*#__PURE__*/new WeakMap(), _class = class Foo { constructor() { - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: "foo" }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reference-in-other-property/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reference-in-other-property/output.js index 0b7476ce49a0..6c3d52803c44 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reference-in-other-property/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reference-in-other-property/output.js @@ -9,20 +9,16 @@ var Foo = function Foo() { babelHelpers.classCallCheck(this, Foo); babelHelpers.defineProperty(this, "one", babelHelpers.classPrivateFieldGet(this, _private)); - - _two.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _two, { writable: true, value: babelHelpers.classPrivateFieldGet(this, _private) }); - - _private.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _private, { writable: true, value: 0 }); - babelHelpers.defineProperty(this, "three", babelHelpers.classPrivateFieldGet(this, _private)); - - _four.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _four, { writable: true, value: babelHelpers.classPrivateFieldGet(this, _private) }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T7364/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T7364/output.mjs index ae07dabb7896..7d23ce353bbc 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T7364/output.mjs +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T7364/output.mjs @@ -4,7 +4,7 @@ class MyClass { constructor() { var _this = this; - _myAsyncMethod.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _myAsyncMethod, { writable: true, value: function () { var _ref = babelHelpers.asyncToGenerator(function* () { @@ -26,7 +26,7 @@ var _myAsyncMethod2 = /*#__PURE__*/new WeakMap(); constructor() { var _this2 = this; - _myAsyncMethod2.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _myAsyncMethod2, { writable: true, value: function () { var _ref2 = babelHelpers.asyncToGenerator(function* () { @@ -48,7 +48,7 @@ export default class MyClass3 { constructor() { var _this3 = this; - _myAsyncMethod3.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _myAsyncMethod3, { writable: true, value: function () { var _ref3 = babelHelpers.asyncToGenerator(function* () { diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/exec.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/exec.js new file mode 100644 index 000000000000..101547f13cee --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/exec.js @@ -0,0 +1,15 @@ +class Test { + + static #x = 1 + + static method() { + const Test = 2; + const func = () => { + const Test = 3; + return this.#x + Test; + } + return func() + Test; + } +} + +expect(Test.method()).toBe(6) diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/input.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/input.js new file mode 100644 index 000000000000..5f5ffa0b2343 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/input.js @@ -0,0 +1,13 @@ +class Test { + + static #x = 1 + + static method() { + const Test = 2; + const func = () => { + const Test = 3; + return this.#x + Test; + } + return func() + Test; + } +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/options.json new file mode 100644 index 000000000000..19ed5174f545 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/output.js new file mode 100644 index 000000000000..8b03caa83f92 --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/static-shadow/output.js @@ -0,0 +1,18 @@ +class Test { + static method() { + const _Test2 = 2; + + const func = () => { + const _Test = 3; + return babelHelpers.classStaticPrivateFieldSpecGet(this, Test, _x) + _Test; + }; + + return func() + _Test2; + } + +} + +var _x = { + writable: true, + value: 1 +}; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-call/output.js index 78bcdf3764a0..c329d248e38c 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-call/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-call/output.js @@ -28,12 +28,10 @@ var B = /*#__PURE__*/function (_A) { babelHelpers.classCallCheck(this, B); _this = _super.call(this, ...args); - - _foo.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _foo, { writable: true, value: babelHelpers.get((_thisSuper = babelHelpers.assertThisInitialized(_this), babelHelpers.getPrototypeOf(B.prototype)), "foo", _thisSuper).call(_thisSuper) }); - return _this; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-expression/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-expression/output.js index 1f17e973a223..d3b2bb1e9ed1 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-expression/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-expression/output.js @@ -11,7 +11,7 @@ var Foo = /*#__PURE__*/function (_Bar) { var _temp, _this; babelHelpers.classCallCheck(this, Foo); - foo((_temp = _this = _super.call(this), _bar.set(babelHelpers.assertThisInitialized(_this), { + foo((_temp = _this = _super.call(this), babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _bar, { writable: true, value: "foo" }), _temp)); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-statement/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-statement/output.js index e652b376af27..310bfc691ca5 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-statement/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-statement/output.js @@ -12,12 +12,10 @@ var Foo = /*#__PURE__*/function (_Bar) { babelHelpers.classCallCheck(this, Foo); _this = _super.call(this); - - _bar.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _bar, { writable: true, value: "foo" }); - return _this; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js index b06497c1fcdc..530024699bfe 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _tag.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _tag, { writable: true, value: void 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/update/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/update/output.js index 59d092de2de4..cab004ed47e6 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/update/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/update/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/output.js index f41cc8189c3d..fc17c143e229 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/output.js @@ -8,8 +8,7 @@ for (let i = 0; i <= 10; ++i) { classes.push((_temp = (_bar = /*#__PURE__*/new WeakMap(), _i = i, _class = class A { constructor() { babelHelpers.defineProperty(this, _i, `computed field ${i}`); - - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: `private field ${i}` }); diff --git a/packages/babel-plugin-proposal-class-static-block/package.json b/packages/babel-plugin-proposal-class-static-block/package.json index 8b41f2cb7d61..341d6c908e69 100644 --- a/packages/babel-plugin-proposal-class-static-block/package.json +++ b/packages/babel-plugin-proposal-class-static-block/package.json @@ -21,7 +21,7 @@ "dependencies": { "@babel/helper-create-class-features-plugin": "workspace:^7.14.5", "@babel/helper-plugin-utils": "workspace:^7.14.5", - "@babel/plugin-syntax-class-static-block": "workspace:^7.14.5" + "@babel/plugin-syntax-class-static-block": "^7.14.5" }, "peerDependencies": { "@babel/core": "^7.12.0" diff --git a/packages/babel-plugin-proposal-class-static-block/src/index.js b/packages/babel-plugin-proposal-class-static-block/src/index.js index 67b2526a8ca4..5bc560fc77cb 100644 --- a/packages/babel-plugin-proposal-class-static-block/src/index.js +++ b/packages/babel-plugin-proposal-class-static-block/src/index.js @@ -29,7 +29,7 @@ export default declare(({ types: t, template, assertVersion }) => { return { name: "proposal-class-static-block", - inherits: syntaxClassStaticBlock, + inherits: syntaxClassStaticBlock.default, pre() { // Enable this in @babel/helper-create-class-features-plugin, so that it diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/basic/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/basic/output.js index 658554a063b1..4b64a3333d2f 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/basic/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/basic/output.js @@ -4,16 +4,14 @@ var _privateFieldValue = /*#__PURE__*/new WeakMap(); class Cl { constructor() { - _privateFieldValue.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateFieldValue, { get: _get_privateFieldValue, set: _set_privateFieldValue }); - - _privateField.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateField, { writable: true, value: "top secret string" }); - this.publicField = "not secret string"; } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/get-only-setter/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/get-only-setter/output.js index 2a0691beefac..6c95f5f1bbdd 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/get-only-setter/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/get-only-setter/output.js @@ -4,16 +4,14 @@ var _privateFieldValue = /*#__PURE__*/new WeakMap(); class Cl { constructor() { - _privateFieldValue.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateFieldValue, { get: void 0, set: _set_privateFieldValue }); - - _privateField.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateField, { writable: true, value: 0 }); - this.publicField = (this, babelHelpers.writeOnlyError("#privateFieldValue")); } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/reassignment/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/reassignment/output.js index 4ee6f05ac82d..3cd48da10e76 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/reassignment/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/reassignment/output.js @@ -4,11 +4,10 @@ var _privateFieldValue = /*#__PURE__*/new WeakMap(); class Foo { constructor() { - _privateFieldValue.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateFieldValue, { get: _get_privateFieldValue, set: void 0 }); - this.self, results.push(2), babelHelpers.readOnlyError("#privateFieldValue"); } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/set-only-getter/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/set-only-getter/output.js index 52a97f6ec2bd..99848e09ac72 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/set-only-getter/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/set-only-getter/output.js @@ -9,16 +9,14 @@ class Cl { } constructor() { - _privateFieldValue.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateFieldValue, { get: _get_privateFieldValue, set: void 0 }); - - _privateField.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateField, { writable: true, value: 0 }); - babelHelpers.defineProperty(this, "counter", 0); this.self, 1([babelHelpers.classPrivateFieldDestructureSet(this.self, _privateFieldValue).value] = [1]), babelHelpers.readOnlyError("#privateFieldValue"); } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js index 90a909b22bbe..c8b534f929cf 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js @@ -2,11 +2,10 @@ var _tag = /*#__PURE__*/new WeakMap(); class Foo { constructor() { - _tag.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _tag, { get: _get_tag, set: void 0 }); - babelHelpers.classPrivateFieldGet(this, _tag).bind(this)``; } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/updates/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/updates/output.js index 0da9a9fc0775..a3e609e11f35 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/updates/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/updates/output.js @@ -4,16 +4,14 @@ var _privateFieldValue = /*#__PURE__*/new WeakMap(); class Cl { constructor() { - _privateFieldValue.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateFieldValue, { get: _get_privateFieldValue, set: _set_privateFieldValue }); - - _privateField.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateField, { writable: true, value: "top secret string" }); - this.publicField = "not secret string"; } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/assumption-constantSuper/private-method-super/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/assumption-constantSuper/private-method-super/output.js index 74762cfc049b..b0c6dcfb4a85 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/assumption-constantSuper/private-method-super/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/assumption-constantSuper/private-method-super/output.js @@ -10,8 +10,7 @@ var _privateMethod = /*#__PURE__*/new WeakSet(); class Sub extends Base { constructor(...args) { super(...args); - - _privateMethod.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _privateMethod); } superMethod() { diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-set/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-set/output.js index 995151f76286..e4e64c0f3494 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-set/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-set/output.js @@ -4,12 +4,11 @@ var _getSet = /*#__PURE__*/new WeakMap(); class Cl { constructor() { - _getSet.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _getSet, { get: _get_getSet, set: _set_getSet }); - - _privateField.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateField, { writable: true, value: 0 }); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-get/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-get/output.js index 3c26592e7614..10379c8a3700 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-get/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-get/output.js @@ -4,12 +4,11 @@ var _getSet = /*#__PURE__*/new WeakMap(); class Cl { constructor() { - _getSet.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _getSet, { get: _get_getSet, set: _set_getSet }); - - _privateField.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateField, { writable: true, value: 0 }); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/assignment/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/assignment/output.js index 0c4c7958abdc..368062ce9a74 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/assignment/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/assignment/output.js @@ -2,8 +2,7 @@ var _privateMethod = /*#__PURE__*/new WeakSet(); class Foo { constructor() { - _privateMethod.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _privateMethod); this.publicField = babelHelpers.classPrivateMethodGet(this, _privateMethod, _privateMethod2).call(this); } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/async/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/async/output.js index 256f7fe629c0..13ee286f7c87 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/async/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/async/output.js @@ -2,7 +2,7 @@ var _foo = /*#__PURE__*/new WeakSet(); class Cl { constructor() { - _foo.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _foo); } test() { diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/before-fields/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/before-fields/output.js index 447aba2a5082..fe5a04321881 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/before-fields/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/before-fields/output.js @@ -4,11 +4,9 @@ var _method = /*#__PURE__*/new WeakSet(); class Cl { constructor() { - _method.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _method); babelHelpers.defineProperty(this, "prop", babelHelpers.classPrivateMethodGet(this, _method, _method2).call(this, 1)); - - _priv.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _priv, { writable: true, value: babelHelpers.classPrivateMethodGet(this, _method, _method2).call(this, 2) }); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/class-expression/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/class-expression/output.js index f0c034edfe8c..b177284a7867 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/class-expression/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/class-expression/output.js @@ -2,7 +2,7 @@ var _foo; console.log((_foo = /*#__PURE__*/new WeakSet(), class A { constructor() { - _foo.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _foo); } method() { diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/context/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/context/output.js index 0be6a465b0b9..9d96c81401a5 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/context/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/context/output.js @@ -2,8 +2,7 @@ var _getStatus = /*#__PURE__*/new WeakSet(); class Foo { constructor(status) { - _getStatus.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _getStatus); this.status = status; } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/exfiltrated/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/exfiltrated/output.js index 88d1606b8f96..cac29e2bd16f 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/exfiltrated/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/exfiltrated/output.js @@ -4,7 +4,7 @@ var _privateMethod = /*#__PURE__*/new WeakSet(); class Foo { constructor() { - _privateMethod.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _privateMethod); if (exfiltrated === undefined) { exfiltrated = babelHelpers.classPrivateMethodGet(this, _privateMethod, _privateMethod2); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/generator/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/generator/output.js index 2d3984fd5d5a..565cde34ac84 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/generator/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/generator/output.js @@ -2,7 +2,7 @@ var _foo = /*#__PURE__*/new WeakSet(); class Cl { constructor() { - _foo.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _foo); } test() { diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/read-only/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/read-only/output.js index 9b9b5db27968..cf55c305310b 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/read-only/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/read-only/output.js @@ -7,8 +7,7 @@ class A { } constructor() { - _method.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _method); babelHelpers.defineProperty(this, "counter", 0); this.self(), 2, babelHelpers.readOnlyError("#method"); [babelHelpers.classPrivateFieldDestructureSet(this, _method).value] = [2]; diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/reassignment/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/reassignment/output.js index d06ddb53ec2b..6fc9d8e6bc40 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/reassignment/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/reassignment/output.js @@ -4,8 +4,7 @@ var _privateFieldValue = /*#__PURE__*/new WeakSet(); class Foo { constructor() { - _privateFieldValue.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _privateFieldValue); this.self, results.push(2), babelHelpers.readOnlyError("#privateFieldValue"); } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/super/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/super/output.js index 475654149f6a..25ba5547ffb6 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/super/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/super/output.js @@ -10,8 +10,7 @@ var _privateMethod = /*#__PURE__*/new WeakSet(); class Sub extends Base { constructor(...args) { super(...args); - - _privateMethod.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _privateMethod); } superMethod() { diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js index 21029095ae9a..fb9580a3f92b 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js @@ -2,7 +2,7 @@ var _tag = /*#__PURE__*/new WeakSet(); class Foo { constructor() { - _tag.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _tag); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/package.json b/packages/babel-plugin-proposal-private-property-in-object/package.json index 499c6fc3da1e..50a538a3682b 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/package.json +++ b/packages/babel-plugin-proposal-private-property-in-object/package.json @@ -20,7 +20,7 @@ "@babel/helper-annotate-as-pure": "workspace:^7.14.5", "@babel/helper-create-class-features-plugin": "workspace:^7.14.5", "@babel/helper-plugin-utils": "workspace:^7.14.5", - "@babel/plugin-syntax-private-property-in-object": "workspace:^7.14.5" + "@babel/plugin-syntax-private-property-in-object": "^7.14.5" }, "peerDependencies": { "@babel/core": "^7.0.0-0" diff --git a/packages/babel-plugin-proposal-private-property-in-object/src/index.js b/packages/babel-plugin-proposal-private-property-in-object/src/index.js index 9d7d31a2942b..094e054c669c 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/src/index.js +++ b/packages/babel-plugin-proposal-private-property-in-object/src/index.js @@ -84,7 +84,7 @@ export default declare(({ assertVersion, types: t, template }, { loose }) => { return { name: "proposal-private-property-in-object", - inherits: syntaxPlugin, + inherits: syntaxPlugin.default, pre() { // Enable this in @babel/helper-create-class-features-plugin, so that it // can be handled by the private fields and methods transform. diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/native-classes/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/native-classes/output.js index 13ebbe421023..51e66218a8ab 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/native-classes/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/native-classes/output.js @@ -2,7 +2,7 @@ var _bar = /*#__PURE__*/new WeakMap(); class Foo { constructor() { - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: "bar" }); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/exec.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/exec.js new file mode 100644 index 000000000000..673b1cced3af --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/exec.js @@ -0,0 +1,17 @@ +class Test { + + static #x = 1 + + method(other) { + const Test = 2; + const func = () => { + const Test = 3; + return #x in other && Test; + } + return func() + Test; + } +} + +const t = new Test(); +const t2 = new Test(); +expect(t.method(Test)).toBe(5) diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/input.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/input.js new file mode 100644 index 000000000000..faa4ce3d104a --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/input.js @@ -0,0 +1,13 @@ +class Test { + + static #x = 1 + + method(other) { + const Test = 2; + const func = () => { + const Test = 3; + return #x in other && Test; + } + return func() + Test; + } +} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/options.json b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/options.json new file mode 100644 index 000000000000..19ed5174f545 --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/output.js new file mode 100644 index 000000000000..898d6a8ddcfb --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/output.js @@ -0,0 +1,18 @@ +class Test { + method(other) { + const _Test2 = 2; + + const func = () => { + const _Test = 3; + return other === Test && _Test; + }; + + return func() + _Test2; + } + +} + +var _x = { + writable: true, + value: 1 +}; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/accessor/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/accessor/output.js index 75a7587782a9..a5a7d2bc3703 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/accessor/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/accessor/output.js @@ -5,8 +5,7 @@ let Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { get: _get_foo, set: void 0 }); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/field/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/field/output.js index c83e48bcd86d..b5206a1f38e3 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/field/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/field/output.js @@ -5,8 +5,7 @@ let Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/method/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/method/output.js index ac675cbf7d85..32edd0cc6acf 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/method/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/method/output.js @@ -5,8 +5,7 @@ let Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _foo); } babelHelpers.createClass(Foo, [{ diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/native-classes/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/native-classes/output.js index 13ebbe421023..51e66218a8ab 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/native-classes/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/native-classes/output.js @@ -2,7 +2,7 @@ var _bar = /*#__PURE__*/new WeakMap(); class Foo { constructor() { - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: "bar" }); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-other-redeclared/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-other-redeclared/output.js index a54b7a6691f1..82f59fa0b443 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-other-redeclared/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-other-redeclared/output.js @@ -7,13 +7,11 @@ let Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); - - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: 1 }); @@ -27,8 +25,7 @@ let Foo = /*#__PURE__*/function () { let Nested = /*#__PURE__*/function () { function Nested() { babelHelpers.classCallCheck(this, Nested); - - _bar2.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar2, { writable: true, value: 2 }); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-redeclared/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-redeclared/output.js index 20a7183234aa..b9c7cf225570 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-redeclared/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-redeclared/output.js @@ -5,8 +5,7 @@ let Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); @@ -20,8 +19,7 @@ let Foo = /*#__PURE__*/function () { let Nested = /*#__PURE__*/function () { function Nested() { babelHelpers.classCallCheck(this, Nested); - - _foo2.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo2, { writable: true, value: 2 }); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class/output.js index 2c52c716a1ee..57550078e7fc 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class/output.js @@ -5,8 +5,7 @@ let Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/exec.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/exec.js new file mode 100644 index 000000000000..673b1cced3af --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/exec.js @@ -0,0 +1,17 @@ +class Test { + + static #x = 1 + + method(other) { + const Test = 2; + const func = () => { + const Test = 3; + return #x in other && Test; + } + return func() + Test; + } +} + +const t = new Test(); +const t2 = new Test(); +expect(t.method(Test)).toBe(5) diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/input.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/input.js new file mode 100644 index 000000000000..faa4ce3d104a --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/input.js @@ -0,0 +1,13 @@ +class Test { + + static #x = 1 + + method(other) { + const Test = 2; + const func = () => { + const Test = 3; + return #x in other && Test; + } + return func() + Test; + } +} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/options.json b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/options.json new file mode 100644 index 000000000000..19ed5174f545 --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/output.js new file mode 100644 index 000000000000..898d6a8ddcfb --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/output.js @@ -0,0 +1,18 @@ +class Test { + method(other) { + const _Test2 = 2; + + const func = () => { + const _Test = 3; + return other === Test && _Test; + }; + + return func() + _Test2; + } + +} + +var _x = { + writable: true, + value: 1 +}; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/exec.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/exec.js new file mode 100644 index 000000000000..673b1cced3af --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/exec.js @@ -0,0 +1,17 @@ +class Test { + + static #x = 1 + + method(other) { + const Test = 2; + const func = () => { + const Test = 3; + return #x in other && Test; + } + return func() + Test; + } +} + +const t = new Test(); +const t2 = new Test(); +expect(t.method(Test)).toBe(5) diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/input.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/input.js new file mode 100644 index 000000000000..faa4ce3d104a --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/input.js @@ -0,0 +1,13 @@ +class Test { + + static #x = 1 + + method(other) { + const Test = 2; + const func = () => { + const Test = 3; + return #x in other && Test; + } + return func() + Test; + } +} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/options.json b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/options.json new file mode 100644 index 000000000000..19ed5174f545 --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["proposal-class-properties"] +} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/output.js new file mode 100644 index 000000000000..898d6a8ddcfb --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/output.js @@ -0,0 +1,18 @@ +class Test { + method(other) { + const _Test2 = 2; + + const func = () => { + const _Test = 3; + return other === Test && _Test; + }; + + return func() + _Test2; + } + +} + +var _x = { + writable: true, + value: 1 +}; diff --git a/packages/babel-plugin-syntax-class-static-block/.npmignore b/packages/babel-plugin-syntax-class-static-block/.npmignore deleted file mode 100644 index f9806945836e..000000000000 --- a/packages/babel-plugin-syntax-class-static-block/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -src -test -*.log diff --git a/packages/babel-plugin-syntax-class-static-block/README.md b/packages/babel-plugin-syntax-class-static-block/README.md deleted file mode 100644 index 8dd2f6b32cb2..000000000000 --- a/packages/babel-plugin-syntax-class-static-block/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# @babel/plugin-syntax-class-static-block - -> Allow parsing of class static blocks - -See our website [@babel/plugin-syntax-class-static-block](https://babeljs.io/docs/en/babel-plugin-syntax-class-static-block) for more information. - -## Install - -Using npm: - -```sh -npm install --save-dev @babel/plugin-syntax-class-static-block -``` - -or using yarn: - -```sh -yarn add @babel/plugin-syntax-class-static-block --dev -``` diff --git a/packages/babel-plugin-syntax-class-static-block/package.json b/packages/babel-plugin-syntax-class-static-block/package.json deleted file mode 100644 index c544de2f0aa3..000000000000 --- a/packages/babel-plugin-syntax-class-static-block/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "@babel/plugin-syntax-class-static-block", - "version": "7.14.5", - "description": "Allow parsing of class static blocks", - "repository": { - "type": "git", - "url": "https://github.com/babel/babel.git", - "directory": "packages/babel-plugin-syntax-class-static-block" - }, - "homepage": "https://babel.dev/docs/en/next/babel-plugin-syntax-class-static-block", - "license": "MIT", - "publishConfig": { - "access": "public" - }, - "main": "./lib/index.js", - "exports": { - ".": "./lib/index.js" - }, - "keywords": [ - "babel-plugin" - ], - "dependencies": { - "@babel/helper-plugin-utils": "workspace:^7.14.5" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - }, - "engines": { - "node": ">=6.9.0" - }, - "author": "The Babel Team (https://babel.dev/team)" -} diff --git a/packages/babel-plugin-syntax-class-static-block/src/index.js b/packages/babel-plugin-syntax-class-static-block/src/index.js deleted file mode 100644 index 716fb853b288..000000000000 --- a/packages/babel-plugin-syntax-class-static-block/src/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import { declare } from "@babel/helper-plugin-utils"; - -export default declare(api => { - api.assertVersion(7); - - return { - name: "syntax-class-static-block", - - manipulateOptions(opts, parserOpts) { - parserOpts.plugins.push("classStaticBlock"); - }, - }; -}); diff --git a/packages/babel-plugin-syntax-private-property-in-object/.npmignore b/packages/babel-plugin-syntax-private-property-in-object/.npmignore deleted file mode 100644 index f9806945836e..000000000000 --- a/packages/babel-plugin-syntax-private-property-in-object/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -src -test -*.log diff --git a/packages/babel-plugin-syntax-private-property-in-object/README.md b/packages/babel-plugin-syntax-private-property-in-object/README.md deleted file mode 100644 index 7869bc42241c..000000000000 --- a/packages/babel-plugin-syntax-private-property-in-object/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# @babel/plugin-syntax-private-property-in-object - -> Allow parsing of '#foo in obj' brand checks - -See our website [@babel/plugin-syntax-private-property-in-object](https://babeljs.io/docs/en/babel-plugin-syntax-private-property-in-object) for more information. - -## Install - -Using npm: - -```sh -npm install --save-dev @babel/plugin-syntax-private-property-in-object -``` - -or using yarn: - -```sh -yarn add @babel/plugin-syntax-private-property-in-object --dev -``` diff --git a/packages/babel-plugin-syntax-private-property-in-object/package.json b/packages/babel-plugin-syntax-private-property-in-object/package.json deleted file mode 100644 index 8e66d3489700..000000000000 --- a/packages/babel-plugin-syntax-private-property-in-object/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "@babel/plugin-syntax-private-property-in-object", - "version": "7.14.5", - "description": "Allow parsing of '#foo in obj' brand checks", - "repository": { - "type": "git", - "url": "https://github.com/babel/babel.git", - "directory": "packages/babel-plugin-syntax-private-property-in-object" - }, - "homepage": "https://babel.dev/docs/en/next/babel-plugin-syntax-private-property-in-object", - "license": "MIT", - "publishConfig": { - "access": "public" - }, - "main": "./lib/index.js", - "exports": { - ".": "./lib/index.js" - }, - "keywords": [ - "babel-plugin" - ], - "dependencies": { - "@babel/helper-plugin-utils": "workspace:^7.14.5" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - }, - "engines": { - "node": ">=6.9.0" - }, - "author": "The Babel Team (https://babel.dev/team)" -} diff --git a/packages/babel-plugin-syntax-private-property-in-object/src/index.js b/packages/babel-plugin-syntax-private-property-in-object/src/index.js deleted file mode 100644 index a716fe39e301..000000000000 --- a/packages/babel-plugin-syntax-private-property-in-object/src/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import { declare } from "@babel/helper-plugin-utils"; - -export default declare(api => { - api.assertVersion(7); - - return { - name: "syntax-private-property-in-object", - - manipulateOptions(opts, parserOpts) { - parserOpts.plugins.push("privateIn"); - }, - }; -}); diff --git a/packages/babel-plugin-syntax-top-level-await/.npmignore b/packages/babel-plugin-syntax-top-level-await/.npmignore deleted file mode 100644 index cace0d6ddcdd..000000000000 --- a/packages/babel-plugin-syntax-top-level-await/.npmignore +++ /dev/null @@ -1,3 +0,0 @@ -node_modules -*.log -src diff --git a/packages/babel-plugin-syntax-top-level-await/README.md b/packages/babel-plugin-syntax-top-level-await/README.md deleted file mode 100644 index 040c3029e888..000000000000 --- a/packages/babel-plugin-syntax-top-level-await/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# @babel/plugin-syntax-top-level-await - -> Allow parsing of top-level await in modules - -See our website [@babel/plugin-syntax-top-level-await](https://babeljs.io/docs/en/babel-plugin-syntax-top-level-await) for more information. - -## Install - -Using npm: - -```sh -npm install --save-dev @babel/plugin-syntax-top-level-await -``` - -or using yarn: - -```sh -yarn add @babel/plugin-syntax-top-level-await --dev -``` diff --git a/packages/babel-plugin-syntax-top-level-await/package.json b/packages/babel-plugin-syntax-top-level-await/package.json deleted file mode 100644 index beb95986edb8..000000000000 --- a/packages/babel-plugin-syntax-top-level-await/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "@babel/plugin-syntax-top-level-await", - "version": "7.14.5", - "description": "Allow parsing of top-level await in modules", - "repository": { - "type": "git", - "url": "https://github.com/babel/babel.git", - "directory": "packages/babel-plugin-syntax-top-level-await" - }, - "homepage": "https://babel.dev/docs/en/next/babel-plugin-syntax-top-level-await", - "license": "MIT", - "publishConfig": { - "access": "public" - }, - "main": "./lib/index.js", - "keywords": [ - "babel-plugin" - ], - "dependencies": { - "@babel/helper-plugin-utils": "workspace:^7.14.5" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - }, - "devDependencies": { - "@babel/core": "workspace:*" - }, - "engines": { - "node": ">=6.9.0" - }, - "author": "The Babel Team (https://babel.dev/team)" -} diff --git a/packages/babel-plugin-syntax-top-level-await/src/index.js b/packages/babel-plugin-syntax-top-level-await/src/index.js deleted file mode 100644 index 2429b8ead657..000000000000 --- a/packages/babel-plugin-syntax-top-level-await/src/index.js +++ /dev/null @@ -1,13 +0,0 @@ -import { declare } from "@babel/helper-plugin-utils"; - -export default declare(api => { - api.assertVersion(7); - - return { - name: "syntax-top-level-await", - - manipulateOptions(opts, parserOpts) { - parserOpts.plugins.push("topLevelAwait"); - }, - }; -}); diff --git a/packages/babel-plugin-transform-modules-commonjs/package.json b/packages/babel-plugin-transform-modules-commonjs/package.json index ba70e8f99730..fc424ad7bbcc 100644 --- a/packages/babel-plugin-transform-modules-commonjs/package.json +++ b/packages/babel-plugin-transform-modules-commonjs/package.json @@ -28,6 +28,7 @@ "@babel/core": "workspace:*", "@babel/helper-plugin-test-runner": "workspace:*", "@babel/plugin-external-helpers": "workspace:*", + "@babel/plugin-syntax-class-static-block": "^7.14.5", "@babel/plugin-syntax-object-rest-spread": "^7.8.3" }, "homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-modules-commonjs", diff --git a/packages/babel-plugin-transform-modules-commonjs/test/fixtures/misc/class-static-block/options.json b/packages/babel-plugin-transform-modules-commonjs/test/fixtures/misc/class-static-block/options.json index b14a64139e69..02226bec484a 100644 --- a/packages/babel-plugin-transform-modules-commonjs/test/fixtures/misc/class-static-block/options.json +++ b/packages/babel-plugin-transform-modules-commonjs/test/fixtures/misc/class-static-block/options.json @@ -1,3 +1,6 @@ { - "plugins": ["transform-modules-commonjs", "syntax-class-static-block"] + "plugins": [ + "transform-modules-commonjs", + "@babel/plugin-syntax-class-static-block" + ] } diff --git a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/options.json b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/options.json index 650b247545bf..38f13007daf6 100644 --- a/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/options.json +++ b/packages/babel-plugin-transform-modules-systemjs/test/fixtures/tla/options.json @@ -1,3 +1,3 @@ { - "plugins": ["transform-modules-systemjs", "syntax-top-level-await"] + "plugins": ["transform-modules-systemjs"] } diff --git a/packages/babel-plugin-transform-typescript/src/namespace.ts b/packages/babel-plugin-transform-typescript/src/namespace.ts index 2a24f156deac..186da7c3c77c 100644 --- a/packages/babel-plugin-transform-typescript/src/namespace.ts +++ b/packages/babel-plugin-transform-typescript/src/namespace.ts @@ -1,4 +1,5 @@ import { template, types as t } from "@babel/core"; +import type { NodePath } from "@babel/traverse"; export default function transpileNamespace(path, t, allowNamespaces) { if (path.node.declare || path.node.id.type === "StringLiteral") { @@ -102,11 +103,34 @@ function handleVariableDeclaration( return [node, t.expressionStatement(t.sequenceExpression(assignments))]; } -function handleNested(path, t, node, parentExport?) { +function buildNestedAmbiendModuleError(path: NodePath, node: t.Node) { + throw path.hub.buildError( + node, + "Ambient modules cannot be nested in other modules or namespaces.", + Error, + ); +} + +function handleNested( + path: NodePath, + t: typeof import("@babel/types"), + node: t.TSModuleDeclaration, + parentExport?, +) { const names = new Set(); const realName = node.id; + t.assertIdentifier(realName); + const name = path.scope.generateUid(realName.name); - const namespaceTopLevel = node.body.body; + + const namespaceTopLevel: t.Statement[] = t.isTSModuleBlock(node.body) + ? node.body.body + : // We handle `namespace X.Y {}` as if it was + // namespace X { + // export namespace Y {} + // } + [t.exportNamedDeclaration(node.body)]; + for (let i = 0; i < namespaceTopLevel.length; i++) { const subNode = namespaceTopLevel[i]; @@ -114,6 +138,10 @@ function handleNested(path, t, node, parentExport?) { // declarations require further transformation. switch (subNode.type) { case "TSModuleDeclaration": { + if (!t.isIdentifier(subNode.id)) { + throw buildNestedAmbiendModuleError(path, subNode); + } + const transformed = handleNested(path, t, subNode); const moduleName = subNode.id.name; if (names.has(moduleName)) { @@ -181,6 +209,10 @@ function handleNested(path, t, node, parentExport?) { break; } case "TSModuleDeclaration": { + if (!t.isIdentifier(subNode.declaration.id)) { + throw buildNestedAmbiendModuleError(path, subNode.declaration); + } + const transformed = handleNested( path, t, @@ -204,7 +236,7 @@ function handleNested(path, t, node, parentExport?) { } // {} - let fallthroughValue = t.objectExpression([]); + let fallthroughValue: t.Expression = t.objectExpression([]); if (parentExport) { const memberExpr = t.memberExpression(parentExport, realName); diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/namespace/ambient-module-nested-exported/input.ts b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/ambient-module-nested-exported/input.ts new file mode 100644 index 000000000000..58db7e4f66d9 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/ambient-module-nested-exported/input.ts @@ -0,0 +1,3 @@ +namespace X { + export module "m" {} +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/namespace/ambient-module-nested-exported/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/ambient-module-nested-exported/options.json new file mode 100644 index 000000000000..653571301113 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/ambient-module-nested-exported/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Ambient modules cannot be nested in other modules or namespaces." +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/namespace/ambient-module-nested/input.ts b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/ambient-module-nested/input.ts new file mode 100644 index 000000000000..35d3d38cb1f6 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/ambient-module-nested/input.ts @@ -0,0 +1,3 @@ +namespace X { + module "m" {} +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/namespace/ambient-module-nested/options.json b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/ambient-module-nested/options.json new file mode 100644 index 000000000000..653571301113 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/ambient-module-nested/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Ambient modules cannot be nested in other modules or namespaces." +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/namespace/nested-shorthand/input.ts b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/nested-shorthand/input.ts new file mode 100644 index 000000000000..8a39ba3d5e72 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/nested-shorthand/input.ts @@ -0,0 +1,7 @@ +namespace X.Y { + export const Z = 1; +} + +namespace proj.data.util.api { + export const X = 1; +} diff --git a/packages/babel-plugin-transform-typescript/test/fixtures/namespace/nested-shorthand/output.mjs b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/nested-shorthand/output.mjs new file mode 100644 index 000000000000..8c99a195f160 --- /dev/null +++ b/packages/babel-plugin-transform-typescript/test/fixtures/namespace/nested-shorthand/output.mjs @@ -0,0 +1,27 @@ +let X; + +(function (_X) { + let Y; + + (function (_Y) { + const Z = _Y.Z = 1; + })(Y || (Y = _X.Y || (_X.Y = {}))); +})(X || (X = {})); + +let proj; + +(function (_proj) { + let data; + + (function (_data) { + let util; + + (function (_util) { + let api; + + (function (_api) { + const X = _api.X = 1; + })(api || (api = _util.api || (_util.api = {}))); + })(util || (util = _data.util || (_data.util = {}))); + })(data || (data = _proj.data || (_proj.data = {}))); +})(proj || (proj = {})); diff --git a/packages/babel-preset-env/package.json b/packages/babel-preset-env/package.json index ca7d5023c09e..bf7ad77907bb 100644 --- a/packages/babel-preset-env/package.json +++ b/packages/babel-preset-env/package.json @@ -38,7 +38,7 @@ "@babel/plugin-proposal-unicode-property-regex": "workspace:^7.14.5", "@babel/plugin-syntax-async-generators": "^7.8.4", "@babel/plugin-syntax-class-properties": "^7.12.13", - "@babel/plugin-syntax-class-static-block": "workspace:^7.14.5", + "@babel/plugin-syntax-class-static-block": "^7.14.5", "@babel/plugin-syntax-dynamic-import": "^7.8.3", "@babel/plugin-syntax-export-namespace-from": "^7.8.3", "@babel/plugin-syntax-json-strings": "^7.8.3", @@ -48,8 +48,8 @@ "@babel/plugin-syntax-object-rest-spread": "^7.8.3", "@babel/plugin-syntax-optional-catch-binding": "^7.8.3", "@babel/plugin-syntax-optional-chaining": "^7.8.3", - "@babel/plugin-syntax-private-property-in-object": "workspace:^7.14.5", - "@babel/plugin-syntax-top-level-await": "workspace:^7.14.5", + "@babel/plugin-syntax-private-property-in-object": "^7.14.5", + "@babel/plugin-syntax-top-level-await": "^7.14.5", "@babel/plugin-transform-arrow-functions": "workspace:^7.14.5", "@babel/plugin-transform-async-to-generator": "workspace:^7.14.5", "@babel/plugin-transform-block-scoped-functions": "workspace:^7.14.5", diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/preset-not-loose-no-plugins/output.js b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/preset-not-loose-no-plugins/output.js index f3de7b04fc78..e411740434d3 100644 --- a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/preset-not-loose-no-plugins/output.js +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/preset-not-loose-no-plugins/output.js @@ -2,8 +2,7 @@ var _foo = /*#__PURE__*/new WeakSet(); class A { constructor() { - _foo.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _foo); babelHelpers.defineProperty(this, "x", 2); } diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-not-loose-preset-loose/output.js b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-not-loose-preset-loose/output.js index f3de7b04fc78..e411740434d3 100644 --- a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-not-loose-preset-loose/output.js +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-not-loose-preset-loose/output.js @@ -2,8 +2,7 @@ var _foo = /*#__PURE__*/new WeakSet(); class A { constructor() { - _foo.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _foo); babelHelpers.defineProperty(this, "x", 2); } diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/output.js b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/output.js index f3de7b04fc78..e411740434d3 100644 --- a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/output.js +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/output.js @@ -2,8 +2,7 @@ var _foo = /*#__PURE__*/new WeakSet(); class A { constructor() { - _foo.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _foo); babelHelpers.defineProperty(this, "x", 2); } diff --git a/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-firefox-70/output.js b/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-firefox-70/output.js index 458142957dda..1cb775441ef3 100644 --- a/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-firefox-70/output.js +++ b/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-firefox-70/output.js @@ -2,7 +2,7 @@ var _foo = /*#__PURE__*/new WeakMap(); class A { constructor() { - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: void 0 }); diff --git a/packages/babel-runtime-corejs2/package.json b/packages/babel-runtime-corejs2/package.json index 0c9b04e96991..819ab3378ce5 100644 --- a/packages/babel-runtime-corejs2/package.json +++ b/packages/babel-runtime-corejs2/package.json @@ -801,6 +801,33 @@ "./helpers/classPrivateMethodGet.js" ], "./helpers/esm/classPrivateMethodGet": "./helpers/esm/classPrivateMethodGet.js", + "./helpers/checkPrivateRedeclaration": [ + { + "node": "./helpers/checkPrivateRedeclaration.js", + "import": "./helpers/esm/checkPrivateRedeclaration.js", + "default": "./helpers/checkPrivateRedeclaration.js" + }, + "./helpers/checkPrivateRedeclaration.js" + ], + "./helpers/esm/checkPrivateRedeclaration": "./helpers/esm/checkPrivateRedeclaration.js", + "./helpers/classPrivateFieldInitSpec": [ + { + "node": "./helpers/classPrivateFieldInitSpec.js", + "import": "./helpers/esm/classPrivateFieldInitSpec.js", + "default": "./helpers/classPrivateFieldInitSpec.js" + }, + "./helpers/classPrivateFieldInitSpec.js" + ], + "./helpers/esm/classPrivateFieldInitSpec": "./helpers/esm/classPrivateFieldInitSpec.js", + "./helpers/classPrivateMethodInitSpec": [ + { + "node": "./helpers/classPrivateMethodInitSpec.js", + "import": "./helpers/esm/classPrivateMethodInitSpec.js", + "default": "./helpers/classPrivateMethodInitSpec.js" + }, + "./helpers/classPrivateMethodInitSpec.js" + ], + "./helpers/esm/classPrivateMethodInitSpec": "./helpers/esm/classPrivateMethodInitSpec.js", "./helpers/classPrivateMethodSet": [ { "node": "./helpers/classPrivateMethodSet.js", diff --git a/packages/babel-runtime-corejs3/package.json b/packages/babel-runtime-corejs3/package.json index d0690a623eb2..8b4529b9c5a5 100644 --- a/packages/babel-runtime-corejs3/package.json +++ b/packages/babel-runtime-corejs3/package.json @@ -800,6 +800,33 @@ "./helpers/classPrivateMethodGet.js" ], "./helpers/esm/classPrivateMethodGet": "./helpers/esm/classPrivateMethodGet.js", + "./helpers/checkPrivateRedeclaration": [ + { + "node": "./helpers/checkPrivateRedeclaration.js", + "import": "./helpers/esm/checkPrivateRedeclaration.js", + "default": "./helpers/checkPrivateRedeclaration.js" + }, + "./helpers/checkPrivateRedeclaration.js" + ], + "./helpers/esm/checkPrivateRedeclaration": "./helpers/esm/checkPrivateRedeclaration.js", + "./helpers/classPrivateFieldInitSpec": [ + { + "node": "./helpers/classPrivateFieldInitSpec.js", + "import": "./helpers/esm/classPrivateFieldInitSpec.js", + "default": "./helpers/classPrivateFieldInitSpec.js" + }, + "./helpers/classPrivateFieldInitSpec.js" + ], + "./helpers/esm/classPrivateFieldInitSpec": "./helpers/esm/classPrivateFieldInitSpec.js", + "./helpers/classPrivateMethodInitSpec": [ + { + "node": "./helpers/classPrivateMethodInitSpec.js", + "import": "./helpers/esm/classPrivateMethodInitSpec.js", + "default": "./helpers/classPrivateMethodInitSpec.js" + }, + "./helpers/classPrivateMethodInitSpec.js" + ], + "./helpers/esm/classPrivateMethodInitSpec": "./helpers/esm/classPrivateMethodInitSpec.js", "./helpers/classPrivateMethodSet": [ { "node": "./helpers/classPrivateMethodSet.js", diff --git a/packages/babel-runtime/package.json b/packages/babel-runtime/package.json index c939ed29be80..759a72f5b9ed 100644 --- a/packages/babel-runtime/package.json +++ b/packages/babel-runtime/package.json @@ -800,6 +800,33 @@ "./helpers/classPrivateMethodGet.js" ], "./helpers/esm/classPrivateMethodGet": "./helpers/esm/classPrivateMethodGet.js", + "./helpers/checkPrivateRedeclaration": [ + { + "node": "./helpers/checkPrivateRedeclaration.js", + "import": "./helpers/esm/checkPrivateRedeclaration.js", + "default": "./helpers/checkPrivateRedeclaration.js" + }, + "./helpers/checkPrivateRedeclaration.js" + ], + "./helpers/esm/checkPrivateRedeclaration": "./helpers/esm/checkPrivateRedeclaration.js", + "./helpers/classPrivateFieldInitSpec": [ + { + "node": "./helpers/classPrivateFieldInitSpec.js", + "import": "./helpers/esm/classPrivateFieldInitSpec.js", + "default": "./helpers/classPrivateFieldInitSpec.js" + }, + "./helpers/classPrivateFieldInitSpec.js" + ], + "./helpers/esm/classPrivateFieldInitSpec": "./helpers/esm/classPrivateFieldInitSpec.js", + "./helpers/classPrivateMethodInitSpec": [ + { + "node": "./helpers/classPrivateMethodInitSpec.js", + "import": "./helpers/esm/classPrivateMethodInitSpec.js", + "default": "./helpers/classPrivateMethodInitSpec.js" + }, + "./helpers/classPrivateMethodInitSpec.js" + ], + "./helpers/esm/classPrivateMethodInitSpec": "./helpers/esm/classPrivateMethodInitSpec.js", "./helpers/classPrivateMethodSet": [ { "node": "./helpers/classPrivateMethodSet.js", diff --git a/packages/babel-standalone/package.json b/packages/babel-standalone/package.json index 109371265c4b..662d6d5f968a 100644 --- a/packages/babel-standalone/package.json +++ b/packages/babel-standalone/package.json @@ -34,7 +34,7 @@ "@babel/plugin-proposal-unicode-property-regex": "workspace:*", "@babel/plugin-syntax-async-generators": "^7.8.4", "@babel/plugin-syntax-class-properties": "^7.12.13", - "@babel/plugin-syntax-class-static-block": "workspace:*", + "@babel/plugin-syntax-class-static-block": "^7.14.5", "@babel/plugin-syntax-decimal": "workspace:*", "@babel/plugin-syntax-decorators": "workspace:*", "@babel/plugin-syntax-do-expressions": "workspace:*", @@ -50,7 +50,7 @@ "@babel/plugin-syntax-optional-catch-binding": "^7.8.3", "@babel/plugin-syntax-pipeline-operator": "workspace:*", "@babel/plugin-syntax-record-and-tuple": "workspace:*", - "@babel/plugin-syntax-top-level-await": "workspace:*", + "@babel/plugin-syntax-top-level-await": "^7.14.5", "@babel/plugin-syntax-typescript": "workspace:*", "@babel/plugin-transform-arrow-functions": "workspace:*", "@babel/plugin-transform-async-to-generator": "workspace:*", diff --git a/packages/babel-types/src/definitions/core.ts b/packages/babel-types/src/definitions/core.ts index 6e275614e2be..fbf7e1859342 100644 --- a/packages/babel-types/src/definitions/core.ts +++ b/packages/babel-types/src/definitions/core.ts @@ -898,7 +898,12 @@ defineType("RestElement", { argument: { validate: !process.env.BABEL_TYPES_8_BREAKING ? assertNodeType("LVal") - : assertNodeType("Identifier", "Pattern", "MemberExpression"), + : assertNodeType( + "Identifier", + "ArrayPattern", + "ObjectPattern", + "MemberExpression", + ), }, // For Flow optional: { diff --git a/packages/babel-types/test/fields.js b/packages/babel-types/test/fields.js index 13408b8c2f67..0a59c40b7df7 100644 --- a/packages/babel-types/test/fields.js +++ b/packages/babel-types/test/fields.js @@ -3,9 +3,10 @@ import glob from "glob"; import path from "path"; import fs from "fs"; import { inspect } from "util"; +import { fileURLToPath } from "url"; -// eslint-disable-next-line no-restricted-globals -const packages = path.resolve(__dirname, "..", ".."); +const dirname = path.dirname(fileURLToPath(import.meta.url)); +const packages = path.resolve(dirname, "..", ".."); function readJson(file) { return new Promise((resolve, reject) => { diff --git a/scripts/integration-tests/e2e-create-react-app.sh b/scripts/integration-tests/e2e-create-react-app.sh index 02fb7f92b755..86fcfddc738d 100755 --- a/scripts/integration-tests/e2e-create-react-app.sh +++ b/scripts/integration-tests/e2e-create-react-app.sh @@ -17,6 +17,9 @@ set -x git clone --depth=1 https://github.com/facebook/create-react-app.git tmp/create-react-app cd tmp/create-react-app || exit +# Update npm to v7 +npm i -g npm@7 + #==============================================================================# # TEST # #==============================================================================# @@ -42,14 +45,10 @@ do (cd "$d"; node "$bump_deps") done -# Don't use Yarn 2 -export YARN_IGNORE_PATH=1 - startLocalRegistry "$PWD"/../../verdaccio-config.yml -yarn install +npm install # Test -CI=true yarn test +CI=true npm run test -unset YARN_IGNORE_PATH cleanup diff --git a/yarn.lock b/yarn.lock index a97bdbd6a272..7968e5db95f1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -492,6 +492,7 @@ __metadata: "@babel/helper-plugin-test-runner": "workspace:*" "@babel/helper-replace-supers": "workspace:^7.15.0" "@babel/helper-split-export-declaration": "workspace:^7.14.5" + "@babel/plugin-syntax-class-static-block": ^7.14.5 "@babel/preset-env": "workspace:*" peerDependencies: "@babel/core": ^7.0.0 @@ -1160,7 +1161,7 @@ __metadata: "@babel/helper-create-class-features-plugin": "workspace:^7.14.5" "@babel/helper-plugin-test-runner": "workspace:*" "@babel/helper-plugin-utils": "workspace:^7.14.5" - "@babel/plugin-syntax-class-static-block": "workspace:^7.14.5" + "@babel/plugin-syntax-class-static-block": ^7.14.5 peerDependencies: "@babel/core": ^7.12.0 languageName: unknown @@ -1545,7 +1546,7 @@ __metadata: "@babel/helper-create-class-features-plugin": "workspace:^7.14.5" "@babel/helper-plugin-test-runner": "workspace:*" "@babel/helper-plugin-utils": "workspace:^7.14.5" - "@babel/plugin-syntax-private-property-in-object": "workspace:^7.14.5" + "@babel/plugin-syntax-private-property-in-object": ^7.14.5 peerDependencies: "@babel/core": ^7.0.0-0 languageName: unknown @@ -1659,16 +1660,6 @@ __metadata: languageName: node linkType: hard -"@babel/plugin-syntax-class-static-block@workspace:*, @babel/plugin-syntax-class-static-block@workspace:^7.14.5, @babel/plugin-syntax-class-static-block@workspace:packages/babel-plugin-syntax-class-static-block": - version: 0.0.0-use.local - resolution: "@babel/plugin-syntax-class-static-block@workspace:packages/babel-plugin-syntax-class-static-block" - dependencies: - "@babel/helper-plugin-utils": "workspace:^7.14.5" - peerDependencies: - "@babel/core": ^7.0.0-0 - languageName: unknown - linkType: soft - "@babel/plugin-syntax-decimal@workspace:*, @babel/plugin-syntax-decimal@workspace:packages/babel-plugin-syntax-decimal": version: 0.0.0-use.local resolution: "@babel/plugin-syntax-decimal@workspace:packages/babel-plugin-syntax-decimal" @@ -1931,16 +1922,6 @@ __metadata: languageName: node linkType: hard -"@babel/plugin-syntax-private-property-in-object@workspace:^7.14.5, @babel/plugin-syntax-private-property-in-object@workspace:packages/babel-plugin-syntax-private-property-in-object": - version: 0.0.0-use.local - resolution: "@babel/plugin-syntax-private-property-in-object@workspace:packages/babel-plugin-syntax-private-property-in-object" - dependencies: - "@babel/helper-plugin-utils": "workspace:^7.14.5" - peerDependencies: - "@babel/core": ^7.0.0-0 - languageName: unknown - linkType: soft - "@babel/plugin-syntax-record-and-tuple@workspace:*, @babel/plugin-syntax-record-and-tuple@workspace:^7.14.5, @babel/plugin-syntax-record-and-tuple@workspace:packages/babel-plugin-syntax-record-and-tuple": version: 0.0.0-use.local resolution: "@babel/plugin-syntax-record-and-tuple@workspace:packages/babel-plugin-syntax-record-and-tuple" @@ -1974,17 +1955,6 @@ __metadata: languageName: node linkType: hard -"@babel/plugin-syntax-top-level-await@workspace:*, @babel/plugin-syntax-top-level-await@workspace:^7.14.5, @babel/plugin-syntax-top-level-await@workspace:packages/babel-plugin-syntax-top-level-await": - version: 0.0.0-use.local - resolution: "@babel/plugin-syntax-top-level-await@workspace:packages/babel-plugin-syntax-top-level-await" - dependencies: - "@babel/core": "workspace:*" - "@babel/helper-plugin-utils": "workspace:^7.14.5" - peerDependencies: - "@babel/core": ^7.0.0-0 - languageName: unknown - linkType: soft - "@babel/plugin-syntax-typescript@npm:^7.14.5, @babel/plugin-syntax-typescript@npm:^7.7.2": version: 7.14.5 resolution: "@babel/plugin-syntax-typescript@npm:7.14.5" @@ -2469,6 +2439,7 @@ __metadata: "@babel/helper-plugin-utils": "workspace:^7.14.5" "@babel/helper-simple-access": "workspace:^7.14.8" "@babel/plugin-external-helpers": "workspace:*" + "@babel/plugin-syntax-class-static-block": ^7.14.5 "@babel/plugin-syntax-object-rest-spread": ^7.8.3 babel-plugin-dynamic-import-node: ^2.3.3 peerDependencies: @@ -3228,7 +3199,7 @@ __metadata: "@babel/plugin-proposal-unicode-property-regex": "workspace:^7.14.5" "@babel/plugin-syntax-async-generators": ^7.8.4 "@babel/plugin-syntax-class-properties": ^7.12.13 - "@babel/plugin-syntax-class-static-block": "workspace:^7.14.5" + "@babel/plugin-syntax-class-static-block": ^7.14.5 "@babel/plugin-syntax-dynamic-import": ^7.8.3 "@babel/plugin-syntax-export-namespace-from": ^7.8.3 "@babel/plugin-syntax-json-strings": ^7.8.3 @@ -3238,8 +3209,8 @@ __metadata: "@babel/plugin-syntax-object-rest-spread": ^7.8.3 "@babel/plugin-syntax-optional-catch-binding": ^7.8.3 "@babel/plugin-syntax-optional-chaining": ^7.8.3 - "@babel/plugin-syntax-private-property-in-object": "workspace:^7.14.5" - "@babel/plugin-syntax-top-level-await": "workspace:^7.14.5" + "@babel/plugin-syntax-private-property-in-object": ^7.14.5 + "@babel/plugin-syntax-top-level-await": ^7.14.5 "@babel/plugin-transform-arrow-functions": "workspace:^7.14.5" "@babel/plugin-transform-async-to-generator": "workspace:^7.14.5" "@babel/plugin-transform-block-scoped-functions": "workspace:^7.14.5" @@ -3467,7 +3438,7 @@ __metadata: "@babel/plugin-proposal-unicode-property-regex": "workspace:*" "@babel/plugin-syntax-async-generators": ^7.8.4 "@babel/plugin-syntax-class-properties": ^7.12.13 - "@babel/plugin-syntax-class-static-block": "workspace:*" + "@babel/plugin-syntax-class-static-block": ^7.14.5 "@babel/plugin-syntax-decimal": "workspace:*" "@babel/plugin-syntax-decorators": "workspace:*" "@babel/plugin-syntax-do-expressions": "workspace:*" @@ -3483,7 +3454,7 @@ __metadata: "@babel/plugin-syntax-optional-catch-binding": ^7.8.3 "@babel/plugin-syntax-pipeline-operator": "workspace:*" "@babel/plugin-syntax-record-and-tuple": "workspace:*" - "@babel/plugin-syntax-top-level-await": "workspace:*" + "@babel/plugin-syntax-top-level-await": ^7.14.5 "@babel/plugin-syntax-typescript": "workspace:*" "@babel/plugin-transform-arrow-functions": "workspace:*" "@babel/plugin-transform-async-to-generator": "workspace:*"