From ebfcc1b52db6eacd814e20efd33c2984b3b43538 Mon Sep 17 00:00:00 2001 From: Andy Date: Thu, 13 Sep 2018 15:24:49 -0700 Subject: [PATCH] Fix bug: Ignore @enum tag in TS (#27076) --- src/compiler/binder.ts | 2 +- tests/baselines/reference/jsdocInTypeScript.errors.txt | 4 ++++ tests/baselines/reference/jsdocInTypeScript.js | 7 +++++++ tests/baselines/reference/jsdocInTypeScript.symbols | 7 +++++++ tests/baselines/reference/jsdocInTypeScript.types | 10 ++++++++++ tests/cases/compiler/jsdocInTypeScript.ts | 4 ++++ 6 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 3205b2c5a55..81d4857ad07 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2666,7 +2666,7 @@ namespace ts { } if (!isBindingPattern(node.name)) { - const isEnum = !!getJSDocEnumTag(node); + const isEnum = isInJSFile(node) && !!getJSDocEnumTag(node); const enumFlags = (isEnum ? SymbolFlags.RegularEnum : SymbolFlags.None); const enumExcludes = (isEnum ? SymbolFlags.RegularEnumExcludes : SymbolFlags.None); if (isBlockOrCatchScoped(node)) { diff --git a/tests/baselines/reference/jsdocInTypeScript.errors.txt b/tests/baselines/reference/jsdocInTypeScript.errors.txt index 7903ef8057f..c8972bb0f0a 100644 --- a/tests/baselines/reference/jsdocInTypeScript.errors.txt +++ b/tests/baselines/reference/jsdocInTypeScript.errors.txt @@ -67,4 +67,8 @@ tests/cases/compiler/jsdocInTypeScript.ts(42,12): error TS2503: Cannot find name * @type {{foo: (function(string, string): string)}} */ const obj = { foo: (a, b) => a + b }; + + /** @enum {string} */ + var E = {}; + E[""]; \ No newline at end of file diff --git a/tests/baselines/reference/jsdocInTypeScript.js b/tests/baselines/reference/jsdocInTypeScript.js index e79f400d039..ebff5629c37 100644 --- a/tests/baselines/reference/jsdocInTypeScript.js +++ b/tests/baselines/reference/jsdocInTypeScript.js @@ -47,6 +47,10 @@ import M = N; // Error: @typedef does not create namespaces in TypeScript code. * @type {{foo: (function(string, string): string)}} */ const obj = { foo: (a, b) => a + b }; + +/** @enum {string} */ +var E = {}; +E[""]; //// [jsdocInTypeScript.js] @@ -79,3 +83,6 @@ var M = N; // Error: @typedef does not create namespaces in TypeScript code. * @type {{foo: (function(string, string): string)}} */ var obj = { foo: function (a, b) { return a + b; } }; +/** @enum {string} */ +var E = {}; +E[""]; diff --git a/tests/baselines/reference/jsdocInTypeScript.symbols b/tests/baselines/reference/jsdocInTypeScript.symbols index 52caadb2064..c65d1215abe 100644 --- a/tests/baselines/reference/jsdocInTypeScript.symbols +++ b/tests/baselines/reference/jsdocInTypeScript.symbols @@ -83,3 +83,10 @@ const obj = { foo: (a, b) => a + b }; >a : Symbol(a, Decl(jsdocInTypeScript.ts, 47, 20)) >b : Symbol(b, Decl(jsdocInTypeScript.ts, 47, 22)) +/** @enum {string} */ +var E = {}; +>E : Symbol(E, Decl(jsdocInTypeScript.ts, 50, 3)) + +E[""]; +>E : Symbol(E, Decl(jsdocInTypeScript.ts, 50, 3)) + diff --git a/tests/baselines/reference/jsdocInTypeScript.types b/tests/baselines/reference/jsdocInTypeScript.types index 8916e006242..010efb68b7a 100644 --- a/tests/baselines/reference/jsdocInTypeScript.types +++ b/tests/baselines/reference/jsdocInTypeScript.types @@ -93,3 +93,13 @@ const obj = { foo: (a, b) => a + b }; >a : any >b : any +/** @enum {string} */ +var E = {}; +>E : {} +>{} : {} + +E[""]; +>E[""] : any +>E : {} +>"" : "" + diff --git a/tests/cases/compiler/jsdocInTypeScript.ts b/tests/cases/compiler/jsdocInTypeScript.ts index bceac17aa2c..4d1f0fbbe42 100644 --- a/tests/cases/compiler/jsdocInTypeScript.ts +++ b/tests/cases/compiler/jsdocInTypeScript.ts @@ -46,3 +46,7 @@ import M = N; // Error: @typedef does not create namespaces in TypeScript code. * @type {{foo: (function(string, string): string)}} */ const obj = { foo: (a, b) => a + b }; + +/** @enum {string} */ +var E = {}; +E[""];