Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2017
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: 4 additions & 2 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion tests/baselines/reference/jsdocInTypeScript.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'.

5 changes: 5 additions & 0 deletions tests/baselines/reference/jsdocInTypeScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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.
3 changes: 3 additions & 0 deletions tests/cases/compiler/jsdocInTypeScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.