Skip to content

Commit fbcddb6

Browse files
Andymhegazy
authored andcommitted
Don't bind JSDoc namespace in a TS file (#16416)
1 parent 050126c commit fbcddb6

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

src/compiler/binder.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2138,8 +2138,10 @@ namespace ts {
21382138
case SyntaxKind.EnumDeclaration:
21392139
return bindEnumDeclaration(<EnumDeclaration>node);
21402140
case SyntaxKind.ModuleDeclaration:
2141-
return bindModuleDeclaration(<ModuleDeclaration>node);
2142-
2141+
if (node.parent.kind !== ts.SyntaxKind.JSDocTypedefTag || isInJavaScriptFile(node)) {
2142+
return bindModuleDeclaration(<ModuleDeclaration>node);
2143+
}
2144+
return undefined;
21432145
// Jsx-attributes
21442146
case SyntaxKind.JsxAttributes:
21452147
return bindJsxAttributes(<JsxAttributes>node);

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6851,7 +6851,7 @@ namespace ts {
68516851
jsDocNamespaceNode.flags |= flags;
68526852
jsDocNamespaceNode.name = typeNameOrNamespaceName;
68536853
jsDocNamespaceNode.body = parseJSDocTypeNameWithNamespace(NodeFlags.NestedNamespace);
6854-
return jsDocNamespaceNode;
6854+
return finishNode(jsDocNamespaceNode);
68556855
}
68566856

68576857
if (typeNameOrNamespaceName && flags & NodeFlags.NestedNamespace) {

tests/baselines/reference/jsdocInTypeScript.errors.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ tests/cases/compiler/jsdocInTypeScript.ts(23,33): error TS2362: The left-hand si
33
tests/cases/compiler/jsdocInTypeScript.ts(25,3): error TS2345: Argument of type '1' is not assignable to parameter of type 'boolean'.
44
tests/cases/compiler/jsdocInTypeScript.ts(25,15): error TS2339: Property 'length' does not exist on type 'number'.
55
tests/cases/compiler/jsdocInTypeScript.ts(30,3): error TS2339: Property 'x' does not exist on type '{}'.
6+
tests/cases/compiler/jsdocInTypeScript.ts(42,12): error TS2503: Cannot find namespace 'N'.
67

78

8-
==== tests/cases/compiler/jsdocInTypeScript.ts (5 errors) ====
9+
==== tests/cases/compiler/jsdocInTypeScript.ts (6 errors) ====
910
// JSDoc typedef tags are not bound TypeScript files.
1011
/** @typedef {function} T */
1112
declare const x: T;
@@ -55,4 +56,9 @@ tests/cases/compiler/jsdocInTypeScript.ts(30,3): error TS2339: Property 'x' does
5556
function tem<T extends number>(t: T): I<T> { return {}; }
5657

5758
let i: I; // Should succeed thanks to type parameter default
59+
60+
/** @typedef {string} N.Str */
61+
import M = N; // Error: @typedef does not create namespaces in TypeScript code.
62+
~
63+
!!! error TS2503: Cannot find namespace 'N'.
5864

tests/baselines/reference/jsdocInTypeScript.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ interface I<T extends number = 0> {}
3838
function tem<T extends number>(t: T): I<T> { return {}; }
3939

4040
let i: I; // Should succeed thanks to type parameter default
41+
42+
/** @typedef {string} N.Str */
43+
import M = N; // Error: @typedef does not create namespaces in TypeScript code.
4144

4245

4346
//// [jsdocInTypeScript.js]
@@ -63,3 +66,5 @@ z.x = 1; // Error
6366
/** @template T */
6467
function tem(t) { return {}; }
6568
var i; // Should succeed thanks to type parameter default
69+
/** @typedef {string} N.Str */
70+
var M = N; // Error: @typedef does not create namespaces in TypeScript code.

tests/cases/compiler/jsdocInTypeScript.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ interface I<T extends number = 0> {}
3737
function tem<T extends number>(t: T): I<T> { return {}; }
3838

3939
let i: I; // Should succeed thanks to type parameter default
40+
41+
/** @typedef {string} N.Str */
42+
import M = N; // Error: @typedef does not create namespaces in TypeScript code.

0 commit comments

Comments
 (0)