From 8965650bc332a8b86db77c8183098c9d8b511df1 Mon Sep 17 00:00:00 2001 From: Alexander Date: Sun, 12 May 2019 23:14:18 +0300 Subject: [PATCH 01/43] ignore trigger chars within a string literal --- src/services/completions.ts | 4 ++- .../completionsStringsWithTriggerCharacter.ts | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionsStringsWithTriggerCharacter.ts diff --git a/src/services/completions.ts b/src/services/completions.ts index 9d569fbedde4f..0d69f5951f856 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -40,7 +40,9 @@ namespace ts.Completions { const compilerOptions = program.getCompilerOptions(); const contextToken = findPrecedingToken(position, sourceFile); - if (triggerCharacter && !isValidTrigger(sourceFile, triggerCharacter, contextToken, position)) return undefined; + if (triggerCharacter && !isInString(sourceFile, position, contextToken) && !isValidTrigger(sourceFile, triggerCharacter, contextToken, position)) { + return undefined; + } const stringCompletions = StringCompletions.getStringLiteralCompletions(sourceFile, position, contextToken, typeChecker, compilerOptions, host, log, preferences); if (stringCompletions) { diff --git a/tests/cases/fourslash/completionsStringsWithTriggerCharacter.ts b/tests/cases/fourslash/completionsStringsWithTriggerCharacter.ts new file mode 100644 index 0000000000000..277218305f4a1 --- /dev/null +++ b/tests/cases/fourslash/completionsStringsWithTriggerCharacter.ts @@ -0,0 +1,30 @@ +/// + +//// type A = "a/b" | "b/a"; +//// const a: A = "a/*1*/"; +//// +//// type B = "a@b" | "b@a"; +//// const a: B = "a@/*2*/"; +//// +//// type C = "a.b" | "b.a"; +//// const c: C = "a./*3*/"; +//// +//// type D = "a'b" | "b'a"; +//// const d: D = "a'/*4*/"; +//// +//// type E = "a`b" | "b`a"; +//// const e: E = "a`/*5*/"; +//// +//// type F = 'a"b' | 'b"a'; +//// const f: F = 'a"/*6*/'; +//// +//// type G = "a Date: Thu, 16 May 2019 20:39:47 -0700 Subject: [PATCH 02/43] Fix newlines in smartSelection baselines to not be platform dependent (#31437) --- src/harness/fourslash.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index e306d2e338b84..df7f0051f3f1f 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1503,7 +1503,7 @@ Actual: ${stringify(fullActual)}`); } public baselineSmartSelection() { - const n = ts.sys.newLine; + const n = "\n"; const baselineFile = this.getBaselineFileName(); const markers = this.getMarkers(); const fileContent = this.activeFile.content; From eeba30afc81e2c7c8a34a2deb0d4d2375a1c21f6 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Fri, 17 May 2019 12:50:39 -0700 Subject: [PATCH 03/43] Fix infinite loop: module.exports alias detection (#31436) * Fix infinite loop: module.exports alias detection Previously, module.exports alias detection in the binder could enter an infinite recursion. Now it does not. Notably, there are *two* safeguards: a counter limiter that I set at 100, and an already-seen set. I actually prefer the counter limiter code because it's foolproof and uses less memory. But it takes 100 iterations to escape from loops. * fix space lint * Remove already-seen map --- src/compiler/binder.ts | 38 +++++++++++-------- ...initializedModuleExportsAssignment.symbols | 15 ++++++++ ...UninitializedModuleExportsAssignment.types | 16 ++++++++ ...derUninitializedModuleExportsAssignment.ts | 8 ++++ 4 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 tests/baselines/reference/binderUninitializedModuleExportsAssignment.symbols create mode 100644 tests/baselines/reference/binderUninitializedModuleExportsAssignment.types create mode 100644 tests/cases/conformance/salsa/binderUninitializedModuleExportsAssignment.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 96db98d337a73..cb6f67d66b1df 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2581,7 +2581,7 @@ namespace ts { // Fix up parent pointers since we're going to use these nodes before we bind into them node.left.parent = node; node.right.parent = node; - if (isIdentifier(lhs.expression) && container === file && isNameOfExportsOrModuleExportsAliasDeclaration(file, lhs.expression)) { + if (isIdentifier(lhs.expression) && container === file && isExportsOrModuleExportsOrAlias(file, lhs.expression)) { // This can be an alias for the 'exports' or 'module.exports' names, e.g. // var util = module.exports; // util.property = function ... @@ -2975,21 +2975,27 @@ namespace ts { } export function isExportsOrModuleExportsOrAlias(sourceFile: SourceFile, node: Expression): boolean { - return isExportsIdentifier(node) || - isModuleExportsPropertyAccessExpression(node) || - isIdentifier(node) && isNameOfExportsOrModuleExportsAliasDeclaration(sourceFile, node); - } - - function isNameOfExportsOrModuleExportsAliasDeclaration(sourceFile: SourceFile, node: Identifier): boolean { - const symbol = lookupSymbolForNameWorker(sourceFile, node.escapedText); - return !!symbol && !!symbol.valueDeclaration && isVariableDeclaration(symbol.valueDeclaration) && - !!symbol.valueDeclaration.initializer && isExportsOrModuleExportsOrAliasOrAssignment(sourceFile, symbol.valueDeclaration.initializer); - } - - function isExportsOrModuleExportsOrAliasOrAssignment(sourceFile: SourceFile, node: Expression): boolean { - return isExportsOrModuleExportsOrAlias(sourceFile, node) || - (isAssignmentExpression(node, /*excludeCompoundAssignment*/ true) && ( - isExportsOrModuleExportsOrAliasOrAssignment(sourceFile, node.left) || isExportsOrModuleExportsOrAliasOrAssignment(sourceFile, node.right))); + let i = 0; + const q = [node]; + while (q.length && i < 100) { + i++; + node = q.shift()!; + if (isExportsIdentifier(node) || isModuleExportsPropertyAccessExpression(node)) { + return true; + } + else if (isIdentifier(node)) { + const symbol = lookupSymbolForNameWorker(sourceFile, node.escapedText); + if (!!symbol && !!symbol.valueDeclaration && isVariableDeclaration(symbol.valueDeclaration) && !!symbol.valueDeclaration.initializer) { + const init = symbol.valueDeclaration.initializer; + q.push(init); + if (isAssignmentExpression(init, /*excludeCompoundAssignment*/ true)) { + q.push(init.left); + q.push(init.right); + } + } + } + } + return false; } function lookupSymbolForNameWorker(container: Node, name: __String): Symbol | undefined { diff --git a/tests/baselines/reference/binderUninitializedModuleExportsAssignment.symbols b/tests/baselines/reference/binderUninitializedModuleExportsAssignment.symbols new file mode 100644 index 0000000000000..73777fb2299df --- /dev/null +++ b/tests/baselines/reference/binderUninitializedModuleExportsAssignment.symbols @@ -0,0 +1,15 @@ +=== tests/cases/conformance/salsa/loop.js === +var loop1 = loop2; +>loop1 : Symbol(loop1, Decl(loop.js, 0, 3)) +>loop2 : Symbol(loop2, Decl(loop.js, 1, 3)) + +var loop2 = loop1; +>loop2 : Symbol(loop2, Decl(loop.js, 1, 3)) +>loop1 : Symbol(loop1, Decl(loop.js, 0, 3)) + +module.exports = loop2; +>module.exports : Symbol("tests/cases/conformance/salsa/loop", Decl(loop.js, 0, 0)) +>module : Symbol(export=, Decl(loop.js, 1, 18)) +>exports : Symbol(export=, Decl(loop.js, 1, 18)) +>loop2 : Symbol(loop2, Decl(loop.js, 1, 3)) + diff --git a/tests/baselines/reference/binderUninitializedModuleExportsAssignment.types b/tests/baselines/reference/binderUninitializedModuleExportsAssignment.types new file mode 100644 index 0000000000000..c8b8540cc562c --- /dev/null +++ b/tests/baselines/reference/binderUninitializedModuleExportsAssignment.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/salsa/loop.js === +var loop1 = loop2; +>loop1 : any +>loop2 : any + +var loop2 = loop1; +>loop2 : any +>loop1 : any + +module.exports = loop2; +>module.exports = loop2 : any +>module.exports : any +>module : { "tests/cases/conformance/salsa/loop": any; } +>exports : any +>loop2 : any + diff --git a/tests/cases/conformance/salsa/binderUninitializedModuleExportsAssignment.ts b/tests/cases/conformance/salsa/binderUninitializedModuleExportsAssignment.ts new file mode 100644 index 0000000000000..ef3ef213d3608 --- /dev/null +++ b/tests/cases/conformance/salsa/binderUninitializedModuleExportsAssignment.ts @@ -0,0 +1,8 @@ +// @noEmit: true +// @allowJs: true +// @checkJs: true +// @Filename: loop.js +var loop1 = loop2; +var loop2 = loop1; + +module.exports = loop2; From d67fe13e3088dbd78f849ec5595c86551b4a2b00 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 17 May 2019 13:10:09 -0700 Subject: [PATCH 04/43] Don't ignore index signatures in this type constraints --- src/compiler/checker.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9f5673af3eee9..18c1f42f838fb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3563,7 +3563,7 @@ namespace ts { context.approximateLength += 6; return createKeywordTypeNode(SyntaxKind.ObjectKeyword); } - if (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType) { + if (isThisTypeParameter(type)) { if (context.flags & NodeBuilderFlags.InObjectTypeLiteral) { if (!context.encounteredError && !(context.flags & NodeBuilderFlags.AllowThisInObjectLiteral)) { context.encounteredError = true; @@ -10193,6 +10193,10 @@ namespace ts { return maybeTypeOfKind(type, TypeFlags.InstantiableNonPrimitive | TypeFlags.Index); } + function isThisTypeParameter(type: Type): boolean { + return !!(type.flags & TypeFlags.TypeParameter && (type).isThisType); + } + function getSimplifiedType(type: Type, writing: boolean): Type { return type.flags & TypeFlags.IndexedAccess ? getSimplifiedIndexedAccessType(type, writing) : type.flags & TypeFlags.Conditional ? getSimplifiedConditionalType(type, writing) : @@ -16772,7 +16776,7 @@ namespace ts { } function narrowByInKeyword(type: Type, literal: LiteralExpression, assumeTrue: boolean) { - if ((type.flags & (TypeFlags.Union | TypeFlags.Object)) || (type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType)) { + if (type.flags & (TypeFlags.Union | TypeFlags.Object) || isThisTypeParameter(type)) { const propName = escapeLeadingUnderscores(literal.text); return filterType(type, t => isTypePresencePossible(t, propName, assumeTrue)); } @@ -20092,7 +20096,7 @@ namespace ts { return anyType; } if (right.escapedText && !checkAndReportErrorForExtendingInterface(node)) { - reportNonexistentProperty(right, leftType.flags & TypeFlags.TypeParameter && (leftType as TypeParameter).isThisType ? apparentType : leftType); + reportNonexistentProperty(right, isThisTypeParameter(leftType) ? apparentType : leftType); } return errorType; } @@ -20496,7 +20500,7 @@ namespace ts { const effectiveIndexType = isForInVariableForNumericPropertyNames(indexExpression) ? numberType : indexType; const accessFlags = isAssignmentTarget(node) ? - AccessFlags.Writing | (isGenericObjectType(objectType) ? AccessFlags.NoIndexSignatures : 0) : + AccessFlags.Writing | (isGenericObjectType(objectType) && !isThisTypeParameter(objectType) ? AccessFlags.NoIndexSignatures : 0) : AccessFlags.None; const indexedAccessType = getIndexedAccessTypeOrUndefined(objectType, effectiveIndexType, node, accessFlags) || errorType; return checkIndexedAccessIndexType(indexedAccessType, node); From c6a670d26cddfe97790e2f3c2d4c1670860b2b2f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 17 May 2019 15:59:01 -0700 Subject: [PATCH 05/43] Add regression test --- .../conformance/types/keyof/keyofAndIndexedAccess2.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts index 5251a83bb0611..a99c2b0a7a106 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts @@ -138,3 +138,12 @@ function fn4() { let x: Array[K] = 'abc'; let y: ReadonlyArray[K] = 'abc'; } + +// Repro from #31439 + +export class c { + [x: string]: string; + constructor() { + this["a"] = "b"; + } +} From 41a3f83b4e8e4ebbfe77446f08d5c1fadf56eee1 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 17 May 2019 15:59:07 -0700 Subject: [PATCH 06/43] Accept new baselines --- .../keyofAndIndexedAccess2.errors.txt | 9 +++++++++ .../reference/keyofAndIndexedAccess2.js | 15 +++++++++++++++ .../reference/keyofAndIndexedAccess2.symbols | 14 ++++++++++++++ .../reference/keyofAndIndexedAccess2.types | 18 ++++++++++++++++++ 4 files changed, 56 insertions(+) diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt b/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt index 5b749df2cab36..9ebf28f1857e9 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt @@ -219,4 +219,13 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(108,5): error TS23 let x: Array[K] = 'abc'; let y: ReadonlyArray[K] = 'abc'; } + + // Repro from #31439 + + export class c { + [x: string]: string; + constructor() { + this["a"] = "b"; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.js b/tests/baselines/reference/keyofAndIndexedAccess2.js index 7bf53b9fba491..374b13b5a643a 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.js +++ b/tests/baselines/reference/keyofAndIndexedAccess2.js @@ -136,6 +136,15 @@ function fn4() { let x: Array[K] = 'abc'; let y: ReadonlyArray[K] = 'abc'; } + +// Repro from #31439 + +export class c { + [x: string]: string; + constructor() { + this["a"] = "b"; + } +} //// [keyofAndIndexedAccess2.js] @@ -226,3 +235,9 @@ function fn4() { let x = 'abc'; let y = 'abc'; } +// Repro from #31439 +export class c { + constructor() { + this["a"] = "b"; + } +} diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.symbols b/tests/baselines/reference/keyofAndIndexedAccess2.symbols index 2155451ef7497..a3412e8a47d31 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess2.symbols @@ -503,3 +503,17 @@ function fn4() { >K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 133, 13)) } +// Repro from #31439 + +export class c { +>c : Symbol(c, Decl(keyofAndIndexedAccess2.ts, 136, 1)) + + [x: string]: string; +>x : Symbol(x, Decl(keyofAndIndexedAccess2.ts, 141, 3)) + + constructor() { + this["a"] = "b"; +>this : Symbol(c, Decl(keyofAndIndexedAccess2.ts, 136, 1)) + } +} + diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.types b/tests/baselines/reference/keyofAndIndexedAccess2.types index af43ed0f4eb27..b7b71ba4f9f71 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.types +++ b/tests/baselines/reference/keyofAndIndexedAccess2.types @@ -499,3 +499,21 @@ function fn4() { >'abc' : "abc" } +// Repro from #31439 + +export class c { +>c : c + + [x: string]: string; +>x : string + + constructor() { + this["a"] = "b"; +>this["a"] = "b" : "b" +>this["a"] : string +>this : this +>"a" : "a" +>"b" : "b" + } +} + From 309ae224f0cd0c98eb3497b082aa39acd0d796ab Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 20 May 2019 06:23:30 -0700 Subject: [PATCH 07/43] Cache unnormalized intersection types --- src/compiler/checker.ts | 57 ++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 18c1f42f838fb..4a1089ff114e5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -391,7 +391,7 @@ namespace ts { const tupleTypes = createMap(); const unionTypes = createMap(); - const intersectionTypes = createMap(); + const intersectionTypes = createMap(); const literalTypes = createMap(); const indexedAccessTypes = createMap(); const substitutionTypes = createMap(); @@ -9838,6 +9838,15 @@ namespace ts { return true; } + function createIntersectionType(types: Type[], aliasSymbol?: Symbol, aliasTypeArguments?: ReadonlyArray) { + const result = createType(TypeFlags.Intersection); + result.objectFlags = getPropagatingFlagsOfTypes(types, /*excludeKinds*/ TypeFlags.Nullable); + result.types = types; + result.aliasSymbol = aliasSymbol; // See comment in `getUnionTypeFromSortedList`. + result.aliasTypeArguments = aliasTypeArguments; + return result; + } + // We normalize combinations of intersection and union types based on the distributive property of the '&' // operator. Specifically, because X & (A | B) is equivalent to X & A | X & B, we can transform intersection // types with union type constituents into equivalent union types with intersection type constituents and @@ -9875,31 +9884,31 @@ namespace ts { if (typeSet.length === 1) { return typeSet[0]; } - if (includes & TypeFlags.Union) { - if (intersectUnionsOfPrimitiveTypes(typeSet)) { - // When the intersection creates a reduced set (which might mean that *all* union types have - // disappeared), we restart the operation to get a new set of combined flags. Once we have - // reduced we'll never reduce again, so this occurs at most once. - return getIntersectionType(typeSet, aliasSymbol, aliasTypeArguments); - } - // We are attempting to construct a type of the form X & (A | B) & Y. Transform this into a type of - // the form X & A & Y | X & B & Y and recursively reduce until no union type constituents remain. - const unionIndex = findIndex(typeSet, t => (t.flags & TypeFlags.Union) !== 0); - const unionType = typeSet[unionIndex]; - return getUnionType(map(unionType.types, t => getIntersectionType(replaceElement(typeSet, unionIndex, t))), - UnionReduction.Literal, aliasSymbol, aliasTypeArguments); - } const id = getTypeListId(typeSet); - let type = intersectionTypes.get(id); - if (!type) { - type = createType(TypeFlags.Intersection); - intersectionTypes.set(id, type); - type.objectFlags = getPropagatingFlagsOfTypes(typeSet, /*excludeKinds*/ TypeFlags.Nullable); - type.types = typeSet; - type.aliasSymbol = aliasSymbol; // See comment in `getUnionTypeFromSortedList`. - type.aliasTypeArguments = aliasTypeArguments; + let result = intersectionTypes.get(id); + if (!result) { + if (includes & TypeFlags.Union) { + if (intersectUnionsOfPrimitiveTypes(typeSet)) { + // When the intersection creates a reduced set (which might mean that *all* union types have + // disappeared), we restart the operation to get a new set of combined flags. Once we have + // reduced we'll never reduce again, so this occurs at most once. + result = getIntersectionType(typeSet, aliasSymbol, aliasTypeArguments); + } + else { + // We are attempting to construct a type of the form X & (A | B) & Y. Transform this into a type of + // the form X & A & Y | X & B & Y and recursively reduce until no union type constituents remain. + const unionIndex = findIndex(typeSet, t => (t.flags & TypeFlags.Union) !== 0); + const unionType = typeSet[unionIndex]; + result = getUnionType(map(unionType.types, t => getIntersectionType(replaceElement(typeSet, unionIndex, t))), + UnionReduction.Literal, aliasSymbol, aliasTypeArguments); + } + } + else { + result = createIntersectionType(typeSet, aliasSymbol, aliasTypeArguments); + } + intersectionTypes.set(id, result); } - return type; + return result; } function getTypeFromIntersectionTypeNode(node: IntersectionTypeNode): Type { From 9052804576cefbc239df539e3ddad522568cfb71 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 20 May 2019 12:50:29 -0700 Subject: [PATCH 08/43] Test docCommentTemplate for prototype methods (#31477) This works in 3.5, but didn't in 3.2. Adding a test to make sure it stays working. --- .../docCommentTemplatePrototypeMethod.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/cases/fourslash/docCommentTemplatePrototypeMethod.ts diff --git a/tests/cases/fourslash/docCommentTemplatePrototypeMethod.ts b/tests/cases/fourslash/docCommentTemplatePrototypeMethod.ts new file mode 100644 index 0000000000000..9031898d52ae0 --- /dev/null +++ b/tests/cases/fourslash/docCommentTemplatePrototypeMethod.ts @@ -0,0 +1,15 @@ +/// +// @Filename: foo.js + +/////** @class */ +////function C() { } +/////*above*/ +////C.prototype.method = /*next*/ function (p) {} + +for (const marker of test.markerNames()) { + verify.docCommentTemplateAt(marker, 8, +`/** + * + * @param {any} p + */`); +} From 00cea41b6545ef7405bf8a5709fa9275b154c8a4 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 16 May 2019 14:46:10 -0700 Subject: [PATCH 09/43] Add sortText depending scope of symbols Fixes #15024 --- src/harness/fourslash.ts | 112 ++++++++++++---- src/services/completions.ts | 124 ++++++++++++++---- src/services/stringCompletions.ts | 14 +- .../unittests/tsserver/completions.ts | 2 +- .../cases/fourslash/codeCompletionEscaping.ts | 4 +- .../fourslash/completionAfterGlobalThis.ts | 6 +- .../completionEntryForClassMembers.ts | 8 +- .../fourslash/completionEntryInJsFile.ts | 22 +++- .../fourslash/completionInFunctionLikeBody.ts | 4 +- .../fourslash/completionInJSDocFunctionNew.ts | 2 +- .../completionInJSDocFunctionThis.ts | 2 +- tests/cases/fourslash/completionInJsDoc.ts | 2 +- ...pletionListAtEndOfWordInArrowFunction02.ts | 6 +- ...pletionListAtEndOfWordInArrowFunction03.ts | 2 +- ...tInClosedObjectTypeLiteralInSignature04.ts | 6 +- .../completionListInNamedClassExpression.ts | 6 +- ...nUnclosedObjectTypeLiteralInSignature04.ts | 6 +- .../completionListIsGlobalCompletion.ts | 2 +- .../cases/fourslash/completionListKeywords.ts | 9 +- .../fourslash/completionListWithMeanings.ts | 6 +- .../completionListWithModulesFromModule.ts | 12 +- ...pletionListWithModulesInsideModuleScope.ts | 11 +- ...letionListWithModulesOutsideModuleScope.ts | 2 +- .../completionListWithUnresolvedModule.ts | 8 +- .../completionsGeneratorFunctions.ts | 2 +- .../fourslash/completionsImportBaseUrl.ts | 1 + .../completionsImport_augmentation.ts | 2 + ...completionsImport_compilerOptionsModule.ts | 17 ++- .../completionsImport_defaultFalsePositive.ts | 1 + ...letionsImport_default_addToNamedImports.ts | 1 + ...ionsImport_default_addToNamespaceImport.ts | 1 + ...Import_default_alreadyExistedWithRename.ts | 1 + .../completionsImport_default_anonymous.ts | 20 ++- ...letionsImport_default_didNotExistBefore.ts | 1 + ...sImport_default_exportDefaultIdentifier.ts | 10 +- ...nsImport_default_fromMergedDeclarations.ts | 1 + .../completionsImport_exportEquals.ts | 14 +- ...mport_exportEqualsNamespace_noDuplicate.ts | 2 +- ...ompletionsImport_exportEquals_anonymous.ts | 21 ++- .../fourslash/completionsImport_importType.ts | 2 + .../fourslash/completionsImport_keywords.ts | 13 +- .../fourslash/completionsImport_matching.ts | 11 +- .../completionsImport_multipleWithSameName.ts | 14 +- ...mpletionsImport_named_addToNamedImports.ts | 1 + ...mpletionsImport_named_didNotExistBefore.ts | 21 ++- ...tionsImport_named_exportEqualsNamespace.ts | 1 + ...port_named_exportEqualsNamespace_merged.ts | 1 + ...tionsImport_named_namespaceImportExists.ts | 1 + .../completionsImport_notFromIndex.ts | 1 + .../fourslash/completionsImport_ofAlias.ts | 12 +- ...mpletionsImport_ofAlias_preferShortPath.ts | 15 ++- ...pletionsImport_previousTokenIsSemicolon.ts | 1 + .../completionsImport_reExportDefault.ts | 6 +- .../completionsImport_reExport_wrongName.ts | 18 ++- .../fourslash/completionsImport_require.ts | 1 + .../completionsImport_shadowedByLocal.ts | 40 +++--- .../cases/fourslash/completionsImport_tsx.ts | 2 +- .../fourslash/completionsInterfaceElement.ts | 9 +- .../fourslash/completionsJsdocTypeTagCast.ts | 8 +- .../completionsJsxAttributeInitializer.ts | 4 +- .../fourslash/completionsKeywordsExtends.ts | 2 +- .../completionsRecommended_import.ts | 1 + .../completionsRecommended_namespace.ts | 1 + tests/cases/fourslash/completionsThisType.ts | 6 +- .../fourslash/completionsTypeKeywords.ts | 2 +- .../fourslash/doubleUnderscoreCompletions.ts | 4 +- tests/cases/fourslash/fourslash.ts | 10 ++ .../fourslash/getJavaScriptCompletions12.ts | 2 +- .../fourslash/getJavaScriptCompletions13.ts | 21 ++- .../fourslash/getJavaScriptCompletions15.ts | 12 +- .../fourslash/getJavaScriptCompletions20.ts | 9 +- .../getJavaScriptGlobalCompletions1.ts | 2 +- tests/cases/fourslash/importJsNodeModule2.ts | 2 +- .../fourslash/indirectClassInstantiation.ts | 13 +- tests/cases/fourslash/javaScriptClass1.ts | 10 +- tests/cases/fourslash/javaScriptModules12.ts | 44 ++++++- tests/cases/fourslash/javaScriptModules13.ts | 6 +- tests/cases/fourslash/javaScriptModules14.ts | 6 +- tests/cases/fourslash/javaScriptModules16.ts | 2 +- tests/cases/fourslash/javaScriptModules19.ts | 6 +- tests/cases/fourslash/javaScriptPrototype2.ts | 2 +- tests/cases/fourslash/javaScriptPrototype3.ts | 6 +- tests/cases/fourslash/javaScriptPrototype4.ts | 5 +- tests/cases/fourslash/javascriptModules20.ts | 6 +- tests/cases/fourslash/javascriptModules21.ts | 8 +- ...JsdocTypedefTagTypeExpressionCompletion.ts | 2 +- ...sdocTypedefTagTypeExpressionCompletion2.ts | 4 +- ...sdocTypedefTagTypeExpressionCompletion3.ts | 2 +- ...oImportCompletionsInOtherJavaScriptFile.ts | 2 + .../server/jsdocTypedefTagNamespace.ts | 2 +- tests/cases/fourslash/tsxCompletion9.ts | 2 +- .../fourslash/tsxCompletionNonTagLessThan.ts | 19 ++- .../tsxCompletionOnOpeningTagWithoutJSX1.ts | 2 +- 93 files changed, 700 insertions(+), 178 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index df7f0051f3f1f..8a0a2bffbd4d6 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -798,8 +798,8 @@ namespace FourSlash { } private verifyCompletionEntry(actual: ts.CompletionEntry, expected: FourSlashInterface.ExpectedCompletionEntry) { - const { insertText, replacementSpan, hasAction, isRecommended, kind, kindModifiers, text, documentation, tags, source, sourceDisplay } = typeof expected === "string" - ? { insertText: undefined, replacementSpan: undefined, hasAction: undefined, isRecommended: undefined, kind: undefined, kindModifiers: undefined, text: undefined, documentation: undefined, tags: undefined, source: undefined, sourceDisplay: undefined } + const { insertText, replacementSpan, hasAction, isRecommended, kind, kindModifiers, text, documentation, tags, source, sourceDisplay, sortText } = typeof expected === "string" + ? { insertText: undefined, replacementSpan: undefined, hasAction: undefined, isRecommended: undefined, kind: undefined, kindModifiers: undefined, text: undefined, documentation: undefined, tags: undefined, source: undefined, sourceDisplay: undefined, sortText: undefined } : expected; if (actual.insertText !== insertText) { @@ -825,6 +825,7 @@ namespace FourSlash { assert.equal(actual.hasAction, hasAction); assert.equal(actual.isRecommended, isRecommended); assert.equal(actual.source, source); + assert.equal(actual.sortText, sortText || ts.Completions.SortText.LocationPriority, this.messageAtLastKnownMarker(`Actual entry: ${JSON.stringify(actual)}`)); if (text !== undefined) { const actualDetails = this.getCompletionEntryDetails(actual.name, actual.source)!; @@ -4434,18 +4435,63 @@ namespace FourSlashInterface { } } export namespace Completion { - const functionEntry = (name: string): ExpectedCompletionEntryObject => ({ name, kind: "function", kindModifiers: "declare" }); - const varEntry = (name: string): ExpectedCompletionEntryObject => ({ name, kind: "var", kindModifiers: "declare" }); - const moduleEntry = (name: string): ExpectedCompletionEntryObject => ({ name, kind: "module", kindModifiers: "declare" }); - const keywordEntry = (name: string): ExpectedCompletionEntryObject => ({ name, kind: "keyword" }); - const methodEntry = (name: string): ExpectedCompletionEntryObject => ({ name, kind: "method", kindModifiers: "declare" }); - const propertyEntry = (name: string): ExpectedCompletionEntryObject => ({ name, kind: "property", kindModifiers: "declare" }); - const interfaceEntry = (name: string): ExpectedCompletionEntryObject => ({ name, kind: "interface", kindModifiers: "declare" }); - const typeEntry = (name: string): ExpectedCompletionEntryObject => ({ name, kind: "type", kindModifiers: "declare" }); + export import SortText = ts.Completions.SortText; + + const functionEntry = (name: string): ExpectedCompletionEntryObject => ({ + name, + kind: "function", + kindModifiers: "declare", + sortText: SortText.GlobalsOrKeywords + }); + const varEntry = (name: string): ExpectedCompletionEntryObject => ({ + name, + kind: "var", + kindModifiers: "declare", + sortText: SortText.GlobalsOrKeywords + }); + const moduleEntry = (name: string): ExpectedCompletionEntryObject => ({ + name, + kind: "module", + kindModifiers: "declare", + sortText: SortText.GlobalsOrKeywords + }); + const keywordEntry = (name: string): ExpectedCompletionEntryObject => ({ + name, + kind: "keyword", + sortText: SortText.GlobalsOrKeywords + }); + const methodEntry = (name: string): ExpectedCompletionEntryObject => ({ + name, + kind: "method", + kindModifiers: "declare", + sortText: SortText.LocationPriority + }); + const propertyEntry = (name: string): ExpectedCompletionEntryObject => ({ + name, + kind: "property", + kindModifiers: "declare", + sortText: SortText.LocationPriority + }); + const interfaceEntry = (name: string): ExpectedCompletionEntryObject => ({ + name, + kind: "interface", + kindModifiers: "declare", + sortText: SortText.GlobalsOrKeywords + }); + const typeEntry = (name: string): ExpectedCompletionEntryObject => ({ + name, + kind: "type", + kindModifiers: "declare", + sortText: SortText.GlobalsOrKeywords + }); const res: ExpectedCompletionEntryObject[] = []; for (let i = ts.SyntaxKind.FirstKeyword; i <= ts.SyntaxKind.LastKeyword; i++) { - res.push({ name: ts.Debug.assertDefined(ts.tokenToString(i)), kind: "keyword" }); + res.push({ + name: ts.Debug.assertDefined(ts.tokenToString(i)), + kind: "keyword", + sortText: SortText.GlobalsOrKeywords + }); } export const keywordsWithUndefined: ReadonlyArray = res; export const keywords: ReadonlyArray = keywordsWithUndefined.filter(k => k.name !== "undefined"); @@ -4552,11 +4598,15 @@ namespace FourSlashInterface { moduleEntry("Intl"), ]; + export const globalThisEntry: ExpectedCompletionEntry = { + name: "globalThis", + kind: "module", + sortText: SortText.GlobalsOrKeywords + }; export const globalTypes = globalTypesPlus([]); - export function globalTypesPlus(plus: ReadonlyArray): ReadonlyArray { return [ - { name: "globalThis", kind: "module" }, + globalThisEntry, ...globalTypeDecls, ...plus, ...typeKeywords, @@ -4605,7 +4655,11 @@ namespace FourSlashInterface { export const classElementInJsKeywords = getInJsKeywords(classElementKeywords); export const constructorParameterKeywords: ReadonlyArray = - ["private", "protected", "public", "readonly"].map((name): ExpectedCompletionEntryObject => ({ name, kind: "keyword" })); + ["private", "protected", "public", "readonly"].map((name): ExpectedCompletionEntryObject => ({ + name, + kind: "keyword", + sortText: SortText.GlobalsOrKeywords + })); export const functionMembers: ReadonlyArray = [ methodEntry("apply"), @@ -4834,13 +4888,18 @@ namespace FourSlashInterface { "await", ].map(keywordEntry); + export const undefinedVarEntry: ExpectedCompletionEntry = { + name: "undefined", + kind: "var", + sortText: SortText.GlobalsOrKeywords + }; // TODO: many of these are inappropriate to always provide export const globalsInsideFunction = (plus: ReadonlyArray): ReadonlyArray => [ { name: "arguments", kind: "local var" }, ...plus, - { name: "globalThis", kind: "module" }, + globalThisEntry, ...globalsVars, - { name: "undefined", kind: "var" }, + undefinedVarEntry, ...globalKeywordsInsideFunction, ]; @@ -4849,10 +4908,10 @@ namespace FourSlashInterface { // TODO: many of these are inappropriate to always provide export const globalsInJsInsideFunction = (plus: ReadonlyArray): ReadonlyArray => [ { name: "arguments", kind: "local var" }, - { name: "globalThis", kind: "module" }, + globalThisEntry, ...globalsVars, ...plus, - { name: "undefined", kind: "var" }, + undefinedVarEntry, ...globalInJsKeywordsInsideFunction, ]; @@ -4990,34 +5049,34 @@ namespace FourSlashInterface { })(); export const globals: ReadonlyArray = [ - { name: "globalThis", kind: "module" }, + globalThisEntry, ...globalsVars, - { name: "undefined", kind: "var" }, + undefinedVarEntry, ...globalKeywords ]; export const globalsInJs: ReadonlyArray = [ - { name: "globalThis", kind: "module" }, + globalThisEntry, ...globalsVars, - { name: "undefined", kind: "var" }, + undefinedVarEntry, ...globalInJsKeywords ]; export function globalsPlus(plus: ReadonlyArray): ReadonlyArray { return [ - { name: "globalThis", kind: "module" }, + globalThisEntry, ...globalsVars, ...plus, - { name: "undefined", kind: "var" }, + undefinedVarEntry, ...globalKeywords]; } export function globalsInJsPlus(plus: ReadonlyArray): ReadonlyArray { return [ - { name: "globalThis", kind: "module" }, + globalThisEntry, ...globalsVars, ...plus, - { name: "undefined", kind: "var" }, + undefinedVarEntry, ...globalInJsKeywords]; } } @@ -5050,6 +5109,7 @@ namespace FourSlashInterface { readonly documentation?: string; readonly sourceDisplay?: string; readonly tags?: ReadonlyArray; + readonly sortText?: ts.Completions.SortText; } export interface VerifyCompletionsOptions { diff --git a/src/services/completions.ts b/src/services/completions.ts index 9d569fbedde4f..1adfc1e480f37 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1,5 +1,12 @@ /* @internal */ namespace ts.Completions { + export enum SortText { + LocationPriority = "0", + SuggestedClassMembers = "1", + GlobalsOrKeywords = "2", + AutoImportSuggestions = "3", + JavascriptIdentifiers = "4" + } export type Log = (message: string) => void; const enum SymbolOriginInfoKind { ThisType, SymbolMemberNoExport, SymbolMemberExport, Export } @@ -22,6 +29,8 @@ namespace ts.Completions { */ type SymbolOriginInfoMap = (SymbolOriginInfo | undefined)[]; + type SymbolSortTextMap = (SortText | undefined)[]; + const enum KeywordCompletionFilters { None, // No keywords All, // Every possible keyword (TODO: This is never appropriate) @@ -78,7 +87,21 @@ namespace ts.Completions { } function completionInfoFromData(sourceFile: SourceFile, typeChecker: TypeChecker, compilerOptions: CompilerOptions, log: Log, completionData: CompletionData, preferences: UserPreferences): CompletionInfo | undefined { - const { symbols, completionKind, isInSnippetScope, isNewIdentifierLocation, location, propertyAccessToConvert, keywordFilters, literals, symbolToOriginInfoMap, recommendedCompletion, isJsxInitializer, insideJsDocTagTypeExpression } = completionData; + const { + symbols, + completionKind, + isInSnippetScope, + isNewIdentifierLocation, + location, + propertyAccessToConvert, + keywordFilters, + literals, + symbolToOriginInfoMap, + recommendedCompletion, + isJsxInitializer, + insideJsDocTagTypeExpression, + symbolToSortTextMap, + } = completionData; if (location && location.parent && isJsxClosingElement(location.parent)) { // In the TypeScript JSX element, if such element is not defined. When users query for completion at closing tag, @@ -93,7 +116,7 @@ namespace ts.Completions { name: tagName.getFullText(sourceFile) + (hasClosingAngleBracket ? "" : ">"), kind: ScriptElementKind.classElement, kindModifiers: undefined, - sortText: "0", + sortText: SortText.LocationPriority, }; return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: false, entries: [entry] }; } @@ -101,7 +124,22 @@ namespace ts.Completions { const entries: CompletionEntry[] = []; if (isUncheckedFile(sourceFile, compilerOptions)) { - const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries, location, sourceFile, typeChecker, compilerOptions.target!, log, completionKind, preferences, propertyAccessToConvert, isJsxInitializer, recommendedCompletion, symbolToOriginInfoMap); + const uniqueNames = getCompletionEntriesFromSymbols( + symbols, + entries, + location, + sourceFile, + typeChecker, + compilerOptions.target!, + log, + completionKind, + preferences, + propertyAccessToConvert, + isJsxInitializer, + recommendedCompletion, + symbolToOriginInfoMap, + symbolToSortTextMap + ); getJSCompletionEntries(sourceFile, location!.pos, uniqueNames, compilerOptions.target!, entries); // TODO: GH#18217 } else { @@ -109,7 +147,22 @@ namespace ts.Completions { return undefined; } - getCompletionEntriesFromSymbols(symbols, entries, location, sourceFile, typeChecker, compilerOptions.target!, log, completionKind, preferences, propertyAccessToConvert, isJsxInitializer, recommendedCompletion, symbolToOriginInfoMap); + getCompletionEntriesFromSymbols( + symbols, + entries, + location, + sourceFile, + typeChecker, + compilerOptions.target!, + log, + completionKind, + preferences, + propertyAccessToConvert, + isJsxInitializer, + recommendedCompletion, + symbolToOriginInfoMap, + symbolToSortTextMap + ); } if (keywordFilters !== KeywordCompletionFilters.None) { @@ -160,7 +213,7 @@ namespace ts.Completions { name: realName, kind: ScriptElementKind.warning, kindModifiers: "", - sortText: "1" + sortText: SortText.JavascriptIdentifiers }); } }); @@ -169,28 +222,23 @@ namespace ts.Completions { const completionNameForLiteral = (literal: string | number | PseudoBigInt) => typeof literal === "object" ? pseudoBigIntToString(literal) + "n" : JSON.stringify(literal); function createCompletionEntryForLiteral(literal: string | number | PseudoBigInt): CompletionEntry { - return { name: completionNameForLiteral(literal), kind: ScriptElementKind.string, kindModifiers: ScriptElementKindModifier.none, sortText: "0" }; + return { name: completionNameForLiteral(literal), kind: ScriptElementKind.string, kindModifiers: ScriptElementKindModifier.none, sortText: SortText.LocationPriority }; } function createCompletionEntry( symbol: Symbol, + sortText: SortText, location: Node | undefined, sourceFile: SourceFile, typeChecker: TypeChecker, - target: ScriptTarget, - kind: CompletionKind, + name: string, + needsConvertPropertyAccess: boolean, origin: SymbolOriginInfo | undefined, recommendedCompletion: Symbol | undefined, propertyAccessToConvert: PropertyAccessExpression | undefined, isJsxInitializer: IsJsxInitializer | undefined, preferences: UserPreferences, ): CompletionEntry | undefined { - const info = getCompletionEntryDisplayNameForSymbol(symbol, target, origin, kind); - if (!info) { - return undefined; - } - const { name, needsConvertPropertyAccess } = info; - let insertText: string | undefined; let replacementSpan: TextSpan | undefined; if (origin && origin.kind === SymbolOriginInfoKind.ThisType) { @@ -230,7 +278,7 @@ namespace ts.Completions { name, kind: SymbolDisplay.getSymbolKind(typeChecker, symbol, location!), // TODO: GH#18217 kindModifiers: SymbolDisplay.getSymbolModifiers(symbol), - sortText: "0", + sortText, source: getSourceFromOrigin(origin), hasAction: trueOrUndefined(!!origin && originIsExport(origin)), isRecommended: trueOrUndefined(isRecommendedCompletionMatch(symbol, recommendedCompletion, typeChecker)), @@ -266,6 +314,7 @@ namespace ts.Completions { isJsxInitializer?: IsJsxInitializer, recommendedCompletion?: Symbol, symbolToOriginInfoMap?: SymbolOriginInfoMap, + symbolToSortTextMap?: SymbolSortTextMap, ): Map { const start = timestamp(); // Tracks unique names. @@ -275,16 +324,33 @@ namespace ts.Completions { const uniques = createMap(); for (const symbol of symbols) { const origin = symbolToOriginInfoMap ? symbolToOriginInfoMap[getSymbolId(symbol)] : undefined; - const entry = createCompletionEntry(symbol, location, sourceFile, typeChecker, target, kind, origin, recommendedCompletion, propertyAccessToConvert, isJsxInitializer, preferences); - if (!entry) { + const info = getCompletionEntryDisplayNameForSymbol(symbol, target, origin, kind); + if (!info) { continue; } - - const { name } = entry; + const { name, needsConvertPropertyAccess } = info; if (uniques.has(name)) { continue; } + const entry = createCompletionEntry( + symbol, + symbolToSortTextMap && symbolToSortTextMap[getSymbolId(symbol)] || SortText.LocationPriority, + location, + sourceFile, + typeChecker, + name, + needsConvertPropertyAccess, + origin, + recommendedCompletion, + propertyAccessToConvert, + isJsxInitializer, + preferences + ); + if (!entry) { + continue; + } + // Latter case tests whether this is a global variable. if (!origin && !(symbol.parent === undefined && !some(symbol.declarations, d => d.getSourceFile() === location!.getSourceFile()))) { // TODO: GH#18217 uniques.set(name, true); @@ -321,7 +387,7 @@ namespace ts.Completions { name, kindModifiers: ScriptElementKindModifier.none, kind: ScriptElementKind.label, - sortText: "0" + sortText: SortText.LocationPriority }); } } @@ -358,7 +424,7 @@ namespace ts.Completions { // We don't need to perform character checks here because we're only comparing the // name against 'entryName' (which is known to be good), not building a new // completion entry. - return firstDefined(symbols, (symbol): SymbolCompletion | undefined => { // TODO: Shouldn't need return type annotation (GH#12632) + return firstDefined(symbols, (symbol): SymbolCompletion | undefined => { const origin = symbolToOriginInfoMap[getSymbolId(symbol)]; const info = getCompletionEntryDisplayNameForSymbol(symbol, compilerOptions.target!, origin, completionKind); return info && info.name === entryId.name && getSourceFromOrigin(origin) === entryId.source @@ -512,6 +578,7 @@ namespace ts.Completions { readonly previousToken: Node | undefined; readonly isJsxInitializer: IsJsxInitializer; readonly insideJsDocTagTypeExpression: boolean; + readonly symbolToSortTextMap: SymbolSortTextMap; } type Request = { readonly kind: CompletionDataKind.JsDocTagName | CompletionDataKind.JsDocTag } | { readonly kind: CompletionDataKind.JsDocParameterName, tag: JSDocParameterTag }; @@ -804,6 +871,7 @@ namespace ts.Completions { let keywordFilters = KeywordCompletionFilters.None; let symbols: Symbol[] = []; const symbolToOriginInfoMap: SymbolOriginInfoMap = []; + const symbolToSortTextMap: SymbolSortTextMap = []; if (isRightOfDot) { getTypeScriptMemberSymbols(); @@ -853,7 +921,8 @@ namespace ts.Completions { recommendedCompletion, previousToken, isJsxInitializer, - insideJsDocTagTypeExpression + insideJsDocTagTypeExpression, + symbolToSortTextMap }; type JSDocTagWithTypeExpression = JSDocParameterTag | JSDocPropertyTag | JSDocReturnTag | JSDocTypeTag | JSDocTypedefTag; @@ -1054,6 +1123,12 @@ namespace ts.Completions { const symbolMeanings = (isTypeOnly ? SymbolFlags.None : SymbolFlags.Value) | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias; symbols = Debug.assertEachDefined(typeChecker.getSymbolsInScope(scopeNode, symbolMeanings), "getSymbolsInScope() should all be defined"); + for (const symbol of symbols) { + if (!typeChecker.isArgumentsSymbol(symbol) && + !some(symbol.declarations, d => d.getSourceFile() === sourceFile)) { + symbolToSortTextMap[getSymbolId(symbol)] = SortText.GlobalsOrKeywords; + } + } // Need to insert 'this.' before properties of `this` type, so only do that if `includeInsertTextCompletions` if (preferences.includeCompletionsWithInsertText && scopeNode.kind !== SyntaxKind.SourceFile) { @@ -1062,6 +1137,7 @@ namespace ts.Completions { for (const symbol of getPropertiesForCompletion(thisType, typeChecker)) { symbolToOriginInfoMap[getSymbolId(symbol)] = { kind: SymbolOriginInfoKind.ThisType }; symbols.push(symbol); + symbolToSortTextMap[getSymbolId(symbol)] = SortText.SuggestedClassMembers; } } } @@ -1195,6 +1271,7 @@ namespace ts.Completions { // So in `declare namespace foo {} declare module "foo" { export = foo; }`, there will just be the global completion for `foo`. some(resolvedModuleSymbol.declarations, d => !!d.getSourceFile().externalModuleIndicator)) { symbols.push(resolvedModuleSymbol); + symbolToSortTextMap[getSymbolId(resolvedModuleSymbol)] = SortText.AutoImportSuggestions; symbolToOriginInfoMap[getSymbolId(resolvedModuleSymbol)] = { kind: SymbolOriginInfoKind.Export, moduleSymbol, isDefaultExport: false }; } @@ -1220,6 +1297,7 @@ namespace ts.Completions { const origin: SymbolOriginInfoExport = { kind: SymbolOriginInfoKind.Export, moduleSymbol, isDefaultExport }; if (detailsEntryId || stringContainsCharactersInOrder(getSymbolName(symbol, origin, target).toLowerCase(), tokenTextLowerCase)) { symbols.push(symbol); + symbolToSortTextMap[getSymbolId(symbol)] = SortText.AutoImportSuggestions; symbolToOriginInfoMap[getSymbolId(symbol)] = origin; } } @@ -1941,7 +2019,7 @@ namespace ts.Completions { name: tokenToString(i)!, kind: ScriptElementKind.keyword, kindModifiers: ScriptElementKindModifier.none, - sortText: "0" + sortText: SortText.GlobalsOrKeywords }); } return res; diff --git a/src/services/stringCompletions.ts b/src/services/stringCompletions.ts index aafe90760560f..b287ebdb406a9 100644 --- a/src/services/stringCompletions.ts +++ b/src/services/stringCompletions.ts @@ -21,7 +21,17 @@ namespace ts.Completions.StringCompletions { return convertPathCompletions(completion.paths); case StringLiteralCompletionKind.Properties: { const entries: CompletionEntry[] = []; - getCompletionEntriesFromSymbols(completion.symbols, entries, sourceFile, sourceFile, checker, ScriptTarget.ESNext, log, CompletionKind.String, preferences); // Target will not be used, so arbitrary + getCompletionEntriesFromSymbols( + completion.symbols, + entries, + sourceFile, + sourceFile, + checker, + ScriptTarget.ESNext, + log, + CompletionKind.String, + preferences + ); // Target will not be used, so arbitrary return { isGlobalCompletion: false, isMemberCompletion: true, isNewIdentifierLocation: completion.hasIndexSignature, entries }; } case StringLiteralCompletionKind.Types: { @@ -60,7 +70,7 @@ namespace ts.Completions.StringCompletions { const isGlobalCompletion = false; // We don't want the editor to offer any other completions, such as snippets, inside a comment. const isNewIdentifierLocation = true; // The user may type in a path that doesn't yet exist, creating a "new identifier" with respect to the collection of identifiers the server is aware of. const entries = pathCompletions.map(({ name, kind, span, extension }): CompletionEntry => - ({ name, kind, kindModifiers: kindModifiersFromExtension(extension), sortText: "0", replacementSpan: span })); + ({ name, kind, kindModifiers: kindModifiersFromExtension(extension), sortText: SortText.LocationPriority, replacementSpan: span })); return { isGlobalCompletion, isMemberCompletion: false, isNewIdentifierLocation, entries }; } function kindModifiersFromExtension(extension: Extension | undefined): ScriptElementKindModifier { diff --git a/src/testRunner/unittests/tsserver/completions.ts b/src/testRunner/unittests/tsserver/completions.ts index 0a62f74dc7d88..1cd44539d68de 100644 --- a/src/testRunner/unittests/tsserver/completions.ts +++ b/src/testRunner/unittests/tsserver/completions.ts @@ -36,7 +36,7 @@ namespace ts.projectSystem { kindModifiers: ScriptElementKindModifier.exportedModifier, name: "foo", replacementSpan: undefined, - sortText: "0", + sortText: Completions.SortText.AutoImportSuggestions, source: "/a", }; assert.deepEqual(response, { diff --git a/tests/cases/fourslash/codeCompletionEscaping.ts b/tests/cases/fourslash/codeCompletionEscaping.ts index e582171575f6c..bc1ae9662a0c5 100644 --- a/tests/cases/fourslash/codeCompletionEscaping.ts +++ b/tests/cases/fourslash/codeCompletionEscaping.ts @@ -7,7 +7,7 @@ verify.completions({ marker: "", includes: [ - { name: "__foo", kind: "warning" }, - { name: "___foo", kind: "warning" }, + { name: "__foo", kind: "warning", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "___foo", kind: "warning", sortText: completion.SortText.JavascriptIdentifiers }, ], }); diff --git a/tests/cases/fourslash/completionAfterGlobalThis.ts b/tests/cases/fourslash/completionAfterGlobalThis.ts index f5241d93c6ad6..bda57b9e0bd08 100644 --- a/tests/cases/fourslash/completionAfterGlobalThis.ts +++ b/tests/cases/fourslash/completionAfterGlobalThis.ts @@ -5,8 +5,8 @@ verify.completions({ marker: "", exact: [ - { name: "globalThis", kind: "module" }, + completion.globalThisEntry, ...completion.globalsVars, - { name: "undefined", kind: "var" } - ] + completion.undefinedVarEntry + ].map(e => ({ ...e, sortText: completion.SortText.LocationPriority })) }); diff --git a/tests/cases/fourslash/completionEntryForClassMembers.ts b/tests/cases/fourslash/completionEntryForClassMembers.ts index 6dcfd059c46f1..d40a8d273bc65 100644 --- a/tests/cases/fourslash/completionEntryForClassMembers.ts +++ b/tests/cases/fourslash/completionEntryForClassMembers.ts @@ -130,9 +130,9 @@ verify.completions( marker: "InsideMethod", exact: [ "arguments", - "globalThis", + completion.globalThisEntry, "B", "C", "D", "D1", "D2", "D3", "D4", "D5", "D6", "E", "F", "F2", "G", "G2", "H", "I", "J", "K", "L", "L2", "M", "N", "O", - "undefined", + completion.undefinedVarEntry, ...completion.insideMethodKeywords, ], }, @@ -146,7 +146,9 @@ verify.completions( "classThatStartedWritingIdentifierAfterPrivateModifier", "classThatStartedWritingIdentifierAfterPrivateStaticModifier", ], - exact: ["private", "protected", "public", "static", "abstract", "async", "constructor", "get", "readonly", "set"], + exact: ["private", "protected", "public", "static", "abstract", "async", "constructor", "get", "readonly", "set"].map( + name => ({ name, sortText: completion.SortText.GlobalsOrKeywords }) + ), isNewIdentifierLocation: true, }, { diff --git a/tests/cases/fourslash/completionEntryInJsFile.ts b/tests/cases/fourslash/completionEntryInJsFile.ts index a3492d9de3ead..cf460f6fcc9e9 100644 --- a/tests/cases/fourslash/completionEntryInJsFile.ts +++ b/tests/cases/fourslash/completionEntryInJsFile.ts @@ -12,9 +12,25 @@ ////function foo() { /////*insideFunction*/ ////} +const warnings = [ + { name: "classA", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "Test7", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "foo", sortText: completion.SortText.JavascriptIdentifiers } +]; verify.completions( { marker: "global", exact: completion.globalsInJsPlus(["foo", "classA", "Test7"]) }, - { marker: "class", isNewIdentifierLocation: true, exact: ["classA", "Test7", "foo", ...completion.classElementInJsKeywords] }, - { marker: "constructorParameter", isNewIdentifierLocation: true, exact: ["classA", "Test7", "foo"] }, + { + marker: "class", + isNewIdentifierLocation: true, + exact: [ + ...warnings, + ...completion.classElementInJsKeywords + ] + }, + { + marker: "constructorParameter", + isNewIdentifierLocation: true, + exact: warnings + }, { marker: "insideFunction", exact: completion.globalsInJsInsideFunction(["foo", "classA", "Test7"]) }, -); +); \ No newline at end of file diff --git a/tests/cases/fourslash/completionInFunctionLikeBody.ts b/tests/cases/fourslash/completionInFunctionLikeBody.ts index 8c163ccb3b05d..cf3b32ccb39b4 100644 --- a/tests/cases/fourslash/completionInFunctionLikeBody.ts +++ b/tests/cases/fourslash/completionInFunctionLikeBody.ts @@ -16,7 +16,9 @@ verify.completions( { marker: ["1", "2"], - includes: ["async", "await"], + includes: ["async", "await"].map( + name => ({ name, sortText: completion.SortText.GlobalsOrKeywords }) + ), excludes: ["public", "private", "protected", "constructor", "readonly", "static", "abstract", "get", "set"], }, { marker: ["3", "4"], exact: completion.classElementKeywords, isNewIdentifierLocation: true }, diff --git a/tests/cases/fourslash/completionInJSDocFunctionNew.ts b/tests/cases/fourslash/completionInJSDocFunctionNew.ts index 8cf8502aa201b..b343104c328e6 100644 --- a/tests/cases/fourslash/completionInJSDocFunctionNew.ts +++ b/tests/cases/fourslash/completionInJSDocFunctionNew.ts @@ -5,4 +5,4 @@ /////** @type {function (new: string, string): string} */ ////var f = function () { return new/**/; } -verify.completions({ marker: "", includes: "new" }); +verify.completions({ marker: "", includes: { name: "new", sortText: completion.SortText.JavascriptIdentifiers } }); diff --git a/tests/cases/fourslash/completionInJSDocFunctionThis.ts b/tests/cases/fourslash/completionInJSDocFunctionThis.ts index 4f732fdcec1fd..8dd1c545e3083 100644 --- a/tests/cases/fourslash/completionInJSDocFunctionThis.ts +++ b/tests/cases/fourslash/completionInJSDocFunctionThis.ts @@ -4,4 +4,4 @@ /////** @type {function (this: string, string): string} */ ////var f = function (s) { return this/**/; } -verify.completions({ marker: "", includes: "this" }); +verify.completions({ marker: "", includes: { name: "this", sortText: completion.SortText.JavascriptIdentifiers } }); diff --git a/tests/cases/fourslash/completionInJsDoc.ts b/tests/cases/fourslash/completionInJsDoc.ts index ef438b8f4be75..d30a92fe114ba 100644 --- a/tests/cases/fourslash/completionInJsDoc.ts +++ b/tests/cases/fourslash/completionInJsDoc.ts @@ -57,7 +57,7 @@ verify.completions( { marker: ["1", "2"], includes: ["constructor", "param", "type", "method", "template"] }, { marker: ["3", "15", "16"], exact: [] }, - { marker: ["4", "5", "8"], includes: "number" }, + { marker: ["4", "5", "8"], includes: { name: "number", sortText: completion.SortText.GlobalsOrKeywords } }, { marker: ["6", "7", "14"], exact: undefined }, { marker: ["9", "10", "11", "12", "13"], includes: ["@argument", "@returns"] }, ); diff --git a/tests/cases/fourslash/completionListAtEndOfWordInArrowFunction02.ts b/tests/cases/fourslash/completionListAtEndOfWordInArrowFunction02.ts index 73cd0c29be97f..690f01ab79375 100644 --- a/tests/cases/fourslash/completionListAtEndOfWordInArrowFunction02.ts +++ b/tests/cases/fourslash/completionListAtEndOfWordInArrowFunction02.ts @@ -5,5 +5,9 @@ verify.completions({ marker: "1", // TODO: should not include 'default' keyword at an expression location - includes: ["d", "defaultIsAnInvalidParameterName", "default"] + includes: [ + "d", + "defaultIsAnInvalidParameterName", + { name: "default", sortText: completion.SortText.GlobalsOrKeywords } + ] }); diff --git a/tests/cases/fourslash/completionListAtEndOfWordInArrowFunction03.ts b/tests/cases/fourslash/completionListAtEndOfWordInArrowFunction03.ts index 0487107d3afee..7aea1a726e28b 100644 --- a/tests/cases/fourslash/completionListAtEndOfWordInArrowFunction03.ts +++ b/tests/cases/fourslash/completionListAtEndOfWordInArrowFunction03.ts @@ -7,6 +7,6 @@ verify.completions({ includes: [ "defaultIsAnInvalidParameterName", // This should probably stop working in the future. - { name: "default", text: "default", kind: "keyword" }, + { name: "default", text: "default", kind: "keyword", sortText: completion.SortText.GlobalsOrKeywords }, ], }); diff --git a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts index 2f07107e0578b..94f109d787a7a 100644 --- a/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts +++ b/tests/cases/fourslash/completionListInClosedObjectTypeLiteralInSignature04.ts @@ -7,4 +7,8 @@ //// ////declare function foo(obj: I): { /*1*/ } -verify.completions({ marker: "1", exact: "readonly", isNewIdentifierLocation: true }); +verify.completions({ + marker: "1", + exact: { name: "readonly", sortText: completion.SortText.GlobalsOrKeywords }, + isNewIdentifierLocation: true +}); diff --git a/tests/cases/fourslash/completionListInNamedClassExpression.ts b/tests/cases/fourslash/completionListInNamedClassExpression.ts index 466342ab630e0..503051310c968 100644 --- a/tests/cases/fourslash/completionListInNamedClassExpression.ts +++ b/tests/cases/fourslash/completionListInNamedClassExpression.ts @@ -11,7 +11,9 @@ verify.completions( { marker: "0", includes: { name: "myClass", text: "(local class) myClass", kind: "local class" } }, { marker: "1", - exact: ["private", "protected", "public", "static", "abstract", "async", "constructor", "get", "readonly", "set"], + exact: ["private", "protected", "public", "static", "abstract", "async", "constructor", "get", "readonly", "set"].map( + name => ({ name, sortText: completion.SortText.GlobalsOrKeywords }) + ), isNewIdentifierLocation: true, - }, + } ); diff --git a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts index 587db09d2676f..52b73aa1f1ed7 100644 --- a/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts +++ b/tests/cases/fourslash/completionListInUnclosedObjectTypeLiteralInSignature04.ts @@ -7,4 +7,8 @@ //// ////declare function foo(obj: I): { /*1*/ -verify.completions({ marker: "1", exact: "readonly", isNewIdentifierLocation: true }); +verify.completions({ + marker: "1", + exact: { name: "readonly", sortText: completion.SortText.GlobalsOrKeywords } , + isNewIdentifierLocation: true +}); diff --git a/tests/cases/fourslash/completionListIsGlobalCompletion.ts b/tests/cases/fourslash/completionListIsGlobalCompletion.ts index 2a37849c2b8ea..ea89155a771c4 100644 --- a/tests/cases/fourslash/completionListIsGlobalCompletion.ts +++ b/tests/cases/fourslash/completionListIsGlobalCompletion.ts @@ -47,6 +47,6 @@ verify.completions( { marker: "10", exact: completion.classElementKeywords, isGlobalCompletion: false, isNewIdentifierLocation: true }, { marker: "13", exact: globals, isGlobalCompletion: false }, { marker: "15", exact: globals, isGlobalCompletion: true, isNewIdentifierLocation: true }, - { marker: "16", exact: [...x, "globalThis", ...completion.globalsVars, "undefined"], isGlobalCompletion: false }, + { marker: "16", exact: [...x, completion.globalThisEntry, ...completion.globalsVars, completion.undefinedVarEntry], isGlobalCompletion: false }, { marker: "17", exact: completion.globalKeywordsPlusUndefined, isGlobalCompletion: false }, ); diff --git a/tests/cases/fourslash/completionListKeywords.ts b/tests/cases/fourslash/completionListKeywords.ts index ed489487b3c60..287e5326a9050 100644 --- a/tests/cases/fourslash/completionListKeywords.ts +++ b/tests/cases/fourslash/completionListKeywords.ts @@ -4,4 +4,11 @@ /////**/ -verify.completions({ marker: "", exact: ["globalThis", "undefined", ...completion.statementKeywordsWithTypes] }); +verify.completions({ + marker: "", + exact: [ + completion.globalThisEntry, + completion.undefinedVarEntry, + ...completion.statementKeywordsWithTypes + ] +}); diff --git a/tests/cases/fourslash/completionListWithMeanings.ts b/tests/cases/fourslash/completionListWithMeanings.ts index 41df1ed381657..034607d08c021 100644 --- a/tests/cases/fourslash/completionListWithMeanings.ts +++ b/tests/cases/fourslash/completionListWithMeanings.ts @@ -16,7 +16,7 @@ ////var zz = { x: 4, y: 3 }; const values: ReadonlyArray = [ - "globalThis", + completion.globalThisEntry, { name: "m2", text: "namespace m2" }, // With no type side, allowed only in value { name: "m3", text: "namespace m3" }, { name: "xx", text: "var xx: number" }, @@ -24,12 +24,12 @@ const values: ReadonlyArray = [ { name: "yy", text: "var yy: point" }, { name: "kk", text: "var kk: m3.point3" }, { name: "zz", text: "var zz: point" }, - "undefined", + completion.undefinedVarEntry, ...completion.statementKeywordsWithTypes, ]; const types: ReadonlyArray = [ - "globalThis", + completion.globalThisEntry, { name: "m", text: "namespace m" }, { name: "m3", text: "namespace m3" }, { name: "point", text: "interface point" }, diff --git a/tests/cases/fourslash/completionListWithModulesFromModule.ts b/tests/cases/fourslash/completionListWithModulesFromModule.ts index dbcbdd797835a..fb5f49b1abf7d 100644 --- a/tests/cases/fourslash/completionListWithModulesFromModule.ts +++ b/tests/cases/fourslash/completionListWithModulesFromModule.ts @@ -263,9 +263,9 @@ verify.completions( { name: "shwvar", text: "var shwvar: string" }, { name: "shwcls", text: "class shwcls" }, "tmp", - "globalThis", + completion.globalThisEntry, ...commonValues, - "undefined", + completion.undefinedVarEntry, ...completion.statementKeywordsWithTypes, ], }, { @@ -273,7 +273,7 @@ verify.completions( exact: [ { name: "shwcls", text: "class shwcls" }, { name: "shwint", text: "interface shwint" }, - "globalThis", + completion.globalThisEntry, ...commonTypes, ...completion.typeKeywords, ] @@ -284,12 +284,12 @@ verify.completions( "Mod1", "iMod1", "tmp", - "globalThis", + completion.globalThisEntry, { name: "shwfn", text: "function shwfn(): void" }, ...commonValues, { name: "shwcls", text: "class shwcls" }, { name: "shwvar", text: "var shwvar: number" }, - "undefined", + completion.undefinedVarEntry, ...completion.statementKeywordsWithTypes, ], }, @@ -298,7 +298,7 @@ verify.completions( exact: [ "Mod1", "iMod1", - "globalThis", + completion.globalThisEntry, ...commonTypes, { name: "shwcls", text: "class shwcls" }, { name: "shwint", text: "interface shwint" }, diff --git a/tests/cases/fourslash/completionListWithModulesInsideModuleScope.ts b/tests/cases/fourslash/completionListWithModulesInsideModuleScope.ts index d1bc6233f72e6..ad0f2531f86e0 100644 --- a/tests/cases/fourslash/completionListWithModulesInsideModuleScope.ts +++ b/tests/cases/fourslash/completionListWithModulesInsideModuleScope.ts @@ -328,7 +328,7 @@ verifyGeneral('class', { // from interface in mod1 verify.completions({ marker: "interface", - exact: "readonly", + exact: { name: "readonly", sortText: completion.SortText.GlobalsOrKeywords }, isNewIdentifierLocation: true, }); @@ -376,7 +376,14 @@ verifyGeneral('exportedClass', { }); // from exported interface in mod1 -verify.completions({ marker: "exportedInterface", exact: ["readonly"], isNewIdentifierLocation: true }); +verify.completions({ + marker: "exportedInterface", + exact: [{ + name: "readonly", + sortText: completion.SortText.GlobalsOrKeywords + }], + isNewIdentifierLocation: true +}); // from exported namespace in mod1 verifyExportedNamespace('exportedNamespace'); diff --git a/tests/cases/fourslash/completionListWithModulesOutsideModuleScope.ts b/tests/cases/fourslash/completionListWithModulesOutsideModuleScope.ts index 8b9a13fc5b29e..c811316ee82ce 100644 --- a/tests/cases/fourslash/completionListWithModulesOutsideModuleScope.ts +++ b/tests/cases/fourslash/completionListWithModulesOutsideModuleScope.ts @@ -256,7 +256,7 @@ verify.completions( // from interface scope { marker: "interface", - exact: ["readonly"], + exact: [{ name: "readonly", sortText: completion.SortText.GlobalsOrKeywords }], isNewIdentifierLocation: true, } ); diff --git a/tests/cases/fourslash/completionListWithUnresolvedModule.ts b/tests/cases/fourslash/completionListWithUnresolvedModule.ts index 73c6c52a93795..1ef421af7f666 100644 --- a/tests/cases/fourslash/completionListWithUnresolvedModule.ts +++ b/tests/cases/fourslash/completionListWithUnresolvedModule.ts @@ -5,4 +5,10 @@ //// var n: num/**/ ////} -verify.completions({ marker: "", includes: "number" }); +verify.completions({ + marker: "", + includes: { + name: "number", + sortText: completion.SortText.GlobalsOrKeywords + } +}); diff --git a/tests/cases/fourslash/completionsGeneratorFunctions.ts b/tests/cases/fourslash/completionsGeneratorFunctions.ts index 1aea1eb6e4dcf..b2abd14864632 100644 --- a/tests/cases/fourslash/completionsGeneratorFunctions.ts +++ b/tests/cases/fourslash/completionsGeneratorFunctions.ts @@ -18,5 +18,5 @@ verify.completions( { marker: ["a", "b"], exact: undefined, isNewIdentifierLocation: true }, { marker: ["c", "d"], exact: ["baseMethod"], isNewIdentifierLocation: true }, { marker: "e", exact: ["baseMethod"] }, - { marker: "f", includes: ["Number"] }, + { marker: "f", includes: [{ name: "Number", sortText: completion.SortText.GlobalsOrKeywords }] }, ); diff --git a/tests/cases/fourslash/completionsImportBaseUrl.ts b/tests/cases/fourslash/completionsImportBaseUrl.ts index d3fa4d7033e5c..5f67a7d4d6301 100644 --- a/tests/cases/fourslash/completionsImportBaseUrl.ts +++ b/tests/cases/fourslash/completionsImportBaseUrl.ts @@ -25,6 +25,7 @@ verify.completions({ kind: "const", kindModifiers: "export", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_augmentation.ts b/tests/cases/fourslash/completionsImport_augmentation.ts index 701af24537fa5..f01f7f43df1a1 100644 --- a/tests/cases/fourslash/completionsImport_augmentation.ts +++ b/tests/cases/fourslash/completionsImport_augmentation.ts @@ -21,6 +21,7 @@ verify.completions({ source: "/a", sourceDisplay: "./a", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, { name: "bar", @@ -28,6 +29,7 @@ verify.completions({ source: "/a", sourceDisplay: "./a", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, ], preferences: { diff --git a/tests/cases/fourslash/completionsImport_compilerOptionsModule.ts b/tests/cases/fourslash/completionsImport_compilerOptionsModule.ts index 27ae94d417207..56d4ca9e27dc3 100644 --- a/tests/cases/fourslash/completionsImport_compilerOptionsModule.ts +++ b/tests/cases/fourslash/completionsImport_compilerOptionsModule.ts @@ -33,9 +33,22 @@ ////const a = import("./a"); // Does not make this an external module ////fo/*dts*/ -verify.completions({ marker: ["b"], excludes: "foo", preferences: { includeCompletionsForModuleExports: true } }); +verify.completions({ + marker: ["b"], + excludes: "foo", + preferences: { includeCompletionsForModuleExports: true } +}); verify.completions({ marker: ["c", "ccheck", "cts", "d", "dcheck", "dts"], - includes: [{ name: "foo", source: "/node_modules/a/index", text: "const foo: 0", kind: "const", kindModifiers: "export,declare", hasAction: true, sourceDisplay: "a" }], + includes: [{ + name: "foo", + source: "/node_modules/a/index", + text: "const foo: 0", + kind: "const", + kindModifiers: "export,declare", + hasAction: true, + sourceDisplay: "a", + sortText: completion.SortText.AutoImportSuggestions + }], preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_defaultFalsePositive.ts b/tests/cases/fourslash/completionsImport_defaultFalsePositive.ts index e077e18105b76..28babd929c9e2 100644 --- a/tests/cases/fourslash/completionsImport_defaultFalsePositive.ts +++ b/tests/cases/fourslash/completionsImport_defaultFalsePositive.ts @@ -22,6 +22,7 @@ verify.completions({ kind: "const", kindModifiers: "export,declare", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_default_addToNamedImports.ts b/tests/cases/fourslash/completionsImport_default_addToNamedImports.ts index 8bd9f194758b2..c81b93e34b1ed 100644 --- a/tests/cases/fourslash/completionsImport_default_addToNamedImports.ts +++ b/tests/cases/fourslash/completionsImport_default_addToNamedImports.ts @@ -18,6 +18,7 @@ verify.completions({ kind: "function", kindModifiers: "export", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_default_addToNamespaceImport.ts b/tests/cases/fourslash/completionsImport_default_addToNamespaceImport.ts index 8debd787641aa..1752d00d1b6f1 100644 --- a/tests/cases/fourslash/completionsImport_default_addToNamespaceImport.ts +++ b/tests/cases/fourslash/completionsImport_default_addToNamespaceImport.ts @@ -17,6 +17,7 @@ verify.completions({ kind: "function", kindModifiers: "export", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts b/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts index b04a7cacffeda..2e1fd6003ba14 100644 --- a/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts +++ b/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts @@ -17,6 +17,7 @@ verify.completions({ kind: "function", kindModifiers: "export", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_default_anonymous.ts b/tests/cases/fourslash/completionsImport_default_anonymous.ts index 720bb3f1c6bec..a1eb5da64900d 100644 --- a/tests/cases/fourslash/completionsImport_default_anonymous.ts +++ b/tests/cases/fourslash/completionsImport_default_anonymous.ts @@ -14,10 +14,26 @@ goTo.marker("0"); const preferences: FourSlashInterface.UserPreferences = { includeCompletionsForModuleExports: true }; verify.completions( - { marker: "0", exact: ["globalThis", "undefined", ...completion.statementKeywordsWithTypes], preferences }, + { + marker: "0", + exact: [ + completion.globalThisEntry, + completion.undefinedVarEntry, + ...completion.statementKeywordsWithTypes + ], + preferences + }, { marker: "1", - includes: { name: "fooBar", source: "/src/foo-bar", sourceDisplay: "./foo-bar", text: "(property) default: 0", kind: "property", hasAction: true }, + includes: { + name: "fooBar", + source: "/src/foo-bar", + sourceDisplay: "./foo-bar", + text: "(property) default: 0", + kind: "property", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions + }, preferences, }, ); diff --git a/tests/cases/fourslash/completionsImport_default_didNotExistBefore.ts b/tests/cases/fourslash/completionsImport_default_didNotExistBefore.ts index 259a22d637bc9..333159ae49348 100644 --- a/tests/cases/fourslash/completionsImport_default_didNotExistBefore.ts +++ b/tests/cases/fourslash/completionsImport_default_didNotExistBefore.ts @@ -18,6 +18,7 @@ verify.completions({ kind: "function", kindModifiers: "export", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_default_exportDefaultIdentifier.ts b/tests/cases/fourslash/completionsImport_default_exportDefaultIdentifier.ts index 766f50fb9e951..ea332cd7ff727 100644 --- a/tests/cases/fourslash/completionsImport_default_exportDefaultIdentifier.ts +++ b/tests/cases/fourslash/completionsImport_default_exportDefaultIdentifier.ts @@ -14,7 +14,15 @@ goTo.marker(""); verify.completions({ marker: "", - includes: { name: "foo", source: "/a", sourceDisplay: "./a", text: "(alias) const foo: 0\nexport default foo", kind: "alias", hasAction: true }, + includes: { + name: "foo", + source: "/a", + sourceDisplay: "./a", + text: "(alias) const foo: 0\nexport default foo", + kind: "alias", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions + }, preferences: { includeCompletionsForModuleExports: true }, }); verify.applyCodeActionFromCompletion("", { diff --git a/tests/cases/fourslash/completionsImport_default_fromMergedDeclarations.ts b/tests/cases/fourslash/completionsImport_default_fromMergedDeclarations.ts index 551cfb54e754f..6c86fc18fa520 100644 --- a/tests/cases/fourslash/completionsImport_default_fromMergedDeclarations.ts +++ b/tests/cases/fourslash/completionsImport_default_fromMergedDeclarations.ts @@ -25,6 +25,7 @@ verify.completions({ kind: "class", kindModifiers: "export,declare", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_exportEquals.ts b/tests/cases/fourslash/completionsImport_exportEquals.ts index 37e78e09f386f..1ea3e7e637ea8 100644 --- a/tests/cases/fourslash/completionsImport_exportEquals.ts +++ b/tests/cases/fourslash/completionsImport_exportEquals.ts @@ -17,12 +17,22 @@ const preferences: FourSlashInterface.UserPreferences = { includeCompletionsForM verify.completions( { marker: "0", - includes: { name: "a", source: "/a", hasAction: true, }, + includes: { + name: "a", + source: "/a", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions + }, preferences, }, { marker: "1", - includes: { name: "b", source: "/a", hasAction: true }, + includes: { + name: "b", + source: "/a", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions + }, preferences, } ); diff --git a/tests/cases/fourslash/completionsImport_exportEqualsNamespace_noDuplicate.ts b/tests/cases/fourslash/completionsImport_exportEqualsNamespace_noDuplicate.ts index 8a687f5a19194..798c70b282793 100644 --- a/tests/cases/fourslash/completionsImport_exportEqualsNamespace_noDuplicate.ts +++ b/tests/cases/fourslash/completionsImport_exportEqualsNamespace_noDuplicate.ts @@ -18,7 +18,7 @@ verify.completions({ marker: "", // Tester will assert that it is only included once - includes: [{ name: "foo", source: "a", hasAction: true }], + includes: [{ name: "foo", source: "a", hasAction: true, sortText: completion.SortText.AutoImportSuggestions }], preferences: { includeCompletionsForModuleExports: true, } diff --git a/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts b/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts index 8fc73457117b5..b28de47c69db1 100644 --- a/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts +++ b/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts @@ -12,9 +12,26 @@ goTo.marker("0"); const preferences: FourSlashInterface.UserPreferences = { includeCompletionsForModuleExports: true }; -const exportEntry: FourSlashInterface.ExpectedCompletionEntryObject = { name: "fooBar", source: "/src/foo-bar", sourceDisplay: "./foo-bar", text: "(property) export=: 0", kind: "property", hasAction: true }; +const exportEntry: FourSlashInterface.ExpectedCompletionEntryObject = { + name: "fooBar", + source: "/src/foo-bar", + sourceDisplay: "./foo-bar", + text: "(property) export=: 0", + kind: "property", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions +}; verify.completions( - { marker: "0", exact: ["globalThis", "undefined", exportEntry, ...completion.statementKeywordsWithTypes], preferences }, + { + marker: "0", + exact: [ + completion.globalThisEntry, + completion.undefinedVarEntry, + exportEntry, + ...completion.statementKeywordsWithTypes + ], + preferences + }, { marker: "1", includes: exportEntry, preferences } ); verify.applyCodeActionFromCompletion("0", { diff --git a/tests/cases/fourslash/completionsImport_importType.ts b/tests/cases/fourslash/completionsImport_importType.ts index 3c371980b9066..3f4bfa38c3bc5 100644 --- a/tests/cases/fourslash/completionsImport_importType.ts +++ b/tests/cases/fourslash/completionsImport_importType.ts @@ -21,6 +21,7 @@ verify.completions({ sourceDisplay: "./a", text: "class C", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, { name: "T", @@ -28,6 +29,7 @@ verify.completions({ sourceDisplay: "./a", text: "type T = number", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, ], excludes: "x", diff --git a/tests/cases/fourslash/completionsImport_keywords.ts b/tests/cases/fourslash/completionsImport_keywords.ts index 64bab64c7a8f5..31d2e1cc6f3c1 100644 --- a/tests/cases/fourslash/completionsImport_keywords.ts +++ b/tests/cases/fourslash/completionsImport_keywords.ts @@ -34,8 +34,17 @@ verify.completions( { marker: "unique", exact: [ - "globalThis", ...completion.globalsVars, "undefined", - { name: "unique", source: "/a", sourceDisplay: "./a", text: "(alias) const unique: 0\nexport unique", hasAction: true }, + completion.globalThisEntry, + ...completion.globalsVars, + completion.undefinedVarEntry, + { + name: "unique", + source: "/a", + sourceDisplay: "./a", + text: "(alias) const unique: 0\nexport unique", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions + }, ...completion.globalKeywords.filter(e => e.name !== "unique"), ], preferences, diff --git a/tests/cases/fourslash/completionsImport_matching.ts b/tests/cases/fourslash/completionsImport_matching.ts index c6dbac369b964..5282d5b3d3c88 100644 --- a/tests/cases/fourslash/completionsImport_matching.ts +++ b/tests/cases/fourslash/completionsImport_matching.ts @@ -17,7 +17,16 @@ verify.completions({ marker: "", includes: ["bdf", "abcdef", "BDF"].map(name => - ({ name, source: "/a", text: `function ${name}(): void`, hasAction: true, kind: "function", kindModifiers: "export", sourceDisplay: "./a" })), + ({ + name, + source: "/a", + text: `function ${name}(): void`, + hasAction: true, + kind: "function", + kindModifiers: "export", + sourceDisplay: "./a", + sortText: completion.SortText.AutoImportSuggestions + })), excludes: ["abcde", "dbf"], preferences: { includeCompletionsForModuleExports: true }, }) diff --git a/tests/cases/fourslash/completionsImport_multipleWithSameName.ts b/tests/cases/fourslash/completionsImport_multipleWithSameName.ts index 5893f6f0fdc8c..d00a7e0bebb5d 100644 --- a/tests/cases/fourslash/completionsImport_multipleWithSameName.ts +++ b/tests/cases/fourslash/completionsImport_multipleWithSameName.ts @@ -20,9 +20,15 @@ goTo.marker(""); verify.completions({ marker: "", exact: [ - "globalThis", - { name: "foo", text: "var foo: number", kind: "var", kindModifiers: "declare" }, - "undefined", + completion.globalThisEntry, + { + name: "foo", + text: "var foo: number", + kind: "var", + kindModifiers: "declare", + sortText: completion.SortText.GlobalsOrKeywords + }, + completion.undefinedVarEntry, { name: "foo", source: "/a", @@ -31,6 +37,7 @@ verify.completions({ kind: "const", kindModifiers: "export", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, { name: "foo", @@ -40,6 +47,7 @@ verify.completions({ kind: "const", kindModifiers: "export", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, ...completion.statementKeywordsWithTypes, ], diff --git a/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts b/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts index 78df2659ade0d..8e1ec13df79f3 100644 --- a/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts +++ b/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts @@ -18,6 +18,7 @@ verify.completions({ kind: "function", kindModifiers: "export", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts b/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts index 5f21db1e3763e..cb55f859cca06 100644 --- a/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts +++ b/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts @@ -13,10 +13,23 @@ verify.completions({ marker: "", exact: [ - { name: "Test2", text: "(alias) function Test2(): void\nimport Test2", kind: "alias" }, - "globalThis", - "undefined", - { name: "Test1", source: "/a", sourceDisplay: "./a", text: "function Test1(): void", kind: "function", kindModifiers: "export", hasAction: true }, + { + name: "Test2", + text: "(alias) function Test2(): void\nimport Test2", + kind: "alias" + }, + completion.globalThisEntry, + completion.undefinedVarEntry, + { + name: "Test1", + source: "/a", + sourceDisplay: "./a", + text: "function Test1(): void", + kind: "function", + kindModifiers: "export", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions + }, ...completion.statementKeywordsWithTypes, ], preferences: { includeCompletionsForModuleExports: true }, diff --git a/tests/cases/fourslash/completionsImport_named_exportEqualsNamespace.ts b/tests/cases/fourslash/completionsImport_named_exportEqualsNamespace.ts index 4f4b579fe4973..ca866d838fc6c 100644 --- a/tests/cases/fourslash/completionsImport_named_exportEqualsNamespace.ts +++ b/tests/cases/fourslash/completionsImport_named_exportEqualsNamespace.ts @@ -21,6 +21,7 @@ verify.completions({ kind: "const", kindModifiers: "export,declare", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_named_exportEqualsNamespace_merged.ts b/tests/cases/fourslash/completionsImport_named_exportEqualsNamespace_merged.ts index ec70d205479c8..bc1d56cfb6a05 100644 --- a/tests/cases/fourslash/completionsImport_named_exportEqualsNamespace_merged.ts +++ b/tests/cases/fourslash/completionsImport_named_exportEqualsNamespace_merged.ts @@ -26,6 +26,7 @@ verify.completions({ kind: "const", kindModifiers: "export,declare", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_named_namespaceImportExists.ts b/tests/cases/fourslash/completionsImport_named_namespaceImportExists.ts index 52c33209ca390..c3e254521de97 100644 --- a/tests/cases/fourslash/completionsImport_named_namespaceImportExists.ts +++ b/tests/cases/fourslash/completionsImport_named_namespaceImportExists.ts @@ -17,6 +17,7 @@ verify.completions({ kind: "function", kindModifiers: "export", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_notFromIndex.ts b/tests/cases/fourslash/completionsImport_notFromIndex.ts index e6aa3e680b13f..3df542daeb498 100644 --- a/tests/cases/fourslash/completionsImport_notFromIndex.ts +++ b/tests/cases/fourslash/completionsImport_notFromIndex.ts @@ -26,6 +26,7 @@ for (const [marker, sourceDisplay] of [["0", "./src"], ["1", "./a"], ["2", "../a kind: "const", kindModifiers: "export", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_ofAlias.ts b/tests/cases/fourslash/completionsImport_ofAlias.ts index cb6af7910ba53..9a9cb4a2b18c1 100644 --- a/tests/cases/fourslash/completionsImport_ofAlias.ts +++ b/tests/cases/fourslash/completionsImport_ofAlias.ts @@ -22,8 +22,16 @@ verify.completions({ marker: "", includes: [ - "undefined", - { name: "foo", source: "/a", sourceDisplay: "./a", text: "(alias) const foo: 0\nexport foo", kind: "alias", hasAction: true }, + completion.undefinedVarEntry, + { + name: "foo", + source: "/a", + sourceDisplay: "./a", + text: "(alias) const foo: 0\nexport foo", + kind: "alias", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions + }, ...completion.statementKeywordsWithTypes, ], preferences: { includeCompletionsForModuleExports: true }, diff --git a/tests/cases/fourslash/completionsImport_ofAlias_preferShortPath.ts b/tests/cases/fourslash/completionsImport_ofAlias_preferShortPath.ts index 71242bc240a96..494b871238fdc 100644 --- a/tests/cases/fourslash/completionsImport_ofAlias_preferShortPath.ts +++ b/tests/cases/fourslash/completionsImport_ofAlias_preferShortPath.ts @@ -19,9 +19,18 @@ verify.completions({ marker: "", exact: [ - "globalThis", - "undefined", - { name: "foo", source: "/foo/lib/foo", sourceDisplay: "./foo", text: "const foo: 0", kind: "const", kindModifiers: "export", hasAction: true }, + completion.globalThisEntry, + completion.undefinedVarEntry, + { + name: "foo", + source: "/foo/lib/foo", + sourceDisplay: "./foo", + text: "const foo: 0", + kind: "const", + kindModifiers: "export", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions + }, ...completion.statementKeywordsWithTypes, ], preferences: { includeCompletionsForModuleExports: true }, diff --git a/tests/cases/fourslash/completionsImport_previousTokenIsSemicolon.ts b/tests/cases/fourslash/completionsImport_previousTokenIsSemicolon.ts index 7099c4b30725e..23924ad33000e 100644 --- a/tests/cases/fourslash/completionsImport_previousTokenIsSemicolon.ts +++ b/tests/cases/fourslash/completionsImport_previousTokenIsSemicolon.ts @@ -17,6 +17,7 @@ verify.completions({ kind: "function", kindModifiers: "export", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_reExportDefault.ts b/tests/cases/fourslash/completionsImport_reExportDefault.ts index 7f6639c3f13d8..b67daf7132e99 100644 --- a/tests/cases/fourslash/completionsImport_reExportDefault.ts +++ b/tests/cases/fourslash/completionsImport_reExportDefault.ts @@ -15,9 +15,9 @@ verify.completions({ marker: "", exact: [ - "globalThis", + completion.globalThisEntry, ...completion.globalsVars, - "undefined", + completion.undefinedVarEntry, { name: "foo", source: "/a/b/impl", @@ -26,6 +26,7 @@ verify.completions({ kind: "function", kindModifiers: "export", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, { name: "foo", @@ -34,6 +35,7 @@ verify.completions({ text: "(alias) function foo(): void\nexport foo", kind: "alias", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, ...completion.globalKeywords, ], diff --git a/tests/cases/fourslash/completionsImport_reExport_wrongName.ts b/tests/cases/fourslash/completionsImport_reExport_wrongName.ts index 31de7ef7d8de0..4080fe5cdb7dd 100644 --- a/tests/cases/fourslash/completionsImport_reExport_wrongName.ts +++ b/tests/cases/fourslash/completionsImport_reExport_wrongName.ts @@ -15,8 +15,22 @@ goTo.marker(""); verify.completions({ marker: "", includes: [ - { name: "x", source: "/a", sourceDisplay: "./a", text: "const x: 0", hasAction: true }, - { name: "y", source: "/index", sourceDisplay: ".", text: "(alias) const y: 0\nexport y", hasAction: true }, + { + name: "x", + source: "/a", + sourceDisplay: "./a", + text: "const x: 0", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions + }, + { + name: "y", + source: "/index", + sourceDisplay: ".", + text: "(alias) const y: 0\nexport y", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions + }, ], preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_require.ts b/tests/cases/fourslash/completionsImport_require.ts index 892a249548531..836a0e2439e18 100644 --- a/tests/cases/fourslash/completionsImport_require.ts +++ b/tests/cases/fourslash/completionsImport_require.ts @@ -19,6 +19,7 @@ verify.completions({ kind: "const", kindModifiers: "export", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsImport_shadowedByLocal.ts b/tests/cases/fourslash/completionsImport_shadowedByLocal.ts index 711386816c081..504702b6cc36f 100644 --- a/tests/cases/fourslash/completionsImport_shadowedByLocal.ts +++ b/tests/cases/fourslash/completionsImport_shadowedByLocal.ts @@ -1,16 +1,24 @@ -/// - -// @noLib: true - -// @Filename: /a.ts -////export const foo = 0; - -// @Filename: /b.ts -////const foo = 1; -////fo/**/ - -verify.completions({ - marker: "", - exact: ["globalThis", { name: "foo", text: "const foo: 1" }, "undefined", ...completion.statementKeywordsWithTypes], - preferences: { includeCompletionsForModuleExports: true }, -}); +/// + +// @noLib: true + +// @Filename: /a.ts +////export const foo = 0; + +// @Filename: /b.ts +////const foo = 1; +////fo/**/ + +verify.completions({ + marker: "", + exact: [ + completion.globalThisEntry, + { + name: "foo", + text: "const foo: 1", + }, + completion.undefinedVarEntry, + ...completion.statementKeywordsWithTypes + ], + preferences: { includeCompletionsForModuleExports: true }, +}); diff --git a/tests/cases/fourslash/completionsImport_tsx.ts b/tests/cases/fourslash/completionsImport_tsx.ts index 9fb4d23922369..3a495f1a0ceb2 100644 --- a/tests/cases/fourslash/completionsImport_tsx.ts +++ b/tests/cases/fourslash/completionsImport_tsx.ts @@ -12,7 +12,7 @@ verify.completions({ marker: "", - includes: { name: "Foo", source: "/a", hasAction: true }, + includes: { name: "Foo", source: "/a", hasAction: true, sortText: completion.SortText.AutoImportSuggestions }, excludes: "Bar", preferences: { includeCompletionsForModuleExports: true, diff --git a/tests/cases/fourslash/completionsInterfaceElement.ts b/tests/cases/fourslash/completionsInterfaceElement.ts index 65b1627c8f31a..5a00473ce562a 100644 --- a/tests/cases/fourslash/completionsInterfaceElement.ts +++ b/tests/cases/fourslash/completionsInterfaceElement.ts @@ -13,4 +13,11 @@ ////interface EndOfFile { f; /*e*/ -verify.completions({ marker: test.markers(), exact: "readonly", isNewIdentifierLocation: true }); +verify.completions({ + marker: test.markers(), + exact: { + name: "readonly", + sortText: completion.SortText.GlobalsOrKeywords + }, + isNewIdentifierLocation: true +}); diff --git a/tests/cases/fourslash/completionsJsdocTypeTagCast.ts b/tests/cases/fourslash/completionsJsdocTypeTagCast.ts index 5eff16bb27834..fe9d8b496e2b6 100644 --- a/tests/cases/fourslash/completionsJsdocTypeTagCast.ts +++ b/tests/cases/fourslash/completionsJsdocTypeTagCast.ts @@ -4,4 +4,10 @@ // @Filename: /a.js ////const x = /** @type {{ s: string }} */ ({ /**/ }); -verify.completions({ marker: "", exact: ["s", "x"] }); +verify.completions({ + marker: "", + exact: [ + "s", + { name: "x", sortText: completion.SortText.JavascriptIdentifiers } + ] +}); diff --git a/tests/cases/fourslash/completionsJsxAttributeInitializer.ts b/tests/cases/fourslash/completionsJsxAttributeInitializer.ts index 44d79b059a6d1..0d6c2f2512307 100644 --- a/tests/cases/fourslash/completionsJsxAttributeInitializer.ts +++ b/tests/cases/fourslash/completionsJsxAttributeInitializer.ts @@ -9,8 +9,8 @@ verify.completions({ marker: "", includes: [ { name: "x", text: "(parameter) x: number", kind: "parameter", insertText: "{x}" }, - { name: "p", text: "(JSX attribute) p: number", kind: "JSX attribute", insertText: "{this.p}" }, - { name: "a b", text: '(JSX attribute) "a b": number', kind: "JSX attribute", insertText: '{this["a b"]}' }, + { name: "p", text: "(JSX attribute) p: number", kind: "JSX attribute", insertText: "{this.p}", sortText: completion.SortText.SuggestedClassMembers }, + { name: "a b", text: '(JSX attribute) "a b": number', kind: "JSX attribute", insertText: '{this["a b"]}', sortText: completion.SortText.SuggestedClassMembers }, ], preferences: { includeInsertTextCompletions: true, diff --git a/tests/cases/fourslash/completionsKeywordsExtends.ts b/tests/cases/fourslash/completionsKeywordsExtends.ts index bd88311b46cc5..8f0b97a56ea51 100644 --- a/tests/cases/fourslash/completionsKeywordsExtends.ts +++ b/tests/cases/fourslash/completionsKeywordsExtends.ts @@ -7,5 +7,5 @@ verify.completions( { marker: "a", exact: undefined }, - { marker: ["b", "c"], includes: "extends" }, + { marker: ["b", "c"], includes: { name: "extends", sortText: completion.SortText.GlobalsOrKeywords } }, ); diff --git a/tests/cases/fourslash/completionsRecommended_import.ts b/tests/cases/fourslash/completionsRecommended_import.ts index 50e3c7b00aa45..ccd77136afc19 100644 --- a/tests/cases/fourslash/completionsRecommended_import.ts +++ b/tests/cases/fourslash/completionsRecommended_import.ts @@ -28,6 +28,7 @@ const classEntry = (isConstructor: boolean): FourSlashInterface.ExpectedCompleti text: isConstructor ? "constructor Cls(): Cls" : "class Cls", hasAction: true, isRecommended: true, + sortText: completion.SortText.AutoImportSuggestions }); verify.completions( { marker: "b0", includes: classEntry(true), preferences }, diff --git a/tests/cases/fourslash/completionsRecommended_namespace.ts b/tests/cases/fourslash/completionsRecommended_namespace.ts index 0d6e19e710645..1b3d8c56726c3 100644 --- a/tests/cases/fourslash/completionsRecommended_namespace.ts +++ b/tests/cases/fourslash/completionsRecommended_namespace.ts @@ -38,6 +38,7 @@ verify.completions( kindModifiers: "export", hasAction: true, isRecommended: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }, diff --git a/tests/cases/fourslash/completionsThisType.ts b/tests/cases/fourslash/completionsThisType.ts index 9923f937afc7b..ec181335cb7ed 100644 --- a/tests/cases/fourslash/completionsThisType.ts +++ b/tests/cases/fourslash/completionsThisType.ts @@ -14,15 +14,15 @@ verify.completions( { marker: "", includes: [ - { name: "xyz", text: "(method) C.xyz(): any", kind: "method", insertText: "this.xyz" }, - { name: "foo bar", text: '(property) C["foo bar"]: number', kind: "property", insertText: 'this["foo bar"]' }, + { name: "xyz", text: "(method) C.xyz(): any", kind: "method", insertText: "this.xyz", sortText: completion.SortText.SuggestedClassMembers }, + { name: "foo bar", text: '(property) C["foo bar"]: number', kind: "property", insertText: 'this["foo bar"]', sortText: completion.SortText.SuggestedClassMembers }, ], isNewIdentifierLocation: true, preferences, }, { marker: "f", - includes: { name: "x", text: "(property) x: number", kind: "property", insertText: "this.x" }, + includes: { name: "x", text: "(property) x: number", kind: "property", insertText: "this.x", sortText: completion.SortText.SuggestedClassMembers }, preferences, }, ); diff --git a/tests/cases/fourslash/completionsTypeKeywords.ts b/tests/cases/fourslash/completionsTypeKeywords.ts index 4c26e13932ec1..6817523bc26d5 100644 --- a/tests/cases/fourslash/completionsTypeKeywords.ts +++ b/tests/cases/fourslash/completionsTypeKeywords.ts @@ -6,5 +6,5 @@ verify.completions({ marker: "", - exact: ["globalThis", "T", ...completion.typeKeywords], + exact: [completion.globalThisEntry, "T", ...completion.typeKeywords], }); diff --git a/tests/cases/fourslash/doubleUnderscoreCompletions.ts b/tests/cases/fourslash/doubleUnderscoreCompletions.ts index 007842edc1bc0..8d07cdf333f4d 100644 --- a/tests/cases/fourslash/doubleUnderscoreCompletions.ts +++ b/tests/cases/fourslash/doubleUnderscoreCompletions.ts @@ -12,7 +12,7 @@ verify.completions({ marker: "1", exact: [ { name: "__property", text: "(property) MyObject.__property: number" }, - "MyObject", - "instance", + { name: "MyObject", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "instance", sortText: completion.SortText.JavascriptIdentifiers }, ], }); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 4252296d5da48..fa9cdd61c2f6f 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -528,6 +528,7 @@ declare namespace FourSlashInterface { readonly isRecommended?: boolean; readonly kind?: string; readonly kindModifiers?: string; + readonly sortText?: completion.SortText; // details readonly text?: string; @@ -650,6 +651,15 @@ declare var cancellation: FourSlashInterface.cancellation; declare var classification: typeof FourSlashInterface.classification; declare namespace completion { type Entry = FourSlashInterface.ExpectedCompletionEntryObject; + export const enum SortText { + LocationPriority = "0", + SuggestedClassMembers = "1", + GlobalsOrKeywords = "2", + AutoImportSuggestions = "3", + JavascriptIdentifiers = "4" + } + export const globalThisEntry: Entry; + export const undefinedVarEntry: Entry; export const globals: ReadonlyArray; export const globalsInJs: ReadonlyArray; export const globalKeywords: ReadonlyArray; diff --git a/tests/cases/fourslash/getJavaScriptCompletions12.ts b/tests/cases/fourslash/getJavaScriptCompletions12.ts index 5534b20b8eaa7..2848ee27c5462 100644 --- a/tests/cases/fourslash/getJavaScriptCompletions12.ts +++ b/tests/cases/fourslash/getJavaScriptCompletions12.ts @@ -26,5 +26,5 @@ verify.completions( { marker: "1", includes: { name: "charCodeAt", kind: "method", kindModifiers: "declare" } }, { marker: ["2", "3", "4"], includes: { name: "toExponential", kind: "method", kindModifiers: "declare" } }, - { marker: "5", includes: { name: "test1", kind: "warning" } }, + { marker: "5", includes: { name: "test1", kind: "warning", sortText: completion.SortText.JavascriptIdentifiers } }, ); diff --git a/tests/cases/fourslash/getJavaScriptCompletions13.ts b/tests/cases/fourslash/getJavaScriptCompletions13.ts index 8c8b494277982..3b8f984cefead 100644 --- a/tests/cases/fourslash/getJavaScriptCompletions13.ts +++ b/tests/cases/fourslash/getJavaScriptCompletions13.ts @@ -14,6 +14,21 @@ ////file2Identifier2./*2*/ verify.completions( - { marker: "1", includes: ["file2Identifier1", "file2Identifier2", "file1Identifier"], excludes: "FooProp" }, - { marker: "2", includes: ["file2Identifier1", "file2Identifier2"], excludes: ["file1Identifier", "FooProp"] }, -) + { + marker: "1", + includes: [ + "file2Identifier1", + "file2Identifier2", + { name: "file1Identifier", sortText: completion.SortText.GlobalsOrKeywords } + ], + excludes: "FooProp" + }, + { + marker: "2", + includes: [ + { name: "file2Identifier1", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "file2Identifier2", sortText: completion.SortText.JavascriptIdentifiers } + ], + excludes: ["file1Identifier", "FooProp"] + }, +); diff --git a/tests/cases/fourslash/getJavaScriptCompletions15.ts b/tests/cases/fourslash/getJavaScriptCompletions15.ts index e46b0780d429e..bcbd6ecbf97a8 100644 --- a/tests/cases/fourslash/getJavaScriptCompletions15.ts +++ b/tests/cases/fourslash/getJavaScriptCompletions15.ts @@ -22,6 +22,16 @@ verify.completions( { marker: "1", includes: "toExponential" }, { marker: "2", includes: "toLowerCase" }, - { marker: "3", exact: ["V", "ref1", "ref2", "require", "v", "x"] }, + { + marker: "3", + exact: [ + "V", + { name: "ref1", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "ref2", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "require", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "v", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "x", sortText: completion.SortText.JavascriptIdentifiers } + ] + }, { marker: "4", includes: "toLowerCase" }, ); diff --git a/tests/cases/fourslash/getJavaScriptCompletions20.ts b/tests/cases/fourslash/getJavaScriptCompletions20.ts index cbe74a4b392d5..901ac4522c584 100644 --- a/tests/cases/fourslash/getJavaScriptCompletions20.ts +++ b/tests/cases/fourslash/getJavaScriptCompletions20.ts @@ -19,5 +19,12 @@ verify.completions({ marker: "", - exact: ["getName", "getNa", ...completion.functionMembersWithPrototype, "Person", "name", "age"], + exact: [ + "getName", + "getNa", + ...completion.functionMembersWithPrototype, + { name: "Person", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "name", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "age", sortText: completion.SortText.JavascriptIdentifiers } + ], }); diff --git a/tests/cases/fourslash/getJavaScriptGlobalCompletions1.ts b/tests/cases/fourslash/getJavaScriptGlobalCompletions1.ts index 478d472217e12..118ca30faeb8b 100644 --- a/tests/cases/fourslash/getJavaScriptGlobalCompletions1.ts +++ b/tests/cases/fourslash/getJavaScriptGlobalCompletions1.ts @@ -12,4 +12,4 @@ //// //// hello/**/ -verify.completions({ includes: "helloWorld" }); +verify.completions({ includes: { name: "helloWorld", sortText: completion.SortText.JavascriptIdentifiers } }); diff --git a/tests/cases/fourslash/importJsNodeModule2.ts b/tests/cases/fourslash/importJsNodeModule2.ts index 0ceae59b215a5..1c4cf77926afa 100644 --- a/tests/cases/fourslash/importJsNodeModule2.ts +++ b/tests/cases/fourslash/importJsNodeModule2.ts @@ -19,7 +19,7 @@ edit.insert('.'); verify.completions({ exact: [ ...["n", "s", "b"].map(name => ({ name, kind: "property" })), - ...["x", "require"].map(name => ({ name, kind: "warning" })), + ...["x", "require"].map(name => ({ name, kind: "warning", sortText: completion.SortText.JavascriptIdentifiers })), ], }); edit.insert('n.'); diff --git a/tests/cases/fourslash/indirectClassInstantiation.ts b/tests/cases/fourslash/indirectClassInstantiation.ts index 198515dd806d7..5a87136446523 100644 --- a/tests/cases/fourslash/indirectClassInstantiation.ts +++ b/tests/cases/fourslash/indirectClassInstantiation.ts @@ -14,7 +14,18 @@ //// inst2.blah/*b*/; goTo.marker('a'); -verify.completions({ exact: ["property", "TestObj", "constructor", "instance", "class2", "prototype", "blah", "inst2"] }); +verify.completions({ + exact: [ + "property", + { name: "TestObj", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "constructor", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "instance", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "class2", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "prototype", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "blah", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "inst2", sortText: completion.SortText.JavascriptIdentifiers } + ] +}); edit.backspace(); goTo.marker('b'); diff --git a/tests/cases/fourslash/javaScriptClass1.ts b/tests/cases/fourslash/javaScriptClass1.ts index dd4ed33f7181d..ec3bc3b5ea66a 100644 --- a/tests/cases/fourslash/javaScriptClass1.ts +++ b/tests/cases/fourslash/javaScriptClass1.ts @@ -19,7 +19,15 @@ goTo.marker(); edit.insert('.'); -verify.completions({ exact: ["bar", "thing", "union", "Foo", "x"] }); +verify.completions({ + exact: [ + "bar", + "thing", + "union", + { name: "Foo", sortText: completion.SortText.JavascriptIdentifiers }, + { name: "x", sortText: completion.SortText.JavascriptIdentifiers } + ] +}); edit.insert('bar.'); verify.completions({ includes: ["substr"] }); diff --git a/tests/cases/fourslash/javaScriptModules12.ts b/tests/cases/fourslash/javaScriptModules12.ts index 5ca58bc4dc76d..0ae594f77c5ef 100644 --- a/tests/cases/fourslash/javaScriptModules12.ts +++ b/tests/cases/fourslash/javaScriptModules12.ts @@ -27,7 +27,45 @@ //// /*5*/ verify.completions( - { marker: "1", includes: ["x", "a", "b"], excludes: "y" }, - { marker: "2", includes: ["y", "a", "b"], excludes: "x" }, - { marker: ["3", "4", "5"], includes: ["a", "b"], excludes: ["x", "y"] }, + { + marker: "1", + includes: [ + "x", + { name: "a", sortText: completion.SortText.GlobalsOrKeywords }, + { name: "b", sortText: completion.SortText.GlobalsOrKeywords } + ], excludes: "y" + }, + { + marker: "2", + includes: [ + "y", + { name: "a", sortText: completion.SortText.GlobalsOrKeywords }, + { name: "b", sortText: completion.SortText.GlobalsOrKeywords } + ], + excludes: "x" + }, + { + marker: "3", + includes: [ + "a", + { name: "b", sortText: completion.SortText.GlobalsOrKeywords } + ], + excludes: ["x", "y"] + }, + { + marker: "4", + includes: [ + { name: "a", sortText: completion.SortText.GlobalsOrKeywords }, + "b" + ], + excludes: ["x", "y"] + }, + { + marker: ["5"], + includes: [ + { name: "a", sortText: completion.SortText.GlobalsOrKeywords }, + { name: "b", sortText: completion.SortText.GlobalsOrKeywords } + ], + excludes: ["x", "y"] + }, ); diff --git a/tests/cases/fourslash/javaScriptModules13.ts b/tests/cases/fourslash/javaScriptModules13.ts index 62987047862ca..69fa87157c89b 100644 --- a/tests/cases/fourslash/javaScriptModules13.ts +++ b/tests/cases/fourslash/javaScriptModules13.ts @@ -19,7 +19,11 @@ goTo.file('consumer.js'); goTo.marker(); -verify.completions({ marker: "", includes: "y", excludes: "invisible" }); +verify.completions({ + marker: "", + includes: { name: "y", sortText: completion.SortText.GlobalsOrKeywords }, + excludes: "invisible" +}); edit.insert('x.'); verify.completions({ includes: { name: "a", kind: "property" } }); diff --git a/tests/cases/fourslash/javaScriptModules14.ts b/tests/cases/fourslash/javaScriptModules14.ts index 1b564c096367c..9f3546625b3ea 100644 --- a/tests/cases/fourslash/javaScriptModules14.ts +++ b/tests/cases/fourslash/javaScriptModules14.ts @@ -21,4 +21,8 @@ //// var x = require('myMod'); //// /**/; -verify.completions({ marker: "", includes: "y", excludes: "invisible" }); +verify.completions({ + marker: "", + includes: { name: "y", sortText: completion.SortText.GlobalsOrKeywords }, + excludes: "invisible" +}); diff --git a/tests/cases/fourslash/javaScriptModules16.ts b/tests/cases/fourslash/javaScriptModules16.ts index 7c3bb31436d3f..51107934fb13d 100644 --- a/tests/cases/fourslash/javaScriptModules16.ts +++ b/tests/cases/fourslash/javaScriptModules16.ts @@ -18,7 +18,7 @@ edit.insert('.'); verify.completions({ exact: [ ...["n", "s", "b"].map(name => ({ name, kind: "property" })), - ...["x", "require"].map(name => ({ name, kind: "warning" })), + ...["x", "require"].map(name => ({ name, kind: "warning", sortText: completion.SortText.JavascriptIdentifiers })), ], }); edit.insert('n.'); diff --git a/tests/cases/fourslash/javaScriptModules19.ts b/tests/cases/fourslash/javaScriptModules19.ts index 1fe4ae3cfd1ee..85735b1f092eb 100644 --- a/tests/cases/fourslash/javaScriptModules19.ts +++ b/tests/cases/fourslash/javaScriptModules19.ts @@ -17,7 +17,11 @@ goTo.file('consumer.js'); goTo.marker(); -verify.completions({ marker: "", includes: "y", excludes: "invisible" }); +verify.completions({ + marker: "", + includes: { name: "y", sortText: completion.SortText.GlobalsOrKeywords }, + excludes: "invisible" +}); edit.insert('x.'); verify.completions({ includes: { name: "a", kind: "property" } }); diff --git a/tests/cases/fourslash/javaScriptPrototype2.ts b/tests/cases/fourslash/javaScriptPrototype2.ts index f8c2e56e1a997..17afc1ed0aa4b 100644 --- a/tests/cases/fourslash/javaScriptPrototype2.ts +++ b/tests/cases/fourslash/javaScriptPrototype2.ts @@ -31,4 +31,4 @@ verify.completions({ includes: { name: "toFixed", kind: "method", kindModifiers: goTo.marker('3'); edit.insert('.'); // Make sure symbols don't leak out into the constructor -verify.completions({ includes: ["qua", "foo", "bar"].map(name => ({ name, kind: "warning" })) }); +verify.completions({ includes: ["qua", "foo", "bar"].map(name => ({ name, kind: "warning", sortText: completion.SortText.JavascriptIdentifiers })) }); diff --git a/tests/cases/fourslash/javaScriptPrototype3.ts b/tests/cases/fourslash/javaScriptPrototype3.ts index 627f5c399778d..72d22b969b259 100644 --- a/tests/cases/fourslash/javaScriptPrototype3.ts +++ b/tests/cases/fourslash/javaScriptPrototype3.ts @@ -22,6 +22,10 @@ verify.completions({ { name: "qua", kind: "property" }, { name: "foo", kind: "method" }, { name: "bar", kind: "method" }, - ...["myCtor", "x", "prototype"].map(name => ({ name, kind: "warning" })), + ...["myCtor", "x", "prototype"].map(name => ({ + name, + kind: "warning", + sortText: completion.SortText.JavascriptIdentifiers + })), ], }); diff --git a/tests/cases/fourslash/javaScriptPrototype4.ts b/tests/cases/fourslash/javaScriptPrototype4.ts index 98deee4f22ac1..783cea8b9dd05 100644 --- a/tests/cases/fourslash/javaScriptPrototype4.ts +++ b/tests/cases/fourslash/javaScriptPrototype4.ts @@ -16,4 +16,7 @@ goTo.marker('1'); edit.insert('.'); // Check members of the function -verify.completions({ includes: ["foo", "bar", "qua"].map(name => ({ name, kind: "warning" })) }); +verify.completions({ + includes: ["foo", "bar", "qua"].map( + name => ({ name, kind: "warning", sortText: completion.SortText.JavascriptIdentifiers })) +}); diff --git a/tests/cases/fourslash/javascriptModules20.ts b/tests/cases/fourslash/javascriptModules20.ts index 8b8f0095959cd..0135ccea758e2 100644 --- a/tests/cases/fourslash/javascriptModules20.ts +++ b/tests/cases/fourslash/javascriptModules20.ts @@ -9,4 +9,8 @@ //// import * as mod from "./mod" //// mod./**/ -verify.completions({ marker: "", exact: [{ name: "a", kind: "property" }, { name: "mod", kind: "warning" }] }); +verify.completions({ + marker: "", exact: [ + { name: "a", kind: "property" }, + { name: "mod", kind: "warning", sortText: completion.SortText.JavascriptIdentifiers }] +}); diff --git a/tests/cases/fourslash/javascriptModules21.ts b/tests/cases/fourslash/javascriptModules21.ts index 5a8dd6b872b1e..9788f3e3ed7c5 100644 --- a/tests/cases/fourslash/javascriptModules21.ts +++ b/tests/cases/fourslash/javascriptModules21.ts @@ -10,4 +10,10 @@ //// import mod from "./mod" //// mod./**/ -verify.completions({ marker: "", exact: [{ name: "a", kind: "property" }, { name: "mod", kind: "warning" }] }); +verify.completions({ + marker: "", + exact: [ + { name: "a", kind: "property" }, + { name: "mod", kind: "warning", sortText: completion.SortText.JavascriptIdentifiers } + ] +}); diff --git a/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion.ts b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion.ts index a117bae1b110c..5e0247b64a56b 100644 --- a/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion.ts +++ b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion.ts @@ -29,7 +29,7 @@ const typeMembers: ReadonlyArray): ReadonlyArray { - return entries.map(e => ({ ...e, kind: "warning", kindModifiers: undefined })); + return entries.map(e => ({ ...e, kind: "warning", kindModifiers: undefined, sortText: completion.SortText.JavascriptIdentifiers })); } verify.completions( diff --git a/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion2.ts b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion2.ts index 9cb94689b7671..57802d84b448d 100644 --- a/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion2.ts +++ b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion2.ts @@ -28,10 +28,10 @@ function getCompletions(nonWarnings: ReadonlyArray): ReadonlyArray entry.name === name)); - return withKinds.map(entry => nonWarnings.includes(entry.name) ? entry : ({ name: entry.name, kind: "warning" })); + return withKinds.map(entry => nonWarnings.includes(entry.name) ? entry : ({ name: entry.name, kind: "warning", sortText: completion.SortText.JavascriptIdentifiers })); } verify.completions( diff --git a/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion3.ts b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion3.ts index efe73d9c023b0..82b0dd9f5e307 100644 --- a/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion3.ts +++ b/tests/cases/fourslash/jsFileJsdocTypedefTagTypeExpressionCompletion3.ts @@ -31,7 +31,7 @@ ////Foo./*valueMemberOfFoo*/; const warnings = (names: ReadonlyArray): ReadonlyArray => - names.map(name => ({ name, kind: "warning" })); + names.map(name => ({ name, kind: "warning", sortText: completion.SortText.JavascriptIdentifiers })); verify.completions( { diff --git a/tests/cases/fourslash/noImportCompletionsInOtherJavaScriptFile.ts b/tests/cases/fourslash/noImportCompletionsInOtherJavaScriptFile.ts index 0848b3e7cc2b3..6051a5d80fc7a 100644 --- a/tests/cases/fourslash/noImportCompletionsInOtherJavaScriptFile.ts +++ b/tests/cases/fourslash/noImportCompletionsInOtherJavaScriptFile.ts @@ -32,6 +32,7 @@ goTo.eachMarker(() => { kind: "const", kindModifiers: "export,declare", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); @@ -45,6 +46,7 @@ goTo.eachMarker(() => { kind: "const", kindModifiers: "export,declare", hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/server/jsdocTypedefTagNamespace.ts b/tests/cases/fourslash/server/jsdocTypedefTagNamespace.ts index 0d04b58606fe6..297238530f07b 100644 --- a/tests/cases/fourslash/server/jsdocTypedefTagNamespace.ts +++ b/tests/cases/fourslash/server/jsdocTypedefTagNamespace.ts @@ -17,5 +17,5 @@ verify.completions( { marker: ["1", "3"], includes: ["charAt", "toExponential"] }, - { marker: "2", includes: "age" }, + { marker: "2", includes: { name: "age", sortText: completion.SortText.JavascriptIdentifiers } }, ); diff --git a/tests/cases/fourslash/tsxCompletion9.ts b/tests/cases/fourslash/tsxCompletion9.ts index 21d2c43f67658..21261090b4e36 100644 --- a/tests/cases/fourslash/tsxCompletion9.ts +++ b/tests/cases/fourslash/tsxCompletion9.ts @@ -18,4 +18,4 @@ for (var i = 1; i <= 10; i++) { verify.completions({ marker: String(i), exact: undefined }); } -verify.completions({ marker: "end", includes: "null" }); +verify.completions({ marker: "end", includes: { name: "null", sortText: completion.SortText.GlobalsOrKeywords } }); diff --git a/tests/cases/fourslash/tsxCompletionNonTagLessThan.ts b/tests/cases/fourslash/tsxCompletionNonTagLessThan.ts index b2b6a046e6b01..a0b1f8ffdc3f6 100644 --- a/tests/cases/fourslash/tsxCompletionNonTagLessThan.ts +++ b/tests/cases/fourslash/tsxCompletionNonTagLessThan.ts @@ -5,7 +5,20 @@ ////[].map Date: Mon, 20 May 2019 16:43:55 -0700 Subject: [PATCH 10/43] Prevent type parameter printing from recuring on the same symbol (#31453) --- src/compiler/checker.ts | 6 ++++++ ...amespaceMergeWithClassConstrainedToSelf.ts | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/cases/fourslash/quickinfoForNamespaceMergeWithClassConstrainedToSelf.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 18c1f42f838fb..e47855ca63c4b 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -4302,6 +4302,11 @@ namespace ts { function lookupTypeParameterNodes(chain: Symbol[], index: number, context: NodeBuilderContext) { Debug.assert(chain && 0 <= index && index < chain.length); const symbol = chain[index]; + const symbolId = "" + getSymbolId(symbol); + if (context.typeParameterSymbolList && context.typeParameterSymbolList.get(symbolId)) { + return undefined; + } + (context.typeParameterSymbolList || (context.typeParameterSymbolList = createMap())).set(symbolId, true); let typeParameterNodes: ReadonlyArray | ReadonlyArray | undefined; if (context.flags & NodeBuilderFlags.WriteTypeParametersInQualifiedName && index < (chain.length - 1)) { const parentSymbol = symbol; @@ -4628,6 +4633,7 @@ namespace ts { inferTypeParameters: TypeParameter[] | undefined; approximateLength: number; truncating?: boolean; + typeParameterSymbolList?: Map; } function isDefaultBindingContext(location: Node) { diff --git a/tests/cases/fourslash/quickinfoForNamespaceMergeWithClassConstrainedToSelf.ts b/tests/cases/fourslash/quickinfoForNamespaceMergeWithClassConstrainedToSelf.ts new file mode 100644 index 0000000000000..e3c982a1203c8 --- /dev/null +++ b/tests/cases/fourslash/quickinfoForNamespaceMergeWithClassConstrainedToSelf.ts @@ -0,0 +1,21 @@ +/// + + +//// declare namespace AMap { +//// namespace MassMarks { +//// interface Data { +//// style?: number; +//// } +//// } +//// class MassMarks { +//// constructor(data: D[] | string); +//// clear(): void; +//// } +//// } +//// +//// interface MassMarksCustomData extends AMap.MassMarks./*1*/Data { +//// name: string; +//// id: string; +//// } + +verify.quickInfoAt("1", "interface AMap.MassMarks.Data"); From db150517d7fa6261ee9362ba58fec42dd5a2f816 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 21 May 2019 09:32:17 -0700 Subject: [PATCH 11/43] Ignore drive letters when comparing casings of the files with forceConsistentCasingInFileNames Fixes #31327 --- src/compiler/program.ts | 5 ++++- src/compiler/utilities.ts | 8 ++++++++ src/testRunner/unittests/moduleResolution.ts | 18 +++++++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 2fda6ea49a55f..6313cc19902b1 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2232,7 +2232,10 @@ namespace ts { if (isRedirect) { inputName = getProjectReferenceRedirect(fileName) || fileName; } - if (getNormalizedAbsolutePath(checkedName, currentDirectory) !== getNormalizedAbsolutePath(inputName, currentDirectory)) { + // Check if it differs only in drive letters its ok to ignore that error: + const checkedAbsolutePath = getNormalizedAbsolutePathWithoutRoot(checkedName, currentDirectory); + const inputAbsolutePath = getNormalizedAbsolutePathWithoutRoot(inputName, currentDirectory); + if (checkedAbsolutePath !== inputAbsolutePath) { reportFileNamesDifferOnlyInCasingError(inputName, checkedName, refFile, refPos, refEnd); } } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 45dc980296be7..ac3be6d434bbd 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -7646,6 +7646,14 @@ namespace ts { return root + pathComponents.slice(1).join(directorySeparator); } + export function getNormalizedAbsolutePathWithoutRoot(fileName: string, currentDirectory: string | undefined) { + return getPathWithoutRoot(getNormalizedPathComponents(fileName, currentDirectory)); + } + + function getPathWithoutRoot(pathComponents: ReadonlyArray) { + if (pathComponents.length === 0) return ""; + return pathComponents.slice(1).join(directorySeparator); + } } /* @internal */ diff --git a/src/testRunner/unittests/moduleResolution.ts b/src/testRunner/unittests/moduleResolution.ts index 69560e5449c19..4fecc6c09f366 100644 --- a/src/testRunner/unittests/moduleResolution.ts +++ b/src/testRunner/unittests/moduleResolution.ts @@ -530,7 +530,7 @@ export = C; }); }); - describe("unittests:: moduleResolution:: Files with different casing", () => { + describe("unittests:: moduleResolution:: Files with different casing with forceConsistentCasingInFileNames", () => { let library: SourceFile; function test(files: Map, options: CompilerOptions, currentDirectory: string, useCaseSensitiveFileNames: boolean, rootFiles: string[], diagnosticCodes: number[]): void { const getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames); @@ -649,6 +649,22 @@ import b = require("./moduleB"); }); test(files, { module: ModuleKind.CommonJS, forceConsistentCasingInFileNames: true }, "/a/B/c", /*useCaseSensitiveFileNames*/ false, ["moduleD.ts"], []); }); + + it("should succeed when the two files in program differ only in drive letter in their names", () => { + const files = createMapFromTemplate({ + "d:/someFolder/moduleA.ts": `import a = require("D:/someFolder/moduleC")`, + "d:/someFolder/moduleB.ts": `import a = require("./moduleC")`, + "D:/someFolder/moduleC.ts": "export const x = 10", + }); + test( + files, + { module: ModuleKind.CommonJS, forceConsistentCasingInFileNames: true }, + "d:/someFolder", + /*useCaseSensitiveFileNames*/ false, + ["d:/someFolder/moduleA.ts", "d:/someFolder/moduleB.ts"], + [] + ); + }); }); describe("unittests:: moduleResolution:: baseUrl augmented module resolution", () => { From 43c7eb77e17e738958bee7b7b9d6fd82c2108655 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 21 May 2019 09:38:14 -0700 Subject: [PATCH 12/43] Switch to using File not found message instead of trace message file does not exit Fixes #30872 --- src/compiler/commandLineParser.ts | 4 ++-- .../unittests/config/configurationExtension.ts | 14 +++++--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index fbc6d8d6fea1d..3aaa217fbd09d 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -2361,7 +2361,7 @@ namespace ts { if (!host.fileExists(extendedConfigPath) && !endsWith(extendedConfigPath, Extension.Json)) { extendedConfigPath = `${extendedConfigPath}.json`; if (!host.fileExists(extendedConfigPath)) { - errors.push(createDiagnostic(Diagnostics.File_0_does_not_exist, extendedConfig)); + errors.push(createDiagnostic(Diagnostics.File_0_not_found, extendedConfig)); return undefined; } } @@ -2372,7 +2372,7 @@ namespace ts { if (resolved.resolvedModule) { return resolved.resolvedModule.resolvedFileName; } - errors.push(createDiagnostic(Diagnostics.File_0_does_not_exist, extendedConfig)); + errors.push(createDiagnostic(Diagnostics.File_0_not_found, extendedConfig)); return undefined; } diff --git a/src/testRunner/unittests/config/configurationExtension.ts b/src/testRunner/unittests/config/configurationExtension.ts index 25e975c0fb208..6c1fc9522954a 100644 --- a/src/testRunner/unittests/config/configurationExtension.ts +++ b/src/testRunner/unittests/config/configurationExtension.ts @@ -197,13 +197,13 @@ namespace ts { const caseSensitiveBasePath = "/dev/"; const caseSensitiveHost = new fakes.ParseConfigHost(createFileSystem(/*ignoreCase*/ false, caseSensitiveBasePath, "/")); - function verifyDiagnostics(actual: Diagnostic[], expected: {code: number, category: DiagnosticCategory, messageText: string}[]) { + function verifyDiagnostics(actual: Diagnostic[], expected: { code: number; messageText: string; }[]) { assert.isTrue(expected.length === actual.length, `Expected error: ${JSON.stringify(expected)}. Actual error: ${JSON.stringify(actual)}.`); for (let i = 0; i < actual.length; i++) { const actualError = actual[i]; const expectedError = expected[i]; assert.equal(actualError.code, expectedError.code, "Error code mismatch"); - assert.equal(actualError.category, expectedError.category, "Category mismatch"); + assert.equal(actualError.category, DiagnosticCategory.Error, "Category mismatch"); // Should always be error assert.equal(flattenDiagnosticMessageText(actualError.messageText, "\n"), expectedError.messageText); } } @@ -246,7 +246,7 @@ namespace ts { }); } - function testFailure(name: string, entry: string, expectedDiagnostics: { code: number, category: DiagnosticCategory, messageText: string }[]) { + function testFailure(name: string, entry: string, expectedDiagnostics: { code: number; messageText: string; }[]) { it(name, () => { const parsed = getParseCommandLine(entry); verifyDiagnostics(parsed.errors, expectedDiagnostics); @@ -280,26 +280,22 @@ namespace ts { testFailure("can report errors on circular imports", "circular.json", [ { code: 18000, - category: DiagnosticCategory.Error, messageText: `Circularity detected while resolving configuration: ${[combinePaths(basePath, "circular.json"), combinePaths(basePath, "circular2.json"), combinePaths(basePath, "circular.json")].join(" -> ")}` } ]); testFailure("can report missing configurations", "missing.json", [{ - code: 6096, - category: DiagnosticCategory.Message, - messageText: `File './missing2' does not exist.` + code: 6053, + messageText: `File './missing2' not found.` }]); testFailure("can report errors in extended configs", "failure.json", [{ code: 6114, - category: DiagnosticCategory.Error, messageText: `Unknown option 'excludes'. Did you mean 'exclude'?` }]); testFailure("can error when 'extends' is not a string", "extends.json", [{ code: 5024, - category: DiagnosticCategory.Error, messageText: `Compiler option 'extends' requires a value of type string.` }]); From c71423edd6dfc7bf357c9c16f7ef4eae2184d9b7 Mon Sep 17 00:00:00 2001 From: TypeScript Bot Date: Tue, 21 May 2019 13:22:02 -0700 Subject: [PATCH 13/43] Update user baselines (#31496) --- .../user/chrome-devtools-frontend.log | 4 +- tests/baselines/reference/user/uglify-js.log | 113 +++++++++--------- 2 files changed, 58 insertions(+), 59 deletions(-) diff --git a/tests/baselines/reference/user/chrome-devtools-frontend.log b/tests/baselines/reference/user/chrome-devtools-frontend.log index 4fd3354a2bbbc..bdde6b918c099 100644 --- a/tests/baselines/reference/user/chrome-devtools-frontend.log +++ b/tests/baselines/reference/user/chrome-devtools-frontend.log @@ -4484,9 +4484,7 @@ node_modules/chrome-devtools-frontend/front_end/coverage/CoverageModel.js(175,64 node_modules/chrome-devtools-frontend/front_end/coverage/CoverageModel.js(190,48): error TS2694: Namespace 'Coverage' has no exported member 'RangeUseCount'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageModel.js(191,11): error TS2403: Subsequent variable declarations must have the same type. Variable 'entry' must be of type '[CSSStyleSheetHeader, any[]]', but here has type 'CoverageInfo'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageModel.js(197,5): error TS2322: Type '[CSSStyleSheetHeader, any[]][]' is not assignable to type 'CoverageInfo[]'. - Types of property 'pop' are incompatible. - Type '() => [CSSStyleSheetHeader, any[]]' is not assignable to type '() => CoverageInfo'. - Type '[CSSStyleSheetHeader, any[]]' is not assignable to type 'CoverageInfo'. + Type '[CSSStyleSheetHeader, any[]]' is not assignable to type 'CoverageInfo'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageModel.js(201,31): error TS2694: Namespace 'Coverage' has no exported member 'RangeUseCount'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageModel.js(202,32): error TS2694: Namespace 'Coverage' has no exported member 'CoverageSegment'. node_modules/chrome-devtools-frontend/front_end/coverage/CoverageModel.js(210,23): error TS2339: Property 'peekLast' does not exist on type 'any[]'. diff --git a/tests/baselines/reference/user/uglify-js.log b/tests/baselines/reference/user/uglify-js.log index eccbc070b8954..3c98006c52f99 100644 --- a/tests/baselines/reference/user/uglify-js.log +++ b/tests/baselines/reference/user/uglify-js.log @@ -1,66 +1,67 @@ Exit Code: 1 Standard output: node_modules/uglify-js/lib/ast.js(223,38): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/ast.js(894,5): error TS2322: Type '{ _visit: (node: any, descend: any) => any; parent: (n: any) => any; push: typeof push; pop: typeof pop; self: () => any; find_parent: (type: any) => any; has_directive: (type: any) => any; loopcontrol_target: (node: any) => any; in_boolean_context: () => boolean | undefined; }' is not assignable to type 'TreeWalker'. +node_modules/uglify-js/lib/ast.js(906,5): error TS2322: Type '{ _visit: (node: any, descend: any) => any; parent: (n: any) => any; push: typeof push; pop: typeof pop; self: () => any; find_parent: (type: any) => any; has_directive: (type: any) => any; loopcontrol_target: (node: any) => any; in_boolean_context: () => boolean | undefined; }' is not assignable to type 'TreeWalker'. Object literal may only specify known properties, but '_visit' does not exist in type 'TreeWalker'. Did you mean to write 'visit'? -node_modules/uglify-js/lib/ast.js(895,14): error TS2339: Property 'push' does not exist on type 'TreeWalker'. -node_modules/uglify-js/lib/ast.js(902,14): error TS2339: Property 'pop' does not exist on type 'TreeWalker'. -node_modules/uglify-js/lib/ast.js(957,25): error TS2339: Property 'self' does not exist on type 'TreeWalker'. -node_modules/uglify-js/lib/ast.js(958,37): error TS2339: Property 'parent' does not exist on type 'TreeWalker'. -node_modules/uglify-js/lib/compress.js(173,42): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(512,41): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(838,33): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(1094,38): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(1108,51): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'true | ((node: any) => any)' has no compatible call signatures. -node_modules/uglify-js/lib/compress.js(1172,53): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(1213,112): error TS2454: Variable 'args' is used before being assigned. -node_modules/uglify-js/lib/compress.js(1214,29): error TS2532: Object is possibly 'undefined'. -node_modules/uglify-js/lib/compress.js(1223,87): error TS2322: Type 'false' is not assignable to type 'number'. -node_modules/uglify-js/lib/compress.js(1231,29): error TS2322: Type 'false' is not assignable to type 'never'. -node_modules/uglify-js/lib/compress.js(1339,53): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(1440,38): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(1550,42): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(1582,41): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(1694,49): error TS2345: Argument of type 'number[]' is not assignable to parameter of type '[number, number, ...never[]]'. +node_modules/uglify-js/lib/ast.js(907,14): error TS2339: Property 'push' does not exist on type 'TreeWalker'. +node_modules/uglify-js/lib/ast.js(914,14): error TS2339: Property 'pop' does not exist on type 'TreeWalker'. +node_modules/uglify-js/lib/ast.js(969,25): error TS2339: Property 'self' does not exist on type 'TreeWalker'. +node_modules/uglify-js/lib/ast.js(970,37): error TS2339: Property 'parent' does not exist on type 'TreeWalker'. +node_modules/uglify-js/lib/compress.js(184,42): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(535,41): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(861,33): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(1121,38): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(1135,51): error TS2349: Cannot invoke an expression whose type lacks a call signature. Type 'true | ((node: any) => any)' has no compatible call signatures. +node_modules/uglify-js/lib/compress.js(1199,53): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(1240,112): error TS2454: Variable 'args' is used before being assigned. +node_modules/uglify-js/lib/compress.js(1241,29): error TS2532: Object is possibly 'undefined'. +node_modules/uglify-js/lib/compress.js(1250,87): error TS2322: Type 'false' is not assignable to type 'number'. +node_modules/uglify-js/lib/compress.js(1258,29): error TS2322: Type 'false' is not assignable to type 'never'. +node_modules/uglify-js/lib/compress.js(1366,53): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(1467,38): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(1577,42): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(1609,41): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(1721,49): error TS2345: Argument of type 'number[]' is not assignable to parameter of type '[number, number, ...never[]]'. Type 'number[]' is missing the following properties from type '[number, number, ...never[]]': 0, 1 -node_modules/uglify-js/lib/compress.js(2017,59): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(2055,53): error TS2345: Argument of type 'any[]' is not assignable to parameter of type '[number, number, ...never[]]'. +node_modules/uglify-js/lib/compress.js(2044,59): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(2082,53): error TS2345: Argument of type 'any[]' is not assignable to parameter of type '[number, number, ...never[]]'. Type 'any[]' is missing the following properties from type '[number, number, ...never[]]': 0, 1 -node_modules/uglify-js/lib/compress.js(2203,34): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(2925,42): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3378,38): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3391,33): error TS2322: Type '"f"' is not assignable to type 'boolean'. -node_modules/uglify-js/lib/compress.js(3525,33): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3578,29): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3595,29): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(3620,75): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3694,63): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3879,38): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(3900,24): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(3910,28): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. -node_modules/uglify-js/lib/compress.js(4069,21): error TS2403: Subsequent variable declarations must have the same type. Variable 'defs' must be of type 'Dictionary & { set: (key: any, val: any) => Dictionary & { set: ...; add: (key: any, val: any) => Dictionary & { set: ...; add: ...; get: (key: any) => any; del: (key: any) => Dictionary & { set: ...; ... 8 more ...; toObject: () => any; }; ... 5 more ...; toObject: () => any; }; ... 7 more ...; toObject: () => any;...', but here has type 'any'. -node_modules/uglify-js/lib/compress.js(4121,17): error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead. -node_modules/uglify-js/lib/compress.js(4182,45): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(4292,33): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(4589,17): error TS2403: Subsequent variable declarations must have the same type. Variable 'body' must be of type 'any[]', but here has type 'any'. -node_modules/uglify-js/lib/compress.js(4673,37): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(4881,57): error TS2345: Argument of type 'any[]' is not assignable to parameter of type '[RegExp, (string | undefined)?]'. +node_modules/uglify-js/lib/compress.js(2230,34): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(2942,42): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3395,38): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3408,33): error TS2322: Type '"f"' is not assignable to type 'boolean'. +node_modules/uglify-js/lib/compress.js(3542,33): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3595,29): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3612,29): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(3637,75): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3711,63): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3832,12): error TS2339: Property 'push' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(3897,38): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(3918,24): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(3928,28): error TS2339: Property 'parent' does not exist on type 'TreeTransformer'. +node_modules/uglify-js/lib/compress.js(4097,21): error TS2403: Subsequent variable declarations must have the same type. Variable 'defs' must be of type 'Dictionary & { set: (key: any, val: any) => Dictionary & { set: ...; add: (key: any, val: any) => Dictionary & { set: ...; add: ...; get: (key: any) => any; del: (key: any) => Dictionary & { set: ...; ... 8 more ...; toObject: () => any; }; ... 5 more ...; toObject: () => any; }; ... 7 more ...; toObject: () => any;...', but here has type 'any'. +node_modules/uglify-js/lib/compress.js(4149,17): error TS2447: The '|=' operator is not allowed for boolean types. Consider using '||' instead. +node_modules/uglify-js/lib/compress.js(4210,45): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(4320,33): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(4618,17): error TS2403: Subsequent variable declarations must have the same type. Variable 'body' must be of type 'any[]', but here has type 'any'. +node_modules/uglify-js/lib/compress.js(4702,37): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(4910,57): error TS2345: Argument of type 'any[]' is not assignable to parameter of type '[RegExp, (string | undefined)?]'. Property '0' is missing in type 'any[]' but required in type '[RegExp, (string | undefined)?]'. -node_modules/uglify-js/lib/compress.js(5045,45): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(5052,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'code' must be of type 'string', but here has type '{ get: () => string; toString: () => string; indent: () => void; indentation: () => number; current_width: () => number; should_break: () => boolean; has_parens: () => boolean; newline: () => void; print: (str: any) => void; ... 24 more ...; parent: (n: any) => any; }'. -node_modules/uglify-js/lib/compress.js(5056,36): error TS2532: Object is possibly 'undefined'. -node_modules/uglify-js/lib/compress.js(5061,41): error TS2339: Property 'get' does not exist on type 'string'. -node_modules/uglify-js/lib/compress.js(5565,18): error TS2454: Variable 'is_strict_comparison' is used before being assigned. -node_modules/uglify-js/lib/compress.js(6060,25): error TS2367: This condition will always return 'false' since the types 'boolean' and '"f"' have no overlap. -node_modules/uglify-js/lib/compress.js(6087,47): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(6160,39): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(6232,39): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(6238,41): error TS2554: Expected 0 arguments, but got 1. -node_modules/uglify-js/lib/compress.js(6676,43): error TS2454: Variable 'property' is used before being assigned. -node_modules/uglify-js/lib/compress.js(6691,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'value' must be of type 'number', but here has type 'any'. -node_modules/uglify-js/lib/compress.js(6694,46): error TS2339: Property 'has_side_effects' does not exist on type 'number'. -node_modules/uglify-js/lib/compress.js(6700,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'value' must be of type 'number', but here has type 'any'. -node_modules/uglify-js/lib/compress.js(6728,34): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(5074,45): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(5081,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'code' must be of type 'string', but here has type '{ get: () => string; toString: () => string; indent: () => void; indentation: () => number; current_width: () => number; should_break: () => boolean; has_parens: () => boolean; newline: () => void; print: (str: any) => void; ... 24 more ...; parent: (n: any) => any; }'. +node_modules/uglify-js/lib/compress.js(5085,36): error TS2532: Object is possibly 'undefined'. +node_modules/uglify-js/lib/compress.js(5090,41): error TS2339: Property 'get' does not exist on type 'string'. +node_modules/uglify-js/lib/compress.js(5594,18): error TS2454: Variable 'is_strict_comparison' is used before being assigned. +node_modules/uglify-js/lib/compress.js(6105,25): error TS2367: This condition will always return 'false' since the types 'boolean' and '"f"' have no overlap. +node_modules/uglify-js/lib/compress.js(6132,47): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(6205,39): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(6277,39): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(6283,41): error TS2554: Expected 0 arguments, but got 1. +node_modules/uglify-js/lib/compress.js(6728,43): error TS2454: Variable 'property' is used before being assigned. +node_modules/uglify-js/lib/compress.js(6743,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'value' must be of type 'number', but here has type 'any'. +node_modules/uglify-js/lib/compress.js(6746,46): error TS2339: Property 'has_side_effects' does not exist on type 'number'. +node_modules/uglify-js/lib/compress.js(6752,25): error TS2403: Subsequent variable declarations must have the same type. Variable 'value' must be of type 'number', but here has type 'any'. +node_modules/uglify-js/lib/compress.js(6790,34): error TS2554: Expected 0 arguments, but got 1. node_modules/uglify-js/lib/minify.js(167,75): error TS2339: Property 'compress' does not exist on type 'Compressor'. node_modules/uglify-js/lib/mozilla-ast.js(566,33): error TS2554: Expected 0 arguments, but got 1. node_modules/uglify-js/lib/output.js(235,25): error TS2554: Expected 0 arguments, but got 2. From 3f5912995b4fb845ff7ec436dcb40ebfe3816b42 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 21 May 2019 14:38:34 -0700 Subject: [PATCH 14/43] Add related span to original declaration on disagreeing variable/property types. --- src/compiler/checker.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e9dddff64af39..9e5c864f6b975 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5352,7 +5352,7 @@ namespace ts { return type; } else if (declaredType !== errorType && type !== errorType && !isTypeIdenticalTo(declaredType, type)) { - errorNextVariableOrPropertyDeclarationMustHaveSameType(declaredType, declaration, type); + errorNextVariableOrPropertyDeclarationMustHaveSameType(/*firstDeclaration*/ undefined, declaredType, declaration, type); } } return declaredType; @@ -26839,7 +26839,7 @@ namespace ts { if (type !== errorType && declarationType !== errorType && !isTypeIdenticalTo(type, declarationType) && !(symbol.flags & SymbolFlags.Assignment)) { - errorNextVariableOrPropertyDeclarationMustHaveSameType(type, node, declarationType); + errorNextVariableOrPropertyDeclarationMustHaveSameType(symbol.valueDeclaration, type, node, declarationType); } if (node.initializer) { checkTypeAssignableToAndOptionallyElaborate(checkExpressionCached(node.initializer), declarationType, node, node.initializer, /*headMessage*/ undefined); @@ -26859,17 +26859,24 @@ namespace ts { } } - function errorNextVariableOrPropertyDeclarationMustHaveSameType(firstType: Type, nextDeclaration: Declaration, nextType: Type): void { + function errorNextVariableOrPropertyDeclarationMustHaveSameType(firstDeclaration: Declaration | undefined, firstType: Type, nextDeclaration: Declaration, nextType: Type): void { const nextDeclarationName = getNameOfDeclaration(nextDeclaration); const message = nextDeclaration.kind === SyntaxKind.PropertyDeclaration || nextDeclaration.kind === SyntaxKind.PropertySignature ? Diagnostics.Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_type_2 : Diagnostics.Subsequent_variable_declarations_must_have_the_same_type_Variable_0_must_be_of_type_1_but_here_has_type_2; - error( + const declName = declarationNameToString(nextDeclarationName); + const err = error( nextDeclarationName, message, - declarationNameToString(nextDeclarationName), + declName, typeToString(firstType), - typeToString(nextType)); + typeToString(nextType) + ); + if (firstDeclaration) { + addRelatedInfo(err, + createDiagnosticForNode(firstDeclaration, Diagnostics._0_was_also_declared_here, declName) + ); + } } function areDeclarationFlagsIdentical(left: Declaration, right: Declaration) { From 81d3595058be3ff808ebdc8417f1d206881f7fae Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 21 May 2019 14:39:11 -0700 Subject: [PATCH 15/43] Accepted baselines. --- tests/baselines/reference/ES5For-of7.errors.txt | 1 + ...onAndModuleWithSameNameAndCommonRoot.errors.txt | 2 ++ .../asyncArrowFunction5_es2017.errors.txt | 1 + .../reference/asyncArrowFunction5_es5.errors.txt | 1 + .../reference/asyncArrowFunction5_es6.errors.txt | 1 + .../asyncArrowFunction9_es2017.errors.txt | 1 + .../reference/asyncArrowFunction9_es5.errors.txt | 1 + .../reference/asyncArrowFunction9_es6.errors.txt | 1 + .../reference/augmentedTypesVar.errors.txt | 1 + tests/baselines/reference/castingTuple.errors.txt | 1 + .../checkMergedGlobalUMDSymbol.errors.txt | 1 + .../classWithDuplicateIdentifier.errors.txt | 2 ++ .../reference/conditionalTypes1.errors.txt | 1 + .../declarationsAndAssignments.errors.txt | 1 + .../reference/duplicateClassElements.errors.txt | 1 + .../duplicateIdentifierInCatchBlock.errors.txt | 1 + .../reference/duplicateLocalVariable1.errors.txt | 1 + .../reference/duplicateLocalVariable2.errors.txt | 1 + .../reference/duplicateLocalVariable3.errors.txt | 1 + .../reference/duplicateLocalVariable4.errors.txt | 3 ++- .../reference/duplicateVariablesWithAny.errors.txt | 4 ++++ .../duplicateVarsAcrossFileBoundaries.errors.txt | 4 ++++ .../reference/dynamicNamesErrors.errors.txt | 1 + .../enumAssignabilityInInheritance.errors.txt | 4 +++- .../reference/for-inStatements.errors.txt | 2 ++ .../for-inStatementsArrayErrors.errors.txt | 2 ++ .../reference/for-inStatementsInvalid.errors.txt | 2 ++ .../forStatementsMultipleInvalidDecl.errors.txt | 14 +++++++++++++- .../reference/functionArgShadowing.errors.txt | 2 ++ .../reference/gettersAndSettersErrors.errors.txt | 1 + ...orSignaturesWithTypeParametersAndAny.errors.txt | 6 +++++- .../reference/interfaceDeclaration1.errors.txt | 1 + .../invalidMultipleVariableDeclarations.errors.txt | 14 +++++++++++++- ...lationDuplicateVariableErrorReported.errors.txt | 3 ++- .../reference/mappedTypeErrors.errors.txt | 4 ++++ ...terfacesWithConflictingPropertyNames.errors.txt | 3 +++ ...atureHandledDeclarationKindForSymbol.errors.txt | 1 + .../missingAndExcessProperties.errors.txt | 4 ++++ .../negateOperatorInvalidOperations.errors.txt | 1 + ...umericStringNamedPropertyEquivalence.errors.txt | 1 + .../objectLiteralContextualTyping.errors.txt | 1 + tests/baselines/reference/objectRest.errors.txt | 1 + ...ionalParamterAndVariableDeclaration2.errors.txt | 1 + ...rderMattersForSignatureGroupIdentity.errors.txt | 1 + .../reference/overloadResolution.errors.txt | 1 + .../overloadResolutionConstructors.errors.txt | 1 + .../parserCastVersusArrowFunction1.errors.txt | 3 +++ .../reference/promiseIdentity2.errors.txt | 3 ++- .../reference/promiseIdentityWithAny2.errors.txt | 4 +++- .../baselines/reference/propertyAccess.errors.txt | 1 + .../propertyIdentityWithPrivacyMismatch.errors.txt | 2 ++ .../reference/reassignStaticProp.errors.txt | 1 + tests/baselines/reference/spreadUnion2.errors.txt | 6 ++++++ .../reference/strictTupleLength.errors.txt | 2 ++ ...TemplateStringsTypeArgumentInference.errors.txt | 1 + ...plateStringsTypeArgumentInferenceES6.errors.txt | 1 + tests/baselines/reference/tupleTypes.errors.txt | 2 ++ .../reference/typeArgumentInference.errors.txt | 1 + ...ArgumentInferenceConstructSignatures.errors.txt | 1 + ...typeArgumentInferenceWithConstraints.errors.txt | 1 + ...ardOfFormTypeOfEqualEqualHasNoEffect.errors.txt | 4 ++++ ...GuardOfFormTypeOfNotEqualHasNoEffect.errors.txt | 4 ++++ .../typeOfEnumAndVarRedeclarations.errors.txt | 2 ++ tests/baselines/reference/typeOfThis.errors.txt | 10 ++++++++++ .../reference/unionTypeEquivalence.errors.txt | 1 + .../reference/unionTypeIdentity.errors.txt | 5 ++++- .../reference/unionTypeLiterals.errors.txt | 4 +++- tests/baselines/reference/varBlock.errors.txt | 1 + tests/baselines/reference/witness.errors.txt | 7 +++++++ 69 files changed, 161 insertions(+), 10 deletions(-) diff --git a/tests/baselines/reference/ES5For-of7.errors.txt b/tests/baselines/reference/ES5For-of7.errors.txt index a3d40f3881416..460c7bf468091 100644 --- a/tests/baselines/reference/ES5For-of7.errors.txt +++ b/tests/baselines/reference/ES5For-of7.errors.txt @@ -10,4 +10,5 @@ tests/cases/conformance/statements/for-ofStatements/ES5For-of7.ts(6,9): error TS var x = [w, v]; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'any[]'. +!!! related TS6203 tests/cases/conformance/statements/for-ofStatements/ES5For-of7.ts:2:9: 'x' was also declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/FunctionAndModuleWithSameNameAndCommonRoot.errors.txt b/tests/baselines/reference/FunctionAndModuleWithSameNameAndCommonRoot.errors.txt index 20f8e09248ad2..0a72e6b641d6c 100644 --- a/tests/baselines/reference/FunctionAndModuleWithSameNameAndCommonRoot.errors.txt +++ b/tests/baselines/reference/FunctionAndModuleWithSameNameAndCommonRoot.errors.txt @@ -24,6 +24,7 @@ tests/cases/conformance/internalModules/DeclarationMerging/test.ts(2,5): error T var fn = A.Point; ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'fn' must be of type '() => { x: number; y: number; }', but here has type 'typeof Point'. +!!! related TS6203 tests/cases/conformance/internalModules/DeclarationMerging/test.ts:1:5: 'fn' was also declared here. var cl: { x: number; y: number; } var cl = A.Point(); @@ -46,6 +47,7 @@ tests/cases/conformance/internalModules/DeclarationMerging/test.ts(2,5): error T var fn = B.Point; // not expected to be an error. bug 840000: [corelang] Function of fundule not assignalbe as expected ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'fn' must be of type '() => { x: number; y: number; }', but here has type 'typeof Point'. +!!! related TS6203 tests/cases/conformance/internalModules/DeclarationMerging/test.ts:1:5: 'fn' was also declared here. var cl: { x: number; y: number; } var cl = B.Point(); diff --git a/tests/baselines/reference/asyncArrowFunction5_es2017.errors.txt b/tests/baselines/reference/asyncArrowFunction5_es2017.errors.txt index 28ddb3bb9b95b..26601467324e6 100644 --- a/tests/baselines/reference/asyncArrowFunction5_es2017.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction5_es2017.errors.txt @@ -16,6 +16,7 @@ tests/cases/conformance/async/es2017/asyncArrowFunction/asyncArrowFunction5_es20 !!! error TS1005: ',' expected. ~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'. +!!! related TS6203 /.ts/lib.es2015.promise.d.ts:152:13: 'Promise' was also declared here. ~ !!! error TS1005: ',' expected. ~~ diff --git a/tests/baselines/reference/asyncArrowFunction5_es5.errors.txt b/tests/baselines/reference/asyncArrowFunction5_es5.errors.txt index f132abff2355b..cf82d765a566a 100644 --- a/tests/baselines/reference/asyncArrowFunction5_es5.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction5_es5.errors.txt @@ -16,6 +16,7 @@ tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction5_es5.ts( !!! error TS1005: ',' expected. ~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'. +!!! related TS6203 /.ts/lib.es2015.promise.d.ts:152:13: 'Promise' was also declared here. ~ !!! error TS1005: ',' expected. ~~ diff --git a/tests/baselines/reference/asyncArrowFunction5_es6.errors.txt b/tests/baselines/reference/asyncArrowFunction5_es6.errors.txt index a2f6f4412521c..909efc3c97eec 100644 --- a/tests/baselines/reference/asyncArrowFunction5_es6.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction5_es6.errors.txt @@ -16,6 +16,7 @@ tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction5_es6.ts( !!! error TS1005: ',' expected. ~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'. +!!! related TS6203 /.ts/lib.es2015.promise.d.ts:152:13: 'Promise' was also declared here. ~ !!! error TS1005: ',' expected. ~~ diff --git a/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt b/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt index cd2bb9c885820..0be88de28681a 100644 --- a/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction9_es2017.errors.txt @@ -16,6 +16,7 @@ tests/cases/conformance/async/es2017/asyncArrowFunction/asyncArrowFunction9_es20 !!! error TS1005: ',' expected. ~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'. +!!! related TS6203 /.ts/lib.es2015.promise.d.ts:152:13: 'Promise' was also declared here. ~ !!! error TS1005: ',' expected. ~~ diff --git a/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt b/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt index be561eab72c0f..085b3b50884b7 100644 --- a/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction9_es5.errors.txt @@ -16,6 +16,7 @@ tests/cases/conformance/async/es5/asyncArrowFunction/asyncArrowFunction9_es5.ts( !!! error TS1005: ',' expected. ~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'. +!!! related TS6203 /.ts/lib.es2015.promise.d.ts:152:13: 'Promise' was also declared here. ~ !!! error TS1005: ',' expected. ~~ diff --git a/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt b/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt index 84177f28292d9..6949aad5cea0c 100644 --- a/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt +++ b/tests/baselines/reference/asyncArrowFunction9_es6.errors.txt @@ -16,6 +16,7 @@ tests/cases/conformance/async/es6/asyncArrowFunction/asyncArrowFunction9_es6.ts( !!! error TS1005: ',' expected. ~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'Promise' must be of type 'PromiseConstructor', but here has type 'any'. +!!! related TS6203 /.ts/lib.es2015.promise.d.ts:152:13: 'Promise' was also declared here. ~ !!! error TS1005: ',' expected. ~~ diff --git a/tests/baselines/reference/augmentedTypesVar.errors.txt b/tests/baselines/reference/augmentedTypesVar.errors.txt index 261686f365936..ae910b4f5be16 100644 --- a/tests/baselines/reference/augmentedTypesVar.errors.txt +++ b/tests/baselines/reference/augmentedTypesVar.errors.txt @@ -30,6 +30,7 @@ tests/cases/compiler/augmentedTypesVar.ts(31,8): error TS2300: Duplicate identif var x3 = () => { } // error ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x3' must be of type 'number', but here has type '() => void'. +!!! related TS6203 tests/cases/compiler/augmentedTypesVar.ts:9:5: 'x3' was also declared here. // var then class var x4 = 1; // error diff --git a/tests/baselines/reference/castingTuple.errors.txt b/tests/baselines/reference/castingTuple.errors.txt index 4ddb42ed2d91d..0a1d592e8b1cf 100644 --- a/tests/baselines/reference/castingTuple.errors.txt +++ b/tests/baselines/reference/castingTuple.errors.txt @@ -71,6 +71,7 @@ tests/cases/conformance/types/tuple/castingTuple.ts(33,1): error TS2304: Cannot var array1 = numStrTuple; ~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'array1' must be of type '{}[]', but here has type 'number[]'. +!!! related TS6203 tests/cases/conformance/types/tuple/castingTuple.ts:23:5: 'array1' was also declared here. t4[2] = 10; ~~ !!! error TS2304: Cannot find name 't4'. diff --git a/tests/baselines/reference/checkMergedGlobalUMDSymbol.errors.txt b/tests/baselines/reference/checkMergedGlobalUMDSymbol.errors.txt index f3d21e26b6e67..f4b889131f17e 100644 --- a/tests/baselines/reference/checkMergedGlobalUMDSymbol.errors.txt +++ b/tests/baselines/reference/checkMergedGlobalUMDSymbol.errors.txt @@ -15,6 +15,7 @@ tests/cases/compiler/global.d.ts(6,16): error TS2403: Subsequent variable declar export const THREE: typeof _three; ~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'THREE' must be of type 'typeof import("tests/cases/compiler/global")', but here has type 'typeof import("tests/cases/compiler/three")'. +!!! related TS6203 tests/cases/compiler/global.d.ts:1:1: 'THREE' was also declared here. } ==== tests/cases/compiler/test.ts (0 errors) ==== diff --git a/tests/baselines/reference/classWithDuplicateIdentifier.errors.txt b/tests/baselines/reference/classWithDuplicateIdentifier.errors.txt index db48c48078cf7..60390e8a84354 100644 --- a/tests/baselines/reference/classWithDuplicateIdentifier.errors.txt +++ b/tests/baselines/reference/classWithDuplicateIdentifier.errors.txt @@ -14,6 +14,7 @@ tests/cases/compiler/classWithDuplicateIdentifier.ts(11,5): error TS2717: Subseq !!! error TS2300: Duplicate identifier 'a'. ~ !!! error TS2717: Subsequent property declarations must have the same type. Property 'a' must be of type '() => number', but here has type 'number'. +!!! related TS6203 tests/cases/compiler/classWithDuplicateIdentifier.ts:2:5: 'a' was also declared here. } class K { b: number; // error: duplicate identifier @@ -30,5 +31,6 @@ tests/cases/compiler/classWithDuplicateIdentifier.ts(11,5): error TS2717: Subseq !!! error TS2300: Duplicate identifier 'c'. ~ !!! error TS2717: Subsequent property declarations must have the same type. Property 'c' must be of type 'number', but here has type 'string'. +!!! related TS6203 tests/cases/compiler/classWithDuplicateIdentifier.ts:10:5: 'c' was also declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/conditionalTypes1.errors.txt b/tests/baselines/reference/conditionalTypes1.errors.txt index 7abcf55b8e7cb..45d3b1f99cb47 100644 --- a/tests/baselines/reference/conditionalTypes1.errors.txt +++ b/tests/baselines/reference/conditionalTypes1.errors.txt @@ -391,6 +391,7 @@ tests/cases/conformance/types/conditional/conditionalTypes1.ts(288,43): error TS var z: T2; // Error, T2 is distributive, T1 isn't ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'T1', but here has type 'Foo'. +!!! related TS6203 tests/cases/conformance/types/conditional/conditionalTypes1.ts:262:9: 'z' was also declared here. } function f33() { diff --git a/tests/baselines/reference/declarationsAndAssignments.errors.txt b/tests/baselines/reference/declarationsAndAssignments.errors.txt index 312a0ed626c1b..b13aacbfbc3fe 100644 --- a/tests/baselines/reference/declarationsAndAssignments.errors.txt +++ b/tests/baselines/reference/declarationsAndAssignments.errors.txt @@ -97,6 +97,7 @@ tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts(138,9): var y: string; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'string | number', but here has type 'string'. +!!! related TS6203 tests/cases/conformance/es6/destructuring/declarationsAndAssignments.ts:56:17: 'y' was also declared here. } function f8() { diff --git a/tests/baselines/reference/duplicateClassElements.errors.txt b/tests/baselines/reference/duplicateClassElements.errors.txt index 4ac9176776888..397ee4454590c 100644 --- a/tests/baselines/reference/duplicateClassElements.errors.txt +++ b/tests/baselines/reference/duplicateClassElements.errors.txt @@ -97,6 +97,7 @@ tests/cases/compiler/duplicateClassElements.ts(41,12): error TS2300: Duplicate i !!! error TS2300: Duplicate identifier 'x2'. ~~ !!! error TS2717: Subsequent property declarations must have the same type. Property 'x2' must be of type 'number', but here has type 'any'. +!!! related TS6203 tests/cases/compiler/duplicateClassElements.ts:29:9: 'x2' was also declared here. get z2() { ~~ diff --git a/tests/baselines/reference/duplicateIdentifierInCatchBlock.errors.txt b/tests/baselines/reference/duplicateIdentifierInCatchBlock.errors.txt index d8065df27c8a2..d2216efc6e653 100644 --- a/tests/baselines/reference/duplicateIdentifierInCatchBlock.errors.txt +++ b/tests/baselines/reference/duplicateIdentifierInCatchBlock.errors.txt @@ -38,4 +38,5 @@ tests/cases/compiler/duplicateIdentifierInCatchBlock.ts(16,9): error TS2403: Sub var p: number; // error ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'string', but here has type 'number'. +!!! related TS6203 tests/cases/compiler/duplicateIdentifierInCatchBlock.ts:15:9: 'p' was also declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/duplicateLocalVariable1.errors.txt b/tests/baselines/reference/duplicateLocalVariable1.errors.txt index 6f52156586203..a31ca844a868f 100644 --- a/tests/baselines/reference/duplicateLocalVariable1.errors.txt +++ b/tests/baselines/reference/duplicateLocalVariable1.errors.txt @@ -201,6 +201,7 @@ tests/cases/compiler/duplicateLocalVariable1.ts(186,37): error TS2356: An arithm for (var i = 0; i < 14; i++) { ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type 'string', but here has type 'number'. +!!! related TS6203 tests/cases/compiler/duplicateLocalVariable1.ts:181:22: 'i' was also declared here. ~~~~~~ !!! error TS2365: Operator '<' cannot be applied to types 'string' and 'number'. ~ diff --git a/tests/baselines/reference/duplicateLocalVariable2.errors.txt b/tests/baselines/reference/duplicateLocalVariable2.errors.txt index 0258e7e846073..f25de4a704710 100644 --- a/tests/baselines/reference/duplicateLocalVariable2.errors.txt +++ b/tests/baselines/reference/duplicateLocalVariable2.errors.txt @@ -33,6 +33,7 @@ tests/cases/compiler/duplicateLocalVariable2.ts(27,37): error TS2356: An arithme for (var i = 0; i < 14; i++) { ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type 'string', but here has type 'number'. +!!! related TS6203 tests/cases/compiler/duplicateLocalVariable2.ts:22:22: 'i' was also declared here. ~~~~~~ !!! error TS2365: Operator '<' cannot be applied to types 'string' and 'number'. ~ diff --git a/tests/baselines/reference/duplicateLocalVariable3.errors.txt b/tests/baselines/reference/duplicateLocalVariable3.errors.txt index 5dda5872da00f..2255776c75c2a 100644 --- a/tests/baselines/reference/duplicateLocalVariable3.errors.txt +++ b/tests/baselines/reference/duplicateLocalVariable3.errors.txt @@ -15,4 +15,5 @@ tests/cases/compiler/duplicateLocalVariable3.ts(11,9): error TS2403: Subsequent var z = ""; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'number', but here has type 'string'. +!!! related TS6203 tests/cases/compiler/duplicateLocalVariable3.ts:10:9: 'z' was also declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/duplicateLocalVariable4.errors.txt b/tests/baselines/reference/duplicateLocalVariable4.errors.txt index 3209c23e39efb..67da21962b1e4 100644 --- a/tests/baselines/reference/duplicateLocalVariable4.errors.txt +++ b/tests/baselines/reference/duplicateLocalVariable4.errors.txt @@ -9,4 +9,5 @@ tests/cases/compiler/duplicateLocalVariable4.ts(6,5): error TS2403: Subsequent v var x = E; var x = E.a; ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'typeof E', but here has type 'E'. \ No newline at end of file +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'typeof E', but here has type 'E'. +!!! related TS6203 tests/cases/compiler/duplicateLocalVariable4.ts:5:5: 'x' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/duplicateVariablesWithAny.errors.txt b/tests/baselines/reference/duplicateVariablesWithAny.errors.txt index 787e118ca373c..0d71fde12e274 100644 --- a/tests/baselines/reference/duplicateVariablesWithAny.errors.txt +++ b/tests/baselines/reference/duplicateVariablesWithAny.errors.txt @@ -10,22 +10,26 @@ tests/cases/compiler/duplicateVariablesWithAny.ts(13,9): error TS2403: Subsequen var x = 2; //error ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/compiler/duplicateVariablesWithAny.ts:2:5: 'x' was also declared here. var y = ""; var y; //error ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'string', but here has type 'any'. +!!! related TS6203 tests/cases/compiler/duplicateVariablesWithAny.ts:5:5: 'y' was also declared here. module N { var x: any; var x = 2; //error ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/compiler/duplicateVariablesWithAny.ts:9:9: 'x' was also declared here. var y = ""; var y; //error ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'string', but here has type 'any'. +!!! related TS6203 tests/cases/compiler/duplicateVariablesWithAny.ts:12:9: 'y' was also declared here. } var z: any; diff --git a/tests/baselines/reference/duplicateVarsAcrossFileBoundaries.errors.txt b/tests/baselines/reference/duplicateVarsAcrossFileBoundaries.errors.txt index d422248321284..2f5e9f0963428 100644 --- a/tests/baselines/reference/duplicateVarsAcrossFileBoundaries.errors.txt +++ b/tests/baselines/reference/duplicateVarsAcrossFileBoundaries.errors.txt @@ -12,18 +12,22 @@ tests/cases/compiler/duplicateVarsAcrossFileBoundaries_2.ts(3,5): error TS2403: var x = true; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'number', but here has type 'boolean'. +!!! related TS6203 tests/cases/compiler/duplicateVarsAcrossFileBoundaries_0.ts:1:5: 'x' was also declared here. var z = 3; ==== tests/cases/compiler/duplicateVarsAcrossFileBoundaries_2.ts (3 errors) ==== var x = ""; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'number', but here has type 'string'. +!!! related TS6203 tests/cases/compiler/duplicateVarsAcrossFileBoundaries_0.ts:1:5: 'x' was also declared here. var y = 3; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'string', but here has type 'number'. +!!! related TS6203 tests/cases/compiler/duplicateVarsAcrossFileBoundaries_0.ts:2:5: 'y' was also declared here. var z = false; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'z' must be of type 'number', but here has type 'boolean'. +!!! related TS6203 tests/cases/compiler/duplicateVarsAcrossFileBoundaries_1.ts:2:5: 'z' was also declared here. ==== tests/cases/compiler/duplicateVarsAcrossFileBoundaries_3.ts (0 errors) ==== var x = 0; diff --git a/tests/baselines/reference/dynamicNamesErrors.errors.txt b/tests/baselines/reference/dynamicNamesErrors.errors.txt index c39140dbd5257..43ca55db4ea83 100644 --- a/tests/baselines/reference/dynamicNamesErrors.errors.txt +++ b/tests/baselines/reference/dynamicNamesErrors.errors.txt @@ -35,6 +35,7 @@ tests/cases/compiler/dynamicNamesErrors.ts(25,1): error TS2322: Type 'T1' is not [c1]: string; ~~~~ !!! error TS2717: Subsequent property declarations must have the same type. Property '[c1]' must be of type 'number', but here has type 'string'. +!!! related TS6203 tests/cases/compiler/dynamicNamesErrors.ts:18:5: '[c1]' was also declared here. } let t1: T1; diff --git a/tests/baselines/reference/enumAssignabilityInInheritance.errors.txt b/tests/baselines/reference/enumAssignabilityInInheritance.errors.txt index e7c1297e1fd41..e76c053a0af36 100644 --- a/tests/baselines/reference/enumAssignabilityInInheritance.errors.txt +++ b/tests/baselines/reference/enumAssignabilityInInheritance.errors.txt @@ -109,10 +109,12 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/enumAssi var r4 = foo16(E.A); ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'r4' must be of type 'E', but here has type 'Object'. +!!! related TS6203 tests/cases/conformance/types/typeRelationships/assignmentCompatibility/enumAssignabilityInInheritance.ts:22:5: 'r4' was also declared here. declare function foo17(x: {}): {}; declare function foo17(x: E): E; var r4 = foo16(E.A); ~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'r4' must be of type 'E', but here has type 'Object'. \ No newline at end of file +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'r4' must be of type 'E', but here has type 'Object'. +!!! related TS6203 tests/cases/conformance/types/typeRelationships/assignmentCompatibility/enumAssignabilityInInheritance.ts:22:5: 'r4' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/for-inStatements.errors.txt b/tests/baselines/reference/for-inStatements.errors.txt index 50f31d669cd41..03e11ff11157b 100644 --- a/tests/baselines/reference/for-inStatements.errors.txt +++ b/tests/baselines/reference/for-inStatements.errors.txt @@ -39,6 +39,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(79,15): for (var x in this) { } ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. +!!! related TS6203 tests/cases/conformance/statements/for-inStatements/for-inStatements.ts:31:18: 'x' was also declared here. return null; } @@ -58,6 +59,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatements.ts(79,15): for (var x in this) { } ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. +!!! related TS6203 tests/cases/conformance/statements/for-inStatements/for-inStatements.ts:48:18: 'x' was also declared here. for (var x in super.biz) { } for (var x in super.biz()) { } diff --git a/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt b/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt index 3ba7a73367f8a..2eb08a8b1f3d2 100644 --- a/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt +++ b/tests/baselines/reference/for-inStatementsArrayErrors.errors.txt @@ -29,11 +29,13 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors. for (var i in a ) { ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type 'number', but here has type 'string'. +!!! related TS6203 tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts:11:5: 'i' was also declared here. } var j: any; for (var j in a ) { ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'j' must be of type 'any', but here has type 'string'. +!!! related TS6203 tests/cases/conformance/statements/for-inStatements/for-inStatementsArrayErrors.ts:15:5: 'j' was also declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/for-inStatementsInvalid.errors.txt b/tests/baselines/reference/for-inStatementsInvalid.errors.txt index 8e1bb29d0834a..e8e29b37c4eba 100644 --- a/tests/baselines/reference/for-inStatementsInvalid.errors.txt +++ b/tests/baselines/reference/for-inStatementsInvalid.errors.txt @@ -73,6 +73,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(6 for (var x in this) { } ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. +!!! related TS6203 tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts:29:18: 'x' was also declared here. return null; } @@ -96,6 +97,7 @@ tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts(6 for (var x in this) { } ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'Extract'. +!!! related TS6203 tests/cases/conformance/statements/for-inStatements/for-inStatementsInvalid.ts:46:18: 'x' was also declared here. for (var x in super.biz) { } for (var x in super.biz()) { } diff --git a/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt b/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt index 53ecb88363df4..f0de0ce954bac 100644 --- a/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt +++ b/tests/baselines/reference/forStatementsMultipleInvalidDecl.errors.txt @@ -47,46 +47,58 @@ tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDec for( var a = 1;;){} ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts:31:10: 'a' was also declared here. for( var a = 'a string';;){} ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a' must be of type 'any', but here has type 'string'. +!!! related TS6203 tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts:31:10: 'a' was also declared here. for( var a = new C();;){} ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a' must be of type 'any', but here has type 'C'. +!!! related TS6203 tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts:31:10: 'a' was also declared here. for( var a = new D();;){} ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a' must be of type 'any', but here has type 'D'. +!!! related TS6203 tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts:31:10: 'a' was also declared here. for( var a = M;;){} ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a' must be of type 'any', but here has type 'typeof M'. +!!! related TS6203 tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts:31:10: 'a' was also declared here. for( var b: I;;){} for( var b = new C();;){} ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'I', but here has type 'C'. +!!! related TS6203 tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts:38:10: 'b' was also declared here. for( var b = new C2();;){} ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'I', but here has type 'C2'. +!!! related TS6203 tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts:38:10: 'b' was also declared here. for(var f = F;;){} for( var f = (x: number) => '';;){} ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'f' must be of type '(x: string) => number', but here has type '(x: number) => string'. +!!! related TS6203 tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts:42:9: 'f' was also declared here. for(var arr: string[];;){} for( var arr = [1, 2, 3, 4];;){} ~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. +!!! related TS6203 tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts:45:9: 'arr' was also declared here. for( var arr = [new C(), new C2(), new D()];;){} ~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '(C | D)[]'. +!!! related TS6203 tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts:45:9: 'arr' was also declared here. for(var arr2 = [new D()];;){} for( var arr2 = new Array>();;){} ~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'D[]', but here has type 'D[]'. +!!! related TS6203 tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts:49:9: 'arr2' was also declared here. for(var m: typeof M;;){} for( var m = M.A;;){} ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'm' must be of type 'typeof M', but here has type 'typeof A'. \ No newline at end of file +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'm' must be of type 'typeof M', but here has type 'typeof A'. +!!! related TS6203 tests/cases/conformance/statements/forStatements/forStatementsMultipleInvalidDecl.ts:52:9: 'm' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/functionArgShadowing.errors.txt b/tests/baselines/reference/functionArgShadowing.errors.txt index 930221784526e..c3ba60a80cdfa 100644 --- a/tests/baselines/reference/functionArgShadowing.errors.txt +++ b/tests/baselines/reference/functionArgShadowing.errors.txt @@ -10,6 +10,7 @@ tests/cases/compiler/functionArgShadowing.ts(10,7): error TS2403: Subsequent var var x: B = new B(); ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'A', but here has type 'B'. +!!! related TS6203 tests/cases/compiler/functionArgShadowing.ts:3:14: 'x' was also declared here. x.bar(); // the property bar does not exist on a value of type A ~~~ !!! error TS2339: Property 'bar' does not exist on type 'A'. @@ -20,6 +21,7 @@ tests/cases/compiler/functionArgShadowing.ts(10,7): error TS2403: Subsequent var var p: string; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'number', but here has type 'string'. +!!! related TS6203 tests/cases/compiler/functionArgShadowing.ts:9:14: 'p' was also declared here. var n: number = p; } diff --git a/tests/baselines/reference/gettersAndSettersErrors.errors.txt b/tests/baselines/reference/gettersAndSettersErrors.errors.txt index e2a4bb3a146b8..013e195876e86 100644 --- a/tests/baselines/reference/gettersAndSettersErrors.errors.txt +++ b/tests/baselines/reference/gettersAndSettersErrors.errors.txt @@ -24,6 +24,7 @@ tests/cases/compiler/gettersAndSettersErrors.ts(12,16): error TS2379: Getter and !!! error TS2300: Duplicate identifier 'Foo'. ~~~ !!! error TS2717: Subsequent property declarations must have the same type. Property 'Foo' must be of type 'string', but here has type 'number'. +!!! related TS6203 tests/cases/compiler/gettersAndSettersErrors.ts:2:16: 'Foo' was also declared here. public get Goo(v:string):string {return null;} // error - getters must not have a parameter ~~~ !!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. diff --git a/tests/baselines/reference/identityForSignaturesWithTypeParametersAndAny.errors.txt b/tests/baselines/reference/identityForSignaturesWithTypeParametersAndAny.errors.txt index 6023928022699..092bfaaeeb3c9 100644 --- a/tests/baselines/reference/identityForSignaturesWithTypeParametersAndAny.errors.txt +++ b/tests/baselines/reference/identityForSignaturesWithTypeParametersAndAny.errors.txt @@ -12,18 +12,22 @@ tests/cases/compiler/identityForSignaturesWithTypeParametersAndAny.ts(14,5): err var g: (x: any, y: any) => any; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'g' must be of type '(x: T, y: U) => T', but here has type '(x: any, y: any) => any'. +!!! related TS6203 tests/cases/compiler/identityForSignaturesWithTypeParametersAndAny.ts:4:5: 'g' was also declared here. var h: (x: T, y: U) => T; var h: (x: any, y: any) => any; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'h' must be of type '(x: T, y: U) => T', but here has type '(x: any, y: any) => any'. +!!! related TS6203 tests/cases/compiler/identityForSignaturesWithTypeParametersAndAny.ts:7:5: 'h' was also declared here. var i: (x: T, y: U) => T; var i: (x: any, y: string) => any; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'i' must be of type '(x: T, y: U) => T', but here has type '(x: any, y: string) => any'. +!!! related TS6203 tests/cases/compiler/identityForSignaturesWithTypeParametersAndAny.ts:10:5: 'i' was also declared here. var j: (x: T, y: U) => T; var j: (x: any, y: any) => string; ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'j' must be of type '(x: T, y: U) => T', but here has type '(x: any, y: any) => string'. \ No newline at end of file +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'j' must be of type '(x: T, y: U) => T', but here has type '(x: any, y: any) => string'. +!!! related TS6203 tests/cases/compiler/identityForSignaturesWithTypeParametersAndAny.ts:13:5: 'j' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/interfaceDeclaration1.errors.txt b/tests/baselines/reference/interfaceDeclaration1.errors.txt index 64410b44c551a..b4c41ca350ee5 100644 --- a/tests/baselines/reference/interfaceDeclaration1.errors.txt +++ b/tests/baselines/reference/interfaceDeclaration1.errors.txt @@ -30,6 +30,7 @@ tests/cases/compiler/interfaceDeclaration1.ts(52,11): error TS2320: Interface 'i !!! error TS2300: Duplicate identifier 'item'. ~~~~ !!! error TS2717: Subsequent property declarations must have the same type. Property 'item' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/compiler/interfaceDeclaration1.ts:7:5: 'item' was also declared here. } interface I3 { diff --git a/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt b/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt index 3ec718f3b25fe..a43b9b0c27184 100644 --- a/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt +++ b/tests/baselines/reference/invalidMultipleVariableDeclarations.errors.txt @@ -47,46 +47,58 @@ tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDec var a = 1; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts:31:5: 'a' was also declared here. var a = 'a string'; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a' must be of type 'any', but here has type 'string'. +!!! related TS6203 tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts:31:5: 'a' was also declared here. var a = new C(); ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a' must be of type 'any', but here has type 'C'. +!!! related TS6203 tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts:31:5: 'a' was also declared here. var a = new D(); ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a' must be of type 'any', but here has type 'D'. +!!! related TS6203 tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts:31:5: 'a' was also declared here. var a = M; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a' must be of type 'any', but here has type 'typeof M'. +!!! related TS6203 tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts:31:5: 'a' was also declared here. var b: I; var b = new C(); ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'I', but here has type 'C'. +!!! related TS6203 tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts:38:5: 'b' was also declared here. var b = new C2(); ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'I', but here has type 'C2'. +!!! related TS6203 tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts:38:5: 'b' was also declared here. var f = F; var f = (x: number) => ''; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'f' must be of type '(x: string) => number', but here has type '(x: number) => string'. +!!! related TS6203 tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts:42:5: 'f' was also declared here. var arr: string[]; var arr = [1, 2, 3, 4]; ~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type 'number[]'. +!!! related TS6203 tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts:45:5: 'arr' was also declared here. var arr = [new C(), new C2(), new D()]; ~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr' must be of type 'string[]', but here has type '(C | D)[]'. +!!! related TS6203 tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts:45:5: 'arr' was also declared here. var arr2 = [new D()]; var arr2 = new Array>(); ~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'arr2' must be of type 'D[]', but here has type 'D[]'. +!!! related TS6203 tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts:49:5: 'arr2' was also declared here. var m: typeof M; var m = M.A; ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'm' must be of type 'typeof M', but here has type 'typeof A'. \ No newline at end of file +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'm' must be of type 'typeof M', but here has type 'typeof A'. +!!! related TS6203 tests/cases/conformance/statements/VariableStatements/invalidMultipleVariableDeclarations.ts:52:5: 'm' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.errors.txt b/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.errors.txt index f1374d957673f..9e46d6225a2c8 100644 --- a/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.errors.txt +++ b/tests/baselines/reference/jsFileCompilationDuplicateVariableErrorReported.errors.txt @@ -9,4 +9,5 @@ tests/cases/compiler/a.ts(1,5): error TS2403: Subsequent variable declarations m ==== tests/cases/compiler/a.ts (1 errors) ==== var x = 10; // Error reported so no declaration file generated? ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'number'. \ No newline at end of file +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'string', but here has type 'number'. +!!! related TS6203 tests/cases/compiler/b.js:1:5: 'x' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/mappedTypeErrors.errors.txt b/tests/baselines/reference/mappedTypeErrors.errors.txt index 254d1cca1a89a..0dc68732e81a2 100644 --- a/tests/baselines/reference/mappedTypeErrors.errors.txt +++ b/tests/baselines/reference/mappedTypeErrors.errors.txt @@ -133,12 +133,15 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(152,17): error TS2339: var x: { [P in keyof T]?: T[P] }; // Error ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type '{ [P in keyof T]: T[P]; }', but here has type '{ [P in keyof T]?: T[P] | undefined; }'. +!!! related TS6203 tests/cases/conformance/types/mapped/mappedTypeErrors.ts:58:9: 'x' was also declared here. var x: { readonly [P in keyof T]: T[P] }; // Error ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type '{ [P in keyof T]: T[P]; }', but here has type '{ readonly [P in keyof T]: T[P]; }'. +!!! related TS6203 tests/cases/conformance/types/mapped/mappedTypeErrors.ts:58:9: 'x' was also declared here. var x: { readonly [P in keyof T]?: T[P] }; // Error ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type '{ [P in keyof T]: T[P]; }', but here has type '{ readonly [P in keyof T]?: T[P] | undefined; }'. +!!! related TS6203 tests/cases/conformance/types/mapped/mappedTypeErrors.ts:58:9: 'x' was also declared here. } function f12() { @@ -146,6 +149,7 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(152,17): error TS2339: var x: { [P in keyof T]: T[P][] }; // Error ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type '{ [P in keyof T]: T[P]; }', but here has type '{ [P in keyof T]: T[P][]; }'. +!!! related TS6203 tests/cases/conformance/types/mapped/mappedTypeErrors.ts:65:9: 'x' was also declared here. } // Check that inferences to mapped types are secondary diff --git a/tests/baselines/reference/mergedInterfacesWithConflictingPropertyNames.errors.txt b/tests/baselines/reference/mergedInterfacesWithConflictingPropertyNames.errors.txt index 523cad05465d4..6bb0e02f4eb66 100644 --- a/tests/baselines/reference/mergedInterfacesWithConflictingPropertyNames.errors.txt +++ b/tests/baselines/reference/mergedInterfacesWithConflictingPropertyNames.errors.txt @@ -12,6 +12,7 @@ tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConfli x: number; ~ !!! error TS2717: Subsequent property declarations must have the same type. Property 'x' must be of type 'string', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConflictingPropertyNames.ts:2:5: 'x' was also declared here. } module M { @@ -23,6 +24,7 @@ tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConfli x: number; // error ~ !!! error TS2717: Subsequent property declarations must have the same type. Property 'x' must be of type 'T', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConflictingPropertyNames.ts:11:9: 'x' was also declared here. } } @@ -49,5 +51,6 @@ tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConfli x: number; // error ~ !!! error TS2717: Subsequent property declarations must have the same type. Property 'x' must be of type 'T', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithConflictingPropertyNames.ts:33:9: 'x' was also declared here. } } \ No newline at end of file diff --git a/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.errors.txt b/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.errors.txt index 99fd038bbb9e9..edb66f56dd347 100644 --- a/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.errors.txt +++ b/tests/baselines/reference/methodSignatureHandledDeclarationKindForSymbol.errors.txt @@ -10,6 +10,7 @@ tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts(6,5): err bold: string; ~~~~ !!! error TS2717: Subsequent property declarations must have the same type. Property 'bold' must be of type '() => string', but here has type 'string'. +!!! related TS6203 tests/cases/compiler/methodSignatureHandledDeclarationKindForSymbol.ts:2:5: 'bold' was also declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/missingAndExcessProperties.errors.txt b/tests/baselines/reference/missingAndExcessProperties.errors.txt index 0ee69d9af306c..7972d770320e6 100644 --- a/tests/baselines/reference/missingAndExcessProperties.errors.txt +++ b/tests/baselines/reference/missingAndExcessProperties.errors.txt @@ -31,6 +31,7 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): var { x = 1, y } = {}; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts:3:11: 'x' was also declared here. ~ !!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. var { x, y = 1 } = {}; @@ -38,11 +39,14 @@ tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts(31,16): !!! error TS2525: Initializer provides no value for this binding element and the binding element has no default value. ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts:3:14: 'y' was also declared here. var { x = 1, y = 1 } = {}; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts:3:11: 'x' was also declared here. ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/es6/destructuring/missingAndExcessProperties.ts:3:14: 'y' was also declared here. } // Missing properties diff --git a/tests/baselines/reference/negateOperatorInvalidOperations.errors.txt b/tests/baselines/reference/negateOperatorInvalidOperations.errors.txt index 105a1af9efe0b..0792565f063ed 100644 --- a/tests/baselines/reference/negateOperatorInvalidOperations.errors.txt +++ b/tests/baselines/reference/negateOperatorInvalidOperations.errors.txt @@ -44,5 +44,6 @@ tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperator var NUMBER =-; ~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'NUMBER' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/expressions/unaryOperators/negateOperator/negateOperatorInvalidOperations.ts:4:19: 'NUMBER' was also declared here. ~ !!! error TS1109: Expression expected. \ No newline at end of file diff --git a/tests/baselines/reference/numericStringNamedPropertyEquivalence.errors.txt b/tests/baselines/reference/numericStringNamedPropertyEquivalence.errors.txt index 8f0a27e03d97d..7d3ff163300d5 100644 --- a/tests/baselines/reference/numericStringNamedPropertyEquivalence.errors.txt +++ b/tests/baselines/reference/numericStringNamedPropertyEquivalence.errors.txt @@ -37,6 +37,7 @@ tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericString !!! error TS2300: Duplicate identifier '1'. ~~~ !!! error TS2717: Subsequent property declarations must have the same type. Property '1.0' must be of type 'number', but here has type 'string'. +!!! related TS6203 tests/cases/conformance/types/objectTypeLiteral/propertySignatures/numericStringNamedPropertyEquivalence.ts:16:5: '1.0' was also declared here. } var b = { diff --git a/tests/baselines/reference/objectLiteralContextualTyping.errors.txt b/tests/baselines/reference/objectLiteralContextualTyping.errors.txt index b73b7b43a89c9..2ff2a7287f8f9 100644 --- a/tests/baselines/reference/objectLiteralContextualTyping.errors.txt +++ b/tests/baselines/reference/objectLiteralContextualTyping.errors.txt @@ -33,4 +33,5 @@ tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTypi var b: {}; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'b' must be of type 'unknown', but here has type '{}'. +!!! related TS6203 tests/cases/conformance/expressions/contextualTyping/objectLiteralContextualTyping.ts:28:5: 'b' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/objectRest.errors.txt b/tests/baselines/reference/objectRest.errors.txt index 02f64fbd4e21b..f6fd179d28d3a 100644 --- a/tests/baselines/reference/objectRest.errors.txt +++ b/tests/baselines/reference/objectRest.errors.txt @@ -62,6 +62,7 @@ tests/cases/conformance/types/rest/objectRest.ts(44,53): error TS2739: Type '{}' !!! error TS2537: Type '{ a: number; b: string; }' has no matching index signature for type 'string'. ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'o' must be of type '{ a: number; b: string; }', but here has type '{}'. +!!! related TS6203 tests/cases/conformance/types/rest/objectRest.ts:1:5: 'o' was also declared here. ({ [computed]: stillNotGreat, [computed2]: soSo, ...o } = o); ~~~~~~~~ !!! error TS2537: Type '{ a: number; b: string; }' has no matching index signature for type 'string'. diff --git a/tests/baselines/reference/optionalParamterAndVariableDeclaration2.errors.txt b/tests/baselines/reference/optionalParamterAndVariableDeclaration2.errors.txt index 982318d2f2548..df38f7d20515b 100644 --- a/tests/baselines/reference/optionalParamterAndVariableDeclaration2.errors.txt +++ b/tests/baselines/reference/optionalParamterAndVariableDeclaration2.errors.txt @@ -7,6 +7,7 @@ tests/cases/compiler/optionalParamterAndVariableDeclaration2.ts(3,13): error TS2 var options = (options || 0); ~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'options' must be of type 'number | undefined', but here has type 'number'. +!!! related TS6203 tests/cases/compiler/optionalParamterAndVariableDeclaration2.ts:2:17: 'options' was also declared here. } } \ No newline at end of file diff --git a/tests/baselines/reference/orderMattersForSignatureGroupIdentity.errors.txt b/tests/baselines/reference/orderMattersForSignatureGroupIdentity.errors.txt index f108f0ea92da0..fc8d68f1af8ee 100644 --- a/tests/baselines/reference/orderMattersForSignatureGroupIdentity.errors.txt +++ b/tests/baselines/reference/orderMattersForSignatureGroupIdentity.errors.txt @@ -33,6 +33,7 @@ tests/cases/compiler/orderMattersForSignatureGroupIdentity.ts(24,5): error TS234 var w: C; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'w' must be of type 'A', but here has type 'C'. +!!! related TS6203 tests/cases/compiler/orderMattersForSignatureGroupIdentity.ts:21:5: 'w' was also declared here. w({ s: "", n: 0 }).toLowerCase(); ~~~~~ diff --git a/tests/baselines/reference/overloadResolution.errors.txt b/tests/baselines/reference/overloadResolution.errors.txt index 27d0392ca8dbc..fde241d62cc51 100644 --- a/tests/baselines/reference/overloadResolution.errors.txt +++ b/tests/baselines/reference/overloadResolution.errors.txt @@ -120,6 +120,7 @@ tests/cases/conformance/expressions/functionCalls/overloadResolution.ts(91,22): var n = fn5((n) => n.toFixed()); ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'n' must be of type 'number', but here has type 'string'. +!!! related TS6203 tests/cases/conformance/expressions/functionCalls/overloadResolution.ts:54:5: 'n' was also declared here. ~~~~~~~ !!! error TS2339: Property 'toFixed' does not exist on type 'string'. var s = fn5((n) => n.substr(0)); diff --git a/tests/baselines/reference/overloadResolutionConstructors.errors.txt b/tests/baselines/reference/overloadResolutionConstructors.errors.txt index 2e09a84d13818..40b660c7eafab 100644 --- a/tests/baselines/reference/overloadResolutionConstructors.errors.txt +++ b/tests/baselines/reference/overloadResolutionConstructors.errors.txt @@ -129,6 +129,7 @@ tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors var n = new fn5((n) => n.toFixed()); ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'n' must be of type 'number', but here has type 'string'. +!!! related TS6203 tests/cases/conformance/expressions/functionCalls/overloadResolutionConstructors.ts:58:5: 'n' was also declared here. ~~~~~~~ !!! error TS2339: Property 'toFixed' does not exist on type 'string'. var s = new fn5((n) => n.substr(0)); diff --git a/tests/baselines/reference/parserCastVersusArrowFunction1.errors.txt b/tests/baselines/reference/parserCastVersusArrowFunction1.errors.txt index e2d90538b8c49..9a34f75ce401c 100644 --- a/tests/baselines/reference/parserCastVersusArrowFunction1.errors.txt +++ b/tests/baselines/reference/parserCastVersusArrowFunction1.errors.txt @@ -25,12 +25,15 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserCastVersusArrowFunctio var v = (a) => 1; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'v' must be of type '() => number', but here has type '(a: any) => number'. +!!! related TS6203 tests/cases/conformance/parser/ecmascript5/Generics/parserCastVersusArrowFunction1.ts:1:5: 'v' was also declared here. var v = (a, b) => 1; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'v' must be of type '() => number', but here has type '(a: any, b: any) => number'. +!!! related TS6203 tests/cases/conformance/parser/ecmascript5/Generics/parserCastVersusArrowFunction1.ts:1:5: 'v' was also declared here. var v = (a = 1, b = 2) => 1; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'v' must be of type '() => number', but here has type '(a?: number, b?: number) => number'. +!!! related TS6203 tests/cases/conformance/parser/ecmascript5/Generics/parserCastVersusArrowFunction1.ts:1:5: 'v' was also declared here. var v = (a); ~ diff --git a/tests/baselines/reference/promiseIdentity2.errors.txt b/tests/baselines/reference/promiseIdentity2.errors.txt index edfba2f42bcd4..0b5ba8d0ff0d9 100644 --- a/tests/baselines/reference/promiseIdentity2.errors.txt +++ b/tests/baselines/reference/promiseIdentity2.errors.txt @@ -14,4 +14,5 @@ tests/cases/compiler/promiseIdentity2.ts(11,5): error TS2403: Subsequent variabl var x: IPromise; var x: Promise; ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'IPromise', but here has type 'Promise'. \ No newline at end of file +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'IPromise', but here has type 'Promise'. +!!! related TS6203 tests/cases/compiler/promiseIdentity2.ts:10:5: 'x' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/promiseIdentityWithAny2.errors.txt b/tests/baselines/reference/promiseIdentityWithAny2.errors.txt index 9d01438b88c49..bedb948b078f2 100644 --- a/tests/baselines/reference/promiseIdentityWithAny2.errors.txt +++ b/tests/baselines/reference/promiseIdentityWithAny2.errors.txt @@ -15,6 +15,7 @@ tests/cases/compiler/promiseIdentityWithAny2.ts(22,5): error TS2403: Subsequent var x: Promise; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'IPromise', but here has type 'Promise'. +!!! related TS6203 tests/cases/compiler/promiseIdentityWithAny2.ts:9:5: 'x' was also declared here. interface IPromise2 { @@ -28,4 +29,5 @@ tests/cases/compiler/promiseIdentityWithAny2.ts(22,5): error TS2403: Subsequent var y: IPromise2; var y: Promise2; ~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'IPromise2', but here has type 'Promise2'. \ No newline at end of file +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'IPromise2', but here has type 'Promise2'. +!!! related TS6203 tests/cases/compiler/promiseIdentityWithAny2.ts:21:5: 'y' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/propertyAccess.errors.txt b/tests/baselines/reference/propertyAccess.errors.txt index a183ad79c1129..1351a46e099f4 100644 --- a/tests/baselines/reference/propertyAccess.errors.txt +++ b/tests/baselines/reference/propertyAccess.errors.txt @@ -170,4 +170,5 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts(149,5): err var x3: A; ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x3' must be of type 'A | B', but here has type 'A'. +!!! related TS6203 tests/cases/conformance/expressions/propertyAccess/propertyAccess.ts:148:5: 'x3' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/propertyIdentityWithPrivacyMismatch.errors.txt b/tests/baselines/reference/propertyIdentityWithPrivacyMismatch.errors.txt index 4c5644f6b767d..f2ac54f6e7c1c 100644 --- a/tests/baselines/reference/propertyIdentityWithPrivacyMismatch.errors.txt +++ b/tests/baselines/reference/propertyIdentityWithPrivacyMismatch.errors.txt @@ -10,6 +10,7 @@ tests/cases/compiler/propertyIdentityWithPrivacyMismatch_1.ts(13,5): error TS240 var x: m2.Foo; // Should be error (mod1.Foo !== mod2.Foo) ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'Foo', but here has type 'Foo'. +!!! related TS6203 tests/cases/compiler/propertyIdentityWithPrivacyMismatch_1.ts:4:5: 'x' was also declared here. class Foo1 { private n; } @@ -20,6 +21,7 @@ tests/cases/compiler/propertyIdentityWithPrivacyMismatch_1.ts(13,5): error TS240 var y: Foo2; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'Foo1', but here has type 'Foo2'. +!!! related TS6203 tests/cases/compiler/propertyIdentityWithPrivacyMismatch_1.ts:12:5: 'y' was also declared here. ==== tests/cases/compiler/propertyIdentityWithPrivacyMismatch_0.ts (0 errors) ==== declare module 'mod1' { class Foo { diff --git a/tests/baselines/reference/reassignStaticProp.errors.txt b/tests/baselines/reference/reassignStaticProp.errors.txt index b1bfb869d6889..bd62f1aa80dfb 100644 --- a/tests/baselines/reference/reassignStaticProp.errors.txt +++ b/tests/baselines/reference/reassignStaticProp.errors.txt @@ -12,6 +12,7 @@ tests/cases/compiler/reassignStaticProp.ts(5,12): error TS2717: Subsequent prope !!! error TS2300: Duplicate identifier 'bar'. ~~~ !!! error TS2717: Subsequent property declarations must have the same type. Property 'bar' must be of type 'number', but here has type 'string'. +!!! related TS6203 tests/cases/compiler/reassignStaticProp.ts:3:12: 'bar' was also declared here. } diff --git a/tests/baselines/reference/spreadUnion2.errors.txt b/tests/baselines/reference/spreadUnion2.errors.txt index 0115c4499301b..f2c1bc757783e 100644 --- a/tests/baselines/reference/spreadUnion2.errors.txt +++ b/tests/baselines/reference/spreadUnion2.errors.txt @@ -14,28 +14,34 @@ tests/cases/conformance/types/spread/spreadUnion2.ts(18,5): error TS2403: Subseq var o1 = { ...undefinedUnion }; ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'o1' must be of type '{} | { a: number; }', but here has type '{}'. +!!! related TS6203 tests/cases/conformance/types/spread/spreadUnion2.ts:4:5: 'o1' was also declared here. var o2: {} | { b: number }; var o2 = { ...nullUnion }; ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'o2' must be of type '{} | { b: number; }', but here has type '{}'. +!!! related TS6203 tests/cases/conformance/types/spread/spreadUnion2.ts:7:5: 'o2' was also declared here. var o3: {} | { a: number } | { b: number } | { a: number, b: number }; var o3 = { ...undefinedUnion, ...nullUnion }; ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'o3' must be of type '{} | { a: number; } | { b: number; } | { a: number; b: number; }', but here has type '{}'. +!!! related TS6203 tests/cases/conformance/types/spread/spreadUnion2.ts:10:5: 'o3' was also declared here. var o3 = { ...nullUnion, ...undefinedUnion }; ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'o3' must be of type '{} | { a: number; } | { b: number; } | { a: number; b: number; }', but here has type '{}'. +!!! related TS6203 tests/cases/conformance/types/spread/spreadUnion2.ts:10:5: 'o3' was also declared here. var o4: {} | { a: number }; var o4 = { ...undefinedUnion, ...undefinedUnion }; ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'o4' must be of type '{} | { a: number; }', but here has type '{}'. +!!! related TS6203 tests/cases/conformance/types/spread/spreadUnion2.ts:14:5: 'o4' was also declared here. var o5: {} | { b: number }; var o5 = { ...nullUnion, ...nullUnion }; ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'o5' must be of type '{} | { b: number; }', but here has type '{}'. +!!! related TS6203 tests/cases/conformance/types/spread/spreadUnion2.ts:17:5: 'o5' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/strictTupleLength.errors.txt b/tests/baselines/reference/strictTupleLength.errors.txt index 933c6e4dcdb20..78cf7b47e97ae 100644 --- a/tests/baselines/reference/strictTupleLength.errors.txt +++ b/tests/baselines/reference/strictTupleLength.errors.txt @@ -17,9 +17,11 @@ tests/cases/conformance/types/tuple/strictTupleLength.ts(18,1): error TS2741: Pr var t1 = t2; // error ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 't1' must be of type '[number]', but here has type '[number, number]'. +!!! related TS6203 tests/cases/conformance/types/tuple/strictTupleLength.ts:2:5: 't1' was also declared here. var t2 = t1; // error ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 't2' must be of type '[number, number]', but here has type '[number]'. +!!! related TS6203 tests/cases/conformance/types/tuple/strictTupleLength.ts:3:5: 't2' was also declared here. type A = T['length']; var b: A<[boolean]>; diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt index b7018031a69a1..c678337cfc9f1 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInference.errors.txt @@ -83,6 +83,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference var a9e: {}; ~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a9e' must be of type '{ x: number; z: Date; y?: undefined; } | { x: number; y: string; z?: undefined; }', but here has type '{}'. +!!! related TS6203 tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference.ts:75:5: 'a9e' was also declared here. // Generic tag with multiple parameters of generic type passed arguments with a single best common type var a9d = someGenerics9 `${ { x: 3 }}${ { x: 6 }}${ { x: 6 } }`; diff --git a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt index ae63e6fd04df0..e03b06d72e027 100644 --- a/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt +++ b/tests/baselines/reference/taggedTemplateStringsTypeArgumentInferenceES6.errors.txt @@ -83,6 +83,7 @@ tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInference var a9e: {}; ~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a9e' must be of type '{ x: number; z: Date; y?: undefined; } | { x: number; y: string; z?: undefined; }', but here has type '{}'. +!!! related TS6203 tests/cases/conformance/es6/templates/taggedTemplateStringsTypeArgumentInferenceES6.ts:75:5: 'a9e' was also declared here. // Generic tag with multiple parameters of generic type passed arguments with a single best common type var a9d = someGenerics9 `${ { x: 3 }}${ { x: 6 }}${ { x: 6 } }`; diff --git a/tests/baselines/reference/tupleTypes.errors.txt b/tests/baselines/reference/tupleTypes.errors.txt index 1cf2f113d1470..af76c872a6f38 100644 --- a/tests/baselines/reference/tupleTypes.errors.txt +++ b/tests/baselines/reference/tupleTypes.errors.txt @@ -39,6 +39,7 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n var t2: number|string; ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 't2' must be of type 'undefined', but here has type 'string | number'. +!!! related TS6203 tests/cases/compiler/tupleTypes.ts:11:5: 't2' was also declared here. t = []; // Error ~ @@ -79,6 +80,7 @@ tests/cases/compiler/tupleTypes.ts(51,1): error TS2322: Type '[number, {}]' is n var tt2: number | string; ~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'tt2' must be of type 'undefined', but here has type 'string | number'. +!!! related TS6203 tests/cases/compiler/tupleTypes.ts:35:5: 'tt2' was also declared here. tt = tuple2(1, undefined); tt = [1, undefined]; diff --git a/tests/baselines/reference/typeArgumentInference.errors.txt b/tests/baselines/reference/typeArgumentInference.errors.txt index 95e47ab583f22..fd4bd90771e80 100644 --- a/tests/baselines/reference/typeArgumentInference.errors.txt +++ b/tests/baselines/reference/typeArgumentInference.errors.txt @@ -92,6 +92,7 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts(84,74 var a9e: {}; ~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a9e' must be of type '{ x: number; z: Date; y?: undefined; } | { x: number; y: string; z?: undefined; }', but here has type '{}'. +!!! related TS6203 tests/cases/conformance/expressions/functionCalls/typeArgumentInference.ts:82:5: 'a9e' was also declared here. var a9f = someGenerics9(undefined, { x: 6, z: new Date() }, { x: 6, y: '' }); ~~~~~ !!! error TS2345: Argument of type '{ x: number; y: string; }' is not assignable to parameter of type 'A92'. diff --git a/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt b/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt index 8707ff26ef052..e40f121048757 100644 --- a/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceConstructSignatures.errors.txt @@ -154,6 +154,7 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstruct var a9e: {}; ~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a9e' must be of type '{ x: number; z: Window; y?: undefined; } | { x: number; y: string; z?: undefined; }', but here has type '{}'. +!!! related TS6203 tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceConstructSignatures.ts:120:5: 'a9e' was also declared here. var a9f = new someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' }); ~~~~~ !!! error TS2345: Argument of type '{ x: number; y: string; }' is not assignable to parameter of type 'A92'. diff --git a/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt b/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt index 3b7750f23f009..e07a0be74cb72 100644 --- a/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt +++ b/tests/baselines/reference/typeArgumentInferenceWithConstraints.errors.txt @@ -140,6 +140,7 @@ tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConst var a9e: {}; ~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a9e' must be of type '{ x: number; z: Window; y?: undefined; } | { x: number; y: string; z?: undefined; }', but here has type '{}'. +!!! related TS6203 tests/cases/conformance/expressions/functionCalls/typeArgumentInferenceWithConstraints.ts:87:5: 'a9e' was also declared here. var a9f = someGenerics9(undefined, { x: 6, z: window }, { x: 6, y: '' }); ~~~~~ !!! error TS2345: Argument of type '{ x: number; y: string; }' is not assignable to parameter of type 'A92'. diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfEqualEqualHasNoEffect.errors.txt b/tests/baselines/reference/typeGuardOfFormTypeOfEqualEqualHasNoEffect.errors.txt index e10cf2d1a78f5..52c312ae7c08e 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfEqualEqualHasNoEffect.errors.txt +++ b/tests/baselines/reference/typeGuardOfFormTypeOfEqualEqualHasNoEffect.errors.txt @@ -21,6 +21,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfEqualEqualHa var r1 = strOrNum; // string | number ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'r1' must be of type 'string', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfEqualEqualHasNoEffect.ts:10:9: 'r1' was also declared here. } if (typeof strOrBool == "boolean") { @@ -30,6 +31,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfEqualEqualHa var r2 = strOrBool; // string | boolean ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'r2' must be of type 'boolean', but here has type 'string'. +!!! related TS6203 tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfEqualEqualHasNoEffect.ts:17:9: 'r2' was also declared here. } if (typeof numOrBool == "number") { @@ -39,6 +41,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfEqualEqualHa var r3 = numOrBool; // number | boolean ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'r3' must be of type 'number', but here has type 'boolean'. +!!! related TS6203 tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfEqualEqualHasNoEffect.ts:24:9: 'r3' was also declared here. } if (typeof strOrC == "Object") { @@ -50,4 +53,5 @@ tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfEqualEqualHa var r4 = strOrC; // string | C ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'r4' must be of type 'C', but here has type 'string'. +!!! related TS6203 tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfEqualEqualHasNoEffect.ts:31:9: 'r4' was also declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/typeGuardOfFormTypeOfNotEqualHasNoEffect.errors.txt b/tests/baselines/reference/typeGuardOfFormTypeOfNotEqualHasNoEffect.errors.txt index a0e9cd0f7bf00..46b10e75b87b1 100644 --- a/tests/baselines/reference/typeGuardOfFormTypeOfNotEqualHasNoEffect.errors.txt +++ b/tests/baselines/reference/typeGuardOfFormTypeOfNotEqualHasNoEffect.errors.txt @@ -21,6 +21,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfNotEqualHasN var r1 = strOrNum; // string | number ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'r1' must be of type 'number', but here has type 'string'. +!!! related TS6203 tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfNotEqualHasNoEffect.ts:10:9: 'r1' was also declared here. } if (typeof strOrBool != "boolean") { @@ -30,6 +31,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfNotEqualHasN var r2 = strOrBool; // string | boolean ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'r2' must be of type 'string', but here has type 'boolean'. +!!! related TS6203 tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfNotEqualHasNoEffect.ts:17:9: 'r2' was also declared here. } if (typeof numOrBool != "number") { @@ -39,6 +41,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfNotEqualHasN var r3 = numOrBool; // number | boolean ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'r3' must be of type 'boolean', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfNotEqualHasNoEffect.ts:24:9: 'r3' was also declared here. } if (typeof strOrC != "Object") { @@ -50,4 +53,5 @@ tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfNotEqualHasN var r4 = strOrC; // string | C ~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'r4' must be of type 'string', but here has type 'C'. +!!! related TS6203 tests/cases/conformance/expressions/typeGuards/typeGuardOfFormTypeOfNotEqualHasNoEffect.ts:31:9: 'r4' was also declared here. } \ No newline at end of file diff --git a/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt b/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt index 89849d3a614a8..4303512121264 100644 --- a/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt +++ b/tests/baselines/reference/typeOfEnumAndVarRedeclarations.errors.txt @@ -14,9 +14,11 @@ tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts(10,70): error TS2375: Dup var x: { readonly a: E; readonly b: E; readonly [x: number]: string; }; // Shouldnt error ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'typeof E', but here has type '{ readonly [x: number]: string; readonly a: E; readonly b: E; }'. +!!! related TS6203 tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts:7:5: 'x' was also declared here. var y = E; var y: { readonly a: E; readonly b: E; readonly [x: number]: string; readonly [x: number]: string } // two errors: the types are not identical and duplicate signatures ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'y' must be of type 'typeof E', but here has type '{ readonly [x: number]: string; readonly a: E; readonly b: E; }'. +!!! related TS6203 tests/cases/compiler/typeOfEnumAndVarRedeclarations.ts:9:5: 'y' was also declared here. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ !!! error TS2375: Duplicate number index signature. \ No newline at end of file diff --git a/tests/baselines/reference/typeOfThis.errors.txt b/tests/baselines/reference/typeOfThis.errors.txt index b47207670cc62..adba7ba2f9f14 100644 --- a/tests/baselines/reference/typeOfThis.errors.txt +++ b/tests/baselines/reference/typeOfThis.errors.txt @@ -27,12 +27,14 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(106,13): error TS2 var t: MyTestClass; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type 'this', but here has type 'MyTestClass'. +!!! related TS6203 tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts:13:16: 't' was also declared here. //type of 'this' in member function body is the class instance type var p = this; var p: MyTestClass; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyTestClass'. +!!! related TS6203 tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts:17:13: 'p' was also declared here. } //type of 'this' in member accessor(get and set) body is the class instance type @@ -41,6 +43,7 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(106,13): error TS2 var p: MyTestClass; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyTestClass'. +!!! related TS6203 tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts:23:13: 'p' was also declared here. return this; } set prop(v) { @@ -48,6 +51,7 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(106,13): error TS2 var p: MyTestClass; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyTestClass'. +!!! related TS6203 tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts:28:13: 'p' was also declared here. p = v; v = p; } @@ -58,6 +62,7 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(106,13): error TS2 var t: MyTestClass; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type 'this', but here has type 'MyTestClass'. +!!! related TS6203 tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts:36:13: 't' was also declared here. }; //type of 'this' in static function param list is constructor function type @@ -106,12 +111,14 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(106,13): error TS2 var t: MyGenericTestClass; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type 'this', but here has type 'MyGenericTestClass'. +!!! related TS6203 tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts:82:16: 't' was also declared here. //type of 'this' in member function body is the class instance type var p = this; var p: MyGenericTestClass; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyGenericTestClass'. +!!! related TS6203 tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts:86:13: 'p' was also declared here. } //type of 'this' in member accessor(get and set) body is the class instance type @@ -120,6 +127,7 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(106,13): error TS2 var p: MyGenericTestClass; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyGenericTestClass'. +!!! related TS6203 tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts:92:13: 'p' was also declared here. return this; } set prop(v) { @@ -127,6 +135,7 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(106,13): error TS2 var p: MyGenericTestClass; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyGenericTestClass'. +!!! related TS6203 tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts:97:13: 'p' was also declared here. p = v; v = p; } @@ -137,6 +146,7 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(106,13): error TS2 var t: MyGenericTestClass; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type 'this', but here has type 'MyGenericTestClass'. +!!! related TS6203 tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts:105:13: 't' was also declared here. }; //type of 'this' in static function param list is constructor function type diff --git a/tests/baselines/reference/unionTypeEquivalence.errors.txt b/tests/baselines/reference/unionTypeEquivalence.errors.txt index d561a96f97e1d..3a50459e925a3 100644 --- a/tests/baselines/reference/unionTypeEquivalence.errors.txt +++ b/tests/baselines/reference/unionTypeEquivalence.errors.txt @@ -9,6 +9,7 @@ tests/cases/conformance/types/union/unionTypeEquivalence.ts(5,5): error TS2403: var x : C | D; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'x' must be of type 'C', but here has type 'C | D'. +!!! related TS6203 tests/cases/conformance/types/union/unionTypeEquivalence.ts:4:5: 'x' was also declared here. // A | B is equivalent to B | A. var y: string | number; diff --git a/tests/baselines/reference/unionTypeIdentity.errors.txt b/tests/baselines/reference/unionTypeIdentity.errors.txt index 77d25bd78d1f7..4acb5895d4130 100644 --- a/tests/baselines/reference/unionTypeIdentity.errors.txt +++ b/tests/baselines/reference/unionTypeIdentity.errors.txt @@ -12,9 +12,12 @@ tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/unionTypeI var strOrNum: string; // error ~~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'strOrNum' must be of type 'string | boolean', but here has type 'string'. +!!! related TS6203 tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/unionTypeIdentity.ts:3:5: 'strOrNum' was also declared here. var strOrNum: boolean; // error ~~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'strOrNum' must be of type 'string | boolean', but here has type 'boolean'. +!!! related TS6203 tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/unionTypeIdentity.ts:3:5: 'strOrNum' was also declared here. var strOrNum: number; // error ~~~~~~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'strOrNum' must be of type 'string | boolean', but here has type 'number'. \ No newline at end of file +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'strOrNum' must be of type 'string | boolean', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/types/typeRelationships/typeAndMemberIdentity/unionTypeIdentity.ts:3:5: 'strOrNum' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/unionTypeLiterals.errors.txt b/tests/baselines/reference/unionTypeLiterals.errors.txt index d976d769f5971..197f4e2364709 100644 --- a/tests/baselines/reference/unionTypeLiterals.errors.txt +++ b/tests/baselines/reference/unionTypeLiterals.errors.txt @@ -16,9 +16,11 @@ tests/cases/conformance/types/specifyingTypes/typeLiterals/unionTypeLiterals.ts( var unionOfFunctionType: () => string | number; ~~~~~~~~~~~~~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'unionOfFunctionType' must be of type '(() => string) | (() => number)', but here has type '() => string | number'. +!!! related TS6203 tests/cases/conformance/types/specifyingTypes/typeLiterals/unionTypeLiterals.ts:9:5: 'unionOfFunctionType' was also declared here. var unionOfConstructorType: (new () => string) | (new () => number); var unionOfConstructorType: { new (): string } | { new (): number }; var unionOfConstructorType: new () => string | number; ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'unionOfConstructorType' must be of type '(new () => string) | (new () => number)', but here has type 'new () => string | number'. \ No newline at end of file +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'unionOfConstructorType' must be of type '(new () => string) | (new () => number)', but here has type 'new () => string | number'. +!!! related TS6203 tests/cases/conformance/types/specifyingTypes/typeLiterals/unionTypeLiterals.ts:13:5: 'unionOfConstructorType' was also declared here. \ No newline at end of file diff --git a/tests/baselines/reference/varBlock.errors.txt b/tests/baselines/reference/varBlock.errors.txt index 12e3fc6a629f6..bcdb58f5979e8 100644 --- a/tests/baselines/reference/varBlock.errors.txt +++ b/tests/baselines/reference/varBlock.errors.txt @@ -98,5 +98,6 @@ tests/cases/compiler/varBlock.ts(39,17): error TS1039: Initializers are not allo declare var c = 10; ~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/compiler/varBlock.ts:38:13: 'c' was also declared here. ~~ !!! error TS1039: Initializers are not allowed in ambient contexts. \ No newline at end of file diff --git a/tests/baselines/reference/witness.errors.txt b/tests/baselines/reference/witness.errors.txt index cf21a8b2ed2c8..efaed3cc43cdd 100644 --- a/tests/baselines/reference/witness.errors.txt +++ b/tests/baselines/reference/witness.errors.txt @@ -56,6 +56,7 @@ tests/cases/conformance/types/witness/witness.ts(128,19): error TS2729: Property var co1: number; ~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'co1' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/types/witness/witness.ts:28:5: 'co1' was also declared here. var co2 = (3, 4, co2); ~ !!! error TS2695: Left side of comma operator is unused and has no side effects. @@ -72,22 +73,26 @@ tests/cases/conformance/types/witness/witness.ts(128,19): error TS2729: Property var co3: number; ~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'co3' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/types/witness/witness.ts:32:5: 'co3' was also declared here. // Assignment var as1 = (as1 = 2); var as1: number; ~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'as1' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/types/witness/witness.ts:36:5: 'as1' was also declared here. var as2 = (as2 = as2 = 2); var as2: number; ~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'as2' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/types/witness/witness.ts:38:5: 'as2' was also declared here. // Conditional var cnd1 = cnd1 ? 0 : 1; var cnd1: number; ~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'cnd1' must be of type 'any', but here has type 'number'. +!!! related TS6203 tests/cases/conformance/types/witness/witness.ts:42:5: 'cnd1' was also declared here. var cnd2 = cnd1 ? cnd1 ? '' : "" : ''; var cnd2: string; @@ -104,6 +109,7 @@ tests/cases/conformance/types/witness/witness.ts(128,19): error TS2729: Property var and1: string; ~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'and1' must be of type 'any', but here has type 'string'. +!!! related TS6203 tests/cases/conformance/types/witness/witness.ts:56:5: 'and1' was also declared here. var and2 = '' && and2; var and2: any; var and3 = and3 && and3; @@ -159,6 +165,7 @@ tests/cases/conformance/types/witness/witness.ts(128,19): error TS2729: Property var propAcc1: { m: any; } ~~~~~~~~ !!! error TS2403: Subsequent variable declarations must have the same type. Variable 'propAcc1' must be of type 'any', but here has type '{ m: any; }'. +!!! related TS6203 tests/cases/conformance/types/witness/witness.ts:107:5: 'propAcc1' was also declared here. // Property access of module member module M2 { From 8120094c81236651da967c33d7bd5ca185188faf Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 22 May 2019 06:49:49 -0700 Subject: [PATCH 16/43] Simplify index and object types when obtaining indexed access constraint --- src/compiler/checker.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e9dddff64af39..bd8d4c05901c7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7657,15 +7657,20 @@ namespace ts { return hasNonCircularBaseConstraint(type) ? getConstraintFromIndexedAccess(type) : undefined; } + function getSimplifiedTypeOrConstraint(type: Type) { + const simplified = getSimplifiedType(type, /*writing*/ false); + return simplified !== type ? simplified : getConstraintOfType(type); + } + function getConstraintFromIndexedAccess(type: IndexedAccessType) { - const indexConstraint = getConstraintOfType(type.indexType); + const indexConstraint = getSimplifiedTypeOrConstraint(type.indexType); if (indexConstraint && indexConstraint !== type.indexType) { const indexedAccess = getIndexedAccessTypeOrUndefined(type.objectType, indexConstraint); if (indexedAccess) { return indexedAccess; } } - const objectConstraint = getConstraintOfType(type.objectType); + const objectConstraint = getSimplifiedTypeOrConstraint(type.objectType); if (objectConstraint && objectConstraint !== type.objectType) { return getIndexedAccessTypeOrUndefined(objectConstraint, type.indexType); } From 2fd4aaee92a17318ad1c45c6f6590bbb8b82d33d Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 22 May 2019 06:54:16 -0700 Subject: [PATCH 17/43] Add regression test --- .../conformance/types/keyof/keyofAndIndexedAccess2.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts index a99c2b0a7a106..898648cea44fe 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts @@ -147,3 +147,13 @@ export class c { this["a"] = "b"; } } + +// Repro from #31385 + +type Foo = { [key: string]: { [K in keyof T]: K }[keyof T] }; + +type Bar = { [key: string]: { [K in keyof T]: [K] }[keyof T] }; + +type Baz> = { [K in keyof Q]: T[Q[K]] }; + +type Qux> = { [K in keyof Q]: T[Q[K]["0"]] }; From b7012b577a6e755215f80d3166e90f60aa50b98e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 22 May 2019 06:54:23 -0700 Subject: [PATCH 18/43] Accept new baselines --- .../keyofAndIndexedAccess2.errors.txt | 10 +++++ .../reference/keyofAndIndexedAccess2.js | 10 +++++ .../reference/keyofAndIndexedAccess2.symbols | 44 +++++++++++++++++++ .../reference/keyofAndIndexedAccess2.types | 16 +++++++ 4 files changed, 80 insertions(+) diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt b/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt index 9ebf28f1857e9..1cad297c52d29 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt @@ -228,4 +228,14 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(108,5): error TS23 this["a"] = "b"; } } + + // Repro from #31385 + + type Foo = { [key: string]: { [K in keyof T]: K }[keyof T] }; + + type Bar = { [key: string]: { [K in keyof T]: [K] }[keyof T] }; + + type Baz> = { [K in keyof Q]: T[Q[K]] }; + + type Qux> = { [K in keyof Q]: T[Q[K]["0"]] }; \ No newline at end of file diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.js b/tests/baselines/reference/keyofAndIndexedAccess2.js index 374b13b5a643a..7547a3f84c593 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.js +++ b/tests/baselines/reference/keyofAndIndexedAccess2.js @@ -145,6 +145,16 @@ export class c { this["a"] = "b"; } } + +// Repro from #31385 + +type Foo = { [key: string]: { [K in keyof T]: K }[keyof T] }; + +type Bar = { [key: string]: { [K in keyof T]: [K] }[keyof T] }; + +type Baz> = { [K in keyof Q]: T[Q[K]] }; + +type Qux> = { [K in keyof Q]: T[Q[K]["0"]] }; //// [keyofAndIndexedAccess2.js] diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.symbols b/tests/baselines/reference/keyofAndIndexedAccess2.symbols index a3412e8a47d31..91602f93e1d85 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccess2.symbols @@ -517,3 +517,47 @@ export class c { } } +// Repro from #31385 + +type Foo = { [key: string]: { [K in keyof T]: K }[keyof T] }; +>Foo : Symbol(Foo, Decl(keyofAndIndexedAccess2.ts, 145, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 149, 9)) +>key : Symbol(key, Decl(keyofAndIndexedAccess2.ts, 149, 17)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 149, 34)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 149, 9)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 149, 34)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 149, 9)) + +type Bar = { [key: string]: { [K in keyof T]: [K] }[keyof T] }; +>Bar : Symbol(Bar, Decl(keyofAndIndexedAccess2.ts, 149, 64)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 151, 9)) +>key : Symbol(key, Decl(keyofAndIndexedAccess2.ts, 151, 17)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 151, 34)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 151, 9)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 151, 34)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 151, 9)) + +type Baz> = { [K in keyof Q]: T[Q[K]] }; +>Baz : Symbol(Baz, Decl(keyofAndIndexedAccess2.ts, 151, 66)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 153, 9)) +>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 153, 11)) +>Foo : Symbol(Foo, Decl(keyofAndIndexedAccess2.ts, 145, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 153, 9)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 153, 35)) +>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 153, 11)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 153, 9)) +>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 153, 11)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 153, 35)) + +type Qux> = { [K in keyof Q]: T[Q[K]["0"]] }; +>Qux : Symbol(Qux, Decl(keyofAndIndexedAccess2.ts, 153, 60)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 155, 9)) +>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 155, 11)) +>Bar : Symbol(Bar, Decl(keyofAndIndexedAccess2.ts, 149, 64)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 155, 9)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 155, 35)) +>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 155, 11)) +>T : Symbol(T, Decl(keyofAndIndexedAccess2.ts, 155, 9)) +>Q : Symbol(Q, Decl(keyofAndIndexedAccess2.ts, 155, 11)) +>K : Symbol(K, Decl(keyofAndIndexedAccess2.ts, 155, 35)) + diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.types b/tests/baselines/reference/keyofAndIndexedAccess2.types index b7b71ba4f9f71..45cf1d4bad5d4 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.types +++ b/tests/baselines/reference/keyofAndIndexedAccess2.types @@ -517,3 +517,19 @@ export class c { } } +// Repro from #31385 + +type Foo = { [key: string]: { [K in keyof T]: K }[keyof T] }; +>Foo : Foo +>key : string + +type Bar = { [key: string]: { [K in keyof T]: [K] }[keyof T] }; +>Bar : Bar +>key : string + +type Baz> = { [K in keyof Q]: T[Q[K]] }; +>Baz : Baz + +type Qux> = { [K in keyof Q]: T[Q[K]["0"]] }; +>Qux : Qux + From b36c8a06902ca47da1568167991bd0bc28ced80e Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 22 May 2019 09:45:41 -0700 Subject: [PATCH 19/43] Make anyArray.filter(Boolean) return any[], not unknown[] (#31515) * Add this-parameter workaround to Array.filter Allows anys.filter(Boolean) to once again return any[], not unknown[]. * Add any constraint to Boolean factory function I want to test how well this works. * Remove Boolean factory type guard * Remove typeGuardBoolean test --- src/lib/es5.d.ts | 2 +- .../reference/booleanFilterAnyArray.js | 37 ++++++ .../reference/booleanFilterAnyArray.symbols | 108 ++++++++++++++++++ .../reference/booleanFilterAnyArray.types | 94 +++++++++++++++ tests/baselines/reference/typeGuardBoolean.js | 30 ----- .../reference/typeGuardBoolean.symbols | 35 ------ .../reference/typeGuardBoolean.types | 44 ------- tests/cases/compiler/booleanFilterAnyArray.ts | 24 ++++ .../typeGuards/typeGuardBoolean.ts | 14 --- 9 files changed, 264 insertions(+), 124 deletions(-) create mode 100644 tests/baselines/reference/booleanFilterAnyArray.js create mode 100644 tests/baselines/reference/booleanFilterAnyArray.symbols create mode 100644 tests/baselines/reference/booleanFilterAnyArray.types delete mode 100644 tests/baselines/reference/typeGuardBoolean.js delete mode 100644 tests/baselines/reference/typeGuardBoolean.symbols delete mode 100644 tests/baselines/reference/typeGuardBoolean.types create mode 100644 tests/cases/compiler/booleanFilterAnyArray.ts delete mode 100644 tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts diff --git a/src/lib/es5.d.ts b/src/lib/es5.d.ts index f2be6716c7299..0d1481dd7d26b 100644 --- a/src/lib/es5.d.ts +++ b/src/lib/es5.d.ts @@ -513,7 +513,7 @@ interface Boolean { interface BooleanConstructor { new(value?: any): Boolean; - (value?: T): value is Exclude; + (value?: T): boolean; readonly prototype: Boolean; } diff --git a/tests/baselines/reference/booleanFilterAnyArray.js b/tests/baselines/reference/booleanFilterAnyArray.js new file mode 100644 index 0000000000000..2cd319ca440ad --- /dev/null +++ b/tests/baselines/reference/booleanFilterAnyArray.js @@ -0,0 +1,37 @@ +//// [booleanFilterAnyArray.ts] +interface Bullean { } +interface BulleanConstructor { + new(v1?: any): Bullean; + (v2?: T): v2 is T; +} + +interface Ari { + filter(cb1: (value: T) => value is S): T extends any ? Ari : Ari; + filter(cb2: (value: T) => unknown): Ari; +} +declare var Bullean: BulleanConstructor; +declare let anys: Ari; +var xs: Ari; +var xs = anys.filter(Bullean) + +declare let realanys: any[]; +var ys: any[]; +var ys = realanys.filter(Boolean) + +var foo = [{ name: 'x' }] +var foor: Array<{name: string}> +var foor = foo.filter(x => x.name) +var foos: Array +var foos = [true, true, false, null].filter((thing): thing is boolean => thing !== null) + + +//// [booleanFilterAnyArray.js] +var xs; +var xs = anys.filter(Bullean); +var ys; +var ys = realanys.filter(Boolean); +var foo = [{ name: 'x' }]; +var foor; +var foor = foo.filter(function (x) { return x.name; }); +var foos; +var foos = [true, true, false, null].filter(function (thing) { return thing !== null; }); diff --git a/tests/baselines/reference/booleanFilterAnyArray.symbols b/tests/baselines/reference/booleanFilterAnyArray.symbols new file mode 100644 index 0000000000000..1e0207fdf8049 --- /dev/null +++ b/tests/baselines/reference/booleanFilterAnyArray.symbols @@ -0,0 +1,108 @@ +=== tests/cases/compiler/booleanFilterAnyArray.ts === +interface Bullean { } +>Bullean : Symbol(Bullean, Decl(booleanFilterAnyArray.ts, 0, 0), Decl(booleanFilterAnyArray.ts, 10, 11)) + +interface BulleanConstructor { +>BulleanConstructor : Symbol(BulleanConstructor, Decl(booleanFilterAnyArray.ts, 0, 21)) + + new(v1?: any): Bullean; +>v1 : Symbol(v1, Decl(booleanFilterAnyArray.ts, 2, 8)) +>Bullean : Symbol(Bullean, Decl(booleanFilterAnyArray.ts, 0, 0), Decl(booleanFilterAnyArray.ts, 10, 11)) + + (v2?: T): v2 is T; +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 3, 5)) +>v2 : Symbol(v2, Decl(booleanFilterAnyArray.ts, 3, 8)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 3, 5)) +>v2 : Symbol(v2, Decl(booleanFilterAnyArray.ts, 3, 8)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 3, 5)) +} + +interface Ari { +>Ari : Symbol(Ari, Decl(booleanFilterAnyArray.ts, 4, 1)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) + + filter(cb1: (value: T) => value is S): T extends any ? Ari : Ari; +>filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 90)) +>S : Symbol(S, Decl(booleanFilterAnyArray.ts, 7, 11)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) +>cb1 : Symbol(cb1, Decl(booleanFilterAnyArray.ts, 7, 24)) +>value : Symbol(value, Decl(booleanFilterAnyArray.ts, 7, 30)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) +>value : Symbol(value, Decl(booleanFilterAnyArray.ts, 7, 30)) +>S : Symbol(S, Decl(booleanFilterAnyArray.ts, 7, 11)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) +>Ari : Symbol(Ari, Decl(booleanFilterAnyArray.ts, 4, 1)) +>Ari : Symbol(Ari, Decl(booleanFilterAnyArray.ts, 4, 1)) +>S : Symbol(S, Decl(booleanFilterAnyArray.ts, 7, 11)) + + filter(cb2: (value: T) => unknown): Ari; +>filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 90)) +>cb2 : Symbol(cb2, Decl(booleanFilterAnyArray.ts, 8, 11)) +>value : Symbol(value, Decl(booleanFilterAnyArray.ts, 8, 17)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) +>Ari : Symbol(Ari, Decl(booleanFilterAnyArray.ts, 4, 1)) +>T : Symbol(T, Decl(booleanFilterAnyArray.ts, 6, 14)) +} +declare var Bullean: BulleanConstructor; +>Bullean : Symbol(Bullean, Decl(booleanFilterAnyArray.ts, 0, 0), Decl(booleanFilterAnyArray.ts, 10, 11)) +>BulleanConstructor : Symbol(BulleanConstructor, Decl(booleanFilterAnyArray.ts, 0, 21)) + +declare let anys: Ari; +>anys : Symbol(anys, Decl(booleanFilterAnyArray.ts, 11, 11)) +>Ari : Symbol(Ari, Decl(booleanFilterAnyArray.ts, 4, 1)) + +var xs: Ari; +>xs : Symbol(xs, Decl(booleanFilterAnyArray.ts, 12, 3), Decl(booleanFilterAnyArray.ts, 13, 3)) +>Ari : Symbol(Ari, Decl(booleanFilterAnyArray.ts, 4, 1)) + +var xs = anys.filter(Bullean) +>xs : Symbol(xs, Decl(booleanFilterAnyArray.ts, 12, 3), Decl(booleanFilterAnyArray.ts, 13, 3)) +>anys.filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 90)) +>anys : Symbol(anys, Decl(booleanFilterAnyArray.ts, 11, 11)) +>filter : Symbol(Ari.filter, Decl(booleanFilterAnyArray.ts, 6, 18), Decl(booleanFilterAnyArray.ts, 7, 90)) +>Bullean : Symbol(Bullean, Decl(booleanFilterAnyArray.ts, 0, 0), Decl(booleanFilterAnyArray.ts, 10, 11)) + +declare let realanys: any[]; +>realanys : Symbol(realanys, Decl(booleanFilterAnyArray.ts, 15, 11)) + +var ys: any[]; +>ys : Symbol(ys, Decl(booleanFilterAnyArray.ts, 16, 3), Decl(booleanFilterAnyArray.ts, 17, 3)) + +var ys = realanys.filter(Boolean) +>ys : Symbol(ys, Decl(booleanFilterAnyArray.ts, 16, 3), Decl(booleanFilterAnyArray.ts, 17, 3)) +>realanys.filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>realanys : Symbol(realanys, Decl(booleanFilterAnyArray.ts, 15, 11)) +>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>Boolean : Symbol(Boolean, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + +var foo = [{ name: 'x' }] +>foo : Symbol(foo, Decl(booleanFilterAnyArray.ts, 19, 3)) +>name : Symbol(name, Decl(booleanFilterAnyArray.ts, 19, 12)) + +var foor: Array<{name: string}> +>foor : Symbol(foor, Decl(booleanFilterAnyArray.ts, 20, 3), Decl(booleanFilterAnyArray.ts, 21, 3)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>name : Symbol(name, Decl(booleanFilterAnyArray.ts, 20, 17)) + +var foor = foo.filter(x => x.name) +>foor : Symbol(foor, Decl(booleanFilterAnyArray.ts, 20, 3), Decl(booleanFilterAnyArray.ts, 21, 3)) +>foo.filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>foo : Symbol(foo, Decl(booleanFilterAnyArray.ts, 19, 3)) +>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(booleanFilterAnyArray.ts, 21, 22)) +>x.name : Symbol(name, Decl(booleanFilterAnyArray.ts, 19, 12)) +>x : Symbol(x, Decl(booleanFilterAnyArray.ts, 21, 22)) +>name : Symbol(name, Decl(booleanFilterAnyArray.ts, 19, 12)) + +var foos: Array +>foos : Symbol(foos, Decl(booleanFilterAnyArray.ts, 22, 3), Decl(booleanFilterAnyArray.ts, 23, 3)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + +var foos = [true, true, false, null].filter((thing): thing is boolean => thing !== null) +>foos : Symbol(foos, Decl(booleanFilterAnyArray.ts, 22, 3), Decl(booleanFilterAnyArray.ts, 23, 3)) +>[true, true, false, null].filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>filter : Symbol(Array.filter, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>thing : Symbol(thing, Decl(booleanFilterAnyArray.ts, 23, 45)) +>thing : Symbol(thing, Decl(booleanFilterAnyArray.ts, 23, 45)) +>thing : Symbol(thing, Decl(booleanFilterAnyArray.ts, 23, 45)) + diff --git a/tests/baselines/reference/booleanFilterAnyArray.types b/tests/baselines/reference/booleanFilterAnyArray.types new file mode 100644 index 0000000000000..a1d4303ef8e30 --- /dev/null +++ b/tests/baselines/reference/booleanFilterAnyArray.types @@ -0,0 +1,94 @@ +=== tests/cases/compiler/booleanFilterAnyArray.ts === +interface Bullean { } +interface BulleanConstructor { + new(v1?: any): Bullean; +>v1 : any + + (v2?: T): v2 is T; +>v2 : T +} + +interface Ari { + filter(cb1: (value: T) => value is S): T extends any ? Ari : Ari; +>filter : { (cb1: (value: T) => value is S): T extends any ? Ari : Ari; (cb2: (value: T) => unknown): Ari; } +>cb1 : (value: T) => value is S +>value : T + + filter(cb2: (value: T) => unknown): Ari; +>filter : { (cb1: (value: T) => value is S): T extends any ? Ari : Ari; (cb2: (value: T) => unknown): Ari; } +>cb2 : (value: T) => unknown +>value : T +} +declare var Bullean: BulleanConstructor; +>Bullean : BulleanConstructor + +declare let anys: Ari; +>anys : Ari + +var xs: Ari; +>xs : Ari + +var xs = anys.filter(Bullean) +>xs : Ari +>anys.filter(Bullean) : Ari +>anys.filter : { (cb1: (value: any) => value is S): Ari; (cb2: (value: any) => unknown): Ari; } +>anys : Ari +>filter : { (cb1: (value: any) => value is S): Ari; (cb2: (value: any) => unknown): Ari; } +>Bullean : BulleanConstructor + +declare let realanys: any[]; +>realanys : any[] + +var ys: any[]; +>ys : any[] + +var ys = realanys.filter(Boolean) +>ys : any[] +>realanys.filter(Boolean) : any[] +>realanys.filter : { (callbackfn: (value: any, index: number, array: any[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: any, index: number, array: any[]) => unknown, thisArg?: any): any[]; } +>realanys : any[] +>filter : { (callbackfn: (value: any, index: number, array: any[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: any, index: number, array: any[]) => unknown, thisArg?: any): any[]; } +>Boolean : BooleanConstructor + +var foo = [{ name: 'x' }] +>foo : { name: string; }[] +>[{ name: 'x' }] : { name: string; }[] +>{ name: 'x' } : { name: string; } +>name : string +>'x' : "x" + +var foor: Array<{name: string}> +>foor : { name: string; }[] +>name : string + +var foor = foo.filter(x => x.name) +>foor : { name: string; }[] +>foo.filter(x => x.name) : { name: string; }[] +>foo.filter : { (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => unknown, thisArg?: any): { name: string; }[]; } +>foo : { name: string; }[] +>filter : { (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: { name: string; }, index: number, array: { name: string; }[]) => unknown, thisArg?: any): { name: string; }[]; } +>x => x.name : (x: { name: string; }) => string +>x : { name: string; } +>x.name : string +>x : { name: string; } +>name : string + +var foos: Array +>foos : boolean[] + +var foos = [true, true, false, null].filter((thing): thing is boolean => thing !== null) +>foos : boolean[] +>[true, true, false, null].filter((thing): thing is boolean => thing !== null) : boolean[] +>[true, true, false, null].filter : { (callbackfn: (value: boolean, index: number, array: boolean[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: boolean, index: number, array: boolean[]) => unknown, thisArg?: any): boolean[]; } +>[true, true, false, null] : boolean[] +>true : true +>true : true +>false : false +>null : null +>filter : { (callbackfn: (value: boolean, index: number, array: boolean[]) => value is S, thisArg?: any): S[]; (callbackfn: (value: boolean, index: number, array: boolean[]) => unknown, thisArg?: any): boolean[]; } +>(thing): thing is boolean => thing !== null : (thing: boolean) => thing is boolean +>thing : boolean +>thing !== null : boolean +>thing : boolean +>null : null + diff --git a/tests/baselines/reference/typeGuardBoolean.js b/tests/baselines/reference/typeGuardBoolean.js deleted file mode 100644 index 1bfe41983d83b..0000000000000 --- a/tests/baselines/reference/typeGuardBoolean.js +++ /dev/null @@ -1,30 +0,0 @@ -//// [typeGuardBoolean.ts] -function test(strOrNull: string | null, strOrUndefined: string | undefined) { - var str: string = "original"; - var nil: null; - if (!Boolean(strOrNull)) { - nil = strOrNull; - } - else { - str = strOrNull; - } - if (Boolean(strOrUndefined)) { - str = strOrUndefined; - } -} - - -//// [typeGuardBoolean.js] -function test(strOrNull, strOrUndefined) { - var str = "original"; - var nil; - if (!Boolean(strOrNull)) { - nil = strOrNull; - } - else { - str = strOrNull; - } - if (Boolean(strOrUndefined)) { - str = strOrUndefined; - } -} diff --git a/tests/baselines/reference/typeGuardBoolean.symbols b/tests/baselines/reference/typeGuardBoolean.symbols deleted file mode 100644 index 6a08dcbda8a06..0000000000000 --- a/tests/baselines/reference/typeGuardBoolean.symbols +++ /dev/null @@ -1,35 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts === -function test(strOrNull: string | null, strOrUndefined: string | undefined) { ->test : Symbol(test, Decl(typeGuardBoolean.ts, 0, 0)) ->strOrNull : Symbol(strOrNull, Decl(typeGuardBoolean.ts, 0, 14)) ->strOrUndefined : Symbol(strOrUndefined, Decl(typeGuardBoolean.ts, 0, 39)) - - var str: string = "original"; ->str : Symbol(str, Decl(typeGuardBoolean.ts, 1, 5)) - - var nil: null; ->nil : Symbol(nil, Decl(typeGuardBoolean.ts, 2, 5)) - - if (!Boolean(strOrNull)) { ->Boolean : Symbol(Boolean, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->strOrNull : Symbol(strOrNull, Decl(typeGuardBoolean.ts, 0, 14)) - - nil = strOrNull; ->nil : Symbol(nil, Decl(typeGuardBoolean.ts, 2, 5)) ->strOrNull : Symbol(strOrNull, Decl(typeGuardBoolean.ts, 0, 14)) - } - else { - str = strOrNull; ->str : Symbol(str, Decl(typeGuardBoolean.ts, 1, 5)) ->strOrNull : Symbol(strOrNull, Decl(typeGuardBoolean.ts, 0, 14)) - } - if (Boolean(strOrUndefined)) { ->Boolean : Symbol(Boolean, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->strOrUndefined : Symbol(strOrUndefined, Decl(typeGuardBoolean.ts, 0, 39)) - - str = strOrUndefined; ->str : Symbol(str, Decl(typeGuardBoolean.ts, 1, 5)) ->strOrUndefined : Symbol(strOrUndefined, Decl(typeGuardBoolean.ts, 0, 39)) - } -} - diff --git a/tests/baselines/reference/typeGuardBoolean.types b/tests/baselines/reference/typeGuardBoolean.types deleted file mode 100644 index db3d6f39cd841..0000000000000 --- a/tests/baselines/reference/typeGuardBoolean.types +++ /dev/null @@ -1,44 +0,0 @@ -=== tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.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" : "original" - - var nil: null; ->nil : null ->null : null - - if (!Boolean(strOrNull)) { ->!Boolean(strOrNull) : boolean ->Boolean(strOrNull) : boolean ->Boolean : BooleanConstructor ->strOrNull : string | null - - nil = strOrNull; ->nil = strOrNull : null ->nil : null ->strOrNull : null - } - else { - str = strOrNull; ->str = strOrNull : string ->str : string ->strOrNull : string - } - if (Boolean(strOrUndefined)) { ->Boolean(strOrUndefined) : boolean ->Boolean : BooleanConstructor ->strOrUndefined : string | undefined - - str = strOrUndefined; ->str = strOrUndefined : string ->str : string ->strOrUndefined : string - } -} - diff --git a/tests/cases/compiler/booleanFilterAnyArray.ts b/tests/cases/compiler/booleanFilterAnyArray.ts new file mode 100644 index 0000000000000..db5f38e78f9a0 --- /dev/null +++ b/tests/cases/compiler/booleanFilterAnyArray.ts @@ -0,0 +1,24 @@ +interface Bullean { } +interface BulleanConstructor { + new(v1?: any): Bullean; + (v2?: T): v2 is T; +} + +interface Ari { + filter(cb1: (value: T) => value is S): T extends any ? Ari : Ari; + filter(cb2: (value: T) => unknown): Ari; +} +declare var Bullean: BulleanConstructor; +declare let anys: Ari; +var xs: Ari; +var xs = anys.filter(Bullean) + +declare let realanys: any[]; +var ys: any[]; +var ys = realanys.filter(Boolean) + +var foo = [{ name: 'x' }] +var foor: Array<{name: string}> +var foor = foo.filter(x => x.name) +var foos: Array +var foos = [true, true, false, null].filter((thing): thing is boolean => thing !== null) diff --git a/tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts b/tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts deleted file mode 100644 index 3f2dde227ba8c..0000000000000 --- a/tests/cases/conformance/expressions/typeGuards/typeGuardBoolean.ts +++ /dev/null @@ -1,14 +0,0 @@ -// @strictNullChecks: true -function test(strOrNull: string | null, strOrUndefined: string | undefined) { - var str: string = "original"; - var nil: null; - if (!Boolean(strOrNull)) { - nil = strOrNull; - } - else { - str = strOrNull; - } - if (Boolean(strOrUndefined)) { - str = strOrUndefined; - } -} From 7611c5b9315b56c665121ae85ed5b20163399658 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 22 May 2019 11:17:54 -0700 Subject: [PATCH 20/43] Fix for computed properties in instance initializers (#31517) --- src/compiler/emitter.ts | 2 ++ .../instanceMemberWithComputedPropertyName.js | 22 ++++++++++++++++ ...anceMemberWithComputedPropertyName.symbols | 20 +++++++++++++++ ...stanceMemberWithComputedPropertyName.types | 25 +++++++++++++++++++ .../instanceMemberWithComputedPropertyName.ts | 8 ++++++ 5 files changed, 77 insertions(+) create mode 100644 tests/baselines/reference/instanceMemberWithComputedPropertyName.js create mode 100644 tests/baselines/reference/instanceMemberWithComputedPropertyName.symbols create mode 100644 tests/baselines/reference/instanceMemberWithComputedPropertyName.types create mode 100644 tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberWithComputedPropertyName.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d335ceb1b6037..07b1208688fab 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4527,6 +4527,8 @@ namespace ts { case SyntaxKind.GetAccessor: case SyntaxKind.SetAccessor: return generateNameForMethodOrAccessor(node); + case SyntaxKind.ComputedPropertyName: + return makeTempVariableName(TempFlags.Auto, /*reserveInNestedScopes*/ true); default: return makeTempVariableName(TempFlags.Auto); } diff --git a/tests/baselines/reference/instanceMemberWithComputedPropertyName.js b/tests/baselines/reference/instanceMemberWithComputedPropertyName.js new file mode 100644 index 0000000000000..eba55c9899e64 --- /dev/null +++ b/tests/baselines/reference/instanceMemberWithComputedPropertyName.js @@ -0,0 +1,22 @@ +//// [instanceMemberWithComputedPropertyName.ts] +// https://github.com/microsoft/TypeScript/issues/30953 +const x = 1; +class C { + [x] = true; + constructor() { + const { a, b } = { a: 1, b: 2 }; + } +} + +//// [instanceMemberWithComputedPropertyName.js] +var _a; +// https://github.com/microsoft/TypeScript/issues/30953 +var x = 1; +var C = /** @class */ (function () { + function C() { + this[_a] = true; + var _b = { a: 1, b: 2 }, a = _b.a, b = _b.b; + } + return C; +}()); +_a = x; diff --git a/tests/baselines/reference/instanceMemberWithComputedPropertyName.symbols b/tests/baselines/reference/instanceMemberWithComputedPropertyName.symbols new file mode 100644 index 0000000000000..3d405c89cc87a --- /dev/null +++ b/tests/baselines/reference/instanceMemberWithComputedPropertyName.symbols @@ -0,0 +1,20 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberWithComputedPropertyName.ts === +// https://github.com/microsoft/TypeScript/issues/30953 +const x = 1; +>x : Symbol(x, Decl(instanceMemberWithComputedPropertyName.ts, 1, 5)) + +class C { +>C : Symbol(C, Decl(instanceMemberWithComputedPropertyName.ts, 1, 12)) + + [x] = true; +>[x] : Symbol(C[x], Decl(instanceMemberWithComputedPropertyName.ts, 2, 9)) +>x : Symbol(x, Decl(instanceMemberWithComputedPropertyName.ts, 1, 5)) + + constructor() { + const { a, b } = { a: 1, b: 2 }; +>a : Symbol(a, Decl(instanceMemberWithComputedPropertyName.ts, 5, 15)) +>b : Symbol(b, Decl(instanceMemberWithComputedPropertyName.ts, 5, 18)) +>a : Symbol(a, Decl(instanceMemberWithComputedPropertyName.ts, 5, 26)) +>b : Symbol(b, Decl(instanceMemberWithComputedPropertyName.ts, 5, 32)) + } +} diff --git a/tests/baselines/reference/instanceMemberWithComputedPropertyName.types b/tests/baselines/reference/instanceMemberWithComputedPropertyName.types new file mode 100644 index 0000000000000..f98cc7bb80a84 --- /dev/null +++ b/tests/baselines/reference/instanceMemberWithComputedPropertyName.types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberWithComputedPropertyName.ts === +// https://github.com/microsoft/TypeScript/issues/30953 +const x = 1; +>x : 1 +>1 : 1 + +class C { +>C : C + + [x] = true; +>[x] : boolean +>x : 1 +>true : true + + constructor() { + const { a, b } = { a: 1, b: 2 }; +>a : number +>b : number +>{ a: 1, b: 2 } : { a: number; b: number; } +>a : number +>1 : 1 +>b : number +>2 : 2 + } +} diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberWithComputedPropertyName.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberWithComputedPropertyName.ts new file mode 100644 index 0000000000000..31aec681445a5 --- /dev/null +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/instanceMemberWithComputedPropertyName.ts @@ -0,0 +1,8 @@ +// https://github.com/microsoft/TypeScript/issues/30953 +const x = 1; +class C { + [x] = true; + constructor() { + const { a, b } = { a: 1, b: 2 }; + } +} \ No newline at end of file From b3dc32fec7ebc2ed3bd6dc88f28be26f1479e854 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 22 May 2019 11:18:07 -0700 Subject: [PATCH 21/43] Reset error record in downlevel for-of (#31519) --- src/compiler/transformers/es2015.ts | 42 ++++++------ tests/baselines/reference/ES5For-of37.js | 64 +++++++++++++++++++ tests/baselines/reference/ES5For-of37.symbols | 35 ++++++++++ tests/baselines/reference/ES5For-of37.types | 52 +++++++++++++++ .../for-ofStatements/ES5For-of37.ts | 16 +++++ 5 files changed, 191 insertions(+), 18 deletions(-) create mode 100644 tests/baselines/reference/ES5For-of37.js create mode 100644 tests/baselines/reference/ES5For-of37.symbols create mode 100644 tests/baselines/reference/ES5For-of37.types create mode 100644 tests/cases/conformance/statements/for-ofStatements/ES5For-of37.ts diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index cdeae5dbf54a5..9849d72f14a08 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -145,7 +145,7 @@ namespace ts { loopOutParameters: LoopOutParameter[]; } - type LoopConverter = (node: IterationStatement, outermostLabeledStatement: LabeledStatement | undefined, convertedLoopBodyStatements: Statement[] | undefined) => Statement; + type LoopConverter = (node: IterationStatement, outermostLabeledStatement: LabeledStatement | undefined, convertedLoopBodyStatements: Statement[] | undefined, ancestorFacts: HierarchyFacts) => Statement; // Facts we track as we traverse the tree const enum HierarchyFacts { @@ -163,11 +163,12 @@ namespace ts { ExportedVariableStatement = 1 << 5, // Enclosed in an exported variable statement in the current scope TopLevel = 1 << 6, // Enclosing block-scoped container is a top-level container Block = 1 << 7, // Enclosing block-scoped container is a Block - IterationStatement = 1 << 8, // Enclosed in an IterationStatement + IterationStatement = 1 << 8, // Immediately enclosed in an IterationStatement IterationStatementBlock = 1 << 9, // Enclosing Block is enclosed in an IterationStatement - ForStatement = 1 << 10, // Enclosing block-scoped container is a ForStatement - ForInOrForOfStatement = 1 << 11, // Enclosing block-scoped container is a ForInStatement or ForOfStatement - ConstructorWithCapturedSuper = 1 << 12, // Enclosed in a constructor that captures 'this' for use with 'super' + IterationContainer = 1 << 10, // Enclosed in an outer IterationStatement + ForStatement = 1 << 11, // Enclosing block-scoped container is a ForStatement + ForInOrForOfStatement = 1 << 12, // Enclosing block-scoped container is a ForInStatement or ForOfStatement + ConstructorWithCapturedSuper = 1 << 13, // Enclosed in a constructor that captures 'this' for use with 'super' // NOTE: do not add more ancestor flags without also updating AncestorFactsMask below. // NOTE: when adding a new ancestor flag, be sure to update the subtree flags below. @@ -184,11 +185,11 @@ namespace ts { // A source file is a top-level block scope. SourceFileIncludes = TopLevel, - SourceFileExcludes = BlockScopeExcludes & ~TopLevel, + SourceFileExcludes = BlockScopeExcludes & ~TopLevel | IterationContainer, // Functions, methods, and accessors are both new lexical scopes and new block scopes. FunctionIncludes = Function | TopLevel, - FunctionExcludes = BlockScopeExcludes & ~TopLevel | ArrowFunction | AsyncFunctionBody | CapturesThis | NonStaticClassElement | ConstructorWithCapturedSuper, + FunctionExcludes = BlockScopeExcludes & ~TopLevel | ArrowFunction | AsyncFunctionBody | CapturesThis | NonStaticClassElement | ConstructorWithCapturedSuper | IterationContainer, AsyncFunctionBodyIncludes = FunctionIncludes | AsyncFunctionBody, AsyncFunctionBodyExcludes = FunctionExcludes & ~NonStaticClassElement, @@ -205,16 +206,16 @@ namespace ts { // 'do' and 'while' statements are not block scopes. We track that the subtree is contained // within an IterationStatement to indicate whether the embedded statement is an // IterationStatementBlock. - DoOrWhileStatementIncludes = IterationStatement, + DoOrWhileStatementIncludes = IterationStatement | IterationContainer, DoOrWhileStatementExcludes = None, // 'for' statements are new block scopes and have special handling for 'let' declarations. - ForStatementIncludes = IterationStatement | ForStatement, + ForStatementIncludes = IterationStatement | ForStatement | IterationContainer, ForStatementExcludes = BlockScopeExcludes & ~ForStatement, // 'for-in' and 'for-of' statements are new block scopes and have special handling for // 'let' declarations. - ForInOrForOfStatementIncludes = IterationStatement | ForInOrForOfStatement, + ForInOrForOfStatementIncludes = IterationStatement | ForInOrForOfStatement | IterationContainer, ForInOrForOfStatementExcludes = BlockScopeExcludes & ~ForInOrForOfStatement, // Blocks (other than function bodies) are new block scopes. @@ -228,8 +229,8 @@ namespace ts { // Subtree facts // - NewTarget = 1 << 13, // Contains a 'new.target' meta-property - CapturedLexicalThis = 1 << 14, // Contains a lexical `this` reference captured by an arrow function. + NewTarget = 1 << 14, // Contains a 'new.target' meta-property + CapturedLexicalThis = 1 << 15, // Contains a lexical `this` reference captured by an arrow function. // // Subtree masks @@ -2227,7 +2228,7 @@ namespace ts { function visitIterationStatementWithFacts(excludeFacts: HierarchyFacts, includeFacts: HierarchyFacts, node: IterationStatement, outermostLabeledStatement: LabeledStatement | undefined, convert?: LoopConverter) { const ancestorFacts = enterSubtree(excludeFacts, includeFacts); - const updated = convertIterationStatementBodyIfNecessary(node, outermostLabeledStatement, convert); + const updated = convertIterationStatementBodyIfNecessary(node, outermostLabeledStatement, ancestorFacts, convert); exitSubtree(ancestorFacts, HierarchyFacts.None, HierarchyFacts.None); return updated; } @@ -2434,7 +2435,7 @@ namespace ts { return restoreEnclosingLabel(forStatement, outermostLabeledStatement, convertedLoopState && resetLabel); } - function convertForOfStatementForIterable(node: ForOfStatement, outermostLabeledStatement: LabeledStatement, convertedLoopBodyStatements: Statement[]): Statement { + function convertForOfStatementForIterable(node: ForOfStatement, outermostLabeledStatement: LabeledStatement, convertedLoopBodyStatements: Statement[], ancestorFacts: HierarchyFacts): Statement { const expression = visitNode(node.expression, visitor, isExpression); const iterator = isIdentifier(expression) ? getGeneratedNameForNode(expression) : createTempVariable(/*recordTempVariable*/ undefined); const result = isIdentifier(expression) ? getGeneratedNameForNode(iterator) : createTempVariable(/*recordTempVariable*/ undefined); @@ -2447,13 +2448,18 @@ namespace ts { hoistVariableDeclaration(errorRecord); hoistVariableDeclaration(returnMethod); + // if we are enclosed in an outer loop ensure we reset 'errorRecord' per each iteration + const initializer = ancestorFacts & HierarchyFacts.IterationContainer + ? inlineExpressions([createAssignment(errorRecord, createVoidZero()), values]) + : values; + const forStatement = setEmitFlags( setTextRange( createFor( /*initializer*/ setEmitFlags( setTextRange( createVariableDeclarationList([ - setTextRange(createVariableDeclaration(iterator, /*type*/ undefined, values), node.expression), + setTextRange(createVariableDeclaration(iterator, /*type*/ undefined, initializer), node.expression), createVariableDeclaration(result, /*type*/ undefined, next) ]), node.expression @@ -2665,7 +2671,7 @@ namespace ts { } } - function convertIterationStatementBodyIfNecessary(node: IterationStatement, outermostLabeledStatement: LabeledStatement | undefined, convert?: LoopConverter): VisitResult { + function convertIterationStatementBodyIfNecessary(node: IterationStatement, outermostLabeledStatement: LabeledStatement | undefined, ancestorFacts: HierarchyFacts, convert?: LoopConverter): VisitResult { if (!shouldConvertIterationStatement(node)) { let saveAllowedNonLabeledJumps: Jump | undefined; if (convertedLoopState) { @@ -2676,7 +2682,7 @@ namespace ts { } const result = convert - ? convert(node, outermostLabeledStatement, /*convertedLoopBodyStatements*/ undefined) + ? convert(node, outermostLabeledStatement, /*convertedLoopBodyStatements*/ undefined, ancestorFacts) : restoreEnclosingLabel(visitEachChild(node, visitor, context), outermostLabeledStatement, convertedLoopState && resetLabel); if (convertedLoopState) { @@ -2708,7 +2714,7 @@ namespace ts { let loop: Statement; if (bodyFunction) { if (convert) { - loop = convert(node, outermostLabeledStatement, bodyFunction.part); + loop = convert(node, outermostLabeledStatement, bodyFunction.part, ancestorFacts); } else { const clone = convertIterationStatementCore(node, initializerFunction, createBlock(bodyFunction.part, /*multiLine*/ true)); diff --git a/tests/baselines/reference/ES5For-of37.js b/tests/baselines/reference/ES5For-of37.js new file mode 100644 index 0000000000000..c9ea023618712 --- /dev/null +++ b/tests/baselines/reference/ES5For-of37.js @@ -0,0 +1,64 @@ +//// [ES5For-of37.ts] +// https://github.com/microsoft/TypeScript/issues/30083 + +for (const i of [0, 1, 2, 3, 4]) { + try { + // Ensure catch binding for the following loop is reset per iteration: + for (const j of [1, 2, 3]) { + if (i === 2) { + throw new Error('ERR'); + } + } + console.log(i); + } catch (err) { + console.log('E %s %s', i, err); + } +} + +//// [ES5For-of37.js] +// https://github.com/microsoft/TypeScript/issues/30083 +var __values = (this && this.__values) || function (o) { + var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; + if (m) return m.call(o); + return { + next: function () { + if (o && i >= o.length) o = void 0; + return { value: o && o[i++], done: !o }; + } + }; +}; +var e_1, _a, e_2, _b; +try { + for (var _c = __values([0, 1, 2, 3, 4]), _d = _c.next(); !_d.done; _d = _c.next()) { + var i = _d.value; + try { + try { + // Ensure catch binding for the following loop is reset per iteration: + for (var _e = (e_2 = void 0, __values([1, 2, 3])), _f = _e.next(); !_f.done; _f = _e.next()) { + var j = _f.value; + if (i === 2) { + throw new Error('ERR'); + } + } + } + catch (e_2_1) { e_2 = { error: e_2_1 }; } + finally { + try { + if (_f && !_f.done && (_b = _e["return"])) _b.call(_e); + } + finally { if (e_2) throw e_2.error; } + } + console.log(i); + } + catch (err) { + console.log('E %s %s', i, err); + } + } +} +catch (e_1_1) { e_1 = { error: e_1_1 }; } +finally { + try { + if (_d && !_d.done && (_a = _c["return"])) _a.call(_c); + } + finally { if (e_1) throw e_1.error; } +} diff --git a/tests/baselines/reference/ES5For-of37.symbols b/tests/baselines/reference/ES5For-of37.symbols new file mode 100644 index 0000000000000..5c36b44170657 --- /dev/null +++ b/tests/baselines/reference/ES5For-of37.symbols @@ -0,0 +1,35 @@ +=== tests/cases/conformance/statements/for-ofStatements/ES5For-of37.ts === +// https://github.com/microsoft/TypeScript/issues/30083 + +for (const i of [0, 1, 2, 3, 4]) { +>i : Symbol(i, Decl(ES5For-of37.ts, 2, 10)) + + try { + // Ensure catch binding for the following loop is reset per iteration: + for (const j of [1, 2, 3]) { +>j : Symbol(j, Decl(ES5For-of37.ts, 5, 18)) + + if (i === 2) { +>i : Symbol(i, Decl(ES5For-of37.ts, 2, 10)) + + throw new Error('ERR'); +>Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) + } + } + console.log(i); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>i : Symbol(i, Decl(ES5For-of37.ts, 2, 10)) + + } catch (err) { +>err : Symbol(err, Decl(ES5For-of37.ts, 11, 13)) + + console.log('E %s %s', i, err); +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>i : Symbol(i, Decl(ES5For-of37.ts, 2, 10)) +>err : Symbol(err, Decl(ES5For-of37.ts, 11, 13)) + } +} diff --git a/tests/baselines/reference/ES5For-of37.types b/tests/baselines/reference/ES5For-of37.types new file mode 100644 index 0000000000000..2488857382ed3 --- /dev/null +++ b/tests/baselines/reference/ES5For-of37.types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/statements/for-ofStatements/ES5For-of37.ts === +// https://github.com/microsoft/TypeScript/issues/30083 + +for (const i of [0, 1, 2, 3, 4]) { +>i : number +>[0, 1, 2, 3, 4] : number[] +>0 : 0 +>1 : 1 +>2 : 2 +>3 : 3 +>4 : 4 + + try { + // Ensure catch binding for the following loop is reset per iteration: + for (const j of [1, 2, 3]) { +>j : number +>[1, 2, 3] : number[] +>1 : 1 +>2 : 2 +>3 : 3 + + if (i === 2) { +>i === 2 : boolean +>i : number +>2 : 2 + + throw new Error('ERR'); +>new Error('ERR') : Error +>Error : ErrorConstructor +>'ERR' : "ERR" + } + } + console.log(i); +>console.log(i) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>i : number + + } catch (err) { +>err : any + + console.log('E %s %s', i, err); +>console.log('E %s %s', i, err) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>'E %s %s' : "E %s %s" +>i : number +>err : any + } +} diff --git a/tests/cases/conformance/statements/for-ofStatements/ES5For-of37.ts b/tests/cases/conformance/statements/for-ofStatements/ES5For-of37.ts new file mode 100644 index 0000000000000..6ac37924016bc --- /dev/null +++ b/tests/cases/conformance/statements/for-ofStatements/ES5For-of37.ts @@ -0,0 +1,16 @@ +// @downlevelIteration: true +// https://github.com/microsoft/TypeScript/issues/30083 + +for (const i of [0, 1, 2, 3, 4]) { + try { + // Ensure catch binding for the following loop is reset per iteration: + for (const j of [1, 2, 3]) { + if (i === 2) { + throw new Error('ERR'); + } + } + console.log(i); + } catch (err) { + console.log('E %s %s', i, err); + } +} \ No newline at end of file From c3055e585d014a65319a548b52a0b01c0cfbbe83 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 22 May 2019 11:20:07 -0700 Subject: [PATCH 22/43] Fix compiler crash with object rest in catch binding (#31522) --- src/compiler/checker.ts | 7 +++++- src/compiler/transformers/es2018.ts | 24 +++++++++++++++++++ .../baselines/reference/objectRestCatchES5.js | 21 ++++++++++++++++ .../reference/objectRestCatchES5.symbols | 9 +++++++ .../reference/objectRestCatchES5.types | 11 +++++++++ .../types/rest/objectRestCatchES5.ts | 2 ++ 6 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/objectRestCatchES5.js create mode 100644 tests/baselines/reference/objectRestCatchES5.symbols create mode 100644 tests/baselines/reference/objectRestCatchES5.types create mode 100644 tests/cases/conformance/types/rest/objectRestCatchES5.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 9e5c864f6b975..fe17a6fbfedc5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -30169,12 +30169,17 @@ namespace ts { return undefined; } + function isSymbolOfDestructuredElementOfCatchBinding(symbol: Symbol) { + return isBindingElement(symbol.valueDeclaration) + && walkUpBindingElementsAndPatterns(symbol.valueDeclaration).parent.kind === SyntaxKind.CatchClause; + } + function isSymbolOfDeclarationWithCollidingName(symbol: Symbol): boolean { if (symbol.flags & SymbolFlags.BlockScoped && !isSourceFile(symbol.valueDeclaration)) { const links = getSymbolLinks(symbol); if (links.isDeclarationWithCollidingName === undefined) { const container = getEnclosingBlockScopeContainer(symbol.valueDeclaration); - if (isStatementWithLocals(container)) { + if (isStatementWithLocals(container) || isSymbolOfDestructuredElementOfCatchBinding(symbol)) { const nodeLinks = getNodeLinks(symbol.valueDeclaration); if (resolveName(container.parent, symbol.escapedName, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false)) { // redeclaration - always should be renamed diff --git a/src/compiler/transformers/es2018.ts b/src/compiler/transformers/es2018.ts index 504870b4ff784..89c43dcf599cf 100644 --- a/src/compiler/transformers/es2018.ts +++ b/src/compiler/transformers/es2018.ts @@ -77,6 +77,8 @@ namespace ts { return visitObjectLiteralExpression(node as ObjectLiteralExpression); case SyntaxKind.BinaryExpression: return visitBinaryExpression(node as BinaryExpression, noDestructuringValue); + case SyntaxKind.CatchClause: + return visitCatchClause(node as CatchClause); case SyntaxKind.VariableDeclaration: return visitVariableDeclaration(node as VariableDeclaration); case SyntaxKind.ForOfStatement: @@ -272,6 +274,28 @@ namespace ts { return visitEachChild(node, visitor, context); } + function visitCatchClause(node: CatchClause) { + if (node.variableDeclaration && + isBindingPattern(node.variableDeclaration.name) && + node.variableDeclaration.name.transformFlags & TransformFlags.ContainsObjectRestOrSpread) { + const name = getGeneratedNameForNode(node.variableDeclaration.name); + const updatedDecl = updateVariableDeclaration(node.variableDeclaration, node.variableDeclaration.name, /*type*/ undefined, name); + const visitedBindings = flattenDestructuringBinding(updatedDecl, visitor, context, FlattenLevel.ObjectRest); + let block = visitNode(node.block, visitor, isBlock); + if (some(visitedBindings)) { + block = updateBlock(block, [ + createVariableStatement(/*modifiers*/ undefined, visitedBindings), + ...block.statements, + ]); + } + return updateCatchClause( + node, + updateVariableDeclaration(node.variableDeclaration, name, /*type*/ undefined, /*initializer*/ undefined), + block); + } + return visitEachChild(node, visitor, context); + } + /** * Visits a VariableDeclaration node with a binding pattern. * diff --git a/tests/baselines/reference/objectRestCatchES5.js b/tests/baselines/reference/objectRestCatchES5.js new file mode 100644 index 0000000000000..210e8cec3bfea --- /dev/null +++ b/tests/baselines/reference/objectRestCatchES5.js @@ -0,0 +1,21 @@ +//// [objectRestCatchES5.ts] +let a = 1, b = 2; +try {} catch ({ a, ...b }) {} + +//// [objectRestCatchES5.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var a = 1, b = 2; +try { } +catch (_a) { + var a_1 = _a.a, b_1 = __rest(_a, ["a"]); +} diff --git a/tests/baselines/reference/objectRestCatchES5.symbols b/tests/baselines/reference/objectRestCatchES5.symbols new file mode 100644 index 0000000000000..007424bd6c32c --- /dev/null +++ b/tests/baselines/reference/objectRestCatchES5.symbols @@ -0,0 +1,9 @@ +=== tests/cases/conformance/types/rest/objectRestCatchES5.ts === +let a = 1, b = 2; +>a : Symbol(a, Decl(objectRestCatchES5.ts, 0, 3)) +>b : Symbol(b, Decl(objectRestCatchES5.ts, 0, 10)) + +try {} catch ({ a, ...b }) {} +>a : Symbol(a, Decl(objectRestCatchES5.ts, 1, 15)) +>b : Symbol(b, Decl(objectRestCatchES5.ts, 1, 18)) + diff --git a/tests/baselines/reference/objectRestCatchES5.types b/tests/baselines/reference/objectRestCatchES5.types new file mode 100644 index 0000000000000..3d6b0a3e69530 --- /dev/null +++ b/tests/baselines/reference/objectRestCatchES5.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/types/rest/objectRestCatchES5.ts === +let a = 1, b = 2; +>a : number +>1 : 1 +>b : number +>2 : 2 + +try {} catch ({ a, ...b }) {} +>a : any +>b : any + diff --git a/tests/cases/conformance/types/rest/objectRestCatchES5.ts b/tests/cases/conformance/types/rest/objectRestCatchES5.ts new file mode 100644 index 0000000000000..0e568d32b5863 --- /dev/null +++ b/tests/cases/conformance/types/rest/objectRestCatchES5.ts @@ -0,0 +1,2 @@ +let a = 1, b = 2; +try {} catch ({ a, ...b }) {} \ No newline at end of file From 3d2af9ff332fca6c5db2390be0b1f08bba8402a1 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 22 May 2019 11:20:29 -0700 Subject: [PATCH 23/43] Relocate Debug namespace to reduce duplication (#31524) --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 4 +- src/compiler/core.ts | 83 ------ src/compiler/debug.ts | 261 ++++++++++++++++++ src/compiler/tsconfig.json | 1 + src/compiler/utilities.ts | 97 +------ src/compiler/visitor.ts | 96 ------- .../codefixes/addNameToNamelessParameter.ts | 4 +- src/services/findAllReferences.ts | 2 +- src/services/importTracker.ts | 4 +- src/services/services.ts | 2 +- src/services/signatureHelp.ts | 2 +- src/testRunner/unittests/factory.ts | 2 +- 13 files changed, 274 insertions(+), 286 deletions(-) create mode 100644 src/compiler/debug.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index cb6f67d66b1df..4540a4409d65b 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2515,7 +2515,7 @@ namespace ts { break; default: - Debug.fail(Debug.showSyntaxKind(thisContainer)); + Debug.failBadSyntaxKind(thisContainer); } } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fe17a6fbfedc5..129a79a7c11fb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5695,7 +5695,7 @@ namespace ts { type = getTypeOfEnumMember(symbol); } else { - return Debug.fail("Unhandled declaration kind! " + Debug.showSyntaxKind(declaration) + " for " + Debug.showSymbol(symbol)); + return Debug.fail("Unhandled declaration kind! " + Debug.formatSyntaxKind(declaration.kind) + " for " + Debug.formatSymbol(symbol)); } if (!popTypeResolution()) { @@ -25536,7 +25536,7 @@ namespace ts { case SyntaxKind.ImportSpecifier: // https://github.com/Microsoft/TypeScript/pull/7591 return DeclarationSpaces.ExportValue; default: - return Debug.fail(Debug.showSyntaxKind(d)); + return Debug.failBadSyntaxKind(d); } } } diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 2dfc7acf18826..0034c275999c6 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -1686,89 +1686,6 @@ namespace ts { export type AnyFunction = (...args: never[]) => void; export type AnyConstructor = new (...args: unknown[]) => unknown; - export namespace Debug { - export let currentAssertionLevel = AssertionLevel.None; - export let isDebugging = false; - - export function shouldAssert(level: AssertionLevel): boolean { - return currentAssertionLevel >= level; - } - - export function assert(expression: boolean, message?: string, verboseDebugInfo?: string | (() => string), stackCrawlMark?: AnyFunction): void { - if (!expression) { - if (verboseDebugInfo) { - message += "\r\nVerbose Debug Information: " + (typeof verboseDebugInfo === "string" ? verboseDebugInfo : verboseDebugInfo()); - } - fail(message ? "False expression: " + message : "False expression.", stackCrawlMark || assert); - } - } - - export function assertEqual(a: T, b: T, msg?: string, msg2?: string): void { - if (a !== b) { - const message = msg ? msg2 ? `${msg} ${msg2}` : msg : ""; - fail(`Expected ${a} === ${b}. ${message}`); - } - } - - export function assertLessThan(a: number, b: number, msg?: string): void { - if (a >= b) { - fail(`Expected ${a} < ${b}. ${msg || ""}`); - } - } - - export function assertLessThanOrEqual(a: number, b: number): void { - if (a > b) { - fail(`Expected ${a} <= ${b}`); - } - } - - export function assertGreaterThanOrEqual(a: number, b: number): void { - if (a < b) { - fail(`Expected ${a} >= ${b}`); - } - } - - export function fail(message?: string, stackCrawlMark?: AnyFunction): never { - debugger; - const e = new Error(message ? `Debug Failure. ${message}` : "Debug Failure."); - if ((Error).captureStackTrace) { - (Error).captureStackTrace(e, stackCrawlMark || fail); - } - throw e; - } - - export function assertDefined(value: T | null | undefined, message?: string): T { - if (value === undefined || value === null) return fail(message); - return value; - } - - export function assertEachDefined>(value: A, message?: string): A { - for (const v of value) { - assertDefined(v, message); - } - return value; - } - - export function assertNever(member: never, message = "Illegal value:", stackCrawlMark?: AnyFunction): never { - const detail = typeof member === "object" && "kind" in member && "pos" in member ? "SyntaxKind: " + showSyntaxKind(member as Node) : JSON.stringify(member); - return fail(`${message} ${detail}`, stackCrawlMark || assertNever); - } - - export function getFunctionName(func: AnyFunction) { - if (typeof func !== "function") { - return ""; - } - else if (func.hasOwnProperty("name")) { - return (func).name; - } - else { - const text = Function.prototype.toString.call(func); - const match = /^function\s+([\w\$]+)\s*\(/.exec(text); - return match ? match[1] : ""; - } - } - } - export function equateValues(a: T, b: T) { return a === b; } diff --git a/src/compiler/debug.ts b/src/compiler/debug.ts new file mode 100644 index 0000000000000..ee6847133c114 --- /dev/null +++ b/src/compiler/debug.ts @@ -0,0 +1,261 @@ +/* @internal */ +namespace ts { + export namespace Debug { + export let currentAssertionLevel = AssertionLevel.None; + export let isDebugging = false; + + export function shouldAssert(level: AssertionLevel): boolean { + return currentAssertionLevel >= level; + } + + export function assert(expression: boolean, message?: string, verboseDebugInfo?: string | (() => string), stackCrawlMark?: AnyFunction): void { + if (!expression) { + if (verboseDebugInfo) { + message += "\r\nVerbose Debug Information: " + (typeof verboseDebugInfo === "string" ? verboseDebugInfo : verboseDebugInfo()); + } + fail(message ? "False expression: " + message : "False expression.", stackCrawlMark || assert); + } + } + + export function assertEqual(a: T, b: T, msg?: string, msg2?: string): void { + if (a !== b) { + const message = msg ? msg2 ? `${msg} ${msg2}` : msg : ""; + fail(`Expected ${a} === ${b}. ${message}`); + } + } + + export function assertLessThan(a: number, b: number, msg?: string): void { + if (a >= b) { + fail(`Expected ${a} < ${b}. ${msg || ""}`); + } + } + + export function assertLessThanOrEqual(a: number, b: number): void { + if (a > b) { + fail(`Expected ${a} <= ${b}`); + } + } + + export function assertGreaterThanOrEqual(a: number, b: number): void { + if (a < b) { + fail(`Expected ${a} >= ${b}`); + } + } + + export function fail(message?: string, stackCrawlMark?: AnyFunction): never { + debugger; + const e = new Error(message ? `Debug Failure. ${message}` : "Debug Failure."); + if ((Error).captureStackTrace) { + (Error).captureStackTrace(e, stackCrawlMark || fail); + } + throw e; + } + + export function assertDefined(value: T | null | undefined, message?: string): T { + if (value === undefined || value === null) return fail(message); + return value; + } + + export function assertEachDefined>(value: A, message?: string): A { + for (const v of value) { + assertDefined(v, message); + } + return value; + } + + export function assertNever(member: never, message = "Illegal value:", stackCrawlMark?: AnyFunction): never { + const detail = typeof member === "object" && "kind" in member && "pos" in member && formatSyntaxKind ? "SyntaxKind: " + formatSyntaxKind((member as Node).kind) : JSON.stringify(member); + return fail(`${message} ${detail}`, stackCrawlMark || assertNever); + } + + export function getFunctionName(func: AnyFunction) { + if (typeof func !== "function") { + return ""; + } + else if (func.hasOwnProperty("name")) { + return (func).name; + } + else { + const text = Function.prototype.toString.call(func); + const match = /^function\s+([\w\$]+)\s*\(/.exec(text); + return match ? match[1] : ""; + } + } + + export function formatSymbol(symbol: Symbol): string { + return `{ name: ${unescapeLeadingUnderscores(symbol.escapedName)}; flags: ${formatSymbolFlags(symbol.flags)}; declarations: ${map(symbol.declarations, node => formatSyntaxKind(node.kind))} }`; + } + + /** + * Formats an enum value as a string for debugging and debug assertions. + */ + export function formatEnum(value = 0, enumObject: any, isFlags?: boolean) { + const members = getEnumMembers(enumObject); + if (value === 0) { + return members.length > 0 && members[0][0] === 0 ? members[0][1] : "0"; + } + if (isFlags) { + let result = ""; + let remainingFlags = value; + for (let i = members.length - 1; i >= 0 && remainingFlags !== 0; i--) { + const [enumValue, enumName] = members[i]; + if (enumValue !== 0 && (remainingFlags & enumValue) === enumValue) { + remainingFlags &= ~enumValue; + result = `${enumName}${result ? "|" : ""}${result}`; + } + } + if (remainingFlags === 0) { + return result; + } + } + else { + for (const [enumValue, enumName] of members) { + if (enumValue === value) { + return enumName; + } + } + } + return value.toString(); + } + + function getEnumMembers(enumObject: any) { + const result: [number, string][] = []; + for (const name in enumObject) { + const value = enumObject[name]; + if (typeof value === "number") { + result.push([value, name]); + } + } + + return stableSort<[number, string]>(result, (x, y) => compareValues(x[0], y[0])); + } + + export function formatSyntaxKind(kind: SyntaxKind | undefined): string { + return formatEnum(kind, (ts).SyntaxKind, /*isFlags*/ false); + } + + export function formatNodeFlags(flags: NodeFlags | undefined): string { + return formatEnum(flags, (ts).NodeFlags, /*isFlags*/ true); + } + + export function formatModifierFlags(flags: ModifierFlags | undefined): string { + return formatEnum(flags, (ts).ModifierFlags, /*isFlags*/ true); + } + + export function formatTransformFlags(flags: TransformFlags | undefined): string { + return formatEnum(flags, (ts).TransformFlags, /*isFlags*/ true); + } + + export function formatEmitFlags(flags: EmitFlags | undefined): string { + return formatEnum(flags, (ts).EmitFlags, /*isFlags*/ true); + } + + export function formatSymbolFlags(flags: SymbolFlags | undefined): string { + return formatEnum(flags, (ts).SymbolFlags, /*isFlags*/ true); + } + + export function formatTypeFlags(flags: TypeFlags | undefined): string { + return formatEnum(flags, (ts).TypeFlags, /*isFlags*/ true); + } + + export function formatObjectFlags(flags: ObjectFlags | undefined): string { + return formatEnum(flags, (ts).ObjectFlags, /*isFlags*/ true); + } + + export function failBadSyntaxKind(node: Node, message?: string): never { + return fail( + `${message || "Unexpected node."}\r\nNode ${formatSyntaxKind(node.kind)} was unexpected.`, + failBadSyntaxKind); + } + + export const assertEachNode = shouldAssert(AssertionLevel.Normal) + ? (nodes: Node[], test: (node: Node) => boolean, message?: string): void => assert( + test === undefined || every(nodes, test), + message || "Unexpected node.", + () => `Node array did not pass test '${getFunctionName(test)}'.`, + assertEachNode) + : noop; + + export const assertNode = shouldAssert(AssertionLevel.Normal) + ? (node: Node | undefined, test: ((node: Node | undefined) => boolean) | undefined, message?: string): void => assert( + test === undefined || test(node), + message || "Unexpected node.", + () => `Node ${formatSyntaxKind(node!.kind)} did not pass test '${getFunctionName(test!)}'.`, + assertNode) + : noop; + + export const assertOptionalNode = shouldAssert(AssertionLevel.Normal) + ? (node: Node, test: (node: Node) => boolean, message?: string): void => assert( + test === undefined || node === undefined || test(node), + message || "Unexpected node.", + () => `Node ${formatSyntaxKind(node.kind)} did not pass test '${getFunctionName(test)}'.`, + assertOptionalNode) + : noop; + + export const assertOptionalToken = shouldAssert(AssertionLevel.Normal) + ? (node: Node, kind: SyntaxKind, message?: string): void => assert( + kind === undefined || node === undefined || node.kind === kind, + message || "Unexpected node.", + () => `Node ${formatSyntaxKind(node.kind)} was not a '${formatSyntaxKind(kind)}' token.`, + assertOptionalToken) + : noop; + + export const assertMissingNode = shouldAssert(AssertionLevel.Normal) + ? (node: Node, message?: string): void => assert( + node === undefined, + message || "Unexpected node.", + () => `Node ${formatSyntaxKind(node.kind)} was unexpected'.`, + assertMissingNode) + : noop; + + let isDebugInfoEnabled = false; + + /** + * Injects debug information into frequently used types. + */ + export function enableDebugInfo() { + if (isDebugInfoEnabled) return; + + // Add additional properties in debug mode to assist with debugging. + Object.defineProperties(objectAllocator.getSymbolConstructor().prototype, { + __debugFlags: { get(this: Symbol) { return formatSymbolFlags(this.flags); } } + }); + + Object.defineProperties(objectAllocator.getTypeConstructor().prototype, { + __debugFlags: { get(this: Type) { return formatTypeFlags(this.flags); } }, + __debugObjectFlags: { get(this: Type) { return this.flags & TypeFlags.Object ? formatObjectFlags((this).objectFlags) : ""; } }, + __debugTypeToString: { value(this: Type) { return this.checker.typeToString(this); } }, + }); + + const nodeConstructors = [ + objectAllocator.getNodeConstructor(), + objectAllocator.getIdentifierConstructor(), + objectAllocator.getTokenConstructor(), + objectAllocator.getSourceFileConstructor() + ]; + + for (const ctor of nodeConstructors) { + if (!ctor.prototype.hasOwnProperty("__debugKind")) { + Object.defineProperties(ctor.prototype, { + __debugKind: { get(this: Node) { return formatSyntaxKind(this.kind); } }, + __debugNodeFlags: { get(this: Node) { return formatNodeFlags(this.flags); } }, + __debugModifierFlags: { get(this: Node) { return formatModifierFlags(getModifierFlagsNoCache(this)); } }, + __debugTransformFlags: { get(this: Node) { return formatTransformFlags(this.transformFlags); } }, + __debugIsParseTreeNode: { get(this: Node) { return isParseTreeNode(this); } }, + __debugEmitFlags: { get(this: Node) { return formatEmitFlags(getEmitFlags(this)); } }, + __debugGetText: { + value(this: Node, includeTrivia?: boolean) { + if (nodeIsSynthesized(this)) return ""; + const parseNode = getParseTreeNode(this); + const sourceFile = parseNode && getSourceFileOfNode(parseNode); + return sourceFile ? getSourceTextOfNodeFromSourceFile(sourceFile, parseNode, includeTrivia) : ""; + } + } + }); + } + } + + isDebugInfoEnabled = true; + } + } +} \ No newline at end of file diff --git a/src/compiler/tsconfig.json b/src/compiler/tsconfig.json index 18934aa9bb1cd..fdc0ff2969f7d 100644 --- a/src/compiler/tsconfig.json +++ b/src/compiler/tsconfig.json @@ -8,6 +8,7 @@ "files": [ "core.ts", + "debug.ts", "performance.ts", "semver.ts", diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index ac3be6d434bbd..0ec81502cf799 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -2073,7 +2073,7 @@ namespace ts { } export function importFromModuleSpecifier(node: StringLiteralLike): AnyValidImportOrReExport { - return tryGetImportFromModuleSpecifier(node) || Debug.fail(Debug.showSyntaxKind(node.parent)); + return tryGetImportFromModuleSpecifier(node) || Debug.failBadSyntaxKind(node.parent); } export function tryGetImportFromModuleSpecifier(node: StringLiteralLike): AnyValidImportOrReExport | undefined { @@ -4186,78 +4186,6 @@ namespace ts { return getNewLine ? getNewLine() : sys ? sys.newLine : carriageReturnLineFeed; } - /** - * Formats an enum value as a string for debugging and debug assertions. - */ - function formatEnum(value = 0, enumObject: any, isFlags?: boolean) { - const members = getEnumMembers(enumObject); - if (value === 0) { - return members.length > 0 && members[0][0] === 0 ? members[0][1] : "0"; - } - if (isFlags) { - let result = ""; - let remainingFlags = value; - for (let i = members.length - 1; i >= 0 && remainingFlags !== 0; i--) { - const [enumValue, enumName] = members[i]; - if (enumValue !== 0 && (remainingFlags & enumValue) === enumValue) { - remainingFlags &= ~enumValue; - result = `${enumName}${result ? ", " : ""}${result}`; - } - } - if (remainingFlags === 0) { - return result; - } - } - else { - for (const [enumValue, enumName] of members) { - if (enumValue === value) { - return enumName; - } - } - } - return value.toString(); - } - - function getEnumMembers(enumObject: any) { - const result: [number, string][] = []; - for (const name in enumObject) { - const value = enumObject[name]; - if (typeof value === "number") { - result.push([value, name]); - } - } - - return stableSort<[number, string]>(result, (x, y) => compareValues(x[0], y[0])); - } - - export function formatSyntaxKind(kind: SyntaxKind | undefined): string { - return formatEnum(kind, (ts).SyntaxKind, /*isFlags*/ false); - } - - export function formatModifierFlags(flags: ModifierFlags | undefined): string { - return formatEnum(flags, (ts).ModifierFlags, /*isFlags*/ true); - } - - export function formatTransformFlags(flags: TransformFlags | undefined): string { - return formatEnum(flags, (ts).TransformFlags, /*isFlags*/ true); - } - - export function formatEmitFlags(flags: EmitFlags | undefined): string { - return formatEnum(flags, (ts).EmitFlags, /*isFlags*/ true); - } - - export function formatSymbolFlags(flags: SymbolFlags | undefined): string { - return formatEnum(flags, (ts).SymbolFlags, /*isFlags*/ true); - } - - export function formatTypeFlags(flags: TypeFlags | undefined): string { - return formatEnum(flags, (ts).TypeFlags, /*isFlags*/ true); - } - - export function formatObjectFlags(flags: ObjectFlags | undefined): string { - return formatEnum(flags, (ts).ObjectFlags, /*isFlags*/ true); - } - /** * Creates a new TextRange from the provided pos and end. * @@ -8428,29 +8356,6 @@ namespace ts { return pathext ? path.slice(0, path.length - pathext.length) + (startsWith(ext, ".") ? ext : "." + ext) : path; } - export namespace Debug { - export function showSymbol(symbol: Symbol): string { - const symbolFlags = (ts as any).SymbolFlags; - return `{ flags: ${symbolFlags ? showFlags(symbol.flags, symbolFlags) : symbol.flags}; declarations: ${map(symbol.declarations, showSyntaxKind)} }`; - } - - function showFlags(flags: number, flagsEnum: { [flag: number]: string }): string { - const out: string[] = []; - for (let pow = 0; pow <= 30; pow++) { - const n = 1 << pow; - if (flags & n) { - out.push(flagsEnum[n]); - } - } - return out.join("|"); - } - - export function showSyntaxKind(node: Node): string { - const syntaxKind = (ts as any).SyntaxKind; - return syntaxKind ? syntaxKind[node.kind] : node.kind.toString(); - } - } - export function tryParsePattern(pattern: string): Pattern | undefined { // This should be verified outside of here and a proper error thrown. Debug.assert(hasZeroOrOneAsteriskCharacter(pattern)); diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 0cb3b2691057e..53ccd81f7a6a3 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -1558,100 +1558,4 @@ namespace ts { function aggregateTransformFlagsForChildNodes(transformFlags: TransformFlags, nodes: NodeArray): TransformFlags { return transformFlags | aggregateTransformFlagsForNodeArray(nodes); } - - export namespace Debug { - let isDebugInfoEnabled = false; - - export function failBadSyntaxKind(node: Node, message?: string): never { - return fail( - `${message || "Unexpected node."}\r\nNode ${formatSyntaxKind(node.kind)} was unexpected.`, - failBadSyntaxKind); - } - - export const assertEachNode = shouldAssert(AssertionLevel.Normal) - ? (nodes: Node[], test: (node: Node) => boolean, message?: string): void => assert( - test === undefined || every(nodes, test), - message || "Unexpected node.", - () => `Node array did not pass test '${getFunctionName(test)}'.`, - assertEachNode) - : noop; - - export const assertNode = shouldAssert(AssertionLevel.Normal) - ? (node: Node | undefined, test: ((node: Node | undefined) => boolean) | undefined, message?: string): void => assert( - test === undefined || test(node), - message || "Unexpected node.", - () => `Node ${formatSyntaxKind(node!.kind)} did not pass test '${getFunctionName(test!)}'.`, - assertNode) - : noop; - - export const assertOptionalNode = shouldAssert(AssertionLevel.Normal) - ? (node: Node, test: (node: Node) => boolean, message?: string): void => assert( - test === undefined || node === undefined || test(node), - message || "Unexpected node.", - () => `Node ${formatSyntaxKind(node.kind)} did not pass test '${getFunctionName(test)}'.`, - assertOptionalNode) - : noop; - - export const assertOptionalToken = shouldAssert(AssertionLevel.Normal) - ? (node: Node, kind: SyntaxKind, message?: string): void => assert( - kind === undefined || node === undefined || node.kind === kind, - message || "Unexpected node.", - () => `Node ${formatSyntaxKind(node.kind)} was not a '${formatSyntaxKind(kind)}' token.`, - assertOptionalToken) - : noop; - - export const assertMissingNode = shouldAssert(AssertionLevel.Normal) - ? (node: Node, message?: string): void => assert( - node === undefined, - message || "Unexpected node.", - () => `Node ${formatSyntaxKind(node.kind)} was unexpected'.`, - assertMissingNode) - : noop; - - /** - * Injects debug information into frequently used types. - */ - export function enableDebugInfo() { - if (isDebugInfoEnabled) return; - - // Add additional properties in debug mode to assist with debugging. - Object.defineProperties(objectAllocator.getSymbolConstructor().prototype, { - __debugFlags: { get(this: Symbol) { return formatSymbolFlags(this.flags); } } - }); - - Object.defineProperties(objectAllocator.getTypeConstructor().prototype, { - __debugFlags: { get(this: Type) { return formatTypeFlags(this.flags); } }, - __debugObjectFlags: { get(this: Type) { return this.flags & TypeFlags.Object ? formatObjectFlags((this).objectFlags) : ""; } }, - __debugTypeToString: { value(this: Type) { return this.checker.typeToString(this); } }, - }); - - const nodeConstructors = [ - objectAllocator.getNodeConstructor(), - objectAllocator.getIdentifierConstructor(), - objectAllocator.getTokenConstructor(), - objectAllocator.getSourceFileConstructor() - ]; - - for (const ctor of nodeConstructors) { - if (!ctor.prototype.hasOwnProperty("__debugKind")) { - Object.defineProperties(ctor.prototype, { - __debugKind: { get(this: Node) { return formatSyntaxKind(this.kind); } }, - __debugModifierFlags: { get(this: Node) { return formatModifierFlags(getModifierFlagsNoCache(this)); } }, - __debugTransformFlags: { get(this: Node) { return formatTransformFlags(this.transformFlags); } }, - __debugEmitFlags: { get(this: Node) { return formatEmitFlags(getEmitFlags(this)); } }, - __debugGetText: { - value(this: Node, includeTrivia?: boolean) { - if (nodeIsSynthesized(this)) return ""; - const parseNode = getParseTreeNode(this); - const sourceFile = parseNode && getSourceFileOfNode(parseNode); - return sourceFile ? getSourceTextOfNodeFromSourceFile(sourceFile, parseNode, includeTrivia) : ""; - } - } - }); - } - } - - isDebugInfoEnabled = true; - } - } } diff --git a/src/services/codefixes/addNameToNamelessParameter.ts b/src/services/codefixes/addNameToNamelessParameter.ts index f87816ab22864..3339f71900845 100644 --- a/src/services/codefixes/addNameToNamelessParameter.ts +++ b/src/services/codefixes/addNameToNamelessParameter.ts @@ -15,11 +15,11 @@ namespace ts.codefix { function makeChange(changeTracker: textChanges.ChangeTracker, sourceFile: SourceFile, pos: number) { const token = getTokenAtPosition(sourceFile, pos); if (!isIdentifier(token)) { - return Debug.fail("add-name-to-nameless-parameter operates on identifiers, but got a " + formatSyntaxKind(token.kind)); + return Debug.fail("add-name-to-nameless-parameter operates on identifiers, but got a " + Debug.formatSyntaxKind(token.kind)); } const param = token.parent; if (!isParameter(param)) { - return Debug.fail("Tried to add a parameter name to a non-parameter: " + formatSyntaxKind(token.kind)); + return Debug.fail("Tried to add a parameter name to a non-parameter: " + Debug.formatSyntaxKind(token.kind)); } const i = param.parent.parameters.indexOf(param); Debug.assert(!param.type, "Tried to add a parameter name to a parameter that already had one."); diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 147fee53393c1..cf0046d2688fa 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -635,7 +635,7 @@ namespace ts.FindAllReferences.Core { // Ignore UMD module and global merge if (symbol.flags & SymbolFlags.Transient) return undefined; // Assertions for GH#21814. We should be handling SourceFile symbols in `getReferencedSymbolsForModule` instead of getting here. - Debug.fail(`Unexpected symbol at ${Debug.showSyntaxKind(node)}: ${Debug.showSymbol(symbol)}`); + Debug.fail(`Unexpected symbol at ${Debug.formatSyntaxKind(node.kind)}: ${Debug.formatSymbol(symbol)}`); } return isTypeLiteralNode(decl.parent) && isUnionTypeNode(decl.parent.parent) ? checker.getPropertyOfType(checker.getTypeFromTypeNode(decl.parent.parent), symbol.name) diff --git a/src/services/importTracker.ts b/src/services/importTracker.ts index e8512528af958..2734d05900070 100644 --- a/src/services/importTracker.ts +++ b/src/services/importTracker.ts @@ -133,7 +133,7 @@ namespace ts.FindAllReferences { break; default: - Debug.assertNever(direct, `Unexpected import kind: ${Debug.showSyntaxKind(direct)}`); + Debug.failBadSyntaxKind(direct, "Unexpected import kind."); } } } @@ -515,7 +515,7 @@ namespace ts.FindAllReferences { const sym = useLhsSymbol ? checker.getSymbolAtLocation(cast(node.left, isPropertyAccessExpression).name) : symbol; // Better detection for GH#20803 if (sym && !(checker.getMergedSymbol(sym.parent!).flags & SymbolFlags.Module)) { - Debug.fail(`Special property assignment kind does not have a module as its parent. Assignment is ${Debug.showSymbol(sym)}, parent is ${Debug.showSymbol(sym.parent!)}`); + Debug.fail(`Special property assignment kind does not have a module as its parent. Assignment is ${Debug.formatSymbol(sym)}, parent is ${Debug.formatSymbol(sym.parent!)}`); } return sym && exportInfo(sym, kind); } diff --git a/src/services/services.ts b/src/services/services.ts index 9637b3c5321f6..6c882bbb28f0e 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -173,7 +173,7 @@ namespace ts { const textPos = scanner.getTextPos(); if (textPos <= end) { if (token === SyntaxKind.Identifier) { - Debug.fail(`Did not expect ${Debug.showSyntaxKind(parent)} to have an Identifier in its trivia`); + Debug.fail(`Did not expect ${Debug.formatSyntaxKind(parent.kind)} to have an Identifier in its trivia`); } nodes.push(createNode(token, pos, textPos, parent)); } diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 0c9f76acacb7f..25f958dfc6a75 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -455,7 +455,7 @@ namespace ts.SignatureHelp { for (let n = node; !isSourceFile(n) && (isManuallyInvoked || !isBlock(n)); n = n.parent) { // If the node is not a subspan of its parent, this is a big problem. // There have been crashes that might be caused by this violation. - Debug.assert(rangeContainsRange(n.parent, n), "Not a subspan", () => `Child: ${Debug.showSyntaxKind(n)}, parent: ${Debug.showSyntaxKind(n.parent)}`); + Debug.assert(rangeContainsRange(n.parent, n), "Not a subspan", () => `Child: ${Debug.formatSyntaxKind(n.kind)}, parent: ${Debug.formatSyntaxKind(n.parent.kind)}`); const argumentInfo = getImmediatelyContainingArgumentOrContextualParameterInfo(n, position, sourceFile, checker); if (argumentInfo) { return argumentInfo; diff --git a/src/testRunner/unittests/factory.ts b/src/testRunner/unittests/factory.ts index cc760059c199d..5593b39256707 100644 --- a/src/testRunner/unittests/factory.ts +++ b/src/testRunner/unittests/factory.ts @@ -1,7 +1,7 @@ namespace ts { describe("unittests:: FactoryAPI", () => { function assertSyntaxKind(node: Node, expected: SyntaxKind) { - assert.strictEqual(node.kind, expected, `Actual: ${Debug.showSyntaxKind(node)} Expected: ${(ts as any).SyntaxKind[expected]}`); + assert.strictEqual(node.kind, expected, `Actual: ${Debug.formatSyntaxKind(node.kind)} Expected: ${Debug.formatSyntaxKind(expected)}`); } describe("createExportAssignment", () => { it("parenthesizes default export if necessary", () => { From 6a559e37ee0d660fcc94f086a34370e79e94b17a Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Wed, 22 May 2019 11:20:57 -0700 Subject: [PATCH 24/43] Fix crash when checking invalid object rest (#31530) --- src/compiler/checker.ts | 39 ++++++++++++------- .../objectRestPropertyMustBeLast.errors.txt | 21 ++++++++++ .../reference/objectRestPropertyMustBeLast.js | 25 ++++++++++++ .../objectRestPropertyMustBeLast.symbols | 23 +++++++++++ .../objectRestPropertyMustBeLast.types | 37 ++++++++++++++++++ .../rest/objectRestPropertyMustBeLast.ts | 5 +++ 6 files changed, 136 insertions(+), 14 deletions(-) create mode 100644 tests/baselines/reference/objectRestPropertyMustBeLast.errors.txt create mode 100644 tests/baselines/reference/objectRestPropertyMustBeLast.js create mode 100644 tests/baselines/reference/objectRestPropertyMustBeLast.symbols create mode 100644 tests/baselines/reference/objectRestPropertyMustBeLast.types create mode 100644 tests/cases/conformance/types/rest/objectRestPropertyMustBeLast.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 129a79a7c11fb..05b1015b12428 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -23370,14 +23370,16 @@ namespace ts { if (strictNullChecks && properties.length === 0) { return checkNonNullType(sourceType, node); } - for (const p of properties) { - checkObjectLiteralDestructuringPropertyAssignment(sourceType, p, properties, rightIsThis); + for (let i = 0; i < properties.length; i++) { + checkObjectLiteralDestructuringPropertyAssignment(node, sourceType, i, properties, rightIsThis); } return sourceType; } /** Note: If property cannot be a SpreadAssignment, then allProperties does not need to be provided */ - function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike, allProperties?: NodeArray, rightIsThis = false) { + function checkObjectLiteralDestructuringPropertyAssignment(node: ObjectLiteralExpression, objectLiteralType: Type, propertyIndex: number, allProperties?: NodeArray, rightIsThis = false) { + const properties = node.properties; + const property = properties[propertyIndex]; if (property.kind === SyntaxKind.PropertyAssignment || property.kind === SyntaxKind.ShorthandPropertyAssignment) { const name = property.name; const exprType = getLiteralTypeFromPropertyName(name); @@ -23394,18 +23396,25 @@ namespace ts { return checkDestructuringAssignment(property.kind === SyntaxKind.ShorthandPropertyAssignment ? property : property.initializer, type); } else if (property.kind === SyntaxKind.SpreadAssignment) { - if (languageVersion < ScriptTarget.ESNext) { - checkExternalEmitHelpers(property, ExternalEmitHelpers.Rest); + if (propertyIndex < properties.length - 1) { + error(property, Diagnostics.A_rest_element_must_be_last_in_a_destructuring_pattern); } - const nonRestNames: PropertyName[] = []; - if (allProperties) { - for (let i = 0; i < allProperties.length - 1; i++) { - nonRestNames.push(allProperties[i].name!); + else { + if (languageVersion < ScriptTarget.ESNext) { + checkExternalEmitHelpers(property, ExternalEmitHelpers.Rest); + } + const nonRestNames: PropertyName[] = []; + if (allProperties) { + for (const otherProperty of allProperties) { + if (!isSpreadAssignment(otherProperty)) { + nonRestNames.push(otherProperty.name); + } + } } + const type = getRestType(objectLiteralType, nonRestNames, objectLiteralType.symbol); + checkGrammarForDisallowedTrailingComma(allProperties, Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma); + return checkDestructuringAssignment(property.expression, type); } - const type = getRestType(objectLiteralType, nonRestNames, objectLiteralType.symbol); - checkGrammarForDisallowedTrailingComma(allProperties, Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma); - return checkDestructuringAssignment(property.expression, type); } else { error(property, Diagnostics.Property_assignment_expected); @@ -29964,8 +29973,10 @@ namespace ts { // If this is from nested object binding pattern // for ({ skills: { primary, secondary } } = multiRobot, i = 0; i < 1; i++) { if (expr.parent.kind === SyntaxKind.PropertyAssignment) { - const typeOfParentObjectLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(expr.parent.parent); - return checkObjectLiteralDestructuringPropertyAssignment(typeOfParentObjectLiteral || errorType, expr.parent)!; // TODO: GH#18217 + const node = cast(expr.parent.parent, isObjectLiteralExpression); + const typeOfParentObjectLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(node); + const propertyIndex = indexOfNode(node.properties, expr.parent); + return checkObjectLiteralDestructuringPropertyAssignment(node, typeOfParentObjectLiteral || errorType, propertyIndex)!; // TODO: GH#18217 } // Array literal assignment - array destructuring pattern Debug.assert(expr.parent.kind === SyntaxKind.ArrayLiteralExpression); diff --git a/tests/baselines/reference/objectRestPropertyMustBeLast.errors.txt b/tests/baselines/reference/objectRestPropertyMustBeLast.errors.txt new file mode 100644 index 0000000000000..bdcb420dc833a --- /dev/null +++ b/tests/baselines/reference/objectRestPropertyMustBeLast.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/types/rest/objectRestPropertyMustBeLast.ts(1,9): error TS2462: A rest element must be last in a destructuring pattern. +tests/cases/conformance/types/rest/objectRestPropertyMustBeLast.ts(2,3): error TS2462: A rest element must be last in a destructuring pattern. +tests/cases/conformance/types/rest/objectRestPropertyMustBeLast.ts(4,9): error TS2462: A rest element must be last in a destructuring pattern. +tests/cases/conformance/types/rest/objectRestPropertyMustBeLast.ts(5,3): error TS2462: A rest element must be last in a destructuring pattern. + + +==== tests/cases/conformance/types/rest/objectRestPropertyMustBeLast.ts (4 errors) ==== + var {...a, x } = { x: 1 }; // Error, rest must be last property + ~ +!!! error TS2462: A rest element must be last in a destructuring pattern. + ({...a, x } = { x: 1 }); // Error, rest must be last property + ~~~~ +!!! error TS2462: A rest element must be last in a destructuring pattern. + + var {...a, x, ...b } = { x: 1 }; // Error, rest must be last property + ~ +!!! error TS2462: A rest element must be last in a destructuring pattern. + ({...a, x, ...b } = { x: 1 }); // Error, rest must be last property + ~~~~ +!!! error TS2462: A rest element must be last in a destructuring pattern. + \ No newline at end of file diff --git a/tests/baselines/reference/objectRestPropertyMustBeLast.js b/tests/baselines/reference/objectRestPropertyMustBeLast.js new file mode 100644 index 0000000000000..dc91f72dbc7dc --- /dev/null +++ b/tests/baselines/reference/objectRestPropertyMustBeLast.js @@ -0,0 +1,25 @@ +//// [objectRestPropertyMustBeLast.ts] +var {...a, x } = { x: 1 }; // Error, rest must be last property +({...a, x } = { x: 1 }); // Error, rest must be last property + +var {...a, x, ...b } = { x: 1 }; // Error, rest must be last property +({...a, x, ...b } = { x: 1 }); // Error, rest must be last property + + +//// [objectRestPropertyMustBeLast.js] +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var _a, _b; +var _c = { x: 1 }, x = _c.x; // Error, rest must be last property +(_a = { x: 1 }, (x = _a.x, _a)); // Error, rest must be last property +var _d = { x: 1 }, x = _d.x, b = __rest(_d, ["a", "x"]); // Error, rest must be last property +(_b = { x: 1 }, (x = _b.x, _b), b = __rest(_b, ["x"])); // Error, rest must be last property diff --git a/tests/baselines/reference/objectRestPropertyMustBeLast.symbols b/tests/baselines/reference/objectRestPropertyMustBeLast.symbols new file mode 100644 index 0000000000000..7163f2a98c9a2 --- /dev/null +++ b/tests/baselines/reference/objectRestPropertyMustBeLast.symbols @@ -0,0 +1,23 @@ +=== tests/cases/conformance/types/rest/objectRestPropertyMustBeLast.ts === +var {...a, x } = { x: 1 }; // Error, rest must be last property +>a : Symbol(a, Decl(objectRestPropertyMustBeLast.ts, 0, 5), Decl(objectRestPropertyMustBeLast.ts, 3, 5)) +>x : Symbol(x, Decl(objectRestPropertyMustBeLast.ts, 0, 10), Decl(objectRestPropertyMustBeLast.ts, 3, 10)) +>x : Symbol(x, Decl(objectRestPropertyMustBeLast.ts, 0, 18)) + +({...a, x } = { x: 1 }); // Error, rest must be last property +>a : Symbol(a, Decl(objectRestPropertyMustBeLast.ts, 0, 5), Decl(objectRestPropertyMustBeLast.ts, 3, 5)) +>x : Symbol(x, Decl(objectRestPropertyMustBeLast.ts, 1, 7)) +>x : Symbol(x, Decl(objectRestPropertyMustBeLast.ts, 1, 15)) + +var {...a, x, ...b } = { x: 1 }; // Error, rest must be last property +>a : Symbol(a, Decl(objectRestPropertyMustBeLast.ts, 0, 5), Decl(objectRestPropertyMustBeLast.ts, 3, 5)) +>x : Symbol(x, Decl(objectRestPropertyMustBeLast.ts, 0, 10), Decl(objectRestPropertyMustBeLast.ts, 3, 10)) +>b : Symbol(b, Decl(objectRestPropertyMustBeLast.ts, 3, 13)) +>x : Symbol(x, Decl(objectRestPropertyMustBeLast.ts, 3, 24)) + +({...a, x, ...b } = { x: 1 }); // Error, rest must be last property +>a : Symbol(a, Decl(objectRestPropertyMustBeLast.ts, 0, 5), Decl(objectRestPropertyMustBeLast.ts, 3, 5)) +>x : Symbol(x, Decl(objectRestPropertyMustBeLast.ts, 4, 7)) +>b : Symbol(b, Decl(objectRestPropertyMustBeLast.ts, 3, 13)) +>x : Symbol(x, Decl(objectRestPropertyMustBeLast.ts, 4, 21)) + diff --git a/tests/baselines/reference/objectRestPropertyMustBeLast.types b/tests/baselines/reference/objectRestPropertyMustBeLast.types new file mode 100644 index 0000000000000..8f8aafe6e0f19 --- /dev/null +++ b/tests/baselines/reference/objectRestPropertyMustBeLast.types @@ -0,0 +1,37 @@ +=== tests/cases/conformance/types/rest/objectRestPropertyMustBeLast.ts === +var {...a, x } = { x: 1 }; // Error, rest must be last property +>a : {} +>x : number +>{ x: 1 } : { x: number; } +>x : number +>1 : 1 + +({...a, x } = { x: 1 }); // Error, rest must be last property +>({...a, x } = { x: 1 }) : { x: number; } +>{...a, x } = { x: 1 } : { x: number; } +>{...a, x } : { x: number; } +>a : {} +>x : number +>{ x: 1 } : { x: number; } +>x : number +>1 : 1 + +var {...a, x, ...b } = { x: 1 }; // Error, rest must be last property +>a : {} +>x : number +>b : {} +>{ x: 1 } : { x: number; } +>x : number +>1 : 1 + +({...a, x, ...b } = { x: 1 }); // Error, rest must be last property +>({...a, x, ...b } = { x: 1 }) : { x: number; } +>{...a, x, ...b } = { x: 1 } : { x: number; } +>{...a, x, ...b } : { x: number; } +>a : {} +>x : number +>b : {} +>{ x: 1 } : { x: number; } +>x : number +>1 : 1 + diff --git a/tests/cases/conformance/types/rest/objectRestPropertyMustBeLast.ts b/tests/cases/conformance/types/rest/objectRestPropertyMustBeLast.ts new file mode 100644 index 0000000000000..2e4e17dc302ce --- /dev/null +++ b/tests/cases/conformance/types/rest/objectRestPropertyMustBeLast.ts @@ -0,0 +1,5 @@ +var {...a, x } = { x: 1 }; // Error, rest must be last property +({...a, x } = { x: 1 }); // Error, rest must be last property + +var {...a, x, ...b } = { x: 1 }; // Error, rest must be last property +({...a, x, ...b } = { x: 1 }); // Error, rest must be last property From 431f0d6d8c1f803ace4edaf7e0036afcddfd6a11 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 21 May 2019 12:47:36 -0700 Subject: [PATCH 25/43] Add test case for #30429 --- ...ionPackageIdWithRelativeAndAbsolutePath.js | 44 +++++++++++ ...ckageIdWithRelativeAndAbsolutePath.symbols | 48 ++++++++++++ ...geIdWithRelativeAndAbsolutePath.trace.json | 76 +++++++++++++++++++ ...PackageIdWithRelativeAndAbsolutePath.types | 46 +++++++++++ ...ionPackageIdWithRelativeAndAbsolutePath.ts | 51 +++++++++++++ 5 files changed, 265 insertions(+) create mode 100644 tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.js create mode 100644 tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.symbols create mode 100644 tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.trace.json create mode 100644 tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.types create mode 100644 tests/cases/compiler/moduleResolutionPackageIdWithRelativeAndAbsolutePath.ts diff --git a/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.js b/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.js new file mode 100644 index 0000000000000..9f09bea10cf20 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/moduleResolutionPackageIdWithRelativeAndAbsolutePath.ts] //// + +//// [package.json] +{ + "name": "troublesome-lib", + "version": "1.17.1" +} +//// [Compactable.d.ts] +import { Option } from './Option'; +export class Compactable { + option: Option; +} +//// [Option.d.ts] +export class Option { + someProperty: string; +} +//// [app.d.ts] +import { Option } from "troublesome-lib/lib/Option"; +export class SharedOption extends Option { } +export const makeSharedOption: () => SharedOption; +//// [index.d.ts] +import { Compactable } from "troublesome-lib/lib/Compactable"; // Including this will resolve Option as relative through the imports of compactable +//// [package.json] +{ + "name": "troublesome-lib", + "version": "1.17.1" +} +//// [Compactable.d.ts] +import { Option } from './Option'; +export class Compactable { + option: Option; +} +//// [Option.d.ts] +export class Option { + someProperty: string; +} +//// [app.ts] +import * as t from "anotherLib"; // Include the lib that recursively includes option as relative module resolution in this directory +import { makeSharedOption } from "@shared/lib/app"; // Includes option as module in shared folder but as module in node_modules folder + + +//// [/project/src/app.js] +"use strict"; +exports.__esModule = true; diff --git a/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.symbols b/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.symbols new file mode 100644 index 0000000000000..1e4d65e10b364 --- /dev/null +++ b/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.symbols @@ -0,0 +1,48 @@ +=== /project/src/app.ts === +import * as t from "anotherLib"; // Include the lib that recursively includes option as relative module resolution in this directory +>t : Symbol(t, Decl(app.ts, 0, 6)) + +import { makeSharedOption } from "@shared/lib/app"; // Includes option as module in shared folder but as module in node_modules folder +>makeSharedOption : Symbol(makeSharedOption, Decl(app.ts, 1, 8)) + +=== /shared/node_modules/troublesome-lib/lib/Option.d.ts === +export class Option { +>Option : Symbol(Option, Decl(Option.d.ts, 0, 0)) + + someProperty: string; +>someProperty : Symbol(Option.someProperty, Decl(Option.d.ts, 0, 21)) +} +=== /shared/lib/app.d.ts === +import { Option } from "troublesome-lib/lib/Option"; +>Option : Symbol(Option, Decl(app.d.ts, 0, 8)) + +export class SharedOption extends Option { } +>SharedOption : Symbol(SharedOption, Decl(app.d.ts, 0, 52)) +>Option : Symbol(Option, Decl(app.d.ts, 0, 8)) + +export const makeSharedOption: () => SharedOption; +>makeSharedOption : Symbol(makeSharedOption, Decl(app.d.ts, 2, 12)) +>SharedOption : Symbol(SharedOption, Decl(app.d.ts, 0, 52)) + +=== /project/node_modules/anotherLib/index.d.ts === +import { Compactable } from "troublesome-lib/lib/Compactable"; // Including this will resolve Option as relative through the imports of compactable +>Compactable : Symbol(Compactable, Decl(index.d.ts, 0, 8)) + +=== /project/node_modules/troublesome-lib/lib/Compactable.d.ts === +import { Option } from './Option'; +>Option : Symbol(Option, Decl(Compactable.d.ts, 0, 8)) + +export class Compactable { +>Compactable : Symbol(Compactable, Decl(Compactable.d.ts, 0, 34)) + + option: Option; +>option : Symbol(Compactable.option, Decl(Compactable.d.ts, 1, 26)) +>Option : Symbol(Option, Decl(Compactable.d.ts, 0, 8)) +} +=== /project/node_modules/troublesome-lib/lib/Option.d.ts === +export class Option { +>Option : Symbol(Option, Decl(Option.d.ts, 0, 0)) + + someProperty: string; +>someProperty : Symbol(Option.someProperty, Decl(Option.d.ts, 0, 21)) +} diff --git a/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.trace.json b/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.trace.json new file mode 100644 index 0000000000000..b08a0f124565d --- /dev/null +++ b/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.trace.json @@ -0,0 +1,76 @@ +[ + "======== Resolving module 'anotherLib' from '/project/src/app.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'baseUrl' option is set to '/project', using this value to resolve non-relative module name 'anotherLib'.", + "'paths' option is specified, looking for a pattern to match module name 'anotherLib'.", + "'baseUrl' option is set to '/project', using this value to resolve non-relative module name 'anotherLib'.", + "Resolving module name 'anotherLib' relative to base url '/project' - '/project/anotherLib'.", + "Loading module as file / folder, candidate module location '/project/anotherLib', target file type 'TypeScript'.", + "File '/project/anotherLib.ts' does not exist.", + "File '/project/anotherLib.tsx' does not exist.", + "File '/project/anotherLib.d.ts' does not exist.", + "Directory '/project/anotherLib' does not exist, skipping all lookups in it.", + "Loading module 'anotherLib' from 'node_modules' folder, target file type 'TypeScript'.", + "Directory '/project/src/node_modules' does not exist, skipping all lookups in it.", + "File '/project/node_modules/anotherLib/package.json' does not exist.", + "File '/project/node_modules/anotherLib.ts' does not exist.", + "File '/project/node_modules/anotherLib.tsx' does not exist.", + "File '/project/node_modules/anotherLib.d.ts' does not exist.", + "File '/project/node_modules/anotherLib/index.ts' does not exist.", + "File '/project/node_modules/anotherLib/index.tsx' does not exist.", + "File '/project/node_modules/anotherLib/index.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/project/node_modules/anotherLib/index.d.ts', result '/project/node_modules/anotherLib/index.d.ts'.", + "======== Module name 'anotherLib' was successfully resolved to '/project/node_modules/anotherLib/index.d.ts'. ========", + "======== Resolving module '@shared/lib/app' from '/project/src/app.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'baseUrl' option is set to '/project', using this value to resolve non-relative module name '@shared/lib/app'.", + "'paths' option is specified, looking for a pattern to match module name '@shared/lib/app'.", + "Module name '@shared/lib/app', matched pattern '@shared/*'.", + "Trying substitution '../shared/*', candidate module location: '../shared/lib/app'.", + "Loading module as file / folder, candidate module location '/shared/lib/app', target file type 'TypeScript'.", + "File '/shared/lib/app.ts' does not exist.", + "File '/shared/lib/app.tsx' does not exist.", + "File '/shared/lib/app.d.ts' exist - use it as a name resolution result.", + "======== Module name '@shared/lib/app' was successfully resolved to '/shared/lib/app.d.ts'. ========", + "======== Resolving module 'troublesome-lib/lib/Compactable' from '/project/node_modules/anotherLib/index.d.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'baseUrl' option is set to '/project', using this value to resolve non-relative module name 'troublesome-lib/lib/Compactable'.", + "'paths' option is specified, looking for a pattern to match module name 'troublesome-lib/lib/Compactable'.", + "'baseUrl' option is set to '/project', using this value to resolve non-relative module name 'troublesome-lib/lib/Compactable'.", + "Resolving module name 'troublesome-lib/lib/Compactable' relative to base url '/project' - '/project/troublesome-lib/lib/Compactable'.", + "Loading module as file / folder, candidate module location '/project/troublesome-lib/lib/Compactable', target file type 'TypeScript'.", + "Loading module 'troublesome-lib/lib/Compactable' from 'node_modules' folder, target file type 'TypeScript'.", + "Directory '/project/node_modules/anotherLib/node_modules' does not exist, skipping all lookups in it.", + "'package.json' does not have a 'typesVersions' field.", + "Found 'package.json' at '/project/node_modules/troublesome-lib/package.json'. Package ID is 'troublesome-lib/lib/Compactable/index.d.ts@1.17.1'.", + "File '/project/node_modules/troublesome-lib/lib/Compactable.ts' does not exist.", + "File '/project/node_modules/troublesome-lib/lib/Compactable.tsx' does not exist.", + "File '/project/node_modules/troublesome-lib/lib/Compactable.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/project/node_modules/troublesome-lib/lib/Compactable.d.ts', result '/project/node_modules/troublesome-lib/lib/Compactable.d.ts'.", + "======== Module name 'troublesome-lib/lib/Compactable' was successfully resolved to '/project/node_modules/troublesome-lib/lib/Compactable.d.ts'. ========", + "======== Resolving module './Option' from '/project/node_modules/troublesome-lib/lib/Compactable.d.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "Loading module as file / folder, candidate module location '/project/node_modules/troublesome-lib/lib/Option', target file type 'TypeScript'.", + "File '/project/node_modules/troublesome-lib/lib/Option.ts' does not exist.", + "File '/project/node_modules/troublesome-lib/lib/Option.tsx' does not exist.", + "File '/project/node_modules/troublesome-lib/lib/Option.d.ts' exist - use it as a name resolution result.", + "'package.json' does not have a 'typesVersions' field.", + "Found 'package.json' at '/project/node_modules/troublesome-lib/package.json'. Package ID is 'troublesome-lib/lib/Option.d.ts@1.17.1'.", + "======== Module name './Option' was successfully resolved to '/project/node_modules/troublesome-lib/lib/Option.d.ts'. ========", + "======== Resolving module 'troublesome-lib/lib/Option' from '/shared/lib/app.d.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'baseUrl' option is set to '/project', using this value to resolve non-relative module name 'troublesome-lib/lib/Option'.", + "'paths' option is specified, looking for a pattern to match module name 'troublesome-lib/lib/Option'.", + "'baseUrl' option is set to '/project', using this value to resolve non-relative module name 'troublesome-lib/lib/Option'.", + "Resolving module name 'troublesome-lib/lib/Option' relative to base url '/project' - '/project/troublesome-lib/lib/Option'.", + "Loading module as file / folder, candidate module location '/project/troublesome-lib/lib/Option', target file type 'TypeScript'.", + "Loading module 'troublesome-lib/lib/Option' from 'node_modules' folder, target file type 'TypeScript'.", + "Directory '/shared/lib/node_modules' does not exist, skipping all lookups in it.", + "'package.json' does not have a 'typesVersions' field.", + "Found 'package.json' at '/shared/node_modules/troublesome-lib/package.json'. Package ID is 'troublesome-lib/lib/Option/index.d.ts@1.17.1'.", + "File '/shared/node_modules/troublesome-lib/lib/Option.ts' does not exist.", + "File '/shared/node_modules/troublesome-lib/lib/Option.tsx' does not exist.", + "File '/shared/node_modules/troublesome-lib/lib/Option.d.ts' exist - use it as a name resolution result.", + "Resolving real path for '/shared/node_modules/troublesome-lib/lib/Option.d.ts', result '/shared/node_modules/troublesome-lib/lib/Option.d.ts'.", + "======== Module name 'troublesome-lib/lib/Option' was successfully resolved to '/shared/node_modules/troublesome-lib/lib/Option.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.types b/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.types new file mode 100644 index 0000000000000..f3aa22e7df2bc --- /dev/null +++ b/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.types @@ -0,0 +1,46 @@ +=== /project/src/app.ts === +import * as t from "anotherLib"; // Include the lib that recursively includes option as relative module resolution in this directory +>t : typeof t + +import { makeSharedOption } from "@shared/lib/app"; // Includes option as module in shared folder but as module in node_modules folder +>makeSharedOption : () => import("/shared/lib/app").SharedOption + +=== /shared/node_modules/troublesome-lib/lib/Option.d.ts === +export class Option { +>Option : Option + + someProperty: string; +>someProperty : string +} +=== /shared/lib/app.d.ts === +import { Option } from "troublesome-lib/lib/Option"; +>Option : typeof Option + +export class SharedOption extends Option { } +>SharedOption : SharedOption +>Option : Option + +export const makeSharedOption: () => SharedOption; +>makeSharedOption : () => SharedOption + +=== /project/node_modules/anotherLib/index.d.ts === +import { Compactable } from "troublesome-lib/lib/Compactable"; // Including this will resolve Option as relative through the imports of compactable +>Compactable : typeof Compactable + +=== /project/node_modules/troublesome-lib/lib/Compactable.d.ts === +import { Option } from './Option'; +>Option : typeof Option + +export class Compactable { +>Compactable : Compactable + + option: Option; +>option : Option +} +=== /project/node_modules/troublesome-lib/lib/Option.d.ts === +export class Option { +>Option : Option + + someProperty: string; +>someProperty : string +} diff --git a/tests/cases/compiler/moduleResolutionPackageIdWithRelativeAndAbsolutePath.ts b/tests/cases/compiler/moduleResolutionPackageIdWithRelativeAndAbsolutePath.ts new file mode 100644 index 0000000000000..acbde7b1c7b9f --- /dev/null +++ b/tests/cases/compiler/moduleResolutionPackageIdWithRelativeAndAbsolutePath.ts @@ -0,0 +1,51 @@ +// @noImplicitReferences: true +// @fullEmitPaths: true +// @traceResolution: true +// @filename: /shared/node_modules/troublesome-lib/package.json +{ + "name": "troublesome-lib", + "version": "1.17.1" +} +// @filename: /shared/node_modules/troublesome-lib/lib/Compactable.d.ts +import { Option } from './Option'; +export class Compactable { + option: Option; +} +// @filename: /shared/node_modules/troublesome-lib/lib/Option.d.ts +export class Option { + someProperty: string; +} +// @filename: /shared/lib/app.d.ts +import { Option } from "troublesome-lib/lib/Option"; +export class SharedOption extends Option { } +export const makeSharedOption: () => SharedOption; +// @filename: /project/node_modules/anotherLib/index.d.ts +import { Compactable } from "troublesome-lib/lib/Compactable"; // Including this will resolve Option as relative through the imports of compactable +// @filename: /project/node_modules/troublesome-lib/package.json +{ + "name": "troublesome-lib", + "version": "1.17.1" +} +// @filename: /project/node_modules/troublesome-lib/lib/Compactable.d.ts +import { Option } from './Option'; +export class Compactable { + option: Option; +} +// @filename: /project/node_modules/troublesome-lib/lib/Option.d.ts +export class Option { + someProperty: string; +} +// @filename: /project/src/app.ts +import * as t from "anotherLib"; // Include the lib that recursively includes option as relative module resolution in this directory +import { makeSharedOption } from "@shared/lib/app"; // Includes option as module in shared folder but as module in node_modules folder + +// @filename: /project/tsconfig.json +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "@shared/*": ["../shared/*"] + } + }, + //"files": ["src/app.ts"] +} \ No newline at end of file From 85d3c5d7a1b755c7c0ce3de59c961cb4a86a783d Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 22 May 2019 11:06:49 -0700 Subject: [PATCH 26/43] Trace Package id at the module resolution site --- src/compiler/diagnosticMessages.json | 14 ++++++++----- src/compiler/moduleNameResolver.ts | 21 ++++++++++++------- ...age_relativeImportWithinPackage.trace.json | 12 +++++------ ...ativeImportWithinPackage_scoped.trace.json | 12 +++++------ ...geIdWithRelativeAndAbsolutePath.trace.json | 12 +++++------ ...on_packageJson_yesAtPackageRoot.trace.json | 6 +++--- ...AtPackageRoot_fakeScopedPackage.trace.json | 6 +++--- ...ageRoot_mainFieldInSubDirectory.trace.json | 4 ++-- .../typesVersions.ambientModules.trace.json | 8 +++---- .../typesVersions.multiFile.trace.json | 8 +++---- ...VersionsDeclarationEmit.ambient.trace.json | 8 +++---- ...rsionsDeclarationEmit.multiFile.trace.json | 8 +++---- ...it.multiFileBackReferenceToSelf.trace.json | 16 +++++++------- ...ultiFileBackReferenceToUnmapped.trace.json | 12 +++++------ 14 files changed, 78 insertions(+), 69 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 87101781eadf7..e8784e7d1f26d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3811,10 +3811,6 @@ "category": "Error", "code": 6189 }, - "Found 'package.json' at '{0}'. Package ID is '{1}'.": { - "category": "Message", - "code": 6190 - }, "Whether to keep outdated console output in watch mode instead of clearing the screen.": { "category": "Message", "code": 6191 @@ -3923,6 +3919,14 @@ "category": "Message", "code": 6217 }, + "======== Module name '{0}' was successfully resolved to '{1}' with Package ID '{2}'. ========": { + "category": "Message", + "code": 6218 + }, + "======== Type reference directive '{0}' was successfully resolved to '{1}' with Package ID '{2}', primary: {3}. ========": { + "category": "Message", + "code": 6219 + }, "Projects to reference": { "category": "Message", @@ -4975,7 +4979,7 @@ "code": 95079 }, - "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer." :{ + "No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": { "category": "Error", "code": 18004 }, diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 8761cc0a08774..0cd9160ac42d2 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -307,7 +307,12 @@ namespace ts { const { fileName, packageId } = resolved; const resolvedFileName = options.preserveSymlinks ? fileName : realPath(fileName, host, traceEnabled); if (traceEnabled) { - trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolvedFileName, primary); + if (packageId) { + trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_with_Package_ID_2_primary_Colon_3, typeReferenceDirectiveName, resolvedFileName, packageIdToString(packageId), primary); + } + else { + trace(host, Diagnostics.Type_reference_directive_0_was_successfully_resolved_to_1_primary_Colon_2, typeReferenceDirectiveName, resolvedFileName, primary); + } } resolvedTypeReferenceDirective = { primary, resolvedFileName, packageId, isExternalLibraryImport: pathContainsNodeModules(fileName) }; } @@ -663,7 +668,12 @@ namespace ts { if (traceEnabled) { if (result.resolvedModule) { - trace(host, Diagnostics.Module_name_0_was_successfully_resolved_to_1, moduleName, result.resolvedModule.resolvedFileName); + if (result.resolvedModule.packageId) { + trace(host, Diagnostics.Module_name_0_was_successfully_resolved_to_1_with_Package_ID_2, moduleName, result.resolvedModule.resolvedFileName, packageIdToString(result.resolvedModule.packageId)); + } + else { + trace(host, Diagnostics.Module_name_0_was_successfully_resolved_to_1, moduleName, result.resolvedModule.resolvedFileName); + } } else { trace(host, Diagnostics.Module_name_0_was_not_resolved, moduleName); @@ -1165,12 +1175,7 @@ namespace ts { ? { name: packageJsonContent.name, subModuleName, version: packageJsonContent.version } : undefined; if (traceEnabled) { - if (packageId) { - trace(host, Diagnostics.Found_package_json_at_0_Package_ID_is_1, packageJsonPath, packageIdToString(packageId)); - } - else { - trace(host, Diagnostics.Found_package_json_at_0, packageJsonPath); - } + trace(host, Diagnostics.Found_package_json_at_0, packageJsonPath); } return { packageJsonContent, packageId, versionPaths }; diff --git a/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage.trace.json b/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage.trace.json index c4421e45579a5..eccaee3a379ab 100644 --- a/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage.trace.json +++ b/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage.trace.json @@ -3,12 +3,12 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'foo/use' from 'node_modules' folder, target file type 'TypeScript'.", "'package.json' does not have a 'typesVersions' field.", - "Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/use/index.d.ts@1.2.3'.", + "Found 'package.json' at '/node_modules/foo/package.json'.", "File '/node_modules/foo/use.ts' does not exist.", "File '/node_modules/foo/use.tsx' does not exist.", "File '/node_modules/foo/use.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/foo/use.d.ts', result '/node_modules/foo/use.d.ts'.", - "======== Module name 'foo/use' was successfully resolved to '/node_modules/foo/use.d.ts'. ========", + "======== Module name 'foo/use' was successfully resolved to '/node_modules/foo/use.d.ts' with Package ID 'foo/use/index.d.ts@1.2.3'. ========", "======== Resolving module 'a' from '/index.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'a' from 'node_modules' folder, target file type 'TypeScript'.", @@ -28,8 +28,8 @@ "File '/node_modules/foo/index.tsx' does not exist.", "File '/node_modules/foo/index.d.ts' exist - use it as a name resolution result.", "'package.json' does not have a 'typesVersions' field.", - "Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/index.d.ts@1.2.3'.", - "======== Module name './index' was successfully resolved to '/node_modules/foo/index.d.ts'. ========", + "Found 'package.json' at '/node_modules/foo/package.json'.", + "======== Module name './index' was successfully resolved to '/node_modules/foo/index.d.ts' with Package ID 'foo/index.d.ts@1.2.3'. ========", "======== Resolving module 'foo' from '/node_modules/a/index.d.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.", @@ -37,7 +37,7 @@ "'package.json' does not have a 'types' field.", "'package.json' does not have a 'main' field.", "'package.json' does not have a 'typesVersions' field.", - "Found 'package.json' at '/node_modules/a/node_modules/foo/package.json'. Package ID is 'foo/index.d.ts@1.2.3'.", + "Found 'package.json' at '/node_modules/a/node_modules/foo/package.json'.", "File '/node_modules/a/node_modules/foo.ts' does not exist.", "File '/node_modules/a/node_modules/foo.tsx' does not exist.", "File '/node_modules/a/node_modules/foo.d.ts' does not exist.", @@ -48,5 +48,5 @@ "File '/node_modules/a/node_modules/foo/index.tsx' does not exist.", "File '/node_modules/a/node_modules/foo/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/a/node_modules/foo/index.d.ts', result '/node_modules/a/node_modules/foo/index.d.ts'.", - "======== Module name 'foo' was successfully resolved to '/node_modules/a/node_modules/foo/index.d.ts'. ========" + "======== Module name 'foo' was successfully resolved to '/node_modules/a/node_modules/foo/index.d.ts' with Package ID 'foo/index.d.ts@1.2.3'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage_scoped.trace.json b/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage_scoped.trace.json index 97340de57ca66..d08d6e074f598 100644 --- a/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage_scoped.trace.json +++ b/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage_scoped.trace.json @@ -3,12 +3,12 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module '@foo/bar/use' from 'node_modules' folder, target file type 'TypeScript'.", "'package.json' does not have a 'typesVersions' field.", - "Found 'package.json' at '/node_modules/@foo/bar/package.json'. Package ID is '@foo/bar/use/index.d.ts@1.2.3'.", + "Found 'package.json' at '/node_modules/@foo/bar/package.json'.", "File '/node_modules/@foo/bar/use.ts' does not exist.", "File '/node_modules/@foo/bar/use.tsx' does not exist.", "File '/node_modules/@foo/bar/use.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/@foo/bar/use.d.ts', result '/node_modules/@foo/bar/use.d.ts'.", - "======== Module name '@foo/bar/use' was successfully resolved to '/node_modules/@foo/bar/use.d.ts'. ========", + "======== Module name '@foo/bar/use' was successfully resolved to '/node_modules/@foo/bar/use.d.ts' with Package ID '@foo/bar/use/index.d.ts@1.2.3'. ========", "======== Resolving module 'a' from '/index.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'a' from 'node_modules' folder, target file type 'TypeScript'.", @@ -28,8 +28,8 @@ "File '/node_modules/@foo/bar/index.tsx' does not exist.", "File '/node_modules/@foo/bar/index.d.ts' exist - use it as a name resolution result.", "'package.json' does not have a 'typesVersions' field.", - "Found 'package.json' at '/node_modules/@foo/bar/package.json'. Package ID is '@foo/bar/index.d.ts@1.2.3'.", - "======== Module name './index' was successfully resolved to '/node_modules/@foo/bar/index.d.ts'. ========", + "Found 'package.json' at '/node_modules/@foo/bar/package.json'.", + "======== Module name './index' was successfully resolved to '/node_modules/@foo/bar/index.d.ts' with Package ID '@foo/bar/index.d.ts@1.2.3'. ========", "======== Resolving module '@foo/bar' from '/node_modules/a/index.d.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module '@foo/bar' from 'node_modules' folder, target file type 'TypeScript'.", @@ -37,7 +37,7 @@ "'package.json' does not have a 'types' field.", "'package.json' does not have a 'main' field.", "'package.json' does not have a 'typesVersions' field.", - "Found 'package.json' at '/node_modules/a/node_modules/@foo/bar/package.json'. Package ID is '@foo/bar/index.d.ts@1.2.3'.", + "Found 'package.json' at '/node_modules/a/node_modules/@foo/bar/package.json'.", "File '/node_modules/a/node_modules/@foo/bar.ts' does not exist.", "File '/node_modules/a/node_modules/@foo/bar.tsx' does not exist.", "File '/node_modules/a/node_modules/@foo/bar.d.ts' does not exist.", @@ -48,5 +48,5 @@ "File '/node_modules/a/node_modules/@foo/bar/index.tsx' does not exist.", "File '/node_modules/a/node_modules/@foo/bar/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/a/node_modules/@foo/bar/index.d.ts', result '/node_modules/a/node_modules/@foo/bar/index.d.ts'.", - "======== Module name '@foo/bar' was successfully resolved to '/node_modules/a/node_modules/@foo/bar/index.d.ts'. ========" + "======== Module name '@foo/bar' was successfully resolved to '/node_modules/a/node_modules/@foo/bar/index.d.ts' with Package ID '@foo/bar/index.d.ts@1.2.3'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.trace.json b/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.trace.json index b08a0f124565d..9f514de9f25c8 100644 --- a/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.trace.json +++ b/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.trace.json @@ -42,12 +42,12 @@ "Loading module 'troublesome-lib/lib/Compactable' from 'node_modules' folder, target file type 'TypeScript'.", "Directory '/project/node_modules/anotherLib/node_modules' does not exist, skipping all lookups in it.", "'package.json' does not have a 'typesVersions' field.", - "Found 'package.json' at '/project/node_modules/troublesome-lib/package.json'. Package ID is 'troublesome-lib/lib/Compactable/index.d.ts@1.17.1'.", + "Found 'package.json' at '/project/node_modules/troublesome-lib/package.json'.", "File '/project/node_modules/troublesome-lib/lib/Compactable.ts' does not exist.", "File '/project/node_modules/troublesome-lib/lib/Compactable.tsx' does not exist.", "File '/project/node_modules/troublesome-lib/lib/Compactable.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/project/node_modules/troublesome-lib/lib/Compactable.d.ts', result '/project/node_modules/troublesome-lib/lib/Compactable.d.ts'.", - "======== Module name 'troublesome-lib/lib/Compactable' was successfully resolved to '/project/node_modules/troublesome-lib/lib/Compactable.d.ts'. ========", + "======== Module name 'troublesome-lib/lib/Compactable' was successfully resolved to '/project/node_modules/troublesome-lib/lib/Compactable.d.ts' with Package ID 'troublesome-lib/lib/Compactable/index.d.ts@1.17.1'. ========", "======== Resolving module './Option' from '/project/node_modules/troublesome-lib/lib/Compactable.d.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/project/node_modules/troublesome-lib/lib/Option', target file type 'TypeScript'.", @@ -55,8 +55,8 @@ "File '/project/node_modules/troublesome-lib/lib/Option.tsx' does not exist.", "File '/project/node_modules/troublesome-lib/lib/Option.d.ts' exist - use it as a name resolution result.", "'package.json' does not have a 'typesVersions' field.", - "Found 'package.json' at '/project/node_modules/troublesome-lib/package.json'. Package ID is 'troublesome-lib/lib/Option.d.ts@1.17.1'.", - "======== Module name './Option' was successfully resolved to '/project/node_modules/troublesome-lib/lib/Option.d.ts'. ========", + "Found 'package.json' at '/project/node_modules/troublesome-lib/package.json'.", + "======== Module name './Option' was successfully resolved to '/project/node_modules/troublesome-lib/lib/Option.d.ts' with Package ID 'troublesome-lib/lib/Option.d.ts@1.17.1'. ========", "======== Resolving module 'troublesome-lib/lib/Option' from '/shared/lib/app.d.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "'baseUrl' option is set to '/project', using this value to resolve non-relative module name 'troublesome-lib/lib/Option'.", @@ -67,10 +67,10 @@ "Loading module 'troublesome-lib/lib/Option' from 'node_modules' folder, target file type 'TypeScript'.", "Directory '/shared/lib/node_modules' does not exist, skipping all lookups in it.", "'package.json' does not have a 'typesVersions' field.", - "Found 'package.json' at '/shared/node_modules/troublesome-lib/package.json'. Package ID is 'troublesome-lib/lib/Option/index.d.ts@1.17.1'.", + "Found 'package.json' at '/shared/node_modules/troublesome-lib/package.json'.", "File '/shared/node_modules/troublesome-lib/lib/Option.ts' does not exist.", "File '/shared/node_modules/troublesome-lib/lib/Option.tsx' does not exist.", "File '/shared/node_modules/troublesome-lib/lib/Option.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/shared/node_modules/troublesome-lib/lib/Option.d.ts', result '/shared/node_modules/troublesome-lib/lib/Option.d.ts'.", - "======== Module name 'troublesome-lib/lib/Option' was successfully resolved to '/shared/node_modules/troublesome-lib/lib/Option.d.ts'. ========" + "======== Module name 'troublesome-lib/lib/Option' was successfully resolved to '/shared/node_modules/troublesome-lib/lib/Option.d.ts' with Package ID 'troublesome-lib/lib/Option/index.d.ts@1.17.1'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot.trace.json b/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot.trace.json index 873805b8b5765..4a2e60d9c7f53 100644 --- a/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot.trace.json +++ b/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot.trace.json @@ -4,7 +4,7 @@ "Loading module 'foo/bar' from 'node_modules' folder, target file type 'TypeScript'.", "File '/node_modules/foo/bar/package.json' does not exist.", "'package.json' does not have a 'typesVersions' field.", - "Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/bar/index.d.ts@1.2.3'.", + "Found 'package.json' at '/node_modules/foo/package.json'.", "File '/node_modules/foo/bar.ts' does not exist.", "File '/node_modules/foo/bar.tsx' does not exist.", "File '/node_modules/foo/bar.d.ts' does not exist.", @@ -15,10 +15,10 @@ "Loading module 'foo/bar' from 'node_modules' folder, target file type 'JavaScript'.", "File '/node_modules/foo/bar/package.json' does not exist.", "'package.json' does not have a 'typesVersions' field.", - "Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/bar/index.d.ts@1.2.3'.", + "Found 'package.json' at '/node_modules/foo/package.json'.", "File '/node_modules/foo/bar.js' does not exist.", "File '/node_modules/foo/bar.jsx' does not exist.", "File '/node_modules/foo/bar/index.js' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/foo/bar/index.js', result '/node_modules/foo/bar/index.js'.", - "======== Module name 'foo/bar' was successfully resolved to '/node_modules/foo/bar/index.js'. ========" + "======== Module name 'foo/bar' was successfully resolved to '/node_modules/foo/bar/index.js' with Package ID 'foo/bar/index.d.ts@1.2.3'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_fakeScopedPackage.trace.json b/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_fakeScopedPackage.trace.json index 95beae1393e75..3f2423ce832b3 100644 --- a/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_fakeScopedPackage.trace.json +++ b/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_fakeScopedPackage.trace.json @@ -4,7 +4,7 @@ "Loading module 'foo/@bar' from 'node_modules' folder, target file type 'TypeScript'.", "File '/node_modules/foo/@bar/package.json' does not exist.", "'package.json' does not have a 'typesVersions' field.", - "Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/@bar/index.d.ts@1.2.3'.", + "Found 'package.json' at '/node_modules/foo/package.json'.", "File '/node_modules/foo/@bar.ts' does not exist.", "File '/node_modules/foo/@bar.tsx' does not exist.", "File '/node_modules/foo/@bar.d.ts' does not exist.", @@ -15,10 +15,10 @@ "Loading module 'foo/@bar' from 'node_modules' folder, target file type 'JavaScript'.", "File '/node_modules/foo/@bar/package.json' does not exist.", "'package.json' does not have a 'typesVersions' field.", - "Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/@bar/index.d.ts@1.2.3'.", + "Found 'package.json' at '/node_modules/foo/package.json'.", "File '/node_modules/foo/@bar.js' does not exist.", "File '/node_modules/foo/@bar.jsx' does not exist.", "File '/node_modules/foo/@bar/index.js' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/foo/@bar/index.js', result '/node_modules/foo/@bar/index.js'.", - "======== Module name 'foo/@bar' was successfully resolved to '/node_modules/foo/@bar/index.js'. ========" + "======== Module name 'foo/@bar' was successfully resolved to '/node_modules/foo/@bar/index.js' with Package ID 'foo/@bar/index.d.ts@1.2.3'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_mainFieldInSubDirectory.trace.json b/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_mainFieldInSubDirectory.trace.json index 4d7ae4878139c..6b373fb300f16 100644 --- a/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_mainFieldInSubDirectory.trace.json +++ b/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_mainFieldInSubDirectory.trace.json @@ -6,7 +6,7 @@ "'package.json' does not have a 'types' field.", "'package.json' has 'main' field 'src/index.js' that references '/node_modules/foo/src/index.js'.", "'package.json' does not have a 'typesVersions' field.", - "Found 'package.json' at '/node_modules/foo/package.json'. Package ID is 'foo/src/index.d.ts@1.2.3'.", + "Found 'package.json' at '/node_modules/foo/package.json'.", "File '/node_modules/foo.ts' does not exist.", "File '/node_modules/foo.tsx' does not exist.", "File '/node_modules/foo.d.ts' does not exist.", @@ -23,5 +23,5 @@ "File '/node_modules/foo/src/index.tsx' does not exist.", "File '/node_modules/foo/src/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/foo/src/index.d.ts', result '/node_modules/foo/src/index.d.ts'.", - "======== Module name 'foo' was successfully resolved to '/node_modules/foo/src/index.d.ts'. ========" + "======== Module name 'foo' was successfully resolved to '/node_modules/foo/src/index.d.ts' with Package ID 'foo/src/index.d.ts@1.2.3'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typesVersions.ambientModules.trace.json b/tests/baselines/reference/typesVersions.ambientModules.trace.json index ad73f88a8ef7a..dcaf6acc09694 100644 --- a/tests/baselines/reference/typesVersions.ambientModules.trace.json +++ b/tests/baselines/reference/typesVersions.ambientModules.trace.json @@ -5,7 +5,7 @@ "'package.json' does not have a 'typings' field.", "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/moduleResolution/node_modules/ext/index'.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/moduleResolution/node_modules/ext/package.json'. Package ID is 'ext/index.d.ts@1.0.0'.", + "Found 'package.json' at 'tests/cases/conformance/moduleResolution/node_modules/ext/package.json'.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext.ts' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext.tsx' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext.d.ts' does not exist.", @@ -20,12 +20,12 @@ "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts', result 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts'.", - "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts'. ========", + "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/index.d.ts@1.0.0'. ========", "======== Resolving module 'ext/other' from 'tests/cases/conformance/moduleResolution/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'TypeScript'.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/moduleResolution/node_modules/ext/package.json'. Package ID is 'ext/other/index.d.ts@1.0.0'.", + "Found 'package.json' at 'tests/cases/conformance/moduleResolution/node_modules/ext/package.json'.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "Module name 'other', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/other'.", @@ -44,7 +44,7 @@ "Directory '/node_modules' does not exist, skipping all lookups in it.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'JavaScript'.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/moduleResolution/node_modules/ext/package.json'. Package ID is 'ext/other/index.d.ts@1.0.0'.", + "Found 'package.json' at 'tests/cases/conformance/moduleResolution/node_modules/ext/package.json'.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "Module name 'other', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/other'.", diff --git a/tests/baselines/reference/typesVersions.multiFile.trace.json b/tests/baselines/reference/typesVersions.multiFile.trace.json index d52db48acfef2..7197547409261 100644 --- a/tests/baselines/reference/typesVersions.multiFile.trace.json +++ b/tests/baselines/reference/typesVersions.multiFile.trace.json @@ -5,7 +5,7 @@ "'package.json' does not have a 'typings' field.", "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/moduleResolution/node_modules/ext/index'.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/moduleResolution/node_modules/ext/package.json'. Package ID is 'ext/index.d.ts@1.0.0'.", + "Found 'package.json' at 'tests/cases/conformance/moduleResolution/node_modules/ext/package.json'.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext.ts' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext.tsx' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext.d.ts' does not exist.", @@ -20,12 +20,12 @@ "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts', result 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts'.", - "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts'. ========", + "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/index.d.ts@1.0.0'. ========", "======== Resolving module 'ext/other' from 'tests/cases/conformance/moduleResolution/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'TypeScript'.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/moduleResolution/node_modules/ext/package.json'. Package ID is 'ext/other/index.d.ts@1.0.0'.", + "Found 'package.json' at 'tests/cases/conformance/moduleResolution/node_modules/ext/package.json'.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "Module name 'other', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/other'.", @@ -33,5 +33,5 @@ "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.tsx' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.d.ts', result 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.d.ts'.", - "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.d.ts'. ========" + "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.d.ts' with Package ID 'ext/other/index.d.ts@1.0.0'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typesVersionsDeclarationEmit.ambient.trace.json b/tests/baselines/reference/typesVersionsDeclarationEmit.ambient.trace.json index 2fcf9d052d452..5d5009e8a4105 100644 --- a/tests/baselines/reference/typesVersionsDeclarationEmit.ambient.trace.json +++ b/tests/baselines/reference/typesVersionsDeclarationEmit.ambient.trace.json @@ -5,7 +5,7 @@ "'package.json' does not have a 'typings' field.", "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/declarationEmit/node_modules/ext/index'.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'. Package ID is 'ext/index.d.ts@1.0.0'.", + "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.ts' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.d.ts' does not exist.", @@ -20,12 +20,12 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'.", - "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'. ========", + "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/index.d.ts@1.0.0'. ========", "======== Resolving module 'ext/other' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'TypeScript'.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'. Package ID is 'ext/other/index.d.ts@1.0.0'.", + "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "Module name 'other', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/other'.", @@ -44,7 +44,7 @@ "Directory '/node_modules' does not exist, skipping all lookups in it.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'JavaScript'.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'. Package ID is 'ext/other/index.d.ts@1.0.0'.", + "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "Module name 'other', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/other'.", diff --git a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFile.trace.json b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFile.trace.json index eee9622037b79..9fb9c48332a18 100644 --- a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFile.trace.json +++ b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFile.trace.json @@ -5,7 +5,7 @@ "'package.json' does not have a 'typings' field.", "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/declarationEmit/node_modules/ext/index'.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'. Package ID is 'ext/index.d.ts@1.0.0'.", + "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.ts' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.d.ts' does not exist.", @@ -20,12 +20,12 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'.", - "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'. ========", + "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/index.d.ts@1.0.0'. ========", "======== Resolving module 'ext/other' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'TypeScript'.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'. Package ID is 'ext/other/index.d.ts@1.0.0'.", + "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "Module name 'other', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/other'.", @@ -33,5 +33,5 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts'.", - "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts'. ========" + "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' with Package ID 'ext/other/index.d.ts@1.0.0'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json index 464da214bae2a..6deb7327c99dc 100644 --- a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json +++ b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json @@ -5,7 +5,7 @@ "'package.json' does not have a 'typings' field.", "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/declarationEmit/node_modules/ext/index'.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'. Package ID is 'ext/ndex/index.d.ts@1.0.0'.", + "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", "'package.json' does not have a 'typings' field.", "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/declarationEmit/node_modules/ext/index'.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'index'.", @@ -16,7 +16,7 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.ts' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", - "======== Module name '../' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'. ========", + "======== Module name '../' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/ndex/index.d.ts@1.0.0'. ========", "======== Resolving module '../other' from 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location 'tests/cases/conformance/declarationEmit/node_modules/ext/other', target file type 'TypeScript'.", @@ -24,15 +24,15 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' exist - use it as a name resolution result.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'. Package ID is 'ext/other.d.ts@1.0.0'.", - "======== Module name '../other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts'. ========", + "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", + "======== Module name '../other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' with Package ID 'ext/other.d.ts@1.0.0'. ========", "======== Resolving module 'ext' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext' from 'node_modules' folder, target file type 'TypeScript'.", "'package.json' does not have a 'typings' field.", "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/declarationEmit/node_modules/ext/index'.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'. Package ID is 'ext/index.d.ts@1.0.0'.", + "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.ts' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.d.ts' does not exist.", @@ -47,12 +47,12 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'.", - "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'. ========", + "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/index.d.ts@1.0.0'. ========", "======== Resolving module 'ext/other' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'TypeScript'.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'. Package ID is 'ext/other/index.d.ts@1.0.0'.", + "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "Module name 'other', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/other'.", @@ -60,5 +60,5 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts'.", - "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts'. ========" + "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' with Package ID 'ext/other/index.d.ts@1.0.0'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToUnmapped.trace.json b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToUnmapped.trace.json index fe65b605283e5..94f15e642605d 100644 --- a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToUnmapped.trace.json +++ b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToUnmapped.trace.json @@ -6,15 +6,15 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' exist - use it as a name resolution result.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'. Package ID is 'ext/other.d.ts@1.0.0'.", - "======== Module name '../other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts'. ========", + "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", + "======== Module name '../other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' with Package ID 'ext/other.d.ts@1.0.0'. ========", "======== Resolving module 'ext' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext' from 'node_modules' folder, target file type 'TypeScript'.", "'package.json' does not have a 'typings' field.", "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/declarationEmit/node_modules/ext/index'.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'. Package ID is 'ext/index.d.ts@1.0.0'.", + "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.ts' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.d.ts' does not exist.", @@ -29,16 +29,16 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'.", - "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'. ========", + "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/index.d.ts@1.0.0'. ========", "======== Resolving module 'ext/other' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'TypeScript'.", "'package.json' has a 'typesVersions' field with version-specific path mappings.", - "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'. Package ID is 'ext/other/index.d.ts@1.0.0'.", + "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.ts' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts'.", - "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts'. ========" + "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' with Package ID 'ext/other/index.d.ts@1.0.0'. ========" ] \ No newline at end of file From eecb6d90497bd460bbe555d39358b30253896de8 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 22 May 2019 13:39:05 -0700 Subject: [PATCH 27/43] Add failing test --- .../conformance/types/tuple/readonlyArraysAndTuples.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts b/tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts index d9fecee7dea3f..35c86175a0bd5 100644 --- a/tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts +++ b/tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts @@ -28,3 +28,10 @@ function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: reado rt = ra; // Error rt = mt; } + +declare var v: readonly[number, number, ...number[]]; +v[0] = 1; // Error +v[1] = 1; // Error +v[2] = 1; // Error +v[0 + 1] = 1; // Error +v[0 + 2] = 1; // Error From 5d188a8c68d1a54d6933ad0be5e1375b7be3e4db Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 22 May 2019 14:22:46 -0700 Subject: [PATCH 28/43] Always use resolved file to figure out subModule name in package id Fixes #30429 --- src/compiler/moduleNameResolver.ts | 129 +++++++----------- ...age_relativeImportWithinPackage.trace.json | 11 +- ...ativeImportWithinPackage_scoped.trace.json | 11 +- .../reference/library-reference-10.trace.json | 6 +- .../reference/library-reference-11.trace.json | 3 +- .../reference/library-reference-12.trace.json | 4 +- .../reference/library-reference-2.trace.json | 8 +- ...geIdWithRelativeAndAbsolutePath.trace.json | 10 +- ...lutionWithExtensions_unexpected.trace.json | 10 +- ...utionWithExtensions_unexpected2.trace.json | 8 +- ...on_packageJson_notAtPackageRoot.trace.json | 4 +- ...AtPackageRoot_fakeScopedPackage.trace.json | 4 +- ...ution_packageJson_scopedPackage.trace.json | 4 +- ...on_packageJson_yesAtPackageRoot.trace.json | 15 +- ...AtPackageRoot_fakeScopedPackage.trace.json | 15 +- ...ageRoot_mainFieldInSubDirectory.trace.json | 5 +- .../reference/packageJsonMain.trace.json | 30 +--- .../packageJsonMain_isNonRecursive.trace.json | 10 +- .../typesVersions.ambientModules.trace.json | 13 +- .../typesVersions.justIndex.trace.json | 5 +- .../typesVersions.multiFile.trace.json | 10 +- ...VersionsDeclarationEmit.ambient.trace.json | 13 +- ...rsionsDeclarationEmit.multiFile.trace.json | 10 +- ...it.multiFileBackReferenceToSelf.trace.json | 18 +-- ...ultiFileBackReferenceToUnmapped.trace.json | 12 +- .../reference/typingsLookup4.trace.json | 24 ++-- 26 files changed, 154 insertions(+), 238 deletions(-) diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 0cd9160ac42d2..19402b03ee9a9 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -16,12 +16,23 @@ namespace ts { push(value: T): void; } - function withPackageId(packageId: PackageId | undefined, r: PathAndExtension | undefined): Resolved | undefined { + function withPackageId(packageInfo: PackageJsonInfo | undefined, r: PathAndExtension | undefined): Resolved | undefined { + let packageId: PackageId | undefined; + if (r && packageInfo) { + const packageJsonContent = packageInfo.packageJsonContent as PackageJson; + if (typeof packageJsonContent.name === "string" && typeof packageJsonContent.version === "string") { + packageId = { + name: packageJsonContent.name, + subModuleName: r.path.slice(packageInfo.packageDirectory.length + directorySeparator.length), + version: packageJsonContent.version + }; + } + } return r && { path: r.path, extension: r.ext, packageId }; } function noPackageId(r: PathAndExtension | undefined): Resolved | undefined { - return withPackageId(/*packageId*/ undefined, r); + return withPackageId(/*packageInfo*/ undefined, r); } function removeIgnoredPackageId(r: Resolved | undefined): PathAndExtension | undefined { @@ -978,10 +989,9 @@ namespace ts { } const resolvedFromFile = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state); if (resolvedFromFile) { - const nm = considerPackageJson ? parseNodeModuleFromPath(resolvedFromFile) : undefined; - const packageInfo = nm && getPackageJsonInfo(nm.packageDirectory, nm.subModuleName, /*onlyRecordFailures*/ false, state); - const packageId = packageInfo && packageInfo.packageId; - return withPackageId(packageId, resolvedFromFile); + const packageDirectory = considerPackageJson ? parseNodeModuleFromPath(resolvedFromFile) : undefined; + const packageInfo = packageDirectory ? getPackageJsonInfo(packageDirectory, /*onlyRecordFailures*/ false, state) : undefined; + return withPackageId(packageInfo, resolvedFromFile); } } if (!onlyRecordFailures) { @@ -1008,13 +1018,12 @@ namespace ts { * (Not neeeded for `loadModuleFromNodeModules` as that looks up the `package.json` as part of resolution.) * * packageDirectory is the directory of the package itself. - * subModuleName is the path within the package. - * For `blah/node_modules/foo/index.d.ts` this is { packageDirectory: "foo", subModuleName: "index.d.ts" }. (Part before "/node_modules/" is ignored.) - * For `/node_modules/foo/bar.d.ts` this is { packageDirectory: "foo", subModuleName": "bar/index.d.ts" }. - * For `/node_modules/@types/foo/bar/index.d.ts` this is { packageDirectory: "@types/foo", subModuleName: "bar/index.d.ts" }. - * For `/node_modules/foo/bar/index.d.ts` this is { packageDirectory: "foo", subModuleName": "bar/index.d.ts" }. + * For `blah/node_modules/foo/index.d.ts` this is packageDirectory: "foo" + * For `/node_modules/foo/bar.d.ts` this is packageDirectory: "foo" + * For `/node_modules/@types/foo/bar/index.d.ts` this is packageDirectory: "@types/foo" + * For `/node_modules/foo/bar/index.d.ts` this is packageDirectory: "foo" */ - function parseNodeModuleFromPath(resolved: PathAndExtension): { packageDirectory: string, subModuleName: string } | undefined { + function parseNodeModuleFromPath(resolved: PathAndExtension): string | undefined { const path = normalizePath(resolved.path); const idx = path.lastIndexOf(nodeModulesPathPart); if (idx === -1) { @@ -1026,9 +1035,7 @@ namespace ts { if (path.charCodeAt(indexAfterNodeModules) === CharacterCodes.at) { indexAfterPackageName = moveToNextDirectorySeparatorIfAvailable(path, indexAfterPackageName); } - const packageDirectory = path.slice(0, indexAfterPackageName); - const subModuleName = removeExtension(path.slice(indexAfterPackageName + 1), resolved.ext) + Extension.Dts; - return { packageDirectory, subModuleName }; + return path.slice(0, indexAfterPackageName); } function moveToNextDirectorySeparatorIfAvailable(path: string, prevSeparatorIndex: number): number { @@ -1036,19 +1043,6 @@ namespace ts { return nextSeparatorIndex === -1 ? prevSeparatorIndex : nextSeparatorIndex; } - function addExtensionAndIndex(path: string): string { - if (path === "") { - return "index.d.ts"; - } - if (endsWith(path, ".d.ts")) { - return path; - } - if (path === "index" || endsWith(path, "/index")) { - return path + ".d.ts"; - } - return path + "/index.d.ts"; - } - function loadModuleFromFileNoPackageId(extensions: Extensions, candidate: string, onlyRecordFailures: boolean, state: ModuleResolutionState): Resolved | undefined { return noPackageId(loadModuleFromFile(extensions, candidate, onlyRecordFailures, state)); } @@ -1129,56 +1123,29 @@ namespace ts { } function loadNodeModuleFromDirectory(extensions: Extensions, candidate: string, onlyRecordFailures: boolean, state: ModuleResolutionState, considerPackageJson = true) { - const packageInfo = considerPackageJson ? getPackageJsonInfo(candidate, "", onlyRecordFailures, state) : undefined; - const packageId = packageInfo && packageInfo.packageId; + const packageInfo = considerPackageJson ? getPackageJsonInfo(candidate, onlyRecordFailures, state) : undefined; const packageJsonContent = packageInfo && packageInfo.packageJsonContent; const versionPaths = packageInfo && packageInfo.versionPaths; - return withPackageId(packageId, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths)); + return withPackageId(packageInfo, loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths)); } interface PackageJsonInfo { - packageJsonContent: PackageJsonPathFields | undefined; - packageId: PackageId | undefined; + packageDirectory: string; + packageJsonContent: PackageJsonPathFields; versionPaths: VersionPaths | undefined; } - function getPackageJsonInfo(packageDirectory: string, subModuleName: string, onlyRecordFailures: boolean, state: ModuleResolutionState): PackageJsonInfo | undefined { + function getPackageJsonInfo(packageDirectory: string, onlyRecordFailures: boolean, state: ModuleResolutionState): PackageJsonInfo | undefined { const { host, traceEnabled } = state; const directoryExists = !onlyRecordFailures && directoryProbablyExists(packageDirectory, host); const packageJsonPath = combinePaths(packageDirectory, "package.json"); if (directoryExists && host.fileExists(packageJsonPath)) { const packageJsonContent = readJson(packageJsonPath, host) as PackageJson; - if (subModuleName === "") { // looking up the root - need to handle types/typings/main redirects for subModuleName - const path = readPackageJsonTypesFields(packageJsonContent, packageDirectory, state); - if (typeof path === "string") { - subModuleName = addExtensionAndIndex(path.substring(packageDirectory.length + 1)); - } - else { - const jsPath = readPackageJsonMainField(packageJsonContent, packageDirectory, state); - if (typeof jsPath === "string" && jsPath.length > packageDirectory.length) { - const potentialSubModule = jsPath.substring(packageDirectory.length + 1); - subModuleName = (forEach(supportedJSExtensions, extension => - tryRemoveExtension(potentialSubModule, extension)) || potentialSubModule) + Extension.Dts; - } - else { - subModuleName = "index.d.ts"; - } - } - } - - if (!endsWith(subModuleName, Extension.Dts)) { - subModuleName = addExtensionAndIndex(subModuleName); - } - - const versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state); - const packageId: PackageId | undefined = typeof packageJsonContent.name === "string" && typeof packageJsonContent.version === "string" - ? { name: packageJsonContent.name, subModuleName, version: packageJsonContent.version } - : undefined; if (traceEnabled) { trace(host, Diagnostics.Found_package_json_at_0, packageJsonPath); } - - return { packageJsonContent, packageId, versionPaths }; + const versionPaths = readPackageJsonTypesVersionPaths(packageJsonContent, state); + return { packageDirectory, packageJsonContent, versionPaths }; } else { if (directoryExists && traceEnabled) { @@ -1333,27 +1300,36 @@ namespace ts { const candidate = normalizePath(combinePaths(nodeModulesDirectory, moduleName)); // First look for a nested package.json, as in `node_modules/foo/bar/package.json`. - let packageJsonContent: PackageJsonPathFields | undefined; - let packageId: PackageId | undefined; - let versionPaths: VersionPaths | undefined; - - const packageInfo = getPackageJsonInfo(candidate, "", !nodeModulesDirectoryExists, state); + let packageInfo = getPackageJsonInfo(candidate, !nodeModulesDirectoryExists, state); if (packageInfo) { - ({ packageJsonContent, packageId, versionPaths } = packageInfo); const fromFile = loadModuleFromFile(extensions, candidate, !nodeModulesDirectoryExists, state); if (fromFile) { return noPackageId(fromFile); } - const fromDirectory = loadNodeModuleFromDirectoryWorker(extensions, candidate, !nodeModulesDirectoryExists, state, packageJsonContent, versionPaths); - return withPackageId(packageId, fromDirectory); + const fromDirectory = loadNodeModuleFromDirectoryWorker( + extensions, + candidate, + !nodeModulesDirectoryExists, + state, + packageInfo.packageJsonContent, + packageInfo.versionPaths + ); + return withPackageId(packageInfo, fromDirectory); } const loader: ResolutionKindSpecificLoader = (extensions, candidate, onlyRecordFailures, state) => { const pathAndExtension = loadModuleFromFile(extensions, candidate, onlyRecordFailures, state) || - loadNodeModuleFromDirectoryWorker(extensions, candidate, onlyRecordFailures, state, packageJsonContent, versionPaths); - return withPackageId(packageId, pathAndExtension); + loadNodeModuleFromDirectoryWorker( + extensions, + candidate, + onlyRecordFailures, + state, + packageInfo && packageInfo.packageJsonContent, + packageInfo && packageInfo.versionPaths + ); + return withPackageId(packageInfo, pathAndExtension); }; const { packageName, rest } = parsePackageName(moduleName); @@ -1361,14 +1337,13 @@ namespace ts { const packageDirectory = combinePaths(nodeModulesDirectory, packageName); // Don't use a "types" or "main" from here because we're not loading the root, but a subdirectory -- just here for the packageId and path mappings. - const packageInfo = getPackageJsonInfo(packageDirectory, rest, !nodeModulesDirectoryExists, state); - if (packageInfo) ({ packageId, versionPaths } = packageInfo); - if (versionPaths) { + packageInfo = getPackageJsonInfo(packageDirectory, !nodeModulesDirectoryExists, state); + if (packageInfo && packageInfo.versionPaths) { if (state.traceEnabled) { - trace(state.host, Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, versionPaths.version, version, rest); + trace(state.host, Diagnostics.package_json_has_a_typesVersions_entry_0_that_matches_compiler_version_1_looking_for_a_pattern_to_match_module_name_2, packageInfo.versionPaths.version, version, rest); } const packageDirectoryExists = nodeModulesDirectoryExists && directoryProbablyExists(packageDirectory, state.host); - const fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, versionPaths.paths, loader, !packageDirectoryExists, state); + const fromPaths = tryLoadModuleUsingPaths(extensions, rest, packageDirectory, packageInfo.versionPaths.paths, loader, !packageDirectoryExists, state); if (fromPaths) { return fromPaths.value; } diff --git a/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage.trace.json b/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage.trace.json index eccaee3a379ab..8711f881de8db 100644 --- a/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage.trace.json +++ b/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage.trace.json @@ -2,13 +2,13 @@ "======== Resolving module 'foo/use' from '/index.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'foo/use' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/foo/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/foo/use.ts' does not exist.", "File '/node_modules/foo/use.tsx' does not exist.", "File '/node_modules/foo/use.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/foo/use.d.ts', result '/node_modules/foo/use.d.ts'.", - "======== Module name 'foo/use' was successfully resolved to '/node_modules/foo/use.d.ts' with Package ID 'foo/use/index.d.ts@1.2.3'. ========", + "======== Module name 'foo/use' was successfully resolved to '/node_modules/foo/use.d.ts' with Package ID 'foo/use.d.ts@1.2.3'. ========", "======== Resolving module 'a' from '/index.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'a' from 'node_modules' folder, target file type 'TypeScript'.", @@ -27,17 +27,14 @@ "File '/node_modules/foo/index.ts' does not exist.", "File '/node_modules/foo/index.tsx' does not exist.", "File '/node_modules/foo/index.d.ts' exist - use it as a name resolution result.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/foo/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "======== Module name './index' was successfully resolved to '/node_modules/foo/index.d.ts' with Package ID 'foo/index.d.ts@1.2.3'. ========", "======== Resolving module 'foo' from '/node_modules/a/index.d.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' does not have a 'types' field.", - "'package.json' does not have a 'main' field.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/a/node_modules/foo/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/a/node_modules/foo.ts' does not exist.", "File '/node_modules/a/node_modules/foo.tsx' does not exist.", "File '/node_modules/a/node_modules/foo.d.ts' does not exist.", diff --git a/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage_scoped.trace.json b/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage_scoped.trace.json index d08d6e074f598..2a4b74ad5550f 100644 --- a/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage_scoped.trace.json +++ b/tests/baselines/reference/duplicatePackage_relativeImportWithinPackage_scoped.trace.json @@ -2,13 +2,13 @@ "======== Resolving module '@foo/bar/use' from '/index.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module '@foo/bar/use' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/@foo/bar/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/@foo/bar/use.ts' does not exist.", "File '/node_modules/@foo/bar/use.tsx' does not exist.", "File '/node_modules/@foo/bar/use.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/@foo/bar/use.d.ts', result '/node_modules/@foo/bar/use.d.ts'.", - "======== Module name '@foo/bar/use' was successfully resolved to '/node_modules/@foo/bar/use.d.ts' with Package ID '@foo/bar/use/index.d.ts@1.2.3'. ========", + "======== Module name '@foo/bar/use' was successfully resolved to '/node_modules/@foo/bar/use.d.ts' with Package ID '@foo/bar/use.d.ts@1.2.3'. ========", "======== Resolving module 'a' from '/index.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'a' from 'node_modules' folder, target file type 'TypeScript'.", @@ -27,17 +27,14 @@ "File '/node_modules/@foo/bar/index.ts' does not exist.", "File '/node_modules/@foo/bar/index.tsx' does not exist.", "File '/node_modules/@foo/bar/index.d.ts' exist - use it as a name resolution result.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/@foo/bar/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "======== Module name './index' was successfully resolved to '/node_modules/@foo/bar/index.d.ts' with Package ID '@foo/bar/index.d.ts@1.2.3'. ========", "======== Resolving module '@foo/bar' from '/node_modules/a/index.d.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module '@foo/bar' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' does not have a 'types' field.", - "'package.json' does not have a 'main' field.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/a/node_modules/@foo/bar/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/a/node_modules/@foo/bar.ts' does not exist.", "File '/node_modules/a/node_modules/@foo/bar.tsx' does not exist.", "File '/node_modules/a/node_modules/@foo/bar.d.ts' does not exist.", diff --git a/tests/baselines/reference/library-reference-10.trace.json b/tests/baselines/reference/library-reference-10.trace.json index 37f8ab543caee..92b5b03507978 100644 --- a/tests/baselines/reference/library-reference-10.trace.json +++ b/tests/baselines/reference/library-reference-10.trace.json @@ -1,18 +1,16 @@ [ "======== Resolving type reference directive 'jquery', containing file '/foo/consumer.ts', root directory './types'. ========", "Resolving with primary search path './types'.", - "'package.json' has 'typings' field 'jquery.d.ts' that references 'types/jquery/jquery.d.ts'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at './types/jquery/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "'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.", "Resolving real path for 'types/jquery/jquery.d.ts', result '/foo/types/jquery/jquery.d.ts'.", "======== Type reference directive 'jquery' was successfully resolved to '/foo/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'.", - "'package.json' has 'typings' field 'jquery.d.ts' that references 'types/jquery/jquery.d.ts'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at './types/jquery/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "'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.", "Resolving real path for 'types/jquery/jquery.d.ts', result '/foo/types/jquery/jquery.d.ts'.", diff --git a/tests/baselines/reference/library-reference-11.trace.json b/tests/baselines/reference/library-reference-11.trace.json index b5e324d8c369a..ff1905707a3d2 100644 --- a/tests/baselines/reference/library-reference-11.trace.json +++ b/tests/baselines/reference/library-reference-11.trace.json @@ -3,9 +3,8 @@ "Root directory cannot be determined, skipping primary search paths.", "Looking up in 'node_modules' folder, initial location '/a/b'.", "Directory '/a/b/node_modules' does not exist, skipping all lookups in it.", - "'package.json' has 'typings' field 'jquery.d.ts' that references '/a/node_modules/jquery/jquery.d.ts'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/a/node_modules/jquery/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/a/node_modules/jquery.d.ts' does not exist.", "'package.json' has 'typings' field 'jquery.d.ts' that references '/a/node_modules/jquery/jquery.d.ts'.", "File '/a/node_modules/jquery/jquery.d.ts' exist - use it as a name resolution result.", diff --git a/tests/baselines/reference/library-reference-12.trace.json b/tests/baselines/reference/library-reference-12.trace.json index 1421f1501d932..63be1cc32a35d 100644 --- a/tests/baselines/reference/library-reference-12.trace.json +++ b/tests/baselines/reference/library-reference-12.trace.json @@ -3,10 +3,8 @@ "Root directory cannot be determined, skipping primary search paths.", "Looking up in 'node_modules' folder, initial location '/a/b'.", "Directory '/a/b/node_modules' does not exist, skipping all lookups in it.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'dist/jquery.d.ts' that references '/a/node_modules/jquery/dist/jquery.d.ts'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/a/node_modules/jquery/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/a/node_modules/jquery.d.ts' does not exist.", "'package.json' does not have a 'typings' field.", "'package.json' has 'types' field 'dist/jquery.d.ts' that references '/a/node_modules/jquery/dist/jquery.d.ts'.", diff --git a/tests/baselines/reference/library-reference-2.trace.json b/tests/baselines/reference/library-reference-2.trace.json index b9b4cf08ca2ce..d4f509900056d 100644 --- a/tests/baselines/reference/library-reference-2.trace.json +++ b/tests/baselines/reference/library-reference-2.trace.json @@ -1,10 +1,8 @@ [ "======== Resolving type reference directive 'jquery', containing file '/consumer.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/types/jquery/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "'package.json' does not have a 'typings' field.", "'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.", @@ -12,10 +10,8 @@ "======== Type reference directive 'jquery' was successfully resolved to '/types/jquery/jquery.d.ts', primary: true. ========", "======== Resolving type reference directive 'jquery', containing file '/test/__inferred type names__.ts', root directory '/types'. ========", "Resolving with primary search path '/types'.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'jquery.d.ts' that references '/types/jquery/jquery.d.ts'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/types/jquery/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "'package.json' does not have a 'typings' field.", "'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/moduleResolutionPackageIdWithRelativeAndAbsolutePath.trace.json b/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.trace.json index 9f514de9f25c8..e3d7b5dea54a4 100644 --- a/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.trace.json +++ b/tests/baselines/reference/moduleResolutionPackageIdWithRelativeAndAbsolutePath.trace.json @@ -41,21 +41,21 @@ "Loading module as file / folder, candidate module location '/project/troublesome-lib/lib/Compactable', target file type 'TypeScript'.", "Loading module 'troublesome-lib/lib/Compactable' from 'node_modules' folder, target file type 'TypeScript'.", "Directory '/project/node_modules/anotherLib/node_modules' does not exist, skipping all lookups in it.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/project/node_modules/troublesome-lib/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/project/node_modules/troublesome-lib/lib/Compactable.ts' does not exist.", "File '/project/node_modules/troublesome-lib/lib/Compactable.tsx' does not exist.", "File '/project/node_modules/troublesome-lib/lib/Compactable.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/project/node_modules/troublesome-lib/lib/Compactable.d.ts', result '/project/node_modules/troublesome-lib/lib/Compactable.d.ts'.", - "======== Module name 'troublesome-lib/lib/Compactable' was successfully resolved to '/project/node_modules/troublesome-lib/lib/Compactable.d.ts' with Package ID 'troublesome-lib/lib/Compactable/index.d.ts@1.17.1'. ========", + "======== Module name 'troublesome-lib/lib/Compactable' was successfully resolved to '/project/node_modules/troublesome-lib/lib/Compactable.d.ts' with Package ID 'troublesome-lib/lib/Compactable.d.ts@1.17.1'. ========", "======== Resolving module './Option' from '/project/node_modules/troublesome-lib/lib/Compactable.d.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location '/project/node_modules/troublesome-lib/lib/Option', target file type 'TypeScript'.", "File '/project/node_modules/troublesome-lib/lib/Option.ts' does not exist.", "File '/project/node_modules/troublesome-lib/lib/Option.tsx' does not exist.", "File '/project/node_modules/troublesome-lib/lib/Option.d.ts' exist - use it as a name resolution result.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/project/node_modules/troublesome-lib/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "======== Module name './Option' was successfully resolved to '/project/node_modules/troublesome-lib/lib/Option.d.ts' with Package ID 'troublesome-lib/lib/Option.d.ts@1.17.1'. ========", "======== Resolving module 'troublesome-lib/lib/Option' from '/shared/lib/app.d.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", @@ -66,11 +66,11 @@ "Loading module as file / folder, candidate module location '/project/troublesome-lib/lib/Option', target file type 'TypeScript'.", "Loading module 'troublesome-lib/lib/Option' from 'node_modules' folder, target file type 'TypeScript'.", "Directory '/shared/lib/node_modules' does not exist, skipping all lookups in it.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/shared/node_modules/troublesome-lib/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/shared/node_modules/troublesome-lib/lib/Option.ts' does not exist.", "File '/shared/node_modules/troublesome-lib/lib/Option.tsx' does not exist.", "File '/shared/node_modules/troublesome-lib/lib/Option.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/shared/node_modules/troublesome-lib/lib/Option.d.ts', result '/shared/node_modules/troublesome-lib/lib/Option.d.ts'.", - "======== Module name 'troublesome-lib/lib/Option' was successfully resolved to '/shared/node_modules/troublesome-lib/lib/Option.d.ts' with Package ID 'troublesome-lib/lib/Option/index.d.ts@1.17.1'. ========" + "======== Module name 'troublesome-lib/lib/Option' was successfully resolved to '/shared/node_modules/troublesome-lib/lib/Option.d.ts' with Package ID 'troublesome-lib/lib/Option.d.ts@1.17.1'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.trace.json b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.trace.json index d386774db15ac..28e150aa34579 100644 --- a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.trace.json +++ b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected.trace.json @@ -2,11 +2,8 @@ "======== Resolving module 'normalize.css' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'normalize.css' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' does not have a 'types' field.", - "'package.json' has 'main' field 'normalize.css' that references '/node_modules/normalize.css/normalize.css'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/normalize.css/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/normalize.css.ts' does not exist.", "File '/node_modules/normalize.css.tsx' does not exist.", "File '/node_modules/normalize.css.d.ts' does not exist.", @@ -25,11 +22,8 @@ "File '/node_modules/normalize.css/index.d.ts' does not exist.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "Loading module 'normalize.css' from 'node_modules' folder, target file type 'JavaScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' does not have a 'types' field.", - "'package.json' has 'main' field 'normalize.css' that references '/node_modules/normalize.css/normalize.css'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/normalize.css/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/normalize.css.js' does not exist.", "File '/node_modules/normalize.css.jsx' does not exist.", "'package.json' has 'main' field 'normalize.css' that references '/node_modules/normalize.css/normalize.css'.", diff --git a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.trace.json b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.trace.json index 09a7bf81c98ab..a92c5953af3a2 100644 --- a/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.trace.json +++ b/tests/baselines/reference/moduleResolutionWithExtensions_unexpected2.trace.json @@ -2,10 +2,8 @@ "======== Resolving module 'foo' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'foo.js' that references '/node_modules/foo/foo.js'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/foo/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/foo.ts' does not exist.", "File '/node_modules/foo.tsx' does not exist.", "File '/node_modules/foo.d.ts' does not exist.", @@ -27,10 +25,8 @@ "File '/node_modules/foo/index.d.ts' does not exist.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "Loading module 'foo' from 'node_modules' folder, target file type 'JavaScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'foo.js' that references '/node_modules/foo/foo.js'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/foo/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/foo.js' does not exist.", "File '/node_modules/foo.jsx' does not exist.", "'package.json' does not have a 'main' field.", diff --git a/tests/baselines/reference/moduleResolution_packageJson_notAtPackageRoot.trace.json b/tests/baselines/reference/moduleResolution_packageJson_notAtPackageRoot.trace.json index dbd645d9d65d8..a0ff3e6a5f767 100644 --- a/tests/baselines/reference/moduleResolution_packageJson_notAtPackageRoot.trace.json +++ b/tests/baselines/reference/moduleResolution_packageJson_notAtPackageRoot.trace.json @@ -2,10 +2,8 @@ "======== Resolving module 'foo/bar' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'foo/bar' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'types.d.ts' that references '/node_modules/foo/bar/types.d.ts'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/foo/bar/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/foo/bar.ts' does not exist.", "File '/node_modules/foo/bar.tsx' does not exist.", "File '/node_modules/foo/bar.d.ts' does not exist.", diff --git a/tests/baselines/reference/moduleResolution_packageJson_notAtPackageRoot_fakeScopedPackage.trace.json b/tests/baselines/reference/moduleResolution_packageJson_notAtPackageRoot_fakeScopedPackage.trace.json index e47dcc86b1234..ebeee4299fe01 100644 --- a/tests/baselines/reference/moduleResolution_packageJson_notAtPackageRoot_fakeScopedPackage.trace.json +++ b/tests/baselines/reference/moduleResolution_packageJson_notAtPackageRoot_fakeScopedPackage.trace.json @@ -2,10 +2,8 @@ "======== Resolving module 'foo/@bar' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'foo/@bar' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'types.d.ts' that references '/node_modules/foo/@bar/types.d.ts'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/foo/@bar/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/foo/@bar.ts' does not exist.", "File '/node_modules/foo/@bar.tsx' does not exist.", "File '/node_modules/foo/@bar.d.ts' does not exist.", diff --git a/tests/baselines/reference/moduleResolution_packageJson_scopedPackage.trace.json b/tests/baselines/reference/moduleResolution_packageJson_scopedPackage.trace.json index a8e509ff6e8af..959e178b57e02 100644 --- a/tests/baselines/reference/moduleResolution_packageJson_scopedPackage.trace.json +++ b/tests/baselines/reference/moduleResolution_packageJson_scopedPackage.trace.json @@ -2,10 +2,8 @@ "======== Resolving module '@foo/bar' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module '@foo/bar' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'types.d.ts' that references '/node_modules/@foo/bar/types.d.ts'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/@foo/bar/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/@foo/bar.ts' does not exist.", "File '/node_modules/@foo/bar.tsx' does not exist.", "File '/node_modules/@foo/bar.d.ts' does not exist.", diff --git a/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot.trace.json b/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot.trace.json index 4a2e60d9c7f53..aafca116d0b68 100644 --- a/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot.trace.json +++ b/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot.trace.json @@ -3,22 +3,31 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'foo/bar' from 'node_modules' folder, target file type 'TypeScript'.", "File '/node_modules/foo/bar/package.json' does not exist.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/foo/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/foo/bar.ts' does not exist.", "File '/node_modules/foo/bar.tsx' does not exist.", "File '/node_modules/foo/bar.d.ts' does not exist.", + "'package.json' does not have a 'typings' field.", + "'package.json' has 'types' field 'types.d.ts' that references '/node_modules/foo/bar/types.d.ts'.", + "File '/node_modules/foo/bar/types.d.ts' does not exist.", + "Loading module as file / folder, candidate module location '/node_modules/foo/bar/types.d.ts', target file type 'TypeScript'.", + "File '/node_modules/foo/bar/types.d.ts.ts' does not exist.", + "File '/node_modules/foo/bar/types.d.ts.tsx' does not exist.", + "File '/node_modules/foo/bar/types.d.ts.d.ts' does not exist.", + "Directory '/node_modules/foo/bar/types.d.ts' does not exist, skipping all lookups in it.", "File '/node_modules/foo/bar/index.ts' does not exist.", "File '/node_modules/foo/bar/index.tsx' does not exist.", "File '/node_modules/foo/bar/index.d.ts' does not exist.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "Loading module 'foo/bar' from 'node_modules' folder, target file type 'JavaScript'.", "File '/node_modules/foo/bar/package.json' does not exist.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/foo/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/foo/bar.js' does not exist.", "File '/node_modules/foo/bar.jsx' does not exist.", + "'package.json' does not have a 'main' field.", "File '/node_modules/foo/bar/index.js' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/foo/bar/index.js', result '/node_modules/foo/bar/index.js'.", - "======== Module name 'foo/bar' was successfully resolved to '/node_modules/foo/bar/index.js' with Package ID 'foo/bar/index.d.ts@1.2.3'. ========" + "======== Module name 'foo/bar' was successfully resolved to '/node_modules/foo/bar/index.js' with Package ID 'foo/bar/index.js@1.2.3'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_fakeScopedPackage.trace.json b/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_fakeScopedPackage.trace.json index 3f2423ce832b3..f41b1ca07102a 100644 --- a/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_fakeScopedPackage.trace.json +++ b/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_fakeScopedPackage.trace.json @@ -3,22 +3,31 @@ "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'foo/@bar' from 'node_modules' folder, target file type 'TypeScript'.", "File '/node_modules/foo/@bar/package.json' does not exist.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/foo/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/foo/@bar.ts' does not exist.", "File '/node_modules/foo/@bar.tsx' does not exist.", "File '/node_modules/foo/@bar.d.ts' does not exist.", + "'package.json' does not have a 'typings' field.", + "'package.json' has 'types' field 'types.d.ts' that references '/node_modules/foo/@bar/types.d.ts'.", + "File '/node_modules/foo/@bar/types.d.ts' does not exist.", + "Loading module as file / folder, candidate module location '/node_modules/foo/@bar/types.d.ts', target file type 'TypeScript'.", + "File '/node_modules/foo/@bar/types.d.ts.ts' does not exist.", + "File '/node_modules/foo/@bar/types.d.ts.tsx' does not exist.", + "File '/node_modules/foo/@bar/types.d.ts.d.ts' does not exist.", + "Directory '/node_modules/foo/@bar/types.d.ts' does not exist, skipping all lookups in it.", "File '/node_modules/foo/@bar/index.ts' does not exist.", "File '/node_modules/foo/@bar/index.tsx' does not exist.", "File '/node_modules/foo/@bar/index.d.ts' does not exist.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "Loading module 'foo/@bar' from 'node_modules' folder, target file type 'JavaScript'.", "File '/node_modules/foo/@bar/package.json' does not exist.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/foo/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/foo/@bar.js' does not exist.", "File '/node_modules/foo/@bar.jsx' does not exist.", + "'package.json' does not have a 'main' field.", "File '/node_modules/foo/@bar/index.js' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/foo/@bar/index.js', result '/node_modules/foo/@bar/index.js'.", - "======== Module name 'foo/@bar' was successfully resolved to '/node_modules/foo/@bar/index.js' with Package ID 'foo/@bar/index.d.ts@1.2.3'. ========" + "======== Module name 'foo/@bar' was successfully resolved to '/node_modules/foo/@bar/index.js' with Package ID 'foo/@bar/index.js@1.2.3'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_mainFieldInSubDirectory.trace.json b/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_mainFieldInSubDirectory.trace.json index 6b373fb300f16..cf2b1082bf88f 100644 --- a/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_mainFieldInSubDirectory.trace.json +++ b/tests/baselines/reference/moduleResolution_packageJson_yesAtPackageRoot_mainFieldInSubDirectory.trace.json @@ -2,11 +2,8 @@ "======== Resolving module 'foo' from '/index.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' does not have a 'types' field.", - "'package.json' has 'main' field 'src/index.js' that references '/node_modules/foo/src/index.js'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/foo/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/foo.ts' does not exist.", "File '/node_modules/foo.tsx' does not exist.", "File '/node_modules/foo.d.ts' does not exist.", diff --git a/tests/baselines/reference/packageJsonMain.trace.json b/tests/baselines/reference/packageJsonMain.trace.json index 1f722312e1d77..2144b6eb15c49 100644 --- a/tests/baselines/reference/packageJsonMain.trace.json +++ b/tests/baselines/reference/packageJsonMain.trace.json @@ -2,11 +2,8 @@ "======== Resolving module 'foo' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' does not have a 'types' field.", - "'package.json' has 'main' field 'oof' that references '/node_modules/foo/oof'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/foo/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/foo.ts' does not exist.", "File '/node_modules/foo.tsx' does not exist.", "File '/node_modules/foo.d.ts' does not exist.", @@ -24,11 +21,8 @@ "File '/node_modules/foo/index.d.ts' does not exist.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "Loading module 'foo' from 'node_modules' folder, target file type 'JavaScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' does not have a 'types' field.", - "'package.json' has 'main' field 'oof' that references '/node_modules/foo/oof'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/foo/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/foo.js' does not exist.", "File '/node_modules/foo.jsx' does not exist.", "'package.json' has 'main' field 'oof' that references '/node_modules/foo/oof'.", @@ -40,11 +34,8 @@ "======== Resolving module 'bar' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'bar' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' does not have a 'types' field.", - "'package.json' has 'main' field 'rab.js' that references '/node_modules/bar/rab.js'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/bar/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/bar.ts' does not exist.", "File '/node_modules/bar.tsx' does not exist.", "File '/node_modules/bar.d.ts' does not exist.", @@ -67,11 +58,8 @@ "File '/node_modules/bar/index.d.ts' does not exist.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "Loading module 'bar' from 'node_modules' folder, target file type 'JavaScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' does not have a 'types' field.", - "'package.json' has 'main' field 'rab.js' that references '/node_modules/bar/rab.js'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/bar/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/bar.js' does not exist.", "File '/node_modules/bar.jsx' does not exist.", "'package.json' has 'main' field 'rab.js' that references '/node_modules/bar/rab.js'.", @@ -81,11 +69,8 @@ "======== Resolving module 'baz' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'baz' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' does not have a 'types' field.", - "'package.json' has 'main' field 'zab' that references '/node_modules/baz/zab'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/baz/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/baz.ts' does not exist.", "File '/node_modules/baz.tsx' does not exist.", "File '/node_modules/baz.d.ts' does not exist.", @@ -105,11 +90,8 @@ "File '/node_modules/baz/index.d.ts' does not exist.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "Loading module 'baz' from 'node_modules' folder, target file type 'JavaScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' does not have a 'types' field.", - "'package.json' has 'main' field 'zab' that references '/node_modules/baz/zab'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/baz/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/baz.js' does not exist.", "File '/node_modules/baz.jsx' does not exist.", "'package.json' has 'main' field 'zab' that references '/node_modules/baz/zab'.", diff --git a/tests/baselines/reference/packageJsonMain_isNonRecursive.trace.json b/tests/baselines/reference/packageJsonMain_isNonRecursive.trace.json index f2f16ec6aebf8..5bdd8a7e90c4b 100644 --- a/tests/baselines/reference/packageJsonMain_isNonRecursive.trace.json +++ b/tests/baselines/reference/packageJsonMain_isNonRecursive.trace.json @@ -2,11 +2,8 @@ "======== Resolving module 'foo' from '/a.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'foo' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' does not have a 'types' field.", - "'package.json' has 'main' field 'oof' that references '/node_modules/foo/oof'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/foo/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/foo.ts' does not exist.", "File '/node_modules/foo.tsx' does not exist.", "File '/node_modules/foo.d.ts' does not exist.", @@ -26,11 +23,8 @@ "File '/node_modules/foo/index.d.ts' does not exist.", "Directory '/node_modules/@types' does not exist, skipping all lookups in it.", "Loading module 'foo' from 'node_modules' folder, target file type 'JavaScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' does not have a 'types' field.", - "'package.json' has 'main' field 'oof' that references '/node_modules/foo/oof'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/foo/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/foo.js' does not exist.", "File '/node_modules/foo.jsx' does not exist.", "'package.json' has 'main' field 'oof' that references '/node_modules/foo/oof'.", diff --git a/tests/baselines/reference/typesVersions.ambientModules.trace.json b/tests/baselines/reference/typesVersions.ambientModules.trace.json index dcaf6acc09694..53de9ae651ec6 100644 --- a/tests/baselines/reference/typesVersions.ambientModules.trace.json +++ b/tests/baselines/reference/typesVersions.ambientModules.trace.json @@ -2,10 +2,8 @@ "======== Resolving module 'ext' from 'tests/cases/conformance/moduleResolution/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/moduleResolution/node_modules/ext/index'.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/moduleResolution/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext.ts' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext.tsx' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext.d.ts' does not exist.", @@ -20,18 +18,20 @@ "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts', result 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts'.", - "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/index.d.ts@1.0.0'. ========", + "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/ts3.1/index.d.ts@1.0.0'. ========", "======== Resolving module 'ext/other' from 'tests/cases/conformance/moduleResolution/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/moduleResolution/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "Module name 'other', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/other'.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.ts' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.tsx' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.d.ts' does not exist.", + "'package.json' does not have a 'typings' field.", + "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other/index'.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'index'.", "Module name 'index', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/index'.", @@ -43,13 +43,14 @@ "Directory 'node_modules' does not exist, skipping all lookups in it.", "Directory '/node_modules' does not exist, skipping all lookups in it.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'JavaScript'.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/moduleResolution/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "Module name 'other', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/other'.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.js' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.jsx' does not exist.", + "'package.json' does not have a 'main' field.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'index'.", "Module name 'index', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/index'.", diff --git a/tests/baselines/reference/typesVersions.justIndex.trace.json b/tests/baselines/reference/typesVersions.justIndex.trace.json index 28e4a5cb3bfaf..263d16b0b4ba4 100644 --- a/tests/baselines/reference/typesVersions.justIndex.trace.json +++ b/tests/baselines/reference/typesVersions.justIndex.trace.json @@ -7,11 +7,8 @@ "File '/a.ts' does not exist.", "File '/a.tsx' does not exist.", "File '/a.d.ts' does not exist.", - "'package.json' does not have a 'typings' field.", - "'package.json' does not have a 'types' field.", - "'package.json' does not have a 'main' field.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at '/a/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "'package.json' does not have a 'typings' field.", "'package.json' does not have a 'types' field.", "'package.json' does not have a 'main' field.", diff --git a/tests/baselines/reference/typesVersions.multiFile.trace.json b/tests/baselines/reference/typesVersions.multiFile.trace.json index 7197547409261..d487d35294882 100644 --- a/tests/baselines/reference/typesVersions.multiFile.trace.json +++ b/tests/baselines/reference/typesVersions.multiFile.trace.json @@ -2,10 +2,8 @@ "======== Resolving module 'ext' from 'tests/cases/conformance/moduleResolution/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/moduleResolution/node_modules/ext/index'.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/moduleResolution/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext.ts' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext.tsx' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext.d.ts' does not exist.", @@ -20,12 +18,12 @@ "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts', result 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts'.", - "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/index.d.ts@1.0.0'. ========", + "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/ts3.1/index.d.ts@1.0.0'. ========", "======== Resolving module 'ext/other' from 'tests/cases/conformance/moduleResolution/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/moduleResolution/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "Module name 'other', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/other'.", @@ -33,5 +31,5 @@ "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.tsx' does not exist.", "File 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.d.ts', result 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.d.ts'.", - "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.d.ts' with Package ID 'ext/other/index.d.ts@1.0.0'. ========" + "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/moduleResolution/node_modules/ext/ts3.1/other.d.ts' with Package ID 'ext/ts3.1/other.d.ts@1.0.0'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typesVersionsDeclarationEmit.ambient.trace.json b/tests/baselines/reference/typesVersionsDeclarationEmit.ambient.trace.json index 5d5009e8a4105..97972b9d1f67c 100644 --- a/tests/baselines/reference/typesVersionsDeclarationEmit.ambient.trace.json +++ b/tests/baselines/reference/typesVersionsDeclarationEmit.ambient.trace.json @@ -2,10 +2,8 @@ "======== Resolving module 'ext' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/declarationEmit/node_modules/ext/index'.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.ts' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.d.ts' does not exist.", @@ -20,18 +18,20 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'.", - "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/index.d.ts@1.0.0'. ========", + "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/ts3.1/index.d.ts@1.0.0'. ========", "======== Resolving module 'ext/other' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "Module name 'other', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/other'.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.ts' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' does not exist.", + "'package.json' does not have a 'typings' field.", + "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other/index'.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'index'.", "Module name 'index', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/index'.", @@ -43,13 +43,14 @@ "Directory 'node_modules' does not exist, skipping all lookups in it.", "Directory '/node_modules' does not exist, skipping all lookups in it.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'JavaScript'.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "Module name 'other', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/other'.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.js' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.jsx' does not exist.", + "'package.json' does not have a 'main' field.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'index'.", "Module name 'index', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/index'.", diff --git a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFile.trace.json b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFile.trace.json index 9fb9c48332a18..224839cf26dbe 100644 --- a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFile.trace.json +++ b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFile.trace.json @@ -2,10 +2,8 @@ "======== Resolving module 'ext' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/declarationEmit/node_modules/ext/index'.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.ts' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.d.ts' does not exist.", @@ -20,12 +18,12 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'.", - "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/index.d.ts@1.0.0'. ========", + "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/ts3.1/index.d.ts@1.0.0'. ========", "======== Resolving module 'ext/other' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "Module name 'other', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/other'.", @@ -33,5 +31,5 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts'.", - "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' with Package ID 'ext/other/index.d.ts@1.0.0'. ========" + "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' with Package ID 'ext/ts3.1/other.d.ts@1.0.0'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json index 6deb7327c99dc..a89df5a6dfe9d 100644 --- a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json +++ b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToSelf.trace.json @@ -2,10 +2,8 @@ "======== Resolving module '../' from 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location 'tests/cases/conformance/declarationEmit/node_modules/ext/', target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/declarationEmit/node_modules/ext/index'.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "'package.json' does not have a 'typings' field.", "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/declarationEmit/node_modules/ext/index'.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'index'.", @@ -16,23 +14,21 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.ts' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", - "======== Module name '../' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/ndex/index.d.ts@1.0.0'. ========", + "======== Module name '../' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/s3.1/index.d.ts@1.0.0'. ========", "======== Resolving module '../other' from 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module as file / folder, candidate module location 'tests/cases/conformance/declarationEmit/node_modules/ext/other', target file type 'TypeScript'.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.ts' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' exist - use it as a name resolution result.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "======== Module name '../other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' with Package ID 'ext/other.d.ts@1.0.0'. ========", "======== Resolving module 'ext' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/declarationEmit/node_modules/ext/index'.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.ts' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.d.ts' does not exist.", @@ -47,12 +43,12 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'.", - "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/index.d.ts@1.0.0'. ========", + "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/ts3.1/index.d.ts@1.0.0'. ========", "======== Resolving module 'ext/other' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "Module name 'other', matched pattern '*'.", "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/other'.", @@ -60,5 +56,5 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts'.", - "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' with Package ID 'ext/other/index.d.ts@1.0.0'. ========" + "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/other.d.ts' with Package ID 'ext/ts3.1/other.d.ts@1.0.0'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToUnmapped.trace.json b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToUnmapped.trace.json index 94f15e642605d..7da95cd402c2f 100644 --- a/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToUnmapped.trace.json +++ b/tests/baselines/reference/typesVersionsDeclarationEmit.multiFileBackReferenceToUnmapped.trace.json @@ -5,16 +5,14 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.ts' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' exist - use it as a name resolution result.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "======== Module name '../other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' with Package ID 'ext/other.d.ts@1.0.0'. ========", "======== Resolving module 'ext' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' does not have a 'typings' field.", - "'package.json' has 'types' field 'index' that references 'tests/cases/conformance/declarationEmit/node_modules/ext/index'.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.ts' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext.d.ts' does not exist.", @@ -29,16 +27,16 @@ "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts'.", - "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/index.d.ts@1.0.0'. ========", + "======== Module name 'ext' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/ts3.1/index.d.ts' with Package ID 'ext/ts3.1/index.d.ts@1.0.0'. ========", "======== Resolving module 'ext/other' from 'tests/cases/conformance/declarationEmit/main.ts'. ========", "Module resolution kind is not specified, using 'NodeJs'.", "Loading module 'ext/other' from 'node_modules' folder, target file type 'TypeScript'.", - "'package.json' has a 'typesVersions' field with version-specific path mappings.", "Found 'package.json' at 'tests/cases/conformance/declarationEmit/node_modules/ext/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'other'.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.ts' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.tsx' does not exist.", "File 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' exist - use it as a name resolution result.", "Resolving real path for 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts', result 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts'.", - "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' with Package ID 'ext/other/index.d.ts@1.0.0'. ========" + "======== Module name 'ext/other' was successfully resolved to 'tests/cases/conformance/declarationEmit/node_modules/ext/other.d.ts' with Package ID 'ext/other.d.ts@1.0.0'. ========" ] \ No newline at end of file diff --git a/tests/baselines/reference/typingsLookup4.trace.json b/tests/baselines/reference/typingsLookup4.trace.json index 6409896ad1744..3ce97d9d8c983 100644 --- a/tests/baselines/reference/typingsLookup4.trace.json +++ b/tests/baselines/reference/typingsLookup4.trace.json @@ -5,9 +5,8 @@ "File '/node_modules/jquery.ts' does not exist.", "File '/node_modules/jquery.tsx' does not exist.", "File '/node_modules/jquery.d.ts' does not exist.", - "'package.json' has 'typings' field 'jquery.d.ts' that references '/node_modules/@types/jquery/jquery.d.ts'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/@types/jquery/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/@types/jquery.d.ts' does not exist.", "'package.json' has 'typings' field 'jquery.d.ts' that references '/node_modules/@types/jquery/jquery.d.ts'.", "File '/node_modules/@types/jquery/jquery.d.ts' exist - use it as a name resolution result.", @@ -19,9 +18,8 @@ "File '/node_modules/kquery.ts' does not exist.", "File '/node_modules/kquery.tsx' does not exist.", "File '/node_modules/kquery.d.ts' does not exist.", - "'package.json' has 'typings' field 'kquery' that references '/node_modules/@types/kquery/kquery'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/@types/kquery/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/@types/kquery.d.ts' does not exist.", "'package.json' has 'typings' field 'kquery' that references '/node_modules/@types/kquery/kquery'.", "File '/node_modules/@types/kquery/kquery' does not exist.", @@ -37,9 +35,8 @@ "File '/node_modules/lquery.ts' does not exist.", "File '/node_modules/lquery.tsx' does not exist.", "File '/node_modules/lquery.d.ts' does not exist.", - "'package.json' has 'typings' field 'lquery' that references '/node_modules/@types/lquery/lquery'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/@types/lquery/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/@types/lquery.d.ts' does not exist.", "'package.json' has 'typings' field 'lquery' that references '/node_modules/@types/lquery/lquery'.", "File '/node_modules/@types/lquery/lquery' does not exist.", @@ -53,9 +50,8 @@ "File '/node_modules/mquery.ts' does not exist.", "File '/node_modules/mquery.tsx' does not exist.", "File '/node_modules/mquery.d.ts' does not exist.", - "'package.json' has 'typings' field 'mquery' that references '/node_modules/@types/mquery/mquery'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/@types/mquery/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "File '/node_modules/@types/mquery.d.ts' does not exist.", "'package.json' has 'typings' field 'mquery' that references '/node_modules/@types/mquery/mquery'.", "File '/node_modules/@types/mquery/mquery' does not exist.", @@ -69,18 +65,16 @@ "======== Module name 'mquery' was successfully resolved to '/node_modules/@types/mquery/mquery/index.tsx'. ========", "======== Resolving type reference directive 'jquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========", "Resolving with primary search path '/node_modules/@types'.", - "'package.json' has 'typings' field 'jquery.d.ts' that references '/node_modules/@types/jquery/jquery.d.ts'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/@types/jquery/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "'package.json' has 'typings' field 'jquery.d.ts' that references '/node_modules/@types/jquery/jquery.d.ts'.", "File '/node_modules/@types/jquery/jquery.d.ts' exist - use it as a name resolution result.", "Resolving real path for '/node_modules/@types/jquery/jquery.d.ts', result '/node_modules/@types/jquery/jquery.d.ts'.", "======== Type reference directive 'jquery' was successfully resolved to '/node_modules/@types/jquery/jquery.d.ts', primary: true. ========", "======== Resolving type reference directive 'kquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========", "Resolving with primary search path '/node_modules/@types'.", - "'package.json' has 'typings' field 'kquery' that references '/node_modules/@types/kquery/kquery'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/@types/kquery/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "'package.json' has 'typings' field 'kquery' that references '/node_modules/@types/kquery/kquery'.", "File '/node_modules/@types/kquery/kquery' does not exist.", "Loading module as file / folder, candidate module location '/node_modules/@types/kquery/kquery', target file type 'TypeScript'.", @@ -91,9 +85,8 @@ "======== Type reference directive 'kquery' was successfully resolved to '/node_modules/@types/kquery/kquery.d.ts', primary: true. ========", "======== Resolving type reference directive 'lquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========", "Resolving with primary search path '/node_modules/@types'.", - "'package.json' has 'typings' field 'lquery' that references '/node_modules/@types/lquery/lquery'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/@types/lquery/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "'package.json' has 'typings' field 'lquery' that references '/node_modules/@types/lquery/lquery'.", "File '/node_modules/@types/lquery/lquery' does not exist.", "Loading module as file / folder, candidate module location '/node_modules/@types/lquery/lquery', target file type 'TypeScript'.", @@ -102,9 +95,8 @@ "======== Type reference directive 'lquery' was successfully resolved to '/node_modules/@types/lquery/lquery.ts', primary: true. ========", "======== Resolving type reference directive 'mquery', containing file '/__inferred type names__.ts', root directory '/node_modules/@types'. ========", "Resolving with primary search path '/node_modules/@types'.", - "'package.json' has 'typings' field 'mquery' that references '/node_modules/@types/mquery/mquery'.", - "'package.json' does not have a 'typesVersions' field.", "Found 'package.json' at '/node_modules/@types/mquery/package.json'.", + "'package.json' does not have a 'typesVersions' field.", "'package.json' has 'typings' field 'mquery' that references '/node_modules/@types/mquery/mquery'.", "File '/node_modules/@types/mquery/mquery' does not exist.", "Loading module as file / folder, candidate module location '/node_modules/@types/mquery/mquery', target file type 'TypeScript'.", From 9f6791a5abef5d9e8161de6c7bc545a65fa3fe7c Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 22 May 2019 15:03:17 -0700 Subject: [PATCH 29/43] Error when writing to readonly tuple in rest element range --- src/compiler/checker.ts | 15 ++--- .../readonlyArraysAndTuples.errors.txt | 32 ++++++++++- .../reference/readonlyArraysAndTuples.js | 17 ++++++ .../reference/readonlyArraysAndTuples.symbols | 26 +++++++++ .../reference/readonlyArraysAndTuples.types | 56 +++++++++++++++++++ .../types/tuple/readonlyArraysAndTuples.ts | 12 ++-- 6 files changed, 145 insertions(+), 13 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 05b1015b12428..dd3a67d0938f1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10101,6 +10101,7 @@ namespace ts { error(indexNode, Diagnostics.Property_0_does_not_exist_on_type_1, unescapeLeadingUnderscores(propName), typeToString(objectType)); } } + errorIfWritingToReadonlyIndex(getIndexInfoOfType(objectType, IndexKind.Number)); return mapType(objectType, t => getRestTypeOfTupleType(t) || undefinedType); } } @@ -10122,13 +10123,7 @@ namespace ts { error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType)); return indexInfo.type; } - if (indexInfo.isReadonly && accessExpression && (isAssignmentTarget(accessExpression) || isDeleteTarget(accessExpression))) { - if (accessExpression) { - error(accessExpression, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(objectType)); - return indexInfo.type; - } - return undefined; - } + errorIfWritingToReadonlyIndex(indexInfo); return indexInfo.type; } if (indexType.flags & TypeFlags.Never) { @@ -10188,6 +10183,12 @@ namespace ts { return indexType; } return undefined; + + function errorIfWritingToReadonlyIndex(indexInfo: IndexInfo | undefined): void { + if (indexInfo && indexInfo.isReadonly && accessExpression && (isAssignmentTarget(accessExpression) || isDeleteTarget(accessExpression))) { + error(accessExpression, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(objectType)); + } + } } function getIndexNodeForAccessExpression(accessNode: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression) { diff --git a/tests/baselines/reference/readonlyArraysAndTuples.errors.txt b/tests/baselines/reference/readonlyArraysAndTuples.errors.txt index 3680b78bb1ba2..39f377f4ee93b 100644 --- a/tests/baselines/reference/readonlyArraysAndTuples.errors.txt +++ b/tests/baselines/reference/readonlyArraysAndTuples.errors.txt @@ -9,9 +9,16 @@ tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(22,5): error TS27 tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(23,5): error TS4104: The type 'readonly [string, string]' is 'readonly' and cannot be assigned to the mutable type '[string, string]'. tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(24,5): error TS2739: Type 'string[]' is missing the following properties from type 'readonly [string, string]': 0, 1 tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(25,5): error TS2739: Type 'readonly string[]' is missing the following properties from type 'readonly [string, string]': 0, 1 +tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(30,3): error TS2540: Cannot assign to '0' because it is a read-only property. +tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(31,3): error TS2540: Cannot assign to '1' because it is a read-only property. +tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(32,1): error TS2542: Index signature in type 'readonly [number, number, ...number[]]' only permits reading. +tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(33,8): error TS2542: Index signature in type 'readonly [number, number, ...number[]]' only permits reading. +tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(34,1): error TS2542: Index signature in type 'readonly [number, number, ...number[]]' only permits reading. +tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(35,1): error TS2542: Index signature in type 'readonly [number, number, ...number[]]' only permits reading. +tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(36,8): error TS2542: Index signature in type 'readonly [number, number, ...number[]]' only permits reading. -==== tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts (11 errors) ==== +==== tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts (18 errors) ==== type T10 = string[]; type T11 = Array; type T12 = readonly string[]; @@ -61,4 +68,27 @@ tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts(25,5): error TS27 !!! error TS2739: Type 'readonly string[]' is missing the following properties from type 'readonly [string, string]': 0, 1 rt = mt; } + + declare var v: readonly[number, number, ...number[]]; + v[0] = 1; // Error + ~ +!!! error TS2540: Cannot assign to '0' because it is a read-only property. + v[1] = 1; // Error + ~ +!!! error TS2540: Cannot assign to '1' because it is a read-only property. + v[2] = 1; // Error + ~~~~ +!!! error TS2542: Index signature in type 'readonly [number, number, ...number[]]' only permits reading. + delete v[2]; // Error + ~~~~ +!!! error TS2542: Index signature in type 'readonly [number, number, ...number[]]' only permits reading. + v[0 + 1] = 1; // Error + ~~~~~~~~ +!!! error TS2542: Index signature in type 'readonly [number, number, ...number[]]' only permits reading. + v[0 + 2] = 1; // Error + ~~~~~~~~ +!!! error TS2542: Index signature in type 'readonly [number, number, ...number[]]' only permits reading. + delete v[0 + 1]; // Error + ~~~~~~~~ +!!! error TS2542: Index signature in type 'readonly [number, number, ...number[]]' only permits reading. \ No newline at end of file diff --git a/tests/baselines/reference/readonlyArraysAndTuples.js b/tests/baselines/reference/readonlyArraysAndTuples.js index 0ba392dadb411..f293ad01b7bbe 100644 --- a/tests/baselines/reference/readonlyArraysAndTuples.js +++ b/tests/baselines/reference/readonlyArraysAndTuples.js @@ -26,6 +26,15 @@ function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: reado rt = ra; // Error rt = mt; } + +declare var v: readonly[number, number, ...number[]]; +v[0] = 1; // Error +v[1] = 1; // Error +v[2] = 1; // Error +delete v[2]; // Error +v[0 + 1] = 1; // Error +v[0 + 2] = 1; // Error +delete v[0 + 1]; // Error //// [readonlyArraysAndTuples.js] @@ -44,6 +53,13 @@ function f1(ma, ra, mt, rt) { rt = ra; // Error rt = mt; } +v[0] = 1; // Error +v[1] = 1; // Error +v[2] = 1; // Error +delete v[2]; // Error +v[0 + 1] = 1; // Error +v[0 + 2] = 1; // Error +delete v[0 + 1]; // Error //// [readonlyArraysAndTuples.d.ts] @@ -58,3 +74,4 @@ declare type T31 = readonly T; declare type T32 = readonly readonly string[]; declare type T33 = readonly Array; declare function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: readonly [string, string]): void; +declare var v: readonly [number, number, ...number[]]; diff --git a/tests/baselines/reference/readonlyArraysAndTuples.symbols b/tests/baselines/reference/readonlyArraysAndTuples.symbols index c7c371af0d884..53b425fec097a 100644 --- a/tests/baselines/reference/readonlyArraysAndTuples.symbols +++ b/tests/baselines/reference/readonlyArraysAndTuples.symbols @@ -90,3 +90,29 @@ function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: reado >mt : Symbol(mt, Decl(readonlyArraysAndTuples.ts, 13, 48)) } +declare var v: readonly[number, number, ...number[]]; +>v : Symbol(v, Decl(readonlyArraysAndTuples.ts, 28, 11)) + +v[0] = 1; // Error +>v : Symbol(v, Decl(readonlyArraysAndTuples.ts, 28, 11)) +>0 : Symbol(0) + +v[1] = 1; // Error +>v : Symbol(v, Decl(readonlyArraysAndTuples.ts, 28, 11)) +>1 : Symbol(1) + +v[2] = 1; // Error +>v : Symbol(v, Decl(readonlyArraysAndTuples.ts, 28, 11)) + +delete v[2]; // Error +>v : Symbol(v, Decl(readonlyArraysAndTuples.ts, 28, 11)) + +v[0 + 1] = 1; // Error +>v : Symbol(v, Decl(readonlyArraysAndTuples.ts, 28, 11)) + +v[0 + 2] = 1; // Error +>v : Symbol(v, Decl(readonlyArraysAndTuples.ts, 28, 11)) + +delete v[0 + 1]; // Error +>v : Symbol(v, Decl(readonlyArraysAndTuples.ts, 28, 11)) + diff --git a/tests/baselines/reference/readonlyArraysAndTuples.types b/tests/baselines/reference/readonlyArraysAndTuples.types index 9ffb409d52698..5075319ef9550 100644 --- a/tests/baselines/reference/readonlyArraysAndTuples.types +++ b/tests/baselines/reference/readonlyArraysAndTuples.types @@ -97,3 +97,59 @@ function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: reado >mt : [string, string] } +declare var v: readonly[number, number, ...number[]]; +>v : readonly [number, number, ...number[]] + +v[0] = 1; // Error +>v[0] = 1 : 1 +>v[0] : any +>v : readonly [number, number, ...number[]] +>0 : 0 +>1 : 1 + +v[1] = 1; // Error +>v[1] = 1 : 1 +>v[1] : any +>v : readonly [number, number, ...number[]] +>1 : 1 +>1 : 1 + +v[2] = 1; // Error +>v[2] = 1 : 1 +>v[2] : number +>v : readonly [number, number, ...number[]] +>2 : 2 +>1 : 1 + +delete v[2]; // Error +>delete v[2] : boolean +>v[2] : number +>v : readonly [number, number, ...number[]] +>2 : 2 + +v[0 + 1] = 1; // Error +>v[0 + 1] = 1 : 1 +>v[0 + 1] : number +>v : readonly [number, number, ...number[]] +>0 + 1 : number +>0 : 0 +>1 : 1 +>1 : 1 + +v[0 + 2] = 1; // Error +>v[0 + 2] = 1 : 1 +>v[0 + 2] : number +>v : readonly [number, number, ...number[]] +>0 + 2 : number +>0 : 0 +>2 : 2 +>1 : 1 + +delete v[0 + 1]; // Error +>delete v[0 + 1] : boolean +>v[0 + 1] : number +>v : readonly [number, number, ...number[]] +>0 + 1 : number +>0 : 0 +>1 : 1 + diff --git a/tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts b/tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts index 35c86175a0bd5..6cfdad0d5c4bd 100644 --- a/tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts +++ b/tests/cases/conformance/types/tuple/readonlyArraysAndTuples.ts @@ -30,8 +30,10 @@ function f1(ma: string[], ra: readonly string[], mt: [string, string], rt: reado } declare var v: readonly[number, number, ...number[]]; -v[0] = 1; // Error -v[1] = 1; // Error -v[2] = 1; // Error -v[0 + 1] = 1; // Error -v[0 + 2] = 1; // Error +v[0] = 1; // Error +v[1] = 1; // Error +v[2] = 1; // Error +delete v[2]; // Error +v[0 + 1] = 1; // Error +v[0 + 2] = 1; // Error +delete v[0 + 1]; // Error From cd7a14ac21974209fc870642e6d1489a66f91af1 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 22 May 2019 17:22:33 -0700 Subject: [PATCH 30/43] Reuse getSimplifiedTypeOrConstraint function --- src/compiler/checker.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index bd8d4c05901c7..386beb7f24dd7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13066,8 +13066,7 @@ namespace ts { } // A type S is assignable to keyof T if S is assignable to keyof C, where C is the // simplified form of T or, if T doesn't simplify, the constraint of T. - const simplified = getSimplifiedType((target).type, /*writing*/ false); - const constraint = simplified !== (target).type ? simplified : getConstraintOfType((target).type); + const constraint = getSimplifiedTypeOrConstraint((target).type); if (constraint) { // We require Ternary.True here such that circular constraints don't cause // false positives. For example, given 'T extends { [K in keyof T]: string }', From 300cbef07105247ec1c826de9d785bfc72849103 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 22 May 2019 17:42:05 -0700 Subject: [PATCH 31/43] =?UTF-8?q?Don=E2=80=99t=20crash=20when=20creating?= =?UTF-8?q?=20a=20union=20signature=20from=20signatures=20that=20do=20and?= =?UTF-8?q?=20don=E2=80=99t=20have=20this=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compiler/checker.ts | 6 ++-- .../reference/unionTypeCallSignatures5.js | 17 ++++++++++ .../unionTypeCallSignatures5.symbols | 31 +++++++++++++++++++ .../reference/unionTypeCallSignatures5.types | 24 ++++++++++++++ .../types/union/unionTypeCallSignatures5.ts | 12 +++++++ 5 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/unionTypeCallSignatures5.js create mode 100644 tests/baselines/reference/unionTypeCallSignatures5.symbols create mode 100644 tests/baselines/reference/unionTypeCallSignatures5.types create mode 100644 tests/cases/conformance/types/union/unionTypeCallSignatures5.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 05b1015b12428..936c73ee9a041 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7052,10 +7052,10 @@ namespace ts { // Union the result types when more than one signature matches if (unionSignatures.length > 1) { let thisParameter = signature.thisParameter; - if (forEach(unionSignatures, sig => sig.thisParameter)) { - // TODO: GH#18217 We tested that *some* has thisParameter and now act as if *all* do + const firstThisParameterOfUnionSignatures = forEach(unionSignatures, sig => sig.thisParameter); + if (firstThisParameterOfUnionSignatures) { const thisType = getUnionType(map(unionSignatures, sig => sig.thisParameter ? getTypeOfSymbol(sig.thisParameter) : anyType), UnionReduction.Subtype); - thisParameter = createSymbolWithType(signature.thisParameter!, thisType); + thisParameter = createSymbolWithType(firstThisParameterOfUnionSignatures, thisType); } s = createUnionSignature(signature, unionSignatures); s.thisParameter = thisParameter; diff --git a/tests/baselines/reference/unionTypeCallSignatures5.js b/tests/baselines/reference/unionTypeCallSignatures5.js new file mode 100644 index 0000000000000..2e756540d9437 --- /dev/null +++ b/tests/baselines/reference/unionTypeCallSignatures5.js @@ -0,0 +1,17 @@ +//// [unionTypeCallSignatures5.ts] +// #31485 +interface A { + (this: void, b?: number): void; +} +interface B { + (this: number, b?: number): void; +} +interface C { + (i: number): void; +} +declare const fn: A | B | C; +fn(0); + + +//// [unionTypeCallSignatures5.js] +fn(0); diff --git a/tests/baselines/reference/unionTypeCallSignatures5.symbols b/tests/baselines/reference/unionTypeCallSignatures5.symbols new file mode 100644 index 0000000000000..d729dcd7aba6d --- /dev/null +++ b/tests/baselines/reference/unionTypeCallSignatures5.symbols @@ -0,0 +1,31 @@ +=== tests/cases/conformance/types/union/unionTypeCallSignatures5.ts === +// #31485 +interface A { +>A : Symbol(A, Decl(unionTypeCallSignatures5.ts, 0, 0)) + + (this: void, b?: number): void; +>this : Symbol(this, Decl(unionTypeCallSignatures5.ts, 2, 3)) +>b : Symbol(b, Decl(unionTypeCallSignatures5.ts, 2, 14)) +} +interface B { +>B : Symbol(B, Decl(unionTypeCallSignatures5.ts, 3, 1)) + + (this: number, b?: number): void; +>this : Symbol(this, Decl(unionTypeCallSignatures5.ts, 5, 3)) +>b : Symbol(b, Decl(unionTypeCallSignatures5.ts, 5, 16)) +} +interface C { +>C : Symbol(C, Decl(unionTypeCallSignatures5.ts, 6, 1)) + + (i: number): void; +>i : Symbol(i, Decl(unionTypeCallSignatures5.ts, 8, 3)) +} +declare const fn: A | B | C; +>fn : Symbol(fn, Decl(unionTypeCallSignatures5.ts, 10, 13)) +>A : Symbol(A, Decl(unionTypeCallSignatures5.ts, 0, 0)) +>B : Symbol(B, Decl(unionTypeCallSignatures5.ts, 3, 1)) +>C : Symbol(C, Decl(unionTypeCallSignatures5.ts, 6, 1)) + +fn(0); +>fn : Symbol(fn, Decl(unionTypeCallSignatures5.ts, 10, 13)) + diff --git a/tests/baselines/reference/unionTypeCallSignatures5.types b/tests/baselines/reference/unionTypeCallSignatures5.types new file mode 100644 index 0000000000000..53ce4ea655086 --- /dev/null +++ b/tests/baselines/reference/unionTypeCallSignatures5.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/types/union/unionTypeCallSignatures5.ts === +// #31485 +interface A { + (this: void, b?: number): void; +>this : void +>b : number +} +interface B { + (this: number, b?: number): void; +>this : number +>b : number +} +interface C { + (i: number): void; +>i : number +} +declare const fn: A | B | C; +>fn : A | B | C + +fn(0); +>fn(0) : void +>fn : A | B | C +>0 : 0 + diff --git a/tests/cases/conformance/types/union/unionTypeCallSignatures5.ts b/tests/cases/conformance/types/union/unionTypeCallSignatures5.ts new file mode 100644 index 0000000000000..30a5ac031adc1 --- /dev/null +++ b/tests/cases/conformance/types/union/unionTypeCallSignatures5.ts @@ -0,0 +1,12 @@ +// #31485 +interface A { + (this: void, b?: number): void; +} +interface B { + (this: number, b?: number): void; +} +interface C { + (i: number): void; +} +declare const fn: A | B | C; +fn(0); From 4d27361680796581f3f4fd5aedadff69b120470b Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 23 May 2019 11:09:28 -0700 Subject: [PATCH 32/43] Allow JS with isolated modules (#31483) * Allow JS with isolated modules Previously legacy JS code was not allowed; it was required to use ES6 module syntax. Unfortunately, the check happens after parsing but before binding, and the commonjs module indicator isn't set until binding because it's not syntactically simple like the ES6 module indicator, which is set during parsing. So I decided that JS should be allowed during isolatedModules unconditionally. We're not going to be transforming it anyway. * Update baselines * Switch test to outDir instead of noEmit --- src/compiler/diagnosticMessages.json | 2 +- src/compiler/program.ts | 4 ++-- tests/baselines/reference/commonJsIsolatedModules.js | 8 ++++++++ .../reference/commonJsIsolatedModules.symbols | 9 +++++++++ .../reference/commonJsIsolatedModules.types | 12 ++++++++++++ .../importHelpersInIsolatedModules.errors.txt | 4 ++-- .../isolatedModulesNoExternalModule.errors.txt | 4 ++-- .../reference/isolatedModulesOut.errors.txt | 4 ++-- .../isolatedModulesPlainFile-AMD.errors.txt | 4 ++-- .../isolatedModulesPlainFile-CommonJS.errors.txt | 4 ++-- .../isolatedModulesPlainFile-ES6.errors.txt | 4 ++-- .../isolatedModulesPlainFile-System.errors.txt | 4 ++-- .../isolatedModulesPlainFile-UMD.errors.txt | 4 ++-- tests/cases/compiler/commonJsIsolatedModules.ts | 12 ++++++++++++ 14 files changed, 60 insertions(+), 19 deletions(-) create mode 100644 tests/baselines/reference/commonJsIsolatedModules.js create mode 100644 tests/baselines/reference/commonJsIsolatedModules.symbols create mode 100644 tests/baselines/reference/commonJsIsolatedModules.types create mode 100644 tests/cases/compiler/commonJsIsolatedModules.ts diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e8784e7d1f26d..101b584ca1352 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -655,7 +655,7 @@ "category": "Error", "code": 1207 }, - "Cannot compile namespaces when the '--isolatedModules' flag is provided.": { + "All files must be modules when the '--isolatedModules' flag is provided.": { "category": "Error", "code": 1208 }, diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 6313cc19902b1..8e4cd48b5bad9 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2858,10 +2858,10 @@ namespace ts { createDiagnosticForOptionName(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES2015_or_higher, "isolatedModules", "target"); } - const firstNonExternalModuleSourceFile = find(files, f => !isExternalModule(f) && !f.isDeclarationFile && f.scriptKind !== ScriptKind.JSON); + const firstNonExternalModuleSourceFile = find(files, f => !isExternalModule(f) && !isSourceFileJS(f) && !f.isDeclarationFile && f.scriptKind !== ScriptKind.JSON); if (firstNonExternalModuleSourceFile) { const span = getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile); - programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); + programDiagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.All_files_must_be_modules_when_the_isolatedModules_flag_is_provided)); } } else if (firstNonAmbientExternalModuleSourceFile && languageVersion < ScriptTarget.ES2015 && options.module === ModuleKind.None) { diff --git a/tests/baselines/reference/commonJsIsolatedModules.js b/tests/baselines/reference/commonJsIsolatedModules.js new file mode 100644 index 0000000000000..fe983eec37ad8 --- /dev/null +++ b/tests/baselines/reference/commonJsIsolatedModules.js @@ -0,0 +1,8 @@ +//// [index.js] +module.exports = {} +var x = 1 + + +//// [index.js] +module.exports = {}; +var x = 1; diff --git a/tests/baselines/reference/commonJsIsolatedModules.symbols b/tests/baselines/reference/commonJsIsolatedModules.symbols new file mode 100644 index 0000000000000..f0f9d0d785553 --- /dev/null +++ b/tests/baselines/reference/commonJsIsolatedModules.symbols @@ -0,0 +1,9 @@ +=== tests/cases/compiler/index.js === +module.exports = {} +>module.exports : Symbol("tests/cases/compiler/index", Decl(index.js, 0, 0)) +>module : Symbol(module, Decl(index.js, 0, 0)) +>exports : Symbol("tests/cases/compiler/index", Decl(index.js, 0, 0)) + +var x = 1 +>x : Symbol(x, Decl(index.js, 1, 3)) + diff --git a/tests/baselines/reference/commonJsIsolatedModules.types b/tests/baselines/reference/commonJsIsolatedModules.types new file mode 100644 index 0000000000000..363b450cef94a --- /dev/null +++ b/tests/baselines/reference/commonJsIsolatedModules.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/index.js === +module.exports = {} +>module.exports = {} : typeof import("tests/cases/compiler/index") +>module.exports : typeof import("tests/cases/compiler/index") +>module : { "tests/cases/compiler/index": typeof import("tests/cases/compiler/index"); } +>exports : typeof import("tests/cases/compiler/index") +>{} : {} + +var x = 1 +>x : number +>1 : 1 + diff --git a/tests/baselines/reference/importHelpersInIsolatedModules.errors.txt b/tests/baselines/reference/importHelpersInIsolatedModules.errors.txt index 7a53c1c8c9954..9655daa3325b5 100644 --- a/tests/baselines/reference/importHelpersInIsolatedModules.errors.txt +++ b/tests/baselines/reference/importHelpersInIsolatedModules.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/script.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. +tests/cases/compiler/script.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided. ==== tests/cases/compiler/external.ts (0 errors) ==== @@ -16,7 +16,7 @@ tests/cases/compiler/script.ts(1,1): error TS1208: Cannot compile namespaces whe ==== tests/cases/compiler/script.ts (1 errors) ==== class A { } ~~~~~ -!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. +!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided. class B extends A { } declare var dec: any; diff --git a/tests/baselines/reference/isolatedModulesNoExternalModule.errors.txt b/tests/baselines/reference/isolatedModulesNoExternalModule.errors.txt index 6d0f12bb1aba3..2ca0a1139fb53 100644 --- a/tests/baselines/reference/isolatedModulesNoExternalModule.errors.txt +++ b/tests/baselines/reference/isolatedModulesNoExternalModule.errors.txt @@ -1,7 +1,7 @@ -tests/cases/compiler/file1.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. +tests/cases/compiler/file1.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided. ==== tests/cases/compiler/file1.ts (1 errors) ==== var x; ~~~ -!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. \ No newline at end of file +!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided. \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesOut.errors.txt b/tests/baselines/reference/isolatedModulesOut.errors.txt index 5581ece62e689..ef9455189d088 100644 --- a/tests/baselines/reference/isolatedModulesOut.errors.txt +++ b/tests/baselines/reference/isolatedModulesOut.errors.txt @@ -1,6 +1,6 @@ error TS5053: Option 'out' cannot be specified with option 'isolatedModules'. tests/cases/compiler/file1.ts(1,1): error TS6131: Cannot compile modules using option 'out' unless the '--module' flag is 'amd' or 'system'. -tests/cases/compiler/file2.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. +tests/cases/compiler/file2.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided. !!! error TS5053: Option 'out' cannot be specified with option 'isolatedModules'. @@ -11,4 +11,4 @@ tests/cases/compiler/file2.ts(1,1): error TS1208: Cannot compile namespaces when ==== tests/cases/compiler/file2.ts (1 errors) ==== var y; ~~~ -!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. \ No newline at end of file +!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided. \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesPlainFile-AMD.errors.txt b/tests/baselines/reference/isolatedModulesPlainFile-AMD.errors.txt index d24da5e09ccfc..6c34c9953f03b 100644 --- a/tests/baselines/reference/isolatedModulesPlainFile-AMD.errors.txt +++ b/tests/baselines/reference/isolatedModulesPlainFile-AMD.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/isolatedModulesPlainFile-AMD.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. +tests/cases/compiler/isolatedModulesPlainFile-AMD.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided. ==== tests/cases/compiler/isolatedModulesPlainFile-AMD.ts (1 errors) ==== declare function run(a: number): void; ~~~~~~~ -!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. +!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided. run(1); \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesPlainFile-CommonJS.errors.txt b/tests/baselines/reference/isolatedModulesPlainFile-CommonJS.errors.txt index 43d18c54eb957..61a6021bf7343 100644 --- a/tests/baselines/reference/isolatedModulesPlainFile-CommonJS.errors.txt +++ b/tests/baselines/reference/isolatedModulesPlainFile-CommonJS.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/isolatedModulesPlainFile-CommonJS.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. +tests/cases/compiler/isolatedModulesPlainFile-CommonJS.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided. ==== tests/cases/compiler/isolatedModulesPlainFile-CommonJS.ts (1 errors) ==== declare function run(a: number): void; ~~~~~~~ -!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. +!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided. run(1); \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesPlainFile-ES6.errors.txt b/tests/baselines/reference/isolatedModulesPlainFile-ES6.errors.txt index 56316072aff36..d1f9d635b0e93 100644 --- a/tests/baselines/reference/isolatedModulesPlainFile-ES6.errors.txt +++ b/tests/baselines/reference/isolatedModulesPlainFile-ES6.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/isolatedModulesPlainFile-ES6.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. +tests/cases/compiler/isolatedModulesPlainFile-ES6.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided. ==== tests/cases/compiler/isolatedModulesPlainFile-ES6.ts (1 errors) ==== declare function run(a: number): void; ~~~~~~~ -!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. +!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided. run(1); \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesPlainFile-System.errors.txt b/tests/baselines/reference/isolatedModulesPlainFile-System.errors.txt index b1e2ba643fa5e..e955549d754b9 100644 --- a/tests/baselines/reference/isolatedModulesPlainFile-System.errors.txt +++ b/tests/baselines/reference/isolatedModulesPlainFile-System.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/isolatedModulesPlainFile-System.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. +tests/cases/compiler/isolatedModulesPlainFile-System.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided. ==== tests/cases/compiler/isolatedModulesPlainFile-System.ts (1 errors) ==== declare function run(a: number): void; ~~~~~~~ -!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. +!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided. run(1); \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesPlainFile-UMD.errors.txt b/tests/baselines/reference/isolatedModulesPlainFile-UMD.errors.txt index 29dfe4f67fbcf..1b7a01dd5bca8 100644 --- a/tests/baselines/reference/isolatedModulesPlainFile-UMD.errors.txt +++ b/tests/baselines/reference/isolatedModulesPlainFile-UMD.errors.txt @@ -1,9 +1,9 @@ -tests/cases/compiler/isolatedModulesPlainFile-UMD.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. +tests/cases/compiler/isolatedModulesPlainFile-UMD.ts(1,1): error TS1208: All files must be modules when the '--isolatedModules' flag is provided. ==== tests/cases/compiler/isolatedModulesPlainFile-UMD.ts (1 errors) ==== declare function run(a: number): void; ~~~~~~~ -!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. +!!! error TS1208: All files must be modules when the '--isolatedModules' flag is provided. run(1); \ No newline at end of file diff --git a/tests/cases/compiler/commonJsIsolatedModules.ts b/tests/cases/compiler/commonJsIsolatedModules.ts new file mode 100644 index 0000000000000..a75a5ec96d289 --- /dev/null +++ b/tests/cases/compiler/commonJsIsolatedModules.ts @@ -0,0 +1,12 @@ +// @Filename: tsconfig.json +{ + "compilerOptions": { + "allowJs": true, + "outDir": "foo", + "isolatedModules": true, + } +} + +// @Filename: index.js +module.exports = {} +var x = 1 From f97f57c1556bde40149ef30f034480917c27fce0 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 23 May 2019 12:15:50 -0700 Subject: [PATCH 33/43] Fix containsPrecedingToken for tokens whose preceding token is a missing node --- src/harness/fourslash.ts | 10 +++++----- src/services/signatureHelp.ts | 20 +++++++++++++++----- tests/cases/fourslash/fourslash.ts | 8 ++++---- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 8a0a2bffbd4d6..bdcb3e082d2ed 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1208,7 +1208,7 @@ Actual: ${stringify(fullActual)}`); } } - public verifySignatureHelpPresence(expectPresent: boolean, triggerReason: ts.SignatureHelpTriggerReason | undefined, markers: ReadonlyArray) { + public verifySignatureHelpPresence(expectPresent: boolean, triggerReason: ts.SignatureHelpTriggerReason | undefined, markers: ReadonlyArray) { if (markers.length) { for (const marker of markers) { this.goToMarker(marker); @@ -3768,15 +3768,15 @@ namespace FourSlashInterface { assert(ranges.length !== 0, "Array of ranges is expected to be non-empty"); } - public noSignatureHelp(...markers: string[]): void { + public noSignatureHelp(...markers: (string | FourSlash.Marker)[]): void { this.state.verifySignatureHelpPresence(/*expectPresent*/ false, /*triggerReason*/ undefined, markers); } - public noSignatureHelpForTriggerReason(reason: ts.SignatureHelpTriggerReason, ...markers: string[]): void { + public noSignatureHelpForTriggerReason(reason: ts.SignatureHelpTriggerReason, ...markers: (string | FourSlash.Marker)[]): void { this.state.verifySignatureHelpPresence(/*expectPresent*/ false, reason, markers); } - public signatureHelpPresentForTriggerReason(reason: ts.SignatureHelpTriggerReason, ...markers: string[]): void { + public signatureHelpPresentForTriggerReason(reason: ts.SignatureHelpTriggerReason, ...markers: (string | FourSlash.Marker)[]): void { this.state.verifySignatureHelpPresence(/*expectPresent*/ true, reason, markers); } @@ -5124,7 +5124,7 @@ namespace FourSlashInterface { } export interface VerifySignatureHelpOptions { - readonly marker?: ArrayOrSingle; + readonly marker?: ArrayOrSingle; /** @default 1 */ readonly overloadsCount?: number; /** @default undefined */ diff --git a/src/services/signatureHelp.ts b/src/services/signatureHelp.ts index 25f958dfc6a75..998e45bd4616c 100644 --- a/src/services/signatureHelp.ts +++ b/src/services/signatureHelp.ts @@ -133,11 +133,21 @@ namespace ts.SignatureHelp { } function containsPrecedingToken(startingToken: Node, sourceFile: SourceFile, container: Node) { - const precedingToken = Debug.assertDefined( - findPrecedingToken(startingToken.getFullStart(), sourceFile, startingToken.parent, /*excludeJsdoc*/ true) - ); - - return rangeContainsRange(container, precedingToken); + const pos = startingToken.getFullStart(); + // There’s a possibility that `startingToken.parent` contains only `startingToken` and + // missing nodes, none of which are valid to be returned by `findPrecedingToken`. In that + // case, the preceding token we want is actually higher up the tree—almost definitely the + // next parent, but theoretically the situation with missing nodes might be happening on + // multiple nested levels. + let currentParent: Node | undefined = startingToken.parent; + while (currentParent) { + const precedingToken = findPrecedingToken(pos, sourceFile, currentParent, /*excludeJsdoc*/ true); + if (precedingToken) { + return rangeContainsRange(container, precedingToken); + } + currentParent = currentParent.parent; + } + return Debug.fail("Could not find preceding token"); } export interface ArgumentInfoForCompletions { diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index fa9cdd61c2f6f..b3253bcd59fff 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -232,9 +232,9 @@ declare namespace FourSlashInterface { rangesWithSameTextAreRenameLocations(): void; rangesAreRenameLocations(options?: Range[] | { findInStrings?: boolean, findInComments?: boolean, ranges?: Range[] }); findReferencesDefinitionDisplayPartsAtCaretAre(expected: ts.SymbolDisplayPart[]): void; - noSignatureHelp(...markers: string[]): void; - noSignatureHelpForTriggerReason(triggerReason: SignatureHelpTriggerReason, ...markers: string[]): void - signatureHelpPresentForTriggerReason(triggerReason: SignatureHelpTriggerReason, ...markers: string[]): void + noSignatureHelp(...markers: (string | Marker)[]): void; + noSignatureHelpForTriggerReason(triggerReason: SignatureHelpTriggerReason, ...markers: (string | Marker)[]): void + signatureHelpPresentForTriggerReason(triggerReason: SignatureHelpTriggerReason, ...markers: (string | Marker)[]): void signatureHelp(...options: VerifySignatureHelpOptions[], ): void; // Checks that there are no compile errors. noErrors(): void; @@ -538,7 +538,7 @@ declare namespace FourSlashInterface { } interface VerifySignatureHelpOptions { - marker?: ArrayOrSingle; + marker?: ArrayOrSingle; /** @default 1 */ overloadsCount?: number; docComment?: string; From 5d9d4b2553df08effc21d27dc90ca726698db348 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 23 May 2019 13:26:41 -0700 Subject: [PATCH 34/43] Manually copy just postMessage changes (#31557) * Manually copy just postMessage changes * Update baselines --- src/lib/dom.generated.d.ts | 3 ++- src/lib/webworker.generated.d.ts | 3 ++- .../baselines/reference/intersectionsOfLargeUnions2.errors.txt | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index b1daca71fed54..18f38b5356053 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -17328,7 +17328,8 @@ interface WorkerEventMap extends AbstractWorkerEventMap { /** An interface of the Web Workers API represents a background task that can be easily created and can send messages back to its creator. Creating a worker is as simple as calling the Worker() constructor and specifying a script to be run in the worker thread. */ interface Worker extends EventTarget, AbstractWorker { onmessage: ((this: Worker, ev: MessageEvent) => any) | null; - postMessage(message: any, transfer?: Transferable[]): void; + postMessage(message: any, transfer: Transferable[]): void; + postMessage(message: any, options?: PostMessageOptions): void; terminate(): void; addEventListener(type: K, listener: (this: Worker, ev: WorkerEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; diff --git a/src/lib/webworker.generated.d.ts b/src/lib/webworker.generated.d.ts index cc35615d12914..de98e9537aa94 100644 --- a/src/lib/webworker.generated.d.ts +++ b/src/lib/webworker.generated.d.ts @@ -4231,7 +4231,8 @@ interface WorkerEventMap extends AbstractWorkerEventMap { /** An interface of the Web Workers API represents a background task that can be easily created and can send messages back to its creator. Creating a worker is as simple as calling the Worker() constructor and specifying a script to be run in the worker thread. */ interface Worker extends EventTarget, AbstractWorker { onmessage: ((this: Worker, ev: MessageEvent) => any) | null; - postMessage(message: any, transfer?: Transferable[]): void; + postMessage(message: any, transfer: Transferable[]): void; + postMessage(message: any, options?: PostMessageOptions): void; terminate(): void; addEventListener(type: K, listener: (this: Worker, ev: WorkerEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; diff --git a/tests/baselines/reference/intersectionsOfLargeUnions2.errors.txt b/tests/baselines/reference/intersectionsOfLargeUnions2.errors.txt index a8d4f797fea9d..bad3705abc0b6 100644 --- a/tests/baselines/reference/intersectionsOfLargeUnions2.errors.txt +++ b/tests/baselines/reference/intersectionsOfLargeUnions2.errors.txt @@ -10,7 +10,7 @@ tests/cases/compiler/intersectionsOfLargeUnions2.ts(31,15): error TS2536: Type ' interface ElementTagNameMap { ~~~~~~~~~~~~~~~~~ !!! error TS2300: Duplicate identifier 'ElementTagNameMap'. -!!! related TS6203 /.ts/lib.dom.d.ts:18109:6: 'ElementTagNameMap' was also declared here. +!!! related TS6203 /.ts/lib.dom.d.ts:18110:6: 'ElementTagNameMap' was also declared here. [index: number]: HTMLElement } From 7359ff8158df18207ff66cb7040509051eab5242 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Thu, 23 May 2019 13:33:38 -0700 Subject: [PATCH 35/43] Add test --- tests/cases/fourslash/signatureHelpJSX.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 tests/cases/fourslash/signatureHelpJSX.ts diff --git a/tests/cases/fourslash/signatureHelpJSX.ts b/tests/cases/fourslash/signatureHelpJSX.ts new file mode 100644 index 0000000000000..181ff85541b72 --- /dev/null +++ b/tests/cases/fourslash/signatureHelpJSX.ts @@ -0,0 +1,10 @@ +/// + +//@Filename: test.tsx +//@jsx: react +////declare var React: any; +////const z =
{[].map(x => Date: Fri, 24 May 2019 01:27:50 +0300 Subject: [PATCH 36/43] Improve error messages when indexing into a type (#31379) * Improved error messages when indexing an object type with a literal string, a literal string union or a string. * Added more specific message when using the indexing operator with an incompatible index argument. * Fixed spelling and error message. --- src/compiler/checker.ts | 32 ++++++++-- src/compiler/diagnosticMessages.json | 8 +++ .../globalThisUnknownNoImplicitAny.errors.txt | 12 ++-- .../keyofAndIndexedAccess2.errors.txt | 6 +- .../reference/noImplicitAnyForIn.errors.txt | 12 ++-- .../noImplicitAnyIndexing.errors.txt | 16 +++-- ...mplicitAnyStringIndexerOnObject.errors.txt | 59 +++++++++++++++++-- .../noImplicitAnyStringIndexerOnObject.js | 38 ++++++++++++ ...noImplicitAnyStringIndexerOnObject.symbols | 52 ++++++++++++++++ .../noImplicitAnyStringIndexerOnObject.types | 59 +++++++++++++++++++ ...eIndexingWithForInNoImplicitAny.errors.txt | 6 +- .../objectSpreadIndexSignature.errors.txt | 6 +- ...ringIndexSignatureNoImplicitAny.errors.txt | 6 +- .../typeFromPrototypeAssignment3.errors.txt | 6 +- .../unionTypeWithIndexSignature.errors.txt | 12 ++-- .../noImplicitAnyStringIndexerOnObject.ts | 20 +++++++ 16 files changed, 312 insertions(+), 38 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c221da7bdb202..0d7c7b022ddd5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10067,7 +10067,7 @@ namespace ts { return false; } - function getPropertyTypeForIndexType(originalObjectType: Type, objectType: Type, indexType: Type, accessNode: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression | undefined, accessFlags: AccessFlags) { + function getPropertyTypeForIndexType(originalObjectType: Type, objectType: Type, indexType: Type, fullIndexType: Type, suppressNoImplicitAnyError: boolean, accessNode: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression | undefined, accessFlags: AccessFlags) { const accessExpression = accessNode && accessNode.kind === SyntaxKind.ElementAccessExpression ? accessNode : undefined; const propName = isTypeUsableAsPropertyName(indexType) ? getPropertyNameFromType(indexType) : @@ -10141,7 +10141,7 @@ namespace ts { if (objectType.symbol === globalThisSymbol && propName !== undefined && globalThisSymbol.exports!.has(propName) && (globalThisSymbol.exports!.get(propName)!.flags & SymbolFlags.BlockScoped)) { error(accessExpression, Diagnostics.Property_0_does_not_exist_on_type_1, unescapeLeadingUnderscores(propName), typeToString(objectType)); } - else if (noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors) { + else if (noImplicitAny && !compilerOptions.suppressImplicitAnyIndexErrors && !suppressNoImplicitAnyError) { if (propName !== undefined && typeHasStaticProperty(propName, objectType)) { error(accessExpression, Diagnostics.Property_0_is_a_static_member_of_type_1, propName as string, typeToString(objectType)); } @@ -10161,7 +10161,29 @@ namespace ts { error(accessExpression, Diagnostics.Element_implicitly_has_an_any_type_because_type_0_has_no_index_signature_Did_you_mean_to_call_1, typeToString(objectType), suggestion); } else { - error(accessExpression, Diagnostics.Element_implicitly_has_an_any_type_because_type_0_has_no_index_signature, typeToString(objectType)); + let errorInfo: DiagnosticMessageChain | undefined; + if (indexType.flags & TypeFlags.EnumLiteral) { + errorInfo = chainDiagnosticMessages(/* details */ undefined, Diagnostics.Property_0_does_not_exist_on_type_1, "[" + typeToString(indexType) + "]", typeToString(objectType)); + } + else if (indexType.flags & TypeFlags.UniqueESSymbol) { + const symbolName = getFullyQualifiedName((indexType as UniqueESSymbolType).symbol, accessExpression); + errorInfo = chainDiagnosticMessages(/* details */ undefined, Diagnostics.Property_0_does_not_exist_on_type_1, "[" + symbolName + "]", typeToString(objectType)); + } + else if (indexType.flags & TypeFlags.StringLiteral) { + errorInfo = chainDiagnosticMessages(/* details */ undefined, Diagnostics.Property_0_does_not_exist_on_type_1, (indexType as StringLiteralType).value, typeToString(objectType)); + } + else if (indexType.flags & TypeFlags.NumberLiteral) { + errorInfo = chainDiagnosticMessages(/* details */ undefined, Diagnostics.Property_0_does_not_exist_on_type_1, (indexType as NumberLiteralType).value, typeToString(objectType)); + } + else if (indexType.flags & (TypeFlags.Number | TypeFlags.String)) { + errorInfo = chainDiagnosticMessages(/* details */ undefined, Diagnostics.No_index_signature_with_a_parameter_of_type_0_was_found_on_type_1, typeToString(indexType), typeToString(objectType)); + } + + errorInfo = chainDiagnosticMessages( + errorInfo, + Diagnostics.Element_implicitly_has_an_any_type_because_expression_of_type_0_can_t_be_used_to_index_type_1, typeToString(fullIndexType), typeToString(objectType) + ); + diagnostics.add(createDiagnosticForNodeFromMessageChain(accessExpression, errorInfo)); } } } @@ -10360,7 +10382,7 @@ namespace ts { const propTypes: Type[] = []; let wasMissingProp = false; for (const t of (indexType).types) { - const propType = getPropertyTypeForIndexType(objectType, apparentObjectType, t, accessNode, accessFlags); + const propType = getPropertyTypeForIndexType(objectType, apparentObjectType, t, indexType, wasMissingProp, accessNode, accessFlags); if (propType) { propTypes.push(propType); } @@ -10378,7 +10400,7 @@ namespace ts { } return accessFlags & AccessFlags.Writing ? getIntersectionType(propTypes) : getUnionType(propTypes); } - return getPropertyTypeForIndexType(objectType, apparentObjectType, indexType, accessNode, accessFlags | AccessFlags.CacheSymbol); + return getPropertyTypeForIndexType(objectType, apparentObjectType, indexType, indexType, /* supressNoImplicitAnyError */ false, accessNode, accessFlags | AccessFlags.CacheSymbol); } function getTypeFromIndexedAccessTypeNode(node: IndexedAccessTypeNode) { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 101b584ca1352..e0579429defe3 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4288,6 +4288,14 @@ "category": "Error", "code": 7052 }, + "Element implicitly has an 'any' type because expression of type '{0}' can't be used to index type '{1}'.": { + "category": "Error", + "code": 7053 + }, + "No index signature with a parameter of type '{0}' was found on type '{1}'.": { + "category": "Error", + "code": 7054 + }, "You cannot rename this element.": { "category": "Error", "code": 8000 diff --git a/tests/baselines/reference/globalThisUnknownNoImplicitAny.errors.txt b/tests/baselines/reference/globalThisUnknownNoImplicitAny.errors.txt index 0668d03f93b84..907a6cd1ced99 100644 --- a/tests/baselines/reference/globalThisUnknownNoImplicitAny.errors.txt +++ b/tests/baselines/reference/globalThisUnknownNoImplicitAny.errors.txt @@ -2,8 +2,10 @@ tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(4,5): error TS2 tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(5,6): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(6,12): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(8,5): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. -tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(9,1): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. -tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(10,1): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. +tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(9,1): error TS7053: Element implicitly has an 'any' type because expression of type '"hi"' can't be used to index type 'typeof globalThis'. + Property 'hi' does not exist on type 'typeof globalThis'. +tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(10,1): error TS7053: Element implicitly has an 'any' type because expression of type '"hi"' can't be used to index type 'typeof globalThis'. + Property 'hi' does not exist on type 'typeof globalThis'. ==== tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts (6 errors) ==== @@ -25,8 +27,10 @@ tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(10,1): error TS !!! error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. this['hi'] ~~~~~~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"hi"' can't be used to index type 'typeof globalThis'. +!!! error TS7053: Property 'hi' does not exist on type 'typeof globalThis'. globalThis['hi'] ~~~~~~~~~~~~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"hi"' can't be used to index type 'typeof globalThis'. +!!! error TS7053: Property 'hi' does not exist on type 'typeof globalThis'. \ No newline at end of file diff --git a/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt b/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt index 1cad297c52d29..40ccd13dac4eb 100644 --- a/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccess2.errors.txt @@ -15,7 +15,8 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(26,7): error TS233 tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(27,5): error TS2322: Type '1' is not assignable to type 'T[keyof T]'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(31,5): error TS2322: Type '{ [key: string]: number; }' is not assignable to type '{ [P in K]: number; }'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(38,5): error TS2322: Type '{ [x: string]: number; }' is not assignable to type '{ [P in K]: number; }'. -tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(50,3): error TS7017: Element implicitly has an 'any' type because type 'Item' has no index signature. +tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(50,3): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Item'. + No index signature with a parameter of type 'string' was found on type 'Item'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(51,3): error TS2322: Type '123' is not assignable to type 'string & number'. Type '123' is not assignable to type 'string'. tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(52,3): error TS2322: Type '123' is not assignable to type 'T[keyof T]'. @@ -112,7 +113,8 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccess2.ts(108,5): error TS23 function f10(obj: T, k1: string, k2: keyof Item, k3: keyof T, k4: K) { obj[k1] = 123; // Error ~~~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type 'Item' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Item'. +!!! error TS7053: No index signature with a parameter of type 'string' was found on type 'Item'. obj[k2] = 123; // Error ~~~~~~~ !!! error TS2322: Type '123' is not assignable to type 'string & number'. diff --git a/tests/baselines/reference/noImplicitAnyForIn.errors.txt b/tests/baselines/reference/noImplicitAnyForIn.errors.txt index b384735d82e97..c66a7e07f9651 100644 --- a/tests/baselines/reference/noImplicitAnyForIn.errors.txt +++ b/tests/baselines/reference/noImplicitAnyForIn.errors.txt @@ -1,5 +1,7 @@ -tests/cases/compiler/noImplicitAnyForIn.ts(7,18): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. -tests/cases/compiler/noImplicitAnyForIn.ts(14,18): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +tests/cases/compiler/noImplicitAnyForIn.ts(7,18): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. + No index signature with a parameter of type 'string' was found on type '{}'. +tests/cases/compiler/noImplicitAnyForIn.ts(14,18): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. + No index signature with a parameter of type 'string' was found on type '{}'. tests/cases/compiler/noImplicitAnyForIn.ts(28,5): error TS7005: Variable 'n' implicitly has an 'any[][]' type. tests/cases/compiler/noImplicitAnyForIn.ts(30,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. @@ -13,7 +15,8 @@ tests/cases/compiler/noImplicitAnyForIn.ts(30,6): error TS2405: The left-hand si //Should yield an implicit 'any' error var _j = x[i][j]; ~~~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. +!!! error TS7053: No index signature with a parameter of type 'string' was found on type '{}'. } for (var k in x[0]) { @@ -22,7 +25,8 @@ tests/cases/compiler/noImplicitAnyForIn.ts(30,6): error TS2405: The left-hand si //Should yield an implicit 'any' error var k2 = k1[k]; ~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. +!!! error TS7053: No index signature with a parameter of type 'string' was found on type '{}'. } } diff --git a/tests/baselines/reference/noImplicitAnyIndexing.errors.txt b/tests/baselines/reference/noImplicitAnyIndexing.errors.txt index 8d1d3ea6c467d..f9631f29aa1f1 100644 --- a/tests/baselines/reference/noImplicitAnyIndexing.errors.txt +++ b/tests/baselines/reference/noImplicitAnyIndexing.errors.txt @@ -1,7 +1,9 @@ tests/cases/compiler/noImplicitAnyIndexing.ts(12,37): error TS7015: Element implicitly has an 'any' type because index expression is not of type 'number'. -tests/cases/compiler/noImplicitAnyIndexing.ts(19,9): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. -tests/cases/compiler/noImplicitAnyIndexing.ts(22,9): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. -tests/cases/compiler/noImplicitAnyIndexing.ts(30,10): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +tests/cases/compiler/noImplicitAnyIndexing.ts(19,9): error TS7053: Element implicitly has an 'any' type because expression of type '"hi"' can't be used to index type '{}'. + Property 'hi' does not exist on type '{}'. +tests/cases/compiler/noImplicitAnyIndexing.ts(22,9): error TS7053: Element implicitly has an 'any' type because expression of type '10' can't be used to index type '{}'. + Property '10' does not exist on type '{}'. +tests/cases/compiler/noImplicitAnyIndexing.ts(30,10): error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{}'. ==== tests/cases/compiler/noImplicitAnyIndexing.ts (4 errors) ==== @@ -27,12 +29,14 @@ tests/cases/compiler/noImplicitAnyIndexing.ts(30,10): error TS7017: Element impl // Should report an implicit 'any'. var x = {}["hi"]; ~~~~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"hi"' can't be used to index type '{}'. +!!! error TS7053: Property 'hi' does not exist on type '{}'. // Should report an implicit 'any'. var y = {}[10]; ~~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type '10' can't be used to index type '{}'. +!!! error TS7053: Property '10' does not exist on type '{}'. var hi: any = "hi"; @@ -42,7 +46,7 @@ tests/cases/compiler/noImplicitAnyIndexing.ts(30,10): error TS7017: Element impl // Should report an implicit 'any'. var z1 = emptyObj[hi]; ~~~~~~~~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{}'. var z2 = (emptyObj)[hi]; interface MyMap { diff --git a/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.errors.txt b/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.errors.txt index 6df52aea46a88..0d2fc1b860e8e 100644 --- a/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.errors.txt +++ b/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.errors.txt @@ -1,16 +1,29 @@ -tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(1,9): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(1,9): error TS7053: Element implicitly has an 'any' type because expression of type '"hello"' can't be used to index type '{}'. + Property 'hello' does not exist on type '{}'. tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(7,1): error TS7052: Element implicitly has an 'any' type because type '{ get: (key: string) => string; }' has no index signature. Did you mean to call 'get' ? tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(8,13): error TS7052: Element implicitly has an 'any' type because type '{ get: (key: string) => string; }' has no index signature. Did you mean to call 'get' ? -tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(13,13): error TS7017: Element implicitly has an 'any' type because type '{ set: (key: string) => string; }' has no index signature. +tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(13,13): error TS7053: Element implicitly has an 'any' type because expression of type '"hello"' can't be used to index type '{ set: (key: string) => string; }'. + Property 'hello' does not exist on type '{ set: (key: string) => string; }'. tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(19,1): error TS7052: Element implicitly has an 'any' type because type '{ set: (key: string) => string; get: (key: string) => string; }' has no index signature. Did you mean to call 'set' ? tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(20,1): error TS7052: Element implicitly has an 'any' type because type '{ set: (key: string) => string; get: (key: string) => string; }' has no index signature. Did you mean to call 'set' ? tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(21,1): error TS7052: Element implicitly has an 'any' type because type '{ set: (key: string) => string; get: (key: string) => string; }' has no index signature. Did you mean to call 'set' ? +tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(26,1): error TS7053: Element implicitly has an 'any' type because expression of type '"a" | "b" | "c"' can't be used to index type '{ a: number; }'. + Property 'b' does not exist on type '{ a: number; }'. +tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(30,1): error TS7053: Element implicitly has an 'any' type because expression of type '"c"' can't be used to index type '{ a: number; }'. + Property 'c' does not exist on type '{ a: number; }'. +tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(33,1): error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type '{ a: number; }'. + Property '[sym]' does not exist on type '{ a: number; }'. +tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(37,1): error TS7053: Element implicitly has an 'any' type because expression of type 'NumEnum' can't be used to index type '{ a: number; }'. + Property '[NumEnum.a]' does not exist on type '{ a: number; }'. +tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(42,1): error TS7053: Element implicitly has an 'any' type because expression of type 'StrEnum' can't be used to index type '{ a: number; }'. + Property '[StrEnum.b]' does not exist on type '{ a: number; }'. -==== tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts (7 errors) ==== +==== tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts (12 errors) ==== var a = {}["hello"]; ~~~~~~~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"hello"' can't be used to index type '{}'. +!!! error TS7053: Property 'hello' does not exist on type '{}'. var b: string = { '': 'foo' }['']; var c = { @@ -28,7 +41,8 @@ tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(21,1): error TS7052: }; const bar = d['hello']; ~~~~~~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type '{ set: (key: string) => string; }' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"hello"' can't be used to index type '{ set: (key: string) => string; }'. +!!! error TS7053: Property 'hello' does not exist on type '{ set: (key: string) => string; }'. var e = { set: (key: string) => 'foobar', @@ -44,4 +58,39 @@ tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts(21,1): error TS7052: ~~~~~~~~~~ !!! error TS7052: Element implicitly has an 'any' type because type '{ set: (key: string) => string; get: (key: string) => string; }' has no index signature. Did you mean to call 'set' ? + const o = { a: 0 }; + + declare const k: "a" | "b" | "c"; + o[k]; + ~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"a" | "b" | "c"' can't be used to index type '{ a: number; }'. +!!! error TS7053: Property 'b' does not exist on type '{ a: number; }'. + + + declare const k2: "c"; + o[k2]; + ~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"c"' can't be used to index type '{ a: number; }'. +!!! error TS7053: Property 'c' does not exist on type '{ a: number; }'. + + declare const sym : unique symbol; + o[sym]; + ~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type '{ a: number; }'. +!!! error TS7053: Property '[sym]' does not exist on type '{ a: number; }'. + + enum NumEnum { a, b } + let numEnumKey: NumEnum; + o[numEnumKey]; + ~~~~~~~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'NumEnum' can't be used to index type '{ a: number; }'. +!!! error TS7053: Property '[NumEnum.a]' does not exist on type '{ a: number; }'. + + + enum StrEnum { a = "a", b = "b" } + let strEnumKey: StrEnum; + o[strEnumKey]; + ~~~~~~~~~~~~~ +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'StrEnum' can't be used to index type '{ a: number; }'. +!!! error TS7053: Property '[StrEnum.b]' does not exist on type '{ a: number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.js b/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.js index a02740351cff5..572d9f38caf03 100644 --- a/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.js +++ b/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.js @@ -21,6 +21,26 @@ e['hello'] = 'modified'; e['hello'] += 1; e['hello'] ++; +const o = { a: 0 }; + +declare const k: "a" | "b" | "c"; +o[k]; + + +declare const k2: "c"; +o[k2]; + +declare const sym : unique symbol; +o[sym]; + +enum NumEnum { a, b } +let numEnumKey: NumEnum; +o[numEnumKey]; + + +enum StrEnum { a = "a", b = "b" } +let strEnumKey: StrEnum; +o[strEnumKey]; //// [noImplicitAnyStringIndexerOnObject.js] @@ -42,3 +62,21 @@ var e = { e['hello'] = 'modified'; e['hello'] += 1; e['hello']++; +var o = { a: 0 }; +o[k]; +o[k2]; +o[sym]; +var NumEnum; +(function (NumEnum) { + NumEnum[NumEnum["a"] = 0] = "a"; + NumEnum[NumEnum["b"] = 1] = "b"; +})(NumEnum || (NumEnum = {})); +var numEnumKey; +o[numEnumKey]; +var StrEnum; +(function (StrEnum) { + StrEnum["a"] = "a"; + StrEnum["b"] = "b"; +})(StrEnum || (StrEnum = {})); +var strEnumKey; +o[strEnumKey]; diff --git a/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.symbols b/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.symbols index f86c0d14b6ff7..307144b8563ce 100644 --- a/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.symbols +++ b/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.symbols @@ -55,4 +55,56 @@ e['hello'] += 1; e['hello'] ++; >e : Symbol(e, Decl(noImplicitAnyStringIndexerOnObject.ts, 14, 3)) +const o = { a: 0 }; +>o : Symbol(o, Decl(noImplicitAnyStringIndexerOnObject.ts, 22, 5)) +>a : Symbol(a, Decl(noImplicitAnyStringIndexerOnObject.ts, 22, 11)) + +declare const k: "a" | "b" | "c"; +>k : Symbol(k, Decl(noImplicitAnyStringIndexerOnObject.ts, 24, 13)) + +o[k]; +>o : Symbol(o, Decl(noImplicitAnyStringIndexerOnObject.ts, 22, 5)) +>k : Symbol(k, Decl(noImplicitAnyStringIndexerOnObject.ts, 24, 13)) + + +declare const k2: "c"; +>k2 : Symbol(k2, Decl(noImplicitAnyStringIndexerOnObject.ts, 28, 13)) + +o[k2]; +>o : Symbol(o, Decl(noImplicitAnyStringIndexerOnObject.ts, 22, 5)) +>k2 : Symbol(k2, Decl(noImplicitAnyStringIndexerOnObject.ts, 28, 13)) + +declare const sym : unique symbol; +>sym : Symbol(sym, Decl(noImplicitAnyStringIndexerOnObject.ts, 31, 13)) + +o[sym]; +>o : Symbol(o, Decl(noImplicitAnyStringIndexerOnObject.ts, 22, 5)) +>sym : Symbol(sym, Decl(noImplicitAnyStringIndexerOnObject.ts, 31, 13)) + +enum NumEnum { a, b } +>NumEnum : Symbol(NumEnum, Decl(noImplicitAnyStringIndexerOnObject.ts, 32, 7)) +>a : Symbol(NumEnum.a, Decl(noImplicitAnyStringIndexerOnObject.ts, 34, 14)) +>b : Symbol(NumEnum.b, Decl(noImplicitAnyStringIndexerOnObject.ts, 34, 17)) + +let numEnumKey: NumEnum; +>numEnumKey : Symbol(numEnumKey, Decl(noImplicitAnyStringIndexerOnObject.ts, 35, 3)) +>NumEnum : Symbol(NumEnum, Decl(noImplicitAnyStringIndexerOnObject.ts, 32, 7)) + +o[numEnumKey]; +>o : Symbol(o, Decl(noImplicitAnyStringIndexerOnObject.ts, 22, 5)) +>numEnumKey : Symbol(numEnumKey, Decl(noImplicitAnyStringIndexerOnObject.ts, 35, 3)) + + +enum StrEnum { a = "a", b = "b" } +>StrEnum : Symbol(StrEnum, Decl(noImplicitAnyStringIndexerOnObject.ts, 36, 14)) +>a : Symbol(StrEnum.a, Decl(noImplicitAnyStringIndexerOnObject.ts, 39, 14)) +>b : Symbol(StrEnum.b, Decl(noImplicitAnyStringIndexerOnObject.ts, 39, 23)) + +let strEnumKey: StrEnum; +>strEnumKey : Symbol(strEnumKey, Decl(noImplicitAnyStringIndexerOnObject.ts, 40, 3)) +>StrEnum : Symbol(StrEnum, Decl(noImplicitAnyStringIndexerOnObject.ts, 36, 14)) + +o[strEnumKey]; +>o : Symbol(o, Decl(noImplicitAnyStringIndexerOnObject.ts, 22, 5)) +>strEnumKey : Symbol(strEnumKey, Decl(noImplicitAnyStringIndexerOnObject.ts, 40, 3)) diff --git a/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.types b/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.types index dcf01d8c5e8df..fa74a19224806 100644 --- a/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.types +++ b/tests/baselines/reference/noImplicitAnyStringIndexerOnObject.types @@ -89,4 +89,63 @@ e['hello'] ++; >e : { set: (key: string) => string; get: (key: string) => string; } >'hello' : "hello" +const o = { a: 0 }; +>o : { a: number; } +>{ a: 0 } : { a: number; } +>a : number +>0 : 0 + +declare const k: "a" | "b" | "c"; +>k : "a" | "b" | "c" + +o[k]; +>o[k] : any +>o : { a: number; } +>k : "a" | "b" | "c" + + +declare const k2: "c"; +>k2 : "c" + +o[k2]; +>o[k2] : any +>o : { a: number; } +>k2 : "c" + +declare const sym : unique symbol; +>sym : unique symbol + +o[sym]; +>o[sym] : any +>o : { a: number; } +>sym : unique symbol + +enum NumEnum { a, b } +>NumEnum : NumEnum +>a : NumEnum.a +>b : NumEnum.b + +let numEnumKey: NumEnum; +>numEnumKey : NumEnum + +o[numEnumKey]; +>o[numEnumKey] : any +>o : { a: number; } +>numEnumKey : NumEnum + + +enum StrEnum { a = "a", b = "b" } +>StrEnum : StrEnum +>a : StrEnum.a +>"a" : "a" +>b : StrEnum.b +>"b" : "b" + +let strEnumKey: StrEnum; +>strEnumKey : StrEnum + +o[strEnumKey]; +>o[strEnumKey] : any +>o : { a: number; } +>strEnumKey : StrEnum diff --git a/tests/baselines/reference/nonPrimitiveIndexingWithForInNoImplicitAny.errors.txt b/tests/baselines/reference/nonPrimitiveIndexingWithForInNoImplicitAny.errors.txt index f7f2ee3db16d5..07f52bf3e6f92 100644 --- a/tests/baselines/reference/nonPrimitiveIndexingWithForInNoImplicitAny.errors.txt +++ b/tests/baselines/reference/nonPrimitiveIndexingWithForInNoImplicitAny.errors.txt @@ -1,4 +1,5 @@ -tests/cases/conformance/types/nonPrimitive/nonPrimitiveIndexingWithForInNoImplicitAny.ts(4,17): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +tests/cases/conformance/types/nonPrimitive/nonPrimitiveIndexingWithForInNoImplicitAny.ts(4,17): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. + No index signature with a parameter of type 'string' was found on type '{}'. ==== tests/cases/conformance/types/nonPrimitive/nonPrimitiveIndexingWithForInNoImplicitAny.ts (1 errors) ==== @@ -7,6 +8,7 @@ tests/cases/conformance/types/nonPrimitive/nonPrimitiveIndexingWithForInNoImplic for (var key in a) { var value = a[key]; // error ~~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. +!!! error TS7053: No index signature with a parameter of type 'string' was found on type '{}'. } \ No newline at end of file diff --git a/tests/baselines/reference/objectSpreadIndexSignature.errors.txt b/tests/baselines/reference/objectSpreadIndexSignature.errors.txt index dede126d063fe..5c373b82ae482 100644 --- a/tests/baselines/reference/objectSpreadIndexSignature.errors.txt +++ b/tests/baselines/reference/objectSpreadIndexSignature.errors.txt @@ -1,4 +1,5 @@ -tests/cases/conformance/types/spread/objectSpreadIndexSignature.ts(6,1): error TS7017: Element implicitly has an 'any' type because type '{ b: number; a: number; }' has no index signature. +tests/cases/conformance/types/spread/objectSpreadIndexSignature.ts(6,1): error TS7053: Element implicitly has an 'any' type because expression of type '101' can't be used to index type '{ b: number; a: number; }'. + Property '101' does not exist on type '{ b: number; a: number; }'. ==== tests/cases/conformance/types/spread/objectSpreadIndexSignature.ts (1 errors) ==== @@ -9,7 +10,8 @@ tests/cases/conformance/types/spread/objectSpreadIndexSignature.ts(6,1): error T // only indexed has indexer, so i[101]: any i[101]; ~~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type '{ b: number; a: number; }' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type '101' can't be used to index type '{ b: number; a: number; }'. +!!! error TS7053: Property '101' does not exist on type '{ b: number; a: number; }'. let ii = { ...indexed1, ...indexed2 }; // both have indexer, so i[1001]: number | boolean ii[1001]; diff --git a/tests/baselines/reference/propertyAccessStringIndexSignatureNoImplicitAny.errors.txt b/tests/baselines/reference/propertyAccessStringIndexSignatureNoImplicitAny.errors.txt index d5fda18109687..0211bf321bfc0 100644 --- a/tests/baselines/reference/propertyAccessStringIndexSignatureNoImplicitAny.errors.txt +++ b/tests/baselines/reference/propertyAccessStringIndexSignatureNoImplicitAny.errors.txt @@ -1,5 +1,6 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccessStringIndexSignatureNoImplicitAny.ts(10,7): error TS2339: Property 'nope' does not exist on type 'Empty'. -tests/cases/conformance/expressions/propertyAccess/propertyAccessStringIndexSignatureNoImplicitAny.ts(11,1): error TS7017: Element implicitly has an 'any' type because type 'Empty' has no index signature. +tests/cases/conformance/expressions/propertyAccess/propertyAccessStringIndexSignatureNoImplicitAny.ts(11,1): error TS7053: Element implicitly has an 'any' type because expression of type '"not allowed either"' can't be used to index type 'Empty'. + Property 'not allowed either' does not exist on type 'Empty'. ==== tests/cases/conformance/expressions/propertyAccess/propertyAccessStringIndexSignatureNoImplicitAny.ts (2 errors) ==== @@ -17,5 +18,6 @@ tests/cases/conformance/expressions/propertyAccess/propertyAccessStringIndexSign !!! error TS2339: Property 'nope' does not exist on type 'Empty'. empty["not allowed either"]; ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type 'Empty' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type '"not allowed either"' can't be used to index type 'Empty'. +!!! error TS7053: Property 'not allowed either' does not exist on type 'Empty'. \ No newline at end of file diff --git a/tests/baselines/reference/typeFromPrototypeAssignment3.errors.txt b/tests/baselines/reference/typeFromPrototypeAssignment3.errors.txt index 579c3efac7265..02ff4ae344cd4 100644 --- a/tests/baselines/reference/typeFromPrototypeAssignment3.errors.txt +++ b/tests/baselines/reference/typeFromPrototypeAssignment3.errors.txt @@ -1,5 +1,6 @@ tests/cases/conformance/salsa/bug26885.js(2,5): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. -tests/cases/conformance/salsa/bug26885.js(11,16): error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +tests/cases/conformance/salsa/bug26885.js(11,16): error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. + No index signature with a parameter of type 'string' was found on type '{}'. ==== tests/cases/conformance/salsa/bug26885.js (2 errors) ==== @@ -17,7 +18,8 @@ tests/cases/conformance/salsa/bug26885.js(11,16): error TS7017: Element implicit get(key) { return this._map[key + '']; ~~~~~~~~~~~~~~~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type '{}' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{}'. +!!! error TS7053: No index signature with a parameter of type 'string' was found on type '{}'. } } diff --git a/tests/baselines/reference/unionTypeWithIndexSignature.errors.txt b/tests/baselines/reference/unionTypeWithIndexSignature.errors.txt index fb4463bc2d90c..14a3ffc58a67f 100644 --- a/tests/baselines/reference/unionTypeWithIndexSignature.errors.txt +++ b/tests/baselines/reference/unionTypeWithIndexSignature.errors.txt @@ -1,9 +1,11 @@ tests/cases/conformance/types/union/unionTypeWithIndexSignature.ts(11,3): error TS2339: Property 'bar' does not exist on type 'Missing'. Property 'bar' does not exist on type '{ [s: string]: string; }'. tests/cases/conformance/types/union/unionTypeWithIndexSignature.ts(14,4): error TS2540: Cannot assign to 'foo' because it is a read-only property. -tests/cases/conformance/types/union/unionTypeWithIndexSignature.ts(24,1): error TS7017: Element implicitly has an 'any' type because type 'Both' has no index signature. +tests/cases/conformance/types/union/unionTypeWithIndexSignature.ts(24,1): error TS7053: Element implicitly has an 'any' type because expression of type '1' can't be used to index type 'Both'. + Property '1' does not exist on type 'Both'. tests/cases/conformance/types/union/unionTypeWithIndexSignature.ts(25,1): error TS2322: Type '"not ok"' is not assignable to type 'number'. -tests/cases/conformance/types/union/unionTypeWithIndexSignature.ts(26,1): error TS7017: Element implicitly has an 'any' type because type 'Both' has no index signature. +tests/cases/conformance/types/union/unionTypeWithIndexSignature.ts(26,1): error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'Both'. + Property '[sym]' does not exist on type 'Both'. ==== tests/cases/conformance/types/union/unionTypeWithIndexSignature.ts (5 errors) ==== @@ -37,11 +39,13 @@ tests/cases/conformance/types/union/unionTypeWithIndexSignature.ts(26,1): error both[0] = 1 both[1] = 0 // not ok ~~~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type 'Both' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type '1' can't be used to index type 'Both'. +!!! error TS7053: Property '1' does not exist on type 'Both'. both[0] = 'not ok' ~~~~~~~ !!! error TS2322: Type '"not ok"' is not assignable to type 'number'. both[sym] = 'not ok' ~~~~~~~~~ -!!! error TS7017: Element implicitly has an 'any' type because type 'Both' has no index signature. +!!! error TS7053: Element implicitly has an 'any' type because expression of type 'unique symbol' can't be used to index type 'Both'. +!!! error TS7053: Property '[sym]' does not exist on type 'Both'. \ No newline at end of file diff --git a/tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts b/tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts index 1cd967c294fb5..5e1b943008843 100644 --- a/tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts +++ b/tests/cases/compiler/noImplicitAnyStringIndexerOnObject.ts @@ -22,3 +22,23 @@ e['hello'] = 'modified'; e['hello'] += 1; e['hello'] ++; +const o = { a: 0 }; + +declare const k: "a" | "b" | "c"; +o[k]; + + +declare const k2: "c"; +o[k2]; + +declare const sym : unique symbol; +o[sym]; + +enum NumEnum { a, b } +let numEnumKey: NumEnum; +o[numEnumKey]; + + +enum StrEnum { a = "a", b = "b" } +let strEnumKey: StrEnum; +o[strEnumKey]; From f20a4fdfc48a5ea2c13896d9087d0492ed34811f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 23 May 2019 15:39:40 -0700 Subject: [PATCH 37/43] Limit size of union types resulting from intersection type normalization --- src/compiler/checker.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3111cffa12693..8760f1709c470 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9908,6 +9908,12 @@ namespace ts { else { // We are attempting to construct a type of the form X & (A | B) & Y. Transform this into a type of // the form X & A & Y | X & B & Y and recursively reduce until no union type constituents remain. + // If the estimated size of the resulting union type exceeds 100000 constituents, report an error. + const size = reduceLeft(typeSet, (n, t) => n * (t.flags & TypeFlags.Union ? (t).types.length : 1), 1); + if (size >= 100000) { + error(currentNode, Diagnostics.Expression_produces_a_union_type_that_is_too_complex_to_represent); + return errorType; + } const unionIndex = findIndex(typeSet, t => (t.flags & TypeFlags.Union) !== 0); const unionType = typeSet[unionIndex]; result = getUnionType(map(unionType.types, t => getIntersectionType(replaceElement(typeSet, unionIndex, t))), From 53f37cfec3dec5810c6099a4545f0fc974698984 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 23 May 2019 17:09:17 -0700 Subject: [PATCH 38/43] Add test --- .../normalizedIntersectionTooComplex.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/cases/compiler/normalizedIntersectionTooComplex.ts diff --git a/tests/cases/compiler/normalizedIntersectionTooComplex.ts b/tests/cases/compiler/normalizedIntersectionTooComplex.ts new file mode 100644 index 0000000000000..dff8bb120198f --- /dev/null +++ b/tests/cases/compiler/normalizedIntersectionTooComplex.ts @@ -0,0 +1,38 @@ +// @strict: true + +// Repro from #30050 + +interface Obj { + ref: T; +} +interface Func { + (x: T): void; +} +type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; +type CtorOf = (arg: UnionToIntersection) => T; + +interface Big { + "0": { common?: string; "0"?: number, ref?: Obj | Func; } + "1": { common?: string; "1"?: number, ref?: Obj | Func; } + "2": { common?: string; "2"?: number, ref?: Obj | Func; } + "3": { common?: string; "3"?: number, ref?: Obj | Func; } + "4": { common?: string; "4"?: number, ref?: Obj | Func; } + "5": { common?: string; "5"?: number, ref?: Obj | Func; } + "6": { common?: string; "6"?: number, ref?: Obj | Func; } + "7": { common?: string; "7"?: number, ref?: Obj | Func; } + "8": { common?: string; "8"?: number, ref?: Obj | Func; } + "9": { common?: string; "9"?: number, ref?: Obj | Func; } + "10": { common?: string; "10"?: number, ref?: Obj | Func; } + "11": { common?: string; "11"?: number, ref?: Obj | Func; } + "12": { common?: string; "12"?: number, ref?: Obj | Func; } + "13": { common?: string; "13"?: number, ref?: Obj | Func; } + "14": { common?: string; "14"?: number, ref?: Obj | Func; } + "15": { common?: string; "15"?: number, ref?: Obj | Func; } + "16": { common?: string; "16"?: number, ref?: Obj | Func; } + "17": { common?: string; "17"?: number, ref?: Obj | Func; } +} +declare function getCtor(comp: T): CtorOf + +declare var all: keyof Big; +const ctor = getCtor(all); +const comp = ctor({ common: "ok", ref: x => console.log(x) }); From 01d15145b402c65505baed1a078a8aa1c65dd4a1 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 23 May 2019 17:09:25 -0700 Subject: [PATCH 39/43] Accept new baselines --- ...ormalizedIntersectionTooComplex.errors.txt | 46 ++++ .../normalizedIntersectionTooComplex.js | 44 +++ .../normalizedIntersectionTooComplex.symbols | 250 ++++++++++++++++++ .../normalizedIntersectionTooComplex.types | 158 +++++++++++ 4 files changed, 498 insertions(+) create mode 100644 tests/baselines/reference/normalizedIntersectionTooComplex.errors.txt create mode 100644 tests/baselines/reference/normalizedIntersectionTooComplex.js create mode 100644 tests/baselines/reference/normalizedIntersectionTooComplex.symbols create mode 100644 tests/baselines/reference/normalizedIntersectionTooComplex.types diff --git a/tests/baselines/reference/normalizedIntersectionTooComplex.errors.txt b/tests/baselines/reference/normalizedIntersectionTooComplex.errors.txt new file mode 100644 index 0000000000000..4e214eff50715 --- /dev/null +++ b/tests/baselines/reference/normalizedIntersectionTooComplex.errors.txt @@ -0,0 +1,46 @@ +tests/cases/compiler/normalizedIntersectionTooComplex.ts(36,14): error TS2590: Expression produces a union type that is too complex to represent. +tests/cases/compiler/normalizedIntersectionTooComplex.ts(36,40): error TS7006: Parameter 'x' implicitly has an 'any' type. + + +==== tests/cases/compiler/normalizedIntersectionTooComplex.ts (2 errors) ==== + // Repro from #30050 + + interface Obj { + ref: T; + } + interface Func { + (x: T): void; + } + type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; + type CtorOf = (arg: UnionToIntersection) => T; + + interface Big { + "0": { common?: string; "0"?: number, ref?: Obj | Func; } + "1": { common?: string; "1"?: number, ref?: Obj | Func; } + "2": { common?: string; "2"?: number, ref?: Obj | Func; } + "3": { common?: string; "3"?: number, ref?: Obj | Func; } + "4": { common?: string; "4"?: number, ref?: Obj | Func; } + "5": { common?: string; "5"?: number, ref?: Obj | Func; } + "6": { common?: string; "6"?: number, ref?: Obj | Func; } + "7": { common?: string; "7"?: number, ref?: Obj | Func; } + "8": { common?: string; "8"?: number, ref?: Obj | Func; } + "9": { common?: string; "9"?: number, ref?: Obj | Func; } + "10": { common?: string; "10"?: number, ref?: Obj | Func; } + "11": { common?: string; "11"?: number, ref?: Obj | Func; } + "12": { common?: string; "12"?: number, ref?: Obj | Func; } + "13": { common?: string; "13"?: number, ref?: Obj | Func; } + "14": { common?: string; "14"?: number, ref?: Obj | Func; } + "15": { common?: string; "15"?: number, ref?: Obj | Func; } + "16": { common?: string; "16"?: number, ref?: Obj | Func; } + "17": { common?: string; "17"?: number, ref?: Obj | Func; } + } + declare function getCtor(comp: T): CtorOf + + declare var all: keyof Big; + const ctor = getCtor(all); + const comp = ctor({ common: "ok", ref: x => console.log(x) }); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2590: Expression produces a union type that is too complex to represent. + ~ +!!! error TS7006: Parameter 'x' implicitly has an 'any' type. + \ No newline at end of file diff --git a/tests/baselines/reference/normalizedIntersectionTooComplex.js b/tests/baselines/reference/normalizedIntersectionTooComplex.js new file mode 100644 index 0000000000000..d55189f7a1cb1 --- /dev/null +++ b/tests/baselines/reference/normalizedIntersectionTooComplex.js @@ -0,0 +1,44 @@ +//// [normalizedIntersectionTooComplex.ts] +// Repro from #30050 + +interface Obj { + ref: T; +} +interface Func { + (x: T): void; +} +type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; +type CtorOf = (arg: UnionToIntersection) => T; + +interface Big { + "0": { common?: string; "0"?: number, ref?: Obj | Func; } + "1": { common?: string; "1"?: number, ref?: Obj | Func; } + "2": { common?: string; "2"?: number, ref?: Obj | Func; } + "3": { common?: string; "3"?: number, ref?: Obj | Func; } + "4": { common?: string; "4"?: number, ref?: Obj | Func; } + "5": { common?: string; "5"?: number, ref?: Obj | Func; } + "6": { common?: string; "6"?: number, ref?: Obj | Func; } + "7": { common?: string; "7"?: number, ref?: Obj | Func; } + "8": { common?: string; "8"?: number, ref?: Obj | Func; } + "9": { common?: string; "9"?: number, ref?: Obj | Func; } + "10": { common?: string; "10"?: number, ref?: Obj | Func; } + "11": { common?: string; "11"?: number, ref?: Obj | Func; } + "12": { common?: string; "12"?: number, ref?: Obj | Func; } + "13": { common?: string; "13"?: number, ref?: Obj | Func; } + "14": { common?: string; "14"?: number, ref?: Obj | Func; } + "15": { common?: string; "15"?: number, ref?: Obj | Func; } + "16": { common?: string; "16"?: number, ref?: Obj | Func; } + "17": { common?: string; "17"?: number, ref?: Obj | Func; } +} +declare function getCtor(comp: T): CtorOf + +declare var all: keyof Big; +const ctor = getCtor(all); +const comp = ctor({ common: "ok", ref: x => console.log(x) }); + + +//// [normalizedIntersectionTooComplex.js] +"use strict"; +// Repro from #30050 +var ctor = getCtor(all); +var comp = ctor({ common: "ok", ref: function (x) { return console.log(x); } }); diff --git a/tests/baselines/reference/normalizedIntersectionTooComplex.symbols b/tests/baselines/reference/normalizedIntersectionTooComplex.symbols new file mode 100644 index 0000000000000..0854ef907df01 --- /dev/null +++ b/tests/baselines/reference/normalizedIntersectionTooComplex.symbols @@ -0,0 +1,250 @@ +=== tests/cases/compiler/normalizedIntersectionTooComplex.ts === +// Repro from #30050 + +interface Obj { +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>T : Symbol(T, Decl(normalizedIntersectionTooComplex.ts, 2, 14)) + + ref: T; +>ref : Symbol(Obj.ref, Decl(normalizedIntersectionTooComplex.ts, 2, 18)) +>T : Symbol(T, Decl(normalizedIntersectionTooComplex.ts, 2, 14)) +} +interface Func { +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>T : Symbol(T, Decl(normalizedIntersectionTooComplex.ts, 5, 15)) + + (x: T): void; +>x : Symbol(x, Decl(normalizedIntersectionTooComplex.ts, 6, 2)) +>T : Symbol(T, Decl(normalizedIntersectionTooComplex.ts, 5, 15)) +} +type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; +>UnionToIntersection : Symbol(UnionToIntersection, Decl(normalizedIntersectionTooComplex.ts, 7, 1)) +>U : Symbol(U, Decl(normalizedIntersectionTooComplex.ts, 8, 25)) +>U : Symbol(U, Decl(normalizedIntersectionTooComplex.ts, 8, 25)) +>k : Symbol(k, Decl(normalizedIntersectionTooComplex.ts, 8, 48)) +>U : Symbol(U, Decl(normalizedIntersectionTooComplex.ts, 8, 25)) +>k : Symbol(k, Decl(normalizedIntersectionTooComplex.ts, 8, 81)) +>I : Symbol(I, Decl(normalizedIntersectionTooComplex.ts, 8, 89)) +>I : Symbol(I, Decl(normalizedIntersectionTooComplex.ts, 8, 89)) + +type CtorOf = (arg: UnionToIntersection) => T; +>CtorOf : Symbol(CtorOf, Decl(normalizedIntersectionTooComplex.ts, 8, 114)) +>T : Symbol(T, Decl(normalizedIntersectionTooComplex.ts, 9, 12)) +>arg : Symbol(arg, Decl(normalizedIntersectionTooComplex.ts, 9, 18)) +>UnionToIntersection : Symbol(UnionToIntersection, Decl(normalizedIntersectionTooComplex.ts, 7, 1)) +>T : Symbol(T, Decl(normalizedIntersectionTooComplex.ts, 9, 12)) +>T : Symbol(T, Decl(normalizedIntersectionTooComplex.ts, 9, 12)) + +interface Big { +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "0": { common?: string; "0"?: number, ref?: Obj | Func; } +>"0" : Symbol(Big["0"], Decl(normalizedIntersectionTooComplex.ts, 11, 15)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 12, 10)) +>"0" : Symbol("0", Decl(normalizedIntersectionTooComplex.ts, 12, 27)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 12, 41)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "1": { common?: string; "1"?: number, ref?: Obj | Func; } +>"1" : Symbol(Big["1"], Decl(normalizedIntersectionTooComplex.ts, 12, 81)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 13, 10)) +>"1" : Symbol("1", Decl(normalizedIntersectionTooComplex.ts, 13, 27)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 13, 41)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "2": { common?: string; "2"?: number, ref?: Obj | Func; } +>"2" : Symbol(Big["2"], Decl(normalizedIntersectionTooComplex.ts, 13, 81)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 14, 10)) +>"2" : Symbol("2", Decl(normalizedIntersectionTooComplex.ts, 14, 27)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 14, 41)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "3": { common?: string; "3"?: number, ref?: Obj | Func; } +>"3" : Symbol(Big["3"], Decl(normalizedIntersectionTooComplex.ts, 14, 81)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 15, 10)) +>"3" : Symbol("3", Decl(normalizedIntersectionTooComplex.ts, 15, 27)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 15, 41)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "4": { common?: string; "4"?: number, ref?: Obj | Func; } +>"4" : Symbol(Big["4"], Decl(normalizedIntersectionTooComplex.ts, 15, 81)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 16, 10)) +>"4" : Symbol("4", Decl(normalizedIntersectionTooComplex.ts, 16, 27)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 16, 41)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "5": { common?: string; "5"?: number, ref?: Obj | Func; } +>"5" : Symbol(Big["5"], Decl(normalizedIntersectionTooComplex.ts, 16, 81)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 17, 10)) +>"5" : Symbol("5", Decl(normalizedIntersectionTooComplex.ts, 17, 27)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 17, 41)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "6": { common?: string; "6"?: number, ref?: Obj | Func; } +>"6" : Symbol(Big["6"], Decl(normalizedIntersectionTooComplex.ts, 17, 81)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 18, 10)) +>"6" : Symbol("6", Decl(normalizedIntersectionTooComplex.ts, 18, 27)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 18, 41)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "7": { common?: string; "7"?: number, ref?: Obj | Func; } +>"7" : Symbol(Big["7"], Decl(normalizedIntersectionTooComplex.ts, 18, 81)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 19, 10)) +>"7" : Symbol("7", Decl(normalizedIntersectionTooComplex.ts, 19, 27)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 19, 41)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "8": { common?: string; "8"?: number, ref?: Obj | Func; } +>"8" : Symbol(Big["8"], Decl(normalizedIntersectionTooComplex.ts, 19, 81)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 20, 10)) +>"8" : Symbol("8", Decl(normalizedIntersectionTooComplex.ts, 20, 27)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 20, 41)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "9": { common?: string; "9"?: number, ref?: Obj | Func; } +>"9" : Symbol(Big["9"], Decl(normalizedIntersectionTooComplex.ts, 20, 81)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 21, 10)) +>"9" : Symbol("9", Decl(normalizedIntersectionTooComplex.ts, 21, 27)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 21, 41)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "10": { common?: string; "10"?: number, ref?: Obj | Func; } +>"10" : Symbol(Big["10"], Decl(normalizedIntersectionTooComplex.ts, 21, 81)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 22, 11)) +>"10" : Symbol("10", Decl(normalizedIntersectionTooComplex.ts, 22, 28)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 22, 43)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "11": { common?: string; "11"?: number, ref?: Obj | Func; } +>"11" : Symbol(Big["11"], Decl(normalizedIntersectionTooComplex.ts, 22, 85)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 23, 11)) +>"11" : Symbol("11", Decl(normalizedIntersectionTooComplex.ts, 23, 28)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 23, 43)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "12": { common?: string; "12"?: number, ref?: Obj | Func; } +>"12" : Symbol(Big["12"], Decl(normalizedIntersectionTooComplex.ts, 23, 85)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 24, 11)) +>"12" : Symbol("12", Decl(normalizedIntersectionTooComplex.ts, 24, 28)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 24, 43)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "13": { common?: string; "13"?: number, ref?: Obj | Func; } +>"13" : Symbol(Big["13"], Decl(normalizedIntersectionTooComplex.ts, 24, 85)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 25, 11)) +>"13" : Symbol("13", Decl(normalizedIntersectionTooComplex.ts, 25, 28)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 25, 43)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "14": { common?: string; "14"?: number, ref?: Obj | Func; } +>"14" : Symbol(Big["14"], Decl(normalizedIntersectionTooComplex.ts, 25, 85)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 26, 11)) +>"14" : Symbol("14", Decl(normalizedIntersectionTooComplex.ts, 26, 28)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 26, 43)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "15": { common?: string; "15"?: number, ref?: Obj | Func; } +>"15" : Symbol(Big["15"], Decl(normalizedIntersectionTooComplex.ts, 26, 85)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 27, 11)) +>"15" : Symbol("15", Decl(normalizedIntersectionTooComplex.ts, 27, 28)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 27, 43)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "16": { common?: string; "16"?: number, ref?: Obj | Func; } +>"16" : Symbol(Big["16"], Decl(normalizedIntersectionTooComplex.ts, 27, 85)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 28, 11)) +>"16" : Symbol("16", Decl(normalizedIntersectionTooComplex.ts, 28, 28)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 28, 43)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + + "17": { common?: string; "17"?: number, ref?: Obj | Func; } +>"17" : Symbol(Big["17"], Decl(normalizedIntersectionTooComplex.ts, 28, 85)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 29, 11)) +>"17" : Symbol("17", Decl(normalizedIntersectionTooComplex.ts, 29, 28)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 29, 43)) +>Obj : Symbol(Obj, Decl(normalizedIntersectionTooComplex.ts, 0, 0)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>Func : Symbol(Func, Decl(normalizedIntersectionTooComplex.ts, 4, 1)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +} +declare function getCtor(comp: T): CtorOf +>getCtor : Symbol(getCtor, Decl(normalizedIntersectionTooComplex.ts, 30, 1)) +>T : Symbol(T, Decl(normalizedIntersectionTooComplex.ts, 31, 25)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>comp : Symbol(comp, Decl(normalizedIntersectionTooComplex.ts, 31, 46)) +>T : Symbol(T, Decl(normalizedIntersectionTooComplex.ts, 31, 25)) +>CtorOf : Symbol(CtorOf, Decl(normalizedIntersectionTooComplex.ts, 8, 114)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) +>T : Symbol(T, Decl(normalizedIntersectionTooComplex.ts, 31, 25)) + +declare var all: keyof Big; +>all : Symbol(all, Decl(normalizedIntersectionTooComplex.ts, 33, 11)) +>Big : Symbol(Big, Decl(normalizedIntersectionTooComplex.ts, 9, 52)) + +const ctor = getCtor(all); +>ctor : Symbol(ctor, Decl(normalizedIntersectionTooComplex.ts, 34, 5)) +>getCtor : Symbol(getCtor, Decl(normalizedIntersectionTooComplex.ts, 30, 1)) +>all : Symbol(all, Decl(normalizedIntersectionTooComplex.ts, 33, 11)) + +const comp = ctor({ common: "ok", ref: x => console.log(x) }); +>comp : Symbol(comp, Decl(normalizedIntersectionTooComplex.ts, 35, 5)) +>ctor : Symbol(ctor, Decl(normalizedIntersectionTooComplex.ts, 34, 5)) +>common : Symbol(common, Decl(normalizedIntersectionTooComplex.ts, 35, 19)) +>ref : Symbol(ref, Decl(normalizedIntersectionTooComplex.ts, 35, 33)) +>x : Symbol(x, Decl(normalizedIntersectionTooComplex.ts, 35, 38)) +>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>console : Symbol(console, Decl(lib.dom.d.ts, --, --)) +>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --)) +>x : Symbol(x, Decl(normalizedIntersectionTooComplex.ts, 35, 38)) + diff --git a/tests/baselines/reference/normalizedIntersectionTooComplex.types b/tests/baselines/reference/normalizedIntersectionTooComplex.types new file mode 100644 index 0000000000000..6750b0b0c73c6 --- /dev/null +++ b/tests/baselines/reference/normalizedIntersectionTooComplex.types @@ -0,0 +1,158 @@ +=== tests/cases/compiler/normalizedIntersectionTooComplex.ts === +// Repro from #30050 + +interface Obj { + ref: T; +>ref : T +} +interface Func { + (x: T): void; +>x : T +} +type UnionToIntersection = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; +>UnionToIntersection : UnionToIntersection +>k : U +>k : I + +type CtorOf = (arg: UnionToIntersection) => T; +>CtorOf : CtorOf +>arg : UnionToIntersection + +interface Big { + "0": { common?: string; "0"?: number, ref?: Obj | Func; } +>"0" : { common?: string | undefined; "0"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"0" : number | undefined +>ref : Obj<{ common?: string | undefined; "0"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "0"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "1": { common?: string; "1"?: number, ref?: Obj | Func; } +>"1" : { common?: string | undefined; "1"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"1" : number | undefined +>ref : Obj<{ common?: string | undefined; "1"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "1"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "2": { common?: string; "2"?: number, ref?: Obj | Func; } +>"2" : { common?: string | undefined; "2"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"2" : number | undefined +>ref : Obj<{ common?: string | undefined; "2"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "2"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "3": { common?: string; "3"?: number, ref?: Obj | Func; } +>"3" : { common?: string | undefined; "3"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"3" : number | undefined +>ref : Obj<{ common?: string | undefined; "3"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "3"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "4": { common?: string; "4"?: number, ref?: Obj | Func; } +>"4" : { common?: string | undefined; "4"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"4" : number | undefined +>ref : Obj<{ common?: string | undefined; "4"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "4"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "5": { common?: string; "5"?: number, ref?: Obj | Func; } +>"5" : { common?: string | undefined; "5"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"5" : number | undefined +>ref : Obj<{ common?: string | undefined; "5"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "5"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "6": { common?: string; "6"?: number, ref?: Obj | Func; } +>"6" : { common?: string | undefined; "6"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"6" : number | undefined +>ref : Obj<{ common?: string | undefined; "6"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "6"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "7": { common?: string; "7"?: number, ref?: Obj | Func; } +>"7" : { common?: string | undefined; "7"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"7" : number | undefined +>ref : Obj<{ common?: string | undefined; "7"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "7"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "8": { common?: string; "8"?: number, ref?: Obj | Func; } +>"8" : { common?: string | undefined; "8"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"8" : number | undefined +>ref : Obj<{ common?: string | undefined; "8"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "8"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "9": { common?: string; "9"?: number, ref?: Obj | Func; } +>"9" : { common?: string | undefined; "9"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"9" : number | undefined +>ref : Obj<{ common?: string | undefined; "9"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "9"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "10": { common?: string; "10"?: number, ref?: Obj | Func; } +>"10" : { common?: string | undefined; "10"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"10" : number | undefined +>ref : Obj<{ common?: string | undefined; "10"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "10"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "11": { common?: string; "11"?: number, ref?: Obj | Func; } +>"11" : { common?: string | undefined; "11"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"11" : number | undefined +>ref : Obj<{ common?: string | undefined; "11"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "11"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "12": { common?: string; "12"?: number, ref?: Obj | Func; } +>"12" : { common?: string | undefined; "12"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"12" : number | undefined +>ref : Obj<{ common?: string | undefined; "12"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "12"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "13": { common?: string; "13"?: number, ref?: Obj | Func; } +>"13" : { common?: string | undefined; "13"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"13" : number | undefined +>ref : Obj<{ common?: string | undefined; "13"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "13"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "14": { common?: string; "14"?: number, ref?: Obj | Func; } +>"14" : { common?: string | undefined; "14"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"14" : number | undefined +>ref : Obj<{ common?: string | undefined; "14"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "14"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "15": { common?: string; "15"?: number, ref?: Obj | Func; } +>"15" : { common?: string | undefined; "15"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"15" : number | undefined +>ref : Obj<{ common?: string | undefined; "15"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "15"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "16": { common?: string; "16"?: number, ref?: Obj | Func; } +>"16" : { common?: string | undefined; "16"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"16" : number | undefined +>ref : Obj<{ common?: string | undefined; "16"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "16"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined + + "17": { common?: string; "17"?: number, ref?: Obj | Func; } +>"17" : { common?: string | undefined; "17"?: number | undefined; ref?: Obj | Func | undefined; } +>common : string | undefined +>"17" : number | undefined +>ref : Obj<{ common?: string | undefined; "17"?: number | undefined; ref?: Obj | Func | undefined; }> | Func<{ common?: string | undefined; "17"?: number | undefined; ref?: Obj | Func | undefined; }> | undefined +} +declare function getCtor(comp: T): CtorOf +>getCtor : (comp: T) => CtorOf +>comp : T + +declare var all: keyof Big; +>all : "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12" | "13" | "14" | "15" | "16" | "17" + +const ctor = getCtor(all); +>ctor : CtorOf<{ common?: string | undefined; "0"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "1"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "2"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "3"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "4"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "5"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "6"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "7"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "8"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "9"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "10"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "11"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "12"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "13"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "14"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "15"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "16"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "17"?: number | undefined; ref?: Obj | Func | undefined; }> +>getCtor(all) : CtorOf<{ common?: string | undefined; "0"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "1"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "2"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "3"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "4"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "5"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "6"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "7"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "8"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "9"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "10"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "11"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "12"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "13"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "14"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "15"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "16"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "17"?: number | undefined; ref?: Obj | Func | undefined; }> +>getCtor : (comp: T) => CtorOf +>all : "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "10" | "11" | "12" | "13" | "14" | "15" | "16" | "17" + +const comp = ctor({ common: "ok", ref: x => console.log(x) }); +>comp : { common?: string | undefined; "0"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "1"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "2"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "3"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "4"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "5"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "6"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "7"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "8"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "9"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "10"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "11"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "12"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "13"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "14"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "15"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "16"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "17"?: number | undefined; ref?: Obj | Func | undefined; } +>ctor({ common: "ok", ref: x => console.log(x) }) : { common?: string | undefined; "0"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "1"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "2"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "3"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "4"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "5"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "6"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "7"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "8"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "9"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "10"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "11"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "12"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "13"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "14"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "15"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "16"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "17"?: number | undefined; ref?: Obj | Func | undefined; } +>ctor : CtorOf<{ common?: string | undefined; "0"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "1"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "2"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "3"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "4"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "5"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "6"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "7"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "8"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "9"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "10"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "11"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "12"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "13"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "14"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "15"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "16"?: number | undefined; ref?: Obj | Func | undefined; } | { common?: string | undefined; "17"?: number | undefined; ref?: Obj | Func | undefined; }> +>{ common: "ok", ref: x => console.log(x) } : { common: string; ref: (x: any) => void; } +>common : string +>"ok" : "ok" +>ref : (x: any) => void +>x => console.log(x) : (x: any) => void +>x : any +>console.log(x) : void +>console.log : (message?: any, ...optionalParams: any[]) => void +>console : Console +>log : (message?: any, ...optionalParams: any[]) => void +>x : any + From bb4080c175d0f554070b963bee05a0696bc958a2 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 23 May 2019 17:17:24 -0700 Subject: [PATCH 40/43] Collect _all_ symlinks a file may have witnessed when attempting to generate specifiers (#31571) --- src/compiler/moduleSpecifiers.ts | 6 +-- ...arationEmitForGlobalishSpecifierSymlink.js | 45 +++++++++++++++++++ ...onEmitForGlobalishSpecifierSymlink.symbols | 43 ++++++++++++++++++ ...tionEmitForGlobalishSpecifierSymlink.types | 41 +++++++++++++++++ ...rationEmitForGlobalishSpecifierSymlink2.js | 33 ++++++++++++++ ...nEmitForGlobalishSpecifierSymlink2.symbols | 30 +++++++++++++ ...ionEmitForGlobalishSpecifierSymlink2.types | 29 ++++++++++++ ...arationEmitForGlobalishSpecifierSymlink.ts | 35 +++++++++++++++ ...rationEmitForGlobalishSpecifierSymlink2.ts | 25 +++++++++++ 9 files changed, 284 insertions(+), 3 deletions(-) create mode 100644 tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink.js create mode 100644 tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink.symbols create mode 100644 tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink.types create mode 100644 tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink2.js create mode 100644 tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink2.symbols create mode 100644 tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink2.types create mode 100644 tests/cases/compiler/declarationEmitForGlobalishSpecifierSymlink.ts create mode 100644 tests/cases/compiler/declarationEmitForGlobalishSpecifierSymlink2.ts diff --git a/src/compiler/moduleSpecifiers.ts b/src/compiler/moduleSpecifiers.ts index 59bb74a22c172..bc448698c699e 100644 --- a/src/compiler/moduleSpecifiers.ts +++ b/src/compiler/moduleSpecifiers.ts @@ -175,9 +175,9 @@ namespace ts.moduleSpecifiers { function discoverProbableSymlinks(files: ReadonlyArray, getCanonicalFileName: GetCanonicalFileName, cwd: string): ReadonlyMap { const result = createMap(); - const symlinks = mapDefined(files, sf => - sf.resolvedModules && firstDefinedIterator(sf.resolvedModules.values(), res => - res && res.originalPath && res.resolvedFileName !== res.originalPath ? [res.resolvedFileName, res.originalPath] : undefined)); + const symlinks = flatten(mapDefined(files, sf => + sf.resolvedModules && compact(arrayFrom(mapIterator(sf.resolvedModules.values(), res => + res && res.originalPath && res.resolvedFileName !== res.originalPath ? [res.resolvedFileName, res.originalPath] as const : undefined))))); for (const [resolvedPath, originalPath] of symlinks) { const [commonResolved, commonOriginal] = guessDirectorySymlink(resolvedPath, originalPath, cwd, getCanonicalFileName); result.set(commonOriginal, commonResolved); diff --git a/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink.js b/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink.js new file mode 100644 index 0000000000000..00efdd49280a3 --- /dev/null +++ b/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink.js @@ -0,0 +1,45 @@ +//// [tests/cases/compiler/declarationEmitForGlobalishSpecifierSymlink.ts] //// + +//// [impl.d.ts] +export function getA(): A; +export enum A { + Val +} +//// [index.d.ts] +export * from "./src/impl"; +//// [package.json] +{ + "name": "typescript-fsa", + "version": "1.0.0" +} +//// [impl.d.ts] +export function getA(): A; +export enum A { + Val +} +//// [index.d.ts] +export * from "./src/impl"; +//// [package.json] +{ + "name": "typescript-fsa", + "version": "1.0.0" +} +//// [index.ts] +import * as _whatever from "p2"; +import { getA } from "typescript-fsa"; + +export const a = getA(); +//// [index.d.ts] +export const a: import("typescript-fsa").A; + + + +//// [index.js] +"use strict"; +exports.__esModule = true; +var typescript_fsa_1 = require("typescript-fsa"); +exports.a = typescript_fsa_1.getA(); + + +//// [index.d.ts] +export declare const a: import("typescript-fsa").A; diff --git a/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink.symbols b/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink.symbols new file mode 100644 index 0000000000000..fa0a8593339ec --- /dev/null +++ b/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink.symbols @@ -0,0 +1,43 @@ +=== /p1/node_modules/typescript-fsa/src/impl.d.ts === +export function getA(): A; +>getA : Symbol(getA, Decl(impl.d.ts, 0, 0)) +>A : Symbol(A, Decl(impl.d.ts, 0, 26)) + +export enum A { +>A : Symbol(A, Decl(impl.d.ts, 0, 26)) + + Val +>Val : Symbol(A.Val, Decl(impl.d.ts, 1, 15)) +} +=== /p1/node_modules/typescript-fsa/index.d.ts === +export * from "./src/impl"; +No type information for this code.=== /p2/node_modules/typescript-fsa/src/impl.d.ts === +export function getA(): A; +>getA : Symbol(getA, Decl(impl.d.ts, 0, 0)) +>A : Symbol(A, Decl(impl.d.ts, 0, 26)) + +export enum A { +>A : Symbol(A, Decl(impl.d.ts, 0, 26)) + + Val +>Val : Symbol(A.Val, Decl(impl.d.ts, 1, 15)) +} +=== /p2/node_modules/typescript-fsa/index.d.ts === +export * from "./src/impl"; +No type information for this code.=== /p1/index.ts === +import * as _whatever from "p2"; +>_whatever : Symbol(_whatever, Decl(index.ts, 0, 6)) + +import { getA } from "typescript-fsa"; +>getA : Symbol(getA, Decl(index.ts, 1, 8)) + +export const a = getA(); +>a : Symbol(a, Decl(index.ts, 3, 12)) +>getA : Symbol(getA, Decl(index.ts, 1, 8)) + +=== /p2/index.d.ts === +export const a: import("typescript-fsa").A; +>a : Symbol(a, Decl(index.d.ts, 0, 12)) +>A : Symbol(A, Decl(impl.d.ts, 0, 26)) + + diff --git a/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink.types b/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink.types new file mode 100644 index 0000000000000..3f62193fd83cb --- /dev/null +++ b/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink.types @@ -0,0 +1,41 @@ +=== /p1/node_modules/typescript-fsa/src/impl.d.ts === +export function getA(): A; +>getA : () => A + +export enum A { +>A : A + + Val +>Val : A +} +=== /p1/node_modules/typescript-fsa/index.d.ts === +export * from "./src/impl"; +No type information for this code.=== /p2/node_modules/typescript-fsa/src/impl.d.ts === +export function getA(): A; +>getA : () => A + +export enum A { +>A : A + + Val +>Val : A +} +=== /p2/node_modules/typescript-fsa/index.d.ts === +export * from "./src/impl"; +No type information for this code.=== /p1/index.ts === +import * as _whatever from "p2"; +>_whatever : typeof _whatever + +import { getA } from "typescript-fsa"; +>getA : () => import("/p1/node_modules/typescript-fsa/index").A + +export const a = getA(); +>a : import("/p1/node_modules/typescript-fsa/index").A +>getA() : import("/p1/node_modules/typescript-fsa/index").A +>getA : () => import("/p1/node_modules/typescript-fsa/index").A + +=== /p2/index.d.ts === +export const a: import("typescript-fsa").A; +>a : import("/p2/node_modules/typescript-fsa/index").A + + diff --git a/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink2.js b/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink2.js new file mode 100644 index 0000000000000..22889aba46193 --- /dev/null +++ b/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink2.js @@ -0,0 +1,33 @@ +//// [tests/cases/compiler/declarationEmitForGlobalishSpecifierSymlink2.ts] //// + +//// [impl.d.ts] +export function getA(): A; +export enum A { + Val +} +//// [index.d.ts] +export * from "./src/impl"; +//// [package.json] +{ + "name": "typescript-fsa", + "version": "1.0.0" +} +//// [index.ts] +import * as _whatever from "p2"; +import { getA } from "typescript-fsa"; + +export const a = getA(); +//// [index.d.ts] +export const a: import("typescript-fsa").A; + + + +//// [index.js] +"use strict"; +exports.__esModule = true; +var typescript_fsa_1 = require("typescript-fsa"); +exports.a = typescript_fsa_1.getA(); + + +//// [index.d.ts] +export declare const a: import("typescript-fsa").A; diff --git a/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink2.symbols b/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink2.symbols new file mode 100644 index 0000000000000..e183f07d5589d --- /dev/null +++ b/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink2.symbols @@ -0,0 +1,30 @@ +=== /cache/typescript-fsa/src/impl.d.ts === +export function getA(): A; +>getA : Symbol(getA, Decl(impl.d.ts, 0, 0)) +>A : Symbol(A, Decl(impl.d.ts, 0, 26)) + +export enum A { +>A : Symbol(A, Decl(impl.d.ts, 0, 26)) + + Val +>Val : Symbol(A.Val, Decl(impl.d.ts, 1, 15)) +} +=== /cache/typescript-fsa/index.d.ts === +export * from "./src/impl"; +No type information for this code.=== /p1/index.ts === +import * as _whatever from "p2"; +>_whatever : Symbol(_whatever, Decl(index.ts, 0, 6)) + +import { getA } from "typescript-fsa"; +>getA : Symbol(getA, Decl(index.ts, 1, 8)) + +export const a = getA(); +>a : Symbol(a, Decl(index.ts, 3, 12)) +>getA : Symbol(getA, Decl(index.ts, 1, 8)) + +=== /p2/index.d.ts === +export const a: import("typescript-fsa").A; +>a : Symbol(a, Decl(index.d.ts, 0, 12)) +>A : Symbol(A, Decl(impl.d.ts, 0, 26)) + + diff --git a/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink2.types b/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink2.types new file mode 100644 index 0000000000000..7c214ced6b63e --- /dev/null +++ b/tests/baselines/reference/declarationEmitForGlobalishSpecifierSymlink2.types @@ -0,0 +1,29 @@ +=== /cache/typescript-fsa/src/impl.d.ts === +export function getA(): A; +>getA : () => A + +export enum A { +>A : A + + Val +>Val : A +} +=== /cache/typescript-fsa/index.d.ts === +export * from "./src/impl"; +No type information for this code.=== /p1/index.ts === +import * as _whatever from "p2"; +>_whatever : typeof _whatever + +import { getA } from "typescript-fsa"; +>getA : () => import("/cache/typescript-fsa/index").A + +export const a = getA(); +>a : import("/cache/typescript-fsa/index").A +>getA() : import("/cache/typescript-fsa/index").A +>getA : () => import("/cache/typescript-fsa/index").A + +=== /p2/index.d.ts === +export const a: import("typescript-fsa").A; +>a : import("/cache/typescript-fsa/index").A + + diff --git a/tests/cases/compiler/declarationEmitForGlobalishSpecifierSymlink.ts b/tests/cases/compiler/declarationEmitForGlobalishSpecifierSymlink.ts new file mode 100644 index 0000000000000..b42d679b521e8 --- /dev/null +++ b/tests/cases/compiler/declarationEmitForGlobalishSpecifierSymlink.ts @@ -0,0 +1,35 @@ +// @useCaseSensitiveFilenames: true +// @declaration: true +// @filename: /p1/node_modules/typescript-fsa/src/impl.d.ts +export function getA(): A; +export enum A { + Val +} +// @filename: /p1/node_modules/typescript-fsa/index.d.ts +export * from "./src/impl"; +// @filename: /p1/node_modules/typescript-fsa/package.json +{ + "name": "typescript-fsa", + "version": "1.0.0" +} +// @filename: /p2/node_modules/typescript-fsa/src/impl.d.ts +export function getA(): A; +export enum A { + Val +} +// @filename: /p2/node_modules/typescript-fsa/index.d.ts +export * from "./src/impl"; +// @filename: /p2/node_modules/typescript-fsa/package.json +{ + "name": "typescript-fsa", + "version": "1.0.0" +} +// @filename: /p1/index.ts +import * as _whatever from "p2"; +import { getA } from "typescript-fsa"; + +export const a = getA(); +// @filename: /p2/index.d.ts +export const a: import("typescript-fsa").A; + +// @link: /p2 -> /p1/node_modules/p2 diff --git a/tests/cases/compiler/declarationEmitForGlobalishSpecifierSymlink2.ts b/tests/cases/compiler/declarationEmitForGlobalishSpecifierSymlink2.ts new file mode 100644 index 0000000000000..5b46de996224c --- /dev/null +++ b/tests/cases/compiler/declarationEmitForGlobalishSpecifierSymlink2.ts @@ -0,0 +1,25 @@ +// @useCaseSensitiveFilenames: true +// @declaration: true +// @filename: /cache/typescript-fsa/src/impl.d.ts +export function getA(): A; +export enum A { + Val +} +// @filename: /cache/typescript-fsa/index.d.ts +export * from "./src/impl"; +// @filename: /cache/typescript-fsa/package.json +{ + "name": "typescript-fsa", + "version": "1.0.0" +} +// @filename: /p1/index.ts +import * as _whatever from "p2"; +import { getA } from "typescript-fsa"; + +export const a = getA(); +// @filename: /p2/index.d.ts +export const a: import("typescript-fsa").A; + +// @link: /p2 -> /p1/node_modules/p2 +// @link: /cache/typescript-fsa -> /p1/node_modules/typescript-fsa +// @link: /cache/typescript-fsa -> /p2/node_modules/typescript-fsa From dfd28d275100db73433318236a2299b002cf0ce3 Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 23 May 2019 17:19:32 -0700 Subject: [PATCH 41/43] Fix handling of empty 'types', 'typings', etc. fields in package.json (#31539) --- src/compiler/diagnosticMessages.json | 4 ++++ src/compiler/moduleNameResolver.ts | 10 +++++++- .../reference/typesVersions.emptyTypes.js | 20 ++++++++++++++++ .../typesVersions.emptyTypes.symbols | 8 +++++++ .../typesVersions.emptyTypes.trace.json | 24 +++++++++++++++++++ .../reference/typesVersions.emptyTypes.types | 9 +++++++ .../typesVersions.emptyTypes.ts | 18 ++++++++++++++ 7 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/typesVersions.emptyTypes.js create mode 100644 tests/baselines/reference/typesVersions.emptyTypes.symbols create mode 100644 tests/baselines/reference/typesVersions.emptyTypes.trace.json create mode 100644 tests/baselines/reference/typesVersions.emptyTypes.types create mode 100644 tests/cases/conformance/moduleResolution/typesVersions.emptyTypes.ts diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index e0579429defe3..5d6dc7d6df411 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -3927,6 +3927,10 @@ "category": "Message", "code": 6219 }, + "'package.json' had a falsy '{0}' field.": { + "category": "Message", + "code": 6220 + }, "Projects to reference": { "category": "Message", diff --git a/src/compiler/moduleNameResolver.ts b/src/compiler/moduleNameResolver.ts index 19402b03ee9a9..604b82cce5e29 100644 --- a/src/compiler/moduleNameResolver.ts +++ b/src/compiler/moduleNameResolver.ts @@ -141,7 +141,15 @@ namespace ts { function readPackageJsonPathField(jsonContent: PackageJson, fieldName: K, baseDirectory: string, state: ModuleResolutionState): PackageJson[K] | undefined { const fileName = readPackageJsonField(jsonContent, fieldName, "string", state); - if (fileName === undefined) return; + if (fileName === undefined) { + return; + } + if (!fileName) { + if (state.traceEnabled) { + trace(state.host, Diagnostics.package_json_had_a_falsy_0_field, fieldName); + } + return; + } const path = normalizePath(combinePaths(baseDirectory, fileName)); if (state.traceEnabled) { trace(state.host, Diagnostics.package_json_has_0_field_1_that_references_2, fieldName, fileName, path); diff --git a/tests/baselines/reference/typesVersions.emptyTypes.js b/tests/baselines/reference/typesVersions.emptyTypes.js new file mode 100644 index 0000000000000..0bcc27d7a65ac --- /dev/null +++ b/tests/baselines/reference/typesVersions.emptyTypes.js @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/moduleResolution/typesVersions.emptyTypes.ts] //// + +//// [package.json] +{ + "types": "", + "typesVersions": { + ">=3.1.0-0": { "*" : ["ts3.1/*"] } + } +} + +//// [index.d.ts] +export const a = 0; + +//// [user.ts] +import { a } from "a"; + + +//// [user.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/tests/baselines/reference/typesVersions.emptyTypes.symbols b/tests/baselines/reference/typesVersions.emptyTypes.symbols new file mode 100644 index 0000000000000..a4441e407d70e --- /dev/null +++ b/tests/baselines/reference/typesVersions.emptyTypes.symbols @@ -0,0 +1,8 @@ +=== /a/ts3.1/index.d.ts === +export const a = 0; +>a : Symbol(a, Decl(index.d.ts, 0, 12)) + +=== /b/user.ts === +import { a } from "a"; +>a : Symbol(a, Decl(user.ts, 0, 8)) + diff --git a/tests/baselines/reference/typesVersions.emptyTypes.trace.json b/tests/baselines/reference/typesVersions.emptyTypes.trace.json new file mode 100644 index 0000000000000..e7a9e7547cf97 --- /dev/null +++ b/tests/baselines/reference/typesVersions.emptyTypes.trace.json @@ -0,0 +1,24 @@ +[ + "======== Resolving module 'a' from '/b/user.ts'. ========", + "Module resolution kind is not specified, using 'NodeJs'.", + "'baseUrl' option is set to '/', using this value to resolve non-relative module name 'a'.", + "Resolving module name 'a' relative to base url '/' - '/a'.", + "Loading module as file / folder, candidate module location '/a', target file type 'TypeScript'.", + "File '/a.ts' does not exist.", + "File '/a.tsx' does not exist.", + "File '/a.d.ts' does not exist.", + "Found 'package.json' at '/a/package.json'.", + "'package.json' has a 'typesVersions' field with version-specific path mappings.", + "'package.json' does not have a 'typings' field.", + "'package.json' had a falsy 'types' field.", + "'package.json' does not have a 'main' field.", + "'package.json' has a 'typesVersions' entry '>=3.1.0-0' that matches compiler version '3.1.0-dev', looking for a pattern to match module name 'index'.", + "Module name 'index', matched pattern '*'.", + "Trying substitution 'ts3.1/*', candidate module location: 'ts3.1/index'.", + "File '/a/ts3.1/index' does not exist.", + "Loading module as file / folder, candidate module location '/a/ts3.1/index', target file type 'TypeScript'.", + "File '/a/ts3.1/index.ts' does not exist.", + "File '/a/ts3.1/index.tsx' does not exist.", + "File '/a/ts3.1/index.d.ts' exist - use it as a name resolution result.", + "======== Module name 'a' was successfully resolved to '/a/ts3.1/index.d.ts'. ========" +] \ No newline at end of file diff --git a/tests/baselines/reference/typesVersions.emptyTypes.types b/tests/baselines/reference/typesVersions.emptyTypes.types new file mode 100644 index 0000000000000..578d4695e1cef --- /dev/null +++ b/tests/baselines/reference/typesVersions.emptyTypes.types @@ -0,0 +1,9 @@ +=== /a/ts3.1/index.d.ts === +export const a = 0; +>a : 0 +>0 : 0 + +=== /b/user.ts === +import { a } from "a"; +>a : 0 + diff --git a/tests/cases/conformance/moduleResolution/typesVersions.emptyTypes.ts b/tests/cases/conformance/moduleResolution/typesVersions.emptyTypes.ts new file mode 100644 index 0000000000000..f5d0792bfc438 --- /dev/null +++ b/tests/cases/conformance/moduleResolution/typesVersions.emptyTypes.ts @@ -0,0 +1,18 @@ +// @baseUrl: / +// @traceResolution: true +// @target: esnext +// @module: commonjs + +// @filename: /a/package.json +{ + "types": "", + "typesVersions": { + ">=3.1.0-0": { "*" : ["ts3.1/*"] } + } +} + +// @filename: /a/ts3.1/index.d.ts +export const a = 0; + +// @filename: /b/user.ts +import { a } from "a"; From b460d8cd267a8fc01c949289de96d424223a666d Mon Sep 17 00:00:00 2001 From: Ron Buckton Date: Thu, 23 May 2019 17:50:44 -0700 Subject: [PATCH 42/43] Expose getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment with better name (#31564) --- src/compiler/checker.ts | 21 +++++++++++-------- src/compiler/types.ts | 1 + .../reference/api/tsserverlibrary.d.ts | 1 + tests/baselines/reference/api/typescript.d.ts | 1 + 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0d7c7b022ddd5..b1e62d69e221e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -182,6 +182,10 @@ namespace ts { node = getParseTreeNode(node); return node ? getTypeOfNode(node) : errorType; }, + getTypeOfAssignmentPattern: nodeIn => { + const node = getParseTreeNode(nodeIn, isAssignmentPattern); + return node && getTypeOfAssignmentPattern(node) || errorType; + }, getPropertySymbolOfDestructuringAssignment: locationIn => { const location = getParseTreeNode(locationIn, isIdentifier); return location ? getPropertySymbolOfDestructuringAssignment(location) : undefined; @@ -29982,7 +29986,7 @@ namespace ts { // } // [ a ] from // [a] = [ some array ...] - function getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(expr: Expression): Type { + function getTypeOfAssignmentPattern(expr: AssignmentPattern): Type | undefined { Debug.assert(expr.kind === SyntaxKind.ObjectLiteralExpression || expr.kind === SyntaxKind.ArrayLiteralExpression); // If this is from "for of" // for ( { a } of elems) { @@ -30001,17 +30005,16 @@ namespace ts { // for ({ skills: { primary, secondary } } = multiRobot, i = 0; i < 1; i++) { if (expr.parent.kind === SyntaxKind.PropertyAssignment) { const node = cast(expr.parent.parent, isObjectLiteralExpression); - const typeOfParentObjectLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(node); + const typeOfParentObjectLiteral = getTypeOfAssignmentPattern(node) || errorType; const propertyIndex = indexOfNode(node.properties, expr.parent); - return checkObjectLiteralDestructuringPropertyAssignment(node, typeOfParentObjectLiteral || errorType, propertyIndex)!; // TODO: GH#18217 + return checkObjectLiteralDestructuringPropertyAssignment(node, typeOfParentObjectLiteral, propertyIndex); } // Array literal assignment - array destructuring pattern - Debug.assert(expr.parent.kind === SyntaxKind.ArrayLiteralExpression); + const node = cast(expr.parent, isArrayLiteralExpression); // [{ property1: p1, property2 }] = elems; - const typeOfArrayLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(expr.parent); - const elementType = checkIteratedTypeOrElementType(typeOfArrayLiteral || errorType, expr.parent, /*allowStringInput*/ false, /*allowAsyncIterables*/ false) || errorType; - return checkArrayLiteralDestructuringElementAssignment(expr.parent, typeOfArrayLiteral, - (expr.parent).elements.indexOf(expr), elementType || errorType)!; // TODO: GH#18217 + const typeOfArrayLiteral = getTypeOfAssignmentPattern(node) || errorType; + const elementType = checkIteratedTypeOrElementType(typeOfArrayLiteral, expr.parent, /*allowStringInput*/ false, /*allowAsyncIterables*/ false) || errorType; + return checkArrayLiteralDestructuringElementAssignment(node, typeOfArrayLiteral, node.elements.indexOf(expr), elementType); } // Gets the property symbol corresponding to the property in destructuring assignment @@ -30022,7 +30025,7 @@ namespace ts { // [a] = [ property1, property2 ] function getPropertySymbolOfDestructuringAssignment(location: Identifier) { // Get the type of the object or array literal and then look for property of given name in the type - const typeOfObjectLiteral = getTypeOfArrayLiteralOrObjectLiteralDestructuringAssignment(location.parent.parent); + const typeOfObjectLiteral = getTypeOfAssignmentPattern(cast(location.parent.parent, isAssignmentPattern)); return typeOfObjectLiteral && getPropertyOfType(typeOfObjectLiteral, location.escapedText); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index db1a62937e662..03ca196a8608c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3154,6 +3154,7 @@ namespace ts { */ getExportSymbolOfSymbol(symbol: Symbol): Symbol; getPropertySymbolOfDestructuringAssignment(location: Identifier): Symbol | undefined; + getTypeOfAssignmentPattern(pattern: AssignmentPattern): Type; getTypeAtLocation(node: Node): Type; getTypeFromTypeNode(node: TypeNode): Type; diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 4b06bc9e8392a..d10aa28ffe40f 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -1969,6 +1969,7 @@ declare namespace ts { */ getExportSymbolOfSymbol(symbol: Symbol): Symbol; getPropertySymbolOfDestructuringAssignment(location: Identifier): Symbol | undefined; + getTypeOfAssignmentPattern(pattern: AssignmentPattern): Type; getTypeAtLocation(node: Node): Type; getTypeFromTypeNode(node: TypeNode): Type; signatureToString(signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind): string; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index f70916a882be6..58ccd42344b00 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -1969,6 +1969,7 @@ declare namespace ts { */ getExportSymbolOfSymbol(symbol: Symbol): Symbol; getPropertySymbolOfDestructuringAssignment(location: Identifier): Symbol | undefined; + getTypeOfAssignmentPattern(pattern: AssignmentPattern): Type; getTypeAtLocation(node: Node): Type; getTypeFromTypeNode(node: TypeNode): Type; signatureToString(signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags, kind?: SignatureKind): string; From 57d9ecc39f588917c3c587795dea739f740b066b Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 24 May 2019 15:04:42 -0700 Subject: [PATCH 43/43] Do not log errors when ts server plugin is not found in one folder but is eventually resolved. Fixes #30106 --- src/server/project.ts | 14 +++++++------- tests/baselines/reference/api/tsserverlibrary.d.ts | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/server/project.ts b/src/server/project.ts index c204facad5ca1..20cd5667dd9db 100644 --- a/src/server/project.ts +++ b/src/server/project.ts @@ -198,13 +198,13 @@ namespace ts.server { return hasOneOrMoreJsAndNoTsFiles(this); } - public static resolveModule(moduleName: string, initialDir: string, host: ServerHost, log: (message: string) => void): {} | undefined { + public static resolveModule(moduleName: string, initialDir: string, host: ServerHost, log: (message: string) => void, logErrors?: (message: string) => void): {} | undefined { const resolvedPath = normalizeSlashes(host.resolvePath(combinePaths(initialDir, "node_modules"))); log(`Loading ${moduleName} from ${initialDir} (resolved to ${resolvedPath})`); const result = host.require!(resolvedPath, moduleName); // TODO: GH#18217 if (result.error) { const err = result.error.stack || result.error.message || JSON.stringify(result.error); - log(`Failed to load module '${moduleName}': ${err}`); + (logErrors || log)(`Failed to load module '${moduleName}' from ${resolvedPath}: ${err}`); return undefined; } return result.module; @@ -1142,12 +1142,11 @@ namespace ts.server { protected enablePlugin(pluginConfigEntry: PluginImport, searchPaths: string[], pluginConfigOverrides: Map | undefined) { this.projectService.logger.info(`Enabling plugin ${pluginConfigEntry.name} from candidate paths: ${searchPaths.join(",")}`); - const log = (message: string) => { - this.projectService.logger.info(message); - }; - + const log = (message: string) => this.projectService.logger.info(message); + let errorLogs: string[] | undefined; + const logError = (message: string) => { (errorLogs || (errorLogs = [])).push(message); }; const resolvedModule = firstDefined(searchPaths, searchPath => - Project.resolveModule(pluginConfigEntry.name, searchPath, this.projectService.host, log)); + Project.resolveModule(pluginConfigEntry.name, searchPath, this.projectService.host, log, logError)); if (resolvedModule) { const configurationOverride = pluginConfigOverrides && pluginConfigOverrides.get(pluginConfigEntry.name); if (configurationOverride) { @@ -1160,6 +1159,7 @@ namespace ts.server { this.enableProxy(resolvedModule, pluginConfigEntry); } else { + forEach(errorLogs, log); this.projectService.logger.info(`Couldn't find ${pluginConfigEntry.name}`); } } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index d10aa28ffe40f..993a7494994be 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -8321,7 +8321,7 @@ declare namespace ts.server { private readonly cancellationToken; isNonTsProject(): boolean; isJsOnlyProject(): boolean; - static resolveModule(moduleName: string, initialDir: string, host: ServerHost, log: (message: string) => void): {} | undefined; + static resolveModule(moduleName: string, initialDir: string, host: ServerHost, log: (message: string) => void, logErrors?: (message: string) => void): {} | undefined; isKnownTypesPackageName(name: string): boolean; installPackage(options: InstallPackageOptions): Promise; private readonly typingsCache;