From 24b09d8502ac8fea8981813bff4ff47b0fd16b7a Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 3 Apr 2017 15:00:40 -0700 Subject: [PATCH] Only bind JSDoc typedefs in JavaScript files --- src/compiler/binder.ts | 4 +++- .../baselines/reference/jsdocInTypeScript.js | 19 +++++++++++++++++++ .../reference/jsdocInTypeScript.symbols | 19 +++++++++++++++++++ .../reference/jsdocInTypeScript.types | 19 +++++++++++++++++++ tests/cases/compiler/jsdocInTypeScript.ts | 9 +++++++++ 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/jsdocInTypeScript.js create mode 100644 tests/baselines/reference/jsdocInTypeScript.symbols create mode 100644 tests/baselines/reference/jsdocInTypeScript.types create mode 100644 tests/cases/compiler/jsdocInTypeScript.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 45e8efdf51..8aafdfce4a 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1910,7 +1910,9 @@ namespace ts { // Here the current node is "foo", which is a container, but the scope of "MyType" should // not be inside "foo". Therefore we always bind @typedef before bind the parent node, // and skip binding this tag later when binding all the other jsdoc tags. - bindJSDocTypedefTagIfAny(node); + if (isInJavaScriptFile(node)) { + bindJSDocTypedefTagIfAny(node); + } // First we bind declaration nodes to a symbol if possible. We'll both create a symbol // and then potentially add the symbol to an appropriate symbol table. Possible diff --git a/tests/baselines/reference/jsdocInTypeScript.js b/tests/baselines/reference/jsdocInTypeScript.js new file mode 100644 index 0000000000..af4b8b6ce0 --- /dev/null +++ b/tests/baselines/reference/jsdocInTypeScript.js @@ -0,0 +1,19 @@ +//// [jsdocInTypeScript.ts] +// JSDoc typedef tags are not bound TypeScript files. +/** @typedef {function} T */ +declare const x: T; + +class T { + prop: number; +} + +x.prop; + + +//// [jsdocInTypeScript.js] +var T = (function () { + function T() { + } + return T; +}()); +x.prop; diff --git a/tests/baselines/reference/jsdocInTypeScript.symbols b/tests/baselines/reference/jsdocInTypeScript.symbols new file mode 100644 index 0000000000..62b6ad3c53 --- /dev/null +++ b/tests/baselines/reference/jsdocInTypeScript.symbols @@ -0,0 +1,19 @@ +=== tests/cases/compiler/jsdocInTypeScript.ts === +// JSDoc typedef tags are not bound TypeScript files. +/** @typedef {function} T */ +declare const x: T; +>x : Symbol(x, Decl(jsdocInTypeScript.ts, 2, 13)) +>T : Symbol(T, Decl(jsdocInTypeScript.ts, 2, 19)) + +class T { +>T : Symbol(T, Decl(jsdocInTypeScript.ts, 2, 19)) + + prop: number; +>prop : Symbol(T.prop, Decl(jsdocInTypeScript.ts, 4, 9)) +} + +x.prop; +>x.prop : Symbol(T.prop, Decl(jsdocInTypeScript.ts, 4, 9)) +>x : Symbol(x, Decl(jsdocInTypeScript.ts, 2, 13)) +>prop : Symbol(T.prop, Decl(jsdocInTypeScript.ts, 4, 9)) + diff --git a/tests/baselines/reference/jsdocInTypeScript.types b/tests/baselines/reference/jsdocInTypeScript.types new file mode 100644 index 0000000000..03ff2929e0 --- /dev/null +++ b/tests/baselines/reference/jsdocInTypeScript.types @@ -0,0 +1,19 @@ +=== tests/cases/compiler/jsdocInTypeScript.ts === +// JSDoc typedef tags are not bound TypeScript files. +/** @typedef {function} T */ +declare const x: T; +>x : T +>T : T + +class T { +>T : T + + prop: number; +>prop : number +} + +x.prop; +>x.prop : number +>x : T +>prop : number + diff --git a/tests/cases/compiler/jsdocInTypeScript.ts b/tests/cases/compiler/jsdocInTypeScript.ts new file mode 100644 index 0000000000..ba9e8dbcbf --- /dev/null +++ b/tests/cases/compiler/jsdocInTypeScript.ts @@ -0,0 +1,9 @@ +// JSDoc typedef tags are not bound TypeScript files. +/** @typedef {function} T */ +declare const x: T; + +class T { + prop: number; +} + +x.prop;