From f74cdaea299ebbc7bee1abd375ac1ff71d6c2fa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Tue, 17 Sep 2019 17:36:39 +0200 Subject: [PATCH 01/12] [parser] Add private names tracking to Scope - Disallow duplicate private names - Disallow undeclared private names --- .../babel-parser/src/parser/expression.js | 13 +- packages/babel-parser/src/parser/statement.js | 49 +++- packages/babel-parser/src/util/scope.js | 95 ++++++++ packages/babel-parser/src/util/scopeflags.js | 20 ++ .../duplicated-accessor-method/input.js | 4 + .../duplicated-accessor-method/options.json | 6 + .../duplicated-accessor-method/output.json | 229 ++++++++++++++++++ .../duplicated-field-method/input.js | 4 + .../duplicated-field-method/options.json | 6 + .../duplicated-field-method/output.json | 207 ++++++++++++++++ .../duplicated-method-accessor/input.js | 4 + .../duplicated-method-accessor/options.json | 6 + .../duplicated-method-accessor/output.json | 229 ++++++++++++++++++ .../duplicated-method-field/input.js | 4 + .../duplicated-method-field/options.json | 6 + .../duplicated-method-field/output.json | 207 ++++++++++++++++ .../duplicated-different-placement/input.js | 4 + .../options.json | 5 + .../output.json | 224 +++++++++++++++++ .../duplicated-same-placement/input.js | 4 + .../duplicated-same-placement/options.json | 5 + .../duplicated-same-placement/output.json | 224 +++++++++++++++++ scripts/parser-tests/test262/whitelist.txt | 184 -------------- 23 files changed, 1539 insertions(+), 200 deletions(-) create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/output.json diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 29ef2ceb3c2f..f69abde15e49 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -612,15 +612,18 @@ export default class ExpressionParser extends LValParser { ? this.parseIdentifier(true) : this.parseMaybePrivateName(); node.computed = computed; - if ( - node.property.type === "PrivateName" && - node.object.type === "Super" - ) { - this.raise(startPos, "Private fields can't be accessed on super"); + + if (node.property.type === "PrivateName") { + if (node.object.type === "Super") { + this.raise(startPos, "Private fields can't be accessed on super"); + } + this.scope.usePrivateName(node.property.id.name, node.property.start); } + if (computed) { this.expect(tt.bracketR); } + if (state.optionalChainMember) { node.optional = optional; return this.finishNode(node, "OptionalMemberExpression"); diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index be090db6edf9..edcab9c6329a 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -20,6 +20,11 @@ import { SCOPE_OTHER, SCOPE_SIMPLE_CATCH, SCOPE_SUPER, + CLASS_ELEMENT_OTHER, + CLASS_ELEMENT_INSTANCE_GETTER, + CLASS_ELEMENT_INSTANCE_SETTER, + CLASS_ELEMENT_STATIC_GETTER, + CLASS_ELEMENT_STATIC_SETTER, type BindingTypes, } from "../util/scopeflags"; @@ -1172,6 +1177,7 @@ export default class StatementParser extends ExpressionParser { parseClassBody(constructorAllowsSuper: boolean): N.ClassBody { this.state.classLevel++; + this.scope.enterClassBody(); const state = { hadConstructor: false }; let decorators: N.Decorator[] = []; @@ -1232,6 +1238,7 @@ export default class StatementParser extends ExpressionParser { } this.state.classLevel--; + this.scope.exitClassBody(); return this.finishNode(classBody, "ClassBody"); } @@ -1514,7 +1521,15 @@ export default class StatementParser extends ExpressionParser { prop: N.ClassPrivateProperty, ) { this.expectPlugin("classPrivateProperties", prop.key.start); - classBody.body.push(this.parseClassPrivateProperty(prop)); + + const node = this.parseClassPrivateProperty(prop); + classBody.body.push(node); + + this.scope.declarePrivateName( + node.key.id.name, + CLASS_ELEMENT_OTHER, + node.key.start, + ); } pushClassMethod( @@ -1545,17 +1560,29 @@ export default class StatementParser extends ExpressionParser { isAsync: boolean, ): void { this.expectPlugin("classPrivateMethods", method.key.start); - classBody.body.push( - this.parseMethod( - method, - isGenerator, - isAsync, - /* isConstructor */ false, - false, - "ClassPrivateMethod", - true, - ), + + const node = this.parseMethod( + method, + isGenerator, + isAsync, + /* isConstructor */ false, + false, + "ClassPrivateMethod", + true, ); + classBody.body.push(node); + + const kind = + node.kind === "get" + ? node.static + ? CLASS_ELEMENT_STATIC_GETTER + : CLASS_ELEMENT_INSTANCE_GETTER + : node.kind === "set" + ? node.static + ? CLASS_ELEMENT_STATIC_SETTER + : CLASS_ELEMENT_INSTANCE_SETTER + : CLASS_ELEMENT_OTHER; + this.scope.declarePrivateName(node.key.id.name, kind, node.key.start); } // Overridden in typescript.js diff --git a/packages/babel-parser/src/util/scope.js b/packages/babel-parser/src/util/scope.js index bc90be4d03cb..5e3ca05a8cd5 100644 --- a/packages/babel-parser/src/util/scope.js +++ b/packages/babel-parser/src/util/scope.js @@ -14,8 +14,11 @@ import { BIND_SCOPE_VAR, BIND_SCOPE_LEXICAL, BIND_KIND_VALUE, + CLASS_ELEMENT_KIND_ACCESSOR, + CLASS_ELEMENT_FLAG_STATIC, type ScopeFlags, type BindingTypes, + type ClassElementTypes, } from "./scopeflags"; import * as N from "../types"; @@ -28,21 +31,33 @@ export class Scope { lexical: string[] = []; // A list of lexically-declared FunctionDeclaration names in the current lexical scope functions: string[] = []; + // A list of private names defined in the current class body + privateNames: string[] = []; constructor(flags: ScopeFlags) { this.flags = flags; } } +export class ClassScope { + privateNames: string[] = new Set(); + + loneAccessors: Map = new Map(); + + undefinedPrivateNames: Map = new Map(); +} + type raiseFunction = (number, string) => void; // The functions in this module keep track of declared variables in the // current scope in order to detect duplicate variable names. export default class ScopeHandler { scopeStack: Array = []; + classScopeStack: Array = []; raise: raiseFunction; inModule: boolean; undefinedExports: Map = new Map(); + undefinedPrivateNames: Map = new Map(); constructor(raise: raiseFunction, inModule: boolean) { this.raise = raise; @@ -101,6 +116,30 @@ export default class ScopeHandler { this.scopeStack.pop(); } + enterClassBody() { + this.classScopeStack.push(new ClassScope()); + } + + exitClassBody() { + const oldClassScope = this.classScopeStack.pop(); + + // Migrate the usage of not yet defined private names to the outer + // class scope, or raise an error if we reached the top-level scope. + + const currentClassScope = this.currentClassScope(); + + // Array.from is needed because this is compiled to an array-like for loop + for (const [name, pos] of Array.from(oldClassScope.undefinedPrivateNames)) { + if (currentClassScope) { + if (!currentClassScope.undefinedPrivateNames.has(name)) { + currentClassScope.undefinedPrivateNames.set(name, pos); + } + } else { + this.raiseUndeclaredPrivateName(name, pos); + } + } + } + // The spec says: // > At the top level of a function, or script, function declarations are // > treated like var declarations rather than like lexical declarations. @@ -140,6 +179,58 @@ export default class ScopeHandler { } } + declarePrivateName( + name: string, + elementType: ClassElementTypes, + pos: number, + ) { + const classScope = this.currentClassScope(); + let redefined = classScope.privateNames.has(name); + + if (elementType & CLASS_ELEMENT_KIND_ACCESSOR) { + const accessor = redefined && classScope.loneAccessors.get(name); + if (accessor) { + const differences = elementType ^ accessor; + + // The private name can be duplicated only if it is used by + // two accessors with different kind (get and set), and if + // they have the same placement (static or not). + redefined = + !(differences & CLASS_ELEMENT_KIND_ACCESSOR) || + differences & CLASS_ELEMENT_FLAG_STATIC; + + if (!redefined) classScope.loneAccessors.delete(name); + } else if (!redefined) { + classScope.loneAccessors.set(name, elementType); + } + } + + if (redefined) { + this.raise(pos, `Duplicate private name #${name}`); + } + + classScope.privateNames.add(name); + classScope.undefinedPrivateNames.delete(name); + } + + usePrivateName(name: string, pos: number) { + let classScope; + for (classScope of this.classScopeStack) { + if (classScope.privateNames.has(name)) return; + } + + if (classScope) { + classScope.undefinedPrivateNames.set(name, pos); + } else { + // top-level + this.raiseUndeclaredPrivateName(name, pos); + } + } + + raiseUndeclaredPrivateName(name, pos) { + this.raise(pos, `Private name #${name} is not defined`); + } + maybeExportDefined(scope: IScope, name: string) { if (this.inModule && scope.flags & SCOPE_PROGRAM) { this.undefinedExports.delete(name); @@ -205,6 +296,10 @@ export default class ScopeHandler { return this.scopeStack[this.scopeStack.length - 1]; } + currentClassScope(): ClassScope { + return this.classScopeStack[this.classScopeStack.length - 1]; + } + // $FlowIgnore currentVarScope(): IScope { for (let i = this.scopeStack.length - 1; ; i--) { diff --git a/packages/babel-parser/src/util/scopeflags.js b/packages/babel-parser/src/util/scopeflags.js index d926998835b6..e49359cf615c 100644 --- a/packages/babel-parser/src/util/scopeflags.js +++ b/packages/babel-parser/src/util/scopeflags.js @@ -84,3 +84,23 @@ export type BindingTypes = | typeof BIND_TS_ENUM | typeof BIND_TS_AMBIENT | typeof BIND_TS_NAMESPACE; + +// prettier-ignore +export const CLASS_ELEMENT_FLAG_STATIC = 0b1_00, + CLASS_ELEMENT_KIND_GETTER = 0b0_10, + CLASS_ELEMENT_KIND_SETTER = 0b0_01, + CLASS_ELEMENT_KIND_ACCESSOR = CLASS_ELEMENT_KIND_GETTER | CLASS_ELEMENT_KIND_SETTER; + +// prettier-ignore +export const CLASS_ELEMENT_STATIC_GETTER = CLASS_ELEMENT_KIND_GETTER | CLASS_ELEMENT_FLAG_STATIC, + CLASS_ELEMENT_STATIC_SETTER = CLASS_ELEMENT_KIND_SETTER | CLASS_ELEMENT_FLAG_STATIC, + CLASS_ELEMENT_INSTANCE_GETTER = CLASS_ELEMENT_KIND_GETTER, + CLASS_ELEMENT_INSTANCE_SETTER = CLASS_ELEMENT_KIND_SETTER, + CLASS_ELEMENT_OTHER = 0; + +export type ClassElementTypes = + | typeof CLASS_ELEMENT_STATIC_GETTER + | typeof CLASS_ELEMENT_STATIC_SETTER + | typeof CLASS_ELEMENT_INSTANCE_GETTER + | typeof CLASS_ELEMENT_INSTANCE_SETTER + | typeof CLASS_ELEMENT_OTHER; diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/input.js new file mode 100644 index 000000000000..00d50846e973 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/input.js @@ -0,0 +1,4 @@ +class A { + get #x() {} + #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/options.json new file mode 100644 index 000000000000..e54e47dbe9eb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "classPrivateMethods", + "classPrivateProperties" + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/output.json new file mode 100644 index 000000000000..9fa1c2917097 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/output.json @@ -0,0 +1,229 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 26, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 26, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/input.js new file mode 100644 index 000000000000..6dde01adc90e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/input.js @@ -0,0 +1,4 @@ +class A { + #x; + #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/options.json new file mode 100644 index 000000000000..e54e47dbe9eb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "classPrivateMethods", + "classPrivateProperties" + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/output.json new file mode 100644 index 000000000000..c5ddc0f4feb1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/output.json @@ -0,0 +1,207 @@ +{ + "type": "File", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": null + }, + { + "type": "ClassPrivateMethod", + "start": 18, + "end": 25, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 18, + "end": 20, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/input.js new file mode 100644 index 000000000000..b1d19924d288 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/input.js @@ -0,0 +1,4 @@ +class A { + #x() {} + get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/options.json new file mode 100644 index 000000000000..e54e47dbe9eb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "classPrivateMethods", + "classPrivateProperties" + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/output.json new file mode 100644 index 000000000000..8dbf70cdb04b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/output.json @@ -0,0 +1,229 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:6)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 22, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 26, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/input.js new file mode 100644 index 000000000000..26122843af16 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/input.js @@ -0,0 +1,4 @@ +class A { + #x() {} + #x; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/options.json new file mode 100644 index 000000000000..e54e47dbe9eb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "classPrivateMethods", + "classPrivateProperties" + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/output.json new file mode 100644 index 000000000000..db05e019cac5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/output.json @@ -0,0 +1,207 @@ +{ + "type": "File", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateProperty", + "start": 22, + "end": 25, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/input.js new file mode 100644 index 000000000000..df22b36e0ae8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/input.js @@ -0,0 +1,4 @@ +class A { + #x = 1; + static #x = 2; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/options.json new file mode 100644 index 000000000000..1ca5069a3a2f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/options.json @@ -0,0 +1,5 @@ +{ + "plugins": [ + "classPrivateProperties" + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/output.json new file mode 100644 index 000000000000..2eda3d02bc66 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/output.json @@ -0,0 +1,224 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ClassPrivateProperty", + "start": 22, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/input.js new file mode 100644 index 000000000000..83ddd3d8a226 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/input.js @@ -0,0 +1,4 @@ +class A { + #x = 1; + #x = 2; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/options.json new file mode 100644 index 000000000000..1ca5069a3a2f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/options.json @@ -0,0 +1,5 @@ +{ + "plugins": [ + "classPrivateProperties" + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/output.json new file mode 100644 index 000000000000..53727fe07998 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/output.json @@ -0,0 +1,224 @@ +{ + "type": "File", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "ClassPrivateProperty", + "start": 22, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/scripts/parser-tests/test262/whitelist.txt b/scripts/parser-tests/test262/whitelist.txt index 512bee9a2ca8..cb608d6442b1 100644 --- a/scripts/parser-tests/test262/whitelist.txt +++ b/scripts/parser-tests/test262/whitelist.txt @@ -1,194 +1,10 @@ -language/expressions/class/elements/fields-duplicate-privatenames.js(default) -language/expressions/class/elements/fields-duplicate-privatenames.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-chained-usage.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-chained-usage.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-recursive.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-recursive.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage.js(strict mode) language/expressions/class/elements/syntax/early-errors/grammar-private-field-on-object-destructuring.js(default) language/expressions/class/elements/syntax/early-errors/grammar-private-field-on-object-destructuring.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-async-gen.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-async-gen.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-async.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-async.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-gen.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-gen.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-get-field.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-get-field.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-get-get.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-get-get.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-field.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-field.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-get.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-get.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-meth.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-meth.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-set.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-set.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-staticfield.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-staticfield.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-staticmeth.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-staticmeth.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-set-field.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-set-field.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-set-set.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-set-set.js(strict mode) -language/expressions/class/elements/syntax/early-errors/grammar-privatename-in-computed-property-missing.js(default) -language/expressions/class/elements/syntax/early-errors/grammar-privatename-in-computed-property-missing.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-call-expression-bad-reference.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-call-expression-bad-reference.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-call-expression-this.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-call-expression-this.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-fn-call-expression-bad-reference.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-fn-call-expression-bad-reference.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-fn-call-expression-this.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-fn-call-expression-this.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-fn-member-expression-bad-reference.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-fn-member-expression-bad-reference.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-fn-member-expression-this.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-fn-member-expression-this.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-member-expression-bad-reference.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-member-expression-bad-reference.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-member-expression-this.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-member-expression-this.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-call-expression-bad-reference.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-call-expression-bad-reference.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-call-expression-this.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-call-expression-this.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-fn-call-expression-bad-reference.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-fn-call-expression-bad-reference.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-fn-call-expression-this.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-fn-call-expression-this.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-fn-member-expression-bad-reference.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-fn-member-expression-bad-reference.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-fn-member-expression-this.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-fn-member-expression-this.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-heritage-call-expression-bad-reference.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-heritage-call-expression-bad-reference.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-heritage-call-expression-this.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-heritage-call-expression-this.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-heritage-member-expression-bad-reference.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-heritage-member-expression-bad-reference.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-heritage-member-expression-this.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-heritage-member-expression-this.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-member-expression-bad-reference.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-member-expression-bad-reference.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-member-expression-this.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-member-expression-this.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-outter-call-expression-bad-reference.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-outter-call-expression-bad-reference.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-outter-call-expression-this.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-outter-call-expression-this.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-outter-member-expression-bad-reference.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-outter-member-expression-bad-reference.js(strict mode) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-outter-member-expression-this.js(default) -language/expressions/class/elements/syntax/early-errors/invalid-names/method-outter-member-expression-this.js(strict mode) language/expressions/object/method-definition/private-name-early-error-async-gen-inside-class.js(default) language/expressions/object/method-definition/private-name-early-error-async-gen-inside-class.js(strict mode) language/expressions/object/method-definition/private-name-early-error-gen-inside-class.js(default) language/expressions/object/method-definition/private-name-early-error-gen-inside-class.js(strict mode) language/expressions/object/method-definition/private-name-early-error-method-inside-class.js(default) language/expressions/object/method-definition/private-name-early-error-method-inside-class.js(strict mode) -language/module-code/privatename-not-valid-earlyerr-module-1.js(default) -language/module-code/privatename-not-valid-earlyerr-module-1.js(strict mode) -language/module-code/privatename-not-valid-earlyerr-module-2.js(default) -language/module-code/privatename-not-valid-earlyerr-module-2.js(strict mode) -language/module-code/privatename-not-valid-earlyerr-module-3.js(default) -language/module-code/privatename-not-valid-earlyerr-module-3.js(strict mode) -language/module-code/privatename-not-valid-earlyerr-module-4.js(default) -language/module-code/privatename-not-valid-earlyerr-module-4.js(strict mode) -language/statements/class/elements/fields-duplicate-privatenames.js(default) -language/statements/class/elements/fields-duplicate-privatenames.js(strict mode) -language/statements/class/elements/privatename-not-valid-earlyerr-script-1.js(default) -language/statements/class/elements/privatename-not-valid-earlyerr-script-1.js(strict mode) -language/statements/class/elements/privatename-not-valid-earlyerr-script-2.js(default) -language/statements/class/elements/privatename-not-valid-earlyerr-script-2.js(strict mode) -language/statements/class/elements/privatename-not-valid-earlyerr-script-3.js(default) -language/statements/class/elements/privatename-not-valid-earlyerr-script-3.js(strict mode) -language/statements/class/elements/privatename-not-valid-earlyerr-script-4.js(default) -language/statements/class/elements/privatename-not-valid-earlyerr-script-4.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-chained-usage.js(default) -language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-chained-usage.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-recursive.js(default) -language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-recursive.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage.js(default) -language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage.js(strict mode) language/statements/class/elements/syntax/early-errors/grammar-private-field-on-object-destructuring.js(default) language/statements/class/elements/syntax/early-errors/grammar-private-field-on-object-destructuring.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-async-gen.js(default) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-async-gen.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-async.js(default) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-async.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-gen.js(default) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-gen.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-get-field.js(default) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-get-field.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-get-get.js(default) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-get-get.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-field.js(default) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-field.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-get.js(default) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-get.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-meth.js(default) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-meth.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-set.js(default) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-set.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-staticfield.js(default) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-staticfield.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-staticmeth.js(default) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-meth-staticmeth.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-set-field.js(default) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-set-field.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-set-set.js(default) -language/statements/class/elements/syntax/early-errors/grammar-privatemeth-duplicate-set-set.js(strict mode) -language/statements/class/elements/syntax/early-errors/grammar-privatename-in-computed-property-missing.js(default) -language/statements/class/elements/syntax/early-errors/grammar-privatename-in-computed-property-missing.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-call-expression-bad-reference.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-call-expression-bad-reference.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-call-expression-this.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-call-expression-this.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-fn-call-expression-bad-reference.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-fn-call-expression-bad-reference.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-fn-call-expression-this.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-fn-call-expression-this.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-fn-member-expression-bad-reference.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-fn-member-expression-bad-reference.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-fn-member-expression-this.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-fn-member-expression-this.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-member-expression-bad-reference.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-member-expression-bad-reference.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-member-expression-this.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/field-init-member-expression-this.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-call-expression-bad-reference.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-call-expression-bad-reference.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-call-expression-this.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-call-expression-this.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-fn-call-expression-bad-reference.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-fn-call-expression-bad-reference.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-fn-call-expression-this.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-fn-call-expression-this.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-fn-member-expression-bad-reference.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-fn-member-expression-bad-reference.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-fn-member-expression-this.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-fn-member-expression-this.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-heritage-call-expression-bad-reference.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-heritage-call-expression-bad-reference.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-heritage-call-expression-this.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-heritage-call-expression-this.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-heritage-member-expression-bad-reference.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-heritage-member-expression-bad-reference.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-heritage-member-expression-this.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-heritage-member-expression-this.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-member-expression-bad-reference.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-member-expression-bad-reference.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-member-expression-this.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-member-expression-this.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-outter-call-expression-bad-reference.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-outter-call-expression-bad-reference.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-outter-call-expression-this.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-outter-call-expression-this.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-outter-member-expression-bad-reference.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-outter-member-expression-bad-reference.js(strict mode) -language/statements/class/elements/syntax/early-errors/invalid-names/method-outter-member-expression-this.js(default) -language/statements/class/elements/syntax/early-errors/invalid-names/method-outter-member-expression-this.js(strict mode) From 0cc21d5d8e64f02388147736dbabc1c2fbd54f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Tue, 17 Sep 2019 18:06:17 +0200 Subject: [PATCH 02/12] Update tests --- .../types/ClassBody-ClassProperty/input.js | 6 ++--- .../types/ClassBody-ClassProperty/output.js | 8 +++--- .../types/ClassBody-MethodDefinition/input.js | 26 +++++++++---------- .../ClassBody-MethodDefinition/output.js | 26 +++++++++---------- .../duplicated-names/get-get/options.json | 2 +- .../duplicated-names/get-method/options.json | 2 +- .../duplicated-names/method-get/options.json | 2 +- .../method-method/options.json | 2 +- .../duplicated-names/method-set/options.json | 2 +- .../duplicated-names/set-method/options.json | 2 +- .../duplicated-names/set-set/options.json | 2 +- 11 files changed, 40 insertions(+), 40 deletions(-) diff --git a/packages/babel-generator/test/fixtures/types/ClassBody-ClassProperty/input.js b/packages/babel-generator/test/fixtures/types/ClassBody-ClassProperty/input.js index 6256942ca5c5..87462c83f603 100644 --- a/packages/babel-generator/test/fixtures/types/ClassBody-ClassProperty/input.js +++ b/packages/babel-generator/test/fixtures/types/ClassBody-ClassProperty/input.js @@ -28,9 +28,9 @@ class Foo { foo = 0; bar = 1; #foo; - #foo = 1; - static #foo; - static #foo = Foo.#foo; + #foo2 = 1; + static #foo3; + static #foo4 = Foo.#foo; } class A1 { diff --git a/packages/babel-generator/test/fixtures/types/ClassBody-ClassProperty/output.js b/packages/babel-generator/test/fixtures/types/ClassBody-ClassProperty/output.js index 905fe31bdbfb..9970811aabad 100644 --- a/packages/babel-generator/test/fixtures/types/ClassBody-ClassProperty/output.js +++ b/packages/babel-generator/test/fixtures/types/ClassBody-ClassProperty/output.js @@ -27,9 +27,9 @@ class Foo { foo = 0; bar = 1; #foo; - #foo = 1; - static #foo; - static #foo = Foo.#foo; + #foo2 = 1; + static #foo3; + static #foo4 = Foo.#foo; } class A1 { @@ -69,4 +69,4 @@ class A6 { class A7 { static get static() {} -} +} \ No newline at end of file diff --git a/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/input.js b/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/input.js index ae3f4b33c003..67ccba8fc28b 100644 --- a/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/input.js +++ b/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/input.js @@ -6,13 +6,13 @@ class Foo { set foo(bar) {} async #foo() {} - #foo() {} - get #foo() {} - set #foo(bar) {} - * #foo() {} - async * #foo() {} - get #bar() {} - set #baz(taz) {} + #foo2() {} + get #foo3() {} + set #foo3(bar) {} + * #foo4() {} + async * #foo5() {} + get #bar6() {} + set #baz6(taz) {} static async foo() {} static foo() {} @@ -23,13 +23,13 @@ class Foo { static * foo() {} static async * foo() {} - static #foo() {} - static async #foo() {} + static #foo7() {} + static async #foo8() {} static ["foo"]() {} - static get #foo() {} - static set #foo(taz) {} - static * #foo() {} - static async * #foo() {} + static get #foo9() {} + static set #foo9(taz) {} + static * #foo10() {} + static async * #foo11() {} get () {} diff --git a/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/output.js b/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/output.js index 24f3e9229c84..7f66930a5422 100644 --- a/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/output.js +++ b/packages/babel-generator/test/fixtures/types/ClassBody-MethodDefinition/output.js @@ -11,19 +11,19 @@ class Foo { async #foo() {} - #foo() {} + #foo2() {} - get #foo() {} + get #foo3() {} - set #foo(bar) {} + set #foo3(bar) {} - *#foo() {} + *#foo4() {} - async *#foo() {} + async *#foo5() {} - get #bar() {} + get #bar6() {} - set #baz(taz) {} + set #baz6(taz) {} static async foo() {} @@ -41,19 +41,19 @@ class Foo { static async *foo() {} - static #foo() {} + static #foo7() {} - static async #foo() {} + static async #foo8() {} static ["foo"]() {} - static get #foo() {} + static get #foo9() {} - static set #foo(taz) {} + static set #foo9(taz) {} - static *#foo() {} + static *#foo10() {} - static async *#foo() {} + static async *#foo11() {} get() {} diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-get/options.json b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-get/options.json index 9c0ba0e4b46a..49dcfc816842 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-get/options.json +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-get/options.json @@ -1,3 +1,3 @@ { - "throws": "Duplicate private field" + "throws": "Duplicate private name #getSet" } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-method/options.json b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-method/options.json index 9c0ba0e4b46a..1edb048c1285 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-method/options.json +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-method/options.json @@ -1,3 +1,3 @@ { - "throws": "Duplicate private field" + "throws": "Duplicate private name #foo" } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/method-get/options.json b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/method-get/options.json index 9c0ba0e4b46a..1edb048c1285 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/method-get/options.json +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/method-get/options.json @@ -1,3 +1,3 @@ { - "throws": "Duplicate private field" + "throws": "Duplicate private name #foo" } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/method-method/options.json b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/method-method/options.json index 9c0ba0e4b46a..b3e2e5dade0d 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/method-method/options.json +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/method-method/options.json @@ -1,3 +1,3 @@ { - "throws": "Duplicate private field" + "throws": "Duplicate private name #dank" } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/method-set/options.json b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/method-set/options.json index 9c0ba0e4b46a..1edb048c1285 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/method-set/options.json +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/method-set/options.json @@ -1,3 +1,3 @@ { - "throws": "Duplicate private field" + "throws": "Duplicate private name #foo" } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-method/options.json b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-method/options.json index 9c0ba0e4b46a..1edb048c1285 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-method/options.json +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-method/options.json @@ -1,3 +1,3 @@ { - "throws": "Duplicate private field" + "throws": "Duplicate private name #foo" } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-set/options.json b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-set/options.json index 9c0ba0e4b46a..49dcfc816842 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-set/options.json +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-set/options.json @@ -1,3 +1,3 @@ { - "throws": "Duplicate private field" + "throws": "Duplicate private name #getSet" } From 7dcf575b4566c149f6f1161a489252a6016cad18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 19 Sep 2019 01:35:11 +0200 Subject: [PATCH 03/12] Test all possible duplications --- .../duplicated-accessor-method/options.json | 6 - .../duplicated-field-method/options.json | 6 - .../duplicated-method-accessor/options.json | 6 - .../duplicated-method-field/options.json | 6 - .../class-private-names-duplicated/README.md | 31 ++ .../instance-field-instance-field/input.js | 4 + .../options.json | 3 + .../instance-field-instance-field/output.json | 224 +++++++++++++++ .../instance-field-instance-get/input.js | 4 + .../instance-field-instance-get/options.json | 3 + .../instance-field-instance-get/output.json | 227 +++++++++++++++ .../instance-field-instance-method}/input.js | 2 +- .../options.json | 3 + .../output.json | 226 +++++++++++++++ .../instance-field-instance-set/input.js | 4 + .../instance-field-instance-set/options.json | 3 + .../instance-field-instance-set/output.json | 245 ++++++++++++++++ .../instance-field-static-field/input.js | 4 + .../instance-field-static-field/options.json | 3 + .../instance-field-static-field/output.json | 224 +++++++++++++++ .../instance-field-static-get/input.js | 4 + .../instance-field-static-get/options.json | 3 + .../instance-field-static-get/output.json | 227 +++++++++++++++ .../instance-field-static-method/input.js | 4 + .../instance-field-static-method/options.json | 3 + .../instance-field-static-method/output.json | 226 +++++++++++++++ .../instance-field-static-set/input.js | 4 + .../instance-field-static-set/options.json | 3 + .../instance-field-static-set/output.json | 245 ++++++++++++++++ .../instance-get-instance-field/input.js | 4 + .../instance-get-instance-field/options.json | 3 + .../instance-get-instance-field/output.json | 227 +++++++++++++++ .../instance-get-instance-get/input.js | 4 + .../instance-get-instance-get/options.json | 3 + .../instance-get-instance-get/output.json | 230 +++++++++++++++ .../instance-get-instance-method}/input.js | 0 .../instance-get-instance-method/options.json | 3 + .../instance-get-instance-method/output.json | 229 +++++++++++++++ .../instance-get-instance-set/input.js | 4 + .../instance-get-instance-set/options.json | 3 + .../instance-get-instance-set/output.json | 245 ++++++++++++++++ .../instance-get-static-field/input.js | 4 + .../instance-get-static-field/options.json | 3 + .../instance-get-static-field/output.json | 227 +++++++++++++++ .../instance-get-static-get/input.js | 4 + .../instance-get-static-get/options.json | 3 + .../instance-get-static-get/output.json | 230 +++++++++++++++ .../instance-get-static-method/input.js | 4 + .../instance-get-static-method/options.json | 3 + .../instance-get-static-method/output.json | 229 +++++++++++++++ .../instance-get-static-set/input.js | 4 + .../instance-get-static-set/options.json | 3 + .../instance-get-static-set/output.json | 248 ++++++++++++++++ .../instance-method-instance-field}/input.js | 2 +- .../options.json | 3 + .../output.json | 226 +++++++++++++++ .../instance-method-instance-get}/input.js | 0 .../instance-method-instance-get/options.json | 3 + .../instance-method-instance-get/output.json | 229 +++++++++++++++ .../instance-method-instance-method/input.js | 4 + .../options.json | 3 + .../output.json | 228 +++++++++++++++ .../instance-method-instance-set/input.js | 4 + .../instance-method-instance-set/options.json | 3 + .../instance-method-instance-set/output.json | 247 ++++++++++++++++ .../instance-method-static-field/input.js | 4 + .../instance-method-static-field/options.json | 3 + .../instance-method-static-field/output.json | 226 +++++++++++++++ .../instance-method-static-get/input.js | 4 + .../instance-method-static-get/options.json | 3 + .../instance-method-static-get/output.json | 229 +++++++++++++++ .../instance-method-static-method/input.js | 4 + .../options.json | 3 + .../instance-method-static-method/output.json | 228 +++++++++++++++ .../instance-method-static-set/input.js | 4 + .../instance-method-static-set/options.json | 3 + .../instance-method-static-set/output.json | 247 ++++++++++++++++ .../instance-set-instance-field/input.js | 4 + .../instance-set-instance-field/options.json | 3 + .../instance-set-instance-field/output.json | 245 ++++++++++++++++ .../instance-set-instance-get/input.js | 4 + .../instance-set-instance-get/options.json | 3 + .../instance-set-instance-get/output.json | 245 ++++++++++++++++ .../instance-set-instance-method/input.js | 4 + .../instance-set-instance-method/options.json | 3 + .../instance-set-instance-method/output.json | 247 ++++++++++++++++ .../instance-set-instance-set/input.js | 4 + .../instance-set-instance-set/options.json | 3 + .../instance-set-instance-set/output.json | 266 ++++++++++++++++++ .../instance-set-static-field/input.js | 4 + .../instance-set-static-field/options.json | 3 + .../instance-set-static-field/output.json | 245 ++++++++++++++++ .../instance-set-static-get/input.js | 4 + .../instance-set-static-get/options.json | 3 + .../instance-set-static-get/output.json | 248 ++++++++++++++++ .../instance-set-static-method/input.js | 4 + .../instance-set-static-method/options.json | 3 + .../instance-set-static-method/output.json | 247 ++++++++++++++++ .../instance-set-static-set/input.js | 4 + .../instance-set-static-set/options.json | 3 + .../instance-set-static-set/output.json | 266 ++++++++++++++++++ .../static-field-instance-field/input.js | 4 + .../static-field-instance-field/options.json | 3 + .../static-field-instance-field/output.json | 224 +++++++++++++++ .../static-field-instance-get/input.js | 4 + .../static-field-instance-get/options.json | 3 + .../static-field-instance-get/output.json | 227 +++++++++++++++ .../static-field-instance-method/input.js | 4 + .../static-field-instance-method/options.json | 3 + .../static-field-instance-method/output.json | 226 +++++++++++++++ .../static-field-instance-set/input.js | 4 + .../static-field-instance-set/options.json | 3 + .../static-field-instance-set/output.json | 245 ++++++++++++++++ .../static-field-static-field/input.js | 4 + .../static-field-static-field/options.json | 3 + .../static-field-static-field/output.json | 224 +++++++++++++++ .../static-field-static-get/input.js | 4 + .../static-field-static-get/options.json | 3 + .../static-field-static-get/output.json | 227 +++++++++++++++ .../static-field-static-method/input.js | 4 + .../static-field-static-method/options.json | 3 + .../static-field-static-method/output.json | 226 +++++++++++++++ .../static-field-static-set/input.js | 4 + .../static-field-static-set/options.json | 3 + .../static-field-static-set/output.json | 245 ++++++++++++++++ .../static-get-instance-field/input.js | 4 + .../static-get-instance-field/options.json | 3 + .../static-get-instance-field/output.json | 227 +++++++++++++++ .../static-get-instance-get/input.js | 4 + .../static-get-instance-get/options.json | 3 + .../static-get-instance-get/output.json | 230 +++++++++++++++ .../static-get-instance-method/input.js | 4 + .../static-get-instance-method/options.json | 3 + .../static-get-instance-method/output.json | 229 +++++++++++++++ .../static-get-instance-set/input.js | 4 + .../static-get-instance-set/options.json | 3 + .../static-get-instance-set/output.json | 248 ++++++++++++++++ .../static-get-static-field/input.js | 4 + .../static-get-static-field/options.json | 3 + .../static-get-static-field/output.json | 227 +++++++++++++++ .../static-get-static-get/input.js | 4 + .../static-get-static-get/options.json | 3 + .../static-get-static-get/output.json | 230 +++++++++++++++ .../static-get-static-method/input.js | 4 + .../static-get-static-method/options.json | 3 + .../static-get-static-method/output.json | 229 +++++++++++++++ .../static-get-static-set/input.js | 4 + .../static-get-static-set/options.json | 3 + .../static-get-static-set/output.json | 245 ++++++++++++++++ .../static-method-instance-field/input.js | 4 + .../static-method-instance-field/options.json | 3 + .../static-method-instance-field/output.json | 226 +++++++++++++++ .../static-method-instance-get/input.js | 4 + .../static-method-instance-get/options.json | 3 + .../static-method-instance-get/output.json | 229 +++++++++++++++ .../static-method-instance-method/input.js | 4 + .../options.json | 3 + .../static-method-instance-method/output.json | 228 +++++++++++++++ .../static-method-instance-set/input.js | 4 + .../static-method-instance-set/options.json | 3 + .../static-method-instance-set/output.json | 247 ++++++++++++++++ .../static-method-static-field/input.js | 4 + .../static-method-static-field/options.json | 3 + .../static-method-static-field/output.json | 226 +++++++++++++++ .../static-method-static-get/input.js | 4 + .../static-method-static-get/options.json | 3 + .../static-method-static-get/output.json | 229 +++++++++++++++ .../static-method-static-method/input.js | 4 + .../static-method-static-method/options.json | 3 + .../static-method-static-method/output.json | 228 +++++++++++++++ .../static-method-static-set/input.js | 4 + .../static-method-static-set/options.json | 3 + .../static-method-static-set/output.json | 247 ++++++++++++++++ .../static-set-instance-field/input.js | 4 + .../static-set-instance-field/options.json | 3 + .../static-set-instance-field/output.json | 245 ++++++++++++++++ .../static-set-instance-get/input.js | 4 + .../static-set-instance-get/options.json | 3 + .../static-set-instance-get/output.json | 248 ++++++++++++++++ .../static-set-instance-method/input.js | 4 + .../static-set-instance-method/options.json | 3 + .../static-set-instance-method/output.json | 247 ++++++++++++++++ .../static-set-instance-set/input.js | 4 + .../static-set-instance-set/options.json | 3 + .../static-set-instance-set/output.json | 266 ++++++++++++++++++ .../static-set-static-field/input.js | 4 + .../static-set-static-field/options.json | 3 + .../static-set-static-field/output.json | 245 ++++++++++++++++ .../static-set-static-get/input.js | 4 + .../static-set-static-get/options.json | 3 + .../static-set-static-get/output.json | 245 ++++++++++++++++ .../static-set-static-method/input.js | 4 + .../static-set-static-method/options.json | 3 + .../static-set-static-method/output.json | 247 ++++++++++++++++ .../static-set-static-set/input.js | 4 + .../static-set-static-set/options.json | 3 + .../static-set-static-set/output.json | 266 ++++++++++++++++++ .../duplicated-different-placement/input.js | 4 - .../options.json | 5 - .../duplicated-same-placement/input.js | 4 - .../duplicated-same-placement/options.json | 5 - 201 files changed, 15621 insertions(+), 44 deletions(-) delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/options.json delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/options.json delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/options.json delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/README.md create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-get/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-get/output.json rename packages/babel-parser/test/fixtures/experimental/{class-private-methods/duplicated-method-field => class-private-names-duplicated/instance-field-instance-method}/input.js (64%) create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-set/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-get/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-get/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-set/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-get/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-get/output.json rename packages/babel-parser/test/fixtures/experimental/{class-private-methods/duplicated-accessor-method => class-private-names-duplicated/instance-get-instance-method}/input.js (100%) create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-get/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-get/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-set/output.json rename packages/babel-parser/test/fixtures/experimental/{class-private-methods/duplicated-field-method => class-private-names-duplicated/instance-method-instance-field}/input.js (64%) create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-field/output.json rename packages/babel-parser/test/fixtures/experimental/{class-private-methods/duplicated-method-accessor => class-private-names-duplicated/instance-method-instance-get}/input.js (100%) create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-get/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-set/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-get/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-get/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-set/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-set/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-get/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-get/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-set/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-get/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-get/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-set/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-get/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-get/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-set/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-get/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-get/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-set/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-get/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-get/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-get/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-get/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-set/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-get/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-get/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-set/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-get/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-get/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-set/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-field/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-field/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-field/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-method/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-method/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-method/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-set/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-set/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-set/output.json delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/input.js delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/options.json delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/input.js delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/options.json diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/options.json deleted file mode 100644 index e54e47dbe9eb..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/options.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "plugins": [ - "classPrivateMethods", - "classPrivateProperties" - ] -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/options.json deleted file mode 100644 index e54e47dbe9eb..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/options.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "plugins": [ - "classPrivateMethods", - "classPrivateProperties" - ] -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/options.json deleted file mode 100644 index e54e47dbe9eb..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/options.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "plugins": [ - "classPrivateMethods", - "classPrivateProperties" - ] -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/options.json deleted file mode 100644 index e54e47dbe9eb..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/options.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "plugins": [ - "classPrivateMethods", - "classPrivateProperties" - ] -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/README.md b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/README.md new file mode 100644 index 000000000000..f735bf293cee --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/README.md @@ -0,0 +1,31 @@ +These tests have been generated using the following script: + +```js +var feat = { + "field": "#x = 0;", + "method": "#x() {}", + "get": "get #x() {}", + "set": "set #x(_) {}", +}; +var placement = { + "static": "static ", + "instance": "" +} + +for (var f1 in feat) for (var f2 in feat) for (var p1 in placement) for (var p2 in placement) { + var code = `class A { + ${placement[p1]}${feat[f1]} + ${placement[p2]}${feat[f2]} +}`; + var name = `${p1}-${f1}-${p2}-${f2}`; + var options = `{ + "plugins": ["classPrivateProperties", "classPrivateMethods"], + "throws": "Duplicate private name #x (3:${2 + placement[p2].length + feat[f2].indexOf("#")})" +}` + var folder = "packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/" + name; + + if (!fs.existsSync(folder)) fs.mkdirSync(folder); + fs.writeFileSync(folder + "/input.js", code); + fs.writeFileSync(folder + "/options.json", options); +} +``` \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-field/input.js new file mode 100644 index 000000000000..bb68229716d6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-field/input.js @@ -0,0 +1,4 @@ +class A { + #x = 0; + #x = 0; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-field/output.json new file mode 100644 index 000000000000..b69a455a0f53 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-field/output.json @@ -0,0 +1,224 @@ +{ + "type": "File", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateProperty", + "start": 22, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-get/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-get/input.js new file mode 100644 index 000000000000..95514f1d83fd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-get/input.js @@ -0,0 +1,4 @@ +class A { + #x = 0; + get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-get/output.json new file mode 100644 index 000000000000..62a6d3a10f71 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-get/output.json @@ -0,0 +1,227 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:6)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateMethod", + "start": 22, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 26, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-method/input.js similarity index 64% rename from packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/input.js rename to packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-method/input.js index 26122843af16..82fa3236ab43 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/input.js +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-method/input.js @@ -1,4 +1,4 @@ class A { + #x = 0; #x() {} - #x; } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-method/output.json new file mode 100644 index 000000000000..0d301cbb847c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-method/output.json @@ -0,0 +1,226 @@ +{ + "type": "File", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateMethod", + "start": 22, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 27, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-set/input.js new file mode 100644 index 000000000000..4bb80c110229 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-set/input.js @@ -0,0 +1,4 @@ +class A { + #x = 0; + set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-set/output.json new file mode 100644 index 000000000000..99af2b8a69a0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-set/output.json @@ -0,0 +1,245 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:6)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateMethod", + "start": 22, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 26, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 32, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-field/input.js new file mode 100644 index 000000000000..67c3cc794ef3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-field/input.js @@ -0,0 +1,4 @@ +class A { + #x = 0; + static #x = 0; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-field/output.json new file mode 100644 index 000000000000..45ed934caa5d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-field/output.json @@ -0,0 +1,224 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateProperty", + "start": 22, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-get/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-get/input.js new file mode 100644 index 000000000000..1f53201d6970 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-get/input.js @@ -0,0 +1,4 @@ +class A { + #x = 0; + static get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-get/output.json new file mode 100644 index 000000000000..d4e1a7d1e628 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-get/output.json @@ -0,0 +1,227 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:13)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateMethod", + "start": 22, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-method/input.js new file mode 100644 index 000000000000..a1229c8992f1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-method/input.js @@ -0,0 +1,4 @@ +class A { + #x = 0; + static #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-method/output.json new file mode 100644 index 000000000000..3fa0178df710 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-method/output.json @@ -0,0 +1,226 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateMethod", + "start": 22, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-set/input.js new file mode 100644 index 000000000000..4221a39406f9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-set/input.js @@ -0,0 +1,4 @@ +class A { + #x = 0; + static set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-set/output.json new file mode 100644 index 000000000000..3e3d50633689 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-static-set/output.json @@ -0,0 +1,245 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:13)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateMethod", + "start": 22, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 39, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-field/input.js new file mode 100644 index 000000000000..45adc3907e0a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-field/input.js @@ -0,0 +1,4 @@ +class A { + get #x() {} + #x = 0; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-field/output.json new file mode 100644 index 000000000000..e7c6f5e6bb2e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-field/output.json @@ -0,0 +1,227 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateProperty", + "start": 26, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 26, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-get/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-get/input.js new file mode 100644 index 000000000000..7818246e3fd0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-get/input.js @@ -0,0 +1,4 @@ +class A { + get #x() {} + get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-get/output.json new file mode 100644 index 000000000000..c63e32cca838 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-get/output.json @@ -0,0 +1,230 @@ +{ + "type": "File", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:6)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 26, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 30, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 35, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-method/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/input.js rename to packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-method/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-method/output.json new file mode 100644 index 000000000000..9fa1c2917097 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-method/output.json @@ -0,0 +1,229 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 26, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 26, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/input.js new file mode 100644 index 000000000000..f5b4f4bb8764 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/input.js @@ -0,0 +1,4 @@ +class A { + get #x() {} + set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/output.json new file mode 100644 index 000000000000..109fbb70bafe --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/output.json @@ -0,0 +1,245 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 26, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 30, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 33, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-field/input.js new file mode 100644 index 000000000000..c915535f827c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-field/input.js @@ -0,0 +1,4 @@ +class A { + get #x() {} + static #x = 0; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-field/output.json new file mode 100644 index 000000000000..5c6ec686f516 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-field/output.json @@ -0,0 +1,227 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateProperty", + "start": 26, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 38, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-get/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-get/input.js new file mode 100644 index 000000000000..88136bae1fe0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-get/input.js @@ -0,0 +1,4 @@ +class A { + get #x() {} + static get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-get/output.json new file mode 100644 index 000000000000..65ec3150bbea --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-get/output.json @@ -0,0 +1,230 @@ +{ + "type": "File", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:13)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 26, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 37, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 38, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 42, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-method/input.js new file mode 100644 index 000000000000..73288616ed47 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-method/input.js @@ -0,0 +1,4 @@ +class A { + get #x() {} + static #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-method/output.json new file mode 100644 index 000000000000..68c3ff18b28b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-method/output.json @@ -0,0 +1,229 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 26, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-set/input.js new file mode 100644 index 000000000000..bce8d6c24669 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-set/input.js @@ -0,0 +1,4 @@ +class A { + get #x() {} + static set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-set/output.json new file mode 100644 index 000000000000..470062c22b80 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-static-set/output.json @@ -0,0 +1,248 @@ +{ + "type": "File", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:13)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 21, + "end": 23, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 13 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 26, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 37, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 38, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 43, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-field/input.js similarity index 64% rename from packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/input.js rename to packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-field/input.js index 6dde01adc90e..48e8c322691f 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/input.js +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-field/input.js @@ -1,4 +1,4 @@ class A { - #x; #x() {} + #x = 0; } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-field/output.json new file mode 100644 index 000000000000..d32285dc3ae0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-field/output.json @@ -0,0 +1,226 @@ +{ + "type": "File", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateProperty", + "start": 22, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-get/input.js similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/input.js rename to packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-get/input.js diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-get/output.json new file mode 100644 index 000000000000..8dbf70cdb04b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-get/output.json @@ -0,0 +1,229 @@ +{ + "type": "File", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:6)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 35, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 22, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 26, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-method/input.js new file mode 100644 index 000000000000..c1a8a11a361a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-method/input.js @@ -0,0 +1,4 @@ +class A { + #x() {} + #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-method/output.json new file mode 100644 index 000000000000..7fe8d83f31e1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-method/output.json @@ -0,0 +1,228 @@ +{ + "type": "File", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 22, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 27, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-set/input.js new file mode 100644 index 000000000000..3ac461db7a73 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-set/input.js @@ -0,0 +1,4 @@ +class A { + #x() {} + set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-set/output.json new file mode 100644 index 000000000000..35d6a2f29be3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-instance-set/output.json @@ -0,0 +1,247 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:6)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 22, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 26, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 27, + "end": 28, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 32, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-field/input.js new file mode 100644 index 000000000000..f9f1b1015567 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-field/input.js @@ -0,0 +1,4 @@ +class A { + #x() {} + static #x = 0; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-field/output.json new file mode 100644 index 000000000000..8e3500892679 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-field/output.json @@ -0,0 +1,226 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateProperty", + "start": 22, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-get/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-get/input.js new file mode 100644 index 000000000000..fdf3bef6984c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-get/input.js @@ -0,0 +1,4 @@ +class A { + #x() {} + static get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-get/output.json new file mode 100644 index 000000000000..1d94cf85460b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-get/output.json @@ -0,0 +1,229 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:13)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 22, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-method/input.js new file mode 100644 index 000000000000..a1aa1d542441 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-method/input.js @@ -0,0 +1,4 @@ +class A { + #x() {} + static #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-method/output.json new file mode 100644 index 000000000000..fd8bc97f5bbd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-method/output.json @@ -0,0 +1,228 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 22, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-set/input.js new file mode 100644 index 000000000000..3b2e1e37704a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-set/input.js @@ -0,0 +1,4 @@ +class A { + #x() {} + static set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-set/output.json new file mode 100644 index 000000000000..b984451082ec --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-method-static-set/output.json @@ -0,0 +1,247 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:13)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 19, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 9 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 22, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 39, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-field/input.js new file mode 100644 index 000000000000..095f191f877b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-field/input.js @@ -0,0 +1,4 @@ +class A { + set #x(_) {} + #x = 0; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-field/output.json new file mode 100644 index 000000000000..83b198523bad --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-field/output.json @@ -0,0 +1,245 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateProperty", + "start": 27, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 27, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/input.js new file mode 100644 index 000000000000..8e7e5544b96e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/input.js @@ -0,0 +1,4 @@ +class A { + set #x(_) {} + get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/output.json new file mode 100644 index 000000000000..08513a3011e8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/output.json @@ -0,0 +1,245 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 27, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-method/input.js new file mode 100644 index 000000000000..f0d912243eef --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-method/input.js @@ -0,0 +1,4 @@ +class A { + set #x(_) {} + #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-method/output.json new file mode 100644 index 000000000000..dceb3bd390a6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-method/output.json @@ -0,0 +1,247 @@ +{ + "type": "File", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 27, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 27, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 28, + "end": 29, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 32, + "end": 34, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-set/input.js new file mode 100644 index 000000000000..d4e2624635cb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-set/input.js @@ -0,0 +1,4 @@ +class A { + set #x(_) {} + set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-set/output.json new file mode 100644 index 000000000000..7add5089ff95 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-set/output.json @@ -0,0 +1,266 @@ +{ + "type": "File", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:6)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 27, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 32, + "end": 33, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 37, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-field/input.js new file mode 100644 index 000000000000..3e3b25f208b6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-field/input.js @@ -0,0 +1,4 @@ +class A { + set #x(_) {} + static #x = 0; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-field/output.json new file mode 100644 index 000000000000..06e380aea7f2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-field/output.json @@ -0,0 +1,245 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateProperty", + "start": 27, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-get/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-get/input.js new file mode 100644 index 000000000000..3c0764dfad45 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-get/input.js @@ -0,0 +1,4 @@ +class A { + set #x(_) {} + static get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-get/output.json new file mode 100644 index 000000000000..339ca0c0d546 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-get/output.json @@ -0,0 +1,248 @@ +{ + "type": "File", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:13)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 27, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 43, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-method/input.js new file mode 100644 index 000000000000..ce3a89c61108 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-method/input.js @@ -0,0 +1,4 @@ +class A { + set #x(_) {} + static #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-method/output.json new file mode 100644 index 000000000000..184125273236 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-method/output.json @@ -0,0 +1,247 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 27, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 39, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-set/input.js new file mode 100644 index 000000000000..7a5e410fdd91 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-set/input.js @@ -0,0 +1,4 @@ +class A { + set #x(_) {} + static set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-set/output.json new file mode 100644 index 000000000000..128468f9659f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-static-set/output.json @@ -0,0 +1,266 @@ +{ + "type": "File", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:13)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 19, + "end": 20, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 27, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 44, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-field/input.js new file mode 100644 index 000000000000..3de944035833 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-field/input.js @@ -0,0 +1,4 @@ +class A { + static #x = 0; + #x = 0; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-field/output.json new file mode 100644 index 000000000000..0724b9e565a2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-field/output.json @@ -0,0 +1,224 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateProperty", + "start": 29, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-get/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-get/input.js new file mode 100644 index 000000000000..dd34390358ee --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-get/input.js @@ -0,0 +1,4 @@ +class A { + static #x = 0; + get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-get/output.json new file mode 100644 index 000000000000..1a3e576e3b80 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-get/output.json @@ -0,0 +1,227 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:6)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateMethod", + "start": 29, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-method/input.js new file mode 100644 index 000000000000..ae2b2f980b8a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-method/input.js @@ -0,0 +1,4 @@ +class A { + static #x = 0; + #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-method/output.json new file mode 100644 index 000000000000..d1c2347cb125 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-method/output.json @@ -0,0 +1,226 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateMethod", + "start": 29, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-set/input.js new file mode 100644 index 000000000000..8962661873c3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-set/input.js @@ -0,0 +1,4 @@ +class A { + static #x = 0; + set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-set/output.json new file mode 100644 index 000000000000..0a638b426ae2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-instance-set/output.json @@ -0,0 +1,245 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:6)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateMethod", + "start": 29, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 39, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-field/input.js new file mode 100644 index 000000000000..f30eaf46a76c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-field/input.js @@ -0,0 +1,4 @@ +class A { + static #x = 0; + static #x = 0; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-field/output.json new file mode 100644 index 000000000000..7cf03fd42bb7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-field/output.json @@ -0,0 +1,224 @@ +{ + "type": "File", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateProperty", + "start": 29, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-get/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-get/input.js new file mode 100644 index 000000000000..27598cc9b1ef --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-get/input.js @@ -0,0 +1,4 @@ +class A { + static #x = 0; + static get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-get/output.json new file mode 100644 index 000000000000..98d454b78c67 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-get/output.json @@ -0,0 +1,227 @@ +{ + "type": "File", + "start": 0, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:13)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateMethod", + "start": 29, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 40, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 45, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-method/input.js new file mode 100644 index 000000000000..3530aef207c1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-method/input.js @@ -0,0 +1,4 @@ +class A { + static #x = 0; + static #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-method/output.json new file mode 100644 index 000000000000..74c7d35d4fa3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-method/output.json @@ -0,0 +1,226 @@ +{ + "type": "File", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateMethod", + "start": 29, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 41, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-set/input.js new file mode 100644 index 000000000000..705e02850f9c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-set/input.js @@ -0,0 +1,4 @@ +class A { + static #x = 0; + static set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-set/output.json new file mode 100644 index 000000000000..379ee84d2d94 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-field-static-set/output.json @@ -0,0 +1,245 @@ +{ + "type": "File", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:13)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ClassPrivateMethod", + "start": 29, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 40, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 43, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 46, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-field/input.js new file mode 100644 index 000000000000..5063908de961 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-field/input.js @@ -0,0 +1,4 @@ +class A { + static get #x() {} + #x = 0; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-field/output.json new file mode 100644 index 000000000000..113e8bbbbeeb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-field/output.json @@ -0,0 +1,227 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateProperty", + "start": 33, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 38, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-get/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-get/input.js new file mode 100644 index 000000000000..819cf9b38c3c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-get/input.js @@ -0,0 +1,4 @@ +class A { + static get #x() {} + get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-get/output.json new file mode 100644 index 000000000000..c7fd9652e864 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-get/output.json @@ -0,0 +1,230 @@ +{ + "type": "File", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:6)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 33, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 37, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 38, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 42, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-method/input.js new file mode 100644 index 000000000000..e22778f87886 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-method/input.js @@ -0,0 +1,4 @@ +class A { + static get #x() {} + #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-method/output.json new file mode 100644 index 000000000000..67e2f41f4ca2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-method/output.json @@ -0,0 +1,229 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 33, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-set/input.js new file mode 100644 index 000000000000..21bab2d3e874 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-set/input.js @@ -0,0 +1,4 @@ +class A { + static get #x() {} + set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-set/output.json new file mode 100644 index 000000000000..ef06223a73fb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-instance-set/output.json @@ -0,0 +1,248 @@ +{ + "type": "File", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:6)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 33, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 37, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 38, + "end": 39, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 40, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 43, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-field/input.js new file mode 100644 index 000000000000..70ab10f5eafd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-field/input.js @@ -0,0 +1,4 @@ +class A { + static get #x() {} + static #x = 0; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-field/output.json new file mode 100644 index 000000000000..e0271651aae5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-field/output.json @@ -0,0 +1,227 @@ +{ + "type": "File", + "start": 0, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateProperty", + "start": 33, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 40, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-get/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-get/input.js new file mode 100644 index 000000000000..dcb23a94a7fa --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-get/input.js @@ -0,0 +1,4 @@ +class A { + static get #x() {} + static get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-get/output.json new file mode 100644 index 000000000000..dd680abb9878 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-get/output.json @@ -0,0 +1,230 @@ +{ + "type": "File", + "start": 0, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:13)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 33, + "end": 51, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 44, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 49, + "end": 51, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-method/input.js new file mode 100644 index 000000000000..5cf7a3e6524f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-method/input.js @@ -0,0 +1,4 @@ +class A { + static get #x() {} + static #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-method/output.json new file mode 100644 index 000000000000..297ceb941b4b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-method/output.json @@ -0,0 +1,229 @@ +{ + "type": "File", + "start": 0, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 33, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 40, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 45, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/input.js new file mode 100644 index 000000000000..f13a22c0b724 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/input.js @@ -0,0 +1,4 @@ +class A { + static get #x() {} + static set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/output.json new file mode 100644 index 000000000000..cb14ff5bd58b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/output.json @@ -0,0 +1,245 @@ +{ + "type": "File", + "start": 0, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 18 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 33, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 44, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 47, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 50, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-field/input.js new file mode 100644 index 000000000000..2e87605b197c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-field/input.js @@ -0,0 +1,4 @@ +class A { + static #x() {} + #x = 0; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-field/output.json new file mode 100644 index 000000000000..e34c853586a9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-field/output.json @@ -0,0 +1,226 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 24, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateProperty", + "start": 29, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-get/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-get/input.js new file mode 100644 index 000000000000..d714c04e0f50 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-get/input.js @@ -0,0 +1,4 @@ +class A { + static #x() {} + get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-get/output.json new file mode 100644 index 000000000000..c6b5cb7b3f5b --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-get/output.json @@ -0,0 +1,229 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:6)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 24, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 29, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-method/input.js new file mode 100644 index 000000000000..520c9088d109 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-method/input.js @@ -0,0 +1,4 @@ +class A { + static #x() {} + #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-method/output.json new file mode 100644 index 000000000000..56572b56584e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-method/output.json @@ -0,0 +1,228 @@ +{ + "type": "File", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 38, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 24, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 29, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 30, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-set/input.js new file mode 100644 index 000000000000..b2c76dfa77f4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-set/input.js @@ -0,0 +1,4 @@ +class A { + static #x() {} + set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-set/output.json new file mode 100644 index 000000000000..b8a0773cf4d6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-instance-set/output.json @@ -0,0 +1,247 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:6)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 24, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 29, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 33, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 34, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 36, + "end": 37, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 39, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-field/input.js new file mode 100644 index 000000000000..24d63ae53646 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-field/input.js @@ -0,0 +1,4 @@ +class A { + static #x() {} + static #x = 0; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-field/output.json new file mode 100644 index 000000000000..dfaf6f688e1e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-field/output.json @@ -0,0 +1,226 @@ +{ + "type": "File", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 24, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateProperty", + "start": 29, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-get/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-get/input.js new file mode 100644 index 000000000000..8a3c3ff6a962 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-get/input.js @@ -0,0 +1,4 @@ +class A { + static #x() {} + static get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-get/output.json new file mode 100644 index 000000000000..e019b3c9aaaa --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-get/output.json @@ -0,0 +1,229 @@ +{ + "type": "File", + "start": 0, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:13)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 49, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 24, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 29, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 40, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 45, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-method/input.js new file mode 100644 index 000000000000..316f6d89f48f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-method/input.js @@ -0,0 +1,4 @@ +class A { + static #x() {} + static #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-method/output.json new file mode 100644 index 000000000000..029d9cd6f8a3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-method/output.json @@ -0,0 +1,228 @@ +{ + "type": "File", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 24, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 29, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 36, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 37, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 41, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-set/input.js new file mode 100644 index 000000000000..590b70f3987e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-set/input.js @@ -0,0 +1,4 @@ +class A { + static #x() {} + static set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-set/output.json new file mode 100644 index 000000000000..d788eda7fd02 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-method-static-set/output.json @@ -0,0 +1,247 @@ +{ + "type": "File", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:13)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 24, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 29, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 40, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 43, + "end": 44, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 46, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-field/input.js new file mode 100644 index 000000000000..315703f68bce --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-field/input.js @@ -0,0 +1,4 @@ +class A { + static set #x(_) {} + #x = 0; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-field/output.json new file mode 100644 index 000000000000..b50939f38415 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-field/output.json @@ -0,0 +1,245 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateProperty", + "start": 34, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-get/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-get/input.js new file mode 100644 index 000000000000..b2515ac17405 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-get/input.js @@ -0,0 +1,4 @@ +class A { + static set #x(_) {} + get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-get/output.json new file mode 100644 index 000000000000..ddea1a756790 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-get/output.json @@ -0,0 +1,248 @@ +{ + "type": "File", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:6)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 34, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 43, + "end": 45, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-method/input.js new file mode 100644 index 000000000000..8249487ab52e --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-method/input.js @@ -0,0 +1,4 @@ +class A { + static set #x(_) {} + #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-method/output.json new file mode 100644 index 000000000000..3b9334d91225 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-method/output.json @@ -0,0 +1,247 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:2)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 34, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 35, + "end": 36, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 39, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 9 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-set/input.js new file mode 100644 index 000000000000..3b7d8653ee40 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-set/input.js @@ -0,0 +1,4 @@ +class A { + static set #x(_) {} + set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-set/output.json new file mode 100644 index 000000000000..b56cf90f93db --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-instance-set/output.json @@ -0,0 +1,266 @@ +{ + "type": "File", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:6)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 48, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 34, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 38, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 3, + "column": 7 + }, + "end": { + "line": 3, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 41, + "end": 42, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 10 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 44, + "end": 46, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 3, + "column": 14 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-field/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-field/input.js new file mode 100644 index 000000000000..3dfbfe2861d4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-field/input.js @@ -0,0 +1,4 @@ +class A { + static set #x(_) {} + static #x = 0; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-field/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-field/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-field/output.json new file mode 100644 index 000000000000..c063c6722c93 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-field/output.json @@ -0,0 +1,245 @@ +{ + "type": "File", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateProperty", + "start": 34, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 41, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 42, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "NumericLiteral", + "start": 46, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/input.js new file mode 100644 index 000000000000..5ac842d7dc2f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/input.js @@ -0,0 +1,4 @@ +class A { + static set #x(_) {} + static get #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/output.json new file mode 100644 index 000000000000..06b5a7c528b0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/output.json @@ -0,0 +1,245 @@ +{ + "type": "File", + "start": 0, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 54, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 34, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 45, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 46, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 50, + "end": 52, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 20 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-method/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-method/input.js new file mode 100644 index 000000000000..3f3537bcb0a0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-method/input.js @@ -0,0 +1,4 @@ +class A { + static set #x(_) {} + static #x() {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-method/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-method/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-method/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-method/output.json new file mode 100644 index 000000000000..78b17369506f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-method/output.json @@ -0,0 +1,247 @@ +{ + "type": "File", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:9)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 34, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 41, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 3, + "column": 11 + } + }, + "id": { + "type": "Identifier", + "start": 42, + "end": 43, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 46, + "end": 48, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 16 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-set/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-set/input.js new file mode 100644 index 000000000000..d6337e16b74f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-set/input.js @@ -0,0 +1,4 @@ +class A { + static set #x(_) {} + static set #x(_) {} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-set/options.json new file mode 100644 index 000000000000..af02072af9d9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-set/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties", "classPrivateMethods"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-set/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-set/output.json new file mode 100644 index 000000000000..146f1c39f34d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-set/output.json @@ -0,0 +1,266 @@ +{ + "type": "File", + "start": 0, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Duplicate private name #x (3:13)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateMethod", + "start": 12, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 24, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 26, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 16 + }, + "end": { + "line": 2, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 29, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 19 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "body": [], + "directives": [] + } + }, + { + "type": "ClassPrivateMethod", + "start": 34, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "static": true, + "key": { + "type": "PrivateName", + "start": 45, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 13 + }, + "end": { + "line": 3, + "column": 15 + } + }, + "id": { + "type": "Identifier", + "start": 46, + "end": 47, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 15 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start": 48, + "end": 49, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 17 + }, + "identifierName": "_" + }, + "name": "_" + } + ], + "body": { + "type": "BlockStatement", + "start": 51, + "end": 53, + "loc": { + "start": { + "line": 3, + "column": 19 + }, + "end": { + "line": 3, + "column": 21 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/input.js deleted file mode 100644 index df22b36e0ae8..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/input.js +++ /dev/null @@ -1,4 +0,0 @@ -class A { - #x = 1; - static #x = 2; -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/options.json deleted file mode 100644 index 1ca5069a3a2f..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/options.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "plugins": [ - "classPrivateProperties" - ] -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/input.js deleted file mode 100644 index 83ddd3d8a226..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/input.js +++ /dev/null @@ -1,4 +0,0 @@ -class A { - #x = 1; - #x = 2; -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/options.json deleted file mode 100644 index 1ca5069a3a2f..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/options.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "plugins": [ - "classPrivateProperties" - ] -} \ No newline at end of file From 47d46a3c059215e45338cb207d61acfbe6f2cab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 19 Sep 2019 01:41:44 +0200 Subject: [PATCH 04/12] Test undeclared private names --- .../declared-later-outer-class/input.js | 9 + .../declared-later-outer-class/options.json | 3 + .../declared-later-outer-class/output.json | 352 ++++++++++++++++++ .../declared-later-same-class/input.js | 4 + .../declared-later-same-class/options.json | 3 + .../declared-later-same-class/output.json | 245 ++++++++++++ .../undeclared-nested/input.js | 6 + .../undeclared-nested/options.json | 4 + .../undeclared-top-level/input.js | 1 + .../undeclared-top-level/options.json | 4 + 10 files changed, 631 insertions(+) create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-outer-class/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-outer-class/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-outer-class/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-same-class/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-same-class/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-same-class/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/input.js create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-outer-class/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-outer-class/input.js new file mode 100644 index 000000000000..e4e3ae4c3870 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-outer-class/input.js @@ -0,0 +1,9 @@ +class B { + meth() { + class A { + #x = this.#y; + } + } + + #y; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-outer-class/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-outer-class/options.json new file mode 100644 index 000000000000..25819769bb20 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-outer-class/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-outer-class/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-outer-class/output.json new file mode 100644 index 000000000000..1bd1092fae92 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-outer-class/output.json @@ -0,0 +1,352 @@ +{ + "type": "File", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "B" + }, + "name": "B" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 73, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 9, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 12, + "end": 64, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 12, + "end": 16, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 6 + }, + "identifierName": "meth" + }, + "name": "meth" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 19, + "end": 64, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "start": 25, + "end": 60, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "id": { + "type": "Identifier", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 11 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 33, + "end": 60, + "loc": { + "start": { + "line": 3, + "column": 12 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 41, + "end": 54, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 19 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 41, + "end": 43, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 8 + } + }, + "id": { + "type": "Identifier", + "start": 42, + "end": 43, + "loc": { + "start": { + "line": 4, + "column": 7 + }, + "end": { + "line": 4, + "column": 8 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "MemberExpression", + "start": 46, + "end": 53, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "object": { + "type": "ThisExpression", + "start": 46, + "end": 50, + "loc": { + "start": { + "line": 4, + "column": 11 + }, + "end": { + "line": 4, + "column": 15 + } + } + }, + "property": { + "type": "PrivateName", + "start": 51, + "end": 53, + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 52, + "end": 53, + "loc": { + "start": { + "line": 4, + "column": 17 + }, + "end": { + "line": 4, + "column": 18 + }, + "identifierName": "y" + }, + "name": "y" + } + }, + "computed": false + } + } + ] + } + } + ], + "directives": [] + } + }, + { + "type": "ClassPrivateProperty", + "start": 68, + "end": 71, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 5 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 68, + "end": 70, + "loc": { + "start": { + "line": 8, + "column": 2 + }, + "end": { + "line": 8, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 69, + "end": 70, + "loc": { + "start": { + "line": 8, + "column": 3 + }, + "end": { + "line": 8, + "column": 4 + }, + "identifierName": "y" + }, + "name": "y" + } + }, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-same-class/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-same-class/input.js new file mode 100644 index 000000000000..bd7c6a515696 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-same-class/input.js @@ -0,0 +1,4 @@ +class A { + #x = this.#y; + #y; +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-same-class/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-same-class/options.json new file mode 100644 index 000000000000..25819769bb20 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-same-class/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["classPrivateProperties"] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-same-class/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-same-class/output.json new file mode 100644 index 000000000000..3c7ad5de9321 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/declared-later-same-class/output.json @@ -0,0 +1,245 @@ +{ + "type": "File", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": { + "type": "MemberExpression", + "start": 17, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "object": { + "type": "ThisExpression", + "start": 17, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 11 + } + } + }, + "property": { + "type": "PrivateName", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "id": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 14 + }, + "identifierName": "y" + }, + "name": "y" + } + }, + "computed": false + } + }, + { + "type": "ClassPrivateProperty", + "start": 28, + "end": 31, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 5 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 28, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 3, + "column": 3 + }, + "end": { + "line": 3, + "column": 4 + }, + "identifierName": "y" + }, + "name": "y" + } + }, + "value": null + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/input.js new file mode 100644 index 000000000000..3177068d7eb0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/input.js @@ -0,0 +1,6 @@ +class A { + #x; + meth() { + var prop = foo.#priv; + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/options.json new file mode 100644 index 000000000000..f5d54118131a --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["classPrivateProperties"], + "throws": "Private name #priv is not defined (4:19)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/input.js b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/input.js new file mode 100644 index 000000000000..10607b89b6db --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/input.js @@ -0,0 +1 @@ +var prop = foo.#priv; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json new file mode 100644 index 000000000000..9682fa229092 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["classPrivateProperties"], + "throws": "Unexpected character '#' (1:15)" +} \ No newline at end of file From 10a0322d95ded6291b1679e0cf9ef06545887c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 19 Sep 2019 01:47:57 +0200 Subject: [PATCH 05/12] Better error message for top-level private names --- packages/babel-parser/src/tokenizer/index.js | 10 ++-------- .../undeclared-top-level/options.json | 2 +- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index 27f1aaa15f96..a4e2de67a242 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -391,14 +391,8 @@ export default class Tokenizer extends LocationParser { } if ( - (this.hasPlugin("classPrivateProperties") || - this.hasPlugin("classPrivateMethods")) && - this.state.classLevel > 0 - ) { - ++this.state.pos; - this.finishToken(tt.hash); - return; - } else if ( + this.hasPlugin("classPrivateProperties") || + this.hasPlugin("classPrivateMethods") || this.getPluginOption("pipelineOperator", "proposal") === "smart" ) { this.finishOp(tt.hash, 1); diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json index 9682fa229092..1a24d82b0b75 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json @@ -1,4 +1,4 @@ { "plugins": ["classPrivateProperties"], - "throws": "Unexpected character '#' (1:15)" + "throws": "Private name #priv is not defined (1:15)" } \ No newline at end of file From 868b3ffa576c342bc3388e228cbc0d560bce5947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 19 Sep 2019 02:10:17 +0200 Subject: [PATCH 06/12] Fix flow --- packages/babel-parser/src/util/scope.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/babel-parser/src/util/scope.js b/packages/babel-parser/src/util/scope.js index 5e3ca05a8cd5..55de27238dad 100644 --- a/packages/babel-parser/src/util/scope.js +++ b/packages/babel-parser/src/util/scope.js @@ -31,8 +31,6 @@ export class Scope { lexical: string[] = []; // A list of lexically-declared FunctionDeclaration names in the current lexical scope functions: string[] = []; - // A list of private names defined in the current class body - privateNames: string[] = []; constructor(flags: ScopeFlags) { this.flags = flags; @@ -40,10 +38,14 @@ export class Scope { } export class ClassScope { - privateNames: string[] = new Set(); + // A list of private named declared in the current class + privateNames: Set = new Set(); + // A list of private getters of setters without their counterpart loneAccessors: Map = new Map(); + // A list of private names used before being defined, mapping to + // their position. undefinedPrivateNames: Map = new Map(); } @@ -227,7 +229,7 @@ export default class ScopeHandler { } } - raiseUndeclaredPrivateName(name, pos) { + raiseUndeclaredPrivateName(name: string, pos: number) { this.raise(pos, `Private name #${name} is not defined`); } From d9781dba3aa6806a740bb5668e65363418956110 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Tue, 24 Sep 2019 22:45:34 +0200 Subject: [PATCH 07/12] Update test262 whitelist --- scripts/parser-tests/test262/whitelist.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/parser-tests/test262/whitelist.txt b/scripts/parser-tests/test262/whitelist.txt index cb608d6442b1..d7a38c2104cf 100644 --- a/scripts/parser-tests/test262/whitelist.txt +++ b/scripts/parser-tests/test262/whitelist.txt @@ -2,9 +2,15 @@ language/expressions/class/elements/syntax/early-errors/grammar-private-field-on language/expressions/class/elements/syntax/early-errors/grammar-private-field-on-object-destructuring.js(strict mode) language/expressions/object/method-definition/private-name-early-error-async-gen-inside-class.js(default) language/expressions/object/method-definition/private-name-early-error-async-gen-inside-class.js(strict mode) +language/expressions/object/method-definition/private-name-early-error-async-gen.js(default) +language/expressions/object/method-definition/private-name-early-error-async-gen.js(strict mode) language/expressions/object/method-definition/private-name-early-error-gen-inside-class.js(default) language/expressions/object/method-definition/private-name-early-error-gen-inside-class.js(strict mode) +language/expressions/object/method-definition/private-name-early-error-gen.js(default) +language/expressions/object/method-definition/private-name-early-error-gen.js(strict mode) language/expressions/object/method-definition/private-name-early-error-method-inside-class.js(default) language/expressions/object/method-definition/private-name-early-error-method-inside-class.js(strict mode) +language/expressions/object/method-definition/private-name-early-error-method.js(default) +language/expressions/object/method-definition/private-name-early-error-method.js(strict mode) language/statements/class/elements/syntax/early-errors/grammar-private-field-on-object-destructuring.js(default) language/statements/class/elements/syntax/early-errors/grammar-private-field-on-object-destructuring.js(strict mode) From 940fe00e3acb1a9bc698f1b5c89e2637a1dd45f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Mon, 2 Dec 2019 23:05:24 +0100 Subject: [PATCH 08/12] Update fixtures --- .../class-private-names-duplicated/README.md | 5 - .../instance-get-instance-set/options.json | 3 - .../instance-set-instance-get/options.json | 3 - .../options.json | 0 .../static-get-static-set/options.json | 3 - .../static-set-static-get/options.json | 3 - .../undeclared-nested/options.json | 5 +- .../undeclared-nested/output.json | 309 ++++++++++++++++++ .../undeclared-top-level/options.json | 5 +- .../undeclared-top-level/output.json | 153 +++++++++ 10 files changed, 468 insertions(+), 21 deletions(-) delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/options.json delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/options.json rename packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/{instance-field-instance-field => }/options.json (100%) delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/options.json delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/options.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/output.json create mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/README.md b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/README.md index f735bf293cee..d8f726880604 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/README.md +++ b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/README.md @@ -18,14 +18,9 @@ for (var f1 in feat) for (var f2 in feat) for (var p1 in placement) for (var p2 ${placement[p2]}${feat[f2]} }`; var name = `${p1}-${f1}-${p2}-${f2}`; - var options = `{ - "plugins": ["classPrivateProperties", "classPrivateMethods"], - "throws": "Duplicate private name #x (3:${2 + placement[p2].length + feat[f2].indexOf("#")})" -}` var folder = "packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/" + name; if (!fs.existsSync(folder)) fs.mkdirSync(folder); fs.writeFileSync(folder + "/input.js", code); - fs.writeFileSync(folder + "/options.json", options); } ``` \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/options.json deleted file mode 100644 index af02072af9d9..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-get-instance-set/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["classPrivateProperties", "classPrivateMethods"] -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/options.json deleted file mode 100644 index af02072af9d9..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-set-instance-get/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["classPrivateProperties", "classPrivateMethods"] -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-field/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/options.json similarity index 100% rename from packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/instance-field-instance-field/options.json rename to packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/options.json diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/options.json deleted file mode 100644 index af02072af9d9..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-get-static-set/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["classPrivateProperties", "classPrivateMethods"] -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/options.json deleted file mode 100644 index af02072af9d9..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-names-duplicated/static-set-static-get/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "plugins": ["classPrivateProperties", "classPrivateMethods"] -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/options.json index f5d54118131a..1ca5069a3a2f 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/options.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/options.json @@ -1,4 +1,5 @@ { - "plugins": ["classPrivateProperties"], - "throws": "Private name #priv is not defined (4:19)" + "plugins": [ + "classPrivateProperties" + ] } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/output.json new file mode 100644 index 000000000000..f13ed5f0567c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-nested/output.json @@ -0,0 +1,309 @@ +{ + "type": "File", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "errors": [ + "SyntaxError: Private name #priv is not defined (4:19)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 8, + "end": 58, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 6, + "column": 1 + } + }, + "body": [ + { + "type": "ClassPrivateProperty", + "start": 12, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 5 + } + }, + "static": false, + "key": { + "type": "PrivateName", + "start": 12, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "id": { + "type": "Identifier", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 2, + "column": 3 + }, + "end": { + "line": 2, + "column": 4 + }, + "identifierName": "x" + }, + "name": "x" + } + }, + "value": null + }, + { + "type": "ClassMethod", + "start": 18, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "static": false, + "key": { + "type": "Identifier", + "start": 18, + "end": 22, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 6 + }, + "identifierName": "meth" + }, + "name": "meth" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 25, + "end": 56, + "loc": { + "start": { + "line": 3, + "column": 9 + }, + "end": { + "line": 5, + "column": 3 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 31, + "end": 52, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 25 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 35, + "end": 51, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 24 + } + }, + "id": { + "type": "Identifier", + "start": 35, + "end": 39, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 12 + }, + "identifierName": "prop" + }, + "name": "prop" + }, + "init": { + "type": "MemberExpression", + "start": 42, + "end": 51, + "loc": { + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 4, + "column": 24 + } + }, + "object": { + "type": "Identifier", + "start": 42, + "end": 45, + "loc": { + "start": { + "line": 4, + "column": 15 + }, + "end": { + "line": 4, + "column": 18 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "property": { + "type": "PrivateName", + "start": 46, + "end": 51, + "loc": { + "start": { + "line": 4, + "column": 19 + }, + "end": { + "line": 4, + "column": 24 + } + }, + "id": { + "type": "Identifier", + "start": 47, + "end": 51, + "loc": { + "start": { + "line": 4, + "column": 20 + }, + "end": { + "line": 4, + "column": 24 + }, + "identifierName": "priv" + }, + "name": "priv" + } + }, + "computed": false + } + } + ], + "kind": "var" + } + ], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json index 1a24d82b0b75..1ca5069a3a2f 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/options.json @@ -1,4 +1,5 @@ { - "plugins": ["classPrivateProperties"], - "throws": "Private name #priv is not defined (1:15)" + "plugins": [ + "classPrivateProperties" + ] } \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/output.json new file mode 100644 index 000000000000..88c45d101fa8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/undeclared-top-level/output.json @@ -0,0 +1,153 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "errors": [ + "SyntaxError: Private name #priv is not defined (1:15)" + ], + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "prop" + }, + "name": "prop" + }, + "init": { + "type": "MemberExpression", + "start": 11, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "object": { + "type": "Identifier", + "start": 11, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "foo" + }, + "name": "foo" + }, + "property": { + "type": "PrivateName", + "start": 15, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "id": { + "type": "Identifier", + "start": 16, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "priv" + }, + "name": "priv" + } + }, + "computed": false + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file From b8d83122cc584e2fa94ba58886af9ce9642c1730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Fri, 10 Jan 2020 01:16:54 +0100 Subject: [PATCH 09/12] Update flow whitelist --- scripts/parser-tests/flow/whitelist.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/parser-tests/flow/whitelist.txt b/scripts/parser-tests/flow/whitelist.txt index 8e24ebf0a28d..668fb625d47d 100644 --- a/scripts/parser-tests/flow/whitelist.txt +++ b/scripts/parser-tests/flow/whitelist.txt @@ -14,10 +14,4 @@ export_import_reserved_words/migrated_0003.js export_statements/export_trailing_comma.js nullish_coalescing/precedence_and.js nullish_coalescing/precedence_or.js -private_class_properties/getter_and_field.js -private_class_properties/getter_duplicate.js -private_class_properties/multiple.js -private_class_properties/multiple.js -private_class_properties/setter_and_field.js -private_class_properties/setter_duplicate.js types/member/reserved_words.js From 9d74632d9407056a6ccc0f002d00c286e36803c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Fri, 10 Jan 2020 01:37:08 +0100 Subject: [PATCH 10/12] Remove old output.json --- .../duplicated-accessor-method/output.json | 229 ------------------ .../duplicated-field-method/output.json | 207 ---------------- .../duplicated-method-accessor/output.json | 229 ------------------ .../duplicated-method-field/output.json | 207 ---------------- .../output.json | 224 ----------------- .../duplicated-same-placement/output.json | 224 ----------------- 6 files changed, 1320 deletions(-) delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/output.json delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/output.json delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/output.json delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/output.json delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/output.json delete mode 100644 packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/output.json diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/output.json deleted file mode 100644 index 9fa1c2917097..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-accessor-method/output.json +++ /dev/null @@ -1,229 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "errors": [ - "SyntaxError: Duplicate private name #x (3:2)" - ], - "program": { - "type": "Program", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "ClassDeclaration", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 6, - "end": 7, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 7 - }, - "identifierName": "A" - }, - "name": "A" - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start": 8, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 8 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "body": [ - { - "type": "ClassPrivateMethod", - "start": 12, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 13 - } - }, - "static": false, - "key": { - "type": "PrivateName", - "start": 16, - "end": 18, - "loc": { - "start": { - "line": 2, - "column": 6 - }, - "end": { - "line": 2, - "column": 8 - } - }, - "id": { - "type": "Identifier", - "start": 17, - "end": 18, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 8 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "computed": false, - "kind": "get", - "id": null, - "generator": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 21, - "end": 23, - "loc": { - "start": { - "line": 2, - "column": 11 - }, - "end": { - "line": 2, - "column": 13 - } - }, - "body": [], - "directives": [] - } - }, - { - "type": "ClassPrivateMethod", - "start": 26, - "end": 33, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 9 - } - }, - "static": false, - "key": { - "type": "PrivateName", - "start": 26, - "end": 28, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 4 - } - }, - "id": { - "type": "Identifier", - "start": 27, - "end": 28, - "loc": { - "start": { - "line": 3, - "column": 3 - }, - "end": { - "line": 3, - "column": 4 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "kind": "method", - "id": null, - "generator": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 31, - "end": 33, - "loc": { - "start": { - "line": 3, - "column": 7 - }, - "end": { - "line": 3, - "column": 9 - } - }, - "body": [], - "directives": [] - } - } - ] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/output.json deleted file mode 100644 index c5ddc0f4feb1..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-field-method/output.json +++ /dev/null @@ -1,207 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "errors": [ - "SyntaxError: Duplicate private name #x (3:2)" - ], - "program": { - "type": "Program", - "start": 0, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "ClassDeclaration", - "start": 0, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 6, - "end": 7, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 7 - }, - "identifierName": "A" - }, - "name": "A" - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start": 8, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 8 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "body": [ - { - "type": "ClassPrivateProperty", - "start": 12, - "end": 15, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 5 - } - }, - "static": false, - "key": { - "type": "PrivateName", - "start": 12, - "end": 14, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 4 - } - }, - "id": { - "type": "Identifier", - "start": 13, - "end": 14, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "value": null - }, - { - "type": "ClassPrivateMethod", - "start": 18, - "end": 25, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 9 - } - }, - "static": false, - "key": { - "type": "PrivateName", - "start": 18, - "end": 20, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 4 - } - }, - "id": { - "type": "Identifier", - "start": 19, - "end": 20, - "loc": { - "start": { - "line": 3, - "column": 3 - }, - "end": { - "line": 3, - "column": 4 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "kind": "method", - "id": null, - "generator": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 23, - "end": 25, - "loc": { - "start": { - "line": 3, - "column": 7 - }, - "end": { - "line": 3, - "column": 9 - } - }, - "body": [], - "directives": [] - } - } - ] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/output.json deleted file mode 100644 index 8dbf70cdb04b..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-accessor/output.json +++ /dev/null @@ -1,229 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "errors": [ - "SyntaxError: Duplicate private name #x (3:6)" - ], - "program": { - "type": "Program", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "ClassDeclaration", - "start": 0, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 6, - "end": 7, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 7 - }, - "identifierName": "A" - }, - "name": "A" - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start": 8, - "end": 35, - "loc": { - "start": { - "line": 1, - "column": 8 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "body": [ - { - "type": "ClassPrivateMethod", - "start": 12, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 9 - } - }, - "static": false, - "key": { - "type": "PrivateName", - "start": 12, - "end": 14, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 4 - } - }, - "id": { - "type": "Identifier", - "start": 13, - "end": 14, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "kind": "method", - "id": null, - "generator": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 17, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 9 - } - }, - "body": [], - "directives": [] - } - }, - { - "type": "ClassPrivateMethod", - "start": 22, - "end": 33, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 13 - } - }, - "static": false, - "key": { - "type": "PrivateName", - "start": 26, - "end": 28, - "loc": { - "start": { - "line": 3, - "column": 6 - }, - "end": { - "line": 3, - "column": 8 - } - }, - "id": { - "type": "Identifier", - "start": 27, - "end": 28, - "loc": { - "start": { - "line": 3, - "column": 7 - }, - "end": { - "line": 3, - "column": 8 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "computed": false, - "kind": "get", - "id": null, - "generator": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 31, - "end": 33, - "loc": { - "start": { - "line": 3, - "column": 11 - }, - "end": { - "line": 3, - "column": 13 - } - }, - "body": [], - "directives": [] - } - } - ] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/output.json deleted file mode 100644 index db05e019cac5..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-methods/duplicated-method-field/output.json +++ /dev/null @@ -1,207 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "errors": [ - "SyntaxError: Duplicate private name #x (3:2)" - ], - "program": { - "type": "Program", - "start": 0, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "ClassDeclaration", - "start": 0, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 6, - "end": 7, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 7 - }, - "identifierName": "A" - }, - "name": "A" - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start": 8, - "end": 27, - "loc": { - "start": { - "line": 1, - "column": 8 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "body": [ - { - "type": "ClassPrivateMethod", - "start": 12, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 9 - } - }, - "static": false, - "key": { - "type": "PrivateName", - "start": 12, - "end": 14, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 4 - } - }, - "id": { - "type": "Identifier", - "start": 13, - "end": 14, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "kind": "method", - "id": null, - "generator": false, - "async": false, - "params": [], - "body": { - "type": "BlockStatement", - "start": 17, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 9 - } - }, - "body": [], - "directives": [] - } - }, - { - "type": "ClassPrivateProperty", - "start": 22, - "end": 25, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 5 - } - }, - "static": false, - "key": { - "type": "PrivateName", - "start": 22, - "end": 24, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 4 - } - }, - "id": { - "type": "Identifier", - "start": 23, - "end": 24, - "loc": { - "start": { - "line": 3, - "column": 3 - }, - "end": { - "line": 3, - "column": 4 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "value": null - } - ] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/output.json deleted file mode 100644 index 2eda3d02bc66..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-different-placement/output.json +++ /dev/null @@ -1,224 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 38, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "errors": [ - "SyntaxError: Duplicate private name #x (3:9)" - ], - "program": { - "type": "Program", - "start": 0, - "end": 38, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "ClassDeclaration", - "start": 0, - "end": 38, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 6, - "end": 7, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 7 - }, - "identifierName": "A" - }, - "name": "A" - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start": 8, - "end": 38, - "loc": { - "start": { - "line": 1, - "column": 8 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "body": [ - { - "type": "ClassPrivateProperty", - "start": 12, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 9 - } - }, - "static": false, - "key": { - "type": "PrivateName", - "start": 12, - "end": 14, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 4 - } - }, - "id": { - "type": "Identifier", - "start": 13, - "end": 14, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "value": { - "type": "NumericLiteral", - "start": 17, - "end": 18, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 8 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - }, - { - "type": "ClassPrivateProperty", - "start": 22, - "end": 36, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 16 - } - }, - "static": true, - "key": { - "type": "PrivateName", - "start": 29, - "end": 31, - "loc": { - "start": { - "line": 3, - "column": 9 - }, - "end": { - "line": 3, - "column": 11 - } - }, - "id": { - "type": "Identifier", - "start": 30, - "end": 31, - "loc": { - "start": { - "line": 3, - "column": 10 - }, - "end": { - "line": 3, - "column": 11 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "value": { - "type": "NumericLiteral", - "start": 34, - "end": 35, - "loc": { - "start": { - "line": 3, - "column": 14 - }, - "end": { - "line": 3, - "column": 15 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } - } - ] - } - } - ], - "directives": [] - } -} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/output.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/output.json deleted file mode 100644 index 53727fe07998..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/duplicated-same-placement/output.json +++ /dev/null @@ -1,224 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "errors": [ - "SyntaxError: Duplicate private name #x (3:2)" - ], - "program": { - "type": "Program", - "start": 0, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "sourceType": "script", - "interpreter": null, - "body": [ - { - "type": "ClassDeclaration", - "start": 0, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "id": { - "type": "Identifier", - "start": 6, - "end": 7, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 7 - }, - "identifierName": "A" - }, - "name": "A" - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start": 8, - "end": 31, - "loc": { - "start": { - "line": 1, - "column": 8 - }, - "end": { - "line": 4, - "column": 1 - } - }, - "body": [ - { - "type": "ClassPrivateProperty", - "start": 12, - "end": 19, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 9 - } - }, - "static": false, - "key": { - "type": "PrivateName", - "start": 12, - "end": 14, - "loc": { - "start": { - "line": 2, - "column": 2 - }, - "end": { - "line": 2, - "column": 4 - } - }, - "id": { - "type": "Identifier", - "start": 13, - "end": 14, - "loc": { - "start": { - "line": 2, - "column": 3 - }, - "end": { - "line": 2, - "column": 4 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "value": { - "type": "NumericLiteral", - "start": 17, - "end": 18, - "loc": { - "start": { - "line": 2, - "column": 7 - }, - "end": { - "line": 2, - "column": 8 - } - }, - "extra": { - "rawValue": 1, - "raw": "1" - }, - "value": 1 - } - }, - { - "type": "ClassPrivateProperty", - "start": 22, - "end": 29, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 9 - } - }, - "static": false, - "key": { - "type": "PrivateName", - "start": 22, - "end": 24, - "loc": { - "start": { - "line": 3, - "column": 2 - }, - "end": { - "line": 3, - "column": 4 - } - }, - "id": { - "type": "Identifier", - "start": 23, - "end": 24, - "loc": { - "start": { - "line": 3, - "column": 3 - }, - "end": { - "line": 3, - "column": 4 - }, - "identifierName": "x" - }, - "name": "x" - } - }, - "value": { - "type": "NumericLiteral", - "start": 27, - "end": 28, - "loc": { - "start": { - "line": 3, - "column": 7 - }, - "end": { - "line": 3, - "column": 8 - } - }, - "extra": { - "rawValue": 2, - "raw": "2" - }, - "value": 2 - } - } - ] - } - } - ], - "directives": [] - } -} \ No newline at end of file From b8d0ea4bcb944cf218216cb3bad53e204eace473 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Fri, 10 Jan 2020 01:39:03 +0100 Subject: [PATCH 11/12] Move ClassScopeHandler to a separate class --- packages/babel-parser/src/parser/base.js | 2 + .../babel-parser/src/parser/expression.js | 5 +- packages/babel-parser/src/parser/index.js | 2 + packages/babel-parser/src/parser/statement.js | 10 +- packages/babel-parser/src/tokenizer/state.js | 3 - packages/babel-parser/src/util/class-scope.js | 111 ++++++++++++++++++ packages/babel-parser/src/util/scope.js | 96 --------------- 7 files changed, 123 insertions(+), 106 deletions(-) create mode 100644 packages/babel-parser/src/util/class-scope.js diff --git a/packages/babel-parser/src/parser/base.js b/packages/babel-parser/src/parser/base.js index f4fb9f3b66e0..f02e6778270f 100644 --- a/packages/babel-parser/src/parser/base.js +++ b/packages/babel-parser/src/parser/base.js @@ -4,12 +4,14 @@ import type { Options } from "../options"; import type State from "../tokenizer/state"; import type { PluginsMap } from "./index"; import type ScopeHandler from "../util/scope"; +import type ClassScopeHandler from "../util/class-scope"; export default class BaseParser { // Properties set by constructor in index.js options: Options; inModule: boolean; scope: ScopeHandler<*>; + classScope: ClassScopeHandler; plugins: PluginsMap; filename: ?string; sawUnambiguousESM: boolean = false; diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index f69abde15e49..9d2b74aaaf63 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -617,7 +617,10 @@ export default class ExpressionParser extends LValParser { if (node.object.type === "Super") { this.raise(startPos, "Private fields can't be accessed on super"); } - this.scope.usePrivateName(node.property.id.name, node.property.start); + this.classScope.usePrivateName( + node.property.id.name, + node.property.start, + ); } if (computed) { diff --git a/packages/babel-parser/src/parser/index.js b/packages/babel-parser/src/parser/index.js index 681de32d0560..d3f5db419c6b 100644 --- a/packages/babel-parser/src/parser/index.js +++ b/packages/babel-parser/src/parser/index.js @@ -7,6 +7,7 @@ import { getOptions } from "../options"; import StatementParser from "./statement"; import { SCOPE_ASYNC, SCOPE_PROGRAM } from "../util/scopeflags"; import ScopeHandler from "../util/scope"; +import ClassScopeHandler from "../util/class-scope"; export type PluginsMap = Map; @@ -25,6 +26,7 @@ export default class Parser extends StatementParser { this.options = options; this.inModule = this.options.sourceType === "module"; this.scope = new ScopeHandler(this.raise.bind(this), this.inModule); + this.classScope = new ClassScopeHandler(this.raise.bind(this)); this.plugins = pluginsMap(this.options.plugins); this.filename = options.sourceFilename; } diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index edcab9c6329a..7a5bc33c9541 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -1176,8 +1176,7 @@ export default class StatementParser extends ExpressionParser { } parseClassBody(constructorAllowsSuper: boolean): N.ClassBody { - this.state.classLevel++; - this.scope.enterClassBody(); + this.classScope.enter(); const state = { hadConstructor: false }; let decorators: N.Decorator[] = []; @@ -1237,8 +1236,7 @@ export default class StatementParser extends ExpressionParser { ); } - this.state.classLevel--; - this.scope.exitClassBody(); + this.classScope.exit(); return this.finishNode(classBody, "ClassBody"); } @@ -1525,7 +1523,7 @@ export default class StatementParser extends ExpressionParser { const node = this.parseClassPrivateProperty(prop); classBody.body.push(node); - this.scope.declarePrivateName( + this.classScope.declarePrivateName( node.key.id.name, CLASS_ELEMENT_OTHER, node.key.start, @@ -1582,7 +1580,7 @@ export default class StatementParser extends ExpressionParser { ? CLASS_ELEMENT_STATIC_SETTER : CLASS_ELEMENT_INSTANCE_SETTER : CLASS_ELEMENT_OTHER; - this.scope.declarePrivateName(node.key.id.name, kind, node.key.start); + this.classScope.declarePrivateName(node.key.id.name, kind, node.key.start); } // Overridden in typescript.js diff --git a/packages/babel-parser/src/tokenizer/state.js b/packages/babel-parser/src/tokenizer/state.js index 874b5cbdfcad..ff0e704b8f00 100644 --- a/packages/babel-parser/src/tokenizer/state.js +++ b/packages/babel-parser/src/tokenizer/state.js @@ -77,9 +77,6 @@ export default class State { soloAwait: boolean = false; inFSharpPipelineDirectBody: boolean = false; - // Check whether we are in a (nested) class or not. - classLevel: number = 0; - // Labels in scope. labels: Array<{ kind: ?("loop" | "switch"), diff --git a/packages/babel-parser/src/util/class-scope.js b/packages/babel-parser/src/util/class-scope.js new file mode 100644 index 000000000000..a30514384bc1 --- /dev/null +++ b/packages/babel-parser/src/util/class-scope.js @@ -0,0 +1,111 @@ +// @flow + +import { + CLASS_ELEMENT_KIND_ACCESSOR, + CLASS_ELEMENT_FLAG_STATIC, + type ClassElementTypes, +} from "./scopeflags"; + +export class ClassScope { + // A list of private named declared in the current class + privateNames: Set = new Set(); + + // A list of private getters of setters without their counterpart + loneAccessors: Map = new Map(); + + // A list of private names used before being defined, mapping to + // their position. + undefinedPrivateNames: Map = new Map(); +} + +type raiseFunction = (number, string) => void; + +export default class ClassScopeHandler { + stack: Array = []; + raise: raiseFunction; + undefinedPrivateNames: Map = new Map(); + + constructor(raise: raiseFunction) { + this.raise = raise; + } + + current(): ClassScope { + return this.stack[this.stack.length - 1]; + } + + enter() { + this.stack.push(new ClassScope()); + } + + exit() { + const oldClassScope = this.stack.pop(); + + // Migrate the usage of not yet defined private names to the outer + // class scope, or raise an error if we reached the top-level scope. + + const current = this.current(); + + // Array.from is needed because this is compiled to an array-like for loop + for (const [name, pos] of Array.from(oldClassScope.undefinedPrivateNames)) { + if (current) { + if (!current.undefinedPrivateNames.has(name)) { + current.undefinedPrivateNames.set(name, pos); + } + } else { + this.raiseUndeclaredPrivateName(name, pos); + } + } + } + + declarePrivateName( + name: string, + elementType: ClassElementTypes, + pos: number, + ) { + const classScope = this.current(); + let redefined = classScope.privateNames.has(name); + + if (elementType & CLASS_ELEMENT_KIND_ACCESSOR) { + const accessor = redefined && classScope.loneAccessors.get(name); + if (accessor) { + const differences = elementType ^ accessor; + + // The private name can be duplicated only if it is used by + // two accessors with different kind (get and set), and if + // they have the same placement (static or not). + redefined = + !(differences & CLASS_ELEMENT_KIND_ACCESSOR) || + differences & CLASS_ELEMENT_FLAG_STATIC; + + if (!redefined) classScope.loneAccessors.delete(name); + } else if (!redefined) { + classScope.loneAccessors.set(name, elementType); + } + } + + if (redefined) { + this.raise(pos, `Duplicate private name #${name}`); + } + + classScope.privateNames.add(name); + classScope.undefinedPrivateNames.delete(name); + } + + usePrivateName(name: string, pos: number) { + let classScope; + for (classScope of this.stack) { + if (classScope.privateNames.has(name)) return; + } + + if (classScope) { + classScope.undefinedPrivateNames.set(name, pos); + } else { + // top-level + this.raiseUndeclaredPrivateName(name, pos); + } + } + + raiseUndeclaredPrivateName(name: string, pos: number) { + this.raise(pos, `Private name #${name} is not defined`); + } +} diff --git a/packages/babel-parser/src/util/scope.js b/packages/babel-parser/src/util/scope.js index 55de27238dad..1cbf06fb671f 100644 --- a/packages/babel-parser/src/util/scope.js +++ b/packages/babel-parser/src/util/scope.js @@ -14,11 +14,8 @@ import { BIND_SCOPE_VAR, BIND_SCOPE_LEXICAL, BIND_KIND_VALUE, - CLASS_ELEMENT_KIND_ACCESSOR, - CLASS_ELEMENT_FLAG_STATIC, type ScopeFlags, type BindingTypes, - type ClassElementTypes, } from "./scopeflags"; import * as N from "../types"; @@ -37,25 +34,12 @@ export class Scope { } } -export class ClassScope { - // A list of private named declared in the current class - privateNames: Set = new Set(); - - // A list of private getters of setters without their counterpart - loneAccessors: Map = new Map(); - - // A list of private names used before being defined, mapping to - // their position. - undefinedPrivateNames: Map = new Map(); -} - type raiseFunction = (number, string) => void; // The functions in this module keep track of declared variables in the // current scope in order to detect duplicate variable names. export default class ScopeHandler { scopeStack: Array = []; - classScopeStack: Array = []; raise: raiseFunction; inModule: boolean; undefinedExports: Map = new Map(); @@ -118,30 +102,6 @@ export default class ScopeHandler { this.scopeStack.pop(); } - enterClassBody() { - this.classScopeStack.push(new ClassScope()); - } - - exitClassBody() { - const oldClassScope = this.classScopeStack.pop(); - - // Migrate the usage of not yet defined private names to the outer - // class scope, or raise an error if we reached the top-level scope. - - const currentClassScope = this.currentClassScope(); - - // Array.from is needed because this is compiled to an array-like for loop - for (const [name, pos] of Array.from(oldClassScope.undefinedPrivateNames)) { - if (currentClassScope) { - if (!currentClassScope.undefinedPrivateNames.has(name)) { - currentClassScope.undefinedPrivateNames.set(name, pos); - } - } else { - this.raiseUndeclaredPrivateName(name, pos); - } - } - } - // The spec says: // > At the top level of a function, or script, function declarations are // > treated like var declarations rather than like lexical declarations. @@ -181,58 +141,6 @@ export default class ScopeHandler { } } - declarePrivateName( - name: string, - elementType: ClassElementTypes, - pos: number, - ) { - const classScope = this.currentClassScope(); - let redefined = classScope.privateNames.has(name); - - if (elementType & CLASS_ELEMENT_KIND_ACCESSOR) { - const accessor = redefined && classScope.loneAccessors.get(name); - if (accessor) { - const differences = elementType ^ accessor; - - // The private name can be duplicated only if it is used by - // two accessors with different kind (get and set), and if - // they have the same placement (static or not). - redefined = - !(differences & CLASS_ELEMENT_KIND_ACCESSOR) || - differences & CLASS_ELEMENT_FLAG_STATIC; - - if (!redefined) classScope.loneAccessors.delete(name); - } else if (!redefined) { - classScope.loneAccessors.set(name, elementType); - } - } - - if (redefined) { - this.raise(pos, `Duplicate private name #${name}`); - } - - classScope.privateNames.add(name); - classScope.undefinedPrivateNames.delete(name); - } - - usePrivateName(name: string, pos: number) { - let classScope; - for (classScope of this.classScopeStack) { - if (classScope.privateNames.has(name)) return; - } - - if (classScope) { - classScope.undefinedPrivateNames.set(name, pos); - } else { - // top-level - this.raiseUndeclaredPrivateName(name, pos); - } - } - - raiseUndeclaredPrivateName(name: string, pos: number) { - this.raise(pos, `Private name #${name} is not defined`); - } - maybeExportDefined(scope: IScope, name: string) { if (this.inModule && scope.flags & SCOPE_PROGRAM) { this.undefinedExports.delete(name); @@ -298,10 +206,6 @@ export default class ScopeHandler { return this.scopeStack[this.scopeStack.length - 1]; } - currentClassScope(): ClassScope { - return this.classScopeStack[this.classScopeStack.length - 1]; - } - // $FlowIgnore currentVarScope(): IScope { for (let i = this.scopeStack.length - 1; ; i--) { From f9edcba539d225878e9354b689891b30c6f5d168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Fri, 10 Jan 2020 01:45:26 +0100 Subject: [PATCH 12/12] Make the code readable --- packages/babel-parser/src/util/class-scope.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/babel-parser/src/util/class-scope.js b/packages/babel-parser/src/util/class-scope.js index a30514384bc1..0d1332160a62 100644 --- a/packages/babel-parser/src/util/class-scope.js +++ b/packages/babel-parser/src/util/class-scope.js @@ -68,14 +68,16 @@ export default class ClassScopeHandler { if (elementType & CLASS_ELEMENT_KIND_ACCESSOR) { const accessor = redefined && classScope.loneAccessors.get(name); if (accessor) { - const differences = elementType ^ accessor; + const oldStatic = accessor & CLASS_ELEMENT_FLAG_STATIC; + const newStatic = elementType & CLASS_ELEMENT_FLAG_STATIC; + + const oldKind = accessor & CLASS_ELEMENT_KIND_ACCESSOR; + const newKind = elementType & CLASS_ELEMENT_KIND_ACCESSOR; // The private name can be duplicated only if it is used by // two accessors with different kind (get and set), and if // they have the same placement (static or not). - redefined = - !(differences & CLASS_ELEMENT_KIND_ACCESSOR) || - differences & CLASS_ELEMENT_FLAG_STATIC; + redefined = oldKind === newKind || oldStatic !== newStatic; if (!redefined) classScope.loneAccessors.delete(name); } else if (!redefined) {