Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45580,6 +45580,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
// If node.kind === SyntaxKind.Parameter, checkParameter reports an error if it's not a parameter property.
return grammarErrorOnNode(modifier, Diagnostics.readonly_modifier_can_only_appear_on_a_property_declaration_or_index_signature);
}
else if (flags & ModifierFlags.Accessor) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "readonly", "accessor");
}
flags |= ModifierFlags.Readonly;
break;

Expand Down Expand Up @@ -45637,6 +45640,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
else if (isPrivateIdentifierClassElementDeclaration(node)) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_a_private_identifier, "declare");
}
else if (flags & ModifierFlags.Accessor) {
return grammarErrorOnNode(modifier, Diagnostics._0_modifier_cannot_be_used_with_1_modifier, "declare", "accessor");
}
flags |= ModifierFlags.Ambient;
lastDeclare = modifier;
break;
Expand Down
12 changes: 12 additions & 0 deletions src/services/goToDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ export function getDefinitionAtPosition(program: Program, sourceFile: SourceFile
return functionDeclaration ? [createDefinitionFromSignatureDeclaration(typeChecker, functionDeclaration)] : undefined;
}

if (node.kind === SyntaxKind.AwaitKeyword) {
const functionDeclaration = findAncestor(node, n => isFunctionLikeDeclaration(n)) as FunctionLikeDeclaration | undefined;
const isAsyncFunction = functionDeclaration && some(functionDeclaration.modifiers, (node) => node.kind === SyntaxKind.AsyncKeyword);
return isAsyncFunction ? [createDefinitionFromSignatureDeclaration(typeChecker, functionDeclaration)] : undefined;
}

if (node.kind === SyntaxKind.YieldKeyword) {
const functionDeclaration = findAncestor(node, n => isFunctionLikeDeclaration(n)) as FunctionLikeDeclaration | undefined;
const isGeneratorFunction = functionDeclaration && functionDeclaration.asteriskToken;
return isGeneratorFunction ? [createDefinitionFromSignatureDeclaration(typeChecker, functionDeclaration)] : undefined;
}

if (isStaticModifier(node) && isClassStaticBlockDeclaration(node.parent)) {
const classDecl = node.parent.parent;
const { symbol, failedAliasResolution } = getSymbol(classDecl, typeChecker, stopAtAlias);
Expand Down
3 changes: 2 additions & 1 deletion src/services/importTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
isImportEqualsDeclaration,
isImportTypeNode,
isInJSFile,
isJSDocCallbackTag,
isJSDocTypedefTag,
isModuleExportsAccessExpression,
isNamedExports,
Expand Down Expand Up @@ -612,7 +613,7 @@ export function getImportOrExportSymbol(node: Node, symbol: Symbol, checker: Typ
else if (isBinaryExpression(grandparent)) {
return getSpecialPropertyExport(grandparent, /*useLhsSymbol*/ true);
}
else if (isJSDocTypedefTag(parent)) {
else if (isJSDocTypedefTag(parent) || isJSDocCallbackTag(parent)) {
return exportInfo(symbol, ExportKind.Named);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/stringCompletions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ function getStringLiteralCompletionEntries(sourceFile: SourceFile, node: StringL
function fromContextualType(): StringLiteralCompletion {
// Get completion for string literal from string literal type
// i.e. var x: "hi" | "hello" = "/*completion position*/"
return { kind: StringLiteralCompletionKind.Types, types: getStringLiteralTypes(getContextualTypeFromParent(node, typeChecker)), isNewIdentifier: false };
return { kind: StringLiteralCompletionKind.Types, types: getStringLiteralTypes(getContextualTypeFromParent(node, typeChecker, ContextFlags.Completions)), isNewIdentifier: false };
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
CompilerOptions,
ConditionalExpression,
contains,
ContextFlags,
createPrinter,
createRange,
createScanner,
Expand Down Expand Up @@ -3270,21 +3271,21 @@ export function needsParentheses(expression: Expression): boolean {
}

/** @internal */
export function getContextualTypeFromParent(node: Expression, checker: TypeChecker): Type | undefined {
export function getContextualTypeFromParent(node: Expression, checker: TypeChecker, contextFlags?: ContextFlags): Type | undefined {
const { parent } = node;
switch (parent.kind) {
case SyntaxKind.NewExpression:
return checker.getContextualType(parent as NewExpression);
return checker.getContextualType(parent as NewExpression, contextFlags);
case SyntaxKind.BinaryExpression: {
const { left, operatorToken, right } = parent as BinaryExpression;
return isEqualityOperatorKind(operatorToken.kind)
? checker.getTypeAtLocation(node === right ? left : right)
: checker.getContextualType(node);
: checker.getContextualType(node, contextFlags);
}
case SyntaxKind.CaseClause:
return (parent as CaseClause).expression === node ? getSwitchedType(parent as CaseClause, checker) : undefined;
default:
return checker.getContextualType(node);
return checker.getContextualType(node, contextFlags);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,26 @@ tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowe
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(12,5): error TS1275: 'accessor' modifier can only appear on a property declaration.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(13,5): error TS1275: 'accessor' modifier can only appear on a property declaration.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(14,15): error TS1276: An 'accessor' property cannot be declared optional.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(18,14): error TS1029: 'override' modifier must precede 'accessor' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(22,5): error TS1070: 'accessor' modifier cannot appear on a type member.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(25,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(26,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(15,14): error TS1243: 'readonly' modifier cannot be used with 'accessor' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(16,14): error TS1243: 'declare' modifier cannot be used with 'accessor' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(20,14): error TS1029: 'override' modifier must precede 'accessor' modifier.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(24,5): error TS1070: 'accessor' modifier cannot appear on a type member.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(27,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(28,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(29,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(30,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(31,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(32,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(33,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(33,25): error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(34,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(35,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(35,25): error TS2792: Cannot find module 'x'. Did you mean to set the 'moduleResolution' option to 'nodenext', or to add aliases to the 'paths' option?
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(36,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(37,1): error TS1275: 'accessor' modifier can only appear on a property declaration.
tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts(38,1): error TS1275: 'accessor' modifier can only appear on a property declaration.


==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts (28 errors) ====
==== tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowedModifiers.ts (30 errors) ====
abstract class C1 {
accessor accessor a: any;
~~~~~~~~
Expand Down Expand Up @@ -69,6 +71,12 @@ tests/cases/conformance/classes/propertyMemberDeclarations/autoAccessorDisallowe
accessor l?: any;
~
!!! error TS1276: An 'accessor' property cannot be declared optional.
accessor readonly m: any;
~~~~~~~~
!!! error TS1243: 'readonly' modifier cannot be used with 'accessor' modifier.
accessor declare n: any;
~~~~~~~
!!! error TS1243: 'declare' modifier cannot be used with 'accessor' modifier.
}

class C2 extends C1 {
Expand Down
3 changes: 3 additions & 0 deletions tests/baselines/reference/autoAccessorDisallowedModifiers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ abstract class C1 {
accessor set k(v: any) {}
accessor constructor() {}
accessor l?: any;
accessor readonly m: any;
accessor declare n: any;
}

class C2 extends C1 {
Expand Down Expand Up @@ -50,6 +52,7 @@ class C1 {
accessor set k(v) { }
constructor() { }
accessor l;
accessor m;
}
class C2 extends C1 {
accessor g;
Expand Down
120 changes: 120 additions & 0 deletions tests/baselines/reference/findAllRefs_importType_js.4.baseline.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// === /a.js ===
// /**
// * @callback /*FIND ALL REFS*/[|A|]
// * @param {unknown} response
// */
//
// module.exports = {};

// === /b.js ===
// /** @typedef {import("./a").[|A|]} A */

[
{
"definition": {
"containerKind": "",
"containerName": "",
"fileName": "/a.js",
"kind": "type",
"name": "type A = (response: unknown) => any",
"textSpan": {
"start": 17,
"length": 1
},
"displayParts": [
{
"text": "type",
"kind": "keyword"
},
{
"text": " ",
"kind": "space"
},
{
"text": "A",
"kind": "aliasName"
},
{
"text": " ",
"kind": "space"
},
{
"text": "=",
"kind": "operator"
},
{
"text": " ",
"kind": "space"
},
{
"text": "(",
"kind": "punctuation"
},
{
"text": "response",
"kind": "parameterName"
},
{
"text": ":",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "unknown",
"kind": "keyword"
},
{
"text": ")",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "=>",
"kind": "punctuation"
},
{
"text": " ",
"kind": "space"
},
{
"text": "any",
"kind": "keyword"
}
],
"contextSpan": {
"start": 7,
"length": 42
}
},
"references": [
{
"textSpan": {
"start": 17,
"length": 1
},
"fileName": "/a.js",
"contextSpan": {
"start": 7,
"length": 42
},
"isWriteAccess": true,
"isDefinition": true
},
{
"textSpan": {
"start": 28,
"length": 1
},
"fileName": "/b.js",
"isWriteAccess": false,
"isDefinition": false
}
]
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ abstract class C1 {
accessor set k(v: any) {}
accessor constructor() {}
accessor l?: any;
accessor readonly m: any;
accessor declare n: any;
}

class C2 extends C1 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />

// @Filename: /a.tsx
//// declare function bar1<P extends "" | "bar" | "baz">(p: { type: P }): void;
////
//// bar1({ type: "/*ts*/" })
////

verify.completions({ marker: ["ts"], exact: ["", "bar", "baz"] });
18 changes: 18 additions & 0 deletions tests/cases/fourslash/findAllRefs_importType_js.4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// <reference path="fourslash.ts" />

// @module: commonjs
// @allowJs: true
// @checkJs: true

// @Filename: /a.js
/////**
//// * @callback /**/A
//// * @param {unknown} response
//// */
////
////module.exports = {};

// @Filename: /b.js
/////** @typedef {import("./a").A} A */

verify.baselineFindAllReferences("");
12 changes: 12 additions & 0 deletions tests/cases/fourslash/goToDefinitionAwait1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference path="fourslash.ts" />

//// async function /*end1*/foo() {
//// [|/*start1*/await|] Promise.resolve(0);
//// }

//// function notAsync() {
//// [|/*start2*/await|] Promise.resolve(0);
//// }

verify.goToDefinition("start1", "end1");
verify.goToDefinition("start2", []);
5 changes: 5 additions & 0 deletions tests/cases/fourslash/goToDefinitionAwait2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference path="fourslash.ts" />

//// [|/*start*/await|] Promise.resolve(0);

verify.goToDefinition("start", []);
14 changes: 14 additions & 0 deletions tests/cases/fourslash/goToDefinitionAwait3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// <reference path="fourslash.ts" />

//// class C {
//// notAsync() {
//// [|/*start1*/await|] Promise.resolve(0);
//// }
////
//// async /*end2*/foo() {
//// [|/*start2*/await|] Promise.resolve(0);
//// }
//// }

verify.goToDefinition("start1", []);
verify.goToDefinition("start2", "end2");
9 changes: 9 additions & 0 deletions tests/cases/fourslash/goToDefinitionAwait4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts" />

//// async function outerAsyncFun() {
//// let /*end*/af = async () => {
//// [|/*start*/await|] Promise.resolve(0);
//// }
//// }

verify.goToDefinition("start", "end");
12 changes: 12 additions & 0 deletions tests/cases/fourslash/goToDefinitionYield1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// <reference path="fourslash.ts" />

//// function* /*end1*/gen() {
//// [|/*start1*/yield|] 0;
//// }
////
//// const /*end2*/genFunction = function*() {
//// [|/*start2*/yield|] 0;
//// }

verify.goToDefinition("start1", "end1");
verify.goToDefinition("start2", "end2");
10 changes: 10 additions & 0 deletions tests/cases/fourslash/goToDefinitionYield2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/// <reference path="fourslash.ts" />

//// function* outerGen() {
//// function* /*end*/gen() {
//// [|/*start*/yield|] 0;
//// }
//// return gen
//// }

verify.goToDefinition("start", "end");
Loading