From 9a9624bceb61170c812c675f8ebb07c50613a470 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 29 Jun 2022 15:31:16 -0700 Subject: [PATCH] Additional tests and language service fixes --- package-lock.json | 30 +- src/compiler/checker.ts | 9 +- src/compiler/diagnosticMessages.json | 4 + src/compiler/factory/nodeFactory.ts | 2 +- src/services/codefixes/helpers.ts | 21 +- src/services/symbolDisplay.ts | 6 +- src/services/types.ts | 3 + .../accessorFieldAllowedModifiers.js | 2 + ...ccessorFieldDisallowedModifiers.errors.txt | 14 +- .../accessorFieldDisallowedModifiers.js | 2 + .../reference/api/tsserverlibrary.d.ts | 2 + tests/baselines/reference/api/typescript.d.ts | 2 + ...nfoDisplayPartsClassAutoAccessors.baseline | 1422 +++++++++++++++++ .../accessorFieldAllowedModifiers.ts | 1 + .../accessorFieldDisallowedModifiers.ts | 1 + ...ImplementClassAbstractGettersAndSetters.ts | 5 + ...quickInfoDisplayPartsClassAutoAccessors.ts | 33 + 17 files changed, 1522 insertions(+), 37 deletions(-) create mode 100644 tests/baselines/reference/quickInfoDisplayPartsClassAutoAccessors.baseline create mode 100644 tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts diff --git a/package-lock.json b/package-lock.json index d192eba7643cf..e3c8d73aebd04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -219,18 +219,18 @@ } }, "@octokit/openapi-types": { - "version": "12.4.0", - "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.4.0.tgz", - "integrity": "sha512-Npcb7Pv30b33U04jvcD7l75yLU0mxhuX2Xqrn51YyZ5WTkF04bpbxLaZ6GcaTqu03WZQHoO/Gbfp95NGRueDUA==", + "version": "12.5.0", + "resolved": "https://registry.npmjs.org/@octokit/openapi-types/-/openapi-types-12.5.0.tgz", + "integrity": "sha512-VatvE5wtRkJq6hAWGTBZ62WkrdlCiy0G0u27cVOYTfAWVZi7QqTurVcjpsyc5+9hXLPRP5O/DaNEs4TgAp4Mqg==", "dev": true }, "@octokit/plugin-paginate-rest": { - "version": "2.19.0", - "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.19.0.tgz", - "integrity": "sha512-hQ4Qysg2hNmEMuZeJkvyzM4eSZiTifOKqYAMsW8FnxFKowhuwWICSgBQ9Gn9GpUmgKB7qaf1hFvMjYaTAg5jQA==", + "version": "2.20.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-paginate-rest/-/plugin-paginate-rest-2.20.0.tgz", + "integrity": "sha512-LbemX86JEmOCFo9eRwrtdP5Isq69TefLS1J7w0DO4PMhfpvRfqYVzq9c0eH1xgcx2PSA7/VJHu9SwvNhD9FjVg==", "dev": true, "requires": { - "@octokit/types": "^6.36.0" + "@octokit/types": "^6.38.1" } }, "@octokit/plugin-request-log": { @@ -240,12 +240,12 @@ "dev": true }, "@octokit/plugin-rest-endpoint-methods": { - "version": "5.15.0", - "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.15.0.tgz", - "integrity": "sha512-Gsw9+Xm56jVhfbJoy4pt6eOOyf8/3K6CAnx1Sl7U2GhZWcg8MR6YgXWnpfdF69S2ViMXLA7nfvTDAsZpFlkLRw==", + "version": "5.16.0", + "resolved": "https://registry.npmjs.org/@octokit/plugin-rest-endpoint-methods/-/plugin-rest-endpoint-methods-5.16.0.tgz", + "integrity": "sha512-mvdwq+LvhR2GRDY82FgSZ52xX6wkOCpjiI3amiKbzKHd9nyKeFdXLsIQ3Go12tWRtvo+HwqoypLHDjRrgMFDQA==", "dev": true, "requires": { - "@octokit/types": "^6.36.0", + "@octokit/types": "^6.38.0", "deprecation": "^2.3.1" } }, @@ -287,12 +287,12 @@ } }, "@octokit/types": { - "version": "6.37.1", - "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.37.1.tgz", - "integrity": "sha512-Q1hXSP2YumHkDdD+V4wFKr7vJ9+8tjocixrTSb75JzJ4GpjSyu5B4kpgrXxO6GOs4nOmVyRwRgS4/RO/Lf9oEA==", + "version": "6.38.1", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-6.38.1.tgz", + "integrity": "sha512-kWMohLCIvnwApRmxRFDOqve7puiNNdtVfgwdDOm6QyJNorWOgKv2/AodCcGqx63o28kF7Dr4/nJCatrwwqhULg==", "dev": true, "requires": { - "@octokit/openapi-types": "^12.4.0" + "@octokit/openapi-types": "^12.5.0" } }, "@types/chai": { diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c40bba772e088..6e49074335da9 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8922,7 +8922,7 @@ namespace ts { return getTypeForBindingElement(declaration as BindingElement); } - const isProperty = isPropertyDeclaration(declaration) || isPropertySignature(declaration); + const isProperty = isPropertyDeclaration(declaration) && !hasAccessorModifier(declaration) || isPropertySignature(declaration); const isOptional = includeOptionality && ( isProperty && !!declaration.questionToken || isParameter(declaration) && (!!declaration.questionToken || isJSDocOptionalParameter(declaration)) || @@ -12774,7 +12774,7 @@ namespace ts { } function isOptionalPropertyDeclaration(node: Declaration) { - return isPropertyDeclaration(node) && node.questionToken; + return isPropertyDeclaration(node) && !hasAccessorModifier(node) && node.questionToken; } function isOptionalJSDocPropertyLikeTag(node: Node): node is JSDocPropertyLikeTag { @@ -45152,9 +45152,12 @@ namespace ts { if (languageVersion < ScriptTarget.ES2015 && isPrivateIdentifier(node.name)) { return grammarErrorOnNode(node.name, Diagnostics.Private_identifiers_are_only_available_when_targeting_ECMAScript_2015_and_higher); } - if (languageVersion < ScriptTarget.ES2015 && hasAccessorModifier(node)) { + if (languageVersion < ScriptTarget.ES2015 && isAutoAccessorPropertyDeclaration(node)) { return grammarErrorOnNode(node.name, Diagnostics.Properties_with_the_accessor_modifier_are_only_available_when_targeting_ECMAScript_2015_and_higher); } + if (isAutoAccessorPropertyDeclaration(node) && checkGrammarForInvalidQuestionMark(node.questionToken, Diagnostics.An_accessor_property_cannot_be_declared_optional)) { + return true; + } } else if (node.parent.kind === SyntaxKind.InterfaceDeclaration) { if (checkGrammarForInvalidDynamicName(node.name, Diagnostics.A_computed_property_name_in_an_interface_must_refer_to_an_expression_whose_type_is_a_literal_type_or_a_unique_symbol_type)) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index de243ea5c9ffd..427df02194306 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -903,6 +903,10 @@ "category": "Error", "code": 1275 }, + "An 'accessor' property cannot be declared optional.": { + "category": "Error", + "code": 1276 + }, "'with' statements are not allowed in an async function block.": { "category": "Error", diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts index 93edb4f760466..480a93a550906 100644 --- a/src/compiler/factory/nodeFactory.ts +++ b/src/compiler/factory/nodeFactory.ts @@ -1100,10 +1100,10 @@ namespace ts { if (flags & ModifierFlags.Private) result.push(createModifier(SyntaxKind.PrivateKeyword)); if (flags & ModifierFlags.Protected) result.push(createModifier(SyntaxKind.ProtectedKeyword)); if (flags & ModifierFlags.Abstract) result.push(createModifier(SyntaxKind.AbstractKeyword)); - if (flags & ModifierFlags.Accessor) result.push(createModifier(SyntaxKind.AccessorKeyword)); if (flags & ModifierFlags.Static) result.push(createModifier(SyntaxKind.StaticKeyword)); if (flags & ModifierFlags.Override) result.push(createModifier(SyntaxKind.OverrideKeyword)); if (flags & ModifierFlags.Readonly) result.push(createModifier(SyntaxKind.ReadonlyKeyword)); + if (flags & ModifierFlags.Accessor) result.push(createModifier(SyntaxKind.AccessorKeyword)); if (flags & ModifierFlags.Async) result.push(createModifier(SyntaxKind.AsyncKeyword)); if (flags & ModifierFlags.In) result.push(createModifier(SyntaxKind.InKeyword)); if (flags & ModifierFlags.Out) result.push(createModifier(SyntaxKind.OutKeyword)); diff --git a/src/services/codefixes/helpers.ts b/src/services/codefixes/helpers.ts index 94b64e57ac934..59433f5f85fac 100644 --- a/src/services/codefixes/helpers.ts +++ b/src/services/codefixes/helpers.ts @@ -67,8 +67,15 @@ namespace ts.codefix { const scriptTarget = getEmitScriptTarget(context.program.getCompilerOptions()); const declaration = declarations[0]; const name = getSynthesizedDeepClone(getNameOfDeclaration(declaration), /*includeTrivia*/ false) as PropertyName; - const visibilityModifier = createVisibilityModifier(getEffectiveModifierFlags(declaration)); - const modifiers = visibilityModifier ? factory.createNodeArray([visibilityModifier]) : undefined; + const effectiveModifierFlags = getEffectiveModifierFlags(declaration); + let modifierFlags = + effectiveModifierFlags & ModifierFlags.Public ? ModifierFlags.Public : + effectiveModifierFlags & ModifierFlags.Protected ? ModifierFlags.Protected : + ModifierFlags.None; + if (isAutoAccessorPropertyDeclaration(declaration)) { + modifierFlags |= ModifierFlags.Accessor; + } + const modifiers = modifierFlags ? factory.createNodeArray(factory.createModifiersFromModifierFlags(modifierFlags)) : undefined; const type = checker.getWidenedType(checker.getTypeOfSymbolAtLocation(symbol, enclosingDeclaration)); const optional = !!(symbol.flags & SymbolFlags.Optional); const ambient = !!(enclosingDeclaration.flags & NodeFlags.Ambient) || isAmbient; @@ -473,16 +480,6 @@ namespace ts.codefix { /*multiline*/ true); } - function createVisibilityModifier(flags: ModifierFlags): Modifier | undefined { - if (flags & ModifierFlags.Public) { - return factory.createToken(SyntaxKind.PublicKeyword); - } - else if (flags & ModifierFlags.Protected) { - return factory.createToken(SyntaxKind.ProtectedKeyword); - } - return undefined; - } - export function setJsonCompilerOptionValues( changeTracker: textChanges.ChangeTracker, configFile: TsConfigSourceFile, diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index 973e28476b6a5..3b7622d347b80 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -158,7 +158,7 @@ namespace ts.SymbolDisplay { if (symbolKind !== ScriptElementKind.unknown || symbolFlags & SymbolFlags.Class || symbolFlags & SymbolFlags.Alias) { // If symbol is accessor, they are allowed only if location is at declaration identifier of the accessor if (symbolKind === ScriptElementKind.memberGetAccessorElement || symbolKind === ScriptElementKind.memberSetAccessorElement) { - const declaration = find(symbol.declarations as ((GetAccessorDeclaration | SetAccessorDeclaration)[]), declaration => declaration.name === location); + const declaration = find(symbol.declarations as ((GetAccessorDeclaration | SetAccessorDeclaration | PropertyDeclaration)[]), declaration => declaration.name === location); if (declaration) { switch(declaration.kind){ case SyntaxKind.GetAccessor: @@ -167,6 +167,9 @@ namespace ts.SymbolDisplay { case SyntaxKind.SetAccessor: symbolKind = ScriptElementKind.memberSetAccessorElement; break; + case SyntaxKind.PropertyDeclaration: + symbolKind = ScriptElementKind.memberAccessorVariableElement; + break; default: Debug.assertNever(declaration); } @@ -509,6 +512,7 @@ namespace ts.SymbolDisplay { // For properties, variables and local vars: show the type if (symbolKind === ScriptElementKind.memberVariableElement || + symbolKind === ScriptElementKind.memberAccessorVariableElement || symbolKind === ScriptElementKind.memberGetAccessorElement || symbolKind === ScriptElementKind.memberSetAccessorElement || symbolKind === ScriptElementKind.jsxAttribute || diff --git a/src/services/types.ts b/src/services/types.ts index 27c7616bf34b2..d8285505bad9c 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -1461,6 +1461,9 @@ namespace ts { */ memberVariableElement = "property", + /** class X { [public|private]* accessor foo: number; } */ + memberAccessorVariableElement = "accessor", + /** * class X { constructor() { } } * class X { static { } } diff --git a/tests/baselines/reference/accessorFieldAllowedModifiers.js b/tests/baselines/reference/accessorFieldAllowedModifiers.js index b1806f06426d2..fb45e88068f84 100644 --- a/tests/baselines/reference/accessorFieldAllowedModifiers.js +++ b/tests/baselines/reference/accessorFieldAllowedModifiers.js @@ -13,6 +13,7 @@ abstract class C1 { accessor "k": any; accessor 108: any; accessor ["m"]: any; + accessor n!: number; } class C2 extends C1 { @@ -40,6 +41,7 @@ class C1 { accessor "k"; accessor 108; accessor ["m"]; + accessor n; } class C2 extends C1 { accessor e; diff --git a/tests/baselines/reference/accessorFieldDisallowedModifiers.errors.txt b/tests/baselines/reference/accessorFieldDisallowedModifiers.errors.txt index 1b7b9db32fab9..0349a5292cab9 100644 --- a/tests/baselines/reference/accessorFieldDisallowedModifiers.errors.txt +++ b/tests/baselines/reference/accessorFieldDisallowedModifiers.errors.txt @@ -10,9 +10,9 @@ tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallow tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(11,5): error TS1275: 'accessor' modifier can only appear on a property declaration. tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(12,5): error TS1275: 'accessor' modifier can only appear on a property declaration. tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(13,5): error TS1275: 'accessor' modifier can only appear on a property declaration. -tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(17,14): error TS1029: 'override' modifier must precede 'accessor' modifier. -tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(21,5): error TS1070: 'accessor' modifier cannot appear on a type member. -tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(24,1): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(14,15): error TS1276: An 'accessor' property cannot be declared optional. +tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(18,14): error TS1029: 'override' modifier must precede 'accessor' modifier. +tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(22,5): error TS1070: 'accessor' modifier cannot appear on a type member. tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(25,1): error TS1275: 'accessor' modifier can only appear on a property declaration. tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(26,1): error TS1275: 'accessor' modifier can only appear on a property declaration. tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(27,1): error TS1275: 'accessor' modifier can only appear on a property declaration. @@ -21,13 +21,14 @@ tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallow tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(30,1): error TS1275: 'accessor' modifier can only appear on a property declaration. tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(31,1): error TS1275: 'accessor' modifier can only appear on a property declaration. tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(32,1): error TS1275: 'accessor' modifier can only appear on a property declaration. -tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(32,25): error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(33,1): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(33,25): error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option? tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(34,1): error TS1275: 'accessor' modifier can only appear on a property declaration. tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(35,1): error TS1275: 'accessor' modifier can only appear on a property declaration. +tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts(36,1): error TS1275: 'accessor' modifier can only appear on a property declaration. -==== tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts (27 errors) ==== +==== tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts (28 errors) ==== abstract class C1 { accessor accessor a: any; ~~~~~~~~ @@ -65,6 +66,9 @@ tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallow accessor constructor() {} ~~~~~~~~ !!! error TS1275: 'accessor' modifier can only appear on a property declaration. + accessor l?: any; + ~ +!!! error TS1276: An 'accessor' property cannot be declared optional. } class C2 extends C1 { diff --git a/tests/baselines/reference/accessorFieldDisallowedModifiers.js b/tests/baselines/reference/accessorFieldDisallowedModifiers.js index 7ba066b51d9b8..efc0082d637ad 100644 --- a/tests/baselines/reference/accessorFieldDisallowedModifiers.js +++ b/tests/baselines/reference/accessorFieldDisallowedModifiers.js @@ -12,6 +12,7 @@ abstract class C1 { accessor get j() { return false; } accessor set k(v: any) {} accessor constructor() {} + accessor l?: any; } class C2 extends C1 { @@ -48,6 +49,7 @@ class C1 { accessor get j() { return false; } accessor set k(v) { } constructor() { } + accessor l; } class C2 extends C1 { accessor g; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index c4bd717c5f38c..378712564ef19 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -6729,6 +6729,8 @@ declare namespace ts { * interface Y { foo:number; } */ memberVariableElement = "property", + /** class X { [public|private]* accessor foo: number; } */ + memberAccessorVariableElement = "accessor", /** * class X { constructor() { } } * class X { static { } } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 5c369b3e6ac0d..f9a93f15a48aa 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -6729,6 +6729,8 @@ declare namespace ts { * interface Y { foo:number; } */ memberVariableElement = "property", + /** class X { [public|private]* accessor foo: number; } */ + memberAccessorVariableElement = "accessor", /** * class X { constructor() { } } * class X { static { } } diff --git a/tests/baselines/reference/quickInfoDisplayPartsClassAutoAccessors.baseline b/tests/baselines/reference/quickInfoDisplayPartsClassAutoAccessors.baseline new file mode 100644 index 0000000000000..c49934974d56d --- /dev/null +++ b/tests/baselines/reference/quickInfoDisplayPartsClassAutoAccessors.baseline @@ -0,0 +1,1422 @@ +[ + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 30, + "name": "1a" + }, + "quickInfo": { + "kind": "accessor", + "kindModifiers": "public", + "textSpan": { + "start": 30, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "accessor", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "publicProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 75, + "name": "2a" + }, + "quickInfo": { + "kind": "accessor", + "kindModifiers": "private", + "textSpan": { + "start": 75, + "length": 15 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "accessor", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "privateProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 123, + "name": "3a" + }, + "quickInfo": { + "kind": "accessor", + "kindModifiers": "protected", + "textSpan": { + "start": 123, + "length": 17 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "accessor", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "protectedProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 170, + "name": "4a" + }, + "quickInfo": { + "kind": "accessor", + "kindModifiers": "static", + "textSpan": { + "start": 170, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "accessor", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "staticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 222, + "name": "5a" + }, + "quickInfo": { + "kind": "accessor", + "kindModifiers": "private,static", + "textSpan": { + "start": 222, + "length": 21 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "accessor", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "privateStaticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 283, + "name": "6a" + }, + "quickInfo": { + "kind": "accessor", + "kindModifiers": "protected,static", + "textSpan": { + "start": 283, + "length": 23 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "accessor", + "kind": "keyword" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "protectedStaticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 371, + "name": "1g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "public", + "textSpan": { + "start": 371, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "publicProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 404, + "name": "2g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "private", + "textSpan": { + "start": 404, + "length": 15 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "privateProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 438, + "name": "3g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "protected", + "textSpan": { + "start": 438, + "length": 17 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "protectedProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 471, + "name": "4g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "static", + "textSpan": { + "start": 471, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "staticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 501, + "name": "5g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "private,static", + "textSpan": { + "start": 501, + "length": 21 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "privateStaticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 538, + "name": "6g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "protected,static", + "textSpan": { + "start": 538, + "length": 23 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "protectedStaticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 576, + "name": "1s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "public", + "textSpan": { + "start": 576, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "publicProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 610, + "name": "2s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "private", + "textSpan": { + "start": 610, + "length": 15 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "privateProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 645, + "name": "3s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "protected", + "textSpan": { + "start": 645, + "length": 17 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "protectedProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 679, + "name": "4s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "static", + "textSpan": { + "start": 679, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "staticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 710, + "name": "5s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "private,static", + "textSpan": { + "start": 710, + "length": 21 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "privateStaticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 748, + "name": "6s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "protected,static", + "textSpan": { + "start": 748, + "length": 23 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "protectedStaticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 830, + "name": "7g" + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 830, + "length": 9 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "cInstance", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 840, + "name": "8g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "public", + "textSpan": { + "start": 840, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "publicProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 860, + "name": "9g" + }, + "quickInfo": { + "kind": "class", + "kindModifiers": "", + "textSpan": { + "start": 860, + "length": 1 + }, + "displayParts": [ + { + "text": "class", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 862, + "name": "10g" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "static", + "textSpan": { + "start": 862, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "staticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 878, + "name": "7s" + }, + "quickInfo": { + "kind": "var", + "kindModifiers": "", + "textSpan": { + "start": 878, + "length": 9 + }, + "displayParts": [ + { + "text": "var", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "cInstance", + "kind": "localName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 888, + "name": "8s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "public", + "textSpan": { + "start": 888, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "publicProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 908, + "name": "9s" + }, + "quickInfo": { + "kind": "class", + "kindModifiers": "", + "textSpan": { + "start": 908, + "length": 1 + }, + "displayParts": [ + { + "text": "class", + "kind": "keyword" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + } + ], + "documentation": [] + } + }, + { + "marker": { + "fileName": "/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts", + "position": 910, + "name": "10s" + }, + "quickInfo": { + "kind": "property", + "kindModifiers": "static", + "textSpan": { + "start": 910, + "length": 14 + }, + "displayParts": [ + { + "text": "(", + "kind": "punctuation" + }, + { + "text": "property", + "kind": "text" + }, + { + "text": ")", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "c", + "kind": "className" + }, + { + "text": ".", + "kind": "punctuation" + }, + { + "text": "staticProperty", + "kind": "propertyName" + }, + { + "text": ":", + "kind": "punctuation" + }, + { + "text": " ", + "kind": "space" + }, + { + "text": "string", + "kind": "keyword" + } + ], + "documentation": [] + } + } +] \ No newline at end of file diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldAllowedModifiers.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldAllowedModifiers.ts index be8aca8bdfd31..0c7bb3d1ad94f 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldAllowedModifiers.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldAllowedModifiers.ts @@ -15,6 +15,7 @@ abstract class C1 { accessor "k": any; accessor 108: any; accessor ["m"]: any; + accessor n!: number; } class C2 extends C1 { diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts index 1d4cdba39ba5f..44e848c1d7ae9 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/accessorFieldDisallowedModifiers.ts @@ -14,6 +14,7 @@ abstract class C1 { accessor get j() { return false; } accessor set k(v: any) {} accessor constructor() {} + accessor l?: any; } class C2 extends C1 { diff --git a/tests/cases/fourslash/codeFixClassImplementClassAbstractGettersAndSetters.ts b/tests/cases/fourslash/codeFixClassImplementClassAbstractGettersAndSetters.ts index dad3c42964d40..e4981c24ceafc 100644 --- a/tests/cases/fourslash/codeFixClassImplementClassAbstractGettersAndSetters.ts +++ b/tests/cases/fourslash/codeFixClassImplementClassAbstractGettersAndSetters.ts @@ -7,6 +7,8 @@ //// abstract get b(): number; //// //// abstract set c(arg: number | string); +//// +//// abstract accessor d: string; ////} //// ////class C implements A {} @@ -21,6 +23,8 @@ verify.codeFix({ abstract get b(): number; abstract set c(arg: number | string); + + abstract accessor d: string; } class C implements A { @@ -36,5 +40,6 @@ class C implements A { set c(arg: string | number) { throw new Error("Method not implemented."); } + accessor d: string; }`, }); diff --git a/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts b/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts new file mode 100644 index 0000000000000..619169e8b3a17 --- /dev/null +++ b/tests/cases/fourslash/quickInfoDisplayPartsClassAutoAccessors.ts @@ -0,0 +1,33 @@ +/// + +////class c { +//// public accessor /*1a*/publicProperty: string; +//// private accessor /*2a*/privateProperty: string; +//// protected accessor /*3a*/protectedProperty: string; +//// static accessor /*4a*/staticProperty: string; +//// private static accessor /*5a*/privateStaticProperty: string; +//// protected static accessor /*6a*/protectedStaticProperty: string; +//// method() { +//// var x: string; +//// x = this./*1g*/publicProperty; +//// x = this./*2g*/privateProperty; +//// x = this./*3g*/protectedProperty; +//// x = c./*4g*/staticProperty; +//// x = c./*5g*/privateStaticProperty; +//// x = c./*6g*/protectedStaticProperty; +//// this./*1s*/publicProperty = ""; +//// this./*2s*/privateProperty = ""; +//// this./*3s*/protectedProperty = ""; +//// c./*4s*/staticProperty = ""; +//// c./*5s*/privateStaticProperty = ""; +//// c./*6s*/protectedStaticProperty = ""; +//// } +////} +////var cInstance = new c(); +////var y: string; +////y = /*7g*/cInstance./*8g*/publicProperty; +////y = /*9g*/c./*10g*/staticProperty; +/////*7s*/cInstance./*8s*/publicProperty = y; +/////*9s*/c./*10s*/staticProperty = y; + +verify.baselineQuickInfo(); \ No newline at end of file