From 8aa34707a7c9e5e0431d53b14d11aa2d6f836bda Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 19 Jan 2023 23:24:09 -0800 Subject: [PATCH 1/6] Add test from the other PR Co-authored-by: Oleksandr T --- ...InfoOnJsDocPropertyWithAmbientDeclaration.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/cases/fourslash/quickInfoOnJsDocPropertyWithAmbientDeclaration.ts diff --git a/tests/cases/fourslash/quickInfoOnJsDocPropertyWithAmbientDeclaration.ts b/tests/cases/fourslash/quickInfoOnJsDocPropertyWithAmbientDeclaration.ts new file mode 100644 index 0000000000000..47b0bb81e20f9 --- /dev/null +++ b/tests/cases/fourslash/quickInfoOnJsDocPropertyWithAmbientDeclaration.ts @@ -0,0 +1,17 @@ +/// + +// @noLib: true +// @allowJs: true +// @filename: /test.js +////class Foo { +//// constructor() { +//// this.prop = { }; +//// } +//// +//// declare prop: string; +//// method() { +//// this.prop.foo/**/ +//// } +////} + +verify.baselineQuickInfo(); From 406fc7cecb7549d5063b5f6ba9396d942392065a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 20 Jan 2023 08:25:16 +0000 Subject: [PATCH 2/6] Rename test and add diagnostics request. --- ...> quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.ts} | 1 + 1 file changed, 1 insertion(+) rename tests/cases/fourslash/{quickInfoOnJsDocPropertyWithAmbientDeclaration.ts => quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.ts} (86%) diff --git a/tests/cases/fourslash/quickInfoOnJsDocPropertyWithAmbientDeclaration.ts b/tests/cases/fourslash/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.ts similarity index 86% rename from tests/cases/fourslash/quickInfoOnJsDocPropertyWithAmbientDeclaration.ts rename to tests/cases/fourslash/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.ts index 47b0bb81e20f9..bfbe786e0545a 100644 --- a/tests/cases/fourslash/quickInfoOnJsDocPropertyWithAmbientDeclaration.ts +++ b/tests/cases/fourslash/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.ts @@ -15,3 +15,4 @@ ////} verify.baselineQuickInfo(); +verify.baselineSyntacticAndSemanticDiagnostics(); \ No newline at end of file From 54734695560f5099fd3970b504aaa2687873ef3b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 20 Jan 2023 08:26:01 +0000 Subject: [PATCH 3/6] Defer to ambients if the assignment kind is some sort of funky JavaScript construct. --- src/compiler/utilities.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 033a0f7b41938..6ea545d6dd14f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3524,8 +3524,7 @@ export function isSpecialPropertyDeclaration(expr: PropertyAccessExpression | El export function setValueDeclaration(symbol: Symbol, node: Declaration): void { const { valueDeclaration } = symbol; if (!valueDeclaration || - !(node.flags & NodeFlags.Ambient && !(valueDeclaration.flags & NodeFlags.Ambient)) && - (isAssignmentDeclaration(valueDeclaration) && !isAssignmentDeclaration(node)) || + ((node.flags & NodeFlags.Ambient) ? (!isAssignmentDeclaration(node) && isAssignmentDeclaration(valueDeclaration)) : (valueDeclaration.flags & NodeFlags.Ambient)) || (valueDeclaration.kind !== node.kind && isEffectiveModuleDeclaration(valueDeclaration))) { // other kinds of value declarations take precedence over modules and assignment declarations symbol.valueDeclaration = node; From 5db8202e33c2deac479ecc4ac3e303661008c6ae Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 20 Jan 2023 08:26:24 +0000 Subject: [PATCH 4/6] Accepted baselines. --- ...nJsPropertyWithAmbientDeclaration.baseline | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/baselines/reference/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.baseline diff --git a/tests/baselines/reference/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.baseline b/tests/baselines/reference/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.baseline new file mode 100644 index 0000000000000..cd99ac79809a8 --- /dev/null +++ b/tests/baselines/reference/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.baseline @@ -0,0 +1,39 @@ +=== /test.js === +// class Foo { +// constructor() { +// this.prop = { }; +// } +// +// declare prop: string; +// method() { +// this.prop.foo +// ^^^ +// | ---------------------------------------------------------------------- +// | any +// | ---------------------------------------------------------------------- +// } +// } + +[ + { + "marker": { + "fileName": "/test.js", + "position": 126, + "name": "" + }, + "item": { + "kind": "", + "kindModifiers": "", + "textSpan": { + "start": 123, + "length": 3 + }, + "displayParts": [ + { + "text": "any", + "kind": "keyword" + } + ] + } + } +] \ No newline at end of file From 46d5ceee2d84a1aa2ae9ae695224ac629833a320 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 20 Jan 2023 09:12:01 +0000 Subject: [PATCH 5/6] Apply a more targeted fix. --- src/compiler/utilities.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 6ea545d6dd14f..4d60b039dea24 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -3524,7 +3524,8 @@ export function isSpecialPropertyDeclaration(expr: PropertyAccessExpression | El export function setValueDeclaration(symbol: Symbol, node: Declaration): void { const { valueDeclaration } = symbol; if (!valueDeclaration || - ((node.flags & NodeFlags.Ambient) ? (!isAssignmentDeclaration(node) && isAssignmentDeclaration(valueDeclaration)) : (valueDeclaration.flags & NodeFlags.Ambient)) || + !(node.flags & NodeFlags.Ambient && !(valueDeclaration.flags & NodeFlags.Ambient)) && (isAssignmentDeclaration(valueDeclaration) && !isAssignmentDeclaration(node)) || + node.kind === SyntaxKind.PropertyDeclaration && isAssignmentDeclaration(valueDeclaration) || (valueDeclaration.kind !== node.kind && isEffectiveModuleDeclaration(valueDeclaration))) { // other kinds of value declarations take precedence over modules and assignment declarations symbol.valueDeclaration = node; From f78bdcf22a7a8c237e452879b08011c09b3b80d2 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Fri, 20 Jan 2023 09:12:16 +0000 Subject: [PATCH 6/6] Accept more-correct baselines. --- ...nJsPropertyWithAmbientDeclaration.baseline | 74 +++++++++---------- 1 file changed, 35 insertions(+), 39 deletions(-) diff --git a/tests/baselines/reference/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.baseline b/tests/baselines/reference/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.baseline index cd99ac79809a8..c4da169cb7b3f 100644 --- a/tests/baselines/reference/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.baseline +++ b/tests/baselines/reference/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.baseline @@ -1,39 +1,35 @@ -=== /test.js === -// class Foo { -// constructor() { -// this.prop = { }; -// } -// -// declare prop: string; -// method() { -// this.prop.foo -// ^^^ -// | ---------------------------------------------------------------------- -// | any -// | ---------------------------------------------------------------------- -// } -// } - -[ - { - "marker": { - "fileName": "/test.js", - "position": 126, - "name": "" - }, - "item": { - "kind": "", - "kindModifiers": "", - "textSpan": { - "start": 123, - "length": 3 - }, - "displayParts": [ - { - "text": "any", - "kind": "keyword" - } - ] - } - } -] \ No newline at end of file +Syntactic Diagnostics for file '/tests/cases/fourslash/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.ts': +/test.js(6,5): error TS8009: The 'declare' modifier can only be used in TypeScript files. +/test.js(6,19): error TS8010: Type annotations can only be used in TypeScript files. + + +==== /test.js (2 errors) ==== + class Foo { + constructor() { + this.prop = { }; + } + + declare prop: string; + ~~~~~~~ +!!! error TS8009: The 'declare' modifier can only be used in TypeScript files. + ~~~~~~ +!!! error TS8010: Type annotations can only be used in TypeScript files. + method() { + this.prop.foo + } + } + +Semantic Diagnostics for file '/tests/cases/fourslash/quickInfoAndSemanticsOnJsPropertyWithAmbientDeclaration.ts': + + +==== /test.js (0 errors) ==== + class Foo { + constructor() { + this.prop = { }; + } + + declare prop: string; + method() { + this.prop.foo + } + } \ No newline at end of file