From 0eefe5e49d21af3f1e3e2d9a90c2e49929863ac2 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Sat, 28 Aug 2021 18:18:40 -0700 Subject: [PATCH] feat: support `PrivateIdentifier` (#3808) Closes #3430 Resolves #2933 --- packages/ast-spec/src/ast-node-types.ts | 1 + .../ast-spec/src/base/MethodDefinitionBase.ts | 7 + .../src/base/PropertyDefinitionBase.ts | 7 + .../src/element/MethodDefinition/spec.ts | 4 +- .../src/element/PropertyDefinition/spec.ts | 4 +- .../TSAbstractMethodDefinition/spec.ts | 1 + .../TSAbstractPropertyDefinition/spec.ts | 1 + .../src/expression/MemberExpression/spec.ts | 5 +- .../src/special/PrivateIdentifier/spec.ts | 7 + packages/ast-spec/src/special/spec.ts | 1 + packages/ast-spec/src/unions/Node.ts | 2 + packages/ast-spec/src/unions/PropertyName.ts | 10 +- .../src/rules/adjacent-overload-signatures.ts | 15 +- .../rules/explicit-member-accessibility.ts | 11 +- .../src/rules/member-ordering.ts | 6 +- .../rules/naming-convention-utils/types.ts | 2 +- .../naming-convention-utils/validator.ts | 19 +- .../src/rules/naming-convention.ts | 7 +- .../eslint-plugin/src/rules/prefer-for-of.ts | 2 +- packages/eslint-plugin/src/util/misc.ts | 40 +- .../adjacent-overload-signatures.test.ts | 37 + .../explicit-member-accessibility.test.ts | 68 ++ .../tests/rules/member-ordering.test.ts | 40 + .../tests/rules/naming-convention.test.ts | 7 + .../src/referencer/ClassVisitor.ts | 4 + .../src/referencer/Referencer.ts | 4 + .../class/declaration/private-identifier.ts | 7 + .../declaration/private-identifier.ts.shot | 83 ++ .../class/expression/private-identifier.ts | 7 + .../expression/private-identifier.ts.shot | 80 ++ .../class-private-identifier-accessor.src.js | 8 + .../class-private-identifier-field.src.js | 8 + .../class-private-identifier-method.src.js | 7 + ...fier-field-with-accessibility-error.src.ts | 5 + ...te-identifier-field-with-annotation.src.ts | 8 + ...s-private-identifier-readonly-field.src.ts | 3 + packages/types/tools/copy-ast-spec.ts | 2 +- packages/typescript-estree/src/convert.ts | 8 + .../src/ts-estree/estree-to-ts-node-types.ts | 1 + .../src/ts-estree/ts-nodes.ts | 3 + .../tests/ast-alignment/fixtures-to-test.ts | 15 + .../semantic-diagnostics-enabled.test.ts.snap | 12 + ...ss-private-identifier-accessor.src.js.shot | 1024 +++++++++++++++++ ...class-private-identifier-field.src.js.shot | 748 ++++++++++++ ...lass-private-identifier-method.src.js.shot | 691 +++++++++++ ...field-with-accessibility-error.src.ts.shot | 597 ++++++++++ ...entifier-field-with-annotation.src.ts.shot | 888 ++++++++++++++ ...vate-identifier-readonly-field.src.ts.shot | 301 +++++ packages/visitor-keys/package.json | 2 +- 49 files changed, 4786 insertions(+), 34 deletions(-) create mode 100644 packages/ast-spec/src/special/PrivateIdentifier/spec.ts create mode 100644 packages/scope-manager/tests/fixtures/class/declaration/private-identifier.ts create mode 100644 packages/scope-manager/tests/fixtures/class/declaration/private-identifier.ts.shot create mode 100644 packages/scope-manager/tests/fixtures/class/expression/private-identifier.ts create mode 100644 packages/scope-manager/tests/fixtures/class/expression/private-identifier.ts.shot create mode 100644 packages/shared-fixtures/fixtures/javascript/classes/class-private-identifier-accessor.src.js create mode 100644 packages/shared-fixtures/fixtures/javascript/classes/class-private-identifier-field.src.js create mode 100644 packages/shared-fixtures/fixtures/javascript/classes/class-private-identifier-method.src.js create mode 100644 packages/shared-fixtures/fixtures/typescript/basics/class-private-identifier-field-with-accessibility-error.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/basics/class-private-identifier-field-with-annotation.src.ts create mode 100644 packages/shared-fixtures/fixtures/typescript/basics/class-private-identifier-readonly-field.src.ts create mode 100644 packages/typescript-estree/tests/snapshots/javascript/classes/class-private-identifier-accessor.src.js.shot create mode 100644 packages/typescript-estree/tests/snapshots/javascript/classes/class-private-identifier-field.src.js.shot create mode 100644 packages/typescript-estree/tests/snapshots/javascript/classes/class-private-identifier-method.src.js.shot create mode 100644 packages/typescript-estree/tests/snapshots/typescript/basics/class-private-identifier-field-with-accessibility-error.src.ts.shot create mode 100644 packages/typescript-estree/tests/snapshots/typescript/basics/class-private-identifier-field-with-annotation.src.ts.shot create mode 100644 packages/typescript-estree/tests/snapshots/typescript/basics/class-private-identifier-readonly-field.src.ts.shot diff --git a/packages/ast-spec/src/ast-node-types.ts b/packages/ast-spec/src/ast-node-types.ts index 3f6b2a81082..c5ee4a189df 100644 --- a/packages/ast-spec/src/ast-node-types.ts +++ b/packages/ast-spec/src/ast-node-types.ts @@ -61,6 +61,7 @@ export enum AST_NODE_TYPES { NewExpression = 'NewExpression', ObjectExpression = 'ObjectExpression', ObjectPattern = 'ObjectPattern', + PrivateIdentifier = 'PrivateIdentifier', Program = 'Program', Property = 'Property', PropertyDefinition = 'PropertyDefinition', diff --git a/packages/ast-spec/src/base/MethodDefinitionBase.ts b/packages/ast-spec/src/base/MethodDefinitionBase.ts index afdea67bcd7..f1f2087ccae 100644 --- a/packages/ast-spec/src/base/MethodDefinitionBase.ts +++ b/packages/ast-spec/src/base/MethodDefinitionBase.ts @@ -3,6 +3,7 @@ import type { TSEmptyBodyFunctionExpression } from '../expression/TSEmptyBodyFun import type { Decorator } from '../special/Decorator/spec'; import type { TSTypeParameterDeclaration } from '../special/TSTypeParameterDeclaration/spec'; import type { + ClassPropertyNameNonComputed, PropertyName, PropertyNameComputed, PropertyNameNonComputed, @@ -34,3 +35,9 @@ export interface MethodDefinitionNonComputedNameBase key: PropertyNameNonComputed; computed: false; } + +export interface ClassMethodDefinitionNonComputedNameBase + extends MethodDefinitionBase { + key: ClassPropertyNameNonComputed; + computed: false; +} diff --git a/packages/ast-spec/src/base/PropertyDefinitionBase.ts b/packages/ast-spec/src/base/PropertyDefinitionBase.ts index a70a21479ae..f1d5b9cc440 100644 --- a/packages/ast-spec/src/base/PropertyDefinitionBase.ts +++ b/packages/ast-spec/src/base/PropertyDefinitionBase.ts @@ -2,6 +2,7 @@ import type { Decorator } from '../special/Decorator/spec'; import type { TSTypeAnnotation } from '../special/TSTypeAnnotation/spec'; import type { Expression } from '../unions/Expression'; import type { + ClassPropertyNameNonComputed, PropertyName, PropertyNameComputed, PropertyNameNonComputed, @@ -35,3 +36,9 @@ export interface PropertyDefinitionNonComputedNameBase key: PropertyNameNonComputed; computed: false; } + +export interface ClassPropertyDefinitionNonComputedNameBase + extends PropertyDefinitionBase { + key: ClassPropertyNameNonComputed; + computed: false; +} diff --git a/packages/ast-spec/src/element/MethodDefinition/spec.ts b/packages/ast-spec/src/element/MethodDefinition/spec.ts index f097f9f8e85..c02aa19b5df 100644 --- a/packages/ast-spec/src/element/MethodDefinition/spec.ts +++ b/packages/ast-spec/src/element/MethodDefinition/spec.ts @@ -1,7 +1,7 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { + ClassMethodDefinitionNonComputedNameBase, MethodDefinitionComputedNameBase, - MethodDefinitionNonComputedNameBase, } from '../../base/MethodDefinitionBase'; export interface MethodDefinitionComputedName @@ -10,7 +10,7 @@ export interface MethodDefinitionComputedName } export interface MethodDefinitionNonComputedName - extends MethodDefinitionNonComputedNameBase { + extends ClassMethodDefinitionNonComputedNameBase { type: AST_NODE_TYPES.MethodDefinition; } diff --git a/packages/ast-spec/src/element/PropertyDefinition/spec.ts b/packages/ast-spec/src/element/PropertyDefinition/spec.ts index 4f79c2eb834..d249b140e66 100644 --- a/packages/ast-spec/src/element/PropertyDefinition/spec.ts +++ b/packages/ast-spec/src/element/PropertyDefinition/spec.ts @@ -1,7 +1,7 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { + ClassPropertyDefinitionNonComputedNameBase, PropertyDefinitionComputedNameBase, - PropertyDefinitionNonComputedNameBase, } from '../../base/PropertyDefinitionBase'; export interface PropertyDefinitionComputedName @@ -10,7 +10,7 @@ export interface PropertyDefinitionComputedName } export interface PropertyDefinitionNonComputedName - extends PropertyDefinitionNonComputedNameBase { + extends ClassPropertyDefinitionNonComputedNameBase { type: AST_NODE_TYPES.PropertyDefinition; } diff --git a/packages/ast-spec/src/element/TSAbstractMethodDefinition/spec.ts b/packages/ast-spec/src/element/TSAbstractMethodDefinition/spec.ts index a8f5a05c50a..ad2c3f7e51f 100644 --- a/packages/ast-spec/src/element/TSAbstractMethodDefinition/spec.ts +++ b/packages/ast-spec/src/element/TSAbstractMethodDefinition/spec.ts @@ -10,6 +10,7 @@ export interface TSAbstractMethodDefinitionComputedName } export interface TSAbstractMethodDefinitionNonComputedName + // this does not extend ClassMethodDefinitionNonComputedNameBase because abstract private names are not allowed extends MethodDefinitionNonComputedNameBase { type: AST_NODE_TYPES.TSAbstractMethodDefinition; } diff --git a/packages/ast-spec/src/element/TSAbstractPropertyDefinition/spec.ts b/packages/ast-spec/src/element/TSAbstractPropertyDefinition/spec.ts index c7032669fc9..efa41b3bd36 100644 --- a/packages/ast-spec/src/element/TSAbstractPropertyDefinition/spec.ts +++ b/packages/ast-spec/src/element/TSAbstractPropertyDefinition/spec.ts @@ -11,6 +11,7 @@ export interface TSAbstractPropertyDefinitionComputedName } export interface TSAbstractPropertyDefinitionNonComputedName + // this does not extend ClassPropertyDefinitionNonComputedNameBase because abstract private names are not allowed extends PropertyDefinitionNonComputedNameBase { type: AST_NODE_TYPES.TSAbstractPropertyDefinition; value: null; diff --git a/packages/ast-spec/src/expression/MemberExpression/spec.ts b/packages/ast-spec/src/expression/MemberExpression/spec.ts index 92bad8cf3dc..260574cc59f 100644 --- a/packages/ast-spec/src/expression/MemberExpression/spec.ts +++ b/packages/ast-spec/src/expression/MemberExpression/spec.ts @@ -1,12 +1,13 @@ import type { AST_NODE_TYPES } from '../../ast-node-types'; import type { BaseNode } from '../../base/BaseNode'; +import type { PrivateIdentifier } from '../../special/PrivateIdentifier/spec'; import type { Expression } from '../../unions/Expression'; import type { LeftHandSideExpression } from '../../unions/LeftHandSideExpression'; import type { Identifier } from '../Identifier/spec'; interface MemberExpressionBase extends BaseNode { object: LeftHandSideExpression; - property: Expression | Identifier; + property: Expression | Identifier | PrivateIdentifier; computed: boolean; optional: boolean; } @@ -19,7 +20,7 @@ export interface MemberExpressionComputedName extends MemberExpressionBase { export interface MemberExpressionNonComputedName extends MemberExpressionBase { type: AST_NODE_TYPES.MemberExpression; - property: Identifier; + property: Identifier | PrivateIdentifier; computed: false; } diff --git a/packages/ast-spec/src/special/PrivateIdentifier/spec.ts b/packages/ast-spec/src/special/PrivateIdentifier/spec.ts new file mode 100644 index 00000000000..f1d2172b837 --- /dev/null +++ b/packages/ast-spec/src/special/PrivateIdentifier/spec.ts @@ -0,0 +1,7 @@ +import type { AST_NODE_TYPES } from '../../ast-node-types'; +import type { BaseNode } from '../../base/BaseNode'; + +export interface PrivateIdentifier extends BaseNode { + type: AST_NODE_TYPES.PrivateIdentifier; + name: string; +} diff --git a/packages/ast-spec/src/special/spec.ts b/packages/ast-spec/src/special/spec.ts index 07142e15c8f..91e5037751d 100644 --- a/packages/ast-spec/src/special/spec.ts +++ b/packages/ast-spec/src/special/spec.ts @@ -6,6 +6,7 @@ export * from './ExportSpecifier/spec'; export * from './ImportDefaultSpecifier/spec'; export * from './ImportNamespaceSpecifier/spec'; export * from './ImportSpecifier/spec'; +export * from './PrivateIdentifier/spec'; export * from './Program/spec'; export * from './SwitchCase/spec'; export * from './TSClassImplements/spec'; diff --git a/packages/ast-spec/src/unions/Node.ts b/packages/ast-spec/src/unions/Node.ts index 4b3c54a09eb..ba2b07bf4d4 100644 --- a/packages/ast-spec/src/unions/Node.ts +++ b/packages/ast-spec/src/unions/Node.ts @@ -82,6 +82,7 @@ import type { ExportSpecifier } from '../special/ExportSpecifier/spec'; import type { ImportDefaultSpecifier } from '../special/ImportDefaultSpecifier/spec'; import type { ImportNamespaceSpecifier } from '../special/ImportNamespaceSpecifier/spec'; import type { ImportSpecifier } from '../special/ImportSpecifier/spec'; +import type { PrivateIdentifier } from '../special/PrivateIdentifier/spec'; import type { Program } from '../special/Program/spec'; import type { SwitchCase } from '../special/SwitchCase/spec'; import type { TemplateElement } from '../special/TemplateElement/spec'; @@ -228,6 +229,7 @@ export type Node = | NewExpression | ObjectExpression | ObjectPattern + | PrivateIdentifier | Program | Property | PropertyDefinition diff --git a/packages/ast-spec/src/unions/PropertyName.ts b/packages/ast-spec/src/unions/PropertyName.ts index 56ba04cabbe..dce45834d7f 100644 --- a/packages/ast-spec/src/unions/PropertyName.ts +++ b/packages/ast-spec/src/unions/PropertyName.ts @@ -1,11 +1,19 @@ import type { Identifier } from '../expression/Identifier/spec'; import type { NumberLiteral } from '../expression/literal/NumberLiteral/spec'; import type { StringLiteral } from '../expression/literal/StringLiteral/spec'; +import type { PrivateIdentifier } from '../special/PrivateIdentifier/spec'; import type { Expression } from '../unions/Expression'; -export type PropertyName = PropertyNameComputed | PropertyNameNonComputed; +export type PropertyName = + | ClassPropertyNameNonComputed + | PropertyNameComputed + | PropertyNameNonComputed; export type PropertyNameComputed = Expression; export type PropertyNameNonComputed = | Identifier | NumberLiteral | StringLiteral; +export type ClassPropertyNameNonComputed = + | PrivateIdentifier + // only class properties can have private identifiers as their names + | PropertyNameNonComputed; diff --git a/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts b/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts index 273b6c6bfb9..c0eec499ab3 100644 --- a/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts +++ b/packages/eslint-plugin/src/rules/adjacent-overload-signatures.ts @@ -25,7 +25,7 @@ export default util.createRule({ }, schema: [], messages: { - adjacentSignature: "All '{{name}}' signatures should be adjacent.", + adjacentSignature: 'All {{name}} signatures should be adjacent.', }, }, defaultOptions: [], @@ -36,6 +36,7 @@ export default util.createRule({ name: string; static: boolean; callSignature: boolean; + type: util.MemberNameType; } /** @@ -71,11 +72,12 @@ export default util.createRule({ name, static: isStatic, callSignature: false, + type: util.MemberNameType.Normal, }; } case AST_NODE_TYPES.TSMethodSignature: return { - name: util.getNameFromMember(member, sourceCode), + ...util.getNameFromMember(member, sourceCode), static: isStatic, callSignature: false, }; @@ -84,16 +86,18 @@ export default util.createRule({ name: 'call', static: isStatic, callSignature: true, + type: util.MemberNameType.Normal, }; case AST_NODE_TYPES.TSConstructSignatureDeclaration: return { name: 'new', static: isStatic, callSignature: false, + type: util.MemberNameType.Normal, }; case AST_NODE_TYPES.MethodDefinition: return { - name: util.getNameFromMember(member, sourceCode), + ...util.getNameFromMember(member, sourceCode), static: isStatic, callSignature: false, }; @@ -107,7 +111,8 @@ export default util.createRule({ !!method2 && method1.name === method2.name && method1.static === method2.static && - method1.callSignature === method2.callSignature + method1.callSignature === method2.callSignature && + method1.type === method2.type ); } @@ -150,7 +155,7 @@ export default util.createRule({ node: member, messageId: 'adjacentSignature', data: { - name: (method.static ? 'static ' : '') + method.name, + name: `${method.static ? 'static ' : ''}${method.name}`, }, }); } else if (index === -1) { diff --git a/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts b/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts index 2e73af17354..a8522f1b87c 100644 --- a/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts +++ b/packages/eslint-plugin/src/rules/explicit-member-accessibility.ts @@ -113,6 +113,10 @@ export default util.createRule({ function checkMethodAccessibilityModifier( methodDefinition: TSESTree.MethodDefinition, ): void { + if (methodDefinition.key.type === AST_NODE_TYPES.PrivateIdentifier) { + return; + } + let nodeType = 'method definition'; let check = baseCheck; switch (methodDefinition.kind) { @@ -129,7 +133,10 @@ export default util.createRule({ break; } - const methodName = util.getNameFromMember(methodDefinition, sourceCode); + const { name: methodName } = util.getNameFromMember( + methodDefinition, + sourceCode, + ); if (check === 'off' || ignoredMethodNames.has(methodName)) { return; @@ -205,7 +212,7 @@ export default util.createRule({ ): void { const nodeType = 'class property'; - const propertyName = util.getNameFromMember( + const { name: propertyName } = util.getNameFromMember( propertyDefinition, sourceCode, ); diff --git a/packages/eslint-plugin/src/rules/member-ordering.ts b/packages/eslint-plugin/src/rules/member-ordering.ts index 9f88228449b..c1e30adc2ef 100644 --- a/packages/eslint-plugin/src/rules/member-ordering.ts +++ b/packages/eslint-plugin/src/rules/member-ordering.ts @@ -280,12 +280,12 @@ function getMemberName( case AST_NODE_TYPES.TSMethodSignature: case AST_NODE_TYPES.TSAbstractPropertyDefinition: case AST_NODE_TYPES.PropertyDefinition: - return util.getNameFromMember(node, sourceCode); + return util.getNameFromMember(node, sourceCode).name; case AST_NODE_TYPES.TSAbstractMethodDefinition: case AST_NODE_TYPES.MethodDefinition: return node.kind === 'constructor' ? 'constructor' - : util.getNameFromMember(node, sourceCode); + : util.getNameFromMember(node, sourceCode).name; case AST_NODE_TYPES.TSConstructSignatureDeclaration: return 'new'; case AST_NODE_TYPES.TSCallSignatureDeclaration: @@ -428,7 +428,7 @@ export default util.createRule({ }, messages: { incorrectOrder: - 'Member "{{member}}" should be declared before member "{{beforeMember}}".', + 'Member {{member}} should be declared before member {{beforeMember}}.', incorrectGroupOrder: 'Member {{name}} should be declared before all {{rank}} definitions.', }, diff --git a/packages/eslint-plugin/src/rules/naming-convention-utils/types.ts b/packages/eslint-plugin/src/rules/naming-convention-utils/types.ts index d66f9ad13d4..9cff76129db 100644 --- a/packages/eslint-plugin/src/rules/naming-convention-utils/types.ts +++ b/packages/eslint-plugin/src/rules/naming-convention-utils/types.ts @@ -60,7 +60,7 @@ interface NormalizedSelector { } type ValidatorFunction = ( - node: TSESTree.Identifier | TSESTree.Literal, + node: TSESTree.Identifier | TSESTree.PrivateIdentifier | TSESTree.Literal, modifiers?: Set, ) => void; type ParsedOptions = Record; diff --git a/packages/eslint-plugin/src/rules/naming-convention-utils/validator.ts b/packages/eslint-plugin/src/rules/naming-convention-utils/validator.ts index a683933d61b..374302f7f12 100644 --- a/packages/eslint-plugin/src/rules/naming-convention-utils/validator.ts +++ b/packages/eslint-plugin/src/rules/naming-convention-utils/validator.ts @@ -25,7 +25,9 @@ function createValidator( type: SelectorsString, context: Context, allConfigs: NormalizedSelector[], -): (node: TSESTree.Identifier | TSESTree.Literal) => void { +): ( + node: TSESTree.Identifier | TSESTree.PrivateIdentifier | TSESTree.Literal, +) => void { // make sure the "highest priority" configs are checked first const selectorType = Selectors[type]; const configs = allConfigs @@ -70,11 +72,14 @@ function createValidator( }); return ( - node: TSESTree.Identifier | TSESTree.Literal, + node: TSESTree.Identifier | TSESTree.PrivateIdentifier | TSESTree.Literal, modifiers: Set = new Set(), ): void => { const originalName = - node.type === AST_NODE_TYPES.Identifier ? node.name : `${node.value}`; + node.type === AST_NODE_TYPES.Identifier || + node.type === AST_NODE_TYPES.PrivateIdentifier + ? node.name + : `${node.value}`; // return will break the loop and stop checking configs // it is only used when the name is known to have failed or succeeded a config. @@ -178,7 +183,7 @@ function createValidator( position: 'leading' | 'trailing', config: NormalizedSelector, name: string, - node: TSESTree.Identifier | TSESTree.Literal, + node: TSESTree.Identifier | TSESTree.PrivateIdentifier | TSESTree.Literal, originalName: string, ): string | null { const option = @@ -299,7 +304,7 @@ function createValidator( position: 'prefix' | 'suffix', config: NormalizedSelector, name: string, - node: TSESTree.Identifier | TSESTree.Literal, + node: TSESTree.Identifier | TSESTree.PrivateIdentifier | TSESTree.Literal, originalName: string, ): string | null { const affixes = config[position]; @@ -339,7 +344,7 @@ function createValidator( function validateCustom( config: NormalizedSelector, name: string, - node: TSESTree.Identifier | TSESTree.Literal, + node: TSESTree.Identifier | TSESTree.PrivateIdentifier | TSESTree.Literal, originalName: string, ): boolean { const custom = config.custom; @@ -372,7 +377,7 @@ function createValidator( function validatePredefinedFormat( config: NormalizedSelector, name: string, - node: TSESTree.Identifier | TSESTree.Literal, + node: TSESTree.Identifier | TSESTree.PrivateIdentifier | TSESTree.Literal, originalName: string, ): boolean { const formats = config.format; diff --git a/packages/eslint-plugin/src/rules/naming-convention.ts b/packages/eslint-plugin/src/rules/naming-convention.ts index 6915c841473..db4463edd98 100644 --- a/packages/eslint-plugin/src/rules/naming-convention.ts +++ b/packages/eslint-plugin/src/rules/naming-convention.ts @@ -620,11 +620,14 @@ function isGlobal(scope: TSESLint.Scope.Scope | null): boolean { } function requiresQuoting( - node: TSESTree.Identifier | TSESTree.Literal, + node: TSESTree.Identifier | TSESTree.Literal | TSESTree.PrivateIdentifier, target: ScriptTarget | undefined, ): boolean { const name = - node.type === AST_NODE_TYPES.Identifier ? node.name : `${node.value}`; + node.type === AST_NODE_TYPES.Identifier || + node.type === AST_NODE_TYPES.PrivateIdentifier + ? node.name + : `${node.value}`; return util.requiresQuoting(name, target); } diff --git a/packages/eslint-plugin/src/rules/prefer-for-of.ts b/packages/eslint-plugin/src/rules/prefer-for-of.ts index 25043615f81..f00868d0409 100644 --- a/packages/eslint-plugin/src/rules/prefer-for-of.ts +++ b/packages/eslint-plugin/src/rules/prefer-for-of.ts @@ -42,7 +42,7 @@ export default util.createRule({ } function isMatchingIdentifier( - node: TSESTree.Expression, + node: TSESTree.Expression | TSESTree.PrivateIdentifier, name: string, ): boolean { return node.type === AST_NODE_TYPES.Identifier && node.name === name; diff --git a/packages/eslint-plugin/src/util/misc.ts b/packages/eslint-plugin/src/util/misc.ts index 748a5cec6a6..95fa4a359c6 100644 --- a/packages/eslint-plugin/src/util/misc.ts +++ b/packages/eslint-plugin/src/util/misc.ts @@ -7,6 +7,7 @@ import { TSESLint, TSESTree, } from '@typescript-eslint/experimental-utils'; +import { requiresQuoting } from './requiresQuoting'; /** * Check if the context file name is *.d.ts or *.d.tsx @@ -64,6 +65,13 @@ function getNameFromIndexSignature(node: TSESTree.TSIndexSignature): string { return propName ? propName.name : '(index signature)'; } +enum MemberNameType { + Private = 1, + Quoted = 2, + Normal = 3, + Expression = 4, +} + /** * Gets a string name representation of the name of the given MethodDefinition * or PropertyDefinition node, with handling for computed property names. @@ -78,15 +86,38 @@ function getNameFromMember( | TSESTree.Property | TSESTree.TSPropertySignature, sourceCode: TSESLint.SourceCode, -): string { +): { type: MemberNameType; name: string } { if (member.key.type === AST_NODE_TYPES.Identifier) { - return member.key.name; + return { + type: MemberNameType.Normal, + name: member.key.name, + }; + } + if (member.key.type === AST_NODE_TYPES.PrivateIdentifier) { + return { + type: MemberNameType.Private, + name: `#${member.key.name}`, + }; } if (member.key.type === AST_NODE_TYPES.Literal) { - return `${member.key.value}`; + const name = `${member.key.value}`; + if (requiresQuoting(name)) { + return { + type: MemberNameType.Quoted, + name: `"${name}"`, + }; + } else { + return { + type: MemberNameType.Normal, + name, + }; + } } - return sourceCode.text.slice(...member.key.range); + return { + type: MemberNameType.Expression, + name: sourceCode.text.slice(...member.key.range), + }; } type ExcludeKeys< @@ -111,6 +142,7 @@ export { getNameFromIndexSignature, getNameFromMember, isDefinitionFile, + MemberNameType, RequireKeys, upperCaseFirst, }; diff --git a/packages/eslint-plugin/tests/rules/adjacent-overload-signatures.test.ts b/packages/eslint-plugin/tests/rules/adjacent-overload-signatures.test.ts index 0f034a787f7..12cf859a84a 100644 --- a/packages/eslint-plugin/tests/rules/adjacent-overload-signatures.test.ts +++ b/packages/eslint-plugin/tests/rules/adjacent-overload-signatures.test.ts @@ -238,6 +238,18 @@ class Test { interface Foo { [Symbol.toStringTag](): void; [Symbol.iterator](): void; +} + `, + // private members + ` +class Test { + #private(): void; + #private(arg: number): void {} + + bar() {} + + '#private'(): void; + '#private'(arg: number): void {} } `, ], @@ -836,5 +848,30 @@ class Foo { }, ], }, + // private members + { + code: ` +class Test { + #private(): void; + '#private'(): void; + #private(arg: number): void {} + '#private'(arg: number): void {} +} + `, + errors: [ + { + messageId: 'adjacentSignature', + data: { name: '#private' }, + line: 5, + column: 3, + }, + { + messageId: 'adjacentSignature', + data: { name: '"#private"' }, + line: 6, + column: 3, + }, + ], + }, ], }); diff --git a/packages/eslint-plugin/tests/rules/explicit-member-accessibility.test.ts b/packages/eslint-plugin/tests/rules/explicit-member-accessibility.test.ts index 906f1b6cc60..4e070acb325 100644 --- a/packages/eslint-plugin/tests/rules/explicit-member-accessibility.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-member-accessibility.test.ts @@ -330,6 +330,16 @@ class Test { code: ` class Test { constructor(private { x }: any[]) {} +} + `, + options: [{ accessibility: 'no-public' }], + }, + // private members + { + code: ` +class Test { + #foo = 1; + #bar() {} } `, options: [{ accessibility: 'no-public' }], @@ -1070,6 +1080,64 @@ class EnsureWhiteSPaceSpan { output: ` class EnsureWhiteSPaceSpan { /* */ constructor() {} +} + `, + }, + // quoted names + { + code: noFormat` +class Test { + public 'foo' = 1; + public 'foo foo' = 2; + public 'bar'() {} + public 'bar bar'() {} +} + `, + options: [{ accessibility: 'no-public' }], + errors: [ + { + messageId: 'unwantedPublicAccessibility', + data: { + type: 'class property', + name: 'foo', + }, + line: 3, + column: 3, + }, + { + messageId: 'unwantedPublicAccessibility', + data: { + type: 'class property', + name: '"foo foo"', + }, + line: 4, + column: 3, + }, + { + messageId: 'unwantedPublicAccessibility', + data: { + type: 'method definition', + name: 'bar', + }, + line: 5, + column: 3, + }, + { + messageId: 'unwantedPublicAccessibility', + data: { + type: 'method definition', + name: '"bar bar"', + }, + line: 6, + column: 3, + }, + ], + output: noFormat` +class Test { + 'foo' = 1; + 'foo foo' = 2; + 'bar'() {} + 'bar bar'() {} } `, }, diff --git a/packages/eslint-plugin/tests/rules/member-ordering.test.ts b/packages/eslint-plugin/tests/rules/member-ordering.test.ts index e457ef3daf4..97b05cfdeff 100644 --- a/packages/eslint-plugin/tests/rules/member-ordering.test.ts +++ b/packages/eslint-plugin/tests/rules/member-ordering.test.ts @@ -3996,6 +3996,20 @@ class Foo { `, options: [{ default: { memberTypes: 'never', order: 'alphabetically' } }], }, + + // default option + private identifiers + { + code: ` +class Foo { + #a = 1; + #b = 2; + #c = 3; +} + `, + options: [ + { default: { memberTypes: defaultOrder, order: 'alphabetically' } }, + ], + }, ], invalid: [ // default option + interface + wrong order @@ -6349,6 +6363,32 @@ type Foo = { }, ], }, + + // default option + private identifiers + { + code: ` +class Foo { + #c = 3; + #b = 2; + #a = 1; +} + `, + options: [ + { default: { memberTypes: defaultOrder, order: 'alphabetically' } }, + ], + errors: [ + { + messageId: 'incorrectOrder', + line: 4, + column: 3, + }, + { + messageId: 'incorrectOrder', + line: 5, + column: 3, + }, + ], + }, ], }; diff --git a/packages/eslint-plugin/tests/rules/naming-convention.test.ts b/packages/eslint-plugin/tests/rules/naming-convention.test.ts index 1c693b4fde0..d35afe5ed30 100644 --- a/packages/eslint-plugin/tests/rules/naming-convention.test.ts +++ b/packages/eslint-plugin/tests/rules/naming-convention.test.ts @@ -486,7 +486,9 @@ const cases: Cases = [ 'interface Ignored { %: string }', 'type Ignored = { %: string }', 'class Ignored { private % = 1 }', + 'class Ignored { #% = 1 }', 'class Ignored { constructor(private %) {} }', + 'class Ignored { #%() {} }', 'class Ignored { private %() {} }', 'const ignored = { %() {} };', 'class Ignored { private get %() {} }', @@ -562,6 +564,8 @@ const cases: Cases = [ 'class Ignored { private static readonly % = 1 }', 'class Ignored { abstract % = 1 }', 'class Ignored { declare % }', + 'class Ignored { #% }', + 'class Ignored { static #% }', ], options: { selector: 'classProperty', @@ -617,6 +621,8 @@ const cases: Cases = [ 'class Ignored { private % = () => {} }', 'class Ignored { abstract %() }', 'class Ignored { declare %() }', + 'class Ignored { #%() }', + 'class Ignored { static #%() }', ], options: { selector: 'classMethod', @@ -653,6 +659,7 @@ const cases: Cases = [ 'class Ignored { private get %() {} }', 'class Ignored { private set "%"(ignored) {} }', 'class Ignored { private static get %() {} }', + 'class Ignored { static get #%() {} }', ], options: { selector: 'accessor', diff --git a/packages/scope-manager/src/referencer/ClassVisitor.ts b/packages/scope-manager/src/referencer/ClassVisitor.ts index d33e362ea41..6f505044213 100644 --- a/packages/scope-manager/src/referencer/ClassVisitor.ts +++ b/packages/scope-manager/src/referencer/ClassVisitor.ts @@ -353,6 +353,10 @@ class ClassVisitor extends Visitor { protected Identifier(node: TSESTree.Identifier): void { this.#referencer.visit(node); } + + protected PrivateIdentifier(): void { + // intentionally skip + } } /** diff --git a/packages/scope-manager/src/referencer/Referencer.ts b/packages/scope-manager/src/referencer/Referencer.ts index df4c318dadd..9109feb3edb 100644 --- a/packages/scope-manager/src/referencer/Referencer.ts +++ b/packages/scope-manager/src/referencer/Referencer.ts @@ -551,6 +551,10 @@ class Referencer extends Visitor { this.visitType(node.typeParameters); } + protected PrivateIdentifier(): void { + // private identifiers are members on classes and thus have no variables to to reference + } + protected Program(node: TSESTree.Program): void { const globalScope = this.scopeManager.nestGlobalScope(node); this.populateGlobalsFromLib(globalScope); diff --git a/packages/scope-manager/tests/fixtures/class/declaration/private-identifier.ts b/packages/scope-manager/tests/fixtures/class/declaration/private-identifier.ts new file mode 100644 index 00000000000..13ab5d80c3e --- /dev/null +++ b/packages/scope-manager/tests/fixtures/class/declaration/private-identifier.ts @@ -0,0 +1,7 @@ +class Foo { + #bar; + + constructor() { + this.#bar = 1; + } +} diff --git a/packages/scope-manager/tests/fixtures/class/declaration/private-identifier.ts.shot b/packages/scope-manager/tests/fixtures/class/declaration/private-identifier.ts.shot new file mode 100644 index 00000000000..bed463a748a --- /dev/null +++ b/packages/scope-manager/tests/fixtures/class/declaration/private-identifier.ts.shot @@ -0,0 +1,83 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`class declaration private-identifier 1`] = ` +ScopeManager { + variables: Array [ + ImplicitGlobalConstTypeVariable, + Variable$2 { + defs: Array [ + ClassNameDefinition$1 { + name: Identifier<"Foo">, + node: ClassDeclaration$1, + }, + ], + name: "Foo", + references: Array [], + isValueVariable: true, + isTypeVariable: true, + }, + Variable$3 { + defs: Array [ + ClassNameDefinition$2 { + name: Identifier<"Foo">, + node: ClassDeclaration$1, + }, + ], + name: "Foo", + references: Array [], + isValueVariable: true, + isTypeVariable: true, + }, + Variable$4 { + defs: Array [], + name: "arguments", + references: Array [], + isValueVariable: true, + isTypeVariable: true, + }, + ], + scopes: Array [ + GlobalScope$1 { + block: Program$2, + isStrict: false, + references: Array [], + set: Map { + "const" => ImplicitGlobalConstTypeVariable, + "Foo" => Variable$2, + }, + type: "global", + upper: null, + variables: Array [ + ImplicitGlobalConstTypeVariable, + Variable$2, + ], + }, + ClassScope$2 { + block: ClassDeclaration$1, + isStrict: true, + references: Array [], + set: Map { + "Foo" => Variable$3, + }, + type: "class", + upper: GlobalScope$1, + variables: Array [ + Variable$3, + ], + }, + FunctionScope$3 { + block: FunctionExpression$3, + isStrict: true, + references: Array [], + set: Map { + "arguments" => Variable$4, + }, + type: "function", + upper: ClassScope$2, + variables: Array [ + Variable$4, + ], + }, + ], +} +`; diff --git a/packages/scope-manager/tests/fixtures/class/expression/private-identifier.ts b/packages/scope-manager/tests/fixtures/class/expression/private-identifier.ts new file mode 100644 index 00000000000..95d1cb660ad --- /dev/null +++ b/packages/scope-manager/tests/fixtures/class/expression/private-identifier.ts @@ -0,0 +1,7 @@ +const Foo = class { + #bar; + + constructor() { + this.#bar = 1; + } +}; diff --git a/packages/scope-manager/tests/fixtures/class/expression/private-identifier.ts.shot b/packages/scope-manager/tests/fixtures/class/expression/private-identifier.ts.shot new file mode 100644 index 00000000000..d9961a85763 --- /dev/null +++ b/packages/scope-manager/tests/fixtures/class/expression/private-identifier.ts.shot @@ -0,0 +1,80 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`class expression private-identifier 1`] = ` +ScopeManager { + variables: Array [ + ImplicitGlobalConstTypeVariable, + Variable$2 { + defs: Array [ + VariableDefinition$1 { + name: Identifier<"Foo">, + node: VariableDeclarator$1, + }, + ], + name: "Foo", + references: Array [ + Reference$1 { + identifier: Identifier<"Foo">, + init: true, + isRead: false, + isTypeReference: false, + isValueReference: true, + isWrite: true, + resolved: Variable$2, + writeExpr: ClassExpression$2, + }, + ], + isValueVariable: true, + isTypeVariable: false, + }, + Variable$3 { + defs: Array [], + name: "arguments", + references: Array [], + isValueVariable: true, + isTypeVariable: true, + }, + ], + scopes: Array [ + GlobalScope$1 { + block: Program$3, + isStrict: false, + references: Array [ + Reference$1, + ], + set: Map { + "const" => ImplicitGlobalConstTypeVariable, + "Foo" => Variable$2, + }, + type: "global", + upper: null, + variables: Array [ + ImplicitGlobalConstTypeVariable, + Variable$2, + ], + }, + ClassScope$2 { + block: ClassExpression$2, + isStrict: true, + references: Array [], + set: Map {}, + type: "class", + upper: GlobalScope$1, + variables: Array [], + }, + FunctionScope$3 { + block: FunctionExpression$4, + isStrict: true, + references: Array [], + set: Map { + "arguments" => Variable$3, + }, + type: "function", + upper: ClassScope$2, + variables: Array [ + Variable$3, + ], + }, + ], +} +`; diff --git a/packages/shared-fixtures/fixtures/javascript/classes/class-private-identifier-accessor.src.js b/packages/shared-fixtures/fixtures/javascript/classes/class-private-identifier-accessor.src.js new file mode 100644 index 00000000000..6a8a8993195 --- /dev/null +++ b/packages/shared-fixtures/fixtures/javascript/classes/class-private-identifier-accessor.src.js @@ -0,0 +1,8 @@ +class Foo { + get #priv1() { return 1 } + set #priv1(value) { } + + constructor() { + this.#priv1 = 1; + } +} diff --git a/packages/shared-fixtures/fixtures/javascript/classes/class-private-identifier-field.src.js b/packages/shared-fixtures/fixtures/javascript/classes/class-private-identifier-field.src.js new file mode 100644 index 00000000000..4519b85cd97 --- /dev/null +++ b/packages/shared-fixtures/fixtures/javascript/classes/class-private-identifier-field.src.js @@ -0,0 +1,8 @@ +class Foo { + #priv1; + #priv2 = 1; + + constructor() { + this.#priv1 = 1; + } +} diff --git a/packages/shared-fixtures/fixtures/javascript/classes/class-private-identifier-method.src.js b/packages/shared-fixtures/fixtures/javascript/classes/class-private-identifier-method.src.js new file mode 100644 index 00000000000..f2694d08e36 --- /dev/null +++ b/packages/shared-fixtures/fixtures/javascript/classes/class-private-identifier-method.src.js @@ -0,0 +1,7 @@ +class Foo { + #bar() {} + + constructor() { + this.#bar(); + } +} diff --git a/packages/shared-fixtures/fixtures/typescript/basics/class-private-identifier-field-with-accessibility-error.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/class-private-identifier-field-with-accessibility-error.src.ts new file mode 100644 index 00000000000..554ea66635a --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/basics/class-private-identifier-field-with-accessibility-error.src.ts @@ -0,0 +1,5 @@ +class Foo { + private #priv1: string + public #priv2: string + static #priv3: string +} diff --git a/packages/shared-fixtures/fixtures/typescript/basics/class-private-identifier-field-with-annotation.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/class-private-identifier-field-with-annotation.src.ts new file mode 100644 index 00000000000..f771a81a83a --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/basics/class-private-identifier-field-with-annotation.src.ts @@ -0,0 +1,8 @@ +class Foo { + #priv1: number; + #priv2: number = 1; + + constructor() { + this.#priv1 = 1; + } +} diff --git a/packages/shared-fixtures/fixtures/typescript/basics/class-private-identifier-readonly-field.src.ts b/packages/shared-fixtures/fixtures/typescript/basics/class-private-identifier-readonly-field.src.ts new file mode 100644 index 00000000000..254995a222b --- /dev/null +++ b/packages/shared-fixtures/fixtures/typescript/basics/class-private-identifier-readonly-field.src.ts @@ -0,0 +1,3 @@ +class Foo { + readonly #priv: string +} diff --git a/packages/types/tools/copy-ast-spec.ts b/packages/types/tools/copy-ast-spec.ts index ed231195eeb..0288453a310 100644 --- a/packages/types/tools/copy-ast-spec.ts +++ b/packages/types/tools/copy-ast-spec.ts @@ -11,7 +11,7 @@ const AST_SPEC_PATH = path.resolve(__dirname, '../../ast-spec'); const OUTPUT_PATH = path.join(path.resolve(__dirname, '../src/')); // ensure the package is built -chlidProcess.execSync('yarn build', { cwd: AST_SPEC_PATH }); +chlidProcess.execSync('yarn build', { cwd: AST_SPEC_PATH, stdio: 'inherit' }); const HEADER = `\ /********************************************** diff --git a/packages/typescript-estree/src/convert.ts b/packages/typescript-estree/src/convert.ts index 0846087759f..e800233a710 100644 --- a/packages/typescript-estree/src/convert.ts +++ b/packages/typescript-estree/src/convert.ts @@ -775,6 +775,14 @@ export class Converter { }); } + case SyntaxKind.PrivateIdentifier: { + return this.createNode(node, { + type: AST_NODE_TYPES.PrivateIdentifier, + // typescript includes the `#` in the text + name: node.text.slice(1), + }); + } + case SyntaxKind.WithStatement: return this.createNode(node, { type: AST_NODE_TYPES.WithStatement, diff --git a/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts b/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts index 07b2bb5db31..586aea269ee 100644 --- a/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts +++ b/packages/typescript-estree/src/ts-estree/estree-to-ts-node-types.ts @@ -72,6 +72,7 @@ export interface EstreeToTsNodeTypes { | ts.Identifier | ts.ConstructorDeclaration | ts.Token; + [AST_NODE_TYPES.PrivateIdentifier]: ts.PrivateIdentifier; [AST_NODE_TYPES.IfStatement]: ts.IfStatement; [AST_NODE_TYPES.ImportDeclaration]: ts.ImportDeclaration; [AST_NODE_TYPES.ImportDefaultSpecifier]: ts.ImportClause; diff --git a/packages/typescript-estree/src/ts-estree/ts-nodes.ts b/packages/typescript-estree/src/ts-estree/ts-nodes.ts index 673dd6f9831..79756053e08 100644 --- a/packages/typescript-estree/src/ts-estree/ts-nodes.ts +++ b/packages/typescript-estree/src/ts-estree/ts-nodes.ts @@ -6,6 +6,8 @@ declare module 'typescript' { /* eslint-disable @typescript-eslint/no-empty-interface */ export interface NamedTupleMember extends ts.Node {} export interface TemplateLiteralTypeNode extends ts.Node {} + export interface PrivateIdentifier extends ts.Node {} + export interface ClassStaticBlockDeclaration extends ts.Node {} /* eslint-enable @typescript-eslint/no-empty-interface */ } @@ -14,6 +16,7 @@ export type TSToken = ts.Token; export type TSNode = | ts.Modifier | ts.Identifier + | ts.PrivateIdentifier | ts.QualifiedName | ts.ComputedPropertyName | ts.Decorator diff --git a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts index a3400b97d33..3f4246b037c 100644 --- a/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts +++ b/packages/typescript-estree/tests/ast-alignment/fixtures-to-test.ts @@ -181,6 +181,12 @@ tester.addFixturePatternConfig('javascript/classes', { * TS3.6 made computed constructors parse as actual constructors. */ 'class-two-methods-computed-constructor', + /** + * Babel emits a `PrivateName` instead of `PrivateIdentifier` + */ + 'class-private-identifier-accessor', + 'class-private-identifier-method', + 'class-private-identifier-field', ], }); @@ -386,6 +392,15 @@ tester.addFixturePatternConfig('typescript/basics', { * This is intentional; babel is not checking types */ 'catch-clause-with-invalid-annotation', + /** + * [BABEL ERRORED, BUT TS-ESTREE DID NOT] + * TODO: enforce that accessibility is not allowed on a private identifier + */ + 'class-private-identifier-field-with-accessibility-error', + /** + * Babel emits a `PrivateName` instead of `PrivateIdentifier` + */ + 'class-private-identifier-field-with-annotation', /** * [TS-ESTREE ERRORED, BUT BABEL DID NOT] * TypeScript 4.4 new feature diff --git a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap index 031e7f61e12..2a46c9188cb 100644 --- a/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap +++ b/packages/typescript-estree/tests/lib/__snapshots__/semantic-diagnostics-enabled.test.ts.snap @@ -273,6 +273,12 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/classes/class-one-method-super.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/classes/class-private-identifier-accessor.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/classes/class-private-identifier-field.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/classes/class-private-identifier-method.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/classes/class-static-method.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/javascript/classes/class-static-method-named-prototype.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; @@ -1751,6 +1757,12 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-multi-line-keyword-declare.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-private-identifier-field-with-accessibility-error.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-private-identifier-field-with-annotation.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + +exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-private-identifier-readonly-field.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; + exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-static-blocks.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/class-with-accessibility-modifiers.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`; diff --git a/packages/typescript-estree/tests/snapshots/javascript/classes/class-private-identifier-accessor.src.js.shot b/packages/typescript-estree/tests/snapshots/javascript/classes/class-private-identifier-accessor.src.js.shot new file mode 100644 index 00000000000..07249d71dc9 --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/javascript/classes/class-private-identifier-accessor.src.js.shot @@ -0,0 +1,1024 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`javascript classes class-private-identifier-accessor.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "name": "priv1", + "range": Array [ + 18, + 24, + ], + "type": "PrivateIdentifier", + }, + "kind": "get", + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "override": false, + "range": Array [ + 14, + 39, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [ + Object { + "argument": Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 2, + }, + "start": Object { + "column": 24, + "line": 2, + }, + }, + "range": Array [ + 36, + 37, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + "loc": Object { + "end": Object { + "column": 25, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 29, + 37, + ], + "type": "ReturnStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 27, + 39, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 12, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 24, + 39, + ], + "type": "FunctionExpression", + }, + }, + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 3, + }, + "start": Object { + "column": 6, + "line": 3, + }, + }, + "name": "priv1", + "range": Array [ + 46, + 52, + ], + "type": "PrivateIdentifier", + }, + "kind": "set", + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "override": false, + "range": Array [ + 42, + 63, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 20, + "line": 3, + }, + }, + "range": Array [ + 60, + 63, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 12, + "line": 3, + }, + }, + "params": Array [ + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 13, + "line": 3, + }, + }, + "name": "value", + "range": Array [ + 53, + 58, + ], + "type": "Identifier", + }, + ], + "range": Array [ + 52, + 63, + ], + "type": "FunctionExpression", + }, + }, + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "name": "constructor", + "range": Array [ + 67, + 78, + ], + "type": "Identifier", + }, + "kind": "constructor", + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "override": false, + "range": Array [ + 67, + 107, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [ + Object { + "expression": Object { + "left": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 15, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "range": Array [ + 87, + 91, + ], + "type": "ThisExpression", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 6, + }, + "start": Object { + "column": 9, + "line": 6, + }, + }, + "name": "priv1", + "range": Array [ + 92, + 98, + ], + "type": "PrivateIdentifier", + }, + "range": Array [ + 87, + 98, + ], + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 19, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "operator": "=", + "range": Array [ + 87, + 102, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 6, + }, + "start": Object { + "column": 18, + "line": 6, + }, + }, + "range": Array [ + 101, + 102, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + "type": "AssignmentExpression", + }, + "loc": Object { + "end": Object { + "column": 20, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "range": Array [ + 87, + 103, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 16, + "line": 5, + }, + }, + "range": Array [ + 81, + 107, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 13, + "line": 5, + }, + }, + "params": Array [], + "range": Array [ + 78, + 107, + ], + "type": "FunctionExpression", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 109, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "Foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 109, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 9, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 110, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "Foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 17, + ], + "type": "Identifier", + "value": "get", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 18, + 24, + ], + "type": "Identifier", + "value": "#priv1", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 2, + }, + "start": Object { + "column": 12, + "line": 2, + }, + }, + "range": Array [ + 24, + 25, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 2, + }, + "start": Object { + "column": 13, + "line": 2, + }, + }, + "range": Array [ + 25, + 26, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 15, + "line": 2, + }, + }, + "range": Array [ + 27, + 28, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 2, + }, + "start": Object { + "column": 17, + "line": 2, + }, + }, + "range": Array [ + 29, + 35, + ], + "type": "Keyword", + "value": "return", + }, + Object { + "loc": Object { + "end": Object { + "column": 25, + "line": 2, + }, + "start": Object { + "column": 24, + "line": 2, + }, + }, + "range": Array [ + 36, + 37, + ], + "type": "Numeric", + "value": "1", + }, + Object { + "loc": Object { + "end": Object { + "column": 27, + "line": 2, + }, + "start": Object { + "column": 26, + "line": 2, + }, + }, + "range": Array [ + 38, + 39, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "range": Array [ + 42, + 45, + ], + "type": "Identifier", + "value": "set", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 3, + }, + "start": Object { + "column": 6, + "line": 3, + }, + }, + "range": Array [ + 46, + 52, + ], + "type": "Identifier", + "value": "#priv1", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 12, + "line": 3, + }, + }, + "range": Array [ + 52, + 53, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 13, + "line": 3, + }, + }, + "range": Array [ + 53, + 58, + ], + "type": "Identifier", + "value": "value", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 3, + }, + "start": Object { + "column": 18, + "line": 3, + }, + }, + "range": Array [ + 58, + 59, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 3, + }, + "start": Object { + "column": 20, + "line": 3, + }, + }, + "range": Array [ + 60, + 61, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 22, + "line": 3, + }, + }, + "range": Array [ + 62, + 63, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "range": Array [ + 67, + 78, + ], + "type": "Identifier", + "value": "constructor", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 5, + }, + "start": Object { + "column": 13, + "line": 5, + }, + }, + "range": Array [ + 78, + 79, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 5, + }, + "start": Object { + "column": 14, + "line": 5, + }, + }, + "range": Array [ + 79, + 80, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 5, + }, + "start": Object { + "column": 16, + "line": 5, + }, + }, + "range": Array [ + 81, + 82, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "range": Array [ + 87, + 91, + ], + "type": "Keyword", + "value": "this", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 6, + }, + "start": Object { + "column": 8, + "line": 6, + }, + }, + "range": Array [ + 91, + 92, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 6, + }, + "start": Object { + "column": 9, + "line": 6, + }, + }, + "range": Array [ + 92, + 98, + ], + "type": "Identifier", + "value": "#priv1", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 6, + }, + "start": Object { + "column": 16, + "line": 6, + }, + }, + "range": Array [ + 99, + 100, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 6, + }, + "start": Object { + "column": 18, + "line": 6, + }, + }, + "range": Array [ + 101, + 102, + ], + "type": "Numeric", + "value": "1", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 6, + }, + "start": Object { + "column": 19, + "line": 6, + }, + }, + "range": Array [ + 102, + 103, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 2, + "line": 7, + }, + }, + "range": Array [ + 106, + 107, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 8, + }, + }, + "range": Array [ + 108, + 109, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; diff --git a/packages/typescript-estree/tests/snapshots/javascript/classes/class-private-identifier-field.src.js.shot b/packages/typescript-estree/tests/snapshots/javascript/classes/class-private-identifier-field.src.js.shot new file mode 100644 index 00000000000..63586a9fa6d --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/javascript/classes/class-private-identifier-field.src.js.shot @@ -0,0 +1,748 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`javascript classes class-private-identifier-field.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "declare": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "name": "priv1", + "range": Array [ + 14, + 20, + ], + "type": "PrivateIdentifier", + }, + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "override": false, + "range": Array [ + 14, + 21, + ], + "readonly": undefined, + "static": false, + "type": "PropertyDefinition", + "value": null, + }, + Object { + "computed": false, + "declare": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "name": "priv2", + "range": Array [ + 24, + 30, + ], + "type": "PrivateIdentifier", + }, + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "override": false, + "range": Array [ + 24, + 35, + ], + "readonly": undefined, + "static": false, + "type": "PropertyDefinition", + "value": Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 3, + }, + "start": Object { + "column": 11, + "line": 3, + }, + }, + "range": Array [ + 33, + 34, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + }, + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "name": "constructor", + "range": Array [ + 39, + 50, + ], + "type": "Identifier", + }, + "kind": "constructor", + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "override": false, + "range": Array [ + 39, + 79, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [ + Object { + "expression": Object { + "left": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 15, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "range": Array [ + 59, + 63, + ], + "type": "ThisExpression", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 6, + }, + "start": Object { + "column": 9, + "line": 6, + }, + }, + "name": "priv1", + "range": Array [ + 64, + 70, + ], + "type": "PrivateIdentifier", + }, + "range": Array [ + 59, + 70, + ], + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 19, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "operator": "=", + "range": Array [ + 59, + 74, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 6, + }, + "start": Object { + "column": 18, + "line": 6, + }, + }, + "range": Array [ + 73, + 74, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + "type": "AssignmentExpression", + }, + "loc": Object { + "end": Object { + "column": 20, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "range": Array [ + 59, + 75, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 16, + "line": 5, + }, + }, + "range": Array [ + 53, + 79, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 13, + "line": 5, + }, + }, + "params": Array [], + "range": Array [ + 50, + 79, + ], + "type": "FunctionExpression", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 81, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "Foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 81, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 9, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 82, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "Foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 20, + ], + "type": "Identifier", + "value": "#priv1", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "range": Array [ + 24, + 30, + ], + "type": "Identifier", + "value": "#priv2", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 3, + }, + "start": Object { + "column": 9, + "line": 3, + }, + }, + "range": Array [ + 31, + 32, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 12, + "line": 3, + }, + "start": Object { + "column": 11, + "line": 3, + }, + }, + "range": Array [ + 33, + 34, + ], + "type": "Numeric", + "value": "1", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 3, + }, + "start": Object { + "column": 12, + "line": 3, + }, + }, + "range": Array [ + 34, + 35, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "range": Array [ + 39, + 50, + ], + "type": "Identifier", + "value": "constructor", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 5, + }, + "start": Object { + "column": 13, + "line": 5, + }, + }, + "range": Array [ + 50, + 51, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 5, + }, + "start": Object { + "column": 14, + "line": 5, + }, + }, + "range": Array [ + 51, + 52, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 5, + }, + "start": Object { + "column": 16, + "line": 5, + }, + }, + "range": Array [ + 53, + 54, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "range": Array [ + 59, + 63, + ], + "type": "Keyword", + "value": "this", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 6, + }, + "start": Object { + "column": 8, + "line": 6, + }, + }, + "range": Array [ + 63, + 64, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 6, + }, + "start": Object { + "column": 9, + "line": 6, + }, + }, + "range": Array [ + 64, + 70, + ], + "type": "Identifier", + "value": "#priv1", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 6, + }, + "start": Object { + "column": 16, + "line": 6, + }, + }, + "range": Array [ + 71, + 72, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 6, + }, + "start": Object { + "column": 18, + "line": 6, + }, + }, + "range": Array [ + 73, + 74, + ], + "type": "Numeric", + "value": "1", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 6, + }, + "start": Object { + "column": 19, + "line": 6, + }, + }, + "range": Array [ + 74, + 75, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 2, + "line": 7, + }, + }, + "range": Array [ + 78, + 79, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 8, + }, + }, + "range": Array [ + 80, + 81, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; diff --git a/packages/typescript-estree/tests/snapshots/javascript/classes/class-private-identifier-method.src.js.shot b/packages/typescript-estree/tests/snapshots/javascript/classes/class-private-identifier-method.src.js.shot new file mode 100644 index 00000000000..099a48f546c --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/javascript/classes/class-private-identifier-method.src.js.shot @@ -0,0 +1,691 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`javascript classes class-private-identifier-method.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "name": "bar", + "range": Array [ + 14, + 18, + ], + "type": "PrivateIdentifier", + }, + "kind": "method", + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "override": false, + "range": Array [ + 14, + 23, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [], + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 21, + 23, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "params": Array [], + "range": Array [ + 18, + 23, + ], + "type": "FunctionExpression", + }, + }, + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "name": "constructor", + "range": Array [ + 27, + 38, + ], + "type": "Identifier", + }, + "kind": "constructor", + "loc": Object { + "end": Object { + "column": 3, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "override": false, + "range": Array [ + 27, + 63, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [ + Object { + "expression": Object { + "arguments": Array [], + "callee": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 4, + "line": 5, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 5, + }, + "start": Object { + "column": 4, + "line": 5, + }, + }, + "range": Array [ + 47, + 51, + ], + "type": "ThisExpression", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 9, + "line": 5, + }, + }, + "name": "bar", + "range": Array [ + 52, + 56, + ], + "type": "PrivateIdentifier", + }, + "range": Array [ + 47, + 56, + ], + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 15, + "line": 5, + }, + "start": Object { + "column": 4, + "line": 5, + }, + }, + "optional": false, + "range": Array [ + 47, + 58, + ], + "type": "CallExpression", + }, + "loc": Object { + "end": Object { + "column": 16, + "line": 5, + }, + "start": Object { + "column": 4, + "line": 5, + }, + }, + "range": Array [ + 47, + 59, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 3, + "line": 6, + }, + "start": Object { + "column": 16, + "line": 4, + }, + }, + "range": Array [ + 41, + 63, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 3, + "line": 6, + }, + "start": Object { + "column": 13, + "line": 4, + }, + }, + "params": Array [], + "range": Array [ + 38, + 63, + ], + "type": "FunctionExpression", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 7, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 65, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "Foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 7, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 65, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 66, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "Foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 6, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 18, + ], + "type": "Identifier", + "value": "#bar", + }, + Object { + "loc": Object { + "end": Object { + "column": 7, + "line": 2, + }, + "start": Object { + "column": 6, + "line": 2, + }, + }, + "range": Array [ + 18, + 19, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 7, + "line": 2, + }, + }, + "range": Array [ + 19, + 20, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 9, + "line": 2, + }, + }, + "range": Array [ + 21, + 22, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 22, + 23, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "range": Array [ + 27, + 38, + ], + "type": "Identifier", + "value": "constructor", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 4, + }, + "start": Object { + "column": 13, + "line": 4, + }, + }, + "range": Array [ + 38, + 39, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 4, + }, + "start": Object { + "column": 14, + "line": 4, + }, + }, + "range": Array [ + 39, + 40, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 4, + }, + "start": Object { + "column": 16, + "line": 4, + }, + }, + "range": Array [ + 41, + 42, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 5, + }, + "start": Object { + "column": 4, + "line": 5, + }, + }, + "range": Array [ + 47, + 51, + ], + "type": "Keyword", + "value": "this", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 5, + }, + "start": Object { + "column": 8, + "line": 5, + }, + }, + "range": Array [ + 51, + 52, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 9, + "line": 5, + }, + }, + "range": Array [ + 52, + 56, + ], + "type": "Identifier", + "value": "#bar", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 5, + }, + "start": Object { + "column": 13, + "line": 5, + }, + }, + "range": Array [ + 56, + 57, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 5, + }, + "start": Object { + "column": 14, + "line": 5, + }, + }, + "range": Array [ + 57, + 58, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 5, + }, + "start": Object { + "column": 15, + "line": 5, + }, + }, + "range": Array [ + 58, + 59, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 6, + }, + "start": Object { + "column": 2, + "line": 6, + }, + }, + "range": Array [ + 62, + 63, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 7, + }, + "start": Object { + "column": 0, + "line": 7, + }, + }, + "range": Array [ + 64, + 65, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/class-private-identifier-field-with-accessibility-error.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/class-private-identifier-field-with-accessibility-error.src.ts.shot new file mode 100644 index 00000000000..04b127b9d7e --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/class-private-identifier-field-with-accessibility-error.src.ts.shot @@ -0,0 +1,597 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`typescript basics class-private-identifier-field-with-accessibility-error.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "accessibility": "private", + "computed": false, + "declare": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "name": "priv1", + "range": Array [ + 22, + 28, + ], + "type": "PrivateIdentifier", + }, + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "override": false, + "range": Array [ + 14, + 36, + ], + "readonly": undefined, + "static": false, + "type": "PropertyDefinition", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 28, + 36, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 30, + 36, + ], + "type": "TSStringKeyword", + }, + }, + "value": null, + }, + Object { + "accessibility": "public", + "computed": false, + "declare": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 9, + "line": 3, + }, + }, + "name": "priv2", + "range": Array [ + 46, + 52, + ], + "type": "PrivateIdentifier", + }, + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "override": false, + "range": Array [ + 39, + 60, + ], + "readonly": undefined, + "static": false, + "type": "PropertyDefinition", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 52, + 60, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 17, + "line": 3, + }, + }, + "range": Array [ + 54, + 60, + ], + "type": "TSStringKeyword", + }, + }, + "value": null, + }, + Object { + "computed": false, + "declare": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 4, + }, + "start": Object { + "column": 9, + "line": 4, + }, + }, + "name": "priv3", + "range": Array [ + 70, + 76, + ], + "type": "PrivateIdentifier", + }, + "loc": Object { + "end": Object { + "column": 23, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "override": false, + "range": Array [ + 63, + 84, + ], + "readonly": undefined, + "static": true, + "type": "PropertyDefinition", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 4, + }, + "start": Object { + "column": 15, + "line": 4, + }, + }, + "range": Array [ + 76, + 84, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 4, + }, + "start": Object { + "column": 17, + "line": 4, + }, + }, + "range": Array [ + 78, + 84, + ], + "type": "TSStringKeyword", + }, + }, + "value": null, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 86, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "Foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 86, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 6, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 87, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "Foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 21, + ], + "type": "Keyword", + "value": "private", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 22, + 28, + ], + "type": "Identifier", + "value": "#priv1", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 30, + 36, + ], + "type": "Identifier", + "value": "string", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "range": Array [ + 39, + 45, + ], + "type": "Keyword", + "value": "public", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 3, + }, + "start": Object { + "column": 9, + "line": 3, + }, + }, + "range": Array [ + 46, + 52, + ], + "type": "Identifier", + "value": "#priv2", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 15, + "line": 3, + }, + }, + "range": Array [ + 52, + 53, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 3, + }, + "start": Object { + "column": 17, + "line": 3, + }, + }, + "range": Array [ + 54, + 60, + ], + "type": "Identifier", + "value": "string", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 4, + }, + "start": Object { + "column": 2, + "line": 4, + }, + }, + "range": Array [ + 63, + 69, + ], + "type": "Keyword", + "value": "static", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 4, + }, + "start": Object { + "column": 9, + "line": 4, + }, + }, + "range": Array [ + 70, + 76, + ], + "type": "Identifier", + "value": "#priv3", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 4, + }, + "start": Object { + "column": 15, + "line": 4, + }, + }, + "range": Array [ + 76, + 77, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 23, + "line": 4, + }, + "start": Object { + "column": 17, + "line": 4, + }, + }, + "range": Array [ + 78, + 84, + ], + "type": "Identifier", + "value": "string", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 5, + }, + "start": Object { + "column": 0, + "line": 5, + }, + }, + "range": Array [ + 85, + 86, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/class-private-identifier-field-with-annotation.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/class-private-identifier-field-with-annotation.src.ts.shot new file mode 100644 index 00000000000..c75fc510111 --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/class-private-identifier-field-with-annotation.src.ts.shot @@ -0,0 +1,888 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`typescript basics class-private-identifier-field-with-annotation.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "declare": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "name": "priv1", + "range": Array [ + 14, + 20, + ], + "type": "PrivateIdentifier", + }, + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "override": false, + "range": Array [ + 14, + 29, + ], + "readonly": undefined, + "static": false, + "type": "PropertyDefinition", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 20, + 28, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 22, + 28, + ], + "type": "TSNumberKeyword", + }, + }, + "value": null, + }, + Object { + "computed": false, + "declare": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "name": "priv2", + "range": Array [ + 32, + 38, + ], + "type": "PrivateIdentifier", + }, + "loc": Object { + "end": Object { + "column": 21, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "override": false, + "range": Array [ + 32, + 51, + ], + "readonly": undefined, + "static": false, + "type": "PropertyDefinition", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 38, + 46, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "range": Array [ + 40, + 46, + ], + "type": "TSNumberKeyword", + }, + }, + "value": Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 3, + }, + "start": Object { + "column": 19, + "line": 3, + }, + }, + "range": Array [ + 49, + 50, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + }, + Object { + "computed": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "name": "constructor", + "range": Array [ + 55, + 66, + ], + "type": "Identifier", + }, + "kind": "constructor", + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "override": false, + "range": Array [ + 55, + 95, + ], + "static": false, + "type": "MethodDefinition", + "value": Object { + "async": false, + "body": Object { + "body": Array [ + Object { + "expression": Object { + "left": Object { + "computed": false, + "loc": Object { + "end": Object { + "column": 15, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "object": Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "range": Array [ + 75, + 79, + ], + "type": "ThisExpression", + }, + "optional": false, + "property": Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 6, + }, + "start": Object { + "column": 9, + "line": 6, + }, + }, + "name": "priv1", + "range": Array [ + 80, + 86, + ], + "type": "PrivateIdentifier", + }, + "range": Array [ + 75, + 86, + ], + "type": "MemberExpression", + }, + "loc": Object { + "end": Object { + "column": 19, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "operator": "=", + "range": Array [ + 75, + 90, + ], + "right": Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 6, + }, + "start": Object { + "column": 18, + "line": 6, + }, + }, + "range": Array [ + 89, + 90, + ], + "raw": "1", + "type": "Literal", + "value": 1, + }, + "type": "AssignmentExpression", + }, + "loc": Object { + "end": Object { + "column": 20, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "range": Array [ + 75, + 91, + ], + "type": "ExpressionStatement", + }, + ], + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 16, + "line": 5, + }, + }, + "range": Array [ + 69, + 95, + ], + "type": "BlockStatement", + }, + "expression": false, + "generator": false, + "id": null, + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 13, + "line": 5, + }, + }, + "params": Array [], + "range": Array [ + 66, + 95, + ], + "type": "FunctionExpression", + }, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 97, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "Foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 97, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 9, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 98, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "Foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 20, + ], + "type": "Identifier", + "value": "#priv1", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 2, + }, + "start": Object { + "column": 8, + "line": 2, + }, + }, + "range": Array [ + 20, + 21, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 10, + "line": 2, + }, + }, + "range": Array [ + 22, + 28, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 3, + }, + "start": Object { + "column": 2, + "line": 3, + }, + }, + "range": Array [ + 32, + 38, + ], + "type": "Identifier", + "value": "#priv2", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 3, + }, + "start": Object { + "column": 8, + "line": 3, + }, + }, + "range": Array [ + 38, + 39, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 3, + }, + }, + "range": Array [ + 40, + 46, + ], + "type": "Identifier", + "value": "number", + }, + Object { + "loc": Object { + "end": Object { + "column": 18, + "line": 3, + }, + "start": Object { + "column": 17, + "line": 3, + }, + }, + "range": Array [ + 47, + 48, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 3, + }, + "start": Object { + "column": 19, + "line": 3, + }, + }, + "range": Array [ + 49, + 50, + ], + "type": "Numeric", + "value": "1", + }, + Object { + "loc": Object { + "end": Object { + "column": 21, + "line": 3, + }, + "start": Object { + "column": 20, + "line": 3, + }, + }, + "range": Array [ + 50, + 51, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 13, + "line": 5, + }, + "start": Object { + "column": 2, + "line": 5, + }, + }, + "range": Array [ + 55, + 66, + ], + "type": "Identifier", + "value": "constructor", + }, + Object { + "loc": Object { + "end": Object { + "column": 14, + "line": 5, + }, + "start": Object { + "column": 13, + "line": 5, + }, + }, + "range": Array [ + 66, + 67, + ], + "type": "Punctuator", + "value": "(", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 5, + }, + "start": Object { + "column": 14, + "line": 5, + }, + }, + "range": Array [ + 67, + 68, + ], + "type": "Punctuator", + "value": ")", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 5, + }, + "start": Object { + "column": 16, + "line": 5, + }, + }, + "range": Array [ + 69, + 70, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 8, + "line": 6, + }, + "start": Object { + "column": 4, + "line": 6, + }, + }, + "range": Array [ + 75, + 79, + ], + "type": "Keyword", + "value": "this", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 6, + }, + "start": Object { + "column": 8, + "line": 6, + }, + }, + "range": Array [ + 79, + 80, + ], + "type": "Punctuator", + "value": ".", + }, + Object { + "loc": Object { + "end": Object { + "column": 15, + "line": 6, + }, + "start": Object { + "column": 9, + "line": 6, + }, + }, + "range": Array [ + 80, + 86, + ], + "type": "Identifier", + "value": "#priv1", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 6, + }, + "start": Object { + "column": 16, + "line": 6, + }, + }, + "range": Array [ + 87, + 88, + ], + "type": "Punctuator", + "value": "=", + }, + Object { + "loc": Object { + "end": Object { + "column": 19, + "line": 6, + }, + "start": Object { + "column": 18, + "line": 6, + }, + }, + "range": Array [ + 89, + 90, + ], + "type": "Numeric", + "value": "1", + }, + Object { + "loc": Object { + "end": Object { + "column": 20, + "line": 6, + }, + "start": Object { + "column": 19, + "line": 6, + }, + }, + "range": Array [ + 90, + 91, + ], + "type": "Punctuator", + "value": ";", + }, + Object { + "loc": Object { + "end": Object { + "column": 3, + "line": 7, + }, + "start": Object { + "column": 2, + "line": 7, + }, + }, + "range": Array [ + 94, + 95, + ], + "type": "Punctuator", + "value": "}", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 8, + }, + "start": Object { + "column": 0, + "line": 8, + }, + }, + "range": Array [ + 96, + 97, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; diff --git a/packages/typescript-estree/tests/snapshots/typescript/basics/class-private-identifier-readonly-field.src.ts.shot b/packages/typescript-estree/tests/snapshots/typescript/basics/class-private-identifier-readonly-field.src.ts.shot new file mode 100644 index 00000000000..1131eb4ab21 --- /dev/null +++ b/packages/typescript-estree/tests/snapshots/typescript/basics/class-private-identifier-readonly-field.src.ts.shot @@ -0,0 +1,301 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`typescript basics class-private-identifier-readonly-field.src 1`] = ` +Object { + "body": Array [ + Object { + "body": Object { + "body": Array [ + Object { + "computed": false, + "declare": false, + "key": Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "name": "priv", + "range": Array [ + 23, + 28, + ], + "type": "PrivateIdentifier", + }, + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "override": false, + "range": Array [ + 14, + 36, + ], + "readonly": true, + "static": false, + "type": "PropertyDefinition", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 28, + 36, + ], + "type": "TSTypeAnnotation", + "typeAnnotation": Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 30, + 36, + ], + "type": "TSStringKeyword", + }, + }, + "value": null, + }, + ], + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 38, + ], + "type": "ClassBody", + }, + "id": Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "name": "Foo", + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + }, + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 38, + ], + "superClass": null, + "type": "ClassDeclaration", + }, + ], + "comments": Array [], + "loc": Object { + "end": Object { + "column": 0, + "line": 4, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 39, + ], + "sourceType": "script", + "tokens": Array [ + Object { + "loc": Object { + "end": Object { + "column": 5, + "line": 1, + }, + "start": Object { + "column": 0, + "line": 1, + }, + }, + "range": Array [ + 0, + 5, + ], + "type": "Keyword", + "value": "class", + }, + Object { + "loc": Object { + "end": Object { + "column": 9, + "line": 1, + }, + "start": Object { + "column": 6, + "line": 1, + }, + }, + "range": Array [ + 6, + 9, + ], + "type": "Identifier", + "value": "Foo", + }, + Object { + "loc": Object { + "end": Object { + "column": 11, + "line": 1, + }, + "start": Object { + "column": 10, + "line": 1, + }, + }, + "range": Array [ + 10, + 11, + ], + "type": "Punctuator", + "value": "{", + }, + Object { + "loc": Object { + "end": Object { + "column": 10, + "line": 2, + }, + "start": Object { + "column": 2, + "line": 2, + }, + }, + "range": Array [ + 14, + 22, + ], + "type": "Identifier", + "value": "readonly", + }, + Object { + "loc": Object { + "end": Object { + "column": 16, + "line": 2, + }, + "start": Object { + "column": 11, + "line": 2, + }, + }, + "range": Array [ + 23, + 28, + ], + "type": "Identifier", + "value": "#priv", + }, + Object { + "loc": Object { + "end": Object { + "column": 17, + "line": 2, + }, + "start": Object { + "column": 16, + "line": 2, + }, + }, + "range": Array [ + 28, + 29, + ], + "type": "Punctuator", + "value": ":", + }, + Object { + "loc": Object { + "end": Object { + "column": 24, + "line": 2, + }, + "start": Object { + "column": 18, + "line": 2, + }, + }, + "range": Array [ + 30, + 36, + ], + "type": "Identifier", + "value": "string", + }, + Object { + "loc": Object { + "end": Object { + "column": 1, + "line": 3, + }, + "start": Object { + "column": 0, + "line": 3, + }, + }, + "range": Array [ + 37, + 38, + ], + "type": "Punctuator", + "value": "}", + }, + ], + "type": "Program", +} +`; diff --git a/packages/visitor-keys/package.json b/packages/visitor-keys/package.json index aed915b8613..5ea3a984b53 100644 --- a/packages/visitor-keys/package.json +++ b/packages/visitor-keys/package.json @@ -39,7 +39,7 @@ }, "dependencies": { "@typescript-eslint/types": "4.33.0", - "eslint-visitor-keys": "^2.0.0" + "eslint-visitor-keys": "^3.0.0" }, "devDependencies": { "@types/eslint-visitor-keys": "*"