From 7c1b28f2cbb0327e46411db789edf04cb961685e Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 8 Jun 2016 15:55:08 -0700 Subject: [PATCH 01/37] Allow primitive type guards with typeof on right Previously, only type guards of the form `typeof x === 'string'` were allowed. Now you can write `'string' === typeof x`. --- src/compiler/binder.ts | 16 +++++++++++++++- src/compiler/checker.ts | 17 +++++++++-------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 8c48d984b78..bfc9b07697b 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -612,7 +612,7 @@ namespace ts { if (isNarrowingExpression(expr.left) && (expr.right.kind === SyntaxKind.NullKeyword || expr.right.kind === SyntaxKind.Identifier)) { return true; } - if (expr.left.kind === SyntaxKind.TypeOfExpression && isNarrowingExpression((expr.left).expression) && expr.right.kind === SyntaxKind.StringLiteral) { + if (isTypeOfNarrowingBinaryExpression(expr)) { return true; } return false; @@ -624,6 +624,20 @@ namespace ts { return false; } + function isTypeOfNarrowingBinaryExpression(expr: BinaryExpression) { + let typeOf: Expression; + if (expr.left.kind === SyntaxKind.StringLiteral) { + typeOf = expr.right; + } + else if (expr.right.kind === SyntaxKind.StringLiteral) { + typeOf = expr.left; + } + else { + typeOf = undefined;; + } + return typeOf && typeOf.kind === SyntaxKind.TypeOfExpression && isNarrowingExpression((typeOf).expression); + } + function createBranchLabel(): FlowLabel { return { flags: FlowFlags.BranchLabel, diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 650bc488b0e..dbc2c920dbb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7864,7 +7864,8 @@ namespace ts { if (isNullOrUndefinedLiteral(expr.right)) { return narrowTypeByNullCheck(type, expr, assumeTrue); } - if (expr.left.kind === SyntaxKind.TypeOfExpression && expr.right.kind === SyntaxKind.StringLiteral) { + if (expr.left.kind === SyntaxKind.TypeOfExpression && expr.right.kind === SyntaxKind.StringLiteral || + expr.left.kind === SyntaxKind.StringLiteral && expr.right.kind === SyntaxKind.TypeOfExpression) { return narrowTypeByTypeof(type, expr, assumeTrue); } break; @@ -7897,12 +7898,12 @@ namespace ts { function narrowTypeByTypeof(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { // We have '==', '!=', '====', or !==' operator with 'typeof xxx' on the left // and string literal on the right - const left = expr.left; - const right = expr.right; - if (!isMatchingReference(reference, left.expression)) { + const typeOf = (expr.left.kind === SyntaxKind.TypeOfExpression ? expr.left : expr.right); + const literal = (expr.right.kind === SyntaxKind.StringLiteral ? expr.right : expr.left); + if (!isMatchingReference(reference, typeOf.expression)) { // For a reference of the form 'x.y', a 'typeof x === ...' type guard resets the // narrowed type of 'y' to its declared type. - if (containsMatchingReference(reference, left.expression)) { + if (containsMatchingReference(reference, typeOf.expression)) { return declaredType; } return type; @@ -7915,14 +7916,14 @@ namespace ts { // We narrow a non-union type to an exact primitive type if the non-union type // is a supertype of that primtive type. For example, type 'any' can be narrowed // to one of the primitive types. - const targetType = getProperty(typeofTypesByName, right.text); + const targetType = getProperty(typeofTypesByName, literal.text); if (targetType && isTypeSubtypeOf(targetType, type)) { return targetType; } } const facts = assumeTrue ? - getProperty(typeofEQFacts, right.text) || TypeFacts.TypeofEQHostObject : - getProperty(typeofNEFacts, right.text) || TypeFacts.TypeofNEHostObject; + getProperty(typeofEQFacts, literal.text) || TypeFacts.TypeofEQHostObject : + getProperty(typeofNEFacts, literal.text) || TypeFacts.TypeofNEHostObject; return getTypeWithFacts(type, facts); } From 11377f9fd342dc21012e9cff1d60d0a2226f30e6 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 8 Jun 2016 15:56:25 -0700 Subject: [PATCH 02/37] Primitive type guards are now order independent --- ...typeGuardOfFormTypeOfIsOrderIndependent.js | 71 ++++++++++++++ ...uardOfFormTypeOfIsOrderIndependent.symbols | 75 +++++++++++++++ ...eGuardOfFormTypeOfIsOrderIndependent.types | 95 +++++++++++++++++++ ...typeGuardOfFormTypeOfIsOrderIndependent.ts | 34 +++++++ 4 files changed, 275 insertions(+) create mode 100644 tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.js create mode 100644 tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.symbols create mode 100644 tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.types create mode 100644 tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfIsOrderIndependent.ts diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.js b/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.js new file mode 100644 index 00000000000..5ea7932e89a --- /dev/null +++ b/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.js @@ -0,0 +1,71 @@ +//// [typeGuardOfFormTypeOfIsOrderIndependent.ts] +var strOrNum: string | number; +var strOrBool: string | boolean; +var strOrFunc: string | (() => void); +var numOrBool: number | boolean +var str: string; +var num: number; +var bool: boolean; +var func: () => void; + +if ("string" === typeof strOrNum) { +// if (typeof strOrNum === "string") { + str = strOrNum; +} +else { + num = strOrNum; +} +if ("function" === typeof strOrFunc) { + func = strOrFunc; +} +else { + str = strOrFunc; +} +if ("number" === typeof numOrBool) { + num = numOrBool; +} +else { + bool = numOrBool; +} +if ("boolean" === typeof strOrBool) { + bool = strOrBool; +} +else { + str = strOrBool; +} + + +//// [typeGuardOfFormTypeOfIsOrderIndependent.js] +var strOrNum; +var strOrBool; +var strOrFunc; +var numOrBool; +var str; +var num; +var bool; +var func; +if ("string" === typeof strOrNum) { + // if (typeof strOrNum === "string") { + str = strOrNum; +} +else { + num = strOrNum; +} +if ("function" === typeof strOrFunc) { + func = strOrFunc; +} +else { + str = strOrFunc; +} +if ("number" === typeof numOrBool) { + num = numOrBool; +} +else { + bool = numOrBool; +} +if ("boolean" === typeof strOrBool) { + bool = strOrBool; +} +else { + str = strOrBool; +} diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.symbols b/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.symbols new file mode 100644 index 00000000000..d75774eba45 --- /dev/null +++ b/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.symbols @@ -0,0 +1,75 @@ +=== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfIsOrderIndependent.ts === +var strOrNum: string | number; +>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 0, 3)) + +var strOrBool: string | boolean; +>strOrBool : Symbol(strOrBool, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 1, 3)) + +var strOrFunc: string | (() => void); +>strOrFunc : Symbol(strOrFunc, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 2, 3)) + +var numOrBool: number | boolean +>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 3, 3)) + +var str: string; +>str : Symbol(str, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 4, 3)) + +var num: number; +>num : Symbol(num, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 5, 3)) + +var bool: boolean; +>bool : Symbol(bool, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 6, 3)) + +var func: () => void; +>func : Symbol(func, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 7, 3)) + +if ("string" === typeof strOrNum) { +>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 0, 3)) + +// if (typeof strOrNum === "string") { + str = strOrNum; +>str : Symbol(str, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 4, 3)) +>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 0, 3)) +} +else { + num = strOrNum; +>num : Symbol(num, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 5, 3)) +>strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 0, 3)) +} +if ("function" === typeof strOrFunc) { +>strOrFunc : Symbol(strOrFunc, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 2, 3)) + + func = strOrFunc; +>func : Symbol(func, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 7, 3)) +>strOrFunc : Symbol(strOrFunc, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 2, 3)) +} +else { + str = strOrFunc; +>str : Symbol(str, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 4, 3)) +>strOrFunc : Symbol(strOrFunc, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 2, 3)) +} +if ("number" === typeof numOrBool) { +>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 3, 3)) + + num = numOrBool; +>num : Symbol(num, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 5, 3)) +>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 3, 3)) +} +else { + bool = numOrBool; +>bool : Symbol(bool, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 6, 3)) +>numOrBool : Symbol(numOrBool, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 3, 3)) +} +if ("boolean" === typeof strOrBool) { +>strOrBool : Symbol(strOrBool, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 1, 3)) + + bool = strOrBool; +>bool : Symbol(bool, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 6, 3)) +>strOrBool : Symbol(strOrBool, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 1, 3)) +} +else { + str = strOrBool; +>str : Symbol(str, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 4, 3)) +>strOrBool : Symbol(strOrBool, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 1, 3)) +} + diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.types b/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.types new file mode 100644 index 00000000000..592d147f386 --- /dev/null +++ b/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.types @@ -0,0 +1,95 @@ +=== tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfIsOrderIndependent.ts === +var strOrNum: string | number; +>strOrNum : string | number + +var strOrBool: string | boolean; +>strOrBool : string | boolean + +var strOrFunc: string | (() => void); +>strOrFunc : string | (() => void) + +var numOrBool: number | boolean +>numOrBool : number | boolean + +var str: string; +>str : string + +var num: number; +>num : number + +var bool: boolean; +>bool : boolean + +var func: () => void; +>func : () => void + +if ("string" === typeof strOrNum) { +>"string" === typeof strOrNum : boolean +>"string" : string +>typeof strOrNum : string +>strOrNum : string | number + +// if (typeof strOrNum === "string") { + str = strOrNum; +>str = strOrNum : string +>str : string +>strOrNum : string +} +else { + num = strOrNum; +>num = strOrNum : number +>num : number +>strOrNum : number +} +if ("function" === typeof strOrFunc) { +>"function" === typeof strOrFunc : boolean +>"function" : string +>typeof strOrFunc : string +>strOrFunc : string | (() => void) + + func = strOrFunc; +>func = strOrFunc : () => void +>func : () => void +>strOrFunc : () => void +} +else { + str = strOrFunc; +>str = strOrFunc : string +>str : string +>strOrFunc : string +} +if ("number" === typeof numOrBool) { +>"number" === typeof numOrBool : boolean +>"number" : string +>typeof numOrBool : string +>numOrBool : number | boolean + + num = numOrBool; +>num = numOrBool : number +>num : number +>numOrBool : number +} +else { + bool = numOrBool; +>bool = numOrBool : boolean +>bool : boolean +>numOrBool : boolean +} +if ("boolean" === typeof strOrBool) { +>"boolean" === typeof strOrBool : boolean +>"boolean" : string +>typeof strOrBool : string +>strOrBool : string | boolean + + bool = strOrBool; +>bool = strOrBool : boolean +>bool : boolean +>strOrBool : boolean +} +else { + str = strOrBool; +>str = strOrBool : string +>str : string +>strOrBool : string +} + diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfIsOrderIndependent.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfIsOrderIndependent.ts new file mode 100644 index 00000000000..79fcf49e245 --- /dev/null +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfIsOrderIndependent.ts @@ -0,0 +1,34 @@ +var strOrNum: string | number; +var strOrBool: string | boolean; +var strOrFunc: string | (() => void); +var numOrBool: number | boolean +var str: string; +var num: number; +var bool: boolean; +var func: () => void; + +if ("string" === typeof strOrNum) { +// if (typeof strOrNum === "string") { + str = strOrNum; +} +else { + num = strOrNum; +} +if ("function" === typeof strOrFunc) { + func = strOrFunc; +} +else { + str = strOrFunc; +} +if ("number" === typeof numOrBool) { + num = numOrBool; +} +else { + bool = numOrBool; +} +if ("boolean" === typeof strOrBool) { + bool = strOrBool; +} +else { + str = strOrBool; +} From a1e4b31d160b11ac4b579b34892ad8e05b64bc42 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Thu, 9 Jun 2016 15:48:35 -0700 Subject: [PATCH 03/37] Allow null/undefined guard with null/undefined on left Also add a test with baselines. --- src/compiler/binder.ts | 5 ++- src/compiler/checker.ts | 10 +++-- ...lOrUndefinedTypeGuardIsOrderIndependent.js | 30 +++++++++++++ ...definedTypeGuardIsOrderIndependent.symbols | 34 +++++++++++++++ ...UndefinedTypeGuardIsOrderIndependent.types | 43 +++++++++++++++++++ ...typeGuardOfFormTypeOfIsOrderIndependent.js | 2 - ...uardOfFormTypeOfIsOrderIndependent.symbols | 1 - ...eGuardOfFormTypeOfIsOrderIndependent.types | 1 - ...lOrUndefinedTypeGuardIsOrderIndependent.ts | 14 ++++++ ...typeGuardOfFormTypeOfIsOrderIndependent.ts | 1 - 10 files changed, 130 insertions(+), 11 deletions(-) create mode 100644 tests/baselines/reference/nullOrUndefinedTypeGuardIsOrderIndependent.js create mode 100644 tests/baselines/reference/nullOrUndefinedTypeGuardIsOrderIndependent.symbols create mode 100644 tests/baselines/reference/nullOrUndefinedTypeGuardIsOrderIndependent.types create mode 100644 tests/cases/conformance/expressions/typeGuards/nullOrUndefinedTypeGuardIsOrderIndependent.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index bfc9b07697b..96213801264 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -609,7 +609,8 @@ namespace ts { case SyntaxKind.ExclamationEqualsToken: case SyntaxKind.EqualsEqualsEqualsToken: case SyntaxKind.ExclamationEqualsEqualsToken: - if (isNarrowingExpression(expr.left) && (expr.right.kind === SyntaxKind.NullKeyword || expr.right.kind === SyntaxKind.Identifier)) { + if ((isNarrowingExpression(expr.left) && (expr.right.kind === SyntaxKind.NullKeyword || expr.right.kind === SyntaxKind.Identifier)) || + (isNarrowingExpression(expr.right) && (expr.left.kind === SyntaxKind.NullKeyword || expr.left.kind === SyntaxKind.Identifier))) { return true; } if (isTypeOfNarrowingBinaryExpression(expr)) { @@ -633,7 +634,7 @@ namespace ts { typeOf = expr.left; } else { - typeOf = undefined;; + typeOf = undefined; } return typeOf && typeOf.kind === SyntaxKind.TypeOfExpression && isNarrowingExpression((typeOf).expression); } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index dbc2c920dbb..281bac29914 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7861,7 +7861,7 @@ namespace ts { case SyntaxKind.ExclamationEqualsToken: case SyntaxKind.EqualsEqualsEqualsToken: case SyntaxKind.ExclamationEqualsEqualsToken: - if (isNullOrUndefinedLiteral(expr.right)) { + if (isNullOrUndefinedLiteral(expr.left) || isNullOrUndefinedLiteral(expr.right)) { return narrowTypeByNullCheck(type, expr, assumeTrue); } if (expr.left.kind === SyntaxKind.TypeOfExpression && expr.right.kind === SyntaxKind.StringLiteral || @@ -7878,18 +7878,20 @@ namespace ts { } function narrowTypeByNullCheck(type: Type, expr: BinaryExpression, assumeTrue: boolean): Type { - // We have '==', '!=', '===', or '!==' operator with 'null' or 'undefined' on the right + // We have '==', '!=', '===', or '!==' operator with 'null' or 'undefined' on one side const operator = expr.operatorToken.kind; + const nullLike = isNullOrUndefinedLiteral(expr.left) ? expr.left : expr.right; + const narrowed = isNullOrUndefinedLiteral(expr.left) ? expr.right : expr.left; if (operator === SyntaxKind.ExclamationEqualsToken || operator === SyntaxKind.ExclamationEqualsEqualsToken) { assumeTrue = !assumeTrue; } - if (!strictNullChecks || !isMatchingReference(reference, expr.left)) { + if (!strictNullChecks || !isMatchingReference(reference, narrowed)) { return type; } const doubleEquals = operator === SyntaxKind.EqualsEqualsToken || operator === SyntaxKind.ExclamationEqualsToken; const facts = doubleEquals ? assumeTrue ? TypeFacts.EQUndefinedOrNull : TypeFacts.NEUndefinedOrNull : - expr.right.kind === SyntaxKind.NullKeyword ? + nullLike.kind === SyntaxKind.NullKeyword ? assumeTrue ? TypeFacts.EQNull : TypeFacts.NENull : assumeTrue ? TypeFacts.EQUndefined : TypeFacts.NEUndefined; return getTypeWithFacts(type, facts); diff --git a/tests/baselines/reference/nullOrUndefinedTypeGuardIsOrderIndependent.js b/tests/baselines/reference/nullOrUndefinedTypeGuardIsOrderIndependent.js new file mode 100644 index 00000000000..f62bd2a3f11 --- /dev/null +++ b/tests/baselines/reference/nullOrUndefinedTypeGuardIsOrderIndependent.js @@ -0,0 +1,30 @@ +//// [nullOrUndefinedTypeGuardIsOrderIndependent.ts] +function test(strOrNull: string | null, strOrUndefined: string | undefined) { + var str: string = "original"; + var nil: null; + if (null === strOrNull) { + nil = strOrNull; + } + else { + str = strOrNull; + } + if (undefined !== strOrUndefined) { + str = strOrUndefined; + } +} + + +//// [nullOrUndefinedTypeGuardIsOrderIndependent.js] +function test(strOrNull, strOrUndefined) { + var str = "original"; + var nil; + if (null === strOrNull) { + nil = strOrNull; + } + else { + str = strOrNull; + } + if (undefined !== strOrUndefined) { + str = strOrUndefined; + } +} diff --git a/tests/baselines/reference/nullOrUndefinedTypeGuardIsOrderIndependent.symbols b/tests/baselines/reference/nullOrUndefinedTypeGuardIsOrderIndependent.symbols new file mode 100644 index 00000000000..bb1d1843289 --- /dev/null +++ b/tests/baselines/reference/nullOrUndefinedTypeGuardIsOrderIndependent.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/expressions/typeGuards/nullOrUndefinedTypeGuardIsOrderIndependent.ts === +function test(strOrNull: string | null, strOrUndefined: string | undefined) { +>test : Symbol(test, Decl(nullOrUndefinedTypeGuardIsOrderIndependent.ts, 0, 0)) +>strOrNull : Symbol(strOrNull, Decl(nullOrUndefinedTypeGuardIsOrderIndependent.ts, 0, 14)) +>strOrUndefined : Symbol(strOrUndefined, Decl(nullOrUndefinedTypeGuardIsOrderIndependent.ts, 0, 39)) + + var str: string = "original"; +>str : Symbol(str, Decl(nullOrUndefinedTypeGuardIsOrderIndependent.ts, 1, 7)) + + var nil: null; +>nil : Symbol(nil, Decl(nullOrUndefinedTypeGuardIsOrderIndependent.ts, 2, 7)) + + if (null === strOrNull) { +>strOrNull : Symbol(strOrNull, Decl(nullOrUndefinedTypeGuardIsOrderIndependent.ts, 0, 14)) + + nil = strOrNull; +>nil : Symbol(nil, Decl(nullOrUndefinedTypeGuardIsOrderIndependent.ts, 2, 7)) +>strOrNull : Symbol(strOrNull, Decl(nullOrUndefinedTypeGuardIsOrderIndependent.ts, 0, 14)) + } + else { + str = strOrNull; +>str : Symbol(str, Decl(nullOrUndefinedTypeGuardIsOrderIndependent.ts, 1, 7)) +>strOrNull : Symbol(strOrNull, Decl(nullOrUndefinedTypeGuardIsOrderIndependent.ts, 0, 14)) + } + if (undefined !== strOrUndefined) { +>undefined : Symbol(undefined) +>strOrUndefined : Symbol(strOrUndefined, Decl(nullOrUndefinedTypeGuardIsOrderIndependent.ts, 0, 39)) + + str = strOrUndefined; +>str : Symbol(str, Decl(nullOrUndefinedTypeGuardIsOrderIndependent.ts, 1, 7)) +>strOrUndefined : Symbol(strOrUndefined, Decl(nullOrUndefinedTypeGuardIsOrderIndependent.ts, 0, 39)) + } +} + diff --git a/tests/baselines/reference/nullOrUndefinedTypeGuardIsOrderIndependent.types b/tests/baselines/reference/nullOrUndefinedTypeGuardIsOrderIndependent.types new file mode 100644 index 00000000000..f599366e66e --- /dev/null +++ b/tests/baselines/reference/nullOrUndefinedTypeGuardIsOrderIndependent.types @@ -0,0 +1,43 @@ +=== tests/cases/conformance/expressions/typeGuards/nullOrUndefinedTypeGuardIsOrderIndependent.ts === +function test(strOrNull: string | null, strOrUndefined: string | undefined) { +>test : (strOrNull: string | null, strOrUndefined: string | undefined) => void +>strOrNull : string | null +>null : null +>strOrUndefined : string | undefined + + var str: string = "original"; +>str : string +>"original" : string + + var nil: null; +>nil : null +>null : null + + if (null === strOrNull) { +>null === strOrNull : boolean +>null : null +>strOrNull : string | null + + nil = strOrNull; +>nil = strOrNull : null +>nil : null +>strOrNull : null + } + else { + str = strOrNull; +>str = strOrNull : string +>str : string +>strOrNull : string + } + if (undefined !== strOrUndefined) { +>undefined !== strOrUndefined : boolean +>undefined : undefined +>strOrUndefined : string | undefined + + str = strOrUndefined; +>str = strOrUndefined : string +>str : string +>strOrUndefined : string + } +} + diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.js b/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.js index 5ea7932e89a..7d9a1651f08 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.js +++ b/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.js @@ -9,7 +9,6 @@ var bool: boolean; var func: () => void; if ("string" === typeof strOrNum) { -// if (typeof strOrNum === "string") { str = strOrNum; } else { @@ -45,7 +44,6 @@ var num; var bool; var func; if ("string" === typeof strOrNum) { - // if (typeof strOrNum === "string") { str = strOrNum; } else { diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.symbols b/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.symbols index d75774eba45..f33908631a4 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.symbols +++ b/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.symbols @@ -26,7 +26,6 @@ var func: () => void; if ("string" === typeof strOrNum) { >strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 0, 3)) -// if (typeof strOrNum === "string") { str = strOrNum; >str : Symbol(str, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 4, 3)) >strOrNum : Symbol(strOrNum, Decl(typeGuardOfFormTypeOfIsOrderIndependent.ts, 0, 3)) diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.types b/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.types index 592d147f386..2d91abb9613 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.types +++ b/tests/baselines/reference/typeGuardOfFormTypeOfIsOrderIndependent.types @@ -29,7 +29,6 @@ if ("string" === typeof strOrNum) { >typeof strOrNum : string >strOrNum : string | number -// if (typeof strOrNum === "string") { str = strOrNum; >str = strOrNum : string >str : string diff --git a/tests/cases/conformance/expressions/typeGuards/nullOrUndefinedTypeGuardIsOrderIndependent.ts b/tests/cases/conformance/expressions/typeGuards/nullOrUndefinedTypeGuardIsOrderIndependent.ts new file mode 100644 index 00000000000..2da52406609 --- /dev/null +++ b/tests/cases/conformance/expressions/typeGuards/nullOrUndefinedTypeGuardIsOrderIndependent.ts @@ -0,0 +1,14 @@ +// @strictNullChecks: true +function test(strOrNull: string | null, strOrUndefined: string | undefined) { + var str: string = "original"; + var nil: null; + if (null === strOrNull) { + nil = strOrNull; + } + else { + str = strOrNull; + } + if (undefined !== strOrUndefined) { + str = strOrUndefined; + } +} diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfIsOrderIndependent.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfIsOrderIndependent.ts index 79fcf49e245..b7a5caf41da 100644 --- a/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfIsOrderIndependent.ts +++ b/tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfIsOrderIndependent.ts @@ -8,7 +8,6 @@ var bool: boolean; var func: () => void; if ("string" === typeof strOrNum) { -// if (typeof strOrNum === "string") { str = strOrNum; } else { From 5ae0602a633339d662fb63fef9c87afad5071757 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Fri, 10 Jun 2016 11:20:59 -0700 Subject: [PATCH 04/37] fix baselines --- .../reference/es6modulekindWithES5Target10.errors.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/baselines/reference/es6modulekindWithES5Target10.errors.txt b/tests/baselines/reference/es6modulekindWithES5Target10.errors.txt index efa4cd87e43..fd01dafc11f 100644 --- a/tests/baselines/reference/es6modulekindWithES5Target10.errors.txt +++ b/tests/baselines/reference/es6modulekindWithES5Target10.errors.txt @@ -1,13 +1,13 @@ -tests/cases/compiler/es6modulekindWithES5Target10.ts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. +tests/cases/compiler/es6modulekindWithES5Target10.ts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. tests/cases/compiler/es6modulekindWithES5Target10.ts(2,20): error TS2307: Cannot find module 'mod'. -tests/cases/compiler/es6modulekindWithES5Target10.ts(7,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead. +tests/cases/compiler/es6modulekindWithES5Target10.ts(7,1): error TS1203: Export assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'export default' or another module format instead. ==== tests/cases/compiler/es6modulekindWithES5Target10.ts (3 errors) ==== import i = require("mod"); // Error; ~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS1202: Import assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. +!!! error TS1202: Import assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead. ~~~~~ !!! error TS2307: Cannot find module 'mod'. @@ -16,4 +16,4 @@ tests/cases/compiler/es6modulekindWithES5Target10.ts(7,1): error TS1203: Export } export = N; // Error ~~~~~~~~~~~ -!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 6 modules. Consider using 'export default' or another module format instead. \ No newline at end of file +!!! error TS1203: Export assignment cannot be used when targeting ECMAScript 2015 modules. Consider using 'export default' or another module format instead. \ No newline at end of file From 642583771d5f3a3175b5bfd93b9b79ce70dc0938 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 10 Jun 2016 14:10:30 -0700 Subject: [PATCH 05/37] Salsa: get members of variables whose initialisers are functions --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 8 ++++++-- src/compiler/utilities.ts | 12 ++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index db956cca647..bfe7ee31eb2 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1945,7 +1945,7 @@ namespace ts { classPrototype.parent = leftSideOfAssignment; const funcSymbol = container.locals[constructorFunction.text]; - if (!funcSymbol || !(funcSymbol.flags & SymbolFlags.Function)) { + if (!funcSymbol || !(funcSymbol.flags & SymbolFlags.Function || isDeclarationOfFunctionExpression(funcSymbol))) { return; } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 044f42414b7..e3a29cce258 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11481,8 +11481,12 @@ namespace ts { // When resolved signature is a call signature (and not a construct signature) the result type is any, unless // the declaring function had members created through 'x.prototype.y = expr' or 'this.y = expr' psuedodeclarations // in a JS file - const funcSymbol = checkExpression(node.expression).symbol; - if (funcSymbol && funcSymbol.members && (funcSymbol.flags & SymbolFlags.Function)) { + // Note:JS inferred classes might come from a variable declaration instead of a function declaration. + // In this case, using getResolvedSymbol directly is required to avoid losing the members from the declaration. + const funcSymbol = node.expression.kind === SyntaxKind.Identifier ? + getResolvedSymbol(node.expression as Identifier) : + checkExpression(node.expression).symbol; + if (funcSymbol && funcSymbol.members && (funcSymbol.flags & SymbolFlags.Function || isDeclarationOfFunctionExpression(funcSymbol))) { return getInferredClassType(funcSymbol); } else if (compilerOptions.noImplicitAny) { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index c54775ad2af..04ea50f4e0c 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1257,6 +1257,18 @@ namespace ts { return charCode === CharacterCodes.singleQuote || charCode === CharacterCodes.doubleQuote; } + /** + * Returns true if the node is a variable declaration whose initializer is a function expression. + * This function does not test if the node is in a JavaScript file or not. + */ + export function isDeclarationOfFunctionExpression(s: Symbol) { + if (s.valueDeclaration && s.valueDeclaration.kind === SyntaxKind.VariableDeclaration) { + const declaration = s.valueDeclaration as VariableDeclaration; + return declaration.initializer && declaration.initializer.kind === SyntaxKind.FunctionExpression; + } + return false; + } + /// Given a BinaryExpression, returns SpecialPropertyAssignmentKind for the various kinds of property /// assignments we treat as special in the binder export function getSpecialPropertyAssignmentKind(expression: Node): SpecialPropertyAssignmentKind { From 4a9b1209aeffb33ddbc6c7358e2a0e901cb8eee9 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 10 Jun 2016 14:11:31 -0700 Subject: [PATCH 06/37] Test adding members to JS variables whose initialisers are functions --- ...salsaMethodsOnAssignedFunctionExpressions.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/cases/fourslash/salsaMethodsOnAssignedFunctionExpressions.ts diff --git a/tests/cases/fourslash/salsaMethodsOnAssignedFunctionExpressions.ts b/tests/cases/fourslash/salsaMethodsOnAssignedFunctionExpressions.ts new file mode 100644 index 00000000000..a73207c01d2 --- /dev/null +++ b/tests/cases/fourslash/salsaMethodsOnAssignedFunctionExpressions.ts @@ -0,0 +1,17 @@ +/// +// @allowJs: true +// @Filename: something.js +////var C = function () { } +/////** +//// * The prototype method. +//// * @param {string} a Parameter definition. +//// */ +////function f(a) {} +////C.prototype.m = f; +//// +////var x = new C(); +////x/*1*/./*2*/m(); +goTo.marker('1'); +verify.quickInfoIs('var x: {\n m: (a: string) => void;\n}'); +goTo.marker('2'); +verify.completionListContains('m', '(property) C.m: (a: string) => void', 'The prototype method.'); From b027b4f4239f950e9e4420a217f1e46f4c388647 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 10 Jun 2016 14:13:56 -0700 Subject: [PATCH 07/37] Recommend runtests-parallel in CONTRIBUTING --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7a99bf318d2..1c242022979 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -91,10 +91,10 @@ These two files represent the DOM typings and are auto-generated. To make any mo ## Running the Tests -To run all tests, invoke the `runtests` target using jake: +To run all tests, invoke the `runtests-parallel` target using jake: ```Shell -jake runtests +jake runtests-parallel ``` This run will all tests; to run only a specific subset of tests, use: From a3a1c49739e413e03c05b498e06db3c9008989ee Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 10 Jun 2016 14:14:32 -0700 Subject: [PATCH 08/37] Allow empty lists on command line --- src/compiler/commandLineParser.ts | 22 +++++++--- tests/cases/unittests/commandLineParsing.ts | 47 +++++++++++++++++++-- 2 files changed, 59 insertions(+), 10 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 361b38d402b..5188c1f8483 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -488,13 +488,20 @@ namespace ts { } /* @internal */ - export function parseListTypeOption(opt: CommandLineOptionOfListType, value: string, errors: Diagnostic[]): (string | number)[] { - const values = trimString((value || "")).split(","); + export function parseListTypeOption(opt: CommandLineOptionOfListType, value = "", errors: Diagnostic[]): (string | number)[] | undefined { + value = trimString(value); + if (startsWith(value, "-")) { + return undefined; + } + if (value === "" || value === ",") { + return []; + } + const values = value.split(","); switch (opt.element.type) { case "number": - return ts.map(values, parseInt); + return map(values, parseInt); case "string": - return ts.map(values, v => v || ""); + return map(values, v => v || ""); default: return filter(map(values, v => parseCustomTypeOption(opt.element, v, errors)), v => !!v); } @@ -555,8 +562,11 @@ namespace ts { i++; break; case "list": - options[opt.name] = parseListTypeOption(opt, args[i], errors); - i++; + const result = parseListTypeOption(opt, args[i], errors); + options[opt.name] = result || []; + if (result) { + i++; + } break; // If not a primitive, the possible types are specified in what is effectively a map of options. default: diff --git a/tests/cases/unittests/commandLineParsing.ts b/tests/cases/unittests/commandLineParsing.ts index 8212ff03da4..5f4d9ac0d07 100644 --- a/tests/cases/unittests/commandLineParsing.ts +++ b/tests/cases/unittests/commandLineParsing.ts @@ -216,10 +216,24 @@ namespace ts { file: undefined, start: undefined, length: undefined, - }, { - messageText: "Argument for '--lib' option must be: 'es5', 'es6', 'es2015', 'es7', 'es2016', 'es2017', 'dom', 'webworker', 'scripthost', 'es2015.core', 'es2015.collection', 'es2015.generator', 'es2015.iterable', 'es2015.promise', 'es2015.proxy', 'es2015.reflect', 'es2015.symbol', 'es2015.symbol.wellknown', 'es2016.array.include', 'es2017.object', 'es2017.sharedmemory'", - category: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.category, - code: ts.Diagnostics.Argument_for_0_option_must_be_Colon_1.code, + }], + fileNames: ["0.ts"], + options: { + lib: [] + } + }); + }); + + + it("Parse empty string of --lib ", () => { + // 0.ts --lib + // This test is an error because the empty string is falsey + assertParseResult(["0.ts", "--lib", ""], + { + errors: [{ + messageText: "Compiler option 'lib' expects an argument.", + category: ts.Diagnostics.Compiler_option_0_expects_an_argument.category, + code: ts.Diagnostics.Compiler_option_0_expects_an_argument.code, file: undefined, start: undefined, @@ -232,6 +246,31 @@ namespace ts { }); }); + it("Parse single comma of --lib ", () => { + // 0.ts --lib + assertParseResult(["0.ts", "--lib", ","], + { + errors: [], + fileNames: ["0.ts"], + options: { + lib: [] + } + }); + }); + + it("Parse immediately following command line argument of --lib ", () => { + // 0.ts --lib + assertParseResult(["0.ts", "--lib", "--sourcemap"], + { + errors: [], + fileNames: ["0.ts"], + options: { + lib: [], + sourceMap: true + } + }); + }); + it("Parse --lib option with extra comma ", () => { // --lib es5, es7 0.ts assertParseResult(["--lib", "es5,", "es7", "0.ts"], From d20459607b96b17dacfd018eb6f8e29a97805dfc Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 10 Jun 2016 14:35:13 -0700 Subject: [PATCH 09/37] Remove single-comma empty array form --- src/compiler/commandLineParser.ts | 2 +- tests/cases/unittests/commandLineParsing.ts | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 5188c1f8483..1434cbbadf0 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -493,7 +493,7 @@ namespace ts { if (startsWith(value, "-")) { return undefined; } - if (value === "" || value === ",") { + if (value === "") { return []; } const values = value.split(","); diff --git a/tests/cases/unittests/commandLineParsing.ts b/tests/cases/unittests/commandLineParsing.ts index 5f4d9ac0d07..49b22b903ad 100644 --- a/tests/cases/unittests/commandLineParsing.ts +++ b/tests/cases/unittests/commandLineParsing.ts @@ -246,18 +246,6 @@ namespace ts { }); }); - it("Parse single comma of --lib ", () => { - // 0.ts --lib - assertParseResult(["0.ts", "--lib", ","], - { - errors: [], - fileNames: ["0.ts"], - options: { - lib: [] - } - }); - }); - it("Parse immediately following command line argument of --lib ", () => { // 0.ts --lib assertParseResult(["0.ts", "--lib", "--sourcemap"], From 8d83cd167fd3327317145b8be560a7ea0358cb2d Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Fri, 10 Jun 2016 15:26:14 -0700 Subject: [PATCH 10/37] Remove trailing whitespace --- tests/cases/unittests/commandLineParsing.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/cases/unittests/commandLineParsing.ts b/tests/cases/unittests/commandLineParsing.ts index 49b22b903ad..095f912ac1c 100644 --- a/tests/cases/unittests/commandLineParsing.ts +++ b/tests/cases/unittests/commandLineParsing.ts @@ -224,7 +224,6 @@ namespace ts { }); }); - it("Parse empty string of --lib ", () => { // 0.ts --lib // This test is an error because the empty string is falsey From 9827b638b4d1a8f3b36fd3e64a46563927c0b326 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Fri, 10 Jun 2016 15:44:11 -0700 Subject: [PATCH 11/37] Implicit type inclusion changes --- src/compiler/commandLineParser.ts | 8 +- src/compiler/diagnosticMessages.json | 4 + src/compiler/program.ts | 96 +++++++++---------- src/compiler/types.ts | 7 +- src/harness/fourslash.ts | 4 +- src/harness/harness.ts | 59 ++++++++---- src/harness/harnessLanguageService.ts | 21 ++-- src/harness/projectsRunner.ts | 3 +- src/server/editorServices.ts | 4 + src/services/services.ts | 10 +- tests/baselines/reference/commonSourceDir5.js | 1 + .../reference/commonSourceDir5.symbols | 9 +- .../reference/commonSourceDir5.types | 1 + .../reference/library-reference-1.symbols | 4 +- .../reference/library-reference-1.trace.json | 15 ++- .../reference/library-reference-1.types | 4 +- .../reference/library-reference-10.symbols | 4 +- .../reference/library-reference-10.trace.json | 18 ++-- .../reference/library-reference-10.types | 4 +- .../reference/library-reference-11.trace.json | 14 +-- .../reference/library-reference-12.trace.json | 14 +-- .../reference/library-reference-13.trace.json | 4 +- .../reference/library-reference-14.trace.json | 4 +- .../reference/library-reference-15.errors.txt | 14 +-- .../reference/library-reference-15.js | 11 ++- .../reference/library-reference-15.trace.json | 27 +----- .../reference/library-reference-2.trace.json | 10 +- .../reference/library-reference-3.trace.json | 15 +-- .../reference/library-reference-4.trace.json | 48 +++------- .../reference/library-reference-5.trace.json | 78 ++++++++------- .../reference/library-reference-6.symbols | 16 ---- .../reference/library-reference-6.trace.json | 31 +++++- .../reference/library-reference-6.types | 16 ---- .../reference/library-reference-7.trace.json | 14 +-- .../reference/library-reference-8.symbols | 6 +- .../reference/library-reference-8.trace.json | 50 ++++++---- .../reference/library-reference-8.types | 6 +- .../reference/library-reference-9.js | 16 ---- .../reference/library-reference-9.symbols | 16 ---- .../reference/library-reference-9.trace.json | 7 -- .../reference/library-reference-9.types | 16 ---- .../moduleResolutionWithSymlinks.errors.txt | 21 ++++ .../moduleResolutionWithSymlinks.symbols | 36 ------- .../moduleResolutionWithSymlinks.trace.json | 42 +++++++- .../moduleResolutionWithSymlinks.types | 38 -------- ...pingBasedModuleResolution3_node.trace.json | 3 + ...pingBasedModuleResolution4_node.trace.json | 3 + ...pingBasedModuleResolution5_node.trace.json | 4 + ...pingBasedModuleResolution6_node.trace.json | 2 + ...pingBasedModuleResolution7_node.trace.json | 5 + .../typeReferenceDirectives1.trace.json | 9 +- .../typeReferenceDirectives10.trace.json | 12 ++- .../typeReferenceDirectives11.trace.json | 5 +- .../typeReferenceDirectives12.trace.json | 14 ++- .../typeReferenceDirectives13.trace.json | 12 ++- .../typeReferenceDirectives2.trace.json | 4 +- .../typeReferenceDirectives3.trace.json | 9 +- .../typeReferenceDirectives4.trace.json | 9 +- .../typeReferenceDirectives5.trace.json | 12 ++- .../typeReferenceDirectives6.trace.json | 9 +- .../typeReferenceDirectives7.trace.json | 9 +- .../typeReferenceDirectives8.trace.json | 5 +- .../typeReferenceDirectives9.trace.json | 14 ++- tests/baselines/reference/typingsLookup1.js | 2 + .../reference/typingsLookup1.symbols | 5 +- .../reference/typingsLookup1.trace.json | 18 ++++ .../baselines/reference/typingsLookup1.types | 5 +- tests/cases/compiler/commonSourceDir5.ts | 1 + .../compiler/typeReferenceDirectives1.ts | 2 +- .../compiler/typeReferenceDirectives10.ts | 2 +- .../compiler/typeReferenceDirectives11.ts | 2 +- .../compiler/typeReferenceDirectives12.ts | 2 +- .../compiler/typeReferenceDirectives13.ts | 2 +- .../compiler/typeReferenceDirectives2.ts | 2 +- .../compiler/typeReferenceDirectives3.ts | 2 +- .../compiler/typeReferenceDirectives4.ts | 2 +- .../compiler/typeReferenceDirectives5.ts | 2 +- .../compiler/typeReferenceDirectives6.ts | 2 +- .../compiler/typeReferenceDirectives7.ts | 2 +- .../compiler/typeReferenceDirectives8.ts | 2 +- .../compiler/typeReferenceDirectives9.ts | 2 +- .../references/library-reference-1.ts | 7 +- .../references/library-reference-10.ts | 9 +- .../references/library-reference-13.ts | 3 +- .../references/library-reference-14.ts | 3 +- .../references/library-reference-15.ts | 8 +- .../references/library-reference-2.ts | 3 +- .../references/library-reference-3.ts | 2 +- .../references/library-reference-4.ts | 3 +- .../references/library-reference-5.ts | 1 + .../references/library-reference-6.ts | 6 +- .../references/library-reference-8.ts | 9 +- .../references/library-reference-9.ts | 20 ---- .../conformance/typings/typingsLookup1.ts | 8 +- .../goToDefinitionTypeReferenceDirective.ts | 2 +- .../goToDefinitionTypeReferenceDirective.ts | 2 +- .../goToDefinitionTypeReferenceDirective.ts | 4 +- tests/cases/unittests/moduleResolution.ts | 29 +++--- .../cases/unittests/reuseProgramStructure.ts | 5 +- 99 files changed, 605 insertions(+), 562 deletions(-) delete mode 100644 tests/baselines/reference/library-reference-6.symbols delete mode 100644 tests/baselines/reference/library-reference-6.types delete mode 100644 tests/baselines/reference/library-reference-9.js delete mode 100644 tests/baselines/reference/library-reference-9.symbols delete mode 100644 tests/baselines/reference/library-reference-9.trace.json delete mode 100644 tests/baselines/reference/library-reference-9.types create mode 100644 tests/baselines/reference/moduleResolutionWithSymlinks.errors.txt delete mode 100644 tests/baselines/reference/moduleResolutionWithSymlinks.symbols delete mode 100644 tests/baselines/reference/moduleResolutionWithSymlinks.types create mode 100644 tests/baselines/reference/typingsLookup1.trace.json delete mode 100644 tests/cases/conformance/references/library-reference-9.ts diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 506a2d5bee4..a79d365fdd4 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -337,8 +337,12 @@ namespace ts { } }, { - name: "typesRoot", - type: "string" + name: "typeRoots", + type: "list", + element: { + name: "typeRoots", + type: "string" + } }, { name: "types", diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 034bd27b147..c7052cf71fe 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1935,6 +1935,10 @@ "category": "Error", "code": 2687 }, + "Cannot find type definition file for '{0}'.": { + "category": "Error", + "code": 2688 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/src/compiler/program.ts b/src/compiler/program.ts index bab554927e7..f7750e43002 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -9,16 +9,11 @@ namespace ts { /* @internal */ export let ioWriteTime = 0; /** The version of the TypeScript compiler release */ + export const version = "1.9.0"; const emptyArray: any[] = []; - const defaultLibrarySearchPaths = [ - "types/", - "node_modules/", - "node_modules/@types/", - ]; - - export const version = "1.9.0"; + const defaultTypeRoots = ["node_modules/@types"]; export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean): string { while (true) { @@ -196,24 +191,22 @@ namespace ts { traceEnabled }; - // use typesRoot and fallback to directory that contains tsconfig or current directory if typesRoot is not set - const rootDir = options.typesRoot || (options.configFilePath ? getDirectoryPath(options.configFilePath) : (host.getCurrentDirectory && host.getCurrentDirectory())); - + const typeRoots = options.typeRoots || defaultTypeRoots; if (traceEnabled) { if (containingFile === undefined) { - if (rootDir === undefined) { + if (typeRoots === undefined) { trace(host, Diagnostics.Resolving_type_reference_directive_0_containing_file_not_set_root_directory_not_set, typeReferenceDirectiveName); } else { - trace(host, Diagnostics.Resolving_type_reference_directive_0_containing_file_not_set_root_directory_1, typeReferenceDirectiveName, rootDir); + trace(host, Diagnostics.Resolving_type_reference_directive_0_containing_file_not_set_root_directory_1, typeReferenceDirectiveName, typeRoots); } } else { - if (rootDir === undefined) { + if (typeRoots === undefined) { trace(host, Diagnostics.Resolving_type_reference_directive_0_containing_file_1_root_directory_not_set, typeReferenceDirectiveName, containingFile); } else { - trace(host, Diagnostics.Resolving_type_reference_directive_0_containing_file_1_root_directory_2, typeReferenceDirectiveName, containingFile, rootDir); + trace(host, Diagnostics.Resolving_type_reference_directive_0_containing_file_1_root_directory_2, typeReferenceDirectiveName, containingFile, typeRoots); } } } @@ -221,14 +214,13 @@ namespace ts { const failedLookupLocations: string[] = []; // Check primary library paths - if (rootDir !== undefined) { - const effectivePrimarySearchPaths = options.typesSearchPaths || defaultLibrarySearchPaths; - for (const searchPath of effectivePrimarySearchPaths) { - const primaryPath = combinePaths(rootDir, searchPath); - if (traceEnabled) { - trace(host, Diagnostics.Resolving_with_primary_search_path_0, primaryPath); - } - const candidate = combinePaths(primaryPath, typeReferenceDirectiveName); + if (typeRoots.length) { + if (traceEnabled) { + trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(', ')); + } + const primarySearchPaths = options.typeRoots || defaultTypeRoots; + for (const typeRoot of primarySearchPaths) { + const candidate = combinePaths(typeRoot, typeReferenceDirectiveName); const candidateDirectory = getDirectoryPath(candidate); const resolvedFile = loadNodeModuleFromDirectory(typeReferenceExtensions, candidate, failedLookupLocations, !directoryProbablyExists(candidateDirectory, host), moduleResolutionState); @@ -255,9 +247,6 @@ namespace ts { if (containingFile) { initialLocationForSecondaryLookup = getDirectoryPath(containingFile); } - else { - initialLocationForSecondaryLookup = rootDir; - } if (initialLocationForSecondaryLookup !== undefined) { // check secondary locations @@ -875,19 +864,6 @@ namespace ts { } } - function getDefaultTypeDirectiveNames(rootPath: string): string[] { - const localTypes = combinePaths(rootPath, "types"); - const npmTypes = combinePaths(rootPath, "node_modules/@types"); - let result: string[] = []; - if (sys.directoryExists(localTypes)) { - result = result.concat(sys.getDirectories(localTypes)); - } - if (sys.directoryExists(npmTypes)) { - result = result.concat(sys.getDirectories(npmTypes)); - } - return result; - } - function getDefaultLibLocation(): string { return getDirectoryPath(normalizePath(sys.getExecutingFilePath())); } @@ -896,7 +872,6 @@ namespace ts { const realpath = sys.realpath && ((path: string) => sys.realpath(path)); return { - getDefaultTypeDirectiveNames, getSourceFile, getDefaultLibLocation, getDefaultLibFileName: options => combinePaths(getDefaultLibLocation(), getDefaultLibFileName(options)), @@ -909,6 +884,7 @@ namespace ts { readFile: fileName => sys.readFile(fileName), trace: (s: string) => sys.write(s + newLine), directoryExists: directoryName => sys.directoryExists(directoryName), + getDirectories: (path: string) => sys.getDirectories(path), realpath }; } @@ -972,21 +948,34 @@ namespace ts { return resolutions; } - export function getDefaultTypeDirectiveNames(options: CompilerOptions, rootFiles: string[], host: CompilerHost): string[] { + function getInferredTypesRoot(options: CompilerOptions, rootFiles: string[], host: CompilerHost) { + return computeCommonSourceDirectoryOfFilenames(rootFiles, host.getCurrentDirectory(), f => host.getCanonicalFileName(f)); + } + + /** + * Given a set of options and a set of root files, returns the set of type directive names + * that should be included for this program automatically. + * This list could either come from the config file, + * or from enumerating the types root + initial secondary types lookup location. + * More type directives might appear in the program later as a result of loading actual source files; + * this list is only the set of defaults that are implicitly included. + */ + export function getAutomaticTypeDirectiveNames(options: CompilerOptions, rootFiles: string[], host: CompilerHost): string[] { // Use explicit type list from tsconfig.json if (options.types) { return options.types; } - // or load all types from the automatic type import fields - if (host && host.getDefaultTypeDirectiveNames) { - const commonRoot = computeCommonSourceDirectoryOfFilenames(rootFiles, host.getCurrentDirectory(), f => host.getCanonicalFileName(f)); - if (commonRoot) { - return host.getDefaultTypeDirectiveNames(commonRoot); + // Walk the primary type lookup locations + let result: string[] = []; + if (host.directoryExists && host.getDirectories) { + for (const root of options.typeRoots || defaultTypeRoots) { + if (host.directoryExists(root)) { + result = result.concat(host.getDirectories(root)); + } } } - - return undefined; + return result; } export function createProgram(rootNames: string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program): Program { @@ -1038,11 +1027,13 @@ namespace ts { if (!tryReuseStructureFromOldProgram()) { forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false)); - // load type declarations specified via 'types' argument - const typeReferences: string[] = getDefaultTypeDirectiveNames(options, rootNames, host); + // load type declarations specified via 'types' argument or implicitly from types/ and node_modules/@types folders + const typeReferences: string[] = getAutomaticTypeDirectiveNames(options, rootNames, host); if (typeReferences) { - const resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, /*containingFile*/ undefined); + const inferredRoot = getInferredTypesRoot(options, rootNames, host); + const containingFilename = combinePaths(inferredRoot, "__inferred type names__.ts"); + const resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, containingFilename); for (let i = 0; i < typeReferences.length; i++) { processTypeReferenceDirective(typeReferences[i], resolutions[i]); } @@ -1149,10 +1140,9 @@ namespace ts { (oldOptions.jsx !== options.jsx) || (oldOptions.allowJs !== options.allowJs) || (oldOptions.rootDir !== options.rootDir) || - (oldOptions.typesSearchPaths !== options.typesSearchPaths) || (oldOptions.configFilePath !== options.configFilePath) || (oldOptions.baseUrl !== options.baseUrl) || - (oldOptions.typesRoot !== options.typesRoot) || + (oldOptions.typeRoots !== options.typeRoots) || !arrayIsEqualTo(oldOptions.rootDirs, options.rootDirs) || !mapIsEqualTo(oldOptions.paths, options.paths)) { return false; @@ -1904,7 +1894,7 @@ namespace ts { } } else { - fileProcessingDiagnostics.add(createDiagnostic(refFile, refPos, refEnd, Diagnostics.Cannot_find_name_0, typeReferenceDirective)); + fileProcessingDiagnostics.add(createDiagnostic(refFile, refPos, refEnd, Diagnostics.Cannot_find_type_definition_file_for_0, typeReferenceDirective)); } if (saveResolution) { diff --git a/src/compiler/types.ts b/src/compiler/types.ts index a86b1ed708d..7f53ac29eaf 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2496,7 +2496,6 @@ namespace ts { jsx?: JsxEmit; reactNamespace?: string; listFiles?: boolean; - typesSearchPaths?: string[]; locale?: string; mapRoot?: string; module?: ModuleKind; @@ -2555,8 +2554,8 @@ namespace ts { // When options come from a config file, its path is recorded here configFilePath?: string; /* @internal */ - // Path used to used to compute primary search locations - typesRoot?: string; + // Paths used to used to compute primary types search locations + typeRoots?: string[]; types?: string[]; list?: string[]; @@ -2861,9 +2860,9 @@ namespace ts { getCancellationToken?(): CancellationToken; getDefaultLibFileName(options: CompilerOptions): string; getDefaultLibLocation?(): string; - getDefaultTypeDirectiveNames?(rootPath: string): string[]; writeFile: WriteFileCallback; getCurrentDirectory(): string; + getDirectories(path: string): string[]; getCanonicalFileName(fileName: string): string; useCaseSensitiveFileNames(): boolean; getNewLine(): string; diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index c05fca5bb47..8104f113392 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -246,8 +246,8 @@ namespace FourSlash { // Create a new Services Adapter this.cancellationToken = new TestCancellationToken(); const compilationOptions = convertGlobalOptionsToCompilerOptions(this.testData.globalOptions); - if (compilationOptions.typesRoot) { - compilationOptions.typesRoot = ts.getNormalizedAbsolutePath(compilationOptions.typesRoot, this.basePath); + if (compilationOptions.typeRoots) { + compilationOptions.typeRoots = compilationOptions.typeRoots.map(p => ts.getNormalizedAbsolutePath(p, this.basePath)); } const languageServiceAdapter = this.getLanguageServiceAdapter(testType, this.cancellationToken, compilationOptions); diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 5fe5b84ac91..37066abd9bd 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -432,6 +432,7 @@ namespace Harness { readFile(path: string): string; writeFile(path: string, contents: string): void; directoryName(path: string): string; + getDirectories(path: string): string[]; createDirectory(path: string): void; fileExists(fileName: string): boolean; directoryExists(path: string): boolean; @@ -477,6 +478,7 @@ namespace Harness { export const readFile: typeof IO.readFile = path => ts.sys.readFile(path); export const writeFile: typeof IO.writeFile = (path, content) => ts.sys.writeFile(path, content); export const directoryName: typeof IO.directoryName = fso.GetParentFolderName; + export const getDirectories: typeof IO.getDirectories = dir => ts.sys.getDirectories(dir); export const directoryExists: typeof IO.directoryExists = fso.FolderExists; export const fileExists: typeof IO.fileExists = fso.FileExists; export const log: typeof IO.log = global.WScript && global.WScript.StdOut.WriteLine; @@ -543,6 +545,7 @@ namespace Harness { export const args = () => ts.sys.args; export const getExecutingFilePath = () => ts.sys.getExecutingFilePath(); export const exit = (exitCode: number) => ts.sys.exit(exitCode); + export const getDirectories: typeof IO.getDirectories = path => ts.sys.getDirectories(path); export const readFile: typeof IO.readFile = path => ts.sys.readFile(path); export const writeFile: typeof IO.writeFile = (path, content) => ts.sys.writeFile(path, content); @@ -616,6 +619,7 @@ namespace Harness { export const args = () => []; export const getExecutingFilePath = () => ""; export const exit = (exitCode: number) => { }; + export const getDirectories = () => []; export let log = (s: string) => console.log(s); @@ -861,7 +865,7 @@ namespace Harness { // Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames const getCanonicalFileName = ts.createGetCanonicalFileName(useCaseSensitiveFileNames); - let realPathMap: ts.FileMap; + const realPathMap: ts.FileMap = ts.createFileMap(); const fileMap: ts.FileMap<() => ts.SourceFile> = ts.createFileMap<() => ts.SourceFile>(); for (const file of inputFiles) { if (file.content !== undefined) { @@ -870,9 +874,6 @@ namespace Harness { if (file.fileOptions && file.fileOptions["symlink"]) { const link = file.fileOptions["symlink"]; const linkPath = ts.toPath(link, currentDirectory, getCanonicalFileName); - if (!realPathMap) { - realPathMap = ts.createFileMap(); - } realPathMap.set(linkPath, fileName); fileMap.set(path, (): ts.SourceFile => { throw new Error("Symlinks should always be resolved to a realpath first"); }); } @@ -906,20 +907,6 @@ namespace Harness { return { - getDefaultTypeDirectiveNames: (path: string) => { - const results: string[] = []; - fileMap.forEachValue((key, value) => { - const rx = /node_modules\/@types\/(\w+)/; - const typeNameResult = rx.exec(key); - if (typeNameResult) { - const typeName = typeNameResult[1]; - if (results.indexOf(typeName) < 0) { - results.push(typeName); - } - } - }); - return results; - }, getCurrentDirectory: () => currentDirectory, getSourceFile, getDefaultLibFileName, @@ -937,7 +924,37 @@ namespace Harness { realpath: realPathMap && ((f: string) => { const path = ts.toPath(f, currentDirectory, getCanonicalFileName); return realPathMap.contains(path) ? realPathMap.get(path) : path; - }) + }), + directoryExists: dir => { + let path = ts.toPath(dir, currentDirectory, getCanonicalFileName); + // Strip trailing /, which may exist if the path is a drive root + if (path[path.length - 1] === "/") { + path = path.substr(0, path.length - 1); + } + let exists = false; + fileMap.forEachValue(key => { + if (key.indexOf(path) === 0 && key[path.length] === "/") { + exists = true; + } + }); + return exists; + }, + getDirectories: d => { + const path = ts.toPath(d, currentDirectory, getCanonicalFileName); + const result: string[] = []; + fileMap.forEachValue((key, value) => { + if (key.indexOf(path) === 0 && key.lastIndexOf("/") > path.length) { + let dirName = key.substr(path.length, key.indexOf("/", path.length + 1) - path.length); + if (dirName[0] === "/") { + dirName = dirName.substr(1); + } + if (result.indexOf(dirName) < 0) { + result.push(dirName); + } + } + }); + return result; + } }; } @@ -1036,7 +1053,9 @@ namespace Harness { options.noErrorTruncation = true; options.skipDefaultLibCheck = true; - currentDirectory = currentDirectory || Harness.IO.getCurrentDirectory(); + if (typeof currentDirectory === "undefined") { + currentDirectory = Harness.IO.getCurrentDirectory(); + } // Parse settings if (harnessSettings) { diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index b3478e40609..c9d31447df7 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -246,16 +246,21 @@ namespace Harness.LanguageService { }; this.getTypeReferenceDirectiveResolutionsForFile = (fileName) => { const scriptInfo = this.getScriptInfo(fileName); - const preprocessInfo = ts.preProcessFile(scriptInfo.content, /*readImportFiles*/ false); - const resolutions: ts.Map = {}; - const settings = this.nativeHost.getCompilationSettings(); - for (const typeReferenceDirective of preprocessInfo.typeReferenceDirectives) { - const resolutionInfo = ts.resolveTypeReferenceDirective(typeReferenceDirective.fileName, fileName, settings, moduleResolutionHost); - if (resolutionInfo.resolvedTypeReferenceDirective.resolvedFileName) { - resolutions[typeReferenceDirective.fileName] = resolutionInfo.resolvedTypeReferenceDirective; + if (scriptInfo) { + const preprocessInfo = ts.preProcessFile(scriptInfo.content, /*readImportFiles*/ false); + const resolutions: ts.Map = {}; + const settings = this.nativeHost.getCompilationSettings(); + for (const typeReferenceDirective of preprocessInfo.typeReferenceDirectives) { + const resolutionInfo = ts.resolveTypeReferenceDirective(typeReferenceDirective.fileName, fileName, settings, moduleResolutionHost); + if (resolutionInfo.resolvedTypeReferenceDirective.resolvedFileName) { + resolutions[typeReferenceDirective.fileName] = resolutionInfo.resolvedTypeReferenceDirective; + } } + return JSON.stringify(resolutions); + } + else { + return "[]"; } - return JSON.stringify(resolutions); }; } } diff --git a/src/harness/projectsRunner.ts b/src/harness/projectsRunner.ts index 64d07b1d88a..6bf73ecced7 100644 --- a/src/harness/projectsRunner.ts +++ b/src/harness/projectsRunner.ts @@ -185,7 +185,8 @@ class ProjectRunner extends RunnerBase { useCaseSensitiveFileNames: () => Harness.IO.useCaseSensitiveFileNames(), getNewLine: () => Harness.IO.newLine(), fileExists: fileName => fileName === Harness.Compiler.defaultLibFileName || getSourceFileText(fileName) !== undefined, - readFile: fileName => Harness.IO.readFile(fileName) + readFile: fileName => Harness.IO.readFile(fileName), + getDirectories: path => Harness.IO.getDirectories(path) }; } } diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 8eae43b503d..a53e9b3d5a0 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -315,6 +315,10 @@ namespace ts.server { return this.host.directoryExists(path); } + getDirectories(path: string): string[] { + return this.host.getDirectories ? this.host.getDirectories(path) : []; + } + /** * @param line 1 based index */ diff --git a/src/services/services.ts b/src/services/services.ts index 34b521b3496..10d9f9e48ef 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1058,6 +1058,7 @@ namespace ts { resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[]; resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[]; directoryExists?(directoryName: string): boolean; + getDirectories?(directoryName: string): string[]; } // @@ -1983,7 +1984,8 @@ namespace ts { getNewLine: () => newLine, fileExists: (fileName): boolean => fileName === inputFileName, readFile: (fileName): string => "", - directoryExists: directoryExists => true + directoryExists: directoryExists => true, + getDirectories: (path: string) => [] }; const program = createProgram([inputFileName], options, compilerHost); @@ -2086,7 +2088,7 @@ namespace ts { const getCanonicalFileName = createGetCanonicalFileName(!!useCaseSensitiveFileNames); function getKeyForCompilationSettings(settings: CompilerOptions): DocumentRegistryBucketKey { - return `_${settings.target}|${settings.module}|${settings.noResolve}|${settings.jsx}|${settings.allowJs}|${settings.baseUrl}|${settings.typesRoot}|${settings.typesSearchPaths}|${JSON.stringify(settings.rootDirs)}|${JSON.stringify(settings.paths)}`; + return `_${settings.target}|${settings.module}|${settings.noResolve}|${settings.jsx}|${settings.allowJs}|${settings.baseUrl}|${settings.typeRoots}|${JSON.stringify(settings.rootDirs)}|${JSON.stringify(settings.paths)}`; } function getBucketForCompilationSettings(key: DocumentRegistryBucketKey, createIfMissing: boolean): FileMap { @@ -2945,8 +2947,10 @@ namespace ts { return entry && entry.scriptSnapshot.getText(0, entry.scriptSnapshot.getLength()); }, directoryExists: directoryName => { - Debug.assert(!host.resolveModuleNames || !host.resolveTypeReferenceDirectives); return directoryProbablyExists(directoryName, host); + }, + getDirectories: path => { + return host.getDirectories ? host.getDirectories(path) : []; } }; if (host.trace) { diff --git a/tests/baselines/reference/commonSourceDir5.js b/tests/baselines/reference/commonSourceDir5.js index 7a43aba254e..1e404b26e13 100644 --- a/tests/baselines/reference/commonSourceDir5.js +++ b/tests/baselines/reference/commonSourceDir5.js @@ -1,6 +1,7 @@ //// [tests/cases/compiler/commonSourceDir5.ts] //// //// [bar.ts] + import {z} from "./foo"; export var x = z + z; diff --git a/tests/baselines/reference/commonSourceDir5.symbols b/tests/baselines/reference/commonSourceDir5.symbols index 6426ac39de3..67494af40fa 100644 --- a/tests/baselines/reference/commonSourceDir5.symbols +++ b/tests/baselines/reference/commonSourceDir5.symbols @@ -1,11 +1,12 @@ === A:/bar.ts === + import {z} from "./foo"; ->z : Symbol(z, Decl(bar.ts, 0, 8)) +>z : Symbol(z, Decl(bar.ts, 1, 8)) export var x = z + z; ->x : Symbol(x, Decl(bar.ts, 1, 10)) ->z : Symbol(z, Decl(bar.ts, 0, 8)) ->z : Symbol(z, Decl(bar.ts, 0, 8)) +>x : Symbol(x, Decl(bar.ts, 2, 10)) +>z : Symbol(z, Decl(bar.ts, 1, 8)) +>z : Symbol(z, Decl(bar.ts, 1, 8)) === A:/foo.ts === import {pi} from "B:/baz"; diff --git a/tests/baselines/reference/commonSourceDir5.types b/tests/baselines/reference/commonSourceDir5.types index ff13bb20215..dd72099d542 100644 --- a/tests/baselines/reference/commonSourceDir5.types +++ b/tests/baselines/reference/commonSourceDir5.types @@ -1,4 +1,5 @@ === A:/bar.ts === + import {z} from "./foo"; >z : number diff --git a/tests/baselines/reference/library-reference-1.symbols b/tests/baselines/reference/library-reference-1.symbols index 0e848c626c5..14a6b115009 100644 --- a/tests/baselines/reference/library-reference-1.symbols +++ b/tests/baselines/reference/library-reference-1.symbols @@ -1,11 +1,11 @@ -=== /consumer.ts === +=== /src/consumer.ts === /// $.foo(); >$.foo : Symbol(foo, Decl(index.d.ts, 3, 16)) >$ : Symbol($, Decl(index.d.ts, 3, 11)) >foo : Symbol(foo, Decl(index.d.ts, 3, 16)) -=== /types/jquery/index.d.ts === +=== /src/types/jquery/index.d.ts === // We can find typings in the ./types folder diff --git a/tests/baselines/reference/library-reference-1.trace.json b/tests/baselines/reference/library-reference-1.trace.json index 1b8c237dff1..71557236240 100644 --- a/tests/baselines/reference/library-reference-1.trace.json +++ b/tests/baselines/reference/library-reference-1.trace.json @@ -1,7 +1,12 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/consumer.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", - "File '/types/jquery/package.json' does not exist.", - "File '/types/jquery/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'jquery' was successfully resolved to '/types/jquery/index.d.ts', primary: true. ========" + "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory 'types'. ========", + "Resolving with primary search path 'types'", + "File 'types/jquery/package.json' does not exist.", + "File 'types/jquery/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'jquery' was successfully resolved to 'types/jquery/index.d.ts', primary: true. ========", + "======== Resolving type reference directive 'jquery', containing file '/src/__inferred type names__.ts', root directory 'types'. ========", + "Resolving with primary search path 'types'", + "File 'types/jquery/package.json' does not exist.", + "File 'types/jquery/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'jquery' was successfully resolved to 'types/jquery/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-1.types b/tests/baselines/reference/library-reference-1.types index 99133f2f8df..c247e94617e 100644 --- a/tests/baselines/reference/library-reference-1.types +++ b/tests/baselines/reference/library-reference-1.types @@ -1,4 +1,4 @@ -=== /consumer.ts === +=== /src/consumer.ts === /// $.foo(); >$.foo() : void @@ -6,7 +6,7 @@ $.foo(); >$ : { foo(): void; } >foo : () => void -=== /types/jquery/index.d.ts === +=== /src/types/jquery/index.d.ts === // We can find typings in the ./types folder diff --git a/tests/baselines/reference/library-reference-10.symbols b/tests/baselines/reference/library-reference-10.symbols index 9d0f7e4781e..50159b4bfc3 100644 --- a/tests/baselines/reference/library-reference-10.symbols +++ b/tests/baselines/reference/library-reference-10.symbols @@ -1,11 +1,11 @@ -=== /consumer.ts === +=== /foo/consumer.ts === /// $.foo(); >$.foo : Symbol(foo, Decl(jquery.d.ts, 0, 16)) >$ : Symbol($, Decl(jquery.d.ts, 0, 11)) >foo : Symbol(foo, Decl(jquery.d.ts, 0, 16)) -=== /types/jquery/jquery.d.ts === +=== /foo/types/jquery/jquery.d.ts === declare var $: { foo(): void }; >$ : Symbol($, Decl(jquery.d.ts, 0, 11)) >foo : Symbol(foo, Decl(jquery.d.ts, 0, 16)) diff --git a/tests/baselines/reference/library-reference-10.trace.json b/tests/baselines/reference/library-reference-10.trace.json index e6a1918a446..f4df00fa52d 100644 --- a/tests/baselines/reference/library-reference-10.trace.json +++ b/tests/baselines/reference/library-reference-10.trace.json @@ -1,8 +1,14 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/consumer.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", - "Found 'package.json' at '/types/jquery/package.json'.", - "'package.json' has 'typings' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.", - "File '/types/jquery/jquery.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'jquery' was successfully resolved to '/types/jquery/jquery.d.ts', primary: true. ========" + "======== Resolving type reference directive 'jquery', containing file '/foo/consumer.ts', root directory './types'. ========", + "Resolving with primary search path './types'", + "Found 'package.json' at './types/jquery/package.json'.", + "'package.json' has 'typings' field 'jquery.d.ts' that references 'types/jquery/jquery.d.ts'.", + "File 'types/jquery/jquery.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'jquery' was successfully resolved to 'types/jquery/jquery.d.ts', primary: true. ========", + "======== Resolving type reference directive 'jquery', containing file '/foo/__inferred type names__.ts', root directory './types'. ========", + "Resolving with primary search path './types'", + "Found 'package.json' at './types/jquery/package.json'.", + "'package.json' has 'typings' field 'jquery.d.ts' that references 'types/jquery/jquery.d.ts'.", + "File 'types/jquery/jquery.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'jquery' was successfully resolved to 'types/jquery/jquery.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-10.types b/tests/baselines/reference/library-reference-10.types index 42d78f72865..ca588d0bc03 100644 --- a/tests/baselines/reference/library-reference-10.types +++ b/tests/baselines/reference/library-reference-10.types @@ -1,4 +1,4 @@ -=== /consumer.ts === +=== /foo/consumer.ts === /// $.foo(); >$.foo() : void @@ -6,7 +6,7 @@ $.foo(); >$ : { foo(): void; } >foo : () => void -=== /types/jquery/jquery.d.ts === +=== /foo/types/jquery/jquery.d.ts === declare var $: { foo(): void }; >$ : { foo(): void; } >foo : () => void diff --git a/tests/baselines/reference/library-reference-11.trace.json b/tests/baselines/reference/library-reference-11.trace.json index 62d828d57d6..7f6a32a0b23 100644 --- a/tests/baselines/reference/library-reference-11.trace.json +++ b/tests/baselines/reference/library-reference-11.trace.json @@ -1,14 +1,8 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", - "File '/types/jquery/package.json' does not exist.", - "File '/types/jquery/index.d.ts' does not exist.", - "Resolving with primary search path '/node_modules/'", - "File '/node_modules/jquery/package.json' does not exist.", - "File '/node_modules/jquery/index.d.ts' does not exist.", - "Resolving with primary search path '/node_modules/@types/'", - "File '/node_modules/@types/jquery/package.json' does not exist.", - "File '/node_modules/@types/jquery/index.d.ts' does not exist.", + "======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory 'node_modules/@types'. ========", + "Resolving with primary search path 'node_modules/@types'", + "File 'node_modules/@types/jquery/package.json' does not exist.", + "File 'node_modules/@types/jquery/index.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/a/b'", "File '/a/b/node_modules/jquery.ts' does not exist.", "File '/a/b/node_modules/jquery.d.ts' does not exist.", diff --git a/tests/baselines/reference/library-reference-12.trace.json b/tests/baselines/reference/library-reference-12.trace.json index abe1f6c0f46..b3debaec9d6 100644 --- a/tests/baselines/reference/library-reference-12.trace.json +++ b/tests/baselines/reference/library-reference-12.trace.json @@ -1,14 +1,8 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", - "File '/types/jquery/package.json' does not exist.", - "File '/types/jquery/index.d.ts' does not exist.", - "Resolving with primary search path '/node_modules/'", - "File '/node_modules/jquery/package.json' does not exist.", - "File '/node_modules/jquery/index.d.ts' does not exist.", - "Resolving with primary search path '/node_modules/@types/'", - "File '/node_modules/@types/jquery/package.json' does not exist.", - "File '/node_modules/@types/jquery/index.d.ts' does not exist.", + "======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory 'node_modules/@types'. ========", + "Resolving with primary search path 'node_modules/@types'", + "File 'node_modules/@types/jquery/package.json' does not exist.", + "File 'node_modules/@types/jquery/index.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/a/b'", "File '/a/b/node_modules/jquery.ts' does not exist.", "File '/a/b/node_modules/jquery.d.ts' does not exist.", diff --git a/tests/baselines/reference/library-reference-13.trace.json b/tests/baselines/reference/library-reference-13.trace.json index 2133414f414..d8dfb57c2a6 100644 --- a/tests/baselines/reference/library-reference-13.trace.json +++ b/tests/baselines/reference/library-reference-13.trace.json @@ -1,6 +1,6 @@ [ - "======== Resolving type reference directive 'jquery', containing file not set, root directory '/a'. ========", - "Resolving with primary search path '/a/types/'", + "======== Resolving type reference directive 'jquery', containing file '/a/b/__inferred type names__.ts', root directory '/a/types'. ========", + "Resolving with primary search path '/a/types'", "File '/a/types/jquery/package.json' does not exist.", "File '/a/types/jquery/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'jquery' was successfully resolved to '/a/types/jquery/index.d.ts', primary: true. ========" diff --git a/tests/baselines/reference/library-reference-14.trace.json b/tests/baselines/reference/library-reference-14.trace.json index 2133414f414..d8dfb57c2a6 100644 --- a/tests/baselines/reference/library-reference-14.trace.json +++ b/tests/baselines/reference/library-reference-14.trace.json @@ -1,6 +1,6 @@ [ - "======== Resolving type reference directive 'jquery', containing file not set, root directory '/a'. ========", - "Resolving with primary search path '/a/types/'", + "======== Resolving type reference directive 'jquery', containing file '/a/b/__inferred type names__.ts', root directory '/a/types'. ========", + "Resolving with primary search path '/a/types'", "File '/a/types/jquery/package.json' does not exist.", "File '/a/types/jquery/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'jquery' was successfully resolved to '/a/types/jquery/index.d.ts', primary: true. ========" diff --git a/tests/baselines/reference/library-reference-15.errors.txt b/tests/baselines/reference/library-reference-15.errors.txt index a311633ca76..9586ba8bc72 100644 --- a/tests/baselines/reference/library-reference-15.errors.txt +++ b/tests/baselines/reference/library-reference-15.errors.txt @@ -1,15 +1,15 @@ -error TS2304: Cannot find name 'jquery'. -/a/b/consumer.ts(1,1): error TS2304: Cannot find name '$'. +/a/b/consumer.ts(2,1): error TS2304: Cannot find name '$2'. -!!! error TS2304: Cannot find name 'jquery'. ==== /a/b/consumer.ts (1 errors) ==== - $.foo(); - ~ -!!! error TS2304: Cannot find name '$'. - + $.foo(); // should OK + $2.foo(); // should error + ~~ +!!! error TS2304: Cannot find name '$2'. ==== /a/types/jquery/index.d.ts (0 errors) ==== declare var $: { foo(): void }; +==== /a/types/jquery2/index.d.ts (0 errors) ==== + declare var $2: { foo(): void }; \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-15.js b/tests/baselines/reference/library-reference-15.js index f9aa7038d53..c1caa0c45e7 100644 --- a/tests/baselines/reference/library-reference-15.js +++ b/tests/baselines/reference/library-reference-15.js @@ -3,11 +3,14 @@ //// [index.d.ts] declare var $: { foo(): void }; - + +//// [index.d.ts] +declare var $2: { foo(): void }; //// [consumer.ts] -$.foo(); - +$.foo(); // should OK +$2.foo(); // should error //// [consumer.js] -$.foo(); +$.foo(); // should OK +$2.foo(); // should error diff --git a/tests/baselines/reference/library-reference-15.trace.json b/tests/baselines/reference/library-reference-15.trace.json index b8029a0b61f..3e9d7dba1d2 100644 --- a/tests/baselines/reference/library-reference-15.trace.json +++ b/tests/baselines/reference/library-reference-15.trace.json @@ -1,24 +1,7 @@ [ - "======== Resolving type reference directive 'jquery', containing file not set, root directory '/'. ========", - "Resolving with primary search path '/types/'", - "File '/types/jquery/package.json' does not exist.", - "File '/types/jquery/index.d.ts' does not exist.", - "Resolving with primary search path '/node_modules/'", - "File '/node_modules/jquery/package.json' does not exist.", - "File '/node_modules/jquery/index.d.ts' does not exist.", - "Resolving with primary search path '/node_modules/@types/'", - "File '/node_modules/@types/jquery/package.json' does not exist.", - "File '/node_modules/@types/jquery/index.d.ts' does not exist.", - "Looking up in 'node_modules' folder, initial location '/'", - "File '/node_modules/jquery.ts' does not exist.", - "File '/node_modules/jquery.d.ts' does not exist.", - "File '/node_modules/jquery/package.json' does not exist.", - "File '/node_modules/jquery/index.ts' does not exist.", - "File '/node_modules/jquery/index.d.ts' does not exist.", - "File '/node_modules/@types/jquery.ts' does not exist.", - "File '/node_modules/@types/jquery.d.ts' does not exist.", - "File '/node_modules/@types/jquery/package.json' does not exist.", - "File '/node_modules/@types/jquery/index.ts' does not exist.", - "File '/node_modules/@types/jquery/index.d.ts' does not exist.", - "======== Type reference directive 'jquery' was not resolved. ========" + "======== Resolving type reference directive 'jquery', containing file '/a/b/__inferred type names__.ts', root directory 'types'. ========", + "Resolving with primary search path 'types'", + "File 'types/jquery/package.json' does not exist.", + "File 'types/jquery/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'jquery' was successfully resolved to 'types/jquery/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-2.trace.json b/tests/baselines/reference/library-reference-2.trace.json index b5ef5f3e208..c26f7d2763d 100644 --- a/tests/baselines/reference/library-reference-2.trace.json +++ b/tests/baselines/reference/library-reference-2.trace.json @@ -1,6 +1,12 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/consumer.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", + "======== Resolving type reference directive 'jquery', containing file '/consumer.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", + "Found 'package.json' at '/types/jquery/package.json'.", + "'package.json' has 'types' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.", + "File '/types/jquery/jquery.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'jquery' was successfully resolved to '/types/jquery/jquery.d.ts', primary: true. ========", + "======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", "Found 'package.json' at '/types/jquery/package.json'.", "'package.json' has 'types' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.", "File '/types/jquery/jquery.d.ts' exist - use it as a name resolution result.", diff --git a/tests/baselines/reference/library-reference-3.trace.json b/tests/baselines/reference/library-reference-3.trace.json index 30dbbc3fca4..909e42140c8 100644 --- a/tests/baselines/reference/library-reference-3.trace.json +++ b/tests/baselines/reference/library-reference-3.trace.json @@ -1,10 +1,13 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory '/src'. ========", - "Resolving with primary search path '/src/types/'", - "File '/src/types/jquery/package.json' does not exist.", - "File '/src/types/jquery/index.d.ts' does not exist.", - "Resolving with primary search path '/src/node_modules/'", + "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory 'node_modules/@types'. ========", + "Resolving with primary search path 'node_modules/@types'", + "File 'node_modules/@types/jquery/package.json' does not exist.", + "File 'node_modules/@types/jquery/index.d.ts' does not exist.", + "Looking up in 'node_modules' folder, initial location '/src'", + "File '/src/node_modules/jquery.ts' does not exist.", + "File '/src/node_modules/jquery.d.ts' does not exist.", "File '/src/node_modules/jquery/package.json' does not exist.", + "File '/src/node_modules/jquery/index.ts' does not exist.", "File '/src/node_modules/jquery/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'jquery' was successfully resolved to '/src/node_modules/jquery/index.d.ts', primary: true. ========" + "======== Type reference directive 'jquery' was successfully resolved to '/src/node_modules/jquery/index.d.ts', primary: false. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-4.trace.json b/tests/baselines/reference/library-reference-4.trace.json index 90b6eb7b01d..5df7320d322 100644 --- a/tests/baselines/reference/library-reference-4.trace.json +++ b/tests/baselines/reference/library-reference-4.trace.json @@ -1,14 +1,8 @@ [ "======== Resolving type reference directive 'foo', containing file '/src/root.ts', root directory '/src'. ========", - "Resolving with primary search path '/src/types/'", - "File '/src/types/foo/package.json' does not exist.", - "File '/src/types/foo/index.d.ts' does not exist.", - "Resolving with primary search path '/src/node_modules/'", - "File '/src/node_modules/foo/package.json' does not exist.", - "File '/src/node_modules/foo/index.d.ts' does not exist.", - "Resolving with primary search path '/src/node_modules/@types/'", - "File '/src/node_modules/@types/foo/package.json' does not exist.", - "File '/src/node_modules/@types/foo/index.d.ts' does not exist.", + "Resolving with primary search path '/src'", + "File '/src/foo/package.json' does not exist.", + "File '/src/foo/index.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/src'", "File '/src/node_modules/foo.ts' does not exist.", "File '/src/node_modules/foo.d.ts' does not exist.", @@ -27,15 +21,9 @@ "File '/node_modules/foo/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'foo' was successfully resolved to '/node_modules/foo/index.d.ts', primary: false. ========", "======== Resolving type reference directive 'bar', containing file '/src/root.ts', root directory '/src'. ========", - "Resolving with primary search path '/src/types/'", - "File '/src/types/bar/package.json' does not exist.", - "File '/src/types/bar/index.d.ts' does not exist.", - "Resolving with primary search path '/src/node_modules/'", - "File '/src/node_modules/bar/package.json' does not exist.", - "File '/src/node_modules/bar/index.d.ts' does not exist.", - "Resolving with primary search path '/src/node_modules/@types/'", - "File '/src/node_modules/@types/bar/package.json' does not exist.", - "File '/src/node_modules/@types/bar/index.d.ts' does not exist.", + "Resolving with primary search path '/src'", + "File '/src/bar/package.json' does not exist.", + "File '/src/bar/index.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/src'", "File '/src/node_modules/bar.ts' does not exist.", "File '/src/node_modules/bar.d.ts' does not exist.", @@ -54,15 +42,9 @@ "File '/node_modules/bar/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'bar' was successfully resolved to '/node_modules/bar/index.d.ts', primary: false. ========", "======== Resolving type reference directive 'alpha', containing file '/node_modules/foo/index.d.ts', root directory '/src'. ========", - "Resolving with primary search path '/src/types/'", - "File '/src/types/alpha/package.json' does not exist.", - "File '/src/types/alpha/index.d.ts' does not exist.", - "Resolving with primary search path '/src/node_modules/'", - "File '/src/node_modules/alpha/package.json' does not exist.", - "File '/src/node_modules/alpha/index.d.ts' does not exist.", - "Resolving with primary search path '/src/node_modules/@types/'", - "File '/src/node_modules/@types/alpha/package.json' does not exist.", - "File '/src/node_modules/@types/alpha/index.d.ts' does not exist.", + "Resolving with primary search path '/src'", + "File '/src/alpha/package.json' does not exist.", + "File '/src/alpha/index.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/node_modules/foo'", "File '/node_modules/foo/node_modules/alpha.ts' does not exist.", "File '/node_modules/foo/node_modules/alpha.d.ts' does not exist.", @@ -71,15 +53,9 @@ "File '/node_modules/foo/node_modules/alpha/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'alpha' was successfully resolved to '/node_modules/foo/node_modules/alpha/index.d.ts', primary: false. ========", "======== Resolving type reference directive 'alpha', containing file '/node_modules/bar/index.d.ts', root directory '/src'. ========", - "Resolving with primary search path '/src/types/'", - "File '/src/types/alpha/package.json' does not exist.", - "File '/src/types/alpha/index.d.ts' does not exist.", - "Resolving with primary search path '/src/node_modules/'", - "File '/src/node_modules/alpha/package.json' does not exist.", - "File '/src/node_modules/alpha/index.d.ts' does not exist.", - "Resolving with primary search path '/src/node_modules/@types/'", - "File '/src/node_modules/@types/alpha/package.json' does not exist.", - "File '/src/node_modules/@types/alpha/index.d.ts' does not exist.", + "Resolving with primary search path '/src'", + "File '/src/alpha/package.json' does not exist.", + "File '/src/alpha/index.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/node_modules/bar'", "File '/node_modules/bar/node_modules/alpha.ts' does not exist.", "File '/node_modules/bar/node_modules/alpha.d.ts' does not exist.", diff --git a/tests/baselines/reference/library-reference-5.trace.json b/tests/baselines/reference/library-reference-5.trace.json index ad34e9e3159..9b8705f0323 100644 --- a/tests/baselines/reference/library-reference-5.trace.json +++ b/tests/baselines/reference/library-reference-5.trace.json @@ -1,30 +1,50 @@ [ - "======== Resolving type reference directive 'foo', containing file '/src/root.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", - "File '/types/foo/package.json' does not exist.", - "File '/types/foo/index.d.ts' does not exist.", - "Resolving with primary search path '/node_modules/'", + "======== Resolving type reference directive 'foo', containing file '/src/root.ts', root directory 'types'. ========", + "Resolving with primary search path 'types'", + "File 'types/foo/package.json' does not exist.", + "File 'types/foo/index.d.ts' does not exist.", + "Looking up in 'node_modules' folder, initial location '/src'", + "File '/src/node_modules/foo.ts' does not exist.", + "File '/src/node_modules/foo.d.ts' does not exist.", + "File '/src/node_modules/foo/package.json' does not exist.", + "File '/src/node_modules/foo/index.ts' does not exist.", + "File '/src/node_modules/foo/index.d.ts' does not exist.", + "File '/src/node_modules/@types/foo.ts' does not exist.", + "File '/src/node_modules/@types/foo.d.ts' does not exist.", + "File '/src/node_modules/@types/foo/package.json' does not exist.", + "File '/src/node_modules/@types/foo/index.ts' does not exist.", + "File '/src/node_modules/@types/foo/index.d.ts' does not exist.", + "File '/node_modules/foo.ts' does not exist.", + "File '/node_modules/foo.d.ts' does not exist.", "File '/node_modules/foo/package.json' does not exist.", + "File '/node_modules/foo/index.ts' does not exist.", "File '/node_modules/foo/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'foo' was successfully resolved to '/node_modules/foo/index.d.ts', primary: true. ========", - "======== Resolving type reference directive 'bar', containing file '/src/root.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", - "File '/types/bar/package.json' does not exist.", - "File '/types/bar/index.d.ts' does not exist.", - "Resolving with primary search path '/node_modules/'", + "======== Type reference directive 'foo' was successfully resolved to '/node_modules/foo/index.d.ts', primary: false. ========", + "======== Resolving type reference directive 'bar', containing file '/src/root.ts', root directory 'types'. ========", + "Resolving with primary search path 'types'", + "File 'types/bar/package.json' does not exist.", + "File 'types/bar/index.d.ts' does not exist.", + "Looking up in 'node_modules' folder, initial location '/src'", + "File '/src/node_modules/bar.ts' does not exist.", + "File '/src/node_modules/bar.d.ts' does not exist.", + "File '/src/node_modules/bar/package.json' does not exist.", + "File '/src/node_modules/bar/index.ts' does not exist.", + "File '/src/node_modules/bar/index.d.ts' does not exist.", + "File '/src/node_modules/@types/bar.ts' does not exist.", + "File '/src/node_modules/@types/bar.d.ts' does not exist.", + "File '/src/node_modules/@types/bar/package.json' does not exist.", + "File '/src/node_modules/@types/bar/index.ts' does not exist.", + "File '/src/node_modules/@types/bar/index.d.ts' does not exist.", + "File '/node_modules/bar.ts' does not exist.", + "File '/node_modules/bar.d.ts' does not exist.", "File '/node_modules/bar/package.json' does not exist.", + "File '/node_modules/bar/index.ts' does not exist.", "File '/node_modules/bar/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'bar' was successfully resolved to '/node_modules/bar/index.d.ts', primary: true. ========", - "======== Resolving type reference directive 'alpha', containing file '/node_modules/foo/index.d.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", - "File '/types/alpha/package.json' does not exist.", - "File '/types/alpha/index.d.ts' does not exist.", - "Resolving with primary search path '/node_modules/'", - "File '/node_modules/alpha/package.json' does not exist.", - "File '/node_modules/alpha/index.d.ts' does not exist.", - "Resolving with primary search path '/node_modules/@types/'", - "File '/node_modules/@types/alpha/package.json' does not exist.", - "File '/node_modules/@types/alpha/index.d.ts' does not exist.", + "======== Type reference directive 'bar' was successfully resolved to '/node_modules/bar/index.d.ts', primary: false. ========", + "======== Resolving type reference directive 'alpha', containing file '/node_modules/foo/index.d.ts', root directory 'types'. ========", + "Resolving with primary search path 'types'", + "File 'types/alpha/package.json' does not exist.", + "File 'types/alpha/index.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/node_modules/foo'", "File '/node_modules/foo/node_modules/alpha.ts' does not exist.", "File '/node_modules/foo/node_modules/alpha.d.ts' does not exist.", @@ -32,16 +52,10 @@ "File '/node_modules/foo/node_modules/alpha/index.ts' does not exist.", "File '/node_modules/foo/node_modules/alpha/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'alpha' was successfully resolved to '/node_modules/foo/node_modules/alpha/index.d.ts', primary: false. ========", - "======== Resolving type reference directive 'alpha', containing file '/node_modules/bar/index.d.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", - "File '/types/alpha/package.json' does not exist.", - "File '/types/alpha/index.d.ts' does not exist.", - "Resolving with primary search path '/node_modules/'", - "File '/node_modules/alpha/package.json' does not exist.", - "File '/node_modules/alpha/index.d.ts' does not exist.", - "Resolving with primary search path '/node_modules/@types/'", - "File '/node_modules/@types/alpha/package.json' does not exist.", - "File '/node_modules/@types/alpha/index.d.ts' does not exist.", + "======== Resolving type reference directive 'alpha', containing file '/node_modules/bar/index.d.ts', root directory 'types'. ========", + "Resolving with primary search path 'types'", + "File 'types/alpha/package.json' does not exist.", + "File 'types/alpha/index.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/node_modules/bar'", "File '/node_modules/bar/node_modules/alpha.ts' does not exist.", "File '/node_modules/bar/node_modules/alpha.d.ts' does not exist.", diff --git a/tests/baselines/reference/library-reference-6.symbols b/tests/baselines/reference/library-reference-6.symbols deleted file mode 100644 index 328842f804c..00000000000 --- a/tests/baselines/reference/library-reference-6.symbols +++ /dev/null @@ -1,16 +0,0 @@ -=== /src/foo.ts === -/// -var x: string = alpha.a; ->x : Symbol(x, Decl(foo.ts, 1, 3)) ->alpha.a : Symbol(a, Decl(index.d.ts, 3, 20)) ->alpha : Symbol(alpha, Decl(index.d.ts, 3, 11)) ->a : Symbol(a, Decl(index.d.ts, 3, 20)) - -=== /types/alpha/index.d.ts === - -// The primary lookup folder is relative to tsconfig.json, if present - -declare var alpha: { a: string }; ->alpha : Symbol(alpha, Decl(index.d.ts, 3, 11)) ->a : Symbol(a, Decl(index.d.ts, 3, 20)) - diff --git a/tests/baselines/reference/library-reference-6.trace.json b/tests/baselines/reference/library-reference-6.trace.json index 426214fdcfc..fc29f3f2478 100644 --- a/tests/baselines/reference/library-reference-6.trace.json +++ b/tests/baselines/reference/library-reference-6.trace.json @@ -1,7 +1,28 @@ [ - "======== Resolving type reference directive 'alpha', containing file '/src/foo.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", - "File '/types/alpha/package.json' does not exist.", - "File '/types/alpha/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'alpha' was successfully resolved to '/types/alpha/index.d.ts', primary: true. ========" + "======== Resolving type reference directive 'alpha', containing file '/src/foo.ts', root directory 'node_modules/@types'. ========", + "Resolving with primary search path 'node_modules/@types'", + "File 'node_modules/@types/alpha/package.json' does not exist.", + "File 'node_modules/@types/alpha/index.d.ts' does not exist.", + "Looking up in 'node_modules' folder, initial location '/src'", + "File '/src/node_modules/alpha.ts' does not exist.", + "File '/src/node_modules/alpha.d.ts' does not exist.", + "File '/src/node_modules/alpha/package.json' does not exist.", + "File '/src/node_modules/alpha/index.ts' does not exist.", + "File '/src/node_modules/alpha/index.d.ts' does not exist.", + "File '/src/node_modules/@types/alpha.ts' does not exist.", + "File '/src/node_modules/@types/alpha.d.ts' does not exist.", + "File '/src/node_modules/@types/alpha/package.json' does not exist.", + "File '/src/node_modules/@types/alpha/index.ts' does not exist.", + "File '/src/node_modules/@types/alpha/index.d.ts' does not exist.", + "File '/node_modules/alpha.ts' does not exist.", + "File '/node_modules/alpha.d.ts' does not exist.", + "File '/node_modules/alpha/package.json' does not exist.", + "File '/node_modules/alpha/index.ts' does not exist.", + "File '/node_modules/alpha/index.d.ts' does not exist.", + "File '/node_modules/@types/alpha.ts' does not exist.", + "File '/node_modules/@types/alpha.d.ts' does not exist.", + "File '/node_modules/@types/alpha/package.json' does not exist.", + "File '/node_modules/@types/alpha/index.ts' does not exist.", + "File '/node_modules/@types/alpha/index.d.ts' does not exist.", + "======== Type reference directive 'alpha' was not resolved. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-6.types b/tests/baselines/reference/library-reference-6.types deleted file mode 100644 index 2f6c1e49b89..00000000000 --- a/tests/baselines/reference/library-reference-6.types +++ /dev/null @@ -1,16 +0,0 @@ -=== /src/foo.ts === -/// -var x: string = alpha.a; ->x : string ->alpha.a : string ->alpha : { a: string; } ->a : string - -=== /types/alpha/index.d.ts === - -// The primary lookup folder is relative to tsconfig.json, if present - -declare var alpha: { a: string }; ->alpha : { a: string; } ->a : string - diff --git a/tests/baselines/reference/library-reference-7.trace.json b/tests/baselines/reference/library-reference-7.trace.json index 9c6b19390d0..909e42140c8 100644 --- a/tests/baselines/reference/library-reference-7.trace.json +++ b/tests/baselines/reference/library-reference-7.trace.json @@ -1,14 +1,8 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", - "File '/types/jquery/package.json' does not exist.", - "File '/types/jquery/index.d.ts' does not exist.", - "Resolving with primary search path '/node_modules/'", - "File '/node_modules/jquery/package.json' does not exist.", - "File '/node_modules/jquery/index.d.ts' does not exist.", - "Resolving with primary search path '/node_modules/@types/'", - "File '/node_modules/@types/jquery/package.json' does not exist.", - "File '/node_modules/@types/jquery/index.d.ts' does not exist.", + "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory 'node_modules/@types'. ========", + "Resolving with primary search path 'node_modules/@types'", + "File 'node_modules/@types/jquery/package.json' does not exist.", + "File 'node_modules/@types/jquery/index.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/src'", "File '/src/node_modules/jquery.ts' does not exist.", "File '/src/node_modules/jquery.d.ts' does not exist.", diff --git a/tests/baselines/reference/library-reference-8.symbols b/tests/baselines/reference/library-reference-8.symbols index 299a60f1b1d..a6a24689f3f 100644 --- a/tests/baselines/reference/library-reference-8.symbols +++ b/tests/baselines/reference/library-reference-8.symbols @@ -1,4 +1,4 @@ -=== /foo.ts === +=== /test/foo.ts === /// /// var x: string = alpha.a + beta.b; @@ -11,7 +11,7 @@ var x: string = alpha.a + beta.b; >b : Symbol(b, Decl(index.d.ts, 1, 19)) -=== /types/alpha/index.d.ts === +=== /test/types/alpha/index.d.ts === // Don't crash in circular library reference situations @@ -20,7 +20,7 @@ declare var alpha: { a: string }; >alpha : Symbol(alpha, Decl(index.d.ts, 4, 11)) >a : Symbol(a, Decl(index.d.ts, 4, 20)) -=== /types/beta/index.d.ts === +=== /test/types/beta/index.d.ts === /// declare var beta: { b: string }; >beta : Symbol(beta, Decl(index.d.ts, 1, 11)) diff --git a/tests/baselines/reference/library-reference-8.trace.json b/tests/baselines/reference/library-reference-8.trace.json index b1dc6478688..d34f206e581 100644 --- a/tests/baselines/reference/library-reference-8.trace.json +++ b/tests/baselines/reference/library-reference-8.trace.json @@ -1,22 +1,32 @@ [ - "======== Resolving type reference directive 'alpha', containing file '/foo.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", - "File '/types/alpha/package.json' does not exist.", - "File '/types/alpha/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'alpha' was successfully resolved to '/types/alpha/index.d.ts', primary: true. ========", - "======== Resolving type reference directive 'beta', containing file '/foo.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", - "File '/types/beta/package.json' does not exist.", - "File '/types/beta/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'beta' was successfully resolved to '/types/beta/index.d.ts', primary: true. ========", - "======== Resolving type reference directive 'beta', containing file '/types/alpha/index.d.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", - "File '/types/beta/package.json' does not exist.", - "File '/types/beta/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'beta' was successfully resolved to '/types/beta/index.d.ts', primary: true. ========", - "======== Resolving type reference directive 'alpha', containing file '/types/beta/index.d.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", - "File '/types/alpha/package.json' does not exist.", - "File '/types/alpha/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'alpha' was successfully resolved to '/types/alpha/index.d.ts', primary: true. ========" + "======== Resolving type reference directive 'alpha', containing file '/test/foo.ts', root directory '/test/types'. ========", + "Resolving with primary search path '/test/types'", + "File '/test/types/alpha/package.json' does not exist.", + "File '/test/types/alpha/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'alpha' was successfully resolved to '/test/types/alpha/index.d.ts', primary: true. ========", + "======== Resolving type reference directive 'beta', containing file '/test/foo.ts', root directory '/test/types'. ========", + "Resolving with primary search path '/test/types'", + "File '/test/types/beta/package.json' does not exist.", + "File '/test/types/beta/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'beta' was successfully resolved to '/test/types/beta/index.d.ts', primary: true. ========", + "======== Resolving type reference directive 'beta', containing file '/test/types/alpha/index.d.ts', root directory '/test/types'. ========", + "Resolving with primary search path '/test/types'", + "File '/test/types/beta/package.json' does not exist.", + "File '/test/types/beta/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'beta' was successfully resolved to '/test/types/beta/index.d.ts', primary: true. ========", + "======== Resolving type reference directive 'alpha', containing file '/test/types/beta/index.d.ts', root directory '/test/types'. ========", + "Resolving with primary search path '/test/types'", + "File '/test/types/alpha/package.json' does not exist.", + "File '/test/types/alpha/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'alpha' was successfully resolved to '/test/types/alpha/index.d.ts', primary: true. ========", + "======== Resolving type reference directive 'alpha', containing file '/test/__inferred type names__.ts', root directory '/test/types'. ========", + "Resolving with primary search path '/test/types'", + "File '/test/types/alpha/package.json' does not exist.", + "File '/test/types/alpha/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'alpha' was successfully resolved to '/test/types/alpha/index.d.ts', primary: true. ========", + "======== Resolving type reference directive 'beta', containing file '/test/__inferred type names__.ts', root directory '/test/types'. ========", + "Resolving with primary search path '/test/types'", + "File '/test/types/beta/package.json' does not exist.", + "File '/test/types/beta/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'beta' was successfully resolved to '/test/types/beta/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-8.types b/tests/baselines/reference/library-reference-8.types index b0780d90f63..d8a2b6e9638 100644 --- a/tests/baselines/reference/library-reference-8.types +++ b/tests/baselines/reference/library-reference-8.types @@ -1,4 +1,4 @@ -=== /foo.ts === +=== /test/foo.ts === /// /// var x: string = alpha.a + beta.b; @@ -12,7 +12,7 @@ var x: string = alpha.a + beta.b; >b : string -=== /types/alpha/index.d.ts === +=== /test/types/alpha/index.d.ts === // Don't crash in circular library reference situations @@ -21,7 +21,7 @@ declare var alpha: { a: string }; >alpha : { a: string; } >a : string -=== /types/beta/index.d.ts === +=== /test/types/beta/index.d.ts === /// declare var beta: { b: string }; >beta : { b: string; } diff --git a/tests/baselines/reference/library-reference-9.js b/tests/baselines/reference/library-reference-9.js deleted file mode 100644 index ccb3b3213a9..00000000000 --- a/tests/baselines/reference/library-reference-9.js +++ /dev/null @@ -1,16 +0,0 @@ -//// [tests/cases/conformance/references/library-reference-9.ts] //// - -//// [index.d.ts] - -// Use types search path - -declare var alpha: { a: string }; - -//// [foo.ts] -/// -var x: string = alpha.a; - - -//// [foo.js] -/// -var x = alpha.a; diff --git a/tests/baselines/reference/library-reference-9.symbols b/tests/baselines/reference/library-reference-9.symbols deleted file mode 100644 index 62cde2117df..00000000000 --- a/tests/baselines/reference/library-reference-9.symbols +++ /dev/null @@ -1,16 +0,0 @@ -=== /base/src/foo.ts === -/// -var x: string = alpha.a; ->x : Symbol(x, Decl(foo.ts, 1, 3)) ->alpha.a : Symbol(a, Decl(index.d.ts, 3, 20)) ->alpha : Symbol(alpha, Decl(index.d.ts, 3, 11)) ->a : Symbol(a, Decl(index.d.ts, 3, 20)) - -=== /share/typelib/alpha/index.d.ts === - -// Use types search path - -declare var alpha: { a: string }; ->alpha : Symbol(alpha, Decl(index.d.ts, 3, 11)) ->a : Symbol(a, Decl(index.d.ts, 3, 20)) - diff --git a/tests/baselines/reference/library-reference-9.trace.json b/tests/baselines/reference/library-reference-9.trace.json deleted file mode 100644 index e2fdfdc0550..00000000000 --- a/tests/baselines/reference/library-reference-9.trace.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - "======== Resolving type reference directive 'alpha', containing file '/base/src/foo.ts', root directory '/'. ========", - "Resolving with primary search path '/share/typelib'", - "File '/share/typelib/alpha/package.json' does not exist.", - "File '/share/typelib/alpha/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'alpha' was successfully resolved to '/share/typelib/alpha/index.d.ts', primary: true. ========" -] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-9.types b/tests/baselines/reference/library-reference-9.types deleted file mode 100644 index 8df2179e249..00000000000 --- a/tests/baselines/reference/library-reference-9.types +++ /dev/null @@ -1,16 +0,0 @@ -=== /base/src/foo.ts === -/// -var x: string = alpha.a; ->x : string ->alpha.a : string ->alpha : { a: string; } ->a : string - -=== /share/typelib/alpha/index.d.ts === - -// Use types search path - -declare var alpha: { a: string }; ->alpha : { a: string; } ->a : string - diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks.errors.txt b/tests/baselines/reference/moduleResolutionWithSymlinks.errors.txt new file mode 100644 index 00000000000..b51933902a4 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionWithSymlinks.errors.txt @@ -0,0 +1,21 @@ +/src/library-b/index.ts(1,23): error TS2307: Cannot find module 'library-a'. + + +==== /src/app.ts (0 errors) ==== + import { MyClass } from "./library-a"; + import { MyClass2 } from "./library-b"; + + let x: MyClass; + let y: MyClass2; + x = y; + y = x; +==== /src/library-a/index.ts (0 errors) ==== + + export class MyClass{} + +==== /src/library-b/index.ts (1 errors) ==== + import {MyClass} from "library-a"; + ~~~~~~~~~~~ +!!! error TS2307: Cannot find module 'library-a'. + export { MyClass as MyClass2 } + \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks.symbols b/tests/baselines/reference/moduleResolutionWithSymlinks.symbols deleted file mode 100644 index ea73755deef..00000000000 --- a/tests/baselines/reference/moduleResolutionWithSymlinks.symbols +++ /dev/null @@ -1,36 +0,0 @@ -=== /src/app.ts === -import { MyClass } from "./library-a"; ->MyClass : Symbol(MyClass, Decl(app.ts, 0, 8)) - -import { MyClass2 } from "./library-b"; ->MyClass2 : Symbol(MyClass2, Decl(app.ts, 1, 8)) - -let x: MyClass; ->x : Symbol(x, Decl(app.ts, 3, 3)) ->MyClass : Symbol(MyClass, Decl(app.ts, 0, 8)) - -let y: MyClass2; ->y : Symbol(y, Decl(app.ts, 4, 3)) ->MyClass2 : Symbol(MyClass2, Decl(app.ts, 1, 8)) - -x = y; ->x : Symbol(x, Decl(app.ts, 3, 3)) ->y : Symbol(y, Decl(app.ts, 4, 3)) - -y = x; ->y : Symbol(y, Decl(app.ts, 4, 3)) ->x : Symbol(x, Decl(app.ts, 3, 3)) - -=== /src/library-a/index.ts === - -export class MyClass{} ->MyClass : Symbol(MyClass, Decl(index.ts, 0, 0)) - -=== /src/library-b/index.ts === -import {MyClass} from "library-a"; ->MyClass : Symbol(MyClass, Decl(index.ts, 0, 8)) - -export { MyClass as MyClass2 } ->MyClass : Symbol(MyClass2, Decl(index.ts, 1, 8)) ->MyClass2 : Symbol(MyClass2, Decl(index.ts, 1, 8)) - diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks.trace.json b/tests/baselines/reference/moduleResolutionWithSymlinks.trace.json index 7f1c2890180..f3bfae4b173 100644 --- a/tests/baselines/reference/moduleResolutionWithSymlinks.trace.json +++ b/tests/baselines/reference/moduleResolutionWithSymlinks.trace.json @@ -26,7 +26,43 @@ "File '/src/library-b/node_modules/library-a.tsx' does not exist.", "File '/src/library-b/node_modules/library-a.d.ts' does not exist.", "File '/src/library-b/node_modules/library-a/package.json' does not exist.", - "File '/src/library-b/node_modules/library-a/index.ts' exist - use it as a name resolution result.", - "Resolving real path for '/src/library-b/node_modules/library-a/index.ts', result '/src/library-a/index.ts'", - "======== Module name 'library-a' was successfully resolved to '/src/library-a/index.ts'. ========" + "File '/src/library-b/node_modules/library-a/index.ts' does not exist.", + "File '/src/library-b/node_modules/library-a/index.tsx' does not exist.", + "File '/src/library-b/node_modules/library-a/index.d.ts' does not exist.", + "File '/src/library-b/node_modules/@types/library-a.ts' does not exist.", + "File '/src/library-b/node_modules/@types/library-a.tsx' does not exist.", + "File '/src/library-b/node_modules/@types/library-a.d.ts' does not exist.", + "File '/src/library-b/node_modules/@types/library-a/package.json' does not exist.", + "File '/src/library-b/node_modules/@types/library-a/index.ts' does not exist.", + "File '/src/library-b/node_modules/@types/library-a/index.tsx' does not exist.", + "File '/src/library-b/node_modules/@types/library-a/index.d.ts' does not exist.", + "File '/src/node_modules/library-a.ts' does not exist.", + "File '/src/node_modules/library-a.tsx' does not exist.", + "File '/src/node_modules/library-a.d.ts' does not exist.", + "File '/src/node_modules/library-a/package.json' does not exist.", + "File '/src/node_modules/library-a/index.ts' does not exist.", + "File '/src/node_modules/library-a/index.tsx' does not exist.", + "File '/src/node_modules/library-a/index.d.ts' does not exist.", + "File '/src/node_modules/@types/library-a.ts' does not exist.", + "File '/src/node_modules/@types/library-a.tsx' does not exist.", + "File '/src/node_modules/@types/library-a.d.ts' does not exist.", + "File '/src/node_modules/@types/library-a/package.json' does not exist.", + "File '/src/node_modules/@types/library-a/index.ts' does not exist.", + "File '/src/node_modules/@types/library-a/index.tsx' does not exist.", + "File '/src/node_modules/@types/library-a/index.d.ts' does not exist.", + "File '/node_modules/library-a.ts' does not exist.", + "File '/node_modules/library-a.tsx' does not exist.", + "File '/node_modules/library-a.d.ts' does not exist.", + "File '/node_modules/library-a/package.json' does not exist.", + "File '/node_modules/library-a/index.ts' does not exist.", + "File '/node_modules/library-a/index.tsx' does not exist.", + "File '/node_modules/library-a/index.d.ts' does not exist.", + "File '/node_modules/@types/library-a.ts' does not exist.", + "File '/node_modules/@types/library-a.tsx' does not exist.", + "File '/node_modules/@types/library-a.d.ts' does not exist.", + "File '/node_modules/@types/library-a/package.json' does not exist.", + "File '/node_modules/@types/library-a/index.ts' does not exist.", + "File '/node_modules/@types/library-a/index.tsx' does not exist.", + "File '/node_modules/@types/library-a/index.d.ts' does not exist.", + "======== Module name 'library-a' was not resolved. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithSymlinks.types b/tests/baselines/reference/moduleResolutionWithSymlinks.types deleted file mode 100644 index 8344adbe817..00000000000 --- a/tests/baselines/reference/moduleResolutionWithSymlinks.types +++ /dev/null @@ -1,38 +0,0 @@ -=== /src/app.ts === -import { MyClass } from "./library-a"; ->MyClass : typeof MyClass - -import { MyClass2 } from "./library-b"; ->MyClass2 : typeof MyClass - -let x: MyClass; ->x : MyClass ->MyClass : MyClass - -let y: MyClass2; ->y : MyClass ->MyClass2 : MyClass - -x = y; ->x = y : MyClass ->x : MyClass ->y : MyClass - -y = x; ->y = x : MyClass ->y : MyClass ->x : MyClass - -=== /src/library-a/index.ts === - -export class MyClass{} ->MyClass : MyClass - -=== /src/library-b/index.ts === -import {MyClass} from "library-a"; ->MyClass : typeof MyClass - -export { MyClass as MyClass2 } ->MyClass : typeof MyClass ->MyClass2 : typeof MyClass - diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json index af5e20a3cc3..ab7210d7d02 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution3_node.trace.json @@ -5,11 +5,13 @@ "Resolving module name 'folder2/file2' relative to base url 'c:/root' - 'c:/root/folder2/file2'.", "Loading module as file / folder, candidate module location 'c:/root/folder2/file2'.", "File 'c:/root/folder2/file2.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/root/folder2/file2.ts', result 'c:/root/folder2/file2.ts'", "======== Module name 'folder2/file2' was successfully resolved to 'c:/root/folder2/file2.ts'. ========", "======== Resolving module './file3' from 'c:/root/folder2/file2.ts'. ========", "Explicitly specified module resolution kind: 'NodeJs'.", "Loading module as file / folder, candidate module location 'c:/root/folder2/file3'.", "File 'c:/root/folder2/file3.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/root/folder2/file3.ts', result 'c:/root/folder2/file3.ts'", "======== Module name './file3' was successfully resolved to 'c:/root/folder2/file3.ts'. ========", "======== Resolving module 'file4' from 'c:/root/folder2/file2.ts'. ========", "Explicitly specified module resolution kind: 'NodeJs'.", @@ -59,5 +61,6 @@ "File 'c:/node_modules/file4/index.ts' does not exist.", "File 'c:/node_modules/file4/index.tsx' does not exist.", "File 'c:/node_modules/file4/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/node_modules/file4/index.d.ts', result 'c:/node_modules/file4/index.d.ts'", "======== Module name 'file4' was successfully resolved to 'c:/node_modules/file4/index.d.ts'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json index af5e20a3cc3..ab7210d7d02 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution4_node.trace.json @@ -5,11 +5,13 @@ "Resolving module name 'folder2/file2' relative to base url 'c:/root' - 'c:/root/folder2/file2'.", "Loading module as file / folder, candidate module location 'c:/root/folder2/file2'.", "File 'c:/root/folder2/file2.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/root/folder2/file2.ts', result 'c:/root/folder2/file2.ts'", "======== Module name 'folder2/file2' was successfully resolved to 'c:/root/folder2/file2.ts'. ========", "======== Resolving module './file3' from 'c:/root/folder2/file2.ts'. ========", "Explicitly specified module resolution kind: 'NodeJs'.", "Loading module as file / folder, candidate module location 'c:/root/folder2/file3'.", "File 'c:/root/folder2/file3.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/root/folder2/file3.ts', result 'c:/root/folder2/file3.ts'", "======== Module name './file3' was successfully resolved to 'c:/root/folder2/file3.ts'. ========", "======== Resolving module 'file4' from 'c:/root/folder2/file2.ts'. ========", "Explicitly specified module resolution kind: 'NodeJs'.", @@ -59,5 +61,6 @@ "File 'c:/node_modules/file4/index.ts' does not exist.", "File 'c:/node_modules/file4/index.tsx' does not exist.", "File 'c:/node_modules/file4/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/node_modules/file4/index.d.ts', result 'c:/node_modules/file4/index.d.ts'", "======== Module name 'file4' was successfully resolved to 'c:/node_modules/file4/index.d.ts'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json index cebd59f01b4..2efeefa24e5 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution5_node.trace.json @@ -7,6 +7,7 @@ "Trying substitution '*', candidate module location: 'folder2/file1'.", "Loading module as file / folder, candidate module location 'c:/root/folder2/file1'.", "File 'c:/root/folder2/file1.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/root/folder2/file1.ts', result 'c:/root/folder2/file1.ts'", "======== Module name 'folder2/file1' was successfully resolved to 'c:/root/folder2/file1.ts'. ========", "======== Resolving module 'folder3/file2' from 'c:/root/folder1/file1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -25,6 +26,7 @@ "Trying substitution 'generated/*', candidate module location: 'generated/folder3/file2'.", "Loading module as file / folder, candidate module location 'c:/root/generated/folder3/file2'.", "File 'c:/root/generated/folder3/file2.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/root/generated/folder3/file2.ts', result 'c:/root/generated/folder3/file2.ts'", "======== Module name 'folder3/file2' was successfully resolved to 'c:/root/generated/folder3/file2.ts'. ========", "======== Resolving module 'components/file3' from 'c:/root/folder1/file1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -40,6 +42,7 @@ "File 'c:/root/shared/components/file3/index.ts' does not exist.", "File 'c:/root/shared/components/file3/index.tsx' does not exist.", "File 'c:/root/shared/components/file3/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/root/shared/components/file3/index.d.ts', result 'c:/root/shared/components/file3/index.d.ts'", "======== Module name 'components/file3' was successfully resolved to 'c:/root/shared/components/file3/index.d.ts'. ========", "======== Resolving module 'file4' from 'c:/root/folder1/file1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -94,5 +97,6 @@ "File 'c:/root/node_modules/@types/file4/index.tsx' does not exist.", "File 'c:/root/node_modules/@types/file4/index.d.ts' does not exist.", "File 'c:/node_modules/file4.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/node_modules/file4.ts', result 'c:/node_modules/file4.ts'", "======== Module name 'file4' was successfully resolved to 'c:/node_modules/file4.ts'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution6_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.trace.json index 7c5e76a2847..28e51a11915 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution6_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution6_node.trace.json @@ -18,6 +18,7 @@ "Loading 'project/file3' from the root dir 'c:/root/generated/src', candidate location 'c:/root/generated/src/project/file3'", "Loading module as file / folder, candidate module location 'c:/root/generated/src/project/file3'.", "File 'c:/root/generated/src/project/file3.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/root/generated/src/project/file3.ts', result 'c:/root/generated/src/project/file3.ts'", "======== Module name './project/file3' was successfully resolved to 'c:/root/generated/src/project/file3.ts'. ========", "======== Resolving module '../file2' from 'c:/root/generated/src/project/file3.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -44,5 +45,6 @@ "File 'c:/root/src/file2/index.ts' does not exist.", "File 'c:/root/src/file2/index.tsx' does not exist.", "File 'c:/root/src/file2/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/root/src/file2/index.d.ts', result 'c:/root/src/file2/index.d.ts'", "======== Module name '../file2' was successfully resolved to 'c:/root/src/file2/index.d.ts'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json index 99d4bf244db..6be7d349fed 100644 --- a/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json +++ b/tests/baselines/reference/pathMappingBasedModuleResolution7_node.trace.json @@ -18,6 +18,7 @@ "Loading 'project/file2' from the root dir 'c:/root/generated/src', candidate location 'c:/root/generated/src/project/file2'", "Loading module as file / folder, candidate module location 'c:/root/generated/src/project/file2'.", "File 'c:/root/generated/src/project/file2.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/root/generated/src/project/file2.ts', result 'c:/root/generated/src/project/file2.ts'", "======== Module name './project/file2' was successfully resolved to 'c:/root/generated/src/project/file2.ts'. ========", "======== Resolving module 'module3' from 'c:/root/src/file1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -74,6 +75,7 @@ "File 'c:/node_modules/module3.ts' does not exist.", "File 'c:/node_modules/module3.tsx' does not exist.", "File 'c:/node_modules/module3.d.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/node_modules/module3.d.ts', result 'c:/node_modules/module3.d.ts'", "======== Module name 'module3' was successfully resolved to 'c:/node_modules/module3.d.ts'. ========", "======== Resolving module 'module1' from 'c:/root/generated/src/project/file2.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -98,6 +100,7 @@ "File 'c:/shared/module1/index.ts' does not exist.", "File 'c:/shared/module1/index.tsx' does not exist.", "File 'c:/shared/module1/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/shared/module1/index.d.ts', result 'c:/shared/module1/index.d.ts'", "======== Module name 'module1' was successfully resolved to 'c:/shared/module1/index.d.ts'. ========", "======== Resolving module 'templates/module2' from 'c:/root/generated/src/project/file2.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -107,6 +110,7 @@ "Trying substitution 'generated/src/templates/*', candidate module location: 'generated/src/templates/module2'.", "Loading module as file / folder, candidate module location 'c:/root/generated/src/templates/module2'.", "File 'c:/root/generated/src/templates/module2.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/root/generated/src/templates/module2.ts', result 'c:/root/generated/src/templates/module2.ts'", "======== Module name 'templates/module2' was successfully resolved to 'c:/root/generated/src/templates/module2.ts'. ========", "======== Resolving module '../file3' from 'c:/root/generated/src/project/file2.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -133,5 +137,6 @@ "File 'c:/root/src/file3/index.ts' does not exist.", "File 'c:/root/src/file3/index.tsx' does not exist.", "File 'c:/root/src/file3/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for 'c:/root/src/file3/index.d.ts', result 'c:/root/src/file3/index.d.ts'", "======== Module name '../file3' was successfully resolved to 'c:/root/src/file3/index.d.ts'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives1.trace.json b/tests/baselines/reference/typeReferenceDirectives1.trace.json index c936a84dcc0..58b23783b0b 100644 --- a/tests/baselines/reference/typeReferenceDirectives1.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives1.trace.json @@ -1,6 +1,11 @@ [ - "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", + "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", + "File '/types/lib/package.json' does not exist.", + "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", + "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" diff --git a/tests/baselines/reference/typeReferenceDirectives10.trace.json b/tests/baselines/reference/typeReferenceDirectives10.trace.json index b6adaf1f513..61341afdab3 100644 --- a/tests/baselines/reference/typeReferenceDirectives10.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives10.trace.json @@ -1,6 +1,6 @@ [ - "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", + "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", @@ -10,5 +10,11 @@ "File '/ref.ts' does not exist.", "File '/ref.tsx' does not exist.", "File '/ref.d.ts' exist - use it as a name resolution result.", - "======== Module name './ref' was successfully resolved to '/ref.d.ts'. ========" + "Resolving real path for '/ref.d.ts', result '/ref.d.ts'", + "======== Module name './ref' was successfully resolved to '/ref.d.ts'. ========", + "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", + "File '/types/lib/package.json' does not exist.", + "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives11.trace.json b/tests/baselines/reference/typeReferenceDirectives11.trace.json index bfaae056c9e..37fa7900a7c 100644 --- a/tests/baselines/reference/typeReferenceDirectives11.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives11.trace.json @@ -3,9 +3,10 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/mod1'.", "File '/mod1.ts' exist - use it as a name resolution result.", + "Resolving real path for '/mod1.ts', result '/mod1.ts'", "======== Module name './mod1' was successfully resolved to '/mod1.ts'. ========", - "======== Resolving type reference directive 'lib', containing file not set, root directory '/'. ========", - "Resolving with primary search path '/types/'", + "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" diff --git a/tests/baselines/reference/typeReferenceDirectives12.trace.json b/tests/baselines/reference/typeReferenceDirectives12.trace.json index f4fc0937325..1024b0cdef3 100644 --- a/tests/baselines/reference/typeReferenceDirectives12.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives12.trace.json @@ -3,14 +3,16 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/main'.", "File '/main.ts' exist - use it as a name resolution result.", + "Resolving real path for '/main.ts', result '/main.ts'", "======== Module name './main' was successfully resolved to '/main.ts'. ========", "======== Resolving module './mod1' from '/mod2.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/mod1'.", "File '/mod1.ts' exist - use it as a name resolution result.", + "Resolving real path for '/mod1.ts', result '/mod1.ts'", "======== Module name './mod1' was successfully resolved to '/mod1.ts'. ========", - "======== Resolving type reference directive 'lib', containing file '/mod1.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", + "======== Resolving type reference directive 'lib', containing file '/mod1.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", @@ -18,5 +20,11 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/main'.", "File '/main.ts' exist - use it as a name resolution result.", - "======== Module name './main' was successfully resolved to '/main.ts'. ========" + "Resolving real path for '/main.ts', result '/main.ts'", + "======== Module name './main' was successfully resolved to '/main.ts'. ========", + "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", + "File '/types/lib/package.json' does not exist.", + "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives13.trace.json b/tests/baselines/reference/typeReferenceDirectives13.trace.json index b6adaf1f513..61341afdab3 100644 --- a/tests/baselines/reference/typeReferenceDirectives13.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives13.trace.json @@ -1,6 +1,6 @@ [ - "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", + "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", @@ -10,5 +10,11 @@ "File '/ref.ts' does not exist.", "File '/ref.tsx' does not exist.", "File '/ref.d.ts' exist - use it as a name resolution result.", - "======== Module name './ref' was successfully resolved to '/ref.d.ts'. ========" + "Resolving real path for '/ref.d.ts', result '/ref.d.ts'", + "======== Module name './ref' was successfully resolved to '/ref.d.ts'. ========", + "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", + "File '/types/lib/package.json' does not exist.", + "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives2.trace.json b/tests/baselines/reference/typeReferenceDirectives2.trace.json index 826abe5d51a..93d3658447d 100644 --- a/tests/baselines/reference/typeReferenceDirectives2.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives2.trace.json @@ -1,6 +1,6 @@ [ - "======== Resolving type reference directive 'lib', containing file not set, root directory '/'. ========", - "Resolving with primary search path '/types/'", + "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" diff --git a/tests/baselines/reference/typeReferenceDirectives3.trace.json b/tests/baselines/reference/typeReferenceDirectives3.trace.json index c936a84dcc0..58b23783b0b 100644 --- a/tests/baselines/reference/typeReferenceDirectives3.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives3.trace.json @@ -1,6 +1,11 @@ [ - "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", + "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", + "File '/types/lib/package.json' does not exist.", + "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", + "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" diff --git a/tests/baselines/reference/typeReferenceDirectives4.trace.json b/tests/baselines/reference/typeReferenceDirectives4.trace.json index c936a84dcc0..58b23783b0b 100644 --- a/tests/baselines/reference/typeReferenceDirectives4.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives4.trace.json @@ -1,6 +1,11 @@ [ - "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", + "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", + "File '/types/lib/package.json' does not exist.", + "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", + "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" diff --git a/tests/baselines/reference/typeReferenceDirectives5.trace.json b/tests/baselines/reference/typeReferenceDirectives5.trace.json index b6adaf1f513..61341afdab3 100644 --- a/tests/baselines/reference/typeReferenceDirectives5.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives5.trace.json @@ -1,6 +1,6 @@ [ - "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", + "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", @@ -10,5 +10,11 @@ "File '/ref.ts' does not exist.", "File '/ref.tsx' does not exist.", "File '/ref.d.ts' exist - use it as a name resolution result.", - "======== Module name './ref' was successfully resolved to '/ref.d.ts'. ========" + "Resolving real path for '/ref.d.ts', result '/ref.d.ts'", + "======== Module name './ref' was successfully resolved to '/ref.d.ts'. ========", + "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", + "File '/types/lib/package.json' does not exist.", + "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typeReferenceDirectives6.trace.json b/tests/baselines/reference/typeReferenceDirectives6.trace.json index c936a84dcc0..58b23783b0b 100644 --- a/tests/baselines/reference/typeReferenceDirectives6.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives6.trace.json @@ -1,6 +1,11 @@ [ - "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", + "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", + "File '/types/lib/package.json' does not exist.", + "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", + "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" diff --git a/tests/baselines/reference/typeReferenceDirectives7.trace.json b/tests/baselines/reference/typeReferenceDirectives7.trace.json index c936a84dcc0..58b23783b0b 100644 --- a/tests/baselines/reference/typeReferenceDirectives7.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives7.trace.json @@ -1,6 +1,11 @@ [ - "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", + "======== Resolving type reference directive 'lib', containing file '/app.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", + "File '/types/lib/package.json' does not exist.", + "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", + "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" diff --git a/tests/baselines/reference/typeReferenceDirectives8.trace.json b/tests/baselines/reference/typeReferenceDirectives8.trace.json index bfaae056c9e..37fa7900a7c 100644 --- a/tests/baselines/reference/typeReferenceDirectives8.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives8.trace.json @@ -3,9 +3,10 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/mod1'.", "File '/mod1.ts' exist - use it as a name resolution result.", + "Resolving real path for '/mod1.ts', result '/mod1.ts'", "======== Module name './mod1' was successfully resolved to '/mod1.ts'. ========", - "======== Resolving type reference directive 'lib', containing file not set, root directory '/'. ========", - "Resolving with primary search path '/types/'", + "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" diff --git a/tests/baselines/reference/typeReferenceDirectives9.trace.json b/tests/baselines/reference/typeReferenceDirectives9.trace.json index f4fc0937325..1024b0cdef3 100644 --- a/tests/baselines/reference/typeReferenceDirectives9.trace.json +++ b/tests/baselines/reference/typeReferenceDirectives9.trace.json @@ -3,14 +3,16 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/main'.", "File '/main.ts' exist - use it as a name resolution result.", + "Resolving real path for '/main.ts', result '/main.ts'", "======== Module name './main' was successfully resolved to '/main.ts'. ========", "======== Resolving module './mod1' from '/mod2.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/mod1'.", "File '/mod1.ts' exist - use it as a name resolution result.", + "Resolving real path for '/mod1.ts', result '/mod1.ts'", "======== Module name './mod1' was successfully resolved to '/mod1.ts'. ========", - "======== Resolving type reference directive 'lib', containing file '/mod1.ts', root directory '/'. ========", - "Resolving with primary search path '/types/'", + "======== Resolving type reference directive 'lib', containing file '/mod1.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", "File '/types/lib/package.json' does not exist.", "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========", @@ -18,5 +20,11 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/main'.", "File '/main.ts' exist - use it as a name resolution result.", - "======== Module name './main' was successfully resolved to '/main.ts'. ========" + "Resolving real path for '/main.ts', result '/main.ts'", + "======== Module name './main' was successfully resolved to '/main.ts'. ========", + "======== Resolving type reference directive 'lib', containing file '/__inferred type names__.ts', root directory '/types'. ========", + "Resolving with primary search path '/types'", + "File '/types/lib/package.json' does not exist.", + "File '/types/lib/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'lib' was successfully resolved to '/types/lib/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typingsLookup1.js b/tests/baselines/reference/typingsLookup1.js index 1f89a2277aa..3927c3db077 100644 --- a/tests/baselines/reference/typingsLookup1.js +++ b/tests/baselines/reference/typingsLookup1.js @@ -4,8 +4,10 @@ declare var $: { x: any }; //// [a.ts] +/// $.x; //// [a.js] +/// $.x; diff --git a/tests/baselines/reference/typingsLookup1.symbols b/tests/baselines/reference/typingsLookup1.symbols index 8a21252d123..73d01df511e 100644 --- a/tests/baselines/reference/typingsLookup1.symbols +++ b/tests/baselines/reference/typingsLookup1.symbols @@ -1,10 +1,11 @@ -=== tests/cases/conformance/typings/a.ts === +=== /a.ts === +/// $.x; >$.x : Symbol(x, Decl(index.d.ts, 0, 16)) >$ : Symbol($, Decl(index.d.ts, 0, 11)) >x : Symbol(x, Decl(index.d.ts, 0, 16)) -=== tests/cases/conformance/typings/node_modules/@types/jquery/index.d.ts === +=== /node_modules/@types/jquery/index.d.ts === declare var $: { x: any }; >$ : Symbol($, Decl(index.d.ts, 0, 11)) >x : Symbol(x, Decl(index.d.ts, 0, 16)) diff --git a/tests/baselines/reference/typingsLookup1.trace.json b/tests/baselines/reference/typingsLookup1.trace.json new file mode 100644 index 00000000000..0463c920bd3 --- /dev/null +++ b/tests/baselines/reference/typingsLookup1.trace.json @@ -0,0 +1,18 @@ +[ + "======== Resolving type reference directive 'jquery', containing file '/a.ts', root directory 'node_modules/@types'. ========", + "Resolving with primary search path 'node_modules/@types'", + "File 'node_modules/@types/jquery/package.json' does not exist.", + "File 'node_modules/@types/jquery/index.d.ts' does not exist.", + "Looking up in 'node_modules' folder, initial location '/'", + "File '/node_modules/jquery.ts' does not exist.", + "File '/node_modules/jquery.d.ts' does not exist.", + "File '/node_modules/jquery/package.json' does not exist.", + "File '/node_modules/jquery/index.ts' does not exist.", + "File '/node_modules/jquery/index.d.ts' does not exist.", + "File '/node_modules/@types/jquery.ts' does not exist.", + "File '/node_modules/@types/jquery.d.ts' does not exist.", + "File '/node_modules/@types/jquery/package.json' does not exist.", + "File '/node_modules/@types/jquery/index.ts' does not exist.", + "File '/node_modules/@types/jquery/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: false. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/typingsLookup1.types b/tests/baselines/reference/typingsLookup1.types index ca79a8248d5..e1b696bf343 100644 --- a/tests/baselines/reference/typingsLookup1.types +++ b/tests/baselines/reference/typingsLookup1.types @@ -1,10 +1,11 @@ -=== tests/cases/conformance/typings/a.ts === +=== /a.ts === +/// $.x; >$.x : any >$ : { x: any; } >x : any -=== tests/cases/conformance/typings/node_modules/@types/jquery/index.d.ts === +=== /node_modules/@types/jquery/index.d.ts === declare var $: { x: any }; >$ : { x: any; } >x : any diff --git a/tests/cases/compiler/commonSourceDir5.ts b/tests/cases/compiler/commonSourceDir5.ts index d181bef68fe..7f5239976e8 100644 --- a/tests/cases/compiler/commonSourceDir5.ts +++ b/tests/cases/compiler/commonSourceDir5.ts @@ -1,6 +1,7 @@ // @outFile: concat.js // @module: amd // @moduleResolution: node + // @Filename: A:/bar.ts import {z} from "./foo"; export var x = z + z; diff --git a/tests/cases/compiler/typeReferenceDirectives1.ts b/tests/cases/compiler/typeReferenceDirectives1.ts index 2127bd13f7b..e17e498b978 100644 --- a/tests/cases/compiler/typeReferenceDirectives1.ts +++ b/tests/cases/compiler/typeReferenceDirectives1.ts @@ -1,7 +1,7 @@ // @noImplicitReferences: true // @traceResolution: true // @declaration: true -// @typesRoot: / +// @typeRoots: /types // @filename: /types/lib/index.d.ts diff --git a/tests/cases/compiler/typeReferenceDirectives10.ts b/tests/cases/compiler/typeReferenceDirectives10.ts index bf0768993c9..61971ba44b2 100644 --- a/tests/cases/compiler/typeReferenceDirectives10.ts +++ b/tests/cases/compiler/typeReferenceDirectives10.ts @@ -1,6 +1,6 @@ // @noImplicitReferences: true // @declaration: true -// @typesRoot: / +// @typeRoots: /types // @traceResolution: true // @filename: /ref.d.ts diff --git a/tests/cases/compiler/typeReferenceDirectives11.ts b/tests/cases/compiler/typeReferenceDirectives11.ts index c955a5daffc..2d93e22bdcf 100644 --- a/tests/cases/compiler/typeReferenceDirectives11.ts +++ b/tests/cases/compiler/typeReferenceDirectives11.ts @@ -1,6 +1,6 @@ // @noImplicitReferences: true // @declaration: true -// @typesRoot: / +// @typeRoots: /types // @traceResolution: true // @types: lib // @out: output.js diff --git a/tests/cases/compiler/typeReferenceDirectives12.ts b/tests/cases/compiler/typeReferenceDirectives12.ts index ef3c8d9755f..efdb1e8312b 100644 --- a/tests/cases/compiler/typeReferenceDirectives12.ts +++ b/tests/cases/compiler/typeReferenceDirectives12.ts @@ -1,6 +1,6 @@ // @noImplicitReferences: true // @declaration: true -// @typesRoot: / +// @typeRoots: /types // @traceResolution: true // @out: output.js diff --git a/tests/cases/compiler/typeReferenceDirectives13.ts b/tests/cases/compiler/typeReferenceDirectives13.ts index 816d419e9d5..124c31274ac 100644 --- a/tests/cases/compiler/typeReferenceDirectives13.ts +++ b/tests/cases/compiler/typeReferenceDirectives13.ts @@ -1,6 +1,6 @@ // @noImplicitReferences: true // @declaration: true -// @typesRoot: / +// @typeRoots: /types // @traceResolution: true // @filename: /ref.d.ts diff --git a/tests/cases/compiler/typeReferenceDirectives2.ts b/tests/cases/compiler/typeReferenceDirectives2.ts index eb651728cea..31a01a0b8e4 100644 --- a/tests/cases/compiler/typeReferenceDirectives2.ts +++ b/tests/cases/compiler/typeReferenceDirectives2.ts @@ -1,7 +1,7 @@ // @noImplicitReferences: true // @traceResolution: true // @declaration: true -// @typesRoot: / +// @typeRoots: /types // @types: lib // @filename: /types/lib/index.d.ts diff --git a/tests/cases/compiler/typeReferenceDirectives3.ts b/tests/cases/compiler/typeReferenceDirectives3.ts index bf81268d141..4c2729ab389 100644 --- a/tests/cases/compiler/typeReferenceDirectives3.ts +++ b/tests/cases/compiler/typeReferenceDirectives3.ts @@ -1,6 +1,6 @@ // @noImplicitReferences: true // @declaration: true -// @typesRoot: / +// @typeRoots: /types // @traceResolution: true // $ comes from d.ts file - no need to add type reference directive diff --git a/tests/cases/compiler/typeReferenceDirectives4.ts b/tests/cases/compiler/typeReferenceDirectives4.ts index 48eb8a5324a..ac7346895ef 100644 --- a/tests/cases/compiler/typeReferenceDirectives4.ts +++ b/tests/cases/compiler/typeReferenceDirectives4.ts @@ -1,7 +1,7 @@ // @noImplicitReferences: true // @traceResolution: true // @declaration: true -// @typesRoot: / +// @typeRoots: /types // $ comes from d.ts file - no need to add type reference directive diff --git a/tests/cases/compiler/typeReferenceDirectives5.ts b/tests/cases/compiler/typeReferenceDirectives5.ts index 675f932da68..bb24b82b324 100644 --- a/tests/cases/compiler/typeReferenceDirectives5.ts +++ b/tests/cases/compiler/typeReferenceDirectives5.ts @@ -1,7 +1,7 @@ // @noImplicitReferences: true // @traceResolution: true // @declaration: true -// @typesRoot: / +// @typeRoots: /types // @filename: /ref.d.ts export interface $ { x } diff --git a/tests/cases/compiler/typeReferenceDirectives6.ts b/tests/cases/compiler/typeReferenceDirectives6.ts index 120a743009c..7154963f1ef 100644 --- a/tests/cases/compiler/typeReferenceDirectives6.ts +++ b/tests/cases/compiler/typeReferenceDirectives6.ts @@ -1,7 +1,7 @@ // @noImplicitReferences: true // @traceResolution: true // @declaration: true -// @typesRoot: / +// @typeRoots: /types // $ comes from type declaration file - type reference directive should be added diff --git a/tests/cases/compiler/typeReferenceDirectives7.ts b/tests/cases/compiler/typeReferenceDirectives7.ts index f18fed37741..79d42fa7018 100644 --- a/tests/cases/compiler/typeReferenceDirectives7.ts +++ b/tests/cases/compiler/typeReferenceDirectives7.ts @@ -1,7 +1,7 @@ // @noImplicitReferences: true // @traceResolution: true // @declaration: true -// @typesRoot: / +// @typeRoots: /types // local value shadows global - no need to add type reference directive diff --git a/tests/cases/compiler/typeReferenceDirectives8.ts b/tests/cases/compiler/typeReferenceDirectives8.ts index 2465d2afb10..c7725a3aab1 100644 --- a/tests/cases/compiler/typeReferenceDirectives8.ts +++ b/tests/cases/compiler/typeReferenceDirectives8.ts @@ -1,6 +1,6 @@ // @noImplicitReferences: true // @declaration: true -// @typesRoot: / +// @typeRoots: /types // @traceResolution: true // @types: lib diff --git a/tests/cases/compiler/typeReferenceDirectives9.ts b/tests/cases/compiler/typeReferenceDirectives9.ts index eb8d6abaef1..610c7173c89 100644 --- a/tests/cases/compiler/typeReferenceDirectives9.ts +++ b/tests/cases/compiler/typeReferenceDirectives9.ts @@ -1,6 +1,6 @@ // @noImplicitReferences: true // @declaration: true -// @typesRoot: / +// @typeRoots: /types // @traceResolution: true // @filename: /types/lib/index.d.ts diff --git a/tests/cases/conformance/references/library-reference-1.ts b/tests/cases/conformance/references/library-reference-1.ts index ca25441521f..c6b6cea36ef 100644 --- a/tests/cases/conformance/references/library-reference-1.ts +++ b/tests/cases/conformance/references/library-reference-1.ts @@ -1,13 +1,14 @@ // @noImplicitReferences: true // @traceResolution: true -// @typesRoot: / +// @currentDirectory: /src +// @typeRoots: types // We can find typings in the ./types folder -// @filename: /types/jquery/index.d.ts +// @filename: /src/types/jquery/index.d.ts declare var $: { foo(): void }; -// @filename: /consumer.ts +// @filename: /src/consumer.ts /// $.foo(); diff --git a/tests/cases/conformance/references/library-reference-10.ts b/tests/cases/conformance/references/library-reference-10.ts index 11e065b0a7d..bc9ec99edcf 100644 --- a/tests/cases/conformance/references/library-reference-10.ts +++ b/tests/cases/conformance/references/library-reference-10.ts @@ -1,18 +1,19 @@ // @noImplicitReferences: true // @traceResolution: true -// @typesRoot: / +// @currentDirectory: /foo +// @typeRoots: ./types // package.json in a primary reference can refer to another file -// @filename: /types/jquery/package.json +// @filename: /foo/types/jquery/package.json { "typings": "jquery.d.ts" } -// @filename: /types/jquery/jquery.d.ts +// @filename: /foo/types/jquery/jquery.d.ts declare var $: { foo(): void }; -// @filename: /consumer.ts +// @filename: /foo/consumer.ts /// $.foo(); diff --git a/tests/cases/conformance/references/library-reference-13.ts b/tests/cases/conformance/references/library-reference-13.ts index a96437f9b2c..92b4b259ba4 100644 --- a/tests/cases/conformance/references/library-reference-13.ts +++ b/tests/cases/conformance/references/library-reference-13.ts @@ -6,7 +6,8 @@ // @filename: /a/tsconfig.json { "compilerOptions": { - "types": [ "jquery" ] + "types": [ "jquery" ], + "typeRoots": ["/a/types"] } } diff --git a/tests/cases/conformance/references/library-reference-14.ts b/tests/cases/conformance/references/library-reference-14.ts index 53bca2ab40d..fa4a63cfcc0 100644 --- a/tests/cases/conformance/references/library-reference-14.ts +++ b/tests/cases/conformance/references/library-reference-14.ts @@ -1,7 +1,8 @@ // @noImplicitReferences: true // @traceResolution: true // @types: jquery -// @typesRoot: /a +// @typeRoots: /a/types +// @currentDirectory: /a // @filename: /a/types/jquery/index.d.ts declare var $: { foo(): void }; diff --git a/tests/cases/conformance/references/library-reference-15.ts b/tests/cases/conformance/references/library-reference-15.ts index dd2179d1af6..417012a4539 100644 --- a/tests/cases/conformance/references/library-reference-15.ts +++ b/tests/cases/conformance/references/library-reference-15.ts @@ -1,11 +1,15 @@ // @noImplicitReferences: true // @traceResolution: true // @types: jquery -// @currentDirectory: / +// @currentDirectory: /a +// @typeRoots: types // @filename: /a/types/jquery/index.d.ts declare var $: { foo(): void }; +// @filename: /a/types/jquery2/index.d.ts +declare var $2: { foo(): void }; // @filename: /a/b/consumer.ts -$.foo(); +$.foo(); // should OK +$2.foo(); // should error \ No newline at end of file diff --git a/tests/cases/conformance/references/library-reference-2.ts b/tests/cases/conformance/references/library-reference-2.ts index d8975664428..9ac7cd4f4d3 100644 --- a/tests/cases/conformance/references/library-reference-2.ts +++ b/tests/cases/conformance/references/library-reference-2.ts @@ -1,6 +1,7 @@ // @noImplicitReferences: true // @traceResolution: true -// @typesRoot: / +// @typeRoots: /types +// @currentDirectory: test // package.json in a primary reference can refer to another file diff --git a/tests/cases/conformance/references/library-reference-3.ts b/tests/cases/conformance/references/library-reference-3.ts index 1af6df89d19..88ef916eaae 100644 --- a/tests/cases/conformance/references/library-reference-3.ts +++ b/tests/cases/conformance/references/library-reference-3.ts @@ -1,6 +1,6 @@ // @noImplicitReferences: true // @traceResolution: true -// @typesRoot: /src +// @currentDirectory: /src // Secondary references are possible diff --git a/tests/cases/conformance/references/library-reference-4.ts b/tests/cases/conformance/references/library-reference-4.ts index 92f1b4008be..9a615f470ef 100644 --- a/tests/cases/conformance/references/library-reference-4.ts +++ b/tests/cases/conformance/references/library-reference-4.ts @@ -1,6 +1,7 @@ // @noImplicitReferences: true // @traceResolution: true -// @typesRoot: /src +// @typeRoots: /src +// @currentDirectory: test // Secondary references may be duplicated if they agree in content diff --git a/tests/cases/conformance/references/library-reference-5.ts b/tests/cases/conformance/references/library-reference-5.ts index 1fe327a1c69..dd72da36dd0 100644 --- a/tests/cases/conformance/references/library-reference-5.ts +++ b/tests/cases/conformance/references/library-reference-5.ts @@ -1,6 +1,7 @@ // @noImplicitReferences: true // @traceResolution: true // @currentDirectory: / +// @typeRoots: types // Secondary references may not be duplicated if they disagree in content diff --git a/tests/cases/conformance/references/library-reference-6.ts b/tests/cases/conformance/references/library-reference-6.ts index a746262dd73..765a6760aa4 100644 --- a/tests/cases/conformance/references/library-reference-6.ts +++ b/tests/cases/conformance/references/library-reference-6.ts @@ -1,9 +1,10 @@ // @noImplicitReferences: true // @traceResolution: true +// @currentDirectory: / // The primary lookup folder is relative to tsconfig.json, if present -// @filename: /types/alpha/index.d.ts +// @filename: /node_modules/@types/alpha/index.d.ts declare var alpha: { a: string }; // @filename: /src/foo.ts @@ -12,4 +13,7 @@ var x: string = alpha.a; // @filename: /tsconfig.json { + "compilerOptions": { + "typesRoot": "types" + } } diff --git a/tests/cases/conformance/references/library-reference-8.ts b/tests/cases/conformance/references/library-reference-8.ts index 9de93776989..1c4ab76f8a1 100644 --- a/tests/cases/conformance/references/library-reference-8.ts +++ b/tests/cases/conformance/references/library-reference-8.ts @@ -1,18 +1,19 @@ // @noImplicitReferences: true // @traceResolution: true -// @typesRoot: / +// @typeRoots: /test/types +// @currentDirectory: /test // Don't crash in circular library reference situations -// @filename: /types/alpha/index.d.ts +// @filename: /test/types/alpha/index.d.ts /// declare var alpha: { a: string }; -// @filename: /types/beta/index.d.ts +// @filename: /test/types/beta/index.d.ts /// declare var beta: { b: string }; -// @filename: /foo.ts +// @filename: /test/foo.ts /// /// var x: string = alpha.a + beta.b; diff --git a/tests/cases/conformance/references/library-reference-9.ts b/tests/cases/conformance/references/library-reference-9.ts deleted file mode 100644 index a187d3c23b9..00000000000 --- a/tests/cases/conformance/references/library-reference-9.ts +++ /dev/null @@ -1,20 +0,0 @@ -// @noImplicitReferences: true -// @traceResolution: true - -// Use types search path - -// @filename: /share/typelib/alpha/index.d.ts -declare var alpha: { a: string }; - -// @filename: /base/src/foo.ts -/// -var x: string = alpha.a; - -// @filename: /tsconfig.json -{ - "compilerOptions": { - "typesSearchPaths": [ - "./share/typelib" - ] - } -} diff --git a/tests/cases/conformance/typings/typingsLookup1.ts b/tests/cases/conformance/typings/typingsLookup1.ts index 702bd4bc21c..555d4569af3 100644 --- a/tests/cases/conformance/typings/typingsLookup1.ts +++ b/tests/cases/conformance/typings/typingsLookup1.ts @@ -1,10 +1,12 @@ +// @traceResolution: true // @noImplicitReferences: true -// @filename: tsconfig.json +// @filename: /tsconfig.json { "files": "a.ts" } -// @filename: node_modules/@types/jquery/index.d.ts +// @filename: /node_modules/@types/jquery/index.d.ts declare var $: { x: any }; -// @filename: a.ts +// @filename: /a.ts +/// $.x; diff --git a/tests/cases/fourslash/goToDefinitionTypeReferenceDirective.ts b/tests/cases/fourslash/goToDefinitionTypeReferenceDirective.ts index 3aaa3ab980f..78dfa94c5e4 100644 --- a/tests/cases/fourslash/goToDefinitionTypeReferenceDirective.ts +++ b/tests/cases/fourslash/goToDefinitionTypeReferenceDirective.ts @@ -1,6 +1,6 @@ /// -// @typesRoot: src +// @typeRoots: src/types // @Filename: src/types/lib/index.d.ts /////*0*/declare let $: {x: number}; diff --git a/tests/cases/fourslash/shims-pp/goToDefinitionTypeReferenceDirective.ts b/tests/cases/fourslash/shims-pp/goToDefinitionTypeReferenceDirective.ts index 3aaa3ab980f..78dfa94c5e4 100644 --- a/tests/cases/fourslash/shims-pp/goToDefinitionTypeReferenceDirective.ts +++ b/tests/cases/fourslash/shims-pp/goToDefinitionTypeReferenceDirective.ts @@ -1,6 +1,6 @@ /// -// @typesRoot: src +// @typeRoots: src/types // @Filename: src/types/lib/index.d.ts /////*0*/declare let $: {x: number}; diff --git a/tests/cases/fourslash/shims/goToDefinitionTypeReferenceDirective.ts b/tests/cases/fourslash/shims/goToDefinitionTypeReferenceDirective.ts index 3aaa3ab980f..dc2fc356c57 100644 --- a/tests/cases/fourslash/shims/goToDefinitionTypeReferenceDirective.ts +++ b/tests/cases/fourslash/shims/goToDefinitionTypeReferenceDirective.ts @@ -1,6 +1,6 @@ -/// +/// -// @typesRoot: src +// @typeRoots: src/types // @Filename: src/types/lib/index.d.ts /////*0*/declare let $: {x: number}; diff --git a/tests/cases/unittests/moduleResolution.ts b/tests/cases/unittests/moduleResolution.ts index ab5eddc0997..16fc7df8d70 100644 --- a/tests/cases/unittests/moduleResolution.ts +++ b/tests/cases/unittests/moduleResolution.ts @@ -314,6 +314,7 @@ namespace ts { getDefaultLibFileName: () => "lib.d.ts", writeFile: (fileName, content): void => { throw new Error("NotImplemented"); }, getCurrentDirectory: () => currentDirectory, + getDirectories: () => [], getCanonicalFileName: fileName => fileName.toLowerCase(), getNewLine: () => "\r\n", useCaseSensitiveFileNames: () => false, @@ -397,6 +398,7 @@ export = C; getDefaultLibFileName: () => "lib.d.ts", writeFile: (fileName, content): void => { throw new Error("NotImplemented"); }, getCurrentDirectory: () => currentDirectory, + getDirectories: () => [], getCanonicalFileName, getNewLine: () => "\r\n", useCaseSensitiveFileNames: () => useCaseSensitiveFileNames, @@ -955,7 +957,7 @@ import b = require("./moduleB.ts"); describe("Type reference directive resolution: ", () => { function test(typesRoot: string, typeDirective: string, primary: boolean, initialFile: File, targetFile: File, ...otherFiles: File[]) { const host = createModuleResolutionHost(/*hasDirectoryExists*/ false, ...[initialFile, targetFile].concat(...otherFiles)); - const result = resolveTypeReferenceDirective(typeDirective, initialFile.name, {typesRoot}, host); + const result = resolveTypeReferenceDirective(typeDirective, initialFile.name, {typeRoots: [typesRoot]}, host); assert(result.resolvedTypeReferenceDirective.resolvedFileName !== undefined, "expected type directive to be resolved"); assert.equal(result.resolvedTypeReferenceDirective.resolvedFileName, targetFile.name, "unexpected result of type reference resolution"); assert.equal(result.resolvedTypeReferenceDirective.primary, primary, "unexpected 'primary' value"); @@ -965,64 +967,64 @@ import b = require("./moduleB.ts"); { const f1 = { name: "/root/src/app.ts" }; const f2 = { name: "/root/src/types/lib/index.d.ts" }; - test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2); + test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ true, f1, f2); } { const f1 = { name: "/root/src/app.ts" }; const f2 = { name: "/root/src/types/lib/typings/lib.d.ts" }; const package = { name: "/root/src/types/lib/package.json", content: JSON.stringify({types: "typings/lib.d.ts"}) }; - test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2, package); + test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ true, f1, f2, package); } { const f1 = { name: "/root/src/app.ts" }; const f2 = { name: "/root/src/node_modules/lib/index.d.ts" }; - test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2); + test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2); } { const f1 = { name: "/root/src/app.ts" }; const f2 = { name: "/root/src/node_modules/lib/typings/lib.d.ts" }; const package = { name: "/root/src/node_modules/lib/package.json", content: JSON.stringify({types: "typings/lib.d.ts"}) }; - test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2, package); + test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2, package); } { const f1 = { name: "/root/src/app.ts" }; const f2 = { name: "/root/src/node_modules/@types/lib/index.d.ts" }; - test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2); + test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2); } { const f1 = { name: "/root/src/app.ts" }; const f2 = { name: "/root/src/node_modules/@types/lib/typings/lib.d.ts" }; const package = { name: "/root/src/node_modules/@types/lib/package.json", content: JSON.stringify({types: "typings/lib.d.ts"}) }; - test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2, package); + test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2, package); } }); it("Can be resolved from secondary location", () => { { const f1 = { name: "/root/src/app.ts" }; const f2 = { name: "/root/node_modules/lib.d.ts" }; - test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ false, f1, f2); + test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2); } { const f1 = { name: "/root/src/app.ts" }; const f2 = { name: "/root/node_modules/lib/index.d.ts" }; - test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ false, f1, f2); + test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2); } { const f1 = { name: "/root/src/app.ts" }; const f2 = { name: "/root/node_modules/lib/typings/lib.d.ts" }; const package = { name: "/root/node_modules/lib/package.json", content: JSON.stringify({typings: "typings/lib.d.ts"}) }; - test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ false, f1, f2, package); + test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2, package); } { const f1 = { name: "/root/src/app.ts" }; const f2 = { name: "/root/node_modules/@types/lib/index.d.ts" }; - test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ false, f1, f2); + test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2); } { const f1 = { name: "/root/src/app.ts" }; const f2 = { name: "/root/node_modules/@types/lib/typings/lib.d.ts" }; const package = { name: "/root/node_modules/@types/lib/package.json", content: JSON.stringify({typings: "typings/lib.d.ts"}) }; - test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ false, f1, f2, package); + test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ false, f1, f2, package); } }); it("Primary resolution overrides secondary resolutions", () => { @@ -1030,7 +1032,7 @@ import b = require("./moduleB.ts"); const f1 = { name: "/root/src/a/b/c/app.ts" }; const f2 = { name: "/root/src/types/lib/index.d.ts" }; const f3 = { name: "/root/src/a/b/node_modules/lib.d.ts" }; - test(/*typesRoot*/"/root/src", /* typeDirective */"lib", /*primary*/ true, f1, f2, f3); + test(/*typesRoot*/"/root/src/types", /* typeDirective */"lib", /*primary*/ true, f1, f2, f3); } }); it("Reused program keeps errors", () => { @@ -1050,6 +1052,7 @@ import b = require("./moduleB.ts"); throw new Error("NYI"); }, getCurrentDirectory: () => "/", + getDirectories: () => [], getCanonicalFileName: f => f.toLowerCase(), getNewLine: () => "\r\n", useCaseSensitiveFileNames: () => false, diff --git a/tests/cases/unittests/reuseProgramStructure.ts b/tests/cases/unittests/reuseProgramStructure.ts index 6ab90595f9f..154cfdd702f 100644 --- a/tests/cases/unittests/reuseProgramStructure.ts +++ b/tests/cases/unittests/reuseProgramStructure.ts @@ -117,6 +117,9 @@ namespace ts { getCurrentDirectory(): string { return ""; }, + getDirectories(path: string): string[] { + return []; + }, getCanonicalFileName(fileName): string { return sys && sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase(); }, @@ -336,7 +339,7 @@ namespace ts { { name: "/a.ts", text: SourceText.New("/// ", "", "var x = $") }, { name: "/types/typedefs/index.d.ts", text: SourceText.New("", "", "declare var $: number") }, ]; - const options: CompilerOptions = { target, typesRoot: "/" }; + const options: CompilerOptions = { target, typeRoots: ["/types"] }; const program_1 = newProgram(files, ["/a.ts"], options); checkResolvedTypeDirectivesCache(program_1, "/a.ts", { "typedefs": { resolvedFileName: "/types/typedefs/index.d.ts", primary: true } }); From 81d1ccfe87d8c872deaebe490d29ba6bb1a2fe88 Mon Sep 17 00:00:00 2001 From: Yui Date: Fri, 10 Jun 2016 18:22:20 -0700 Subject: [PATCH 12/37] Only inlineSourceMap when debugging through jake-browser (#9080) * Only inlineSourceMap when debugging through jake-browser * Address PR: fix typo in opt's property --- Jakefile.js | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index 85ae5f60361..df8edc7dded 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -276,6 +276,7 @@ var builtLocalCompiler = path.join(builtLocalDirectory, compilerFilename); * @param {boolean} opts.noResolve: true if compiler should not include non-rooted files in compilation * @param {boolean} opts.stripInternal: true if compiler should remove declarations marked as @internal * @param {boolean} opts.noMapRoot: true if compiler omit mapRoot option + * @param {boolean} opts.inlineSourceMap: true if compiler should inline sourceMap * @param callback: a function to execute after the compilation process ends */ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts, callback) { @@ -313,7 +314,14 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts } if (useDebugMode) { - options += " --inlineSourceMap --inlineSources"; + if (opts.inlineSourceMap) { + options += " --inlineSourceMap --inlineSources"; + } else { + options += " -sourcemap"; + if (!opts.noMapRoot) { + options += " -mapRoot file:///" + path.resolve(path.dirname(outFile)); + } + } } else { options += " --newLine LF"; } @@ -483,6 +491,7 @@ var tscFile = path.join(builtLocalDirectory, compilerFilename); compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false); var servicesFile = path.join(builtLocalDirectory, "typescriptServices.js"); +var servicesFileInBrowserTest = path.join(builtLocalDirectory, "typescriptServicesInBrowserTest.js"); var standaloneDefinitionsFile = path.join(builtLocalDirectory, "typescriptServices.d.ts"); var nodePackageFile = path.join(builtLocalDirectory, "typescript.js"); var nodeDefinitionsFile = path.join(builtLocalDirectory, "typescript.d.ts"); @@ -491,7 +500,13 @@ var nodeStandaloneDefinitionsFile = path.join(builtLocalDirectory, "typescript_s compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].concat(servicesSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, - { noOutFile: false, generateDeclarations: true, preserveConstEnums: true, keepComments: true, noResolve: false, stripInternal: true }, + /*opts*/ { noOutFile: false, + generateDeclarations: true, + preserveConstEnums: true, + keepComments: true, + noResolve: false, + stripInternal: true + }, /*callback*/ function () { jake.cpR(servicesFile, nodePackageFile, {silent: true}); @@ -514,6 +529,21 @@ compileFile(servicesFile, servicesSources,[builtLocalDirectory, copyright].conca fs.writeFileSync(nodeStandaloneDefinitionsFile, nodeStandaloneDefinitionsFileContents); }); +compileFile( + servicesFileInBrowserTest, + servicesSources, + [builtLocalDirectory, copyright].concat(servicesSources), + /*prefixes*/ [copyright], + /*useBuiltCompiler*/ true, + { noOutFile: false, + generateDeclarations: true, + preserveConstEnums: true, + keepComments: true, + noResolve: false, + stripInternal: true, + noMapRoot: true, + inlineSourceMap: true + }); var serverFile = path.join(builtLocalDirectory, "tsserver.js"); compileFile(serverFile, serverSources,[builtLocalDirectory, copyright].concat(serverSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true); @@ -614,7 +644,13 @@ directory(builtLocalDirectory); // Task to build the tests infrastructure using the built compiler var run = path.join(builtLocalDirectory, "run.js"); -compileFile(run, harnessSources, [builtLocalDirectory, tscFile].concat(libraryTargets).concat(harnessSources), [], /*useBuiltCompiler:*/ true); +compileFile( + /*outFile*/ run, + /*source*/ harnessSources, + /*prereqs*/ [builtLocalDirectory, tscFile].concat(libraryTargets).concat(harnessSources), + /*prefixes*/ [], + /*useBuiltCompiler:*/ true, + /*opts*/ { inlineSourceMap: true }); var internalTests = "internal/"; @@ -813,7 +849,7 @@ task("browserify", ["tests", builtLocalDirectory, nodeServerOutFile], function() }, {async: true}); desc("Runs the tests using the built run.js file like 'jake runtests'. Syntax is jake runtests-browser. Additional optional parameters tests=[regex], port=, browser=[chrome|IE]"); -task("runtests-browser", ["tests", "browserify", builtLocalDirectory, servicesFile], function() { +task("runtests-browser", ["tests", "browserify", builtLocalDirectory, servicesFileInBrowserTest], function() { cleanTestDirs(); host = "node"; port = process.env.port || process.env.p || '8888'; From 61534225e558fd905cbc0bc1bfaa98c59a612ab1 Mon Sep 17 00:00:00 2001 From: york yao Date: Mon, 13 Jun 2016 18:48:39 +0800 Subject: [PATCH 13/37] minor fix: add missing return clause --- src/compiler/utilities.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index bf163b47c05..b4f00917b1f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -830,6 +830,8 @@ namespace ts { case SyntaxKind.ConstructorType: return true; } + + return false; } export function introducesArgumentsExoticObject(node: Node) { From fb050f17f6845215bb32cea5493a274cf741cbf2 Mon Sep 17 00:00:00 2001 From: Yui Date: Mon, 13 Jun 2016 09:23:37 -0700 Subject: [PATCH 14/37] Use camel-case instead of snake-case (#9134) --- src/services/services.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index 13df3a54a30..a8b4acdeaf6 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1941,17 +1941,17 @@ namespace ts { - let commandLineOptions_stringToEnum: CommandLineOptionOfCustomType[]; + let commandLineOptionsStringToEnum: CommandLineOptionOfCustomType[]; /** JS users may pass in string values for enum compiler options (such as ModuleKind), so convert. */ function fixupCompilerOptions(options: CompilerOptions, diagnostics: Diagnostic[]): CompilerOptions { // Lazily create this value to fix module loading errors. - commandLineOptions_stringToEnum = commandLineOptions_stringToEnum || filter(optionDeclarations, o => + commandLineOptionsStringToEnum = commandLineOptionsStringToEnum || filter(optionDeclarations, o => typeof o.type === "object" && !forEachValue(> o.type, v => typeof v !== "number")); options = clone(options); - for (const opt of commandLineOptions_stringToEnum) { + for (const opt of commandLineOptionsStringToEnum) { if (!hasProperty(options, opt.name)) { continue; } From e8ac1abbd6b3b1b720e39190b74252c76edab043 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 13 Jun 2016 09:33:49 -0700 Subject: [PATCH 15/37] Baseline fix, CR comments, lint --- src/compiler/commandLineParser.ts | 5 ++-- src/compiler/program.ts | 4 +-- src/compiler/types.ts | 2 +- src/server/editorServices.ts | 2 +- src/services/services.ts | 2 +- .../reference/library-reference-6.symbols | 16 ++++++++++ .../reference/library-reference-6.trace.json | 30 +++++-------------- .../reference/library-reference-6.types | 16 ++++++++++ .../moduleResolutionWithExtensions.trace.json | 4 +++ 9 files changed, 51 insertions(+), 30 deletions(-) create mode 100644 tests/baselines/reference/library-reference-6.symbols create mode 100644 tests/baselines/reference/library-reference-6.types diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 74bfdf3e961..9e9fb8e2ee2 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -341,8 +341,9 @@ namespace ts { type: "list", element: { name: "typeRoots", - type: "string" - } + type: "string", + isFilePath: true + } }, { name: "types", diff --git a/src/compiler/program.ts b/src/compiler/program.ts index f6cc048ace6..9cb000a4d61 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -217,9 +217,9 @@ namespace ts { // Check primary library paths if (typeRoots.length) { if (traceEnabled) { - trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(', ')); + trace(host, Diagnostics.Resolving_with_primary_search_path_0, typeRoots.join(", ")); } - const primarySearchPaths = options.typeRoots || defaultTypeRoots; + const primarySearchPaths = typeRoots; for (const typeRoot of primarySearchPaths) { const candidate = combinePaths(typeRoot, typeReferenceDirectiveName); const candidateDirectory = getDirectoryPath(candidate); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index d9edd5a76c4..db34bb7c6e8 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -2562,7 +2562,7 @@ namespace ts { target?: ScriptTarget; traceResolution?: boolean; types?: string[]; - // Paths used to used to compute primary types search locations + /** Paths used to used to compute primary types search locations */ typeRoots?: string[]; typesSearchPaths?: string[]; /*@internal*/ version?: boolean; diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 53b0c28671f..b887b5c7256 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -316,7 +316,7 @@ namespace ts.server { } getDirectories(path: string): string[] { - return this.host.getDirectories ? this.host.getDirectories(path) : []; + return this.host.getDirectories(path); } /** diff --git a/src/services/services.ts b/src/services/services.ts index 6d29310f93c..ba157afaf9f 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2141,7 +2141,7 @@ namespace ts { const getCanonicalFileName = createGetCanonicalFileName(!!useCaseSensitiveFileNames); function getKeyForCompilationSettings(settings: CompilerOptions): DocumentRegistryBucketKey { - return `_${settings.target}|${settings.module}|${settings.noResolve}|${settings.jsx}|${settings.allowJs}|${settings.baseUrl}|${settings.typeRoots}|${JSON.stringify(settings.rootDirs)}|${JSON.stringify(settings.paths)}`; + return `_${settings.target}|${settings.module}|${settings.noResolve}|${settings.jsx}|${settings.allowJs}|${settings.baseUrl}|${JSON.stringify(settings.typeRoots)}|${JSON.stringify(settings.rootDirs)}|${JSON.stringify(settings.paths)}`; } function getBucketForCompilationSettings(key: DocumentRegistryBucketKey, createIfMissing: boolean): FileMap { diff --git a/tests/baselines/reference/library-reference-6.symbols b/tests/baselines/reference/library-reference-6.symbols new file mode 100644 index 00000000000..595d43df3fa --- /dev/null +++ b/tests/baselines/reference/library-reference-6.symbols @@ -0,0 +1,16 @@ +=== /src/foo.ts === +/// +var x: string = alpha.a; +>x : Symbol(x, Decl(foo.ts, 1, 3)) +>alpha.a : Symbol(a, Decl(index.d.ts, 3, 20)) +>alpha : Symbol(alpha, Decl(index.d.ts, 3, 11)) +>a : Symbol(a, Decl(index.d.ts, 3, 20)) + +=== /node_modules/@types/alpha/index.d.ts === + +// The primary lookup folder is relative to tsconfig.json, if present + +declare var alpha: { a: string }; +>alpha : Symbol(alpha, Decl(index.d.ts, 3, 11)) +>a : Symbol(a, Decl(index.d.ts, 3, 20)) + diff --git a/tests/baselines/reference/library-reference-6.trace.json b/tests/baselines/reference/library-reference-6.trace.json index fc29f3f2478..21843c2ecf4 100644 --- a/tests/baselines/reference/library-reference-6.trace.json +++ b/tests/baselines/reference/library-reference-6.trace.json @@ -2,27 +2,11 @@ "======== Resolving type reference directive 'alpha', containing file '/src/foo.ts', root directory 'node_modules/@types'. ========", "Resolving with primary search path 'node_modules/@types'", "File 'node_modules/@types/alpha/package.json' does not exist.", - "File 'node_modules/@types/alpha/index.d.ts' does not exist.", - "Looking up in 'node_modules' folder, initial location '/src'", - "File '/src/node_modules/alpha.ts' does not exist.", - "File '/src/node_modules/alpha.d.ts' does not exist.", - "File '/src/node_modules/alpha/package.json' does not exist.", - "File '/src/node_modules/alpha/index.ts' does not exist.", - "File '/src/node_modules/alpha/index.d.ts' does not exist.", - "File '/src/node_modules/@types/alpha.ts' does not exist.", - "File '/src/node_modules/@types/alpha.d.ts' does not exist.", - "File '/src/node_modules/@types/alpha/package.json' does not exist.", - "File '/src/node_modules/@types/alpha/index.ts' does not exist.", - "File '/src/node_modules/@types/alpha/index.d.ts' does not exist.", - "File '/node_modules/alpha.ts' does not exist.", - "File '/node_modules/alpha.d.ts' does not exist.", - "File '/node_modules/alpha/package.json' does not exist.", - "File '/node_modules/alpha/index.ts' does not exist.", - "File '/node_modules/alpha/index.d.ts' does not exist.", - "File '/node_modules/@types/alpha.ts' does not exist.", - "File '/node_modules/@types/alpha.d.ts' does not exist.", - "File '/node_modules/@types/alpha/package.json' does not exist.", - "File '/node_modules/@types/alpha/index.ts' does not exist.", - "File '/node_modules/@types/alpha/index.d.ts' does not exist.", - "======== Type reference directive 'alpha' was not resolved. ========" + "File 'node_modules/@types/alpha/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'alpha' was successfully resolved to 'node_modules/@types/alpha/index.d.ts', primary: true. ========", + "======== Resolving type reference directive 'alpha', containing file '/src/__inferred type names__.ts', root directory 'node_modules/@types'. ========", + "Resolving with primary search path 'node_modules/@types'", + "File 'node_modules/@types/alpha/package.json' does not exist.", + "File 'node_modules/@types/alpha/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'alpha' was successfully resolved to 'node_modules/@types/alpha/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-6.types b/tests/baselines/reference/library-reference-6.types new file mode 100644 index 00000000000..e2762c0943a --- /dev/null +++ b/tests/baselines/reference/library-reference-6.types @@ -0,0 +1,16 @@ +=== /src/foo.ts === +/// +var x: string = alpha.a; +>x : string +>alpha.a : string +>alpha : { a: string; } +>a : string + +=== /node_modules/@types/alpha/index.d.ts === + +// The primary lookup folder is relative to tsconfig.json, if present + +declare var alpha: { a: string }; +>alpha : { a: string; } +>a : string + diff --git a/tests/baselines/reference/moduleResolutionWithExtensions.trace.json b/tests/baselines/reference/moduleResolutionWithExtensions.trace.json index 6e6589d7c1f..7dc9e8c104b 100644 --- a/tests/baselines/reference/moduleResolutionWithExtensions.trace.json +++ b/tests/baselines/reference/moduleResolutionWithExtensions.trace.json @@ -3,11 +3,13 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/src/a'.", "File '/src/a.ts' exist - use it as a name resolution result.", + "Resolving real path for '/src/a.ts', result '/src/a.ts'", "======== Module name './a' was successfully resolved to '/src/a.ts'. ========", "======== Resolving module './a.ts' from '/src/c.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/src/a.ts'.", "File '/src/a.ts' exist - use it as a name resolution result.", + "Resolving real path for '/src/a.ts', result '/src/a.ts'", "======== Module name './a.ts' was successfully resolved to '/src/a.ts'. ========", "======== Resolving module './a.js' from '/src/d.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -17,6 +19,7 @@ "File '/src/a.js.d.ts' does not exist.", "File name '/src/a.js' has a '.js' extension - stripping it", "File '/src/a.ts' exist - use it as a name resolution result.", + "Resolving real path for '/src/a.ts', result '/src/a.ts'", "======== Module name './a.js' was successfully resolved to '/src/a.ts'. ========", "======== Resolving module './jquery.js' from '/src/jquery_user_1.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -28,5 +31,6 @@ "File '/src/jquery.ts' does not exist.", "File '/src/jquery.tsx' does not exist.", "File '/src/jquery.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/src/jquery.d.ts', result '/src/jquery.d.ts'", "======== Module name './jquery.js' was successfully resolved to '/src/jquery.d.ts'. ========" ] \ No newline at end of file From 6702e651a3e6de28a9a751d2c4282494412a0081 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 13 Jun 2016 10:15:29 -0700 Subject: [PATCH 16/37] CR changes --- src/compiler/program.ts | 4 +++- .../reference/typingsLookup1.trace.json | 16 ++++++++++++++++ .../references/library-reference-6.ts | 3 --- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 9cb000a4d61..59ae0d862ad 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -1031,7 +1031,9 @@ namespace ts { // Walk the primary type lookup locations let result: string[] = []; if (host.directoryExists && host.getDirectories) { - for (const root of options.typeRoots || defaultTypeRoots) { + const typeRoots = options.typeRoots || + defaultTypeRoots.map(d => combinePaths(options.configFilePath ? getDirectoryPath(options.configFilePath) : host.getCurrentDirectory(), d)); + for (const root of typeRoots) { if (host.directoryExists(root)) { result = result.concat(host.getDirectories(root)); } diff --git a/tests/baselines/reference/typingsLookup1.trace.json b/tests/baselines/reference/typingsLookup1.trace.json index 0463c920bd3..ad0354157c3 100644 --- a/tests/baselines/reference/typingsLookup1.trace.json +++ b/tests/baselines/reference/typingsLookup1.trace.json @@ -14,5 +14,21 @@ "File '/node_modules/@types/jquery/package.json' does not exist.", "File '/node_modules/@types/jquery/index.ts' does not exist.", "File '/node_modules/@types/jquery/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: false. ========", + "======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory 'node_modules/@types'. ========", + "Resolving with primary search path 'node_modules/@types'", + "File 'node_modules/@types/jquery/package.json' does not exist.", + "File 'node_modules/@types/jquery/index.d.ts' does not exist.", + "Looking up in 'node_modules' folder, initial location '/'", + "File '/node_modules/jquery.ts' does not exist.", + "File '/node_modules/jquery.d.ts' does not exist.", + "File '/node_modules/jquery/package.json' does not exist.", + "File '/node_modules/jquery/index.ts' does not exist.", + "File '/node_modules/jquery/index.d.ts' does not exist.", + "File '/node_modules/@types/jquery.ts' does not exist.", + "File '/node_modules/@types/jquery.d.ts' does not exist.", + "File '/node_modules/@types/jquery/package.json' does not exist.", + "File '/node_modules/@types/jquery/index.ts' does not exist.", + "File '/node_modules/@types/jquery/index.d.ts' exist - use it as a name resolution result.", "======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: false. ========" ] \ No newline at end of file diff --git a/tests/cases/conformance/references/library-reference-6.ts b/tests/cases/conformance/references/library-reference-6.ts index 765a6760aa4..13ad382e636 100644 --- a/tests/cases/conformance/references/library-reference-6.ts +++ b/tests/cases/conformance/references/library-reference-6.ts @@ -13,7 +13,4 @@ var x: string = alpha.a; // @filename: /tsconfig.json { - "compilerOptions": { - "typesRoot": "types" - } } From 89488f83171a0eb9118e825b86410cab88dca4c6 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 13 Jun 2016 12:08:31 -0700 Subject: [PATCH 17/37] Add test for jsdoc in navigation bar --- tests/cases/fourslash/navigationBarJsDoc.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/cases/fourslash/navigationBarJsDoc.ts diff --git a/tests/cases/fourslash/navigationBarJsDoc.ts b/tests/cases/fourslash/navigationBarJsDoc.ts new file mode 100644 index 00000000000..20a235bce95 --- /dev/null +++ b/tests/cases/fourslash/navigationBarJsDoc.ts @@ -0,0 +1,21 @@ +/// + +// @Filename: foo.js +/////** @typedef {(number|string)} NumberLike */ +/////** @typedef {(string|number)} */ +////const x = 0; + +verify.navigationBar([ + { + "text": "NumberLike", + "kind": "type" + }, + { + "text": "x", + "kind": "type" + }, + { + "text": "x", + "kind": "var" + } +]); From 3dca09b200454af40d9cd4da05f9d74b71e442eb Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Mon, 13 Jun 2016 12:58:21 -0700 Subject: [PATCH 18/37] Fixes runtests-parallel not reporting failure for failed tests. --- scripts/mocha-parallel.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/mocha-parallel.js b/scripts/mocha-parallel.js index cc695729cbd..bf33f68f204 100644 --- a/scripts/mocha-parallel.js +++ b/scripts/mocha-parallel.js @@ -193,7 +193,6 @@ function runTests(taskConfigsFolder, run, options, cb) { counter--; if (counter <= 0) { - var failed = 0; var reporter = new Base(), stats = reporter.stats, failures = reporter.failures; @@ -224,8 +223,8 @@ function runTests(taskConfigsFolder, run, options, cb) { reporter.epilogue(); } - if (failed) { - return cb(new Error("Test failures reported: " + failed)); + if (stats.failures) { + return cb(new Error("Test failures reported: " + stats.failures)); } else { return cb(); From c0c707c37f4464356b6408304da5a285fad8b5cf Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 13 Jun 2016 12:57:00 -0700 Subject: [PATCH 19/37] Fix decorator metadata emit for rest arg with no type --- src/compiler/emitter.ts | 4 +- .../emitDecoratorMetadata_restArgs.js | 80 +++++++++++++++++++ .../emitDecoratorMetadata_restArgs.symbols | 44 ++++++++++ .../emitDecoratorMetadata_restArgs.types | 44 ++++++++++ .../emitDecoratorMetadata_restArgs.ts | 20 +++++ 5 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/emitDecoratorMetadata_restArgs.js create mode 100644 tests/baselines/reference/emitDecoratorMetadata_restArgs.symbols create mode 100644 tests/baselines/reference/emitDecoratorMetadata_restArgs.types create mode 100644 tests/cases/compiler/emitDecoratorMetadata_restArgs.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 46362bd7827..e3f092257a3 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6133,10 +6133,10 @@ const _super = (function (geti, seti) { if (parameters[i].dotDotDotToken) { let parameterType = parameters[i].type; - if (parameterType.kind === SyntaxKind.ArrayType) { + if (parameterType && parameterType.kind === SyntaxKind.ArrayType) { parameterType = (parameterType).elementType; } - else if (parameterType.kind === SyntaxKind.TypeReference && (parameterType).typeArguments && (parameterType).typeArguments.length === 1) { + else if (parameterType && parameterType.kind === SyntaxKind.TypeReference && (parameterType).typeArguments && (parameterType).typeArguments.length === 1) { parameterType = (parameterType).typeArguments[0]; } else { diff --git a/tests/baselines/reference/emitDecoratorMetadata_restArgs.js b/tests/baselines/reference/emitDecoratorMetadata_restArgs.js new file mode 100644 index 00000000000..35350c54e0a --- /dev/null +++ b/tests/baselines/reference/emitDecoratorMetadata_restArgs.js @@ -0,0 +1,80 @@ +//// [emitDecoratorMetadata_restArgs.ts] + +declare const MyClassDecorator: ClassDecorator; +declare const MyMethodDecorator: MethodDecorator; + +@MyClassDecorator +class A { + constructor(...args) {} + @MyMethodDecorator + method(...args) {} +} + +@MyClassDecorator +class B { + constructor(...args: number[]) {} + @MyMethodDecorator + method(...args: string[]) {} +} + + +//// [emitDecoratorMetadata_restArgs.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var A = (function () { + function A() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + } + A.prototype.method = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + }; + __decorate([ + MyMethodDecorator, + __metadata('design:type', Function), + __metadata('design:paramtypes', [Object]), + __metadata('design:returntype', void 0) + ], A.prototype, "method", null); + A = __decorate([ + MyClassDecorator, + __metadata('design:paramtypes', [Object]) + ], A); + return A; +}()); +var B = (function () { + function B() { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + } + B.prototype.method = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i - 0] = arguments[_i]; + } + }; + __decorate([ + MyMethodDecorator, + __metadata('design:type', Function), + __metadata('design:paramtypes', [String]), + __metadata('design:returntype', void 0) + ], B.prototype, "method", null); + B = __decorate([ + MyClassDecorator, + __metadata('design:paramtypes', [Number]) + ], B); + return B; +}()); diff --git a/tests/baselines/reference/emitDecoratorMetadata_restArgs.symbols b/tests/baselines/reference/emitDecoratorMetadata_restArgs.symbols new file mode 100644 index 00000000000..b665b778f86 --- /dev/null +++ b/tests/baselines/reference/emitDecoratorMetadata_restArgs.symbols @@ -0,0 +1,44 @@ +=== tests/cases/compiler/emitDecoratorMetadata_restArgs.ts === + +declare const MyClassDecorator: ClassDecorator; +>MyClassDecorator : Symbol(MyClassDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 1, 13)) +>ClassDecorator : Symbol(ClassDecorator, Decl(lib.d.ts, --, --)) + +declare const MyMethodDecorator: MethodDecorator; +>MyMethodDecorator : Symbol(MyMethodDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 2, 13)) +>MethodDecorator : Symbol(MethodDecorator, Decl(lib.d.ts, --, --)) + +@MyClassDecorator +>MyClassDecorator : Symbol(MyClassDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 1, 13)) + +class A { +>A : Symbol(A, Decl(emitDecoratorMetadata_restArgs.ts, 2, 49)) + + constructor(...args) {} +>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 6, 16)) + + @MyMethodDecorator +>MyMethodDecorator : Symbol(MyMethodDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 2, 13)) + + method(...args) {} +>method : Symbol(A.method, Decl(emitDecoratorMetadata_restArgs.ts, 6, 27)) +>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 8, 11)) +} + +@MyClassDecorator +>MyClassDecorator : Symbol(MyClassDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 1, 13)) + +class B { +>B : Symbol(B, Decl(emitDecoratorMetadata_restArgs.ts, 9, 1)) + + constructor(...args: number[]) {} +>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 13, 16)) + + @MyMethodDecorator +>MyMethodDecorator : Symbol(MyMethodDecorator, Decl(emitDecoratorMetadata_restArgs.ts, 2, 13)) + + method(...args: string[]) {} +>method : Symbol(B.method, Decl(emitDecoratorMetadata_restArgs.ts, 13, 37)) +>args : Symbol(args, Decl(emitDecoratorMetadata_restArgs.ts, 15, 11)) +} + diff --git a/tests/baselines/reference/emitDecoratorMetadata_restArgs.types b/tests/baselines/reference/emitDecoratorMetadata_restArgs.types new file mode 100644 index 00000000000..4820d3a7d8d --- /dev/null +++ b/tests/baselines/reference/emitDecoratorMetadata_restArgs.types @@ -0,0 +1,44 @@ +=== tests/cases/compiler/emitDecoratorMetadata_restArgs.ts === + +declare const MyClassDecorator: ClassDecorator; +>MyClassDecorator : (target: TFunction) => TFunction | void +>ClassDecorator : (target: TFunction) => TFunction | void + +declare const MyMethodDecorator: MethodDecorator; +>MyMethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void +>MethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void + +@MyClassDecorator +>MyClassDecorator : (target: TFunction) => TFunction | void + +class A { +>A : A + + constructor(...args) {} +>args : any[] + + @MyMethodDecorator +>MyMethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void + + method(...args) {} +>method : (...args: any[]) => void +>args : any[] +} + +@MyClassDecorator +>MyClassDecorator : (target: TFunction) => TFunction | void + +class B { +>B : B + + constructor(...args: number[]) {} +>args : number[] + + @MyMethodDecorator +>MyMethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void + + method(...args: string[]) {} +>method : (...args: string[]) => void +>args : string[] +} + diff --git a/tests/cases/compiler/emitDecoratorMetadata_restArgs.ts b/tests/cases/compiler/emitDecoratorMetadata_restArgs.ts new file mode 100644 index 00000000000..6b0741e2205 --- /dev/null +++ b/tests/cases/compiler/emitDecoratorMetadata_restArgs.ts @@ -0,0 +1,20 @@ +// @experimentaldecorators: true +// @emitdecoratormetadata: true +// @target: ES5 + +declare const MyClassDecorator: ClassDecorator; +declare const MyMethodDecorator: MethodDecorator; + +@MyClassDecorator +class A { + constructor(...args) {} + @MyMethodDecorator + method(...args) {} +} + +@MyClassDecorator +class B { + constructor(...args: number[]) {} + @MyMethodDecorator + method(...args: string[]) {} +} From 5a7f7469eae853cbe9c21612e8e4d64324d3d5da Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 13 Jun 2016 13:21:47 -0700 Subject: [PATCH 20/37] Add isDefinition to ReferenceEntry Clients can now easily tell if the reference is to a definition or a usage. --- src/server/client.ts | 1 + src/server/protocol.d.ts | 5 +++++ src/server/session.ts | 5 +++-- src/services/services.ts | 7 +++++-- src/services/shims.ts | 4 ++-- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/server/client.ts b/src/server/client.ts index b0a1a8ec9e9..ea6c948c4fb 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -376,6 +376,7 @@ namespace ts.server { fileName: fileName, textSpan: ts.createTextSpanFromBounds(start, end), isWriteAccess: entry.isWriteAccess, + isDefinition: entry.isDefinition, }; }); } diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index d2c15b308ec..dd29411f97d 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -304,6 +304,11 @@ declare namespace ts.server.protocol { * True if reference is a write location, false otherwise. */ isWriteAccess: boolean; + + /** + * True if reference is a definition, false otherwise. + */ + isDefinition?: boolean; } /** diff --git a/src/server/session.ts b/src/server/session.ts index 0ec3d87e58c..2964dc66505 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -379,7 +379,7 @@ namespace ts.server { start, end, file: fileName, - isWriteAccess + isWriteAccess, }; }); } @@ -555,7 +555,8 @@ namespace ts.server { start: start, lineText: lineText, end: compilerService.host.positionToLineOffset(ref.fileName, ts.textSpanEnd(ref.textSpan)), - isWriteAccess: ref.isWriteAccess + isWriteAccess: ref.isWriteAccess, + isDefinition: ref.isDefinition }; }); }, diff --git a/src/services/services.ts b/src/services/services.ts index 13df3a54a30..5e1b69170a5 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1208,6 +1208,7 @@ namespace ts { textSpan: TextSpan; fileName: string; isWriteAccess: boolean; + isDefinition?: boolean; } export interface DocumentHighlights { @@ -6183,7 +6184,8 @@ namespace ts { references: [{ fileName: sourceFile.fileName, textSpan: createTextSpan(position, searchText.length), - isWriteAccess: false + isWriteAccess: false, + isDefinition: false }] }); } @@ -6737,7 +6739,8 @@ namespace ts { return { fileName: node.getSourceFile().fileName, textSpan: createTextSpanFromBounds(start, end), - isWriteAccess: isWriteAccess(node) + isWriteAccess: isWriteAccess(node), + isDefinition: isDeclarationName(node) }; } diff --git a/src/services/shims.ts b/src/services/shims.ts index 94ff3367e3c..96392ca42be 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -164,7 +164,7 @@ namespace ts { /** * Returns a JSON-encoded value of the type: - * { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean }[] + * { fileName: string; textSpan: { start: number; length: number}; isWriteAccess: boolean, isDefinition?: boolean }[] */ getReferencesAtPosition(fileName: string, position: number): string; @@ -1141,4 +1141,4 @@ namespace TypeScript.Services { /* @internal */ const toolsVersion = "1.9"; -/* tslint:enable:no-unused-variable */ \ No newline at end of file +/* tslint:enable:no-unused-variable */ From ac9e617e5e1cab0e3cdd1fd9cc1d855e72df49dc Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 13 Jun 2016 13:23:32 -0700 Subject: [PATCH 21/37] Test isDefinition --- src/harness/fourslash.ts | 11 +++++---- tests/cases/fourslash/fourslash.ts | 2 +- ...tOccurrencesIsDefinitionOfArrowFunction.ts | 8 +++++++ .../getOccurrencesIsDefinitionOfClass.ts | 13 +++++++++++ .../getOccurrencesIsDefinitionOfEnum.ts | 11 +++++++++ .../getOccurrencesIsDefinitionOfFunction.ts | 9 ++++++++ .../getOccurrencesIsDefinitionOfInterface.ts | 10 ++++++++ ...rencesIsDefinitionOfInterfaceClassMerge.ts | 19 +++++++++++++++ .../getOccurrencesIsDefinitionOfNamespace.ts | 10 ++++++++ .../getOccurrencesIsDefinitionOfParameter.ts | 9 ++++++++ .../getOccurrencesIsDefinitionOfTypeAlias.ts | 8 +++++++ .../getOccurrencesIsDefinitionOfVariable.ts | 23 +++++++++++++++++++ 12 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts create mode 100644 tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts create mode 100644 tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts create mode 100644 tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts create mode 100644 tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts create mode 100644 tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts create mode 100644 tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts create mode 100644 tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts create mode 100644 tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts create mode 100644 tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index c05fca5bb47..d852a0b84f3 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -728,7 +728,7 @@ namespace FourSlash { } } - public verifyReferencesAtPositionListContains(fileName: string, start: number, end: number, isWriteAccess?: boolean) { + public verifyReferencesAtPositionListContains(fileName: string, start: number, end: number, isWriteAccess?: boolean, isDefinition?: boolean) { const references = this.getReferencesAtCaret(); if (!references || references.length === 0) { @@ -741,11 +741,14 @@ namespace FourSlash { if (typeof isWriteAccess !== "undefined" && reference.isWriteAccess !== isWriteAccess) { this.raiseError(`verifyReferencesAtPositionListContains failed - item isWriteAccess value does not match, actual: ${reference.isWriteAccess}, expected: ${isWriteAccess}.`); } + if (typeof isDefinition !== "undefined" && reference.isDefinition !== isDefinition) { + this.raiseError(`verifyReferencesAtPositionListContains failed - item isDefinition value does not match, actual: ${reference.isDefinition}, expected: ${isDefinition}.`); + } return; } } - const missingItem = { fileName: fileName, start: start, end: end, isWriteAccess: isWriteAccess }; + const missingItem = { fileName, start, end, isWriteAccess, isDefinition }; this.raiseError(`verifyReferencesAtPositionListContains failed - could not find the item: ${stringify(missingItem)} in the returned list: (${stringify(references)})`); } @@ -2835,8 +2838,8 @@ namespace FourSlashInterface { this.state.verifyReferencesCountIs(count, /*localFilesOnly*/ false); } - public referencesAtPositionContains(range: FourSlash.Range, isWriteAccess?: boolean) { - this.state.verifyReferencesAtPositionListContains(range.fileName, range.start, range.end, isWriteAccess); + public referencesAtPositionContains(range: FourSlash.Range, isWriteAccess?: boolean, isDefinition?: boolean) { + this.state.verifyReferencesAtPositionListContains(range.fileName, range.start, range.end, isWriteAccess, isDefinition); } public signatureHelpPresent() { diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 540a6503138..78de5b02358 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -125,7 +125,7 @@ declare namespace FourSlashInterface { completionListAllowsNewIdentifier(): void; memberListIsEmpty(): void; referencesCountIs(count: number): void; - referencesAtPositionContains(range: Range, isWriteAccess?: boolean): void; + referencesAtPositionContains(range: Range, isWriteAccess?: boolean, isDefinition?: boolean): void; signatureHelpPresent(): void; errorExistsBetweenMarkers(startMarker: string, endMarker: string): void; errorExistsAfterMarker(markerName?: string): void; diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts new file mode 100644 index 00000000000..eb9980c946d --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts @@ -0,0 +1,8 @@ +/// +////var [|{| "isDefinition": true |}f|] = x => x + 1; +////[|{| "isDefinition": false |}f|](12); +var firstRange = test.ranges()[0]; +goTo.position(firstRange.start, firstRange.fileName); +test.ranges().forEach(range => { + verify.referencesAtPositionContains(range, undefined, range.marker.data.isDefinition); +}); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts new file mode 100644 index 00000000000..04b1f90681a --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts @@ -0,0 +1,13 @@ +/// +////class [|{| "isDefinition": true |}C|] { +//// n: number; +//// constructor() { +//// this.n = 12; +//// } +////} +////let c = new [|{| "isDefinition": false |}C|](); +var firstRange = test.ranges()[0]; +goTo.position(firstRange.start, firstRange.fileName); +test.ranges().forEach(range => { + verify.referencesAtPositionContains(range, undefined, range.marker.data.isDefinition); +}); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts new file mode 100644 index 00000000000..a5764206bce --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts @@ -0,0 +1,11 @@ +/// +////enum [|{| "isDefinition": true |}E|] { +//// First, +//// Second +////} +////let first = [|{| "isDefinition": false |}E|].First; +var firstRange = test.ranges()[0]; +goTo.position(firstRange.start, firstRange.fileName); +test.ranges().forEach(range => { + verify.referencesAtPositionContains(range, undefined, range.marker.data.isDefinition); +}); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts new file mode 100644 index 00000000000..456d953092d --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts @@ -0,0 +1,9 @@ +/// +////function [|{| "isDefinition": true |}func|](x: number) { +////} +////[|{| "isDefinition": false |}func|](x) +var firstRange = test.ranges()[0]; +goTo.position(firstRange.start, firstRange.fileName); +test.ranges().forEach(range => { + verify.referencesAtPositionContains(range, undefined, range.marker.data.isDefinition); +}); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts new file mode 100644 index 00000000000..51d1e858185 --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts @@ -0,0 +1,10 @@ +/// +////interface [|{| "isDefinition": true |}I|] { +//// p: number; +////} +////let i: [|{| "isDefinition": false |}I|] = { p: 12 }; +var firstRange = test.ranges()[0]; +goTo.position(firstRange.start, firstRange.fileName); +test.ranges().forEach(range => { + verify.referencesAtPositionContains(range, undefined, range.marker.data.isDefinition); +}); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts new file mode 100644 index 00000000000..7efefa17a4b --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts @@ -0,0 +1,19 @@ +/// +////interface [|{| "isDefinition": true |}Numbers|] { +//// p: number; +////} +////interface [|{| "isDefinition": true |}Numbers|] { +//// m: number; +////} +////class [|{| "isDefinition": true |}Numbers|] { +//// f(n: number) { +//// return this.p + this.m + n; +//// } +////} +////let i: [|{| "isDefinition": false |}Numbers|] = new [|{| "isDefinition": false |}Numbers|](); +////let x = i.f(i.p + i.m); +var firstRange = test.ranges()[0]; +goTo.position(firstRange.start, firstRange.fileName); +test.ranges().forEach(range => { + verify.referencesAtPositionContains(range, undefined, range.marker.data.isDefinition); +}); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts new file mode 100644 index 00000000000..86b92ec9ce7 --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts @@ -0,0 +1,10 @@ +/// +////namespace [|{| "isDefinition": true |}Numbers|] { +//// export var n = 12; +////} +////let x = [|{| "isDefinition": false |}Numbers|].n + 1; +var firstRange = test.ranges()[0]; +goTo.position(firstRange.start, firstRange.fileName); +test.ranges().forEach(range => { + verify.referencesAtPositionContains(range, undefined, range.marker.data.isDefinition); +}); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts new file mode 100644 index 00000000000..cdb0e281d53 --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts @@ -0,0 +1,9 @@ +/// +////function f([|{| "isDefinition": true |}x|]: number) { +//// return [|{| "isDefinition": false |}x|] + 1 +////} +var firstRange = test.ranges()[0]; +goTo.position(firstRange.start, firstRange.fileName); +test.ranges().forEach(range => { + verify.referencesAtPositionContains(range, undefined, range.marker.data.isDefinition); +}); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts new file mode 100644 index 00000000000..44a7c64a93a --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts @@ -0,0 +1,8 @@ +/// +////type [|{| "isDefinition": true |}Alias|]= number; +////let n: [|{| "isDefinition": false |}Alias|] = 12; +var firstRange = test.ranges()[0]; +goTo.position(firstRange.start, firstRange.fileName); +test.ranges().forEach(range => { + verify.referencesAtPositionContains(range, undefined, range.marker.data.isDefinition); +}); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts new file mode 100644 index 00000000000..8d046c67e3a --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts @@ -0,0 +1,23 @@ +/// +////var [|{| "isDefinition": true |}x|] = 0; +////var assignmentRightHandSide = [|{| "isDefinition": false |}x|]; +////var assignmentRightHandSide2 = 1 + [|{| "isDefinition": false |}x|]; +//// +////[|{| "isDefinition": false |}x|] = 1; +////[|{| "isDefinition": false |}x|] = [|{| "isDefinition": false |}x|] + [|{| "isDefinition": false |}x|]; +//// +////[|{| "isDefinition": false |}x|] == 1; +////[|{| "isDefinition": false |}x|] <= 1; +//// +////var preIncrement = ++[|{| "isDefinition": false |}x|]; +////var postIncrement = [|{| "isDefinition": false |}x|]++; +////var preDecrement = --[|{| "isDefinition": false |}x|]; +////var postDecrement = [|{| "isDefinition": false |}x|]--; +//// +////[|{| "isDefinition": false |}x|] += 1; +////[|{| "isDefinition": false |}x|] <<= 1; +var firstRange = test.ranges()[0]; +goTo.position(firstRange.start, firstRange.fileName); +test.ranges().forEach(range => { + verify.referencesAtPositionContains(range, undefined, range.marker.data.isDefinition); +}); From 7d31bcf87b48309621525746c2bdc977f87d75a5 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Mon, 13 Jun 2016 13:35:37 -0700 Subject: [PATCH 22/37] Add option to bail out of `jake runtests` when one test fails --- Jakefile.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index df8edc7dded..dc0585d3b1c 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -754,13 +754,14 @@ function runConsoleTests(defaultReporter, runInParallel) { colors = process.env.colors || process.env.color; colors = colors ? ' --no-colors ' : ' --colors '; reporter = process.env.reporter || process.env.r || defaultReporter; + var bail = (process.env.bail || process.env.b) ? "--bail" : ""; var lintFlag = process.env.lint !== 'false'; // timeout normally isn't necessary but Travis-CI has been timing out on compiler baselines occasionally // default timeout is 2sec which really should be enough, but maybe we just need a small amount longer if(!runInParallel) { tests = tests ? ' -g "' + tests + '"' : ''; - var cmd = "mocha" + (debug ? " --debug-brk" : "") + " -R " + reporter + tests + colors + ' -t ' + testTimeout + ' ' + run; + var cmd = "mocha" + (debug ? " --debug-brk" : "") + " -R " + reporter + tests + colors + bail + ' -t ' + testTimeout + ' ' + run; console.log(cmd); var savedNodeEnv = process.env.NODE_ENV; @@ -825,7 +826,7 @@ task("runtests-parallel", ["build-rules", "tests", builtLocalDirectory], functio runConsoleTests('min', /*runInParallel*/ true); }, {async: true}); -desc("Runs the tests using the built run.js file. Optional arguments are: t[ests]=regex r[eporter]=[list|spec|json|] d[ebug]=true color[s]=false lint=true."); +desc("Runs the tests using the built run.js file. Optional arguments are: t[ests]=regex r[eporter]=[list|spec|json|] d[ebug]=true color[s]=false lint=true bail=false."); task("runtests", ["build-rules", "tests", builtLocalDirectory], function() { runConsoleTests('mocha-fivemat-progress-reporter', /*runInParallel*/ false); }, {async: true}); From b10d93291fb6b3a7087bff1e93b39ccbb6b4099a Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 13 Jun 2016 14:20:31 -0700 Subject: [PATCH 23/37] Absolute-ify paths in both places --- src/compiler/program.ts | 3 +- .../reference/library-reference-11.trace.json | 8 ++--- .../reference/library-reference-12.trace.json | 8 ++--- .../reference/library-reference-3.trace.json | 8 ++--- .../reference/library-reference-6.trace.json | 20 +++++------ .../reference/library-reference-7.trace.json | 8 ++--- .../reference/typingsLookup1.trace.json | 34 ++++--------------- 7 files changed, 34 insertions(+), 55 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 59ae0d862ad..28dd6275143 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -192,7 +192,8 @@ namespace ts { traceEnabled }; - const typeRoots = options.typeRoots || defaultTypeRoots; + const typeRoots = options.typeRoots || + defaultTypeRoots.map(d => combinePaths(options.configFilePath ? getDirectoryPath(options.configFilePath) : host.getCurrentDirectory(), d)); if (traceEnabled) { if (containingFile === undefined) { if (typeRoots === undefined) { diff --git a/tests/baselines/reference/library-reference-11.trace.json b/tests/baselines/reference/library-reference-11.trace.json index 7f6a32a0b23..365fe3ce72d 100644 --- a/tests/baselines/reference/library-reference-11.trace.json +++ b/tests/baselines/reference/library-reference-11.trace.json @@ -1,8 +1,8 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory 'node_modules/@types'. ========", - "Resolving with primary search path 'node_modules/@types'", - "File 'node_modules/@types/jquery/package.json' does not exist.", - "File 'node_modules/@types/jquery/index.d.ts' does not exist.", + "======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory '/node_modules/@types'. ========", + "Resolving with primary search path '/node_modules/@types'", + "File '/node_modules/@types/jquery/package.json' does not exist.", + "File '/node_modules/@types/jquery/index.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/a/b'", "File '/a/b/node_modules/jquery.ts' does not exist.", "File '/a/b/node_modules/jquery.d.ts' does not exist.", diff --git a/tests/baselines/reference/library-reference-12.trace.json b/tests/baselines/reference/library-reference-12.trace.json index b3debaec9d6..84144f82729 100644 --- a/tests/baselines/reference/library-reference-12.trace.json +++ b/tests/baselines/reference/library-reference-12.trace.json @@ -1,8 +1,8 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory 'node_modules/@types'. ========", - "Resolving with primary search path 'node_modules/@types'", - "File 'node_modules/@types/jquery/package.json' does not exist.", - "File 'node_modules/@types/jquery/index.d.ts' does not exist.", + "======== Resolving type reference directive 'jquery', containing file '/a/b/consumer.ts', root directory '/node_modules/@types'. ========", + "Resolving with primary search path '/node_modules/@types'", + "File '/node_modules/@types/jquery/package.json' does not exist.", + "File '/node_modules/@types/jquery/index.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/a/b'", "File '/a/b/node_modules/jquery.ts' does not exist.", "File '/a/b/node_modules/jquery.d.ts' does not exist.", diff --git a/tests/baselines/reference/library-reference-3.trace.json b/tests/baselines/reference/library-reference-3.trace.json index 909e42140c8..730835c65e9 100644 --- a/tests/baselines/reference/library-reference-3.trace.json +++ b/tests/baselines/reference/library-reference-3.trace.json @@ -1,8 +1,8 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory 'node_modules/@types'. ========", - "Resolving with primary search path 'node_modules/@types'", - "File 'node_modules/@types/jquery/package.json' does not exist.", - "File 'node_modules/@types/jquery/index.d.ts' does not exist.", + "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory '/src/node_modules/@types'. ========", + "Resolving with primary search path '/src/node_modules/@types'", + "File '/src/node_modules/@types/jquery/package.json' does not exist.", + "File '/src/node_modules/@types/jquery/index.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/src'", "File '/src/node_modules/jquery.ts' does not exist.", "File '/src/node_modules/jquery.d.ts' does not exist.", diff --git a/tests/baselines/reference/library-reference-6.trace.json b/tests/baselines/reference/library-reference-6.trace.json index 21843c2ecf4..48fb49e6c7f 100644 --- a/tests/baselines/reference/library-reference-6.trace.json +++ b/tests/baselines/reference/library-reference-6.trace.json @@ -1,12 +1,12 @@ [ - "======== Resolving type reference directive 'alpha', containing file '/src/foo.ts', root directory 'node_modules/@types'. ========", - "Resolving with primary search path 'node_modules/@types'", - "File 'node_modules/@types/alpha/package.json' does not exist.", - "File 'node_modules/@types/alpha/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'alpha' was successfully resolved to 'node_modules/@types/alpha/index.d.ts', primary: true. ========", - "======== Resolving type reference directive 'alpha', containing file '/src/__inferred type names__.ts', root directory 'node_modules/@types'. ========", - "Resolving with primary search path 'node_modules/@types'", - "File 'node_modules/@types/alpha/package.json' does not exist.", - "File 'node_modules/@types/alpha/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'alpha' was successfully resolved to 'node_modules/@types/alpha/index.d.ts', primary: true. ========" + "======== Resolving type reference directive 'alpha', containing file '/src/foo.ts', root directory '/node_modules/@types'. ========", + "Resolving with primary search path '/node_modules/@types'", + "File '/node_modules/@types/alpha/package.json' does not exist.", + "File '/node_modules/@types/alpha/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'alpha' was successfully resolved to '/node_modules/@types/alpha/index.d.ts', primary: true. ========", + "======== Resolving type reference directive 'alpha', containing file '/src/__inferred type names__.ts', root directory '/node_modules/@types'. ========", + "Resolving with primary search path '/node_modules/@types'", + "File '/node_modules/@types/alpha/package.json' does not exist.", + "File '/node_modules/@types/alpha/index.d.ts' exist - use it as a name resolution result.", + "======== Type reference directive 'alpha' was successfully resolved to '/node_modules/@types/alpha/index.d.ts', primary: true. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/library-reference-7.trace.json b/tests/baselines/reference/library-reference-7.trace.json index 909e42140c8..b681ea312a8 100644 --- a/tests/baselines/reference/library-reference-7.trace.json +++ b/tests/baselines/reference/library-reference-7.trace.json @@ -1,8 +1,8 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory 'node_modules/@types'. ========", - "Resolving with primary search path 'node_modules/@types'", - "File 'node_modules/@types/jquery/package.json' does not exist.", - "File 'node_modules/@types/jquery/index.d.ts' does not exist.", + "======== Resolving type reference directive 'jquery', containing file '/src/consumer.ts', root directory '/node_modules/@types'. ========", + "Resolving with primary search path '/node_modules/@types'", + "File '/node_modules/@types/jquery/package.json' does not exist.", + "File '/node_modules/@types/jquery/index.d.ts' does not exist.", "Looking up in 'node_modules' folder, initial location '/src'", "File '/src/node_modules/jquery.ts' does not exist.", "File '/src/node_modules/jquery.d.ts' does not exist.", diff --git a/tests/baselines/reference/typingsLookup1.trace.json b/tests/baselines/reference/typingsLookup1.trace.json index ad0354157c3..83b0e91d6c7 100644 --- a/tests/baselines/reference/typingsLookup1.trace.json +++ b/tests/baselines/reference/typingsLookup1.trace.json @@ -1,34 +1,12 @@ [ - "======== Resolving type reference directive 'jquery', containing file '/a.ts', root directory 'node_modules/@types'. ========", - "Resolving with primary search path 'node_modules/@types'", - "File 'node_modules/@types/jquery/package.json' does not exist.", - "File 'node_modules/@types/jquery/index.d.ts' does not exist.", - "Looking up in 'node_modules' folder, initial location '/'", - "File '/node_modules/jquery.ts' does not exist.", - "File '/node_modules/jquery.d.ts' does not exist.", - "File '/node_modules/jquery/package.json' does not exist.", - "File '/node_modules/jquery/index.ts' does not exist.", - "File '/node_modules/jquery/index.d.ts' does not exist.", - "File '/node_modules/@types/jquery.ts' does not exist.", - "File '/node_modules/@types/jquery.d.ts' does not exist.", + "======== Resolving type reference directive 'jquery', containing file '/a.ts', root directory '/node_modules/@types'. ========", + "Resolving with primary search path '/node_modules/@types'", "File '/node_modules/@types/jquery/package.json' does not exist.", - "File '/node_modules/@types/jquery/index.ts' does not exist.", "File '/node_modules/@types/jquery/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: false. ========", - "======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory 'node_modules/@types'. ========", - "Resolving with primary search path 'node_modules/@types'", - "File 'node_modules/@types/jquery/package.json' does not exist.", - "File 'node_modules/@types/jquery/index.d.ts' does not exist.", - "Looking up in 'node_modules' folder, initial location '/'", - "File '/node_modules/jquery.ts' does not exist.", - "File '/node_modules/jquery.d.ts' does not exist.", - "File '/node_modules/jquery/package.json' does not exist.", - "File '/node_modules/jquery/index.ts' does not exist.", - "File '/node_modules/jquery/index.d.ts' does not exist.", - "File '/node_modules/@types/jquery.ts' does not exist.", - "File '/node_modules/@types/jquery.d.ts' does not exist.", + "======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: true. ========", + "======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========", + "Resolving with primary search path '/node_modules/@types'", "File '/node_modules/@types/jquery/package.json' does not exist.", - "File '/node_modules/@types/jquery/index.ts' does not exist.", "File '/node_modules/@types/jquery/index.d.ts' exist - use it as a name resolution result.", - "======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: false. ========" + "======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/index.d.ts', primary: true. ========" ] \ No newline at end of file From 29f52914530e2c632cb3cd5bea9dcd8fe8bca327 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 13 Jun 2016 14:37:07 -0700 Subject: [PATCH 24/37] Refactor --- src/compiler/program.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 28dd6275143..15afbe18265 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -178,6 +178,11 @@ namespace ts { const typeReferenceExtensions = [".d.ts"]; + function getEffectiveTypeRoots(options: CompilerOptions, host: ModuleResolutionHost) { + return options.typeRoots || + defaultTypeRoots.map(d => combinePaths(options.configFilePath ? getDirectoryPath(options.configFilePath) : host.getCurrentDirectory(), d)); + } + /** * @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown. * This is possible in case if resolution is performed for directives specified via 'types' parameter. In this case initial path for secondary lookups @@ -192,8 +197,7 @@ namespace ts { traceEnabled }; - const typeRoots = options.typeRoots || - defaultTypeRoots.map(d => combinePaths(options.configFilePath ? getDirectoryPath(options.configFilePath) : host.getCurrentDirectory(), d)); + const typeRoots = getEffectiveTypeRoots(options, host); if (traceEnabled) { if (containingFile === undefined) { if (typeRoots === undefined) { @@ -1032,8 +1036,7 @@ namespace ts { // Walk the primary type lookup locations let result: string[] = []; if (host.directoryExists && host.getDirectories) { - const typeRoots = options.typeRoots || - defaultTypeRoots.map(d => combinePaths(options.configFilePath ? getDirectoryPath(options.configFilePath) : host.getCurrentDirectory(), d)); + const typeRoots = getEffectiveTypeRoots(options, host); for (const root of typeRoots) { if (host.directoryExists(root)) { result = result.concat(host.getDirectories(root)); @@ -1208,7 +1211,7 @@ namespace ts { (oldOptions.rootDir !== options.rootDir) || (oldOptions.configFilePath !== options.configFilePath) || (oldOptions.baseUrl !== options.baseUrl) || - (oldOptions.typeRoots !== options.typeRoots) || + !arrayIsEqualTo(oldOptions.typeRoots, oldOptions.typeRoots) || !arrayIsEqualTo(oldOptions.rootDirs, options.rootDirs) || !mapIsEqualTo(oldOptions.paths, options.paths)) { return false; From 236351d4f0b83a943a90e2a9f6e9994fae256ef7 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 13 Jun 2016 14:43:19 -0700 Subject: [PATCH 25/37] Add unit test --- tests/cases/unittests/reuseProgramStructure.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/cases/unittests/reuseProgramStructure.ts b/tests/cases/unittests/reuseProgramStructure.ts index 154cfdd702f..db67eb2c252 100644 --- a/tests/cases/unittests/reuseProgramStructure.ts +++ b/tests/cases/unittests/reuseProgramStructure.ts @@ -259,6 +259,22 @@ namespace ts { assert.isTrue(!program_1.structureIsReused); }); + it("fails if change affects type references", () => { + const program_1 = newProgram(files, ["a.ts"], { types: ["a"] }); + updateProgram(program_1, ["a.ts"], { types: ["b"] }, files => { + + }); + assert.isTrue(!program_1.structureIsReused); + }); + + it("succeeds if change doesn't affect type references", () => { + const program_1 = newProgram(files, ["a.ts"], { types: ["a"] }); + updateProgram(program_1, ["a.ts"], { types: ["a"] },afiles => { + + }); + assert.isTrue(program_1.structureIsReused); + }); + it("fails if change affects imports", () => { const program_1 = newProgram(files, ["a.ts"], { target }); updateProgram(program_1, ["a.ts"], { target }, files => { From 90b319fc246d53604f54c9b7d003ab2dfb741ec6 Mon Sep 17 00:00:00 2001 From: Ryan Cavanaugh Date: Mon, 13 Jun 2016 14:52:41 -0700 Subject: [PATCH 26/37] lint --- tests/cases/unittests/reuseProgramStructure.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/unittests/reuseProgramStructure.ts b/tests/cases/unittests/reuseProgramStructure.ts index db67eb2c252..b8a36baf824 100644 --- a/tests/cases/unittests/reuseProgramStructure.ts +++ b/tests/cases/unittests/reuseProgramStructure.ts @@ -269,7 +269,7 @@ namespace ts { it("succeeds if change doesn't affect type references", () => { const program_1 = newProgram(files, ["a.ts"], { types: ["a"] }); - updateProgram(program_1, ["a.ts"], { types: ["a"] },afiles => { + updateProgram(program_1, ["a.ts"], { types: ["a"] }, files => { }); assert.isTrue(program_1.structureIsReused); From 318e9573779136a169dc4a7c0da3d918389d7cce Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 13 Jun 2016 23:33:23 -0700 Subject: [PATCH 27/37] Added tests. --- .../shorthandOfExportedEntity01_targetES2015_CommonJS.ts | 9 +++++++++ .../shorthandOfExportedEntity02_targetES5_CommonJS.ts | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 tests/cases/compiler/shorthandOfExportedEntity01_targetES2015_CommonJS.ts create mode 100644 tests/cases/compiler/shorthandOfExportedEntity02_targetES5_CommonJS.ts diff --git a/tests/cases/compiler/shorthandOfExportedEntity01_targetES2015_CommonJS.ts b/tests/cases/compiler/shorthandOfExportedEntity01_targetES2015_CommonJS.ts new file mode 100644 index 00000000000..25328afd6ce --- /dev/null +++ b/tests/cases/compiler/shorthandOfExportedEntity01_targetES2015_CommonJS.ts @@ -0,0 +1,9 @@ +// @target: ES2015 +// @module: commonjs +// @declaration: true + +export const test = "test"; + +export function foo () { + const x = { test }; +} diff --git a/tests/cases/compiler/shorthandOfExportedEntity02_targetES5_CommonJS.ts b/tests/cases/compiler/shorthandOfExportedEntity02_targetES5_CommonJS.ts new file mode 100644 index 00000000000..c7b3a2b37ec --- /dev/null +++ b/tests/cases/compiler/shorthandOfExportedEntity02_targetES5_CommonJS.ts @@ -0,0 +1,9 @@ +// @target: ES5 +// @module: commonjs +// @declaration: true + +export const test = "test"; + +export function foo () { + const x = { test }; +} From d54094c6f7533a76c11c0bbb98148c62146f28e8 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 13 Jun 2016 23:33:36 -0700 Subject: [PATCH 28/37] Accepted baselines. --- ...fExportedEntity01_targetES2015_CommonJS.js | 21 +++++++++++++++++++ ...rtedEntity01_targetES2015_CommonJS.symbols | 13 ++++++++++++ ...portedEntity01_targetES2015_CommonJS.types | 15 +++++++++++++ ...ndOfExportedEntity02_targetES5_CommonJS.js | 21 +++++++++++++++++++ ...xportedEntity02_targetES5_CommonJS.symbols | 13 ++++++++++++ ...fExportedEntity02_targetES5_CommonJS.types | 15 +++++++++++++ 6 files changed, 98 insertions(+) create mode 100644 tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js create mode 100644 tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.symbols create mode 100644 tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types create mode 100644 tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.js create mode 100644 tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.symbols create mode 100644 tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types diff --git a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js new file mode 100644 index 00000000000..dbbc72fead3 --- /dev/null +++ b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js @@ -0,0 +1,21 @@ +//// [shorthandOfExportedEntity01_targetES2015_CommonJS.ts] + +export const test = "test"; + +export function foo () { + const x = { test }; +} + + +//// [shorthandOfExportedEntity01_targetES2015_CommonJS.js] +"use strict"; +exports.test = "test"; +function foo() { + const x = { test }; +} +exports.foo = foo; + + +//// [shorthandOfExportedEntity01_targetES2015_CommonJS.d.ts] +export declare const test: string; +export declare function foo(): void; diff --git a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.symbols b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.symbols new file mode 100644 index 00000000000..341d40bc542 --- /dev/null +++ b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/shorthandOfExportedEntity01_targetES2015_CommonJS.ts === + +export const test = "test"; +>test : Symbol(test, Decl(shorthandOfExportedEntity01_targetES2015_CommonJS.ts, 1, 12)) + +export function foo () { +>foo : Symbol(foo, Decl(shorthandOfExportedEntity01_targetES2015_CommonJS.ts, 1, 27)) + + const x = { test }; +>x : Symbol(x, Decl(shorthandOfExportedEntity01_targetES2015_CommonJS.ts, 4, 7)) +>test : Symbol(test, Decl(shorthandOfExportedEntity01_targetES2015_CommonJS.ts, 4, 13)) +} + diff --git a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types new file mode 100644 index 00000000000..dcc04015993 --- /dev/null +++ b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/shorthandOfExportedEntity01_targetES2015_CommonJS.ts === + +export const test = "test"; +>test : string +>"test" : string + +export function foo () { +>foo : () => void + + const x = { test }; +>x : { test: string; } +>{ test } : { test: string; } +>test : string +} + diff --git a/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.js b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.js new file mode 100644 index 00000000000..764739705c4 --- /dev/null +++ b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.js @@ -0,0 +1,21 @@ +//// [shorthandOfExportedEntity02_targetES5_CommonJS.ts] + +export const test = "test"; + +export function foo () { + const x = { test }; +} + + +//// [shorthandOfExportedEntity02_targetES5_CommonJS.js] +"use strict"; +exports.test = "test"; +function foo() { + var x = { test: exports.test }; +} +exports.foo = foo; + + +//// [shorthandOfExportedEntity02_targetES5_CommonJS.d.ts] +export declare const test: string; +export declare function foo(): void; diff --git a/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.symbols b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.symbols new file mode 100644 index 00000000000..3b0b40922c9 --- /dev/null +++ b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/shorthandOfExportedEntity02_targetES5_CommonJS.ts === + +export const test = "test"; +>test : Symbol(test, Decl(shorthandOfExportedEntity02_targetES5_CommonJS.ts, 1, 12)) + +export function foo () { +>foo : Symbol(foo, Decl(shorthandOfExportedEntity02_targetES5_CommonJS.ts, 1, 27)) + + const x = { test }; +>x : Symbol(x, Decl(shorthandOfExportedEntity02_targetES5_CommonJS.ts, 4, 7)) +>test : Symbol(test, Decl(shorthandOfExportedEntity02_targetES5_CommonJS.ts, 4, 13)) +} + diff --git a/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types new file mode 100644 index 00000000000..27d16e2166f --- /dev/null +++ b/tests/baselines/reference/shorthandOfExportedEntity02_targetES5_CommonJS.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/shorthandOfExportedEntity02_targetES5_CommonJS.ts === + +export const test = "test"; +>test : string +>"test" : string + +export function foo () { +>foo : () => void + + const x = { test }; +>x : { test: string; } +>{ test } : { test: string; } +>test : string +} + From eae289c7b7e645e14f9d1655e918d0c4660f903f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 13 Jun 2016 23:33:47 -0700 Subject: [PATCH 29/37] Emit 'exports.' if the shorthand is a general export. --- src/compiler/emitter.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 46362bd7827..411c0494546 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2150,9 +2150,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge } // Return true if identifier resolves to an exported member of a namespace - function isNamespaceExportReference(node: Identifier) { + function isExportReference(node: Identifier) { const container = resolver.getReferencedExportContainer(node); - return container && container.kind !== SyntaxKind.SourceFile; + return !!container; } // Return true if identifier resolves to an imported identifier @@ -2185,10 +2185,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge // const foo_1 = require('./foo'); // exports.baz = { foo: foo_1.foo }; // - if (languageVersion < ScriptTarget.ES6 || (modulekind !== ModuleKind.ES6 && isImportedReference(node.name)) || isNamespaceExportReference(node.name) ) { + if (languageVersion < ScriptTarget.ES6 || (modulekind !== ModuleKind.ES6 && isImportedReference(node.name)) || isExportReference(node.name)) { // Emit identifier as an identifier write(": "); - emit(node.name); + emitExpressionIdentifier(node.name); } if (languageVersion >= ScriptTarget.ES6 && node.objectAssignmentInitializer) { From e8a7e0c0d41fa524ddb7912d0b335abce7e4b1ea Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 13 Jun 2016 23:34:00 -0700 Subject: [PATCH 30/37] Accepted baselines. --- .../shorthandOfExportedEntity01_targetES2015_CommonJS.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js index dbbc72fead3..9e057951b3a 100644 --- a/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js +++ b/tests/baselines/reference/shorthandOfExportedEntity01_targetES2015_CommonJS.js @@ -11,7 +11,7 @@ export function foo () { "use strict"; exports.test = "test"; function foo() { - const x = { test }; + const x = { test: exports.test }; } exports.foo = foo; From f6cee27af9479236b3c2dc58460aea9cde728579 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 14 Jun 2016 06:11:00 -0700 Subject: [PATCH 31/37] Emit 'Promise' decorator metadata return type for async methods --- src/compiler/emitter.ts | 13 +++- .../reference/decoratorMetadataPromise.js | 59 +++++++++++++++++++ .../decoratorMetadataPromise.symbols | 33 +++++++++++ .../reference/decoratorMetadataPromise.types | 34 +++++++++++ .../compiler/decoratorMetadataPromise.ts | 14 +++++ 5 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/decoratorMetadataPromise.js create mode 100644 tests/baselines/reference/decoratorMetadataPromise.symbols create mode 100644 tests/baselines/reference/decoratorMetadataPromise.types create mode 100644 tests/cases/compiler/decoratorMetadataPromise.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e3f092257a3..e37a4d2d048 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6156,9 +6156,16 @@ const _super = (function (geti, seti) { /** Serializes the return type of function. Used by the __metadata decorator for a method. */ function emitSerializedReturnTypeOfNode(node: Node) { - if (node && isFunctionLike(node) && (node).type) { - emitSerializedTypeNode((node).type); - return; + if (node && isFunctionLike(node)) { + const fn = node; + if (fn.type) { + emitSerializedTypeNode((node).type); + return; + } + else if (isAsyncFunctionLike(fn)) { + write("Promise"); + return; + } } write("void 0"); diff --git a/tests/baselines/reference/decoratorMetadataPromise.js b/tests/baselines/reference/decoratorMetadataPromise.js new file mode 100644 index 00000000000..3ed8942033d --- /dev/null +++ b/tests/baselines/reference/decoratorMetadataPromise.js @@ -0,0 +1,59 @@ +//// [decoratorMetadataPromise.ts] + +declare const decorator: MethodDecorator; + +class A { + @decorator + async foo() {} + @decorator + async bar(): Promise { return 0; } + @decorator + baz(n: Promise): Promise { return n; } +} + + +//// [decoratorMetadataPromise.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); + else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; + return c > 3 && r && Object.defineProperty(target, key, r), r; +}; +var __metadata = (this && this.__metadata) || function (k, v) { + if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); +}; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments)).next()); + }); +}; +class A { + foo() { + return __awaiter(this, void 0, void 0, function* () { }); + } + bar() { + return __awaiter(this, void 0, void 0, function* () { return 0; }); + } + baz(n) { return n; } +} +__decorate([ + decorator, + __metadata('design:type', Function), + __metadata('design:paramtypes', []), + __metadata('design:returntype', Promise) +], A.prototype, "foo", null); +__decorate([ + decorator, + __metadata('design:type', Function), + __metadata('design:paramtypes', []), + __metadata('design:returntype', Promise) +], A.prototype, "bar", null); +__decorate([ + decorator, + __metadata('design:type', Function), + __metadata('design:paramtypes', [Promise]), + __metadata('design:returntype', Promise) +], A.prototype, "baz", null); diff --git a/tests/baselines/reference/decoratorMetadataPromise.symbols b/tests/baselines/reference/decoratorMetadataPromise.symbols new file mode 100644 index 00000000000..b0ebe05e8c1 --- /dev/null +++ b/tests/baselines/reference/decoratorMetadataPromise.symbols @@ -0,0 +1,33 @@ +=== tests/cases/compiler/decoratorMetadataPromise.ts === + +declare const decorator: MethodDecorator; +>decorator : Symbol(decorator, Decl(decoratorMetadataPromise.ts, 1, 13)) +>MethodDecorator : Symbol(MethodDecorator, Decl(lib.es5.d.ts, --, --)) + +class A { +>A : Symbol(A, Decl(decoratorMetadataPromise.ts, 1, 41)) + + @decorator +>decorator : Symbol(decorator, Decl(decoratorMetadataPromise.ts, 1, 13)) + + async foo() {} +>foo : Symbol(A.foo, Decl(decoratorMetadataPromise.ts, 3, 9)) + + @decorator +>decorator : Symbol(decorator, Decl(decoratorMetadataPromise.ts, 1, 13)) + + async bar(): Promise { return 0; } +>bar : Symbol(A.bar, Decl(decoratorMetadataPromise.ts, 5, 18)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + @decorator +>decorator : Symbol(decorator, Decl(decoratorMetadataPromise.ts, 1, 13)) + + baz(n: Promise): Promise { return n; } +>baz : Symbol(A.baz, Decl(decoratorMetadataPromise.ts, 7, 46)) +>n : Symbol(n, Decl(decoratorMetadataPromise.ts, 9, 8)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>n : Symbol(n, Decl(decoratorMetadataPromise.ts, 9, 8)) +} + diff --git a/tests/baselines/reference/decoratorMetadataPromise.types b/tests/baselines/reference/decoratorMetadataPromise.types new file mode 100644 index 00000000000..900e751e841 --- /dev/null +++ b/tests/baselines/reference/decoratorMetadataPromise.types @@ -0,0 +1,34 @@ +=== tests/cases/compiler/decoratorMetadataPromise.ts === + +declare const decorator: MethodDecorator; +>decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void +>MethodDecorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void + +class A { +>A : A + + @decorator +>decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void + + async foo() {} +>foo : () => Promise + + @decorator +>decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void + + async bar(): Promise { return 0; } +>bar : () => Promise +>Promise : Promise +>0 : number + + @decorator +>decorator : (target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor | void + + baz(n: Promise): Promise { return n; } +>baz : (n: Promise) => Promise +>n : Promise +>Promise : Promise +>Promise : Promise +>n : Promise +} + diff --git a/tests/cases/compiler/decoratorMetadataPromise.ts b/tests/cases/compiler/decoratorMetadataPromise.ts new file mode 100644 index 00000000000..ef55e1946de --- /dev/null +++ b/tests/cases/compiler/decoratorMetadataPromise.ts @@ -0,0 +1,14 @@ +// @experimentaldecorators: true +// @emitdecoratormetadata: true +// @target: es6 + +declare const decorator: MethodDecorator; + +class A { + @decorator + async foo() {} + @decorator + async bar(): Promise { return 0; } + @decorator + baz(n: Promise): Promise { return n; } +} From 33e4c7a9a3a4d2824c0967a615637df5429fa8d1 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 14 Jun 2016 06:50:44 -0700 Subject: [PATCH 32/37] Respond to PR comment --- src/compiler/emitter.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index e37a4d2d048..12377a0f26c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -6157,12 +6157,11 @@ const _super = (function (geti, seti) { /** Serializes the return type of function. Used by the __metadata decorator for a method. */ function emitSerializedReturnTypeOfNode(node: Node) { if (node && isFunctionLike(node)) { - const fn = node; - if (fn.type) { + if ((node).type) { emitSerializedTypeNode((node).type); return; } - else if (isAsyncFunctionLike(fn)) { + else if (isAsyncFunctionLike(node)) { write("Promise"); return; } From 1b4b01eed5c67591827e10c4b268ac97cd2f1937 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 14 Jun 2016 06:49:17 -0700 Subject: [PATCH 33/37] Unescape identifiers used in code completion --- src/harness/fourslash.ts | 2 ++ src/services/services.ts | 2 +- tests/cases/fourslash/codeCompletionEscaping.ts | 8 ++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/codeCompletionEscaping.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 8104f113392..17f14e30737 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -717,6 +717,8 @@ namespace FourSlash { public verifyCompletionEntryDetails(entryName: string, expectedText: string, expectedDocumentation?: string, kind?: string) { const details = this.getCompletionEntryDetails(entryName); + assert(details, "no completion entry available"); + assert.equal(ts.displayPartsToString(details.displayParts), expectedText, this.assertionMessageAtLastKnownMarker("completion entry details text")); if (expectedDocumentation !== undefined) { diff --git a/src/services/services.ts b/src/services/services.ts index d051a4378e4..d5f63627471 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3234,7 +3234,7 @@ namespace ts { } } - return name; + return unescapeIdentifier(name); } function getCompletionData(fileName: string, position: number) { diff --git a/tests/cases/fourslash/codeCompletionEscaping.ts b/tests/cases/fourslash/codeCompletionEscaping.ts new file mode 100644 index 00000000000..b8182307b7b --- /dev/null +++ b/tests/cases/fourslash/codeCompletionEscaping.ts @@ -0,0 +1,8 @@ +/// + +// @Filename: a.js +// @allowJs: true +////__foo;/**/ + +goTo.marker(); +verify.completionListContains("__foo", undefined, undefined, "warning"); From 792b23edc23684d0577143659cf9a37bab10dc73 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 14 Jun 2016 08:48:26 -0700 Subject: [PATCH 34/37] Make isDefinition required. For the deprecated getOccurrencesAtPosition, isDefinition is always false. --- src/server/client.ts | 1 + src/server/protocol.d.ts | 2 +- src/services/services.ts | 5 +++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/server/client.ts b/src/server/client.ts index ea6c948c4fb..864dac9fdaa 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -537,6 +537,7 @@ namespace ts.server { fileName, textSpan: ts.createTextSpanFromBounds(start, end), isWriteAccess: entry.isWriteAccess, + isDefinition: false }; }); } diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index dd29411f97d..b62d89ae520 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -308,7 +308,7 @@ declare namespace ts.server.protocol { /** * True if reference is a definition, false otherwise. */ - isDefinition?: boolean; + isDefinition: boolean; } /** diff --git a/src/services/services.ts b/src/services/services.ts index 5e1b69170a5..4f5bdbdc469 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1208,7 +1208,7 @@ namespace ts { textSpan: TextSpan; fileName: string; isWriteAccess: boolean; - isDefinition?: boolean; + isDefinition: boolean; } export interface DocumentHighlights { @@ -5750,7 +5750,8 @@ namespace ts { result.push({ fileName: entry.fileName, textSpan: highlightSpan.textSpan, - isWriteAccess: highlightSpan.kind === HighlightSpanKind.writtenReference + isWriteAccess: highlightSpan.kind === HighlightSpanKind.writtenReference, + isDefinition: false }); } } From 7bf40c49358edb44cfaaf79618455613158f7f4e Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 14 Jun 2016 09:39:30 -0700 Subject: [PATCH 35/37] Add more isDefinition tests and fix computed property bug --- src/services/services.ts | 2 +- .../getOccurrencesIsDefinitionOfBindingPattern.ts | 8 ++++++++ .../getOccurrencesIsDefinitionOfComputedProperty.ts | 9 +++++++++ .../fourslash/getOccurrencesIsDefinitionOfExport.ts | 11 +++++++++++ ...getOccurrencesIsDefinitionOfNumberNamedProperty.ts | 8 ++++++++ ...getOccurrencesIsDefinitionOfStringNamedProperty.ts | 8 ++++++++ 6 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/getOccurrencesIsDefinitionOfBindingPattern.ts create mode 100644 tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts create mode 100644 tests/cases/fourslash/getOccurrencesIsDefinitionOfExport.ts create mode 100644 tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts create mode 100644 tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts diff --git a/src/services/services.ts b/src/services/services.ts index 4f5bdbdc469..3cf6b432c5d 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -6741,7 +6741,7 @@ namespace ts { fileName: node.getSourceFile().fileName, textSpan: createTextSpanFromBounds(start, end), isWriteAccess: isWriteAccess(node), - isDefinition: isDeclarationName(node) + isDefinition: isDeclarationName(node) || node.parent.kind === SyntaxKind.ComputedPropertyName }; } diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfBindingPattern.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfBindingPattern.ts new file mode 100644 index 00000000000..9a30687c59e --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfBindingPattern.ts @@ -0,0 +1,8 @@ +/// +////const { [|{| "isDefinition": true |}x|], y } = { x: 1, y: 2 }; +////const z = [|{| "isDefinition": false |}x|]; +var firstRange = test.ranges()[0]; +goTo.position(firstRange.start, firstRange.fileName); +test.ranges().forEach(range => { + verify.referencesAtPositionContains(range, undefined, range.marker.data.isDefinition); +}); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts new file mode 100644 index 00000000000..8896694db50 --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts @@ -0,0 +1,9 @@ +/// +////let o = { ["[|{| "isDefinition": true |}foo|]"]: 12 }; +////let y = o.[|{| "isDefinition": false |}foo|]; +////let z = o['[|{| "isDefinition": false |}foo|]']; +var firstRange = test.ranges()[0]; +goTo.position(firstRange.start, firstRange.fileName); +test.ranges().forEach(range => { + verify.referencesAtPositionContains(range, undefined, range.marker.data.isDefinition); +}); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfExport.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfExport.ts new file mode 100644 index 00000000000..f863af9184f --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfExport.ts @@ -0,0 +1,11 @@ +/// +// @Filename: m.ts +////export var [|{| "isDefinition": true |}x|] = 12; +// @Filename: main.ts +////import { [|{| "isDefinition": true |}x|] } from "./m"; +////const y = [|{| "isDefinition": false |}x|]; +var firstRange = test.ranges()[0]; +goTo.position(firstRange.start, firstRange.fileName); +test.ranges().forEach(range => { + verify.referencesAtPositionContains(range, undefined, range.marker.data.isDefinition); +}); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts new file mode 100644 index 00000000000..7e3e084948f --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts @@ -0,0 +1,8 @@ +/// +////let o = { [|{| "isDefinition": true |}1|]: 12 }; +////let y = o[[|{| "isDefinition": false |}1|]]; +var firstRange = test.ranges()[0]; +goTo.position(firstRange.start, firstRange.fileName); +test.ranges().forEach(range => { + verify.referencesAtPositionContains(range, undefined, range.marker.data.isDefinition); +}); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts new file mode 100644 index 00000000000..291aec90dda --- /dev/null +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts @@ -0,0 +1,8 @@ +/// +////let o = { "[|{| "isDefinition": true |}x|]": 12 }; +////let y = o.[|{| "isDefinition": false |}x|]; +var firstRange = test.ranges()[0]; +goTo.position(firstRange.start, firstRange.fileName); +test.ranges().forEach(range => { + verify.referencesAtPositionContains(range, undefined, range.marker.data.isDefinition); +}); From 6b05ecab5bbdac72d1c94e32052c8053fa55fd7c Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 14 Jun 2016 09:39:48 -0700 Subject: [PATCH 36/37] Fix bug: do unescaping in the right place, so that it only affects escaped javascript identifiers --- src/services/services.ts | 4 ++-- tests/cases/fourslash/codeCompletionEscaping.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index d5f63627471..70cc7e2e08d 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -3234,7 +3234,7 @@ namespace ts { } } - return unescapeIdentifier(name); + return name; } function getCompletionData(fileName: string, position: number) { @@ -4141,7 +4141,7 @@ namespace ts { if (!uniqueNames[name]) { uniqueNames[name] = name; - const displayName = getCompletionEntryDisplayName(name, target, /*performCharacterChecks*/ true); + const displayName = getCompletionEntryDisplayName(unescapeIdentifier(name), target, /*performCharacterChecks*/ true); if (displayName) { const entry = { name: displayName, diff --git a/tests/cases/fourslash/codeCompletionEscaping.ts b/tests/cases/fourslash/codeCompletionEscaping.ts index b8182307b7b..5061a87e5b6 100644 --- a/tests/cases/fourslash/codeCompletionEscaping.ts +++ b/tests/cases/fourslash/codeCompletionEscaping.ts @@ -2,7 +2,8 @@ // @Filename: a.js // @allowJs: true -////__foo;/**/ +////___foo; __foo;/**/ goTo.marker(); verify.completionListContains("__foo", undefined, undefined, "warning"); +verify.completionListContains("___foo", undefined, undefined, "warning"); From 102a890214f21ef56fa5325cf8eb859beef743ae Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 14 Jun 2016 10:27:36 -0700 Subject: [PATCH 37/37] Use `isLiteralComputedPropertyDeclarationName` --- src/services/services.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/services.ts b/src/services/services.ts index 3cf6b432c5d..07094df7d2b 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -6741,7 +6741,7 @@ namespace ts { fileName: node.getSourceFile().fileName, textSpan: createTextSpanFromBounds(start, end), isWriteAccess: isWriteAccess(node), - isDefinition: isDeclarationName(node) || node.parent.kind === SyntaxKind.ComputedPropertyName + isDefinition: isDeclarationName(node) || isLiteralComputedPropertyDeclarationName(node) }; }