Don't bind JSDoc namespace in a TS file (#16416)

This commit is contained in:
Andy 2017-06-12 14:35:35 -07:00 committed by Mohamed Hegazy
parent 050126c1b6
commit fbcddb61e2
5 changed files with 20 additions and 4 deletions

View File

@ -2138,8 +2138,10 @@ namespace ts {
case SyntaxKind.EnumDeclaration:
return bindEnumDeclaration(<EnumDeclaration>node);
case SyntaxKind.ModuleDeclaration:
return bindModuleDeclaration(<ModuleDeclaration>node);
if (node.parent.kind !== ts.SyntaxKind.JSDocTypedefTag || isInJavaScriptFile(node)) {
return bindModuleDeclaration(<ModuleDeclaration>node);
}
return undefined;
// Jsx-attributes
case SyntaxKind.JsxAttributes:
return bindJsxAttributes(<JsxAttributes>node);

View File

@ -6851,7 +6851,7 @@ namespace ts {
jsDocNamespaceNode.flags |= flags;
jsDocNamespaceNode.name = typeNameOrNamespaceName;
jsDocNamespaceNode.body = parseJSDocTypeNameWithNamespace(NodeFlags.NestedNamespace);
return jsDocNamespaceNode;
return finishNode(jsDocNamespaceNode);
}
if (typeNameOrNamespaceName && flags & NodeFlags.NestedNamespace) {

View File

@ -3,9 +3,10 @@ tests/cases/compiler/jsdocInTypeScript.ts(23,33): error TS2362: The left-hand si
tests/cases/compiler/jsdocInTypeScript.ts(25,3): error TS2345: Argument of type '1' is not assignable to parameter of type 'boolean'.
tests/cases/compiler/jsdocInTypeScript.ts(25,15): error TS2339: Property 'length' does not exist on type 'number'.
tests/cases/compiler/jsdocInTypeScript.ts(30,3): error TS2339: Property 'x' does not exist on type '{}'.
tests/cases/compiler/jsdocInTypeScript.ts(42,12): error TS2503: Cannot find namespace 'N'.
==== tests/cases/compiler/jsdocInTypeScript.ts (5 errors) ====
==== tests/cases/compiler/jsdocInTypeScript.ts (6 errors) ====
// JSDoc typedef tags are not bound TypeScript files.
/** @typedef {function} T */
declare const x: T;
@ -55,4 +56,9 @@ tests/cases/compiler/jsdocInTypeScript.ts(30,3): error TS2339: Property 'x' does
function tem<T extends number>(t: T): I<T> { return {}; }
let i: I; // Should succeed thanks to type parameter default
/** @typedef {string} N.Str */
import M = N; // Error: @typedef does not create namespaces in TypeScript code.
~
!!! error TS2503: Cannot find namespace 'N'.

View File

@ -38,6 +38,9 @@ interface I<T extends number = 0> {}
function tem<T extends number>(t: T): I<T> { return {}; }
let i: I; // Should succeed thanks to type parameter default
/** @typedef {string} N.Str */
import M = N; // Error: @typedef does not create namespaces in TypeScript code.
//// [jsdocInTypeScript.js]
@ -63,3 +66,5 @@ z.x = 1; // Error
/** @template T */
function tem(t) { return {}; }
var i; // Should succeed thanks to type parameter default
/** @typedef {string} N.Str */
var M = N; // Error: @typedef does not create namespaces in TypeScript code.

View File

@ -37,3 +37,6 @@ interface I<T extends number = 0> {}
function tem<T extends number>(t: T): I<T> { return {}; }
let i: I; // Should succeed thanks to type parameter default
/** @typedef {string} N.Str */
import M = N; // Error: @typedef does not create namespaces in TypeScript code.