From 0d052fae18fba7c18140bc843d54ab26fcabdd6c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 18 Oct 2019 13:36:56 -0700 Subject: [PATCH] Bind @class in the right place -- bindWorker not bindChildrenWorker Also add an assert to make future mismatches fail in an obvious place instead of in a while loop. --- src/compiler/binder.ts | 5 ++--- src/compiler/checker.ts | 1 + ...lOfPropertylessConstructorFunction.errors.txt | 14 ++++++++++++++ ...callOfPropertylessConstructorFunction.symbols | 14 ++++++++++++++ .../callOfPropertylessConstructorFunction.types | 16 ++++++++++++++++ .../callOfPropertylessConstructorFunction.ts | 11 +++++++++++ 6 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/callOfPropertylessConstructorFunction.errors.txt create mode 100644 tests/baselines/reference/callOfPropertylessConstructorFunction.symbols create mode 100644 tests/baselines/reference/callOfPropertylessConstructorFunction.types create mode 100644 tests/cases/conformance/jsdoc/callOfPropertylessConstructorFunction.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index e3fcc4624cf57..8a751525aa3cf 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -821,9 +821,6 @@ namespace ts { case SyntaxKind.JSDocEnumTag: bindJSDocTypeAlias(node as JSDocTypedefTag | JSDocCallbackTag | JSDocEnumTag); break; - case SyntaxKind.JSDocClassTag: - bindJSDocClassTag(node as JSDocClassTag); - break; // In source files and blocks, bind functions first to match hoisting that occurs at runtime case SyntaxKind.SourceFile: { bindEachFunctionsFirst((node as SourceFile).statements); @@ -2454,6 +2451,8 @@ namespace ts { case SyntaxKind.JSDocTypeLiteral: case SyntaxKind.MappedType: return bindAnonymousTypeWorker(node as TypeLiteralNode | MappedTypeNode | JSDocTypeLiteral); + case SyntaxKind.JSDocClassTag: + return bindJSDocClassTag(node as JSDocClassTag); case SyntaxKind.ObjectLiteralExpression: return bindObjectLiteralExpression(node); case SyntaxKind.FunctionExpression: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 96a783a6c9e73..8eb70561d1aac 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7688,6 +7688,7 @@ namespace ts { // The outer type parameters are those defined by enclosing generic classes, methods, or functions. function getOuterTypeParametersOfClassOrInterface(symbol: Symbol): TypeParameter[] | undefined { const declaration = symbol.flags & SymbolFlags.Class ? symbol.valueDeclaration : getDeclarationOfKind(symbol, SyntaxKind.InterfaceDeclaration)!; + Debug.assert(!!declaration, "Class was missing valueDeclaration -OR- non-class had no interface declarations"); return getOuterTypeParameters(declaration); } diff --git a/tests/baselines/reference/callOfPropertylessConstructorFunction.errors.txt b/tests/baselines/reference/callOfPropertylessConstructorFunction.errors.txt new file mode 100644 index 0000000000000..0abc6cf8d0c36 --- /dev/null +++ b/tests/baselines/reference/callOfPropertylessConstructorFunction.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/jsdoc/callOfPropertylessConstructorFunction.js(7,1): error TS2348: Value of type 'typeof Dependency' is not callable. Did you mean to include 'new'? + + +==== tests/cases/conformance/jsdoc/callOfPropertylessConstructorFunction.js (1 errors) ==== + /** + * @constructor + */ + function Dependency(j) { + return j + } + Dependency({}) + ~~~~~~~~~~~~~~ +!!! error TS2348: Value of type 'typeof Dependency' is not callable. Did you mean to include 'new'? + \ No newline at end of file diff --git a/tests/baselines/reference/callOfPropertylessConstructorFunction.symbols b/tests/baselines/reference/callOfPropertylessConstructorFunction.symbols new file mode 100644 index 0000000000000..94ebfa6cef275 --- /dev/null +++ b/tests/baselines/reference/callOfPropertylessConstructorFunction.symbols @@ -0,0 +1,14 @@ +=== tests/cases/conformance/jsdoc/callOfPropertylessConstructorFunction.js === +/** + * @constructor + */ +function Dependency(j) { +>Dependency : Symbol(Dependency, Decl(callOfPropertylessConstructorFunction.js, 0, 0)) +>j : Symbol(j, Decl(callOfPropertylessConstructorFunction.js, 3, 20)) + + return j +>j : Symbol(j, Decl(callOfPropertylessConstructorFunction.js, 3, 20)) +} +Dependency({}) +>Dependency : Symbol(Dependency, Decl(callOfPropertylessConstructorFunction.js, 0, 0)) + diff --git a/tests/baselines/reference/callOfPropertylessConstructorFunction.types b/tests/baselines/reference/callOfPropertylessConstructorFunction.types new file mode 100644 index 0000000000000..1294e4164c4f5 --- /dev/null +++ b/tests/baselines/reference/callOfPropertylessConstructorFunction.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/jsdoc/callOfPropertylessConstructorFunction.js === +/** + * @constructor + */ +function Dependency(j) { +>Dependency : typeof Dependency +>j : any + + return j +>j : any +} +Dependency({}) +>Dependency({}) : any +>Dependency : typeof Dependency +>{} : {} + diff --git a/tests/cases/conformance/jsdoc/callOfPropertylessConstructorFunction.ts b/tests/cases/conformance/jsdoc/callOfPropertylessConstructorFunction.ts new file mode 100644 index 0000000000000..213b66908d907 --- /dev/null +++ b/tests/cases/conformance/jsdoc/callOfPropertylessConstructorFunction.ts @@ -0,0 +1,11 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @Filename: callOfPropertylessConstructorFunction.js +/** + * @constructor + */ +function Dependency(j) { + return j +} +Dependency({})