From 8515f7e2b56c39cbaee699125dc7363d5a819dc9 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Fri, 27 Jan 2017 08:59:33 -0800 Subject: [PATCH 01/16] Change find-all-references tests to test for groups * Also always test for isWriteAccess and isDefinition --- src/harness/fourslash.ts | 121 +++++++++++++----- src/services/findAllReferences.ts | 19 +-- src/services/services.ts | 7 +- .../fourslash/ambientShorthandFindAllRefs.ts | 15 ++- ...cellationWhenfindingAllRefsOnDefinition.ts | 18 ++- .../findAllReferencesOfConstructor.ts | 6 +- ...dAllReferencesOfConstructor_badOverload.ts | 2 +- .../findAllRefsForComputedProperties.ts | 20 ++- .../findAllRefsForComputedProperties2.ts | 18 ++- .../fourslash/findAllRefsForDefaultExport.ts | 6 +- .../findAllRefsForDefaultExport01.ts | 7 +- .../findAllRefsForDefaultExport02.ts | 17 ++- .../findAllRefsForDefaultExport03.ts | 9 +- .../findAllRefsForDefaultExport04.ts | 23 ---- .../findAllRefsForDefaultExport05.ts | 23 ---- .../findAllRefsForDefaultExport06.ts | 23 ---- .../findAllRefsForDefaultExport07.ts | 16 --- .../findAllRefsForDefaultExport08.ts | 5 +- .../findAllRefsForFunctionExpression01.ts | 4 +- .../fourslash/findAllRefsForMappedType.ts | 18 ++- .../findAllRefsForObjectLiteralProperties.ts | 10 +- .../fourslash/findAllRefsForObjectSpread.ts | 17 ++- tests/cases/fourslash/findAllRefsForRest.ts | 4 +- .../findAllRefsForStringLiteralTypes.ts | 2 +- .../findAllRefsForUMDModuleAlias1.ts | 4 +- ...findAllRefsForVariableInExtendsClause01.ts | 4 +- ...findAllRefsForVariableInExtendsClause02.ts | 4 +- ...dAllRefsForVariableInImplementsClause01.ts | 3 +- .../fourslash/findAllRefsInClassExpression.ts | 12 +- .../findAllRefsInheritedProperties1.ts | 14 +- .../findAllRefsInheritedProperties2.ts | 10 +- .../findAllRefsInheritedProperties3.ts | 46 ++++--- .../findAllRefsInheritedProperties4.ts | 17 +-- .../findAllRefsInheritedProperties5.ts | 15 +-- .../fourslash/findAllRefsInsideTemplates1.ts | 4 +- .../fourslash/findAllRefsInsideTemplates2.ts | 4 +- .../fourslash/findAllRefsInsideWithBlock.ts | 6 +- ...lRefsObjectBindingElementPropertyName01.ts | 4 +- ...lRefsObjectBindingElementPropertyName02.ts | 4 +- ...lRefsObjectBindingElementPropertyName03.ts | 12 +- ...lRefsObjectBindingElementPropertyName04.ts | 13 +- ...lRefsObjectBindingElementPropertyName05.ts | 2 +- ...lRefsObjectBindingElementPropertyName06.ts | 21 ++- ...lRefsObjectBindingElementPropertyName07.ts | 10 +- ...lRefsObjectBindingElementPropertyName09.ts | 15 --- ...lRefsObjectBindingElementPropertyName10.ts | 4 +- .../findAllRefsOfConstructor_withModifier.ts | 3 +- .../fourslash/findAllRefsOnDecorators.ts | 4 +- .../fourslash/findAllRefsOnDefinition.ts | 10 +- .../fourslash/findAllRefsOnDefinition2.ts | 8 +- .../fourslash/findAllRefsOnImportAliases.ts | 11 +- .../fourslash/findAllRefsOnImportAliases2.ts | 16 ++- .../findAllRefsOnPrivateParameterProperty1.ts | 4 +- ...indAllRefsParameterPropertyDeclaration1.ts | 9 +- ...indAllRefsParameterPropertyDeclaration2.ts | 9 +- ...indAllRefsParameterPropertyDeclaration3.ts | 9 +- tests/cases/fourslash/findAllRefsPrimitive.ts | 2 +- ...sPropertyContextuallyTypedByTypeParam01.ts | 18 ++- .../cases/fourslash/findAllRefsThisKeyword.ts | 22 ++-- .../findAllRefsWithLeadingUnderscoreNames1.ts | 10 +- .../findAllRefsWithLeadingUnderscoreNames2.ts | 10 +- .../findAllRefsWithLeadingUnderscoreNames3.ts | 10 +- .../findAllRefsWithLeadingUnderscoreNames4.ts | 10 +- .../findAllRefsWithLeadingUnderscoreNames5.ts | 4 +- .../findAllRefsWithLeadingUnderscoreNames6.ts | 4 +- .../findAllRefsWithLeadingUnderscoreNames7.ts | 4 +- .../findAllRefsWithLeadingUnderscoreNames8.ts | 4 +- .../findAllRefsWithLeadingUnderscoreNames9.ts | 4 +- ...dAllRefsWithShorthandPropertyAssignment.ts | 21 +-- ...AllRefsWithShorthandPropertyAssignment2.ts | 20 ++- .../findReferencesAcrossMultipleProjects.ts | 8 +- .../fourslash/findReferencesAfterEdit.ts | 6 +- .../fourslash/findReferencesJSXTagName.ts | 8 +- .../fourslash/findReferencesJSXTagName2.ts | 6 +- tests/cases/fourslash/fourslash.ts | 16 +-- ...tOccurrencesIsDefinitionOfArrowFunction.ts | 6 +- ...OccurrencesIsDefinitionOfBindingPattern.ts | 4 +- .../getOccurrencesIsDefinitionOfClass.ts | 9 +- ...currencesIsDefinitionOfComputedProperty.ts | 12 +- .../getOccurrencesIsDefinitionOfEnum.ts | 6 +- .../getOccurrencesIsDefinitionOfExport.ts | 8 +- .../getOccurrencesIsDefinitionOfFunction.ts | 6 +- .../getOccurrencesIsDefinitionOfInterface.ts | 6 +- ...rencesIsDefinitionOfInterfaceClassMerge.ts | 13 +- .../getOccurrencesIsDefinitionOfNamespace.ts | 6 +- ...rencesIsDefinitionOfNumberNamedProperty.ts | 10 +- .../getOccurrencesIsDefinitionOfParameter.ts | 6 +- ...rencesIsDefinitionOfStringNamedProperty.ts | 10 +- .../getOccurrencesIsDefinitionOfTypeAlias.ts | 6 +- .../getOccurrencesIsDefinitionOfVariable.ts | 28 ++-- tests/cases/fourslash/hoverOverComment.ts | 2 +- tests/cases/fourslash/localGetReferences.ts | 66 ++++++---- tests/cases/fourslash/quickInfoForRequire.ts | 5 +- ...referenceInParameterPropertyDeclaration.ts | 21 ++- tests/cases/fourslash/referenceToClass.ts | 7 +- .../cases/fourslash/referencesBloomFilters.ts | 16 ++- .../fourslash/referencesBloomFilters2.ts | 16 ++- .../fourslash/referencesBloomFilters3.ts | 4 +- .../cases/fourslash/referencesForAmbients.ts | 16 +-- .../fourslash/referencesForClassLocal.ts | 4 +- .../fourslash/referencesForClassMembers.ts | 30 ++++- ...esForClassMembersExtendingAbstractClass.ts | 30 ++++- ...cesForClassMembersExtendingGenericClass.ts | 30 ++++- .../fourslash/referencesForClassParameter.ts | 10 +- ...ontextuallyTypedObjectLiteralProperties.ts | 28 ++-- ...ncesForContextuallyTypedUnionProperties.ts | 36 +++--- ...cesForContextuallyTypedUnionProperties2.ts | 26 ++-- tests/cases/fourslash/referencesForEnums.ts | 11 +- .../fourslash/referencesForExportedValues.ts | 4 +- .../referencesForExternalModuleNames.ts | 7 +- .../referencesForFunctionOverloads.ts | 6 +- .../referencesForFunctionParameter.ts | 6 +- tests/cases/fourslash/referencesForGlobals.ts | 4 +- .../cases/fourslash/referencesForGlobals2.ts | 4 +- .../cases/fourslash/referencesForGlobals3.ts | 4 +- .../cases/fourslash/referencesForGlobals4.ts | 4 +- .../cases/fourslash/referencesForGlobals5.ts | 4 +- .../referencesForGlobalsInExternalModule.ts | 18 ++- .../referencesForIllegalAssignment.ts | 10 +- tests/cases/fourslash/referencesForImports.ts | 8 +- .../fourslash/referencesForIndexProperty.ts | 8 +- .../fourslash/referencesForIndexProperty2.ts | 2 +- .../fourslash/referencesForIndexProperty3.ts | 4 +- .../referencesForInheritedProperties.ts | 25 +++- .../referencesForInheritedProperties2.ts | 25 +++- .../referencesForInheritedProperties3.ts | 8 +- .../referencesForInheritedProperties4.ts | 15 ++- .../referencesForInheritedProperties5.ts | 22 +++- .../referencesForInheritedProperties6.ts | 21 ++- .../referencesForInheritedProperties7.ts | 44 ++++--- .../referencesForInheritedProperties8.ts | 13 +- .../referencesForInheritedProperties9.ts | 12 +- tests/cases/fourslash/referencesForLabel.ts | 4 +- tests/cases/fourslash/referencesForLabel2.ts | 3 +- tests/cases/fourslash/referencesForLabel3.ts | 3 +- tests/cases/fourslash/referencesForLabel4.ts | 2 +- tests/cases/fourslash/referencesForLabel5.ts | 4 +- tests/cases/fourslash/referencesForLabel6.ts | 6 +- .../referencesForMergedDeclarations.ts | 13 +- .../referencesForMergedDeclarations2.ts | 4 +- .../referencesForMergedDeclarations3.ts | 12 +- .../referencesForMergedDeclarations4.ts | 10 +- .../referencesForMergedDeclarations5.ts | 14 +- .../referencesForMergedDeclarations6.ts | 4 +- .../referencesForMergedDeclarations7.ts | 14 +- .../referencesForMergedDeclarations8.ts | 4 +- .../cases/fourslash/referencesForNoContext.ts | 12 +- ...eferencesForNumericLiteralPropertyNames.ts | 19 ++- .../referencesForObjectLiteralProperties.ts | 10 +- .../cases/fourslash/referencesForOverrides.ts | 93 +++++++++++--- .../referencesForPropertiesOfGenericType.ts | 14 +- tests/cases/fourslash/referencesForStatic.ts | 4 +- ...rencesForStaticsAndMembersWithSameNames.ts | 19 +-- ...referencesForStringLiteralPropertyNames.ts | 18 ++- ...eferencesForStringLiteralPropertyNames2.ts | 11 +- ...eferencesForStringLiteralPropertyNames3.ts | 12 +- ...eferencesForStringLiteralPropertyNames4.ts | 12 +- .../fourslash/referencesForUnionProperties.ts | 22 +++- tests/cases/fourslash/referencesInComment.ts | 2 +- tests/cases/fourslash/remoteGetReferences.ts | 42 ++++-- tests/cases/fourslash/renameDefaultImport.ts | 10 +- .../renameDefaultImportDifferentName.ts | 10 +- .../renameImportAndExportInDiffFiles.ts | 8 +- .../shims-pp/getReferencesAtPosition.ts | 12 +- .../shims/getReferencesAtPosition.ts | 12 +- tests/cases/fourslash/untypedModuleImport.ts | 6 +- 166 files changed, 1349 insertions(+), 776 deletions(-) delete mode 100644 tests/cases/fourslash/findAllRefsForDefaultExport04.ts delete mode 100644 tests/cases/fourslash/findAllRefsForDefaultExport05.ts delete mode 100644 tests/cases/fourslash/findAllRefsForDefaultExport06.ts delete mode 100644 tests/cases/fourslash/findAllRefsForDefaultExport07.ts delete mode 100644 tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName09.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 721647df0cd..3deddf1f2cc 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -452,7 +452,8 @@ namespace FourSlash { } private messageAtLastKnownMarker(message: string) { - return "Marker: " + this.lastKnownMarker + "\n" + message; + const locationDescription = this.lastKnownMarker ? this.lastKnownMarker : this.getLineColStringAtPosition(this.currentCaretPosition); + return `At ${locationDescription}: ${message}`; } private assertionMessageAtLastKnownMarker(msg: string) { @@ -562,7 +563,7 @@ namespace FourSlash { } public verifyGoToDefinitionIs(endMarker: string | string[]) { - this.verifyGoToXWorker(endMarker instanceof Array ? endMarker : [endMarker], () => this.getGoToDefinition()); + this.verifyGoToXWorker(toArray(endMarker), () => this.getGoToDefinition()); } public verifyGoToDefinition(arg0: any, endMarkerNames?: string | string[]) { @@ -582,7 +583,7 @@ namespace FourSlash { if (endMarkerNames) { this.verifyGoToXPlain(arg0, endMarkerNames, getDefs); } - else if (arg0 instanceof Array) { + else if (ts.isArray(arg0)) { const pairs: [string | string[], string | string[]][] = arg0; for (const [start, end] of pairs) { this.verifyGoToXPlain(start, end, getDefs); @@ -599,13 +600,8 @@ namespace FourSlash { } private verifyGoToXPlain(startMarkerNames: string | string[], endMarkerNames: string | string[], getDefs: () => ts.DefinitionInfo[] | undefined) { - if (startMarkerNames instanceof Array) { - for (const start of startMarkerNames) { - this.verifyGoToXSingle(start, endMarkerNames, getDefs); - } - } - else { - this.verifyGoToXSingle(startMarkerNames, endMarkerNames, getDefs); + for (const start of toArray(startMarkerNames)) { + this.verifyGoToXSingle(start, endMarkerNames, getDefs); } } @@ -617,7 +613,7 @@ namespace FourSlash { private verifyGoToXSingle(startMarkerName: string, endMarkerNames: string | string[], getDefs: () => ts.DefinitionInfo[] | undefined) { this.goToMarker(startMarkerName); - this.verifyGoToXWorker(endMarkerNames instanceof Array ? endMarkerNames : [endMarkerNames], getDefs); + this.verifyGoToXWorker(toArray(endMarkerNames), getDefs); } private verifyGoToXWorker(endMarkers: string[], getDefs: () => ts.DefinitionInfo[] | undefined) { @@ -899,8 +895,74 @@ namespace FourSlash { } } - public verifyRangesWithSameTextReferenceEachOther() { - this.rangesByText().forEach(ranges => this.verifyRangesReferenceEachOther(ranges)); + public verifyReferenceGroups(startRanges: Range | Range[], parts: Array<{ definition: string, ranges: Range[] }>): void { + interface ReferenceJson { definition: string; ranges: ts.ReferenceEntry[]; } + type ReferencesJson = ReferenceJson[]; + const fullExpected = parts.map(({ definition, ranges }) => ({ definition, ranges: ranges.map(rangeToReferenceEntry) })); + + for (const startRange of toArray(startRanges)) { + this.goToRangeStart(startRange); + const fullActual = this.findReferencesAtCaret().map(({ definition, references }) => ({ + definition: definition.displayParts.map(d => d.text).join(""), + ranges: references + })); + this.assertObjectsEqual(fullActual, fullExpected); + } + + function rangeToReferenceEntry(r: Range) { + let { isWriteAccess, isDefinition } = (r.marker && r.marker.data) || { isWriteAccess: false, isDefinition: false }; + isWriteAccess = isWriteAccess || false; isDefinition = isDefinition || false; + return { fileName: r.fileName, textSpan: { start: r.start, length: r.end - r.start }, isWriteAccess, isDefinition } + } + } + + public verifyNoReferences(markerNameOrRange?: string | Range) { + if (markerNameOrRange) { + if (typeof markerNameOrRange === "string") { + this.goToMarker(markerNameOrRange); + } + else { + this.goToRangeStart(markerNameOrRange); + } + } + + const refs = this.getReferencesAtCaret(); + if (refs && refs.length) { + console.log(refs); + this.raiseError("Expected getReferences to fail"); + } + } + + public verifySingleReferenceGroup(definition: string, ranges?: Range[]) { + ranges = ranges || this.getRanges(); + this.verifyReferenceGroups(ranges, [{ definition, ranges }]); + } + + private assertObjectsEqual(fullActual: T, fullExpected: T, msgPrefix = ""): void { + const recur = (actual: U, expected: U, path: string) => { + const fail = (msg: string) => { + console.log("Expected:", stringify(fullExpected)); + console.log("Actual: ", stringify(fullActual)); + this.raiseError(`${msgPrefix}At ${path}: ${msg}`); + }; + + for (const key in actual) if (ts.hasProperty(actual as any, key)) { + const ak = actual[key], ek = expected[key]; + if (typeof ak === "object" && typeof ek === "object") { + recur(ak, ek, path ? path + "." + key : key); + } + else if (ak !== ek) { + fail(`Expected '${key}' to be '${ek}', got '${ak}'`); + } + } + for (const key in expected) if (ts.hasProperty(expected as any, key)) { + if (!ts.hasProperty(actual as any, key)) { + fail(`${msgPrefix}Missing property '${key}'`); + } + } + }; + recur(fullActual, fullExpected, ""); + } public verifyDisplayPartsOfReferencedSymbol(expected: ts.SymbolDisplayPart[]) { @@ -974,7 +1036,7 @@ namespace FourSlash { public verifyQuickInfos(namesAndTexts: { [name: string]: string | [string, string] }) { for (const name in namesAndTexts) if (ts.hasProperty(namesAndTexts, name)) { const text = namesAndTexts[name]; - if (text instanceof Array) { + if (ts.isArray(text)) { assert(text.length === 2); const [expectedText, expectedDocumentation] = text; this.verifyQuickInfoAt(name, expectedText, expectedDocumentation); @@ -1411,13 +1473,6 @@ namespace FourSlash { Harness.IO.log(membersString); } - public printReferences() { - const references = this.getReferencesAtCaret(); - ts.forEach(references, entry => { - Harness.IO.log(stringify(entry)); - }); - } - public printContext() { ts.forEach(this.languageServiceAdapterHost.getFilenames(), Harness.IO.log); } @@ -3082,6 +3137,10 @@ ${code} } return ts.arrayFrom(set.keys()); } + + function toArray(x: T | T[]): T[] { + return ts.isArray(x) ? x : [x]; + } } namespace FourSlashInterface { @@ -3346,6 +3405,18 @@ namespace FourSlashInterface { this.state.verifyReferencesOf(start, references); } + public referenceGroups(startRanges: FourSlash.Range[], parts: Array<{ definition: string, ranges: FourSlash.Range[] }>) { + this.state.verifyReferenceGroups(startRanges, parts); + } + + public noReferences(markerNameOrRange?: string | FourSlash.Range) { + this.state.verifyNoReferences(markerNameOrRange); + } + + public singleReferenceGroup(definition: string, ranges?: FourSlash.Range[]) { + this.state.verifySingleReferenceGroup(definition, ranges); + } + public rangesReferenceEachOther(ranges?: FourSlash.Range[]) { this.state.verifyRangesReferenceEachOther(ranges); } @@ -3354,10 +3425,6 @@ namespace FourSlashInterface { this.state.verifyDisplayPartsOfReferencedSymbol(expected); } - public rangesWithSameTextReferenceEachOther() { - this.state.verifyRangesWithSameTextReferenceEachOther(); - } - public currentParameterHelpArgumentNameIs(name: string) { this.state.verifyCurrentParameterHelpName(name); } @@ -3660,10 +3727,6 @@ namespace FourSlashInterface { this.state.printNavigationBar(); } - public printReferences() { - this.state.printReferences(); - } - public printContext() { this.state.printContext(); } diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 28474839cf3..cd1477c4448 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -5,6 +5,10 @@ namespace ts.FindAllReferences { return getReferencedSymbolsForNode(typeChecker, cancellationToken, node, sourceFiles, findInStrings, findInComments, isForRename); } + export function convertReferences(referenceSymbols: ReferencedSymbol[]): ReferenceEntry[] { + return referenceSymbols && flatMap(referenceSymbols, r => r.references); + } + export function getReferencedSymbolsForNode(typeChecker: TypeChecker, cancellationToken: CancellationToken, node: Node, sourceFiles: SourceFile[], findInStrings?: boolean, findInComments?: boolean, isForRename?: boolean, implementations?: boolean): ReferencedSymbol[] | undefined { if (!implementations) { const special = getReferencedSymbolsSpecial(node, sourceFiles, typeChecker, cancellationToken); @@ -411,7 +415,6 @@ namespace ts.FindAllReferences { textSpan: createTextSpan(0, 1), displayParts: [{ text: name, kind: ScriptElementKind.keyword }] } - const references: ReferenceEntry[] = []; for (const sourceFile of sourceFiles) { cancellationToken.throwIfCancellationRequested(); @@ -1316,20 +1319,6 @@ namespace ts.FindAllReferences { return meaning; } - export function convertReferences(referenceSymbols: ReferencedSymbol[]): ReferenceEntry[] { - if (!referenceSymbols) { - return undefined; - } - - const referenceEntries: ReferenceEntry[] = []; - - for (const referenceSymbol of referenceSymbols) { - addRange(referenceEntries, referenceSymbol.references); - } - - return referenceEntries; - } - function isImplementation(node: Node): boolean { if (!node) { return false; diff --git a/src/services/services.ts b/src/services/services.ts index b3e3093cddb..b83995e31ed 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1415,7 +1415,6 @@ namespace ts { function findReferences(fileName: string, position: number): ReferencedSymbol[] { const referencedSymbols = findReferencedSymbols(fileName, position, /*findInStrings*/ false, /*findInComments*/ false, /*isForRename*/false); - // Only include referenced symbols that have a valid definition. return filter(referencedSymbols, rs => !!rs.definition); } @@ -2015,9 +2014,5 @@ namespace ts { throw new Error("getDefaultLibFilePath is only supported when consumed as a node module. "); } - function initializeServices() { - objectAllocator = getServicesObjectAllocator(); - } - - initializeServices(); + objectAllocator = getServicesObjectAllocator(); } diff --git a/tests/cases/fourslash/ambientShorthandFindAllRefs.ts b/tests/cases/fourslash/ambientShorthandFindAllRefs.ts index 2f0dbf914e7..06bc6e94782 100644 --- a/tests/cases/fourslash/ambientShorthandFindAllRefs.ts +++ b/tests/cases/fourslash/ambientShorthandFindAllRefs.ts @@ -4,9 +4,18 @@ ////declare module "jquery"; // @Filename: user.ts -////import {[|x|]} from "jquery"; +////import {[|{| "isWriteAccess": true, "isDefinition": true |}x|]} from "jquery"; // @Filename: user2.ts -////import {[|x|]} from "jquery"; +////import {[|{| "isWriteAccess": true, "isDefinition": true |}x|]} from "jquery"; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [ + { definition: "import x", ranges: [r0] }, + { definition: 'module "jquery"', ranges: [r1] } +]); +verify.referenceGroups(r1, [ + { definition: 'module "jquery"', ranges: [r0] }, + { definition: "import x", ranges: [r1] } +]); diff --git a/tests/cases/fourslash/cancellationWhenfindingAllRefsOnDefinition.ts b/tests/cases/fourslash/cancellationWhenfindingAllRefsOnDefinition.ts index d3d18b2dabb..8f80c871eb3 100644 --- a/tests/cases/fourslash/cancellationWhenfindingAllRefsOnDefinition.ts +++ b/tests/cases/fourslash/cancellationWhenfindingAllRefsOnDefinition.ts @@ -7,7 +7,7 @@ //// //// } //// -//// public /**/[|start|](){ +//// public /**/[|{| "isWriteAccess": true, "isDefinition": true |}start|](){ //// return this; //// } //// @@ -23,11 +23,21 @@ ////second.[|start|](); ////second.stop(); -verify.rangesReferenceEachOther(); +checkRefs(); cancellation.setCancelled(); -verifyOperationIsCancelled(() => verify.rangesReferenceEachOther()); +verifyOperationIsCancelled(checkRefs); // verify that internal state is still correct cancellation.resetCancelled(); -verify.rangesReferenceEachOther(); +checkRefs(); + +function checkRefs() { + const ranges = test.ranges(); + const [r0, r1] = ranges; + verify.referenceGroups(r0, [{ definition: "(method) Test.start(): this", ranges }]); + verify.referenceGroups(r1, [ + { definition: "(method) Second.Test.start(): Second.Test", ranges: [r0] }, + { definition: "(method) Second.Test.start(): Second.Test", ranges: [r1] } + ]); +} diff --git a/tests/cases/fourslash/findAllReferencesOfConstructor.ts b/tests/cases/fourslash/findAllReferencesOfConstructor.ts index b25508a60db..dcdc23bdc7f 100644 --- a/tests/cases/fourslash/findAllReferencesOfConstructor.ts +++ b/tests/cases/fourslash/findAllReferencesOfConstructor.ts @@ -41,6 +41,6 @@ ////class d extends a.C { constructor() { [|super|](); } const ranges = test.ranges(); -for (const ctr of ranges.slice(0, 3)) { - verify.referencesOf(ctr, ranges); -} +const [r0, r1, r2] = ranges; +verify.referenceGroups([r0, r2], [{ definition: "constructor C(n: number): C (+1 overload)", ranges }]); +verify.referenceGroups(r1, [{ definition: "constructor C(): C (+1 overload)", ranges }]); diff --git a/tests/cases/fourslash/findAllReferencesOfConstructor_badOverload.ts b/tests/cases/fourslash/findAllReferencesOfConstructor_badOverload.ts index 77479bad113..bb8b62a1462 100644 --- a/tests/cases/fourslash/findAllReferencesOfConstructor_badOverload.ts +++ b/tests/cases/fourslash/findAllReferencesOfConstructor_badOverload.ts @@ -5,4 +5,4 @@ //// [|constructor|](){} ////} -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("constructor C(n: number): C"); diff --git a/tests/cases/fourslash/findAllRefsForComputedProperties.ts b/tests/cases/fourslash/findAllRefsForComputedProperties.ts index 065d34c6fc5..72c49104ded 100644 --- a/tests/cases/fourslash/findAllRefsForComputedProperties.ts +++ b/tests/cases/fourslash/findAllRefsForComputedProperties.ts @@ -1,16 +1,26 @@ /// - ////interface I { -//// ["[|prop1|]"]: () => void; +//// ["[|{| "isDefinition": true |}prop1|]"]: () => void; ////} //// ////class C implements I { -//// ["[|prop1|]"]: any; +//// ["[|{| "isDefinition": true |}prop1|]"]: any; ////} //// ////var x: I = { -//// ["[|prop1|]"]: function () { }, +//// ["[|{| "isDefinition": true |}prop1|]"]: function () { }, ////} -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2] = ranges; +verify.referenceGroups(r0, [{ definition: '(property) I[["prop1"]]: () => void', ranges }]); +verify.referenceGroups(r1, [ + { definition: '(property) I[["prop1"]]: () => void', ranges: [r0, r2] }, + { definition: '(property) C[["prop1"]]: any', ranges: [r1] } +]); +verify.referenceGroups(r2, [ + { definition: '(property) I[["prop1"]]: () => void', ranges: [r0, r1] }, + { definition: '(property) ["prop1"]: () => void', ranges: [r2] } +]); + diff --git a/tests/cases/fourslash/findAllRefsForComputedProperties2.ts b/tests/cases/fourslash/findAllRefsForComputedProperties2.ts index 37a9bd8470e..4a7a17047ec 100644 --- a/tests/cases/fourslash/findAllRefsForComputedProperties2.ts +++ b/tests/cases/fourslash/findAllRefsForComputedProperties2.ts @@ -1,15 +1,25 @@ /// ////interface I { -//// [[|42|]](): void; +//// [[|{| "isDefinition": true |}42|]](): void; ////} //// ////class C implements I { -//// [[|42|]]: any; +//// [[|{| "isDefinition": true |}42|]]: any; ////} //// ////var x: I = { -//// ["[|42|]"]: function () { } +//// ["[|{| "isDefinition": true |}42|]"]: function () { } ////} -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2] = ranges; +verify.referenceGroups(r0, [{ definition: "(method) I[[42]](): void", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(method) I[[42]](): void", ranges: [r0, r2] }, + { definition: "(property) C[[42]]: any", ranges: [r1] } +]); +verify.referenceGroups(r2, [ + { definition: "(method) I[[42]](): void", ranges: [r0, r1] }, + { definition: '(property) ["42"]: () => void', ranges: [r2] } +]); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport.ts b/tests/cases/fourslash/findAllRefsForDefaultExport.ts index a27227b907a..c518bb8f59e 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport.ts @@ -1,11 +1,11 @@ /// // @Filename: a.ts -////export default function /*def*/[|f|]() {} +////export default function /*def*/[|{| "isWriteAccess": true, "isDefinition": true |}f|]() {} // @Filename: b.ts -////import [|g|] from "./a"; +////import [|{| "isWriteAccess": true, "isDefinition": true |}g|] from "./a"; /////*ref*/[|g|](); -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("function f(): void"); verify.goToDefinition("ref", "def"); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport01.ts b/tests/cases/fourslash/findAllRefsForDefaultExport01.ts index 39079294a3b..c04550e54f3 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport01.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport01.ts @@ -1,10 +1,13 @@ /// -////export default class [|DefaultExportedClass|] { +////export default class [|{| "isWriteAccess": true, "isDefinition": true |}DefaultExportedClass|] { ////} //// ////var x: [|DefaultExportedClass|]; //// ////var y = new [|DefaultExportedClass|]; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2] = ranges; +verify.referenceGroups([r0, r1], [{ definition: "class DefaultExportedClass", ranges }]); +verify.referenceGroups(r2, [{ definition: "constructor DefaultExportedClass(): DefaultExportedClass", ranges }]); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport02.ts b/tests/cases/fourslash/findAllRefsForDefaultExport02.ts index 19f31ece9b0..558bbd2de85 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport02.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport02.ts @@ -1,11 +1,22 @@ /// -////export default function [|DefaultExportedFunction|]() { -//// return [|DefaultExportedFunction|] +////export default function [|{| "isWriteAccess": true, "isDefinition": true |}DefaultExportedFunction|]() { +//// return [|DefaultExportedFunction|]; ////} //// ////var x: typeof [|DefaultExportedFunction|]; //// ////var y = [|DefaultExportedFunction|](); +//// +////namespace [|{| "isWriteAccess": true, "isDefinition": true |}DefaultExportedFunction|] { +////} -verify.rangesReferenceEachOther(); + +const ranges = test.ranges(); +const [r0, r1, r2, r3, r4] = ranges; +const fnRanges = [r0, r1, r2, r3]; +verify.singleReferenceGroup("function DefaultExportedFunction(): () => typeof DefaultExportedFunction", fnRanges); + +// The namespace and function do not merge, +// so the namespace should be all alone. +verify.singleReferenceGroup("namespace DefaultExportedFunction", [r4]); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport03.ts b/tests/cases/fourslash/findAllRefsForDefaultExport03.ts index b9bbfa14a64..d94043f4016 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport03.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport03.ts @@ -1,6 +1,6 @@ /// -////function [|f|]() { +////function [|{| "isWriteAccess": true, "isDefinition": true |}f|]() { //// return 100; ////} //// @@ -10,8 +10,11 @@ //// ////var y = [|f|](); //// -////namespace [|f|] { +////namespace [|{| "isWriteAccess": true, "isDefinition": true |}f|] { //// var local = 100; ////} -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2, r3, r4] = ranges; +verify.referenceGroups([r0, r3], [{ definition: "function f(): number\nnamespace f", ranges }]); +verify.referenceGroups([r1, r2, r4], [{ definition: "namespace f\nfunction f(): number", ranges }]); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport04.ts b/tests/cases/fourslash/findAllRefsForDefaultExport04.ts deleted file mode 100644 index 44b7ee0a06f..00000000000 --- a/tests/cases/fourslash/findAllRefsForDefaultExport04.ts +++ /dev/null @@ -1,23 +0,0 @@ -/// - -////function f() { -//// return 100; -////} -//// -////export default [|f|]; -//// -////var x: typeof f; -//// -////var y = f(); -//// -////namespace /**/[|f|] { -////} - -// The function 'f' and the namespace 'f' don't get merged, -// but the 'export default' site, includes both meanings. - -// Here we are testing whether the 'export default' -// site is included in the references to the namespace. - -goTo.marker(); -verify.referencesAre(test.ranges()); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport05.ts b/tests/cases/fourslash/findAllRefsForDefaultExport05.ts deleted file mode 100644 index 0f06792458d..00000000000 --- a/tests/cases/fourslash/findAllRefsForDefaultExport05.ts +++ /dev/null @@ -1,23 +0,0 @@ -/// - -////function /**/[|f|]() { -//// return 100; -////} -//// -////export default [|f|]; -//// -////var x: typeof [|f|]; -//// -////var y = [|f|](); -//// -////namespace f { -////} - -// The function 'f' and the namespace 'f' don't get merged, -// but the 'export default' site, includes both meanings. - -// Here we are testing whether the 'export default' site -// and all value-uses of 'f' are included in the references to the function. - -goTo.marker(); -verify.referencesAre(test.ranges()); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport06.ts b/tests/cases/fourslash/findAllRefsForDefaultExport06.ts deleted file mode 100644 index cdd9b4f980c..00000000000 --- a/tests/cases/fourslash/findAllRefsForDefaultExport06.ts +++ /dev/null @@ -1,23 +0,0 @@ -/// - -////function [|f|]() { -//// return 100; -////} -//// -////export default /**/[|f|]; -//// -////var x: typeof [|f|]; -//// -////var y = [|f|](); -//// -////namespace [|f|] { -////} - -// The function 'f' and the namespace 'f' don't get merged, -// but the 'export default' site, includes both meanings. - -// Here we are testing whether the 'export default' site -// and all value-uses of 'f' are included in the references to the function. - -goTo.marker(); -verify.referencesAre(test.ranges()); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport07.ts b/tests/cases/fourslash/findAllRefsForDefaultExport07.ts deleted file mode 100644 index 88d0a775026..00000000000 --- a/tests/cases/fourslash/findAllRefsForDefaultExport07.ts +++ /dev/null @@ -1,16 +0,0 @@ -/// - -////export default function DefaultExportedFunction() { -//// return DefaultExportedFunction -////} -//// -////var x: typeof DefaultExportedFunction; -//// -////var y = DefaultExportedFunction(); -//// -////namespace [|DefaultExportedFunction|] { -////} - -// The namespace and function do not merge, -// so the namespace should be all alone. -verify.rangesReferenceEachOther(); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport08.ts b/tests/cases/fourslash/findAllRefsForDefaultExport08.ts index b7ae7f4d534..b29060f6099 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport08.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport08.ts @@ -7,10 +7,9 @@ //// ////var y = new DefaultExportedClass; //// -////namespace [|DefaultExportedClass|] { +////namespace [|{| "isWriteAccess": true, "isDefinition": true |}DefaultExportedClass|] { ////} // The namespace and class do not merge, // so the namespace should be all alone. - -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("namespace DefaultExportedClass"); diff --git a/tests/cases/fourslash/findAllRefsForFunctionExpression01.ts b/tests/cases/fourslash/findAllRefsForFunctionExpression01.ts index 35d5c45e3d9..15ff0aca5cb 100644 --- a/tests/cases/fourslash/findAllRefsForFunctionExpression01.ts +++ b/tests/cases/fourslash/findAllRefsForFunctionExpression01.ts @@ -1,7 +1,7 @@ /// // @Filename: file1.ts -////var foo = function [|foo|](a = [|foo|](), b = () => [|foo|]) { +////var foo = function [|{| "isWriteAccess": true, "isDefinition": true |}foo|](a = [|foo|](), b = () => [|foo|]) { //// [|foo|]([|foo|], [|foo|]); ////} @@ -9,4 +9,4 @@ /////// ////foo(); -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(local function) foo(a?: void, b?: () => (a?: void, b?: any) => void): void"); diff --git a/tests/cases/fourslash/findAllRefsForMappedType.ts b/tests/cases/fourslash/findAllRefsForMappedType.ts index 38fb3a226c6..a841c7e6e46 100644 --- a/tests/cases/fourslash/findAllRefsForMappedType.ts +++ b/tests/cases/fourslash/findAllRefsForMappedType.ts @@ -1,9 +1,19 @@ /// -////interface T { [|a|]: number }; +////interface T { [|{| "isWriteAccess": true, "isDefinition": true |}a|]: number }; ////type U = { [K in keyof T]: string }; ////type V = { [K in keyof U]: boolean }; -////const u: U = { [|a|]: "" } -////const v: V = { [|a|]: true } +////const u: U = { [|{| "isWriteAccess": true, "isDefinition": true |}a|]: "" } +////const v: V = { [|{| "isWriteAccess": true, "isDefinition": true |}a|]: true } -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2] = ranges; +verify.referenceGroups(r0, [{ definition: "(property) T.a: number", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(property) T.a: number", ranges: [r0, r2] }, + { definition: "(property) a: string", ranges: [r1] } +]); +verify.referenceGroups(r2, [ + { definition: "(property) T.a: number", ranges: [r0, r1] }, + { definition: "(property) a: boolean", ranges: [r2] } +]); diff --git a/tests/cases/fourslash/findAllRefsForObjectLiteralProperties.ts b/tests/cases/fourslash/findAllRefsForObjectLiteralProperties.ts index cea4db81ea1..125a11f19c4 100644 --- a/tests/cases/fourslash/findAllRefsForObjectLiteralProperties.ts +++ b/tests/cases/fourslash/findAllRefsForObjectLiteralProperties.ts @@ -1,11 +1,17 @@ /// ////var x = { -//// [|property|]: {} +//// [|{| "isWriteAccess": true, "isDefinition": true |}property|]: {} ////}; //// ////x.[|property|]; //// ////let {[|property|]: pVar} = x; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2] = ranges; +verify.referenceGroups(r0, [{ definition: "(property) property: {}", ranges }]); +verify.referenceGroups([r1, r2], [ + { definition: "(property) property: {}", ranges: [r0] }, + { definition: "(property) property: {}", ranges: [r1, r2] } +]); diff --git a/tests/cases/fourslash/findAllRefsForObjectSpread.ts b/tests/cases/fourslash/findAllRefsForObjectSpread.ts index 05c83491f66..a65f18ef57c 100644 --- a/tests/cases/fourslash/findAllRefsForObjectSpread.ts +++ b/tests/cases/fourslash/findAllRefsForObjectSpread.ts @@ -1,14 +1,21 @@ /// -////interface A1 { [|a|]: string }; -////interface A2 { [|a|]?: number }; +////interface A1 { [|{| "isWriteAccess": true, "isDefinition": true |}a|]: string }; +////interface A2 { [|{| "isWriteAccess": true, "isDefinition": true |}a|]?: number }; ////let a1: A1; ////let a2: A2; ////let a12 = { ...a1, ...a2 }; ////a12.[|a|]; const ranges = test.ranges(); +const [r0, r1, r2] = ranges; + // members of spread types only refer to themselves and the resulting property -verify.referencesOf(ranges[0], [ranges[0], ranges[2]]); -verify.referencesOf(ranges[1], [ranges[1], ranges[2]]); +verify.referenceGroups(r0, [{ definition: "(property) A1.a: string", ranges: [r0, r2] }]); +verify.referenceGroups(r1, [{ definition: "(property) A2.a: number", ranges: [r1, r2] }]); + // but the resulting property refers to everything -verify.referencesOf(ranges[2], ranges); +verify.referenceGroups(r2, [ + { definition: "(property) A1.a: string", ranges: [r0] }, + { definition: "(property) A2.a: number", ranges: [r1] }, + { definition: "(property) a: string | number", ranges: [r2] } +]); diff --git a/tests/cases/fourslash/findAllRefsForRest.ts b/tests/cases/fourslash/findAllRefsForRest.ts index 65d6a3c60e3..026451d68b8 100644 --- a/tests/cases/fourslash/findAllRefsForRest.ts +++ b/tests/cases/fourslash/findAllRefsForRest.ts @@ -1,11 +1,11 @@ /// ////interface Gen { //// x: number -//// [|parent|]: Gen; +//// [|{| "isWriteAccess": true, "isDefinition": true |}parent|]: Gen; //// millenial: string; ////} ////let t: Gen; ////var { x, ...rest } = t; ////rest.[|parent|]; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(property) Gen.parent: Gen"); diff --git a/tests/cases/fourslash/findAllRefsForStringLiteralTypes.ts b/tests/cases/fourslash/findAllRefsForStringLiteralTypes.ts index 45e981d8a84..e450102c127 100644 --- a/tests/cases/fourslash/findAllRefsForStringLiteralTypes.ts +++ b/tests/cases/fourslash/findAllRefsForStringLiteralTypes.ts @@ -3,4 +3,4 @@ ////type Options = "[|option 1|]" | "option 2"; ////let myOption: Options = "[|option 1|]"; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup('"option 1"'); diff --git a/tests/cases/fourslash/findAllRefsForUMDModuleAlias1.ts b/tests/cases/fourslash/findAllRefsForUMDModuleAlias1.ts index 4177e154532..99ca347eac4 100644 --- a/tests/cases/fourslash/findAllRefsForUMDModuleAlias1.ts +++ b/tests/cases/fourslash/findAllRefsForUMDModuleAlias1.ts @@ -4,10 +4,10 @@ //// export function doThing(): string; //// export function doTheOtherThing(): void; -//// export as namespace [|myLib|]; +//// export as namespace [|{| "isWriteAccess": true, "isDefinition": true |}myLib|]; // @Filename: 1.ts //// /// //// [|myLib|].doThing(); -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("export namespace myLib"); diff --git a/tests/cases/fourslash/findAllRefsForVariableInExtendsClause01.ts b/tests/cases/fourslash/findAllRefsForVariableInExtendsClause01.ts index dd8fb1026c4..d40cb009f1e 100644 --- a/tests/cases/fourslash/findAllRefsForVariableInExtendsClause01.ts +++ b/tests/cases/fourslash/findAllRefsForVariableInExtendsClause01.ts @@ -1,6 +1,6 @@ /// -////var [|Base|] = class { }; +////var [|{| "isWriteAccess": true, "isDefinition": true |}Base|] = class { }; ////class C extends [|Base|] { } -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("var Base: typeof (Anonymous class)"); diff --git a/tests/cases/fourslash/findAllRefsForVariableInExtendsClause02.ts b/tests/cases/fourslash/findAllRefsForVariableInExtendsClause02.ts index 3fc41358dfd..5685df0c4e1 100644 --- a/tests/cases/fourslash/findAllRefsForVariableInExtendsClause02.ts +++ b/tests/cases/fourslash/findAllRefsForVariableInExtendsClause02.ts @@ -1,9 +1,9 @@ /// -////interface [|Base|] { } +////interface [|{| "isWriteAccess": true, "isDefinition": true |}Base|] { } ////namespace n { //// var Base = class { }; //// interface I extends [|Base|] { } ////} -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("interface Base"); diff --git a/tests/cases/fourslash/findAllRefsForVariableInImplementsClause01.ts b/tests/cases/fourslash/findAllRefsForVariableInImplementsClause01.ts index f8326eade58..419b828d0b3 100644 --- a/tests/cases/fourslash/findAllRefsForVariableInImplementsClause01.ts +++ b/tests/cases/fourslash/findAllRefsForVariableInImplementsClause01.ts @@ -3,5 +3,4 @@ ////var Base = class { }; ////class C extends Base implements /**/Base { } -goTo.marker(); -verify.referencesAre([]); +verify.noReferences(""); diff --git a/tests/cases/fourslash/findAllRefsInClassExpression.ts b/tests/cases/fourslash/findAllRefsInClassExpression.ts index f874bcbcb5c..b83d8992b4f 100644 --- a/tests/cases/fourslash/findAllRefsInClassExpression.ts +++ b/tests/cases/fourslash/findAllRefsInClassExpression.ts @@ -1,8 +1,14 @@ /// -////interface I { [|boom|](): void; } +////interface I { [|{| "isWriteAccess": true, "isDefinition": true |}boom|](): void; } ////new class C implements I { -//// [|boom|](){} +//// [|{| "isWriteAccess": true, "isDefinition": true |}boom|](){} ////} -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [{ definition: "(method) I.boom(): void", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(method) I.boom(): void", ranges: [r0] }, + { definition: "(method) C.boom(): void", ranges: [r1] } +]); diff --git a/tests/cases/fourslash/findAllRefsInheritedProperties1.ts b/tests/cases/fourslash/findAllRefsInheritedProperties1.ts index 358ba3f249d..41acc117f9e 100644 --- a/tests/cases/fourslash/findAllRefsInheritedProperties1.ts +++ b/tests/cases/fourslash/findAllRefsInheritedProperties1.ts @@ -1,8 +1,8 @@ /// //// class class1 extends class1 { -//// [|doStuff|]() { } -//// [|propName|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } +//// [|{| "isWriteAccess": true, "isDefinition": true |}propName|]: string; //// } //// //// var v: class1; @@ -10,7 +10,9 @@ //// v.[|propName|]; const [r0, r1, r2, r3] = test.ranges(); -verify.referencesOf(r0, [r0, r2]); -verify.referencesOf(r1, [r1, r3]); -verify.referencesOf(r2, [r0, r2]); -verify.referencesOf(r3, [r1, r3]); +verify.referenceGroups(r0, [{ definition: "(method) class1.doStuff(): void", ranges: [r0, r2] }]); +verify.referenceGroups(r2, [ + { definition: "(method) class1.doStuff(): void", ranges: [r0] }, + { definition: "(method) class1.doStuff(): void", ranges: [r2] } +]); +verify.singleReferenceGroup("(property) class1.propName: string", [r1, r3]); diff --git a/tests/cases/fourslash/findAllRefsInheritedProperties2.ts b/tests/cases/fourslash/findAllRefsInheritedProperties2.ts index 9fe36fbb48e..23badd64d48 100644 --- a/tests/cases/fourslash/findAllRefsInheritedProperties2.ts +++ b/tests/cases/fourslash/findAllRefsInheritedProperties2.ts @@ -1,8 +1,8 @@ /// //// interface interface1 extends interface1 { -//// [|doStuff|](): void; // r0 -//// [|propName|]: string; // r1 +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|](): void; // r0 +//// [|{| "isWriteAccess": true, "isDefinition": true |}propName|]: string; // r1 //// } //// //// var v: interface1; @@ -10,7 +10,5 @@ //// v.[|propName|]; // r3 const [r0, r1, r2, r3] = test.ranges(); -verify.referencesOf(r0, [r0, r2]); -verify.referencesOf(r1, [r1, r3]); -verify.referencesOf(r2, [r0, r2]); -verify.referencesOf(r3, [r1, r3]); +verify.singleReferenceGroup("(method) interface1.doStuff(): void", [r0, r2]); +verify.singleReferenceGroup("(property) interface1.propName: string", [r1, r3]); diff --git a/tests/cases/fourslash/findAllRefsInheritedProperties3.ts b/tests/cases/fourslash/findAllRefsInheritedProperties3.ts index 772fb78a2e8..cc82e4a4e44 100644 --- a/tests/cases/fourslash/findAllRefsInheritedProperties3.ts +++ b/tests/cases/fourslash/findAllRefsInheritedProperties3.ts @@ -1,28 +1,40 @@ /// //// class class1 extends class1 { -//// [|doStuff|]() { } // r0 -//// [|propName|]: string; // r1 +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } // r0 +//// [|{| "isWriteAccess": true, "isDefinition": true |}propName|]: string; // r1 //// } //// interface interface1 extends interface1 { -//// [|doStuff|](): void; // r2 -//// [|propName|]: string; // r3 +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|](): void; // r2 +//// [|{| "isWriteAccess": true, "isDefinition": true |}propName|]: string; // r3 //// } //// class class2 extends class1 implements interface1 { -//// [|doStuff|]() { } // r4 -//// [|propName|]: string; // r5 +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } // r4 +//// [|{| "isWriteAccess": true, "isDefinition": true |}propName|]: string; // r5 //// } -//// +//// //// var v: class2; -//// v.[|propName|]; // r6 -//// v.[|doStuff|](); // r7 +//// v.[|doStuff|](); // r6 +//// v.[|propName|]; // r7 const [r0, r1, r2, r3, r4, r5, r6, r7] = test.ranges(); -verify.referencesOf(r0, [r0, r4, r7]); -verify.referencesOf(r1, [r1, r5, r6]); -verify.referencesOf(r2, [r2, r4, r7]); -verify.referencesOf(r3, [r3, r5, r6]); -verify.referencesOf(r4, [r0, r2, r4, r7]); -verify.referencesOf(r5, [r1, r3, r5, r6]); -verify.referencesOf(r6, [r1, r3, r5, r6]); -verify.referencesOf(r7, [r0, r2, r4, r7]); +verify.referenceGroups(r0, [{ definition: "(method) class1.doStuff(): void", ranges: [r0, r4, r6] }]); +verify.referenceGroups(r1, [{ definition: "(property) class1.propName: string", ranges: [r1, r5, r7] }]); +verify.referenceGroups(r2, [{ definition: "(method) interface1.doStuff(): void", ranges: [r2, r4, r6] }]); +verify.referenceGroups(r3, [{ definition: "(property) interface1.propName: string", ranges: [r3, r5, r7] }]); +verify.referenceGroups(r4, [ + { definition: "(method) class1.doStuff(): void", ranges: [r0] }, + { definition: "(method) interface1.doStuff(): void", ranges: [r2] }, + { definition: "(method) class2.doStuff(): void", ranges: [r4, r6] } +]); +verify.referenceGroups([r5, r7], [ + { definition: "(property) class1.propName: string", ranges: [r1] }, + { definition: "(property) interface1.propName: string", ranges: [r3] }, + { definition: "(property) class2.propName: string", ranges: [r5, r7] } +]); +verify.referenceGroups(r6, [ + { definition: "(method) class1.doStuff(): void", ranges: [r0] }, + { definition: "(method) interface1.doStuff(): void", ranges: [r2] }, + { definition: "(method) class2.doStuff(): void", ranges: [r4] }, + { definition: "(method) class2.doStuff(): void", ranges: [r6] } +]); diff --git a/tests/cases/fourslash/findAllRefsInheritedProperties4.ts b/tests/cases/fourslash/findAllRefsInheritedProperties4.ts index 1ecb85bfae1..e2d8887bbe8 100644 --- a/tests/cases/fourslash/findAllRefsInheritedProperties4.ts +++ b/tests/cases/fourslash/findAllRefsInheritedProperties4.ts @@ -1,12 +1,12 @@ /// //// interface C extends D { -//// [|prop0|]: string; // r0 -//// [|prop1|]: number; // r1 +//// [|{| "isWriteAccess": true, "isDefinition": true |}prop0|]: string; // r0 +//// [|{| "isWriteAccess": true, "isDefinition": true |}prop1|]: number; // r1 //// } //// //// interface D extends C { -//// [|prop0|]: string; // r2 +//// [|{| "isWriteAccess": true, "isDefinition": true |}prop0|]: string; // r2 //// } //// //// var d: D; @@ -14,8 +14,9 @@ //// d.[|prop1|]; // r4 const [r0, r1, r2, r3, r4] = test.ranges(); -verify.referencesOf(r0, [r0, r2, r3]); -verify.referencesOf(r1, [r1]); -verify.referencesOf(r2, [r0, r2, r3]); -verify.referencesOf(r3, [r0, r2, r3]); -verify.referencesOf(r4, []); +verify.referenceGroups([r0, r2, r3], [ + { definition: "(property) C.prop0: string", ranges: [r0] }, + { definition: "(property) D.prop0: string", ranges: [r2, r3] } +]); +verify.singleReferenceGroup("(property) C.prop1: number", [r1]); +verify.noReferences(r4); diff --git a/tests/cases/fourslash/findAllRefsInheritedProperties5.ts b/tests/cases/fourslash/findAllRefsInheritedProperties5.ts index 6d6dbb392bf..c534a9d6aab 100644 --- a/tests/cases/fourslash/findAllRefsInheritedProperties5.ts +++ b/tests/cases/fourslash/findAllRefsInheritedProperties5.ts @@ -1,12 +1,12 @@ /// //// class C extends D { -//// [|prop0|]: string; // r0 -//// [|prop1|]: number; // r1 +//// [|{| "isWriteAccess": true, "isDefinition": true |}prop0|]: string; // r0 +//// [|{| "isWriteAccess": true, "isDefinition": true |}prop1|]: number; // r1 //// } //// //// class D extends C { -//// [|prop0|]: string; // r2 +//// [|{| "isWriteAccess": true, "isDefinition": true |}prop0|]: string; // r2 //// } //// //// var d: D; @@ -14,8 +14,7 @@ //// d.[|prop1|]; // r4 const [r0, r1, r2, r3, r4] = test.ranges(); -verify.referencesOf(r0, [r0]); -verify.referencesOf(r1, [r1]); -verify.referencesOf(r2, [r2, r3]); -verify.referencesOf(r3, [r2, r3]); -verify.referencesOf(r4, []); +verify.singleReferenceGroup("(property) C.prop0: string", [r0]); +verify.singleReferenceGroup("(property) C.prop1: number", [r1]); +verify.singleReferenceGroup("(property) D.prop0: string", [r2, r3]); +verify.noReferences(r4); diff --git a/tests/cases/fourslash/findAllRefsInsideTemplates1.ts b/tests/cases/fourslash/findAllRefsInsideTemplates1.ts index 9ab4c624230..8d41961c6fd 100644 --- a/tests/cases/fourslash/findAllRefsInsideTemplates1.ts +++ b/tests/cases/fourslash/findAllRefsInsideTemplates1.ts @@ -1,6 +1,6 @@ /// -////var [|x|] = 10; +////var [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 10; ////var y = `${ [|x|] } ${ [|x|] }` -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("var x: number"); diff --git a/tests/cases/fourslash/findAllRefsInsideTemplates2.ts b/tests/cases/fourslash/findAllRefsInsideTemplates2.ts index 63265eb944b..24a4a7c131b 100644 --- a/tests/cases/fourslash/findAllRefsInsideTemplates2.ts +++ b/tests/cases/fourslash/findAllRefsInsideTemplates2.ts @@ -1,6 +1,6 @@ /// -////function [|f|](...rest: any[]) { } +////function [|{| "isWriteAccess": true, "isDefinition": true |}f|](...rest: any[]) { } ////[|f|] `${ [|f|] } ${ [|f|] }` -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("function f(...rest: any[]): void"); diff --git a/tests/cases/fourslash/findAllRefsInsideWithBlock.ts b/tests/cases/fourslash/findAllRefsInsideWithBlock.ts index c95925ff863..52936248095 100644 --- a/tests/cases/fourslash/findAllRefsInsideWithBlock.ts +++ b/tests/cases/fourslash/findAllRefsInsideWithBlock.ts @@ -1,12 +1,12 @@ /// -////var [|x|] = 0; +////var [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 0; //// ////with ({}) { //// var y = x; // Reference of x here should not be picked //// /*2*/y++; // also reference for y should be ignored ////} //// -////[|x|] = [|x|] + 1; +////[|{| "isWriteAccess": true |}x|] = [|x|] + 1; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("var x: number"); diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName01.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName01.ts index 895b2168b23..d11bcee506f 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName01.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName01.ts @@ -1,11 +1,11 @@ /// ////interface I { -//// [|property1|]: number; +//// [|{| "isWriteAccess": true, "isDefinition": true |}property1|]: number; //// property2: string; ////} //// ////var foo: I; ////var { [|property1|]: prop1 } = foo; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(property) I.property1: number"); diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName02.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName02.ts index 67a31f33d1e..6ad98df9cd8 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName02.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName02.ts @@ -1,11 +1,11 @@ /// ////interface I { -//// [|property1|]: number; +//// [|{| "isWriteAccess": true, "isDefinition": true |}property1|]: number; //// property2: string; ////} //// ////var foo: I; ////var { [|property1|]: {} } = foo; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(property) I.property1: number"); diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName03.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName03.ts index 40ecf0139a7..520dbc8e1e4 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName03.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName03.ts @@ -1,11 +1,17 @@ /// ////interface I { -//// [|property1|]: number; +//// [|{| "isWriteAccess": true, "isDefinition": true |}property1|]: number; //// property2: string; ////} //// ////var foo: I; -////var [{ [|property1|]: prop1 }, { [|property1|], property2 } ] = [foo, foo]; +////var [{ [|property1|]: prop1 }, { [|{| "isWriteAccess": true, "isDefinition": true |}property1|], property2 } ] = [foo, foo]; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2] = ranges; +verify.referenceGroups([r0, r1], [{ definition: "(property) I.property1: number", ranges }]); +verify.referenceGroups(r2, [ + { definition: "(property) I.property1: number", ranges: [r0, r1] }, + { definition: "var property1: number", ranges: [r2] } +]); diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts index 5696d242fed..f25fff9da23 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts @@ -1,15 +1,22 @@ /// ////interface I { -//// [|property1|]: number; +//// [|{| "isWriteAccess": true, "isDefinition": true |}property1|]: number; //// property2: string; ////} //// ////function f({ [|property1|]: p1 }: I, -//// { [|property1|] }: I, +//// { [|{| "isWriteAccess": true, "isDefinition": true |}property1|] }: I, //// { property1: p2 }) { //// //// return [|property1|] + 1; ////} -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2, r3] = ranges; +verify.referenceGroups([r0, r1], [{ definition: "(property) I.property1: number", ranges }]); +verify.referenceGroups([r2, r3], [ + { definition: "(property) I.property1: number", ranges: [r0, r1] }, + { definition: "var property1: number", ranges: [r2, r3] } +]); + diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName05.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName05.ts index e33c73ff838..f4e7bd70f7a 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName05.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName05.ts @@ -10,4 +10,4 @@ ////} goTo.marker(); -verify.referencesAre([]); \ No newline at end of file +verify.noReferences(""); \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts index 8be45ac87e6..c589dccacbc 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts @@ -1,22 +1,29 @@ /// ////interface I { -//// [|property1|]: number; +//// [|{| "isWriteAccess": true, "isDefinition": true |}property1|]: number; //// property2: string; ////} //// ////var elems: I[]; ////for (let { [|property1|]: p } of elems) { ////} -////for (let { [|property1|] } of elems) { +////for (let { [|{| "isWriteAccess": true, "isDefinition": true |}property1|] } of elems) { ////} ////for (var { [|property1|]: p1 } of elems) { ////} ////var p2; -////for ({ [|property1|] : p2 } of elems) { +////for ({ [|{| "isWriteAccess": true, "isDefinition": true |}property1|] : p2 } of elems) { ////} -// Note: if this test ever changes, consider updating -// 'quickInfoForObjectBindingElementPropertyName05.ts' - -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2, r3, r4] = ranges; +verify.referenceGroups([r0, r1, r3], [{ definition: "(property) I.property1: number", ranges }]); +verify.referenceGroups(r2, [ + { definition: "(property) I.property1: number", ranges: [r0, r1, r3, r4] }, + { definition: "let property1: number", ranges: [r2] } +]); +verify.referenceGroups(r4, [ + { definition: "(property) I.property1: number", ranges: [r0, r1, r2, r3] }, + { definition: "(property) property1: I", ranges: [r4] } +]); diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName07.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName07.ts index 96f414dc060..f9415ab6a81 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName07.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName07.ts @@ -2,6 +2,12 @@ ////let p, b; //// -////p, [{ [|a|]: p, b }] = [{ [|a|]: 10, b: true }]; +////p, [{ [|{| "isWriteAccess": true, "isDefinition": true |}a|]: p, b }] = [{ [|{| "isWriteAccess": true, "isDefinition": true |}a|]: 10, b: true }]; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [{ definition: "(property) a: any", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(property) a: any", ranges: [r0] }, + { definition: "(property) a: number", ranges: [r1] } +]); diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName09.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName09.ts deleted file mode 100644 index 5696d242fed..00000000000 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName09.ts +++ /dev/null @@ -1,15 +0,0 @@ -/// - -////interface I { -//// [|property1|]: number; -//// property2: string; -////} -//// -////function f({ [|property1|]: p1 }: I, -//// { [|property1|] }: I, -//// { property1: p2 }) { -//// -//// return [|property1|] + 1; -////} - -verify.rangesReferenceEachOther(); diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts index 6ffa4b03b68..1c79d326dbc 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts @@ -1,11 +1,11 @@ /// ////interface Recursive { -//// [|next|]?: Recursive; +//// [|{| "isWriteAccess": true, "isDefinition": true |}next|]?: Recursive; //// value: any; ////} //// ////function f ({ [|next|]: { [|next|]: x} }: Recursive) { ////} -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(property) Recursive.next: Recursive"); diff --git a/tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts b/tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts index 0954945a546..061903e703d 100644 --- a/tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts +++ b/tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts @@ -6,5 +6,4 @@ ////var x = new [|X|](); const ranges = test.ranges(); -const ctr = ranges[0]; -verify.referencesOf(ctr, ranges); +verify.referenceGroups(ranges[0], [{ definition: "constructor X(): X", ranges }]); diff --git a/tests/cases/fourslash/findAllRefsOnDecorators.ts b/tests/cases/fourslash/findAllRefsOnDecorators.ts index b58e15b9571..95bf1072014 100644 --- a/tests/cases/fourslash/findAllRefsOnDecorators.ts +++ b/tests/cases/fourslash/findAllRefsOnDecorators.ts @@ -1,7 +1,7 @@ /// // @Filename: a.ts -////function [|decorator|](target) { +////function [|{| "isWriteAccess": true, "isDefinition": true |}decorator|](target) { //// return target; ////} ////[|decorator|](); @@ -13,4 +13,4 @@ //// method() {} ////} -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("function decorator(target: any): any"); diff --git a/tests/cases/fourslash/findAllRefsOnDefinition.ts b/tests/cases/fourslash/findAllRefsOnDefinition.ts index cb829807602..7d136efc42a 100644 --- a/tests/cases/fourslash/findAllRefsOnDefinition.ts +++ b/tests/cases/fourslash/findAllRefsOnDefinition.ts @@ -7,7 +7,7 @@ //// //// } //// -//// public [|start|](){ +//// public [|{| "isWriteAccess": true, "isDefinition": true |}start|](){ //// return this; //// } //// @@ -23,4 +23,10 @@ ////second.[|start|](); ////second.stop(); -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [{ definition: "(method) Test.start(): this", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(method) Second.Test.start(): Second.Test", ranges: [r0] }, + { definition: "(method) Second.Test.start(): Second.Test", ranges: [r1] }, +]); diff --git a/tests/cases/fourslash/findAllRefsOnDefinition2.ts b/tests/cases/fourslash/findAllRefsOnDefinition2.ts index 8edfd7f8cd7..6d2438a124c 100644 --- a/tests/cases/fourslash/findAllRefsOnDefinition2.ts +++ b/tests/cases/fourslash/findAllRefsOnDefinition2.ts @@ -3,7 +3,7 @@ //@Filename: findAllRefsOnDefinition2-import.ts ////export module Test{ //// -//// export interface [|start|] { } +//// export interface [|{| "isWriteAccess": true, "isDefinition": true |}start|] { } //// //// export interface stop { } ////} @@ -14,4 +14,8 @@ ////var start: Second.Test.[|start|]; ////var stop: Second.Test.stop; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [{ definition: "interface Test.start", ranges }]); +verify.referenceGroups(r1, [{ definition: "interface Second.Test.start", ranges }]); + diff --git a/tests/cases/fourslash/findAllRefsOnImportAliases.ts b/tests/cases/fourslash/findAllRefsOnImportAliases.ts index cd258e80316..7574e11625f 100644 --- a/tests/cases/fourslash/findAllRefsOnImportAliases.ts +++ b/tests/cases/fourslash/findAllRefsOnImportAliases.ts @@ -1,15 +1,18 @@ /// //@Filename: a.ts -////export class [|Class|] { +////export class [|{| "isWriteAccess": true, "isDefinition": true |}Class|] { ////} //@Filename: b.ts -////import { [|Class|] } from "./a"; +////import { [|{| "isWriteAccess": true, "isDefinition": true |}Class|] } from "./a"; //// ////var c = new [|Class|](); //@Filename: c.ts -////export { [|Class|] } from "./a"; +////export { [|{| "isWriteAccess": true, "isDefinition": true |}Class|] } from "./a"; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2, r3] = ranges; +verify.referenceGroups([r0, r1, r3], [{ definition: "class Class", ranges }]); +verify.referenceGroups(r2, [{ definition: "constructor Class(): Class", ranges }]); diff --git a/tests/cases/fourslash/findAllRefsOnImportAliases2.ts b/tests/cases/fourslash/findAllRefsOnImportAliases2.ts index 67c4d14b5d9..a21d2da4c03 100644 --- a/tests/cases/fourslash/findAllRefsOnImportAliases2.ts +++ b/tests/cases/fourslash/findAllRefsOnImportAliases2.ts @@ -1,15 +1,23 @@ /// //@Filename: a.ts -////export class [|Class|] { +////export class [|{| "isWriteAccess": true, "isDefinition": true |}Class|] { ////} //@Filename: b.ts -////import { [|Class|] as [|C2|] } from "./a"; +////import { [|{| "isWriteAccess": true, "isDefinition": true |}Class|] as [|{| "isWriteAccess": true, "isDefinition": true |}C2|] } from "./a"; //// ////var c = new [|C2|](); //@Filename: c.ts -////export { [|Class|] as [|C3|] } from "./a"; +////export { [|{| "isWriteAccess": true, "isDefinition": true |}Class|] as [|{| "isWriteAccess": true, "isDefinition": true |}C3|] } from "./a"; -verify.rangesWithSameTextReferenceEachOther(); +const ranges = test.rangesByText(); +verify.singleReferenceGroup("class Class", ranges.get("Class")); + +const c2s = ranges.get("C2"); +const [c2_0, c2_1] = c2s; +verify.referenceGroups(c2_0, [{ definition: "import C2", ranges: c2s }]); +verify.referenceGroups(c2_1, [{ definition: "(alias) new C2(): C2\nimport C2", ranges: c2s }]); + +verify.singleReferenceGroup("import C3", ranges.get("C3")); diff --git a/tests/cases/fourslash/findAllRefsOnPrivateParameterProperty1.ts b/tests/cases/fourslash/findAllRefsOnPrivateParameterProperty1.ts index 3b8b5084a6b..df33f2888e6 100644 --- a/tests/cases/fourslash/findAllRefsOnPrivateParameterProperty1.ts +++ b/tests/cases/fourslash/findAllRefsOnPrivateParameterProperty1.ts @@ -1,7 +1,7 @@ /// ////class ABCD { -//// constructor(private x: number, public y: number, private [|z|]: number) { +//// constructor(private x: number, public y: number, private [|{| "isWriteAccess": true, "isDefinition": true |}z|]: number) { //// } //// //// func() { @@ -9,4 +9,4 @@ //// } ////} -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(property) ABCD.z: number"); diff --git a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration1.ts b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration1.ts index 8f30e3cc853..fa1254118a1 100644 --- a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration1.ts +++ b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration1.ts @@ -1,10 +1,15 @@ /// //// class Foo { -//// constructor(private [|privateParam|]: number) { +//// constructor(private [|{| "isWriteAccess": true, "isDefinition": true |}privateParam|]: number) { //// let localPrivate = [|privateParam|]; //// this.[|privateParam|] += 10; //// } //// } -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2] = ranges; +verify.referenceGroups(ranges, [ + { definition: "(property) Foo.privateParam: number", ranges: [r0, r2] }, + { definition: "(parameter) privateParam: number", ranges: [r1] } +]); diff --git a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration2.ts b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration2.ts index d9656e8b5cf..45d814f909e 100644 --- a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration2.ts +++ b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration2.ts @@ -1,10 +1,15 @@ /// //// class Foo { -//// constructor(public [|publicParam|]: number) { +//// constructor(public [|{| "isWriteAccess": true, "isDefinition": true |}publicParam|]: number) { //// let localPublic = [|publicParam|]; //// this.[|publicParam|] += 10; //// } //// } -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2] = ranges; +verify.referenceGroups(ranges, [ + { definition: "(property) Foo.publicParam: number", ranges: [r0, r2] }, + { definition: "(parameter) publicParam: number", ranges: [r1] } +]); diff --git a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration3.ts b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration3.ts index dc48ffedb21..3520fecb8ad 100644 --- a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration3.ts +++ b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration3.ts @@ -1,10 +1,15 @@ /// //// class Foo { -//// constructor(protected [|protectedParam|]: number) { +//// constructor(protected [|{| "isWriteAccess": true, "isDefinition": true |}protectedParam|]: number) { //// let localProtected = [|protectedParam|]; //// this.[|protectedParam|] += 10; //// } //// } -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2] = ranges; +verify.referenceGroups(ranges, [ + { definition: "(property) Foo.protectedParam: number", ranges: [r0, r2] }, + { definition: "(parameter) protectedParam: number", ranges: [r1] } +]); diff --git a/tests/cases/fourslash/findAllRefsPrimitive.ts b/tests/cases/fourslash/findAllRefsPrimitive.ts index 51c463843e1..bf704c6ae71 100644 --- a/tests/cases/fourslash/findAllRefsPrimitive.ts +++ b/tests/cases/fourslash/findAllRefsPrimitive.ts @@ -24,7 +24,7 @@ // @Filename: b.ts // const z: [|any|] = 0; -verify.rangesWithSameTextReferenceEachOther(); +test.rangesByText().forEach((ranges, text) => verify.singleReferenceGroup(text, ranges)); verify.rangesWithSameTextAreDocumentHighlights(); goTo.rangeStart(test.ranges()[0]); diff --git a/tests/cases/fourslash/findAllRefsPropertyContextuallyTypedByTypeParam01.ts b/tests/cases/fourslash/findAllRefsPropertyContextuallyTypedByTypeParam01.ts index f5b0143ac4b..dec6575ebc4 100644 --- a/tests/cases/fourslash/findAllRefsPropertyContextuallyTypedByTypeParam01.ts +++ b/tests/cases/fourslash/findAllRefsPropertyContextuallyTypedByTypeParam01.ts @@ -1,12 +1,12 @@ /// ////interface IFoo { -//// [|a|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}a|]: string; ////} ////class C { //// method() { //// var x: T = { -//// [|a|]: "" +//// [|{| "isWriteAccess": true, "isDefinition": true |}a|]: "" //// }; //// x.[|a|]; //// } @@ -14,7 +14,17 @@ //// //// ////var x: IFoo = { -//// [|a|]: "ss" +//// [|{| "isWriteAccess": true, "isDefinition": true |}a|]: "ss" ////}; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2, r3] = ranges; +verify.referenceGroups([r0, r2], [{ definition: "(property) IFoo.a: string", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(property) IFoo.a: string", ranges: [r0, r2, r3] }, + { definition: "(property) a: string", ranges: [r1] } +]); +verify.referenceGroups(r3, [ + { definition: "(property) IFoo.a: string", ranges: [r0, r1, r2] }, + { definition: "(property) a: string", ranges: [r3] } +]); diff --git a/tests/cases/fourslash/findAllRefsThisKeyword.ts b/tests/cases/fourslash/findAllRefsThisKeyword.ts index f08a70ccf65..6f5374f902a 100644 --- a/tests/cases/fourslash/findAllRefsThisKeyword.ts +++ b/tests/cases/fourslash/findAllRefsThisKeyword.ts @@ -2,9 +2,9 @@ // @noLib: true ////[|this|]; -////function f([|this|]) { +////function f([|{| "isWriteAccess": true, "isDefinition": true |}this|]) { //// return [|this|]; -//// function g([|this|]) { return [|this|]; } +//// function g([|{| "isWriteAccess": true, "isDefinition": true |}this|]) { return [|this|]; } ////} ////class C { //// static x() { @@ -21,13 +21,19 @@ //// } ////} ////// These are *not* real uses of the 'this' keyword, they are identifiers. -////const x = { [|this|]: 0 } +////const x = { [|{| "isWriteAccess": true, "isDefinition": true |}this|]: 0 } ////x.[|this|]; const [global, f0, f1, g0, g1, x, y, constructor, method, propDef, propUse] = test.ranges(); verify.referencesOf(global, [global]); -verify.rangesReferenceEachOther([f0, f1]); -verify.rangesReferenceEachOther([g0, g1]); -verify.rangesReferenceEachOther([x, y]); -verify.rangesReferenceEachOther([constructor, method]); -verify.rangesReferenceEachOther([propDef, propUse]); +verify.referenceGroups(f0, [{ definition: "(parameter) this: any", ranges: [f0, f1] }]); +verify.referenceGroups(f1, [{ definition: "this: any", ranges: [f0, f1] }]); +verify.referenceGroups(g0, [{ definition: "(parameter) this: any", ranges: [g0, g1] }]); +verify.referenceGroups(g1, [{ definition: "this: any", ranges: [g0, g1] }]); +verify.singleReferenceGroup("this: typeof C", [x, y]); +verify.singleReferenceGroup("this: this", [constructor, method]); +verify.referenceGroups(propDef, [{ definition: "(property) this: number", ranges: [propDef, propUse] }]); +verify.referenceGroups(propUse, [ + { definition: "(property) this: number", ranges: [propDef] }, + { definition: "(property) this: number", ranges: [propUse] }, +]); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames1.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames1.ts index 7cc47ee34ea..d2baf7c96b3 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames1.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames1.ts @@ -1,10 +1,16 @@ /// ////class Foo { -//// public [|_bar|]() { return 0; } +//// public [|{| "isWriteAccess": true, "isDefinition": true |}_bar|]() { return 0; } ////} //// ////var x: Foo; ////x.[|_bar|]; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [{ definition: "(method) Foo._bar(): number", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(method) Foo._bar(): number", ranges: [r0] }, + { definition: "(method) Foo._bar(): number", ranges: [r1] } +]); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames2.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames2.ts index d1449016b59..3f5cd9ddbed 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames2.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames2.ts @@ -1,10 +1,16 @@ /// ////class Foo { -//// public [|__bar|]() { return 0; } +//// public [|{| "isWriteAccess": true, "isDefinition": true |}__bar|]() { return 0; } ////} //// ////var x: Foo; ////x.[|__bar|]; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [{ definition: "(method) Foo.__bar(): number", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(method) Foo.__bar(): number", ranges: [r0] }, + { definition: "(method) Foo.__bar(): number", ranges: [r1] } +]); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames3.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames3.ts index e0d6f7f3456..e1870065325 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames3.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames3.ts @@ -1,10 +1,16 @@ /// ////class Foo { -//// public [|___bar|]() { return 0; } +//// public [|{| "isWriteAccess": true, "isDefinition": true |}___bar|]() { return 0; } ////} //// ////var x: Foo; ////x.[|___bar|]; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [{ definition: "(method) Foo.___bar(): number", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(method) Foo.___bar(): number", ranges: [r0] }, + { definition: "(method) Foo.___bar(): number", ranges: [r1] } +]); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames4.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames4.ts index 5a8de54db4d..74eef0ae989 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames4.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames4.ts @@ -1,10 +1,16 @@ /// ////class Foo { -//// public [|____bar|]() { return 0; } +//// public [|{| "isWriteAccess": true, "isDefinition": true |}____bar|]() { return 0; } ////} //// ////var x: Foo; ////x.[|____bar|]; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [{ definition: "(method) Foo.____bar(): number", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(method) Foo.____bar(): number", ranges: [r0] }, + { definition: "(method) Foo.____bar(): number", ranges: [r1] } +]); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames5.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames5.ts index 4ab28f164fe..d54b48bf662 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames5.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames5.ts @@ -3,7 +3,7 @@ ////class Foo { //// public _bar; //// public __bar; -//// public [|___bar|]; +//// public [|{| "isWriteAccess": true, "isDefinition": true |}___bar|]; //// public ____bar; ////} //// @@ -13,4 +13,4 @@ ////x.[|___bar|]; ////x.____bar; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(property) Foo.___bar: any"); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames6.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames6.ts index 191b0bdbc14..39bc1d73ca3 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames6.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames6.ts @@ -2,7 +2,7 @@ ////class Foo { //// public _bar; -//// public [|__bar|]; +//// public [|{| "isWriteAccess": true, "isDefinition": true |}__bar|]; //// public ___bar; //// public ____bar; ////} @@ -13,4 +13,4 @@ ////x.___bar; ////x.____bar; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(property) Foo.__bar: any"); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames7.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames7.ts index f3578193096..dac42f4fc7c 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames7.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames7.ts @@ -1,7 +1,7 @@ /// -////function [|__foo|]() { +////function [|{| "isWriteAccess": true, "isDefinition": true |}__foo|]() { //// [|__foo|](); ////} -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("function __foo(): void"); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames8.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames8.ts index 15c66f4e7c6..8c92275e27f 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames8.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames8.ts @@ -1,7 +1,7 @@ /// -////(function [|__foo|]() { +////(function [|{| "isWriteAccess": true, "isDefinition": true |}__foo|]() { //// [|__foo|](); ////}) -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(local function) __foo(): void"); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames9.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames9.ts index cc33b618c41..bc5799e61cf 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames9.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames9.ts @@ -1,7 +1,7 @@ /// -////(function [|___foo|]() { +////(function [|{| "isWriteAccess": true, "isDefinition": true |}___foo|]() { //// [|___foo|](); ////}) -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(local function) ___foo(): void"); diff --git a/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment.ts b/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment.ts index 0dc050602c5..544a3238e3b 100644 --- a/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment.ts +++ b/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment.ts @@ -1,14 +1,19 @@ /// -//// var [|name|] = "Foo"; +//// var [|{| "isWriteAccess": true, "isDefinition": true |}name|] = "Foo"; //// -//// var obj = { [|name|] }; -//// var obj1 = { [|name|]:[|name|] }; +//// var obj = { [|{| "isWriteAccess": true, "isDefinition": true |}name|] }; +//// var obj1 = { [|{| "isWriteAccess": true, "isDefinition": true |}name|]:[|name|] }; //// obj.[|name|]; const [r0, r1, r2, r3, r4] = test.ranges(); -verify.referencesOf(r0, [r0, r1, r3]); -verify.referencesOf(r1, [r0, r1, r3, r4]); -verify.referencesOf(r2, [r2]); -verify.referencesOf(r3, [r0, r1, r3]); -verify.referencesOf(r4, [r1, r4]); +verify.referenceGroups([r0, r3], [{ definition: "var name: string", ranges: [r0, r1, r3] }]); +verify.referenceGroups(r1, [ + { definition: "var name: string", ranges: [r0, r3] }, + { definition: "(property) name: string", ranges: [r1, r4] } +]); +verify.singleReferenceGroup("(property) name: string", [r2]); +verify.referenceGroups(r4, [ + { definition: "(property) name: string", ranges: [r1] }, + { definition: "(property) name: string", ranges: [r4] }, +]); diff --git a/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment2.ts b/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment2.ts index 59ba87fabb6..d4f758696fe 100644 --- a/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment2.ts +++ b/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment2.ts @@ -1,16 +1,22 @@ /// -//// var [|dx|] = "Foo"; +//// var [|{| "isWriteAccess": true, "isDefinition": true |}dx|] = "Foo"; //// -//// module M { export var [|dx|]; } +//// module M { export var [|{| "isWriteAccess": true, "isDefinition": true |}dx|]; } //// module M { //// var z = 100; -//// export var y = { [|dx|], z }; +//// export var y = { [|{| "isWriteAccess": true, "isDefinition": true |}dx|], z }; //// } //// M.y.[|dx|]; const [r0, r1, r2, r3] = test.ranges(); -verify.referencesOf(r0, [r0]); -verify.referencesOf(r1, [r1, r2]); -verify.referencesOf(r2, [r1, r2, r3]); -verify.referencesOf(r3, [r2, r3]); +verify.singleReferenceGroup("var dx: string", [r0]); +verify.referenceGroups(r1, [{ definition: "var M.dx: any", ranges: [r1, r2] }]); +verify.referenceGroups(r2, [ + { definition: "var M.dx: any", ranges: [r1] }, + { definition: "(property) dx: any", ranges: [r2, r3] } +]); +verify.referenceGroups(r3, [ + { definition: "(property) dx: any", ranges: [r2] }, + { definition: "(property) dx: any", ranges: [r3] } +]); diff --git a/tests/cases/fourslash/findReferencesAcrossMultipleProjects.ts b/tests/cases/fourslash/findReferencesAcrossMultipleProjects.ts index a9915fc4b3d..f9feb5ddb62 100644 --- a/tests/cases/fourslash/findReferencesAcrossMultipleProjects.ts +++ b/tests/cases/fourslash/findReferencesAcrossMultipleProjects.ts @@ -1,14 +1,14 @@ /// //@Filename: a.ts -////var [|x|]: number; +////var [|{| "isWriteAccess": true, "isDefinition": true |}x|]: number; //@Filename: b.ts /////// -////[|x|]++; +////[|{| "isWriteAccess": true |}x|]++; //@Filename: c.ts /////// -////[|x|]++; +////[|{| "isWriteAccess": true |}x|]++; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("var x: number"); diff --git a/tests/cases/fourslash/findReferencesAfterEdit.ts b/tests/cases/fourslash/findReferencesAfterEdit.ts index 6140ca9a767..2d57e78c637 100644 --- a/tests/cases/fourslash/findReferencesAfterEdit.ts +++ b/tests/cases/fourslash/findReferencesAfterEdit.ts @@ -2,7 +2,7 @@ // @Filename: a.ts ////interface A { -//// [|foo|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}foo|]: string; ////} // @Filename: b.ts @@ -12,9 +12,9 @@ //// x.[|foo|] ////} -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(property) A.foo: string"); goTo.marker(""); edit.insert("\r\n"); -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(property) A.foo: string"); diff --git a/tests/cases/fourslash/findReferencesJSXTagName.ts b/tests/cases/fourslash/findReferencesJSXTagName.ts index 24760046eb2..5f8bc3a475f 100644 --- a/tests/cases/fourslash/findReferencesJSXTagName.ts +++ b/tests/cases/fourslash/findReferencesJSXTagName.ts @@ -1,14 +1,16 @@ /// // @Filename: index.tsx -////import { [|SubmissionComp|] } from "./RedditSubmission" +////import { [|{| "isWriteAccess": true, "isDefinition": true |}SubmissionComp|] } from "./RedditSubmission" ////function displaySubreddit(subreddit: string) { //// let components = submissions //// .map((value, index) => <[|SubmissionComp|] key={ index } elementPosition= { index } {...value.data} />); ////} // @Filename: RedditSubmission.ts -////export const [|SubmissionComp|] = (submission: SubmissionProps) => +////export const [|{| "isWriteAccess": true, "isDefinition": true |}SubmissionComp|] = (submission: SubmissionProps) => ////
; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2] = ranges; +verify.referenceGroups(ranges, [{ definition: "const SubmissionComp: (submission: any) => any", ranges: [r2, r0, r1] }]); diff --git a/tests/cases/fourslash/findReferencesJSXTagName2.ts b/tests/cases/fourslash/findReferencesJSXTagName2.ts index 4ce08647c52..a8882b60088 100644 --- a/tests/cases/fourslash/findReferencesJSXTagName2.ts +++ b/tests/cases/fourslash/findReferencesJSXTagName2.ts @@ -1,7 +1,9 @@ /// // @Filename: index.tsx -////const [|obj|] = {Component: () =>
}; +////const [|{| "isWriteAccess": true, "isDefinition": true |}obj|] = {Component: () =>
}; ////const element = <[|obj|].Component/>; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup(`const obj: { + Component: () => any; +}`); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 6685bbc19c0..c613204f539 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -182,18 +182,19 @@ declare namespace FourSlashInterface { goToType(startMarkerNames: string | string[], endMarkerNames: string | string[]): void; verifyGetEmitOutputForCurrentFile(expected: string): void; verifyGetEmitOutputContentsForCurrentFile(expected: ts.OutputFile[]): void; + noReferences(markerNameOrRange?: string | Range): void; /** - * Asserts that the given ranges are the references from the current position. - * If ranges have markers, those markers may have "isDefinition" and "isWriteAccess" data - * (otherwise these properties pf the reference are not tested). - * Order of ranges does not matter. - */ - referencesAre(ranges: Range[]): void; - /** + * @deprecated, prefer 'referenceGroups' * Like `referencesAre`, but goes to `start` first. * `start` should be included in `references`. */ referencesOf(start: Range, references: Range[]): void; + /** + * For each of startRanges, asserts the ranges that are referenced from there. + * This uses the 'findReferences' command instead of 'getReferencesAtPosition', so references are grouped by their definition. + */ + referenceGroups(startRanges: Range | Range[], parts: Array<{ definition: string, ranges: Range[] }>): void; + singleReferenceGroup(definition: string, ranges?: Range[]): void; rangesAreOccurrences(isWriteAccess?: boolean): void; rangesAreRenameLocations(findInStrings?: boolean, findInComments?: boolean): void; /** @@ -202,7 +203,6 @@ declare namespace FourSlashInterface { */ rangesReferenceEachOther(ranges?: Range[]): void; findReferencesDefinitionDisplayPartsAtCaretAre(expected: ts.SymbolDisplayPart[]): void; - rangesWithSameTextReferenceEachOther(): void; currentParameterHelpArgumentNameIs(name: string): void; currentParameterSpanIs(parameter: string): void; currentParameterHelpArgumentDocCommentIs(docComment: string): void; diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts index 57b4c14ffba..b1acb76ad2c 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts @@ -1,5 +1,5 @@ /// -////var [|{| "isDefinition": true |}f|] = x => x + 1; -////[|{| "isDefinition": false |}f|](12); +////var [|{| "isWriteAccess": true, "isDefinition": true |}f|] = x => x + 1; +////[|f|](12); -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("var f: (x: any) => any"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfBindingPattern.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfBindingPattern.ts index e60921ec3b8..7725b2e94f8 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfBindingPattern.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfBindingPattern.ts @@ -1,5 +1,5 @@ /// -////const { [|{| "isDefinition": true |}x|], y } = { x: 1, y: 2 }; +////const { [|{| "isWriteAccess": true, "isDefinition": true |}x|], y } = { x: 1, y: 2 }; ////const z = [|{| "isDefinition": false |}x|]; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("const x: number"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts index 0a3c2e4231c..b39c11dfe6b 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts @@ -1,10 +1,13 @@ /// -////class [|{| "isDefinition": true |}C|] { +////class [|{| "isWriteAccess": true, "isDefinition": true |}C|] { //// n: number; //// constructor() { //// this.n = 12; //// } ////} -////let c = new [|{| "isDefinition": false |}C|](); +////let c = new [|C|](); -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [{ definition: "class C", ranges }]); +verify.referenceGroups(r1, [{ definition: "constructor C(): C", ranges }]); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts index 81df97eff2d..27c34e56600 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts @@ -1,7 +1,9 @@ /// -////let o = { ["/**/[|{| "isDefinition": true |}foo|]"]: 12 }; -////let y = o.[|{| "isDefinition": false |}foo|]; -////let z = o['[|{| "isDefinition": false |}foo|]']; +////let o = { ["[|{| "isDefinition": true |}foo|]"]: 12 }; +////let y = o.[|foo|]; +////let z = o['[|foo|]']; -goTo.marker(); -verify.referencesAre(test.ranges()); +const ranges = test.ranges(); +const [r0, r1, r2] = ranges; +verify.referenceGroups(r0, [{ definition: '(property) ["foo"]: number', ranges }]); +verify.referenceGroups([r1, r2], []); // TODO: fix diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts index 5b77bf6158a..325674d8ee7 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts @@ -1,8 +1,8 @@ /// -////enum [|{| "isDefinition": true |}E|] { +////enum [|{| "isWriteAccess": true, "isDefinition": true |}E|] { //// First, //// Second ////} -////let first = [|{| "isDefinition": false |}E|].First; +////let first = [|E|].First; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("enum E"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfExport.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfExport.ts index 759df4fa383..9cdfb0aa0f7 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfExport.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfExport.ts @@ -1,8 +1,8 @@ /// // @Filename: m.ts -////export var [|{| "isDefinition": true |}x|] = 12; +////export var [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 12; // @Filename: main.ts -////import { [|{| "isDefinition": true |}x|] } from "./m"; -////const y = [|{| "isDefinition": false |}x|]; +////import { [|{| "isWriteAccess": true, "isDefinition": true |}x|] } from "./m"; +////const y = [|x|]; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("var x: number"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts index 357ef088d61..4c91bc08ef8 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts @@ -1,6 +1,6 @@ /// -////function [|{| "isDefinition": true |}func|](x: number) { +////function [|{| "isWriteAccess": true, "isDefinition": true |}func|](x: number) { ////} -////[|{| "isDefinition": false |}func|](x) +////[|func|](x) -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("function func(x: number): void"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts index b7117995d84..826890c4da9 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts @@ -1,7 +1,7 @@ /// -////interface [|{| "isDefinition": true |}I|] { +////interface [|{| "isWriteAccess": true, "isDefinition": true |}I|] { //// p: number; ////} -////let i: [|{| "isDefinition": false |}I|] = { p: 12 }; +////let i: [|I|] = { p: 12 }; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("interface I"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts index b0506490c70..0e949ca6496 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts @@ -1,16 +1,19 @@ /// -////interface [|{| "isDefinition": true |}Numbers|] { +////interface [|{| "isWriteAccess": true, "isDefinition": true |}Numbers|] { //// p: number; ////} -////interface [|{| "isDefinition": true |}Numbers|] { +////interface [|{| "isWriteAccess": true, "isDefinition": true |}Numbers|] { //// m: number; ////} -////class [|{| "isDefinition": true |}Numbers|] { +////class [|{| "isWriteAccess": true, "isDefinition": true |}Numbers|] { //// f(n: number) { //// return this.p + this.m + n; //// } ////} -////let i: [|{| "isDefinition": false |}Numbers|] = new [|{| "isDefinition": false |}Numbers|](); +////let i: [|Numbers|] = new [|Numbers|](); ////let x = i.f(i.p + i.m); -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2, r3, r4] = ranges; +verify.referenceGroups([r0, r1, r2, r3], [{ definition: "class Numbers\ninterface Numbers", ranges }]); +verify.referenceGroups(r4, [{ definition: "constructor Numbers(): Numbers", ranges }]); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts index ff1cf00fa9b..04d00e6c19f 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts @@ -1,7 +1,7 @@ /// -////namespace [|{| "isDefinition": true |}Numbers|] { +////namespace [|{| "isWriteAccess": true, "isDefinition": true |}Numbers|] { //// export var n = 12; ////} -////let x = [|{| "isDefinition": false |}Numbers|].n + 1; +////let x = [|Numbers|].n + 1; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("namespace Numbers"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts index a041dab435a..c603f398e5e 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts @@ -1,5 +1,11 @@ /// ////let o = { [|{| "isDefinition": true |}1|]: 12 }; -////let y = o[[|{| "isDefinition": false |}1|]]; +////let y = o[[|1|]]; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [{ definition: "(property) 1: number", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(property) 1: number", ranges: [r0] }, + { definition: "(property) 1: number", ranges: [r1] } +]); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts index cdcc47014fd..8afa67bfe64 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts @@ -1,6 +1,6 @@ /// -////function f([|{| "isDefinition": true |}x|]: number) { -//// return [|{| "isDefinition": false |}x|] + 1 +////function f([|{| "isWriteAccess": true, "isDefinition": true |}x|]: number) { +//// return [|x|] + 1 ////} -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(parameter) x: number"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts index 383cf49a2e3..43fe0c571fc 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts @@ -1,5 +1,11 @@ /// ////let o = { "[|{| "isDefinition": true |}x|]": 12 }; -////let y = o.[|{| "isDefinition": false |}x|]; +////let y = o.[|x|]; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [{ definition: '(property) "x": number', ranges }]); +verify.referenceGroups(r1, [ + { definition: '(property) "x": number', ranges: [r0] }, + { definition: '(property) "x": number', ranges: [r1] }, +]); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts index 2bd66830c69..18a4ec0396c 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts @@ -1,5 +1,5 @@ /// -////type [|{| "isDefinition": true |}Alias|]= number; -////let n: [|{| "isDefinition": false |}Alias|] = 12; +////type [|{| "isWriteAccess": true, "isDefinition": true |}Alias|]= number; +////let n: [|Alias|] = 12; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("type Alias = number"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts index 78529186ad3..2faf5b53e1b 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts @@ -1,20 +1,20 @@ /// -////var [|{| "isDefinition": true |}x|] = 0; -////var assignmentRightHandSide = [|{| "isDefinition": false |}x|]; -////var assignmentRightHandSide2 = 1 + [|{| "isDefinition": false |}x|]; +////var [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 0; +////var assignmentRightHandSide = [|x|]; +////var assignmentRightHandSide2 = 1 + [|x|]; //// -////[|{| "isDefinition": false |}x|] = 1; -////[|{| "isDefinition": false |}x|] = [|{| "isDefinition": false |}x|] + [|{| "isDefinition": false |}x|]; +////[|{| "isWriteAccess": true |}x|] = 1; +////[|{| "isWriteAccess": true |}x|] = [|x|] + [|x|]; //// -////[|{| "isDefinition": false |}x|] == 1; -////[|{| "isDefinition": false |}x|] <= 1; +////[|x|] == 1; +////[|x|] <= 1; //// -////var preIncrement = ++[|{| "isDefinition": false |}x|]; -////var postIncrement = [|{| "isDefinition": false |}x|]++; -////var preDecrement = --[|{| "isDefinition": false |}x|]; -////var postDecrement = [|{| "isDefinition": false |}x|]--; +////var preIncrement = ++[|{| "isWriteAccess": true |}x|]; +////var postIncrement = [|{| "isWriteAccess": true |}x|]++; +////var preDecrement = --[|{| "isWriteAccess": true |}x|]; +////var postDecrement = [|{| "isWriteAccess": true |}x|]--; //// -////[|{| "isDefinition": false |}x|] += 1; -////[|{| "isDefinition": false |}x|] <<= 1; +////[|{| "isWriteAccess": true |}x|] += 1; +////[|{| "isWriteAccess": true |}x|] <<= 1; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("var x: number"); diff --git a/tests/cases/fourslash/hoverOverComment.ts b/tests/cases/fourslash/hoverOverComment.ts index 653eaedfcb7..fd1a7fcd9de 100644 --- a/tests/cases/fourslash/hoverOverComment.ts +++ b/tests/cases/fourslash/hoverOverComment.ts @@ -7,4 +7,4 @@ goTo.marker(); verify.quickInfoIs(""); verify.goToDefinitionIs([]); -verify.referencesAre([]); +verify.noReferences(); diff --git a/tests/cases/fourslash/localGetReferences.ts b/tests/cases/fourslash/localGetReferences.ts index d8e64be1ada..4648471648a 100644 --- a/tests/cases/fourslash/localGetReferences.ts +++ b/tests/cases/fourslash/localGetReferences.ts @@ -3,17 +3,17 @@ // @Filename: localGetReferences_1.ts ////// Comment Refence Test: g/*1*/lobalVar ////// References to a variable declared in global. -////var [|globalVar|]: number = 2; +////var [|{| "isWriteAccess": true, "isDefinition": true |}globalVar|]: number = 2; //// ////class fooCls { //// // References to static variable declared in a class. -//// static [|clsSVar|] = 1; +//// static [|{| "isWriteAccess": true, "isDefinition": true |}clsSVar|] = 1; //// // References to a variable declared in a class. -//// [|clsVar|] = 1; +//// [|{| "isWriteAccess": true, "isDefinition": true |}clsVar|] = 1; //// -//// constructor (public [|clsParam|]: number) { +//// constructor (public [|{| "isWriteAccess": true, "isDefinition": true |}clsParam|]: number) { //// //Increments -//// [|globalVar|]++; +//// [|{| "isWriteAccess": true |}globalVar|]++; //// this.[|clsVar|]++; //// fooCls.[|clsSVar|]++; //// // References to a class parameter. @@ -23,18 +23,18 @@ ////} //// ////// References to a function parameter. -////function [|foo|]([|x|]: number) { +////function [|{| "isWriteAccess": true, "isDefinition": true |}foo|]([|{| "isWriteAccess": true, "isDefinition": true |}x|]: number) { //// // References to a variable declared in a function. -//// var [|fnVar|] = 1; +//// var [|{| "isWriteAccess": true, "isDefinition": true |}fnVar|] = 1; //// //// //Increments //// fooCls.[|clsSVar|]++; -//// [|globalVar|]++; +//// [|{| "isWriteAccess": true |}globalVar|]++; //// modTest.modVar++; -//// [|fnVar|]++; +//// [|{| "isWriteAccess": true |}fnVar|]++; //// //// //Return -//// return [|x|]++; +//// return [|{| "isWriteAccess": true |}x|]++; ////} //// ////module modTest { @@ -42,7 +42,7 @@ //// export var modVar:number; //// //// //Increments -//// [|globalVar|]++; +//// [|{| "isWriteAccess": true |}globalVar|]++; //// fooCls.[|clsSVar|]++; //// modVar++; //// @@ -54,7 +54,7 @@ //// static boo = [|foo|]; //// //// //Increments -//// [|globalVar|]++; +//// [|{| "isWriteAccess": true |}globalVar|]++; //// fooCls.[|clsSVar|]++; //// modVar++; //// } @@ -76,18 +76,18 @@ //////Increments ////fooCls.[|clsSVar|]++; ////modTest.modVar++; -////[|globalVar|] = [|globalVar|] + [|globalVar|]; +////[|{| "isWriteAccess": true |}globalVar|] = [|globalVar|] + [|globalVar|]; //// //////ETC - Other cases -////[|globalVar|] = 3; +////[|{| "isWriteAccess": true |}globalVar|] = 3; ////// References to illegal assignment. -////[|foo|] = [|foo|] + 1; +////[|{| "isWriteAccess": true |}foo|] = [|foo|] + 1; /////*3*/err = err++; /////*4*/ //////Shadowed fn Parameter -////function shdw([|{| "shadow": true |}globalVar|]: number) { +////function shdw([|{| "isWriteAccess": true, "isDefinition": true, "shadow": true |}globalVar|]: number) { //// //Increments -//// [|{| "shadow": true |}globalVar|]++; +//// [|{| "isWriteAccess": true, "shadow": true |}globalVar|]++; //// return [|{| "shadow": true |}globalVar|]; ////} //// @@ -117,7 +117,7 @@ ////array.forEach( //// //// -////function([|str|]) { +////function([|{| "isWriteAccess": true, "isDefinition": true |}str|]) { //// //// //// @@ -187,24 +187,36 @@ // References to comment. goTo.marker("1"); -verify.referencesAre([]); +verify.noReferences(); // References to unresolved symbol. goTo.marker("3"); -verify.referencesAre([]); +verify.noReferences(); // References to no context. goTo.marker("4"); -verify.referencesAre([]); +verify.noReferences(); -const rangesByText = test.rangesByText(); -rangesByText.forEach((ranges, text) => { +test.rangesByText().forEach((ranges, text) => { if (text === "globalVar") { - verify.rangesReferenceEachOther(ranges.filter(isShadow)); - verify.rangesReferenceEachOther(ranges.filter(r => !isShadow(r))); - } else { - verify.rangesReferenceEachOther(ranges); + verify.singleReferenceGroup("(parameter) globalVar: number", ranges.filter(isShadow)); + verify.singleReferenceGroup("var globalVar: number", ranges.filter(r => !isShadow(r))); + return; } + + const definition = (() => { + switch (text) { + case "fnVar": return "(local var) fnVar: number"; + case "clsSVar": return "(property) fooCls.clsSVar: number"; + case "clsVar": return "(property) fooCls.clsVar: number"; + case "clsParam": return "(property) fooCls.clsParam: number"; + case "foo": return "function foo(x: number): number"; + case "x": return "(parameter) x: number"; + case "str": return "(parameter) str: string"; + default: throw new Error(text); + } + })(); + verify.singleReferenceGroup(definition, ranges); }); function isShadow(r) { diff --git a/tests/cases/fourslash/quickInfoForRequire.ts b/tests/cases/fourslash/quickInfoForRequire.ts index 26b0371fe0e..e97810401f4 100644 --- a/tests/cases/fourslash/quickInfoForRequire.ts +++ b/tests/cases/fourslash/quickInfoForRequire.ts @@ -6,5 +6,6 @@ //@Filename: quickInfoForRequire_input.ts ////import a = require("./AA/B/*1*/B"); -verify.quickInfoAt("1", "module a"); -verify.referencesAre([]); \ No newline at end of file +goTo.marker("1"); +verify.quickInfoIs("module a"); +verify.noReferences(); diff --git a/tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts b/tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts index 68a9f73b1d6..79bf6172863 100644 --- a/tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts +++ b/tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts @@ -2,19 +2,26 @@ // @Filename: file1.ts //// class Foo { -//// constructor(private [|privateParam|]: number, -//// public [|publicParam|]: string, -//// protected [|protectedParam|]: boolean) { -//// +//// constructor(private [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}privateParam|]: number, +//// public [|{| "isWriteAccess": true, "isDefinition": true, "type": "string" |}publicParam|]: string, +//// protected [|{| "isWriteAccess": true, "isDefinition": true, "type": "boolean" |}protectedParam|]: boolean) { +//// //// let localPrivate = [|privateParam|]; //// this.[|privateParam|] += 10; -//// +//// //// let localPublic = [|publicParam|]; //// this.[|publicParam|] += " Hello!"; -//// +//// //// let localProtected = [|protectedParam|]; //// this.[|protectedParam|] = false; //// } //// } -verify.rangesWithSameTextReferenceEachOther(); +test.rangesByText().forEach((ranges, text) => { + const [r0, r1, r2] = ranges; + const type = r0.marker.data.type; + verify.referenceGroups(ranges, [ + { definition: `(property) Foo.${text}: ${type}`, ranges: [r0, r2] }, + { definition: `(parameter) ${text}: ${type}`, ranges: [r1] } + ]); +}); diff --git a/tests/cases/fourslash/referenceToClass.ts b/tests/cases/fourslash/referenceToClass.ts index 3e523487bd1..d6d2171507c 100644 --- a/tests/cases/fourslash/referenceToClass.ts +++ b/tests/cases/fourslash/referenceToClass.ts @@ -3,7 +3,7 @@ // Class references should work across file and not find local variables. // @Filename: referenceToClass_1.ts -////class [|foo|] { +////class [|{| "isWriteAccess": true, "isDefinition": true |}foo|] { //// public n: [|foo|]; //// public foo: number; ////} @@ -20,4 +20,7 @@ // @Filename: referenceToClass_2.ts ////var k: [|foo|]; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2, r3, r4, r5] = ranges; +verify.referenceGroups([r0, r1, r2, r4, r5], [{ definition: "class foo", ranges }]); +verify.referenceGroups(r3, [{ definition: "constructor foo(): foo", ranges }]); diff --git a/tests/cases/fourslash/referencesBloomFilters.ts b/tests/cases/fourslash/referencesBloomFilters.ts index 7d99ccdfd3c..c9f290db0db 100644 --- a/tests/cases/fourslash/referencesBloomFilters.ts +++ b/tests/cases/fourslash/referencesBloomFilters.ts @@ -3,7 +3,7 @@ // Ensure BloomFilter building logic is correct, by having one reference per file // @Filename: declaration.ts -////var container = { [|searchProp|] : 1 }; +////var container = { [|{| "isWriteAccess": true, "isDefinition": true |}searchProp|] : 1 }; // @Filename: expression.ts ////function blah() { return (1 + 2 + container.[|searchProp|]()) === 2; }; @@ -12,6 +12,16 @@ ////function blah2() { container["[|searchProp|]"] }; // @Filename: redeclaration.ts -////container = { "[|searchProp|]" : 18 }; +////container = { "[|{| "isDefinition": true |}searchProp|]" : 18 }; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2, r3] = ranges; +verify.referenceGroups(r0, [{ definition: "(property) searchProp: number", ranges }]); +verify.referenceGroups([r1, r2], [ + { definition: "(property) searchProp: number", ranges: [r0, r3] }, + { definition: "(property) searchProp: number", ranges: [r1, r2] } +]); +verify.referenceGroups(r3, [ + { definition: "(property) searchProp: number", ranges: [r0, r1, r2] }, + { definition: '(property) "searchProp": number', ranges: [r3] } +]); diff --git a/tests/cases/fourslash/referencesBloomFilters2.ts b/tests/cases/fourslash/referencesBloomFilters2.ts index c42e5d4eaf1..daf60d0dd01 100644 --- a/tests/cases/fourslash/referencesBloomFilters2.ts +++ b/tests/cases/fourslash/referencesBloomFilters2.ts @@ -3,7 +3,7 @@ // Ensure BloomFilter building logic is correct, by having one reference per file // @Filename: declaration.ts -////var container = { [|42|]: 1 }; +////var container = { [|{| "isDefinition": true |}42|]: 1 }; // @Filename: expression.ts ////function blah() { return (container[[|42|]]) === 2; }; @@ -12,6 +12,16 @@ ////function blah2() { container["[|42|]"] }; // @Filename: redeclaration.ts -////container = { "[|42|]" : 18 }; +////container = { "[|{| "isDefinition": true |}42|]" : 18 }; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2, r3] = ranges; +verify.referenceGroups(r0, [{ definition: "(property) 42: number", ranges }]); +verify.referenceGroups([r1, r2], [ + { definition: "(property) 42: number", ranges: [r0, r3] }, + { definition: "(property) 42: number", ranges: [r1, r2] } +]); +verify.referenceGroups(r3, [ + { definition: "(property) 42: number", ranges: [r0, r1, r2] }, + { definition: '(property) "42": number', ranges: [r3] } +]); diff --git a/tests/cases/fourslash/referencesBloomFilters3.ts b/tests/cases/fourslash/referencesBloomFilters3.ts index 9703baceb12..0dd5c645264 100644 --- a/tests/cases/fourslash/referencesBloomFilters3.ts +++ b/tests/cases/fourslash/referencesBloomFilters3.ts @@ -4,9 +4,9 @@ // @Filename: declaration.ts -////enum Test { "[|42|]" = 1 }; +////enum Test { "[|{| "isDefinition": true |}42|]" = 1 }; // @Filename: expression.ts ////(Test[[|42|]]); -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup('(enum member) Test["42"] = 1'); diff --git a/tests/cases/fourslash/referencesForAmbients.ts b/tests/cases/fourslash/referencesForAmbients.ts index da3f3f43aae..58e4d6e59a5 100644 --- a/tests/cases/fourslash/referencesForAmbients.ts +++ b/tests/cases/fourslash/referencesForAmbients.ts @@ -1,11 +1,11 @@ /// -////declare module "[|foo|]" { -//// var [|f|]: number; +////declare module "[|{| "isDefinition": true |}foo|]" { +//// var [|{| "isWriteAccess": true, "isDefinition": true |}f|]: number; ////} //// -////declare module "[|bar|]" { -//// export import [|foo|] = require("[|foo|]"); +////declare module "[|{| "isDefinition": true |}bar|]" { +//// export import [|{| "isWriteAccess": true, "isDefinition": true |}foo|] = require("[|foo|]"); //// var f2: typeof [|foo|].[|f|]; ////} //// @@ -15,7 +15,7 @@ ////} const [moduleFoo0, f0, moduleBar0, foo0, moduleFoo1, foo1, f1, moduleBar1, foo2] = test.ranges(); -verify.rangesReferenceEachOther([moduleFoo0, moduleFoo1]); -verify.rangesReferenceEachOther([moduleBar0, moduleBar1]); -verify.rangesReferenceEachOther([foo0, foo1, foo2]); -verify.rangesReferenceEachOther([f0, f1]); +verify.singleReferenceGroup('module "foo"', [moduleFoo0, moduleFoo1]); +verify.singleReferenceGroup('module "bar"', [moduleBar0, moduleBar1]); +verify.singleReferenceGroup('import foo = require("foo")', [foo0, foo1, foo2]); +verify.singleReferenceGroup("var f: number", [f0, f1]); diff --git a/tests/cases/fourslash/referencesForClassLocal.ts b/tests/cases/fourslash/referencesForClassLocal.ts index bdde0e7f126..4108c060a39 100644 --- a/tests/cases/fourslash/referencesForClassLocal.ts +++ b/tests/cases/fourslash/referencesForClassLocal.ts @@ -5,7 +5,7 @@ ////var n = 14; //// ////class foo { -//// private [|n|] = 0; +//// private [|{| "isWriteAccess": true, "isDefinition": true |}n|] = 0; //// //// public bar() { //// this.[|n|] = 9; @@ -20,4 +20,4 @@ //// } ////} -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(property) foo.n: number"); diff --git a/tests/cases/fourslash/referencesForClassMembers.ts b/tests/cases/fourslash/referencesForClassMembers.ts index 0208b13589d..0db4ebb0873 100644 --- a/tests/cases/fourslash/referencesForClassMembers.ts +++ b/tests/cases/fourslash/referencesForClassMembers.ts @@ -1,16 +1,36 @@ /// ////class Base { -//// [|a|]: number; -//// [|method|](): void { } +//// [|{| "isWriteAccess": true, "isDefinition": true |}a|]: number; +//// [|{| "isWriteAccess": true, "isDefinition": true |}method|](): void { } ////} ////class MyClass extends Base { -//// [|a|]; -//// [|method|]() { } +//// [|{| "isWriteAccess": true, "isDefinition": true |}a|]; +//// [|{| "isWriteAccess": true, "isDefinition": true |}method|]() { } ////} //// ////var c: MyClass; ////c.[|a|]; ////c.[|method|](); -verify.rangesWithSameTextReferenceEachOther(); +const ranges = test.rangesByText(); +const properties = ranges.get("a"); +const [a0, a1, a2] = properties; +verify.referenceGroups(a0, [{ definition: "(property) Base.a: number", ranges: properties }]); +verify.referenceGroups([a1, a2], [ + { definition: "(property) Base.a: number", ranges: [a0] }, + { definition: "(property) MyClass.a: any", ranges: [a1, a2] } +]); + +const methods = ranges.get("method"); +const [m0, m1, m2] = methods; +verify.referenceGroups(m0, [{ definition: "(method) Base.method(): void", ranges: methods }]); +verify.referenceGroups(m1, [ + { definition: "(method) Base.method(): void", ranges: [m0] }, + { definition: "(method) MyClass.method(): void", ranges: [m1, m2] } +]); +verify.referenceGroups(m2, [ + { definition: "(method) Base.method(): void", ranges: [m0] }, + { definition: "(method) MyClass.method(): void", ranges: [m1] }, + { definition: "(method) MyClass.method(): void", ranges: [m2] } +]); diff --git a/tests/cases/fourslash/referencesForClassMembersExtendingAbstractClass.ts b/tests/cases/fourslash/referencesForClassMembersExtendingAbstractClass.ts index 46115f9da17..b5be77a73bb 100644 --- a/tests/cases/fourslash/referencesForClassMembersExtendingAbstractClass.ts +++ b/tests/cases/fourslash/referencesForClassMembersExtendingAbstractClass.ts @@ -1,16 +1,36 @@ /// ////abstract class Base { -//// abstract [|a|]: number; -//// abstract [|method|](): void; +//// abstract [|{| "isWriteAccess": true, "isDefinition": true |}a|]: number; +//// abstract [|{| "isWriteAccess": true, "isDefinition": true |}method|](): void; ////} ////class MyClass extends Base { -//// [|a|]; -//// [|method|]() { } +//// [|{| "isWriteAccess": true, "isDefinition": true |}a|]; +//// [|{| "isWriteAccess": true, "isDefinition": true |}method|]() { } ////} //// ////var c: MyClass; ////c.[|a|]; ////c.[|method|](); -verify.rangesWithSameTextReferenceEachOther(); +const ranges = test.rangesByText(); +const properties = ranges.get("a"); +const [a0, a1, a2] = properties; +verify.referenceGroups(a0, [{ definition: "(property) Base.a: number", ranges: properties }]); +verify.referenceGroups([a1, a2], [ + { definition: "(property) Base.a: number", ranges: [a0] }, + { definition: "(property) MyClass.a: any", ranges: [a1, a2] } +]); + +const methods = ranges.get("method"); +const [m0, m1, m2] = methods; +verify.referenceGroups(m0, [{ definition: "(method) Base.method(): void", ranges: methods }]); +verify.referenceGroups(m1, [ + { definition: "(method) Base.method(): void", ranges: [m0] }, + { definition: "(method) MyClass.method(): void", ranges: [m1, m2] } +]); +verify.referenceGroups(m2, [ + { definition: "(method) Base.method(): void", ranges: [m0] }, + { definition: "(method) MyClass.method(): void", ranges: [m1] }, + { definition: "(method) MyClass.method(): void", ranges: [m2] } +]); diff --git a/tests/cases/fourslash/referencesForClassMembersExtendingGenericClass.ts b/tests/cases/fourslash/referencesForClassMembersExtendingGenericClass.ts index 2b701f25cc1..3e453663f63 100644 --- a/tests/cases/fourslash/referencesForClassMembersExtendingGenericClass.ts +++ b/tests/cases/fourslash/referencesForClassMembersExtendingGenericClass.ts @@ -1,16 +1,36 @@ /// ////class Base { -//// [|a|]: this; -//// [|method|](a?:T, b?:U): this { } +//// [|{| "isWriteAccess": true, "isDefinition": true |}a|]: this; +//// [|{| "isWriteAccess": true, "isDefinition": true |}method|](a?:T, b?:U): this { } ////} ////class MyClass extends Base { -//// [|a|]; -//// [|method|]() { } +//// [|{| "isWriteAccess": true, "isDefinition": true |}a|]; +//// [|{| "isWriteAccess": true, "isDefinition": true |}method|]() { } ////} //// ////var c: MyClass; ////c.[|a|]; ////c.[|method|](); -verify.rangesWithSameTextReferenceEachOther(); +const ranges = test.rangesByText(); +const properties = ranges.get("a"); +const [a0, a1, a2] = properties; +verify.referenceGroups(a0, [{ definition: "(property) Base.a: this", ranges: properties }]); +verify.referenceGroups([a1, a2], [ + { definition: "(property) Base.a: this", ranges: [a0] }, + { definition: "(property) MyClass.a: any", ranges: [a1, a2] } +]); + +const methods = ranges.get("method"); +const [m0, m1, m2] = methods; +verify.referenceGroups(m0, [{ definition: "(method) Base.method(a?: T, b?: U): this", ranges: methods }]); +verify.referenceGroups(m1, [ + { definition: "(method) Base.method(): void", ranges: [m0] }, + { definition: "(method) MyClass.method(): void", ranges: [m1, m2] } +]); +verify.referenceGroups(m2, [ + { definition: "(method) Base.method(a?: T, b?: U): this", ranges: [m0] }, + { definition: "(method) MyClass.method(): void", ranges: [m1] }, + { definition: "(method) MyClass.method(): void", ranges: [m2] } +]); diff --git a/tests/cases/fourslash/referencesForClassParameter.ts b/tests/cases/fourslash/referencesForClassParameter.ts index ce383b36503..e1a33dc5ac4 100644 --- a/tests/cases/fourslash/referencesForClassParameter.ts +++ b/tests/cases/fourslash/referencesForClassParameter.ts @@ -7,7 +7,7 @@ ////class p { } //// ////class foo { -//// constructor (public [|p|]: any) { +//// constructor (public [|{| "isWriteAccess": true, "isDefinition": true |}p|]: any) { //// } //// //// public f(p) { @@ -19,4 +19,10 @@ ////var n = new foo(undefined); ////n.[|p|] = null; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2] = ranges; +verify.referenceGroups([r0, r1], [{ definition: "(property) foo.p: any", ranges }]); +verify.referenceGroups(r2, [ + { definition: "(property) foo.p: any", ranges: [r0, r1] }, + { definition: "(property) foo.p: any", ranges: [r2] } +]); diff --git a/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts b/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts index 65bd7eebfb5..7d6bc05cf30 100644 --- a/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts +++ b/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts @@ -1,28 +1,36 @@ /// -////interface IFoo { [|xy|]: number; } +////interface IFoo { [|{| "isWriteAccess": true, "isDefinition": true |}xy|]: number; } //// ////// Assignment -////var a1: IFoo = { [|xy|]: 0 }; -////var a2: IFoo = { [|xy|]: 0 }; +////var a1: IFoo = { [|{| "isWriteAccess": true, "isDefinition": true |}xy|]: 0 }; +////var a2: IFoo = { [|{| "isWriteAccess": true, "isDefinition": true |}xy|]: 0 }; //// ////// Function call ////function consumer(f: IFoo) { } -////consumer({ [|xy|]: 1 }); +////consumer({ [|{| "isWriteAccess": true, "isDefinition": true |}xy|]: 1 }); //// -////// Type cast -////var c = { [|xy|]: 0 }; +////// Type cast +////var c = { [|{| "isWriteAccess": true, "isDefinition": true |}xy|]: 0 }; //// ////// Array literal -////var ar: IFoo[] = [{ [|xy|]: 1 }, { [|xy|]: 2 }]; +////var ar: IFoo[] = [{ [|{| "isWriteAccess": true, "isDefinition": true |}xy|]: 1 }, { [|{| "isWriteAccess": true, "isDefinition": true |}xy|]: 2 }]; //// ////// Nested object literal -////var ob: { ifoo: IFoo } = { ifoo: { [|xy|]: 0 } }; +////var ob: { ifoo: IFoo } = { ifoo: { [|{| "isWriteAccess": true, "isDefinition": true |}xy|]: 0 } }; //// ////// Widened type -////var w: IFoo = { [|xy|]: undefined }; +////var w: IFoo = { [|{| "isWriteAccess": true, "isDefinition": true, "type": "undefined" |}xy|]: undefined }; //// ////// Untped -- should not be included ////var u = { xy: 0 }; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +verify.referenceGroups(ranges[0], [{ definition: "(property) IFoo.xy: number", ranges }]); +for (const range of ranges.slice(1)) { + const type = range.marker.data.type || "number"; + verify.referenceGroups(range, [ + { definition: "(property) IFoo.xy: number", ranges: ranges.filter(r => r !== range) }, + { definition: `(property) xy: ${type}`, ranges: [range] } + ]); +} diff --git a/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts index c0e4a5f90ea..d79d4097ee7 100644 --- a/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts +++ b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts @@ -2,33 +2,33 @@ ////interface A { //// a: number; -//// [|common|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}common|]: string; ////} //// ////interface B { //// b: number; -//// [|common|]: number; +//// [|{| "isWriteAccess": true, "isDefinition": true |}common|]: number; ////} //// ////// Assignment -////var v1: A | B = { a: 0, [|common|]: "" }; -////var v2: A | B = { b: 0, [|common|]: 3 }; +////var v1: A | B = { a: 0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "string" |}common|]: "" }; +////var v2: A | B = { b: 0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}common|]: 3 }; //// ////// Function call ////function consumer(f: A | B) { } -////consumer({ a: 0, b: 0, [|common|]: 1 }); +////consumer({ a: 0, b: 0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}common|]: 1 }); //// -////// Type cast -////var c = { [|common|]: 0, b: 0 }; +////// Type cast +////var c = { [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}common|]: 0, b: 0 }; //// ////// Array literal -////var ar: Array = [{ a: 0, [|common|]: "" }, { b: 0, [|common|]: 0 }]; +////var ar: Array = [{ a: 0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "string" |}common|]: "" }, { b: 0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}common|]: 0 }]; //// ////// Nested object literal -////var ob: { aorb: A|B } = { aorb: { b: 0, [|common|]: 0 } }; +////var ob: { aorb: A|B } = { aorb: { b: 0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}common|]: 0 } }; //// ////// Widened type -////var w: A|B = { a:0, [|common|]: undefined }; +////var w: A|B = { a:0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "undefined" |}common|]: undefined }; //// ////// Untped -- should not be included ////var u1 = { a: 0, b: 0, common: "" }; @@ -36,8 +36,14 @@ const all = test.ranges(); const [aCommon, bCommon, ...unionRefs] = all; -verify.referencesOf(aCommon, [aCommon, ...unionRefs]); -verify.referencesOf(bCommon, [bCommon, ...unionRefs]); -for (const ref of unionRefs) { - verify.referencesOf(ref, all); -} +verify.referenceGroups(aCommon, [{ definition: "(property) A.common: string", ranges: [aCommon, ...unionRefs] }]); +verify.referenceGroups(bCommon, [{ definition: "(property) B.common: number", ranges: [bCommon, ...unionRefs] }]); + +unionRefs.forEach((unionRef, idx) => { + const type = unionRef.marker.data.type; + verify.referenceGroups(unionRef, [ + { definition: "(property) A.common: string", ranges: all.filter(x => x !== bCommon && x !== unionRef) }, + { definition: "(property) B.common: number", ranges: [bCommon] }, + { definition: `(property) common: ${type}`, ranges: [unionRef] } + ]); +}); diff --git a/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts index de9ffbfd3be..2c48e353b03 100644 --- a/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts +++ b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts @@ -6,32 +6,40 @@ ////} //// ////interface B { -//// [|b|]: number; +//// [|{| "isWriteAccess": true, "isDefinition": true |}b|]: number; //// common: number; ////} //// ////// Assignment ////var v1: A | B = { a: 0, common: "" }; -////var v2: A | B = { [|b|]: 0, common: 3 }; +////var v2: A | B = { [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}b|]: 0, common: 3 }; //// ////// Function call ////function consumer(f: A | B) { } -////consumer({ a: 0, [|b|]: 0, common: 1 }); +////consumer({ a: 0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}b|]: 0, common: 1 }); //// -////// Type cast -////var c = { common: 0, [|b|]: 0 }; +////// Type cast +////var c = { common: 0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}b|]: 0 }; //// ////// Array literal -////var ar: Array = [{ a: 0, common: "" }, { [|b|]: 0, common: 0 }]; +////var ar: Array = [{ a: 0, common: "" }, { [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}b|]: 0, common: 0 }]; //// ////// Nested object literal -////var ob: { aorb: A|B } = { aorb: { [|b|]: 0, common: 0 } }; +////var ob: { aorb: A|B } = { aorb: { [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}b|]: 0, common: 0 } }; //// ////// Widened type -////var w: A|B = { [|b|]:undefined, common: undefined }; +////var w: A|B = { [|{| "isWriteAccess": true, "isDefinition": true, "type": "undefined" |}b|]:undefined, common: undefined }; //// ////// Untped -- should not be included ////var u1 = { a: 0, b: 0, common: "" }; ////var u2 = { b: 0, common: 0 }; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +verify.referenceGroups(ranges[0], [{ definition: "(property) B.b: number", ranges }]); +for (const reference of ranges.slice(1)) { + const type = reference.marker.data.type; + verify.referenceGroups(reference, [ + { definition: "(property) B.b: number", ranges: ranges.filter(r => r !== reference) }, + { definition: `(property) b: ${type}`, ranges: [reference] } + ]); +} diff --git a/tests/cases/fourslash/referencesForEnums.ts b/tests/cases/fourslash/referencesForEnums.ts index 3b979bc5096..68face36d04 100644 --- a/tests/cases/fourslash/referencesForEnums.ts +++ b/tests/cases/fourslash/referencesForEnums.ts @@ -1,9 +1,9 @@ /// ////enum E { -//// [|value1|] = 1, -//// "[|value2|]" = [|value1|], -//// [|111|] = 11 +//// [|{| "isWriteAccess": true, "isDefinition": true |}value1|] = 1, +//// "[|{| "isDefinition": true |}value2|]" = [|value1|], +//// [|{| "isDefinition": true |}111|] = 11 ////} //// ////E.[|value1|]; @@ -11,4 +11,7 @@ ////E.[|value2|]; ////E[[|111|]]; -verify.rangesWithSameTextReferenceEachOther(); +const r = test.rangesByText(); +verify.singleReferenceGroup("(enum member) E.value1 = 1", r.get("value1")); +verify.singleReferenceGroup("(enum member) E[\"value2\"] = 1", r.get("value2")); +verify.singleReferenceGroup("(enum member) E[111] = 11", r.get("111")); diff --git a/tests/cases/fourslash/referencesForExportedValues.ts b/tests/cases/fourslash/referencesForExportedValues.ts index 315d0b1b585..ff00f844260 100644 --- a/tests/cases/fourslash/referencesForExportedValues.ts +++ b/tests/cases/fourslash/referencesForExportedValues.ts @@ -1,7 +1,7 @@ /// ////module M { -//// export var [|variable|] = 0; +//// export var [|{| "isWriteAccess": true, "isDefinition": true |}variable|] = 0; //// //// // local use //// var x = [|variable|]; @@ -10,4 +10,4 @@ ////// external use ////M.[|variable|] -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("var M.variable: number"); diff --git a/tests/cases/fourslash/referencesForExternalModuleNames.ts b/tests/cases/fourslash/referencesForExternalModuleNames.ts index ee783c8bd7e..5e01eae3530 100644 --- a/tests/cases/fourslash/referencesForExternalModuleNames.ts +++ b/tests/cases/fourslash/referencesForExternalModuleNames.ts @@ -3,7 +3,7 @@ // Global interface reference. // @Filename: referencesForGlobals_1.ts -////declare module "[|foo|]" { +////declare module "[|{| "isDefinition": true |}foo|]" { //// var f: number; ////} @@ -11,4 +11,7 @@ // @Filename: referencesForGlobals_2.ts ////import f = require("[|foo|]"); -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [{ definition: 'module "foo"', ranges }]); +verify.referenceGroups(r1, [{ definition: 'module f', ranges }]); diff --git a/tests/cases/fourslash/referencesForFunctionOverloads.ts b/tests/cases/fourslash/referencesForFunctionOverloads.ts index d6873643cd4..7afa5a20133 100644 --- a/tests/cases/fourslash/referencesForFunctionOverloads.ts +++ b/tests/cases/fourslash/referencesForFunctionOverloads.ts @@ -2,9 +2,9 @@ // Function overloads should be highlighted together. -////function [|foo|](x: string); -////function [|foo|](x: string, y: number) { +////function [|{| "isWriteAccess": true, "isDefinition": true |}foo|](x: string); +////function [|{| "isWriteAccess": true, "isDefinition": true |}foo|](x: string, y: number) { //// [|foo|]('', 43); ////} -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("function foo(x: string): any"); diff --git a/tests/cases/fourslash/referencesForFunctionParameter.ts b/tests/cases/fourslash/referencesForFunctionParameter.ts index 64d33ca9a60..24582a68e08 100644 --- a/tests/cases/fourslash/referencesForFunctionParameter.ts +++ b/tests/cases/fourslash/referencesForFunctionParameter.ts @@ -3,9 +3,9 @@ ////var x; ////var n; //// -////function n(x: number, [|n|]: number) { -//// [|n|] = 32; +////function n(x: number, [|{| "isWriteAccess": true, "isDefinition": true |}n|]: number) { +//// [|{| "isWriteAccess": true |}n|] = 32; //// x = [|n|]; ////} -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(parameter) n: number"); diff --git a/tests/cases/fourslash/referencesForGlobals.ts b/tests/cases/fourslash/referencesForGlobals.ts index f4d7c479767..dc5bc4deb6f 100644 --- a/tests/cases/fourslash/referencesForGlobals.ts +++ b/tests/cases/fourslash/referencesForGlobals.ts @@ -3,7 +3,7 @@ // Global variable reference. // @Filename: referencesForGlobals_1.ts -////var [|global|] = 2; +////var [|{| "isWriteAccess": true, "isDefinition": true |}global|] = 2; //// ////class foo { //// constructor (public global) { } @@ -25,4 +25,4 @@ // @Filename: referencesForGlobals_2.ts ////var m = [|global|]; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("var global: number"); diff --git a/tests/cases/fourslash/referencesForGlobals2.ts b/tests/cases/fourslash/referencesForGlobals2.ts index 7c6baf5bf67..e08be585c7a 100644 --- a/tests/cases/fourslash/referencesForGlobals2.ts +++ b/tests/cases/fourslash/referencesForGlobals2.ts @@ -3,11 +3,11 @@ // Global class reference. // @Filename: referencesForGlobals_1.ts -////class [|globalClass|] { +////class [|{| "isWriteAccess": true, "isDefinition": true |}globalClass|] { //// public f() { } ////} // @Filename: referencesForGlobals_2.ts ////var c = [|globalClass|](); -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("class globalClass"); diff --git a/tests/cases/fourslash/referencesForGlobals3.ts b/tests/cases/fourslash/referencesForGlobals3.ts index 67e209aaad3..38edddc8255 100644 --- a/tests/cases/fourslash/referencesForGlobals3.ts +++ b/tests/cases/fourslash/referencesForGlobals3.ts @@ -3,11 +3,11 @@ // Global interface reference. // @Filename: referencesForGlobals_1.ts -////interface [|globalInterface|] { +////interface [|{| "isWriteAccess": true, "isDefinition": true |}globalInterface|] { //// f(); ////} // @Filename: referencesForGlobals_2.ts ////var i: [|globalInterface|]; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("interface globalInterface"); diff --git a/tests/cases/fourslash/referencesForGlobals4.ts b/tests/cases/fourslash/referencesForGlobals4.ts index d7acfbd2df4..b8356461699 100644 --- a/tests/cases/fourslash/referencesForGlobals4.ts +++ b/tests/cases/fourslash/referencesForGlobals4.ts @@ -3,11 +3,11 @@ // Global module reference. // @Filename: referencesForGlobals_1.ts -////module [|globalModule|] { +////module [|{| "isWriteAccess": true, "isDefinition": true |}globalModule|] { //// export f() { }; ////} // @Filename: referencesForGlobals_2.ts ////var m = [|globalModule|]; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("namespace globalModule"); diff --git a/tests/cases/fourslash/referencesForGlobals5.ts b/tests/cases/fourslash/referencesForGlobals5.ts index 4db2410f638..d7dd9304746 100644 --- a/tests/cases/fourslash/referencesForGlobals5.ts +++ b/tests/cases/fourslash/referencesForGlobals5.ts @@ -7,9 +7,9 @@ //// export var x; ////} //// -////import [|globalAlias|] = globalModule; +////import [|{| "isWriteAccess": true, "isDefinition": true |}globalAlias|] = globalModule; // @Filename: referencesForGlobals_2.ts ////var m = [|globalAlias|]; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("import globalAlias = globalModule"); diff --git a/tests/cases/fourslash/referencesForGlobalsInExternalModule.ts b/tests/cases/fourslash/referencesForGlobalsInExternalModule.ts index c2f70420402..5047a2f12a4 100644 --- a/tests/cases/fourslash/referencesForGlobalsInExternalModule.ts +++ b/tests/cases/fourslash/referencesForGlobalsInExternalModule.ts @@ -2,20 +2,28 @@ // Global variable reference. -////var [|topLevelVar|] = 2; +////var [|{| "isWriteAccess": true, "isDefinition": true |}topLevelVar|] = 2; ////var topLevelVar2 = [|topLevelVar|]; //// -////class [|topLevelClass|] { } +////class [|{| "isWriteAccess": true, "isDefinition": true |}topLevelClass|] { } ////var c = new [|topLevelClass|](); //// -////interface [|topLevelInterface|] { } +////interface [|{| "isWriteAccess": true, "isDefinition": true |}topLevelInterface|] { } ////var i: [|topLevelInterface|]; //// -////module [|topLevelModule|] { +////module [|{| "isWriteAccess": true, "isDefinition": true |}topLevelModule|] { //// export var x; ////} ////var x = [|topLevelModule|].x; //// ////export = x; -verify.rangesWithSameTextReferenceEachOther(); +const ranges = test.rangesByText(); +verify.singleReferenceGroup("var topLevelVar: number", ranges.get("topLevelVar")); + +const topLevelClass = ranges.get("topLevelClass"); +verify.referenceGroups(topLevelClass[0], [{ definition: "class topLevelClass", ranges: topLevelClass }]); +verify.referenceGroups(topLevelClass[1], [{ definition: "constructor topLevelClass(): topLevelClass", ranges: topLevelClass }]); + +verify.singleReferenceGroup("interface topLevelInterface", ranges.get("topLevelInterface")); +verify.singleReferenceGroup("namespace topLevelModule", ranges.get("topLevelModule")); diff --git a/tests/cases/fourslash/referencesForIllegalAssignment.ts b/tests/cases/fourslash/referencesForIllegalAssignment.ts index 59cb6f4f273..f65cd5bf1a6 100644 --- a/tests/cases/fourslash/referencesForIllegalAssignment.ts +++ b/tests/cases/fourslash/referencesForIllegalAssignment.ts @@ -2,13 +2,13 @@ ////f/*1*/oo = fo/*2*/o; -////var [|bar|] = function () { }; -////[|bar|] = [|bar|] + 1; +////var [|{| "isWriteAccess": true, "isDefinition": true |}bar|] = function () { }; +////[|{| "isWriteAccess": true |}bar|] = [|bar|] + 1; goTo.marker("1"); -verify.referencesAre([]); +verify.noReferences(); goTo.marker("2"); -verify.referencesAre([]); +verify.noReferences(); -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("var bar: () => void"); diff --git a/tests/cases/fourslash/referencesForImports.ts b/tests/cases/fourslash/referencesForImports.ts index 0203bcee096..54cbb0f1155 100644 --- a/tests/cases/fourslash/referencesForImports.ts +++ b/tests/cases/fourslash/referencesForImports.ts @@ -5,11 +5,11 @@ //// export = $; ////} -////import [|$|] = require("jquery"); +////import [|{| "isWriteAccess": true, "isDefinition": true |}$|] = require("jquery"); ////[|$|]("a"); -////import [|$|] = require("jquery"); +////import [|{| "isWriteAccess": true, "isDefinition": true |}$|] = require("jquery"); const [r0, r1, r2] = test.ranges(); -verify.rangesReferenceEachOther([r0, r1]); -verify.referencesOf(r2, [r2]); +verify.singleReferenceGroup('import $ = require("jquery")', [r0, r1]); +verify.singleReferenceGroup('import $ = require("jquery")', [r2]); diff --git a/tests/cases/fourslash/referencesForIndexProperty.ts b/tests/cases/fourslash/referencesForIndexProperty.ts index 49d12c25819..dba2549e414 100644 --- a/tests/cases/fourslash/referencesForIndexProperty.ts +++ b/tests/cases/fourslash/referencesForIndexProperty.ts @@ -3,12 +3,14 @@ // References a class property using string index access ////class Foo { -//// [|property|]: number; -//// [|method|](): void { } +//// [|{| "isWriteAccess": true, "isDefinition": true |}property|]: number; +//// [|{| "isWriteAccess": true, "isDefinition": true |}method|](): void { } ////} //// ////var f: Foo; ////f["[|property|]"]; ////f["[|method|]"]; -verify.rangesWithSameTextReferenceEachOther(); +const ranges = test.rangesByText(); +verify.singleReferenceGroup("(property) Foo.property: number", ranges.get("property")); +verify.singleReferenceGroup("(method) Foo.method(): void", ranges.get("method")); diff --git a/tests/cases/fourslash/referencesForIndexProperty2.ts b/tests/cases/fourslash/referencesForIndexProperty2.ts index 35c9d7cdd64..a4d5c75a908 100644 --- a/tests/cases/fourslash/referencesForIndexProperty2.ts +++ b/tests/cases/fourslash/referencesForIndexProperty2.ts @@ -5,4 +5,4 @@ ////var a; ////a["[|blah|]"]; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup('"blah"'); diff --git a/tests/cases/fourslash/referencesForIndexProperty3.ts b/tests/cases/fourslash/referencesForIndexProperty3.ts index 1fdee9b6602..a2e008c937e 100644 --- a/tests/cases/fourslash/referencesForIndexProperty3.ts +++ b/tests/cases/fourslash/referencesForIndexProperty3.ts @@ -3,7 +3,7 @@ // References to a property of the apparent type using string indexer ////interface Object { -//// [|toMyString|](); +//// [|{| "isWriteAccess": true, "isDefinition": true |}toMyString|](); ////} //// ////var y: Object; @@ -12,4 +12,4 @@ ////var x = {}; ////x["[|toMyString|]"](); -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(method) Object.toMyString(): any"); diff --git a/tests/cases/fourslash/referencesForInheritedProperties.ts b/tests/cases/fourslash/referencesForInheritedProperties.ts index 19fef4066ee..c2674fe1fe1 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties.ts @@ -1,15 +1,15 @@ /// ////interface interface1 { -//// [|doStuff|](): void; +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|](): void; ////} //// ////interface interface2 extends interface1{ -//// [|doStuff|](): void; +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|](): void; ////} //// ////class class1 implements interface2 { -//// [|doStuff|]() { +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { //// //// } ////} @@ -21,4 +21,21 @@ ////var v: class2; ////v.[|doStuff|](); -verify.rangesWithSameTextReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2, r3] = ranges; +verify.referenceGroups(r0, [{ definition: "(method) interface1.doStuff(): void", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(method) interface1.doStuff(): void", ranges: [r0] }, + { definition: "(method) interface2.doStuff(): void", ranges: [r1, r2, r3] } +]); +verify.referenceGroups(r2, [ + { definition: "(method) interface1.doStuff(): void", ranges: [r0] }, + { definition: "(method) interface2.doStuff(): void", ranges: [r1] }, + { definition: "(method) class1.doStuff(): void", ranges: [r2, r3] } +]); +verify.referenceGroups(r3, [ + { definition: "(method) interface1.doStuff(): void", ranges: [r0] }, + { definition: "(method) interface2.doStuff(): void", ranges: [r1] }, + { definition: "(method) class1.doStuff(): void", ranges: [r2] }, + { definition: "(method) class1.doStuff(): void", ranges: [r3] } +]); diff --git a/tests/cases/fourslash/referencesForInheritedProperties2.ts b/tests/cases/fourslash/referencesForInheritedProperties2.ts index 33a7f26aaea..0f89a9aa744 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties2.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties2.ts @@ -3,18 +3,18 @@ // extends statement in a diffrent declaration ////interface interface1 { -//// [|doStuff|](): void; +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|](): void; ////} //// ////interface interface2 { -//// [|doStuff|](): void; +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|](): void; ////} //// ////interface interface2 extends interface1 { ////} //// ////class class1 implements interface2 { -//// [|doStuff|]() { +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { //// //// } ////} @@ -26,4 +26,21 @@ ////var v: class2; ////v.[|doStuff|](); -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2, r3] = ranges; +verify.referenceGroups(r0, [{ definition: "(method) interface1.doStuff(): void", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(method) interface1.doStuff(): void", ranges: [r0] }, + { definition: "(method) interface2.doStuff(): void", ranges: [r1, r2, r3] } +]); +verify.referenceGroups(r2, [ + { definition: "(method) interface1.doStuff(): void", ranges: [r0] }, + { definition: "(method) interface2.doStuff(): void", ranges: [r1] }, + { definition: "(method) class1.doStuff(): void", ranges: [r2, r3] } +]); +verify.referenceGroups(r3, [ + { definition: "(method) interface1.doStuff(): void", ranges: [r0] }, + { definition: "(method) interface2.doStuff(): void", ranges: [r1] }, + { definition: "(method) class1.doStuff(): void", ranges: [r2] }, + { definition: "(method) class1.doStuff(): void", ranges: [r3] } +]); diff --git a/tests/cases/fourslash/referencesForInheritedProperties3.ts b/tests/cases/fourslash/referencesForInheritedProperties3.ts index 3a2d11da692..c6c870ca350 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties3.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties3.ts @@ -1,12 +1,14 @@ /// //// interface interface1 extends interface1 { -//// [|doStuff|](): void; -//// [|propName|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|](): void; +//// [|{| "isWriteAccess": true, "isDefinition": true |}propName|]: string; //// } //// //// var v: interface1; //// v.[|propName|]; //// v.[|doStuff|](); -verify.rangesWithSameTextReferenceEachOther(); +const ranges = test.rangesByText(); +verify.singleReferenceGroup("(method) interface1.doStuff(): void", ranges.get("doStuff")); +verify.singleReferenceGroup("(property) interface1.propName: string", ranges.get("propName")); diff --git a/tests/cases/fourslash/referencesForInheritedProperties4.ts b/tests/cases/fourslash/referencesForInheritedProperties4.ts index 96010d05086..8a822ec5238 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties4.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties4.ts @@ -1,12 +1,21 @@ /// //// class class1 extends class1 { -//// [|doStuff|]() { } -//// [|propName|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } +//// [|{| "isWriteAccess": true, "isDefinition": true |}propName|]: string; //// } //// //// var c: class1; //// c.[|doStuff|](); //// c.[|propName|]; -verify.rangesWithSameTextReferenceEachOther(); +const ranges = test.rangesByText(); +const [r0, r1] = ranges.get("doStuff"); +verify.referenceGroups(r0, [ + { definition: "(method) class1.doStuff(): void", ranges: [r0, r1] }, +]); +verify.referenceGroups(r1, [ + { definition: "(method) class1.doStuff(): void", ranges: [r0] }, + { definition: "(method) class1.doStuff(): void", ranges: [r1] }, +]); +verify.singleReferenceGroup("(property) class1.propName: string", ranges.get("propName")); diff --git a/tests/cases/fourslash/referencesForInheritedProperties5.ts b/tests/cases/fourslash/referencesForInheritedProperties5.ts index bbb86f0defb..7a5cff0ad2b 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties5.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties5.ts @@ -1,16 +1,28 @@ /// //// interface interface1 extends interface1 { -//// [|doStuff|](): void; -//// [|propName|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|](): void; +//// [|{| "isWriteAccess": true, "isDefinition": true |}propName|]: string; //// } //// interface interface2 extends interface1 { -//// [|doStuff|](): void; -//// [|propName|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|](): void; +//// [|{| "isWriteAccess": true, "isDefinition": true |}propName|]: string; //// } //// //// var v: interface1; //// v.[|propName|]; //// v.[|doStuff|](); -verify.rangesWithSameTextReferenceEachOther(); +const ranges = test.rangesByText(); +const [m0, m1, m2] = ranges.get("doStuff"); +const [p0, p1, p2] = ranges.get("propName"); +verify.referenceGroups([m0, m2], [{ definition: "(method) interface1.doStuff(): void", ranges: [m0, m1, m2] }]); +verify.referenceGroups(m1, [ + { definition: "(method) interface1.doStuff(): void", ranges: [m0, m2] }, + { definition: "(method) interface2.doStuff(): void", ranges: [m1] } +]); +verify.referenceGroups([p0, p2], [{ definition: "(property) interface1.propName: string", ranges: [p0, p1, p2] }]); +verify.referenceGroups(p1, [ + { definition: "(property) interface1.propName: string", ranges: [p0, p2] }, + { definition: "(property) interface2.propName: string", ranges: [p1] } +]); diff --git a/tests/cases/fourslash/referencesForInheritedProperties6.ts b/tests/cases/fourslash/referencesForInheritedProperties6.ts index ff008cceb43..a39dc085c71 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties6.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties6.ts @@ -1,16 +1,27 @@ /// //// class class1 extends class1 { -//// [|doStuff|]() { } -//// [|propName|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } +//// [|{| "isWriteAccess": true, "isDefinition": true |}propName|]: string; //// } //// class class2 extends class1 { -//// [|doStuff|]() { } -//// [|propName|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } +//// [|{| "isWriteAccess": true, "isDefinition": true |}propName|]: string; //// } //// //// var v: class2; //// v.[|propName|]; //// v.[|doStuff|](); -verify.rangesWithSameTextReferenceEachOther(); +const ranges = test.rangesByText(); +const [m0, m1, m2] = ranges.get("doStuff"); +verify.referenceGroups(m0, [{ definition: "(method) class1.doStuff(): void", ranges: [m0, m1, m2] }]); +verify.referenceGroups(m1, [ + { definition: "(method) class1.doStuff(): void", ranges: [m0] }, + { definition: "(method) class2.doStuff(): void", ranges: [m1, m2] } +]); +verify.referenceGroups(m2, [ + { definition: "(method) class1.doStuff(): void", ranges: [m0] }, + { definition: "(method) class2.doStuff(): void", ranges: [m1] }, + { definition: "(method) class2.doStuff(): void", ranges: [m2] } +]); diff --git a/tests/cases/fourslash/referencesForInheritedProperties7.ts b/tests/cases/fourslash/referencesForInheritedProperties7.ts index ec92a06f0a3..4911cbefd57 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties7.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties7.ts @@ -1,30 +1,40 @@ /// //// class class1 extends class1 { -//// [|doStuff|]() { } -//// [|propName|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } +//// [|{| "isWriteAccess": true, "isDefinition": true |}propName|]: string; //// } //// interface interface1 extends interface1 { -//// [|doStuff|](): void; -//// [|propName|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|](): void; +//// [|{| "isWriteAccess": true, "isDefinition": true |}propName|]: string; //// } //// class class2 extends class1 implements interface1 { -//// [|doStuff|]() { } -//// [|propName|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } +//// [|{| "isWriteAccess": true, "isDefinition": true |}propName|]: string; //// } //// //// var v: class2; -//// v.[|propName|]; //// v.[|doStuff|](); +//// v.[|propName|]; const [r0, r1, r2, r3, r4, r5, r6, r7] = test.ranges(); -verify.referencesOf(r0, [r0, r4, r7]); -verify.referencesOf(r1, [r1, r5, r6]); -verify.referencesOf(r2, [r2, r4, r7]); -verify.referencesOf(r3, [r3, r5, r6]); -const allDoStuff = [r0, r2, r4, r7]; -verify.referencesOf(r4, allDoStuff); -const allPropName = [r1, r3, r5, r6]; -verify.referencesOf(r5, allPropName); -verify.referencesOf(r6, allPropName); -verify.referencesOf(r7, allDoStuff); +verify.referenceGroups(r0, [{ definition: "(method) class1.doStuff(): void", ranges: [r0, r4, r6] }]); +verify.referenceGroups(r1, [{ definition: "(property) class1.propName: string", ranges: [r1, r5, r7] }]); +verify.referenceGroups(r2, [{ definition: "(method) interface1.doStuff(): void", ranges: [r2, r4, r6] }]); +verify.referenceGroups(r3, [{ definition: "(property) interface1.propName: string", ranges: [r3, r5, r7] }]); +verify.referenceGroups(r4, [ + { definition: "(method) class1.doStuff(): void", ranges: [r0] }, + { definition: "(method) interface1.doStuff(): void", ranges: [r2] }, + { definition: "(method) class2.doStuff(): void", ranges: [r4, r6] } +]); +verify.referenceGroups([r5, r7], [ + { definition: "(property) class1.propName: string", ranges: [r1] }, + { definition: "(property) interface1.propName: string", ranges: [r3] }, + { definition: "(property) class2.propName: string", ranges: [r5, r7] } +]); +verify.referenceGroups(r6, [ + { definition: "(method) class1.doStuff(): void", ranges: [r0] }, + { definition: "(method) interface1.doStuff(): void", ranges: [r2] }, + { definition: "(method) class2.doStuff(): void", ranges: [r4] }, + { definition: "(method) class2.doStuff(): void", ranges: [r6] } +]); diff --git a/tests/cases/fourslash/referencesForInheritedProperties8.ts b/tests/cases/fourslash/referencesForInheritedProperties8.ts index 964309fc477..d0d94b49b57 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties8.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties8.ts @@ -1,16 +1,19 @@ /// //// interface C extends D { -//// [|propD|]: number; +//// [|{| "isWriteAccess": true, "isDefinition": true |}propD|]: number; //// } //// interface D extends C { -//// [|propD|]: string; -//// [|propC|]: number; +//// [|{| "isWriteAccess": true, "isDefinition": true |}propD|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}propC|]: number; //// } //// var d: D; //// d.[|propD|]; //// d.[|propC|]; const [d0, d1, c0, d2, c1] = test.ranges(); -verify.rangesReferenceEachOther([d0, d1, d2]); -verify.rangesReferenceEachOther([c0, c1]); +verify.referenceGroups([d0, d1, d2], [ + { definition: "(property) C.propD: number", ranges: [d0] }, + { definition: "(property) D.propD: string", ranges: [d1, d2] }, +]); +verify.singleReferenceGroup("(property) D.propC: number", [c0, c1]); diff --git a/tests/cases/fourslash/referencesForInheritedProperties9.ts b/tests/cases/fourslash/referencesForInheritedProperties9.ts index 7d4330d0aa6..27bc164a8fc 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties9.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties9.ts @@ -1,16 +1,16 @@ /// //// class D extends C { -//// [|prop1|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}prop1|]: string; //// } -//// +//// //// class C extends D { -//// [|prop1|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}prop1|]: string; //// } -//// +//// //// var c: C; //// c.[|prop1|]; const [r0, r1, r2] = test.ranges(); -verify.referencesOf(r0, [r0]); -verify.rangesReferenceEachOther([r1, r2]); +verify.singleReferenceGroup("(property) D.prop1: string", [r0]); +verify.singleReferenceGroup("(property) C.prop1: string", [r1, r2]); diff --git a/tests/cases/fourslash/referencesForLabel.ts b/tests/cases/fourslash/referencesForLabel.ts index 14b58fd1d92..1abcafda0f2 100644 --- a/tests/cases/fourslash/referencesForLabel.ts +++ b/tests/cases/fourslash/referencesForLabel.ts @@ -11,5 +11,5 @@ ////var label = "label"; const [r0, r1, r2, r3] = test.ranges(); -verify.rangesReferenceEachOther([r0, r1, r2]); -verify.referencesOf(r3, [r3]); +verify.singleReferenceGroup("label", [r0, r1, r2]); +verify.singleReferenceGroup("label", [r3]); diff --git a/tests/cases/fourslash/referencesForLabel2.ts b/tests/cases/fourslash/referencesForLabel2.ts index 841e35ad700..6f3721431e0 100644 --- a/tests/cases/fourslash/referencesForLabel2.ts +++ b/tests/cases/fourslash/referencesForLabel2.ts @@ -8,5 +8,4 @@ //// if (true) continue label; ////} -goTo.marker(); -verify.referencesAre([]); +verify.noReferences(""); diff --git a/tests/cases/fourslash/referencesForLabel3.ts b/tests/cases/fourslash/referencesForLabel3.ts index fb7a51f858e..13622eb90c3 100644 --- a/tests/cases/fourslash/referencesForLabel3.ts +++ b/tests/cases/fourslash/referencesForLabel3.ts @@ -6,5 +6,4 @@ //// var label = "label"; ////} -const [label] = test.ranges(); -verify.referencesOf(label, [label]); +verify.singleReferenceGroup("label"); diff --git a/tests/cases/fourslash/referencesForLabel4.ts b/tests/cases/fourslash/referencesForLabel4.ts index 5462500f53c..2ff159bc755 100644 --- a/tests/cases/fourslash/referencesForLabel4.ts +++ b/tests/cases/fourslash/referencesForLabel4.ts @@ -8,4 +8,4 @@ //// } ////} -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("label"); diff --git a/tests/cases/fourslash/referencesForLabel5.ts b/tests/cases/fourslash/referencesForLabel5.ts index 48d5aab04c2..bc986e3350d 100644 --- a/tests/cases/fourslash/referencesForLabel5.ts +++ b/tests/cases/fourslash/referencesForLabel5.ts @@ -13,5 +13,5 @@ //// } const [outer1, outer2, inner1, inner2, outer3] = test.ranges(); -verify.rangesReferenceEachOther([outer1, outer2, outer3]); -verify.rangesReferenceEachOther([inner1, inner2]); +verify.singleReferenceGroup("label", [outer1, outer2, outer3]); +verify.singleReferenceGroup("label", [inner1, inner2]); diff --git a/tests/cases/fourslash/referencesForLabel6.ts b/tests/cases/fourslash/referencesForLabel6.ts index aea45805756..0255c07943c 100644 --- a/tests/cases/fourslash/referencesForLabel6.ts +++ b/tests/cases/fourslash/referencesForLabel6.ts @@ -7,6 +7,6 @@ //// break labelc; ////} -const [a, b, useB] = test.ranges(); -verify.referencesOf(a, [a]); -verify.rangesReferenceEachOther([b, useB]); +const ranges = test.rangesByText(); +verify.singleReferenceGroup("labela", ranges.get("labela")); +verify.singleReferenceGroup("labelb", ranges.get("labelb")); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations.ts b/tests/cases/fourslash/referencesForMergedDeclarations.ts index 8a0a5d4c680..3e2fe8e4b2c 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations.ts @@ -1,13 +1,13 @@ /// -////interface [|Foo|] { +////interface [|{| "isWriteAccess": true, "isDefinition": true |}Foo|] { ////} //// -////module [|Foo|] { +////module [|{| "isWriteAccess": true, "isDefinition": true |}Foo|] { //// export interface Bar { } ////} //// -////function [|Foo|](): void { +////function [|{| "isWriteAccess": true, "isDefinition": true |}Foo|](): void { ////} //// ////var f1: [|Foo|].Bar; @@ -15,6 +15,7 @@ ////[|Foo|].bind(this); const [type1, namespace1, value1, namespace2, type2, value2] = test.ranges(); -verify.rangesReferenceEachOther([type1, type2]); -verify.rangesReferenceEachOther([namespace1, namespace2]); -verify.rangesReferenceEachOther([value1, value2]); +verify.singleReferenceGroup("interface Foo\nnamespace Foo\nfunction Foo(): void", [type1, type2]); +verify.singleReferenceGroup("namespace Foo\nfunction Foo(): void", [namespace1, namespace2]); +verify.referenceGroups(value1, [{ definition: "function Foo(): void\nnamespace Foo", ranges: [value1, value2] }]); +verify.referenceGroups(value2, [{ definition: "namespace Foo\nfunction Foo(): void", ranges: [value1, value2] }]); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations2.ts b/tests/cases/fourslash/referencesForMergedDeclarations2.ts index 75d485002a4..5cf9234511a 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations2.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations2.ts @@ -6,9 +6,9 @@ //// ////function ATest() { } //// -////import [|alias|] = ATest; // definition +////import [|{| "isWriteAccess": true, "isDefinition": true |}alias|] = ATest; // definition //// ////var a: [|alias|].Bar; // namespace ////[|alias|].call(this); // value -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("import alias = ATest"); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations3.ts b/tests/cases/fourslash/referencesForMergedDeclarations3.ts index 181d68e79b3..5ce024258ed 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations3.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations3.ts @@ -1,13 +1,13 @@ /// -// class and uninstanciated module +// class and uninstantiated module -////class [|testClass|] { +////class [|{| "isWriteAccess": true, "isDefinition": true |}testClass|] { //// static staticMethod() { } //// method() { } ////} //// -////module [|testClass|] { +////module [|{| "isWriteAccess": true, "isDefinition": true |}testClass|] { //// export interface Bar { //// //// } @@ -21,5 +21,7 @@ ////new [|testClass|](); const [class0, module0, class1, module1, class2, class3, class4, class5] = test.ranges(); -verify.rangesReferenceEachOther([module0, module1]); -verify.rangesReferenceEachOther([class0, class1, class2, class3, class4, class5]); +verify.singleReferenceGroup("class testClass\nnamespace testClass", [module0, module1]); +const classes = [class0, class1, class2, class3, class4, class5]; +verify.referenceGroups(classes.slice(0, 5), [{ definition: "class testClass\nnamespace testClass", ranges: classes }]); +verify.referenceGroups(class5, [{ definition: "constructor testClass(): testClass\nnamespace testClass", ranges: classes }]); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations4.ts b/tests/cases/fourslash/referencesForMergedDeclarations4.ts index d35cbea745d..55eb331dd90 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations4.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations4.ts @@ -1,13 +1,13 @@ /// -// class and instanciated module +// class and instantiated module -////class [|testClass|] { +////class [|{| "isWriteAccess": true, "isDefinition": true |}testClass|] { //// static staticMethod() { } //// method() { } ////} //// -////module [|testClass|] { +////module [|{| "isWriteAccess": true, "isDefinition": true |}testClass|] { //// export interface Bar { //// //// } @@ -22,4 +22,6 @@ ////[|testClass|].s; ////new [|testClass|](); -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +verify.referenceGroups(ranges.slice(0, 8), [{ definition: "class testClass\nnamespace testClass", ranges }]); +verify.referenceGroups(ranges[8], [{ definition: "constructor testClass(): testClass\nnamespace testClass", ranges }]); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations5.ts b/tests/cases/fourslash/referencesForMergedDeclarations5.ts index 8fe33ca31e4..8cf597333b0 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations5.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations5.ts @@ -1,10 +1,14 @@ /// -////interface [|Foo|] { } -////module [|Foo|] { export interface Bar { } } -////function [|Foo|]() { } +////interface [|{| "isWriteAccess": true, "isDefinition": true |}Foo|] { } +////module [|{| "isWriteAccess": true, "isDefinition": true |}Foo|] { export interface Bar { } } +////function [|{| "isWriteAccess": true, "isDefinition": true |}Foo|]() { } //// ////export = [|Foo|]; -const [r0, r1, r2, r3] = test.ranges(); -verify.referencesOf(r3, [r0, r1, r2, r3]); +const ranges = test.ranges(); +const [r0, r1, r2, r3] = ranges; +verify.referenceGroups(r0, [{ definition: "interface Foo\nnamespace Foo\nfunction Foo(): void", ranges: [r0, r3] }]); +verify.referenceGroups(r1, [{ definition: "namespace Foo\nfunction Foo(): void", ranges: [r1, r3] }]); +verify.referenceGroups(r2, [{ definition: "function Foo(): void\nnamespace Foo", ranges: [r2, r3] }]); +verify.referenceGroups(r3, [{ definition: "interface Foo\nnamespace Foo\nfunction Foo(): void", ranges }]); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations6.ts b/tests/cases/fourslash/referencesForMergedDeclarations6.ts index e4b5b9111c6..79ee0128ab6 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations6.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations6.ts @@ -1,7 +1,7 @@ /// ////interface Foo { } -////module [|Foo|] { +////module [|{| "isWriteAccess": true, "isDefinition": true |}Foo|] { //// export interface Bar { } //// export module Bar { export interface Baz { } } //// export function Bar() { } @@ -10,4 +10,4 @@ ////// module ////import a1 = [|Foo|]; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("namespace Foo"); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations7.ts b/tests/cases/fourslash/referencesForMergedDeclarations7.ts index bc56b5d6f9d..66acffde980 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations7.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations7.ts @@ -2,13 +2,17 @@ ////interface Foo { } ////module Foo { -//// export interface [|Bar|] { } -//// export module [|Bar|] { export interface Baz { } } -//// export function [|Bar|]() { } +//// export interface [|{| "isWriteAccess": true, "isDefinition": true |}Bar|] { } +//// export module [|{| "isWriteAccess": true, "isDefinition": true |}Bar|] { export interface Baz { } } +//// export function [|{| "isWriteAccess": true, "isDefinition": true |}Bar|]() { } ////} //// ////// module, value and type ////import a2 = Foo.[|Bar|]; -const [r0, r1, r2, r3] = test.ranges(); -verify.referencesOf(r3, [r0, r1, r2, r3]); +const ranges = test.ranges(); +const [r0, r1, r2, r3] = ranges; +verify.referenceGroups(r0, [{ definition: "interface Foo.Bar\nnamespace Foo.Bar\nfunction Foo.Bar(): void", ranges: [r0, r3] }]); +verify.referenceGroups(r1, [{ definition: "namespace Foo.Bar\nfunction Foo.Bar(): void", ranges: [r1, r3] }]); +verify.referenceGroups(r2, [{ definition: "function Foo.Bar(): void\nnamespace Foo.Bar", ranges: [r2, r3] }]); +verify.referenceGroups(r3, [{ definition: "interface Foo.Bar\nnamespace Foo.Bar\nfunction Foo.Bar(): void", ranges }]); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations8.ts b/tests/cases/fourslash/referencesForMergedDeclarations8.ts index b5b1428b7c9..742561e21c5 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations8.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations8.ts @@ -3,11 +3,11 @@ ////interface Foo { } ////module Foo { //// export interface Bar { } -//// export module [|Bar|] { export interface Baz { } } +//// export module [|{| "isWriteAccess": true, "isDefinition": true |}Bar|] { export interface Baz { } } //// export function Bar() { } ////} //// ////// module ////import a3 = Foo.[|Bar|].Baz; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("namespace Foo.Bar\nfunction Foo.Bar(): void"); diff --git a/tests/cases/fourslash/referencesForNoContext.ts b/tests/cases/fourslash/referencesForNoContext.ts index 4631ce50c16..2ea57656167 100644 --- a/tests/cases/fourslash/referencesForNoContext.ts +++ b/tests/cases/fourslash/referencesForNoContext.ts @@ -21,14 +21,4 @@ //// } ////} -goTo.marker("1"); -verify.referencesAre([]); - -goTo.marker("2"); -verify.referencesAre([]); - -goTo.marker("3"); -verify.referencesAre([]); - -goTo.marker("4"); -verify.referencesAre([]); +goTo.eachMarker(() => verify.noReferences()); diff --git a/tests/cases/fourslash/referencesForNumericLiteralPropertyNames.ts b/tests/cases/fourslash/referencesForNumericLiteralPropertyNames.ts index 5e6e8172092..effa4abc164 100644 --- a/tests/cases/fourslash/referencesForNumericLiteralPropertyNames.ts +++ b/tests/cases/fourslash/referencesForNumericLiteralPropertyNames.ts @@ -1,12 +1,23 @@ /// ////class Foo { -//// public [|12|]: any; +//// public [|{| "isDefinition": true |}12|]: any; ////} //// ////var x: Foo; ////x[[|12|]]; -////x = { "[|12|]": 0 }; -////x = { [|12|]: 0 }; +////x = { "[|{| "isDefinition": true |}12|]": 0 }; +////x = { [|{| "isDefinition": true |}12|]: 0 }; -verify.rangesReferenceEachOther(); +//verify.singleReferenceGroup("(property) Foo[12]: any"); +const ranges = test.ranges(); +const [r0, r1, r2, r3] = ranges; +verify.referenceGroups([r0, r1], [{ definition: "(property) Foo[12]: any", ranges }]); +verify.referenceGroups(r2, [ + { definition: "(property) Foo[12]: any", ranges: [r0, r1, r3] }, + { definition: "(property) \"12\": number", ranges: [r2] } +]); +verify.referenceGroups(r3, [ + { definition: "(property) Foo[12]: any", ranges: [r0, r1, r2] }, + { definition: "(property) 12: number", ranges: [r3] } +]); diff --git a/tests/cases/fourslash/referencesForObjectLiteralProperties.ts b/tests/cases/fourslash/referencesForObjectLiteralProperties.ts index f2a815e845b..ea7c20829ae 100644 --- a/tests/cases/fourslash/referencesForObjectLiteralProperties.ts +++ b/tests/cases/fourslash/referencesForObjectLiteralProperties.ts @@ -2,10 +2,16 @@ // References to an object literal property -////var x = { [|add|]: 0, b: "string" }; +////var x = { [|{| "isWriteAccess": true, "isDefinition": true |}add|]: 0, b: "string" }; ////x["[|add|]"]; ////x.[|add|]; ////var y = x; ////y.[|add|]; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2, r3] = ranges; +verify.referenceGroups(r0, [{ definition: "(property) add: number", ranges }]); +verify.referenceGroups([r1, r2, r3], [ + { definition: "(property) add: number", ranges: [r0] }, + { definition: "(property) add: number", ranges: [r1, r2, r3] } +]); diff --git a/tests/cases/fourslash/referencesForOverrides.ts b/tests/cases/fourslash/referencesForOverrides.ts index 4896bd1cd39..5ce6bc5ed04 100644 --- a/tests/cases/fourslash/referencesForOverrides.ts +++ b/tests/cases/fourslash/referencesForOverrides.ts @@ -3,59 +3,59 @@ ////module FindRef3 { //// module SimpleClassTest { //// export class Foo { -//// public [|foo|](): void { +//// public [|{| "isWriteAccess": true, "isDefinition": true |}foo|](): void { //// } //// } //// export class Bar extends Foo { -//// public [|foo|](): void { +//// public [|{| "isWriteAccess": true, "isDefinition": true |}foo|](): void { //// } //// } //// } //// //// module SimpleInterfaceTest { //// export interface IFoo { -//// [|ifoo|](): void; +//// [|{| "isWriteAccess": true, "isDefinition": true |}ifoo|](): void; //// } //// export interface IBar extends IFoo { -//// [|ifoo|](): void; +//// [|{| "isWriteAccess": true, "isDefinition": true |}ifoo|](): void; //// } //// } //// //// module SimpleClassInterfaceTest { //// export interface IFoo { -//// [|icfoo|](): void; +//// [|{| "isWriteAccess": true, "isDefinition": true |}icfoo|](): void; //// } //// export class Bar implements IFoo { -//// public [|icfoo|](): void { +//// public [|{| "isWriteAccess": true, "isDefinition": true |}icfoo|](): void { //// } //// } //// } //// //// module Test { //// export interface IBase { -//// [|field|]: string; -//// [|method|](): void; +//// [|{| "isWriteAccess": true, "isDefinition": true |}field|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}method|](): void; //// } //// //// export interface IBlah extends IBase { -//// [|field|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}field|]: string; //// } //// //// export interface IBlah2 extends IBlah { -//// [|field|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}field|]: string; //// } //// //// export interface IDerived extends IBlah2 { -//// [|method|](): void; +//// [|{| "isWriteAccess": true, "isDefinition": true |}method|](): void; //// } //// //// export class Bar implements IDerived { -//// public [|field|]: string; -//// public [|method|](): void { } +//// public [|{| "isWriteAccess": true, "isDefinition": true |}field|]: string; +//// public [|{| "isWriteAccess": true, "isDefinition": true |}method|](): void { } //// } //// //// export class BarBlah extends Bar { -//// public [|field|]: string; +//// public [|{| "isWriteAccess": true, "isDefinition": true |}field|]: string; //// } //// } //// @@ -75,4 +75,67 @@ //// } ////} -verify.rangesWithSameTextReferenceEachOther(); +const ranges = test.rangesByText(); + +const fooRanges = ranges.get("foo"); +const [foo0, foo1, foo2] = fooRanges; +verify.referenceGroups(foo0, [{ definition: "(method) SimpleClassTest.Foo.foo(): void", ranges: fooRanges }]); +verify.referenceGroups([foo1, foo2], [ + { definition: "(method) SimpleClassTest.Foo.foo(): void", ranges: [foo0] }, + { definition: "(method) SimpleClassTest.Bar.foo(): void", ranges: [foo1, foo2] } +]); + +const ifooRanges = ranges.get("ifoo"); +const [ifoo0, ifoo1, ifoo2] = ifooRanges; +verify.referenceGroups(ifoo0, [{ definition: "(method) SimpleInterfaceTest.IFoo.ifoo(): void", ranges: ifooRanges }]); +verify.referenceGroups([ifoo1, ifoo2], [ + { definition: "(method) SimpleInterfaceTest.IFoo.ifoo(): void", ranges: [ifoo0] }, + { definition: "(method) SimpleInterfaceTest.IBar.ifoo(): void", ranges: [ifoo1, ifoo2] } +]); + +const icfooRanges = ranges.get("icfoo"); +const [icfoo0, icfoo1, icfoo2] = icfooRanges; +verify.referenceGroups(icfoo0, [{ definition: "(method) SimpleClassInterfaceTest.IFoo.icfoo(): void", ranges: icfooRanges }]); +verify.referenceGroups([icfoo1, icfoo2], [ + { definition: "(method) SimpleClassInterfaceTest.IFoo.icfoo(): void", ranges: [icfoo0] }, + { definition: "(method) SimpleClassInterfaceTest.Bar.icfoo(): void", ranges: [icfoo1, icfoo2] } +]); + +const fieldRanges = ranges.get("field"); +const [field0, field1, field2, field3, field4, field5] = fieldRanges; +verify.referenceGroups(field0, [{ definition: "(property) Test.IBase.field: string", ranges: fieldRanges }]); +verify.referenceGroups(field1, [ + { definition: "(property) Test.IBase.field: string", ranges: [field0] }, + { definition: "(property) Test.IBlah.field: string", ranges: fieldRanges.slice(1) } +]); +verify.referenceGroups(field2, [ + { definition: "(property) Test.IBase.field: string", ranges: [field0] }, + { definition: "(property) Test.IBlah.field: string", ranges: [field1] }, + { definition: "(property) Test.IBlah2.field: string", ranges: fieldRanges.slice(2) } +]); +verify.referenceGroups(field3, [ + { definition: "(property) Test.IBase.field: string", ranges: [field0] }, + { definition: "(property) Test.IBlah.field: string", ranges: [field1] }, + { definition: "(property) Test.IBlah2.field: string", ranges: [field2] }, + { definition: "(property) Test.Bar.field: string", ranges: fieldRanges.slice(3) } +]); +verify.referenceGroups([field4, field5], [ + { definition: "(property) Test.IBase.field: string", ranges: [field0] }, + { definition: "(property) Test.IBlah.field: string", ranges: [field1] }, + { definition: "(property) Test.IBlah2.field: string", ranges: [field2] }, + { definition: "(property) Test.Bar.field: string", ranges: [field3] }, + { definition: "(property) Test.BarBlah.field: string", ranges: fieldRanges.slice(4) } +]); + +const methodRanges = ranges.get("method"); +const [method0, method1, method2, method3] = methodRanges; +verify.referenceGroups(method0, [{ definition: "(method) Test.IBase.method(): void", ranges: methodRanges }]); +verify.referenceGroups(method1, [ + { definition: "(method) Test.IBase.method(): void", ranges: [method0] }, + { definition: "(method) Test.IDerived.method(): void", ranges: methodRanges.slice(1) } +]); +verify.referenceGroups([method2, method3], [ + { definition: "(method) Test.IBase.method(): void", ranges: [method0] }, + { definition: "(method) Test.IDerived.method(): void", ranges: [method1] }, + { definition: "(method) Test.Bar.method(): void", ranges: methodRanges.slice(2) } +]); diff --git a/tests/cases/fourslash/referencesForPropertiesOfGenericType.ts b/tests/cases/fourslash/referencesForPropertiesOfGenericType.ts index a8b08eae506..a92ac909782 100644 --- a/tests/cases/fourslash/referencesForPropertiesOfGenericType.ts +++ b/tests/cases/fourslash/referencesForPropertiesOfGenericType.ts @@ -1,7 +1,7 @@ /// ////interface IFoo { -//// [|doSomething|](v: T): T; +//// [|{| "isWriteAccess": true, "isDefinition": true |}doSomething|](v: T): T; ////} //// ////var x: IFoo; @@ -10,4 +10,14 @@ ////var y: IFoo; ////y.[|doSomething|](12); -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2] = ranges; +verify.referenceGroups(r0, [{ definition: "(method) IFoo.doSomething(v: T): T", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(method) IFoo.doSomething(v: string): string", ranges: [r0, r2] }, + { definition: "(method) IFoo.doSomething(v: string): string", ranges: [r1] } +]); +verify.referenceGroups(r2, [ + { definition: "(method) IFoo.doSomething(v: number): number", ranges: [r0, r1] }, + { definition: "(method) IFoo.doSomething(v: number): number", ranges: [r2] } +]); diff --git a/tests/cases/fourslash/referencesForStatic.ts b/tests/cases/fourslash/referencesForStatic.ts index c6594006708..17c33daac32 100644 --- a/tests/cases/fourslash/referencesForStatic.ts +++ b/tests/cases/fourslash/referencesForStatic.ts @@ -6,7 +6,7 @@ ////var n = 43; //// ////class foo { -//// static [|n|] = ''; +//// static [|{| "isWriteAccess": true, "isDefinition": true |}n|] = ''; //// //// public bar() { //// foo.[|n|] = "'"; @@ -30,4 +30,4 @@ // @Filename: referencesOnStatic_2.ts ////var q = foo.[|n|]; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("(property) foo.n: string"); diff --git a/tests/cases/fourslash/referencesForStaticsAndMembersWithSameNames.ts b/tests/cases/fourslash/referencesForStaticsAndMembersWithSameNames.ts index cada3e0fcf4..1e393ef6761 100644 --- a/tests/cases/fourslash/referencesForStaticsAndMembersWithSameNames.ts +++ b/tests/cases/fourslash/referencesForStaticsAndMembersWithSameNames.ts @@ -3,12 +3,12 @@ ////module FindRef4 { //// module MixedStaticsClassTest { //// export class Foo { -//// [|bar|]: Foo; -//// static [|bar|]: Foo; +//// [|{| "isWriteAccess": true, "isDefinition": true |}bar|]: Foo; +//// static [|{| "isWriteAccess": true, "isDefinition": true |}bar|]: Foo; //// -//// public [|foo|](): void { +//// public [|{| "isWriteAccess": true, "isDefinition": true |}foo|](): void { //// } -//// public static [|foo|](): void { +//// public static [|{| "isWriteAccess": true, "isDefinition": true |}foo|](): void { //// } //// } //// } @@ -28,13 +28,16 @@ const [fooBar, fooStaticBar, fooFoo, fooStaticFoo, xFoo, xBar, staticFoo, staticBar] = test.ranges(); // References to a member method with the same name as a static. -verify.referencesOf(fooFoo, [fooFoo, xFoo]); +verify.singleReferenceGroup("(method) MixedStaticsClassTest.Foo.foo(): void", [fooFoo, xFoo]); // References to a static method with the same name as a member. -verify.referencesOf(fooStaticFoo, [fooStaticFoo, staticFoo]); +verify.singleReferenceGroup("(method) MixedStaticsClassTest.Foo.foo(): void", [fooStaticFoo, staticFoo]); // References to a member property with the same name as a static. -verify.referencesOf(fooBar, [fooBar, xBar]); +//verify.singleReferenceGroup("(property) MixedStaticsClassTest.Foo.bar: Foo", [fooBar, xBar]); +verify.referenceGroups(fooBar, [{ definition: "(property) MixedStaticsClassTest.Foo.bar: Foo", ranges: [fooBar, xBar] }]); +verify.referenceGroups(xBar, [{ definition: "(property) MixedStaticsClassTest.Foo.bar: MixedStaticsClassTest.Foo", ranges: [fooBar, xBar] }]); // References to a static property with the same name as a member. -verify.referencesOf(fooStaticBar, [fooStaticBar, staticBar]); +verify.referenceGroups(fooStaticBar, [{ definition: "(property) MixedStaticsClassTest.Foo.bar: Foo", ranges: [fooStaticBar, staticBar] }]); +verify.referenceGroups(staticBar, [{ definition: "(property) MixedStaticsClassTest.Foo.bar: MixedStaticsClassTest.Foo", ranges: [fooStaticBar, staticBar] }]); diff --git a/tests/cases/fourslash/referencesForStringLiteralPropertyNames.ts b/tests/cases/fourslash/referencesForStringLiteralPropertyNames.ts index 2db0325d324..e9be352f819 100644 --- a/tests/cases/fourslash/referencesForStringLiteralPropertyNames.ts +++ b/tests/cases/fourslash/referencesForStringLiteralPropertyNames.ts @@ -1,13 +1,23 @@ /// ////class Foo { -//// public "[|ss|]": any; +//// public "[|{| "isDefinition": true |}ss|]": any; ////} //// ////var x: Foo; ////x.[|ss|]; ////x["[|ss|]"]; -////x = { "[|ss|]": 0 }; -////x = { [|ss|]: 0 }; +////x = { "[|{| "isDefinition": true |}ss|]": 0 }; +////x = { [|{| "isWriteAccess": true, "isDefinition": true |}ss|]: 0 }; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2, r3, r4] = ranges; +verify.referenceGroups([r0, r1, r2], [{ definition: '(property) Foo["ss"]: any', ranges }]); +verify.referenceGroups(r3, [ + { definition: '(property) Foo["ss"]: any', ranges: [r0, r1, r2, r4] }, + { definition: '(property) "ss": number', ranges: [r3] } +]); +verify.referenceGroups(r4, [ + { definition: '(property) Foo["ss"]: any', ranges: [r0, r1, r2, r3] }, + { definition: '(property) ss: number', ranges: [r4] } +]); diff --git a/tests/cases/fourslash/referencesForStringLiteralPropertyNames2.ts b/tests/cases/fourslash/referencesForStringLiteralPropertyNames2.ts index 275a2b2756c..6fbb0b85072 100644 --- a/tests/cases/fourslash/referencesForStringLiteralPropertyNames2.ts +++ b/tests/cases/fourslash/referencesForStringLiteralPropertyNames2.ts @@ -1,10 +1,17 @@ /// ////class Foo { -//// "[|blah|]"() { return 0; } +//// "[|{| "isDefinition": true |}blah|]"() { return 0; } ////} //// ////var x: Foo; ////x.[|blah|]; -verify.rangesReferenceEachOther(); +//verify.singleReferenceGroup('(method) Foo["blah"](): number'); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [{ definition: '(method) Foo["blah"](): number', ranges }]); +verify.referenceGroups(r1, [ + { definition: '(method) Foo["blah"](): number', ranges: [r0] }, + { definition: '(method) Foo["blah"](): number', ranges: [r1] } +]); diff --git a/tests/cases/fourslash/referencesForStringLiteralPropertyNames3.ts b/tests/cases/fourslash/referencesForStringLiteralPropertyNames3.ts index 55a067ae8c3..d4e12a67afc 100644 --- a/tests/cases/fourslash/referencesForStringLiteralPropertyNames3.ts +++ b/tests/cases/fourslash/referencesForStringLiteralPropertyNames3.ts @@ -1,11 +1,17 @@ /// ////class Foo2 { -//// get "[|42|]"() { return 0; } -//// set [|42|](n) { } +//// get "[|{| "isDefinition": true |}42|]"() { return 0; } +//// set [|{| "isDefinition": true |}42|](n) { } ////} //// ////var y: Foo2; ////y[[|42|]]; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2] = ranges; +verify.referenceGroups([r0, r1], [{ definition: '(property) Foo2["42"]: number', ranges }]); +verify.referenceGroups(r2, [ + { definition: '(property) Foo2["42"]: number', ranges: [r0, r1] }, + { definition: '(property) Foo2["42"]: number', ranges: [r2] }, +]); diff --git a/tests/cases/fourslash/referencesForStringLiteralPropertyNames4.ts b/tests/cases/fourslash/referencesForStringLiteralPropertyNames4.ts index 34cad8f11e8..efe8972f2c7 100644 --- a/tests/cases/fourslash/referencesForStringLiteralPropertyNames4.ts +++ b/tests/cases/fourslash/referencesForStringLiteralPropertyNames4.ts @@ -1,7 +1,13 @@ /// -////var x = { "[|someProperty|]": 0 } +////var x = { "[|{| "isDefinition": true |}someProperty|]": 0 } ////x["[|someProperty|]"] = 3; -////x./*1*/[|someProperty|] = 5; +////x.[|someProperty|] = 5; -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1, r2] = ranges; +verify.referenceGroups(r0, [{ definition: '(property) "someProperty": number', ranges }]); +verify.referenceGroups([r1, r2], [ + { definition: '(property) "someProperty": number', ranges: [r0] }, + { definition: '(property) "someProperty": number', ranges: [r1, r2] }, +]); diff --git a/tests/cases/fourslash/referencesForUnionProperties.ts b/tests/cases/fourslash/referencesForUnionProperties.ts index 07eebeb5f74..97570077346 100644 --- a/tests/cases/fourslash/referencesForUnionProperties.ts +++ b/tests/cases/fourslash/referencesForUnionProperties.ts @@ -1,16 +1,16 @@ /// ////interface One { -//// common: { [|a|]: number; }; +//// common: { [|{| "isWriteAccess": true, "isDefinition": true |}a|]: number; }; ////} //// ////interface Base { -//// [|a|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}a|]: string; //// b: string; ////} //// ////interface HasAOrB extends Base { -//// [|a|]: string; +//// [|{| "isWriteAccess": true, "isDefinition": true |}a|]: string; //// b: string; ////} //// @@ -23,7 +23,15 @@ ////x.common.[|a|]; const [one, base, hasAOrB, x] = test.ranges(); -verify.referencesOf(one, [one, x]); -verify.referencesOf(base, [base, hasAOrB, x]); -verify.referencesOf(hasAOrB, [base, hasAOrB, x]); -verify.referencesOf(x, [one, base, hasAOrB, x]); +verify.referenceGroups(one, [{ definition: "(property) a: number", ranges: [one, x] }]); +verify.referenceGroups(base, [{ definition: "(property) Base.a: string", ranges: [base, hasAOrB, x] }]); +verify.referenceGroups(hasAOrB, [ + { definition: "(property) Base.a: string", ranges: [base] }, + { definition: "(property) HasAOrB.a: string", ranges: [hasAOrB, x] } +]); +verify.referenceGroups(x, [ + { definition: "(property) a: number", ranges: [one] }, + { definition: "(property) Base.a: string", ranges: [base] }, + { definition: "(property) HasAOrB.a: string", ranges: [hasAOrB] }, + { definition: "(property) a: string | number", ranges: [x] } +]); diff --git a/tests/cases/fourslash/referencesInComment.ts b/tests/cases/fourslash/referencesInComment.ts index eabf74d2f23..674ee41a8d2 100644 --- a/tests/cases/fourslash/referencesInComment.ts +++ b/tests/cases/fourslash/referencesInComment.ts @@ -5,4 +5,4 @@ ////class foo { } ////var bar = 0; -goTo.eachMarker(() => verify.referencesAre([])); +goTo.eachMarker(() => verify.noReferences()); diff --git a/tests/cases/fourslash/remoteGetReferences.ts b/tests/cases/fourslash/remoteGetReferences.ts index d9b6c6e852c..292864f9ed4 100644 --- a/tests/cases/fourslash/remoteGetReferences.ts +++ b/tests/cases/fourslash/remoteGetReferences.ts @@ -95,10 +95,10 @@ //////Increments ////[|remotefooCls|].[|remoteclsSVar|]++; ////remotemodTest.remotemodVar++; -////[|remoteglobalVar|] = [|remoteglobalVar|] + [|remoteglobalVar|]; +////[|{| "isWriteAccess": true |}remoteglobalVar|] = [|remoteglobalVar|] + [|remoteglobalVar|]; //// //////ETC - Other cases -////[|remoteglobalVar|] = 3; +////[|{| "isWriteAccess": true |}remoteglobalVar|] = 3; //// //////Find References misses method param ////var @@ -119,16 +119,16 @@ ////}); // @Filename: remoteGetReferences_2.ts -////var [|remoteglobalVar|]: number = 2; +////var [|{| "isWriteAccess": true, "isDefinition": true |}remoteglobalVar|]: number = 2; //// -////class [|remotefooCls|] { +////class [|{| "isWriteAccess": true, "isDefinition": true |}remotefooCls|] { //// //Declare -//// [|remoteclsVar|] = 1; -//// static [|remoteclsSVar|] = 1; +//// [|{| "isWriteAccess": true, "isDefinition": true |}remoteclsVar|] = 1; +//// static [|{| "isWriteAccess": true, "isDefinition": true |}remoteclsSVar|] = 1; //// //// constructor(public remoteclsParam: number) { //// //Increments -//// [|remoteglobalVar|]++; +//// [|{| "isWriteAccess": true |}remoteglobalVar|]++; //// this.[|remoteclsVar|]++; //// [|remotefooCls|].[|remoteclsSVar|]++; //// this.remoteclsParam++; @@ -142,7 +142,7 @@ //// //// //Increments //// [|remotefooCls|].[|remoteclsSVar|]++; -//// [|remoteglobalVar|]++; +//// [|{| "isWriteAccess": true |}remoteglobalVar|]++; //// remotemodTest.remotemodVar++; //// remotefnVar++; //// @@ -155,7 +155,7 @@ //// export var remotemodVar: number; //// //// //Increments -//// [|remoteglobalVar|]++; +//// [|{| "isWriteAccess": true |}remoteglobalVar|]++; //// [|remotefooCls|].[|remoteclsSVar|]++; //// remotemodVar++; //// @@ -167,7 +167,7 @@ //// static remoteboo = remotefoo; //// //// //Increments -//// [|remoteglobalVar|]++; +//// [|{| "isWriteAccess": true |}remoteglobalVar|]++; //// [|remotefooCls|].[|remoteclsSVar|]++; //// remotemodVar++; //// } @@ -177,4 +177,24 @@ //// } ////} -verify.rangesWithSameTextReferenceEachOther(); +test.rangesByText().forEach((ranges, text) => { + const definition = (() => { + switch (text) { + case "remotefooCls": return "class remotefooCls"; + case "remoteglobalVar": return "var remoteglobalVar: number"; + case "remoteclsSVar": return "(property) remotefooCls.remoteclsSVar: number"; + case "remoteclsVar": return "(property) remotefooCls.remoteclsVar: number"; + default: throw new Error(text); + } + })(); + + if (text === "remotefooCls") { + verify.referenceGroups([ranges[0], ...ranges.slice(2)], [{ definition, ranges }]); + verify.referenceGroups(ranges[1], [ + { definition: "constructor remotefooCls(remoteclsParam: number): remotefooCls", ranges} + ]); + } + else { + verify.singleReferenceGroup(definition, ranges); + } +}); diff --git a/tests/cases/fourslash/renameDefaultImport.ts b/tests/cases/fourslash/renameDefaultImport.ts index ff297ffa147..bcac46d7a63 100644 --- a/tests/cases/fourslash/renameDefaultImport.ts +++ b/tests/cases/fourslash/renameDefaultImport.ts @@ -1,21 +1,23 @@ /// // @Filename: B.ts -////export default class /*1*/[|B|] { +////export default class /*1*/[|{| "isWriteAccess": true, "isDefinition": true |}B|] { //// test() { //// } ////} // @Filename: A.ts -////import [|B|] from "./B"; +////import [|{| "isWriteAccess": true, "isDefinition": true |}B|] from "./B"; ////let b = new [|B|](); ////b.test(); goTo.marker("1"); verify.occurrencesAtPositionCount(1); -const [C, B0, B1] = test.ranges(); -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [C, B0, B1] = ranges; +verify.referenceGroups([C, B0], [{ definition: "class B", ranges }]); +verify.referenceGroups(B1, [{ definition: "constructor B(): B", ranges }]); goTo.rangeStart(C); verify.renameLocations(false, false, [C, B0, B1]); diff --git a/tests/cases/fourslash/renameDefaultImportDifferentName.ts b/tests/cases/fourslash/renameDefaultImportDifferentName.ts index be968c9b883..590c81c650c 100644 --- a/tests/cases/fourslash/renameDefaultImportDifferentName.ts +++ b/tests/cases/fourslash/renameDefaultImportDifferentName.ts @@ -1,21 +1,23 @@ /// // @Filename: B.ts -////export default class /*1*/[|C|] { +////export default class /*1*/[|{| "isWriteAccess": true, "isDefinition": true |}C|] { //// test() { //// } ////} // @Filename: A.ts -////import [|B|] from "./B"; +////import [|{| "isWriteAccess": true, "isDefinition": true |}B|] from "./B"; ////let b = new [|B|](); ////b.test(); goTo.marker("1"); verify.occurrencesAtPositionCount(1); -const [C, B0, B1] = test.ranges(); -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [C, B0, B1] = ranges; +verify.referenceGroups([C, B0], [{ definition: "class C", ranges }]); +verify.referenceGroups(B1, [{ definition: "constructor C(): B", ranges }]); goTo.rangeStart(C); verify.renameLocations(false, false, [C, B0, B1]); diff --git a/tests/cases/fourslash/renameImportAndExportInDiffFiles.ts b/tests/cases/fourslash/renameImportAndExportInDiffFiles.ts index e982d6a4c7b..656a48f24dd 100644 --- a/tests/cases/fourslash/renameImportAndExportInDiffFiles.ts +++ b/tests/cases/fourslash/renameImportAndExportInDiffFiles.ts @@ -1,10 +1,10 @@ /// // @Filename: a.ts -////export var [|a|]; +////export var [|{| "isWriteAccess": true, "isDefinition": true |}a|]; // @Filename: b.ts -////import { [|a|] } from './a'; -////export { [|a|] }; +////import { [|{| "isWriteAccess": true, "isDefinition": true |}a|] } from './a'; +////export { [|{| "isWriteAccess": true, "isDefinition": true |}a|] }; -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("var a: any"); diff --git a/tests/cases/fourslash/shims-pp/getReferencesAtPosition.ts b/tests/cases/fourslash/shims-pp/getReferencesAtPosition.ts index cb829807602..fa9a510d5ac 100644 --- a/tests/cases/fourslash/shims-pp/getReferencesAtPosition.ts +++ b/tests/cases/fourslash/shims-pp/getReferencesAtPosition.ts @@ -1,4 +1,4 @@ -/// +/// //@Filename: findAllRefsOnDefinition-import.ts ////export class Test{ @@ -7,7 +7,7 @@ //// //// } //// -//// public [|start|](){ +//// public [|{| "isWriteAccess": true, "isDefinition": true |}start|](){ //// return this; //// } //// @@ -23,4 +23,10 @@ ////second.[|start|](); ////second.stop(); -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [{ definition: "(method) Test.start(): this", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(method) Second.Test.start(): Second.Test", ranges: [r0] }, + { definition: "(method) Second.Test.start(): Second.Test", ranges: [r1] } +]); diff --git a/tests/cases/fourslash/shims/getReferencesAtPosition.ts b/tests/cases/fourslash/shims/getReferencesAtPosition.ts index cb829807602..fa9a510d5ac 100644 --- a/tests/cases/fourslash/shims/getReferencesAtPosition.ts +++ b/tests/cases/fourslash/shims/getReferencesAtPosition.ts @@ -1,4 +1,4 @@ -/// +/// //@Filename: findAllRefsOnDefinition-import.ts ////export class Test{ @@ -7,7 +7,7 @@ //// //// } //// -//// public [|start|](){ +//// public [|{| "isWriteAccess": true, "isDefinition": true |}start|](){ //// return this; //// } //// @@ -23,4 +23,10 @@ ////second.[|start|](); ////second.stop(); -verify.rangesReferenceEachOther(); +const ranges = test.ranges(); +const [r0, r1] = ranges; +verify.referenceGroups(r0, [{ definition: "(method) Test.start(): this", ranges }]); +verify.referenceGroups(r1, [ + { definition: "(method) Second.Test.start(): Second.Test", ranges: [r0] }, + { definition: "(method) Second.Test.start(): Second.Test", ranges: [r1] } +]); diff --git a/tests/cases/fourslash/untypedModuleImport.ts b/tests/cases/fourslash/untypedModuleImport.ts index da6473cf992..1854010d5b6 100644 --- a/tests/cases/fourslash/untypedModuleImport.ts +++ b/tests/cases/fourslash/untypedModuleImport.ts @@ -4,7 +4,7 @@ ////{} // @Filename: a.ts -////import /*foo*/[|foo|] from /*fooModule*/"foo"; +////import /*foo*/[|{| "isWriteAccess": true, "isDefinition": true |}foo|] from /*fooModule*/"foo"; ////[|foo|](); goTo.file("a.ts"); @@ -13,9 +13,9 @@ verify.numberOfErrorsInCurrentFile(0); goTo.marker("fooModule"); verify.goToDefinitionIs([]); verify.quickInfoIs(""); -verify.referencesAre([]) +verify.noReferences(); goTo.marker("foo"); verify.goToDefinitionIs([]); verify.quickInfoIs("import foo"); -verify.rangesReferenceEachOther(); +verify.singleReferenceGroup("import foo"); From 914150f2f19583b40be46663628e9bbe3c66b2f4 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sun, 5 Feb 2017 15:18:27 -0800 Subject: [PATCH 02/16] Widen special JS property declarations to match regular property declarations --- src/compiler/checker.ts | 40 ++++++++++++------- .../jsFileClassPropertyType.errors.txt | 17 ++++++++ .../jsFileClassPropertyType2.errors.txt | 18 +++++++++ .../reference/multipleDeclarations.types | 2 +- ...naturesUseJSDocForOptionalParameters.types | 30 +++++++------- .../cases/compiler/jsFileClassPropertyType.ts | 13 ++++++ .../compiler/jsFileClassPropertyType2.ts | 14 +++++++ .../getJavaScriptSyntacticDiagnostics24.ts | 2 +- 8 files changed, 104 insertions(+), 32 deletions(-) create mode 100644 tests/baselines/reference/jsFileClassPropertyType.errors.txt create mode 100644 tests/baselines/reference/jsFileClassPropertyType2.errors.txt create mode 100644 tests/cases/compiler/jsFileClassPropertyType.ts create mode 100644 tests/cases/compiler/jsFileClassPropertyType2.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b5306771dd7..10c5f5422e3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3254,7 +3254,7 @@ namespace ts { type; } - function getTypeForVariableLikeDeclarationFromJSDocComment(declaration: VariableLikeDeclaration) { + function getTypeForDeclarationFromJSDocComment(declaration: Node ) { const jsdocType = getJSDocType(declaration); if (jsdocType) { return getTypeFromTypeNode(jsdocType); @@ -3282,7 +3282,7 @@ namespace ts { // If this is a variable in a JavaScript file, then use the JSDoc type (if it has // one as its type), otherwise fallback to the below standard TS codepaths to // try to figure it out. - const type = getTypeForVariableLikeDeclarationFromJSDocComment(declaration); + const type = getTypeForDeclarationFromJSDocComment(declaration); if (type && type !== unknownType) { return type; } @@ -3377,6 +3377,27 @@ namespace ts { return undefined; } + // Return the inferred type for a variable, parameter, or property declaration + function getWidenedTypeForJSSpecialPropertyDeclaration(declaration: Declaration): Type { + const expression = declaration.kind === SyntaxKind.BinaryExpression ? declaration : + declaration.kind === SyntaxKind.PropertyAccessExpression ? getAncestor(declaration, SyntaxKind.BinaryExpression) : + undefined; + + if (!expression) { + return unknownType; + } + + if (expression.flags & NodeFlags.JavaScriptFile) { + // If there is a JSDoc type, use it + const type = getTypeForDeclarationFromJSDocComment(expression.parent); + if (type && type !== unknownType) { + return getWidenedType(type); + } + } + + return getWidenedType(getWidenedLiteralType(checkExpressionCached(expression.right))); + } + // Return the type implied by a binding pattern element. This is the type of the initializer of the element if // one is present. Otherwise, if the element is itself a binding pattern, it is the type implied by the binding // pattern. Otherwise, it is the type any. @@ -3531,18 +3552,7 @@ namespace ts { // * className.prototype.method = expr if (declaration.kind === SyntaxKind.BinaryExpression || declaration.kind === SyntaxKind.PropertyAccessExpression && declaration.parent.kind === SyntaxKind.BinaryExpression) { - // Use JS Doc type if present on parent expression statement - if (declaration.flags & NodeFlags.JavaScriptFile) { - const jsdocType = getJSDocType(declaration.parent); - if (jsdocType) { - return links.type = getTypeFromTypeNode(jsdocType); - } - } - const declaredTypes = map(symbol.declarations, - decl => decl.kind === SyntaxKind.BinaryExpression ? - checkExpressionCached((decl).right) : - checkExpressionCached((decl.parent).right)); - type = getUnionType(declaredTypes, /*subtypeReduction*/ true); + type = getUnionType(map(symbol.declarations, getWidenedTypeForJSSpecialPropertyDeclaration), /*subtypeReduction*/ true); } else { type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true); @@ -3585,7 +3595,7 @@ namespace ts { const setter = getDeclarationOfKind(symbol, SyntaxKind.SetAccessor); if (getter && getter.flags & NodeFlags.JavaScriptFile) { - const jsDocType = getTypeForVariableLikeDeclarationFromJSDocComment(getter); + const jsDocType = getTypeForDeclarationFromJSDocComment(getter); if (jsDocType) { return links.type = jsDocType; } diff --git a/tests/baselines/reference/jsFileClassPropertyType.errors.txt b/tests/baselines/reference/jsFileClassPropertyType.errors.txt new file mode 100644 index 00000000000..f3767175710 --- /dev/null +++ b/tests/baselines/reference/jsFileClassPropertyType.errors.txt @@ -0,0 +1,17 @@ +tests/cases/compiler/bar.ts(2,1): error TS2322: Type '"string"' is not assignable to type 'number'. + + +==== tests/cases/compiler/foo.js (0 errors) ==== + + class C { + constructor () { + this.p = 0; + } + } + +==== tests/cases/compiler/bar.ts (1 errors) ==== + + (new C()).p = "string"; + ~~~~~~~~~~~ +!!! error TS2322: Type '"string"' is not assignable to type 'number'. + \ No newline at end of file diff --git a/tests/baselines/reference/jsFileClassPropertyType2.errors.txt b/tests/baselines/reference/jsFileClassPropertyType2.errors.txt new file mode 100644 index 00000000000..d0d138f7f48 --- /dev/null +++ b/tests/baselines/reference/jsFileClassPropertyType2.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/bar.ts(2,18): error TS2345: Argument of type '"string"' is not assignable to parameter of type 'number'. + + +==== tests/cases/compiler/foo.js (0 errors) ==== + + class C { + constructor() { + /** @type {number[]}*/ + this.p = []; + } + } + +==== tests/cases/compiler/bar.ts (1 errors) ==== + + (new C()).p.push("string"); + ~~~~~~~~ +!!! error TS2345: Argument of type '"string"' is not assignable to parameter of type 'number'. + \ No newline at end of file diff --git a/tests/baselines/reference/multipleDeclarations.types b/tests/baselines/reference/multipleDeclarations.types index 195bdc2ad0d..c11bd13dffe 100644 --- a/tests/baselines/reference/multipleDeclarations.types +++ b/tests/baselines/reference/multipleDeclarations.types @@ -21,7 +21,7 @@ C.prototype.m = function() { this.nothing(); >this.nothing() : any >this.nothing : any ->this : { m: () => void; } +>this : { m: any; } >nothing : any } class X { diff --git a/tests/baselines/reference/signaturesUseJSDocForOptionalParameters.types b/tests/baselines/reference/signaturesUseJSDocForOptionalParameters.types index f8822397306..99bf5e15fa7 100644 --- a/tests/baselines/reference/signaturesUseJSDocForOptionalParameters.types +++ b/tests/baselines/reference/signaturesUseJSDocForOptionalParameters.types @@ -15,39 +15,39 @@ function MyClass() { * @returns {MyClass} */ MyClass.prototype.optionalParam = function(required, notRequired) { ->MyClass.prototype.optionalParam = function(required, notRequired) { return this;} : (required: string, notRequired?: string) => { prop: null; optionalParam: any; } +>MyClass.prototype.optionalParam = function(required, notRequired) { return this;} : (required: string, notRequired?: string) => { prop: any; optionalParam: any; } >MyClass.prototype.optionalParam : any >MyClass.prototype : any >MyClass : () => void >prototype : any >optionalParam : any ->function(required, notRequired) { return this;} : (required: string, notRequired?: string) => { prop: null; optionalParam: any; } +>function(required, notRequired) { return this;} : (required: string, notRequired?: string) => { prop: any; optionalParam: any; } >required : string >notRequired : string return this; ->this : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } +>this : { prop: any; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } }; let pInst = new MyClass(); ->pInst : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } ->new MyClass() : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } +>pInst : { prop: any; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } +>new MyClass() : { prop: any; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } >MyClass : () => void let c1 = pInst.optionalParam('hello') ->c1 : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } ->pInst.optionalParam('hello') : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } ->pInst.optionalParam : (required: string, notRequired?: string) => { prop: null; optionalParam: any; } ->pInst : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } ->optionalParam : (required: string, notRequired?: string) => { prop: null; optionalParam: any; } +>c1 : { prop: any; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } +>pInst.optionalParam('hello') : { prop: any; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } +>pInst.optionalParam : (required: string, notRequired?: string) => { prop: any; optionalParam: any; } +>pInst : { prop: any; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } +>optionalParam : (required: string, notRequired?: string) => { prop: any; optionalParam: any; } >'hello' : "hello" let c2 = pInst.optionalParam('hello', null) ->c2 : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } ->pInst.optionalParam('hello', null) : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } ->pInst.optionalParam : (required: string, notRequired?: string) => { prop: null; optionalParam: any; } ->pInst : { prop: null; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } ->optionalParam : (required: string, notRequired?: string) => { prop: null; optionalParam: any; } +>c2 : { prop: any; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } +>pInst.optionalParam('hello', null) : { prop: any; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } +>pInst.optionalParam : (required: string, notRequired?: string) => { prop: any; optionalParam: any; } +>pInst : { prop: any; optionalParam: (required: string, notRequired?: string) => typeof MyClass; } +>optionalParam : (required: string, notRequired?: string) => { prop: any; optionalParam: any; } >'hello' : "hello" >null : null diff --git a/tests/cases/compiler/jsFileClassPropertyType.ts b/tests/cases/compiler/jsFileClassPropertyType.ts new file mode 100644 index 00000000000..53540096721 --- /dev/null +++ b/tests/cases/compiler/jsFileClassPropertyType.ts @@ -0,0 +1,13 @@ +// @allowJs: true +// @noEmit: true + +// @filename: foo.js +class C { + constructor () { + this.p = 0; + } +} + +// @filename: bar.ts + +(new C()).p = "string"; diff --git a/tests/cases/compiler/jsFileClassPropertyType2.ts b/tests/cases/compiler/jsFileClassPropertyType2.ts new file mode 100644 index 00000000000..82c36f53147 --- /dev/null +++ b/tests/cases/compiler/jsFileClassPropertyType2.ts @@ -0,0 +1,14 @@ +// @allowJs: true +// @noEmit: true + +// @filename: foo.js +class C { + constructor() { + /** @type {number[]}*/ + this.p = []; + } +} + +// @filename: bar.ts + +(new C()).p.push("string"); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics24.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics24.ts index d93ec4c1914..59be947e3a1 100644 --- a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics24.ts +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics24.ts @@ -12,4 +12,4 @@ //// let x = new Person(100); //// x.canVote/**/; -verify.quickInfoAt("", "(property) Person.canVote: true | 23"); +verify.quickInfoAt("", "(property) Person.canVote: number | boolean"); From 188e9df9b55d15b003852632c14425ffe92823e5 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Mon, 6 Feb 2017 18:13:17 -0800 Subject: [PATCH 03/16] Emit missing trailing comment of an element in node list --- src/compiler/comments.ts | 6 ++++++ src/compiler/emitter.ts | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/compiler/comments.ts b/src/compiler/comments.ts index 200158c2f5c..8e17bf2d91b 100644 --- a/src/compiler/comments.ts +++ b/src/compiler/comments.ts @@ -9,6 +9,7 @@ namespace ts { emitNodeWithComments(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void): void; emitBodyWithDetachedComments(node: Node, detachedRange: TextRange, emitCallback: (node: Node) => void): void; emitTrailingCommentsOfPosition(pos: number): void; + emitLeadingComments(pos: number, isEmittedNode: boolean): void; } export function createCommentWriter(printerOptions: PrinterOptions, emitPos: ((pos: number) => void) | undefined): CommentWriter { @@ -32,6 +33,7 @@ namespace ts { emitNodeWithComments, emitBodyWithDetachedComments, emitTrailingCommentsOfPosition, + emitLeadingComments, }; function emitNodeWithComments(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) { @@ -167,6 +169,10 @@ namespace ts { } function emitLeadingComments(pos: number, isEmittedNode: boolean) { + if (disabled) { + return; + } + hasWrittenComment = false; if (isEmittedNode) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 498f65ad366..d3e46f0827d 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -211,6 +211,7 @@ namespace ts { emitNodeWithComments, emitBodyWithDetachedComments, emitTrailingCommentsOfPosition, + emitLeadingComments, } = comments; let currentSourceFile: SourceFile; @@ -2228,6 +2229,15 @@ namespace ts { // Write the delimiter if this is not the first node. if (previousSibling) { + // i.e + // function commentedParameters( + // /* Parameter a */ + // a + // /* End of parameter a */ -> this comment doesn't consider to be trailing comment of parameter "a" due to newline + // , + if (emitLeadingComments && delimiter && previousSibling.end !== parentNode.end) { + emitLeadingComments(previousSibling.end, /*isEmittedNode*/ previousSibling.kind !== SyntaxKind.NotEmittedStatement); + } write(delimiter); // Write either a line terminator or whitespace to separate the elements. @@ -2274,6 +2284,20 @@ namespace ts { write(","); } + + // Emit any trailing comment of the last element in the list + // i.e + // var array = [... + // 2 + // /* end of element 2 */ + // ]; + if (previousSibling && delimiter && previousSibling.end !== parentNode.end) { + emitLeadingComments(previousSibling.end, /*isEmittedNode*/ previousSibling.kind !== SyntaxKind.NotEmittedStatement); + if (hasTrailingComma) { + emitLeadingComments(previousSibling.end, /*isEmittedNode*/ previousSibling.kind !== SyntaxKind.NotEmittedStatement); + } + } + // Decrease the indent, if requested. if (format & ListFormat.Indented) { decreaseIndent(); From 7fd404dbbc20611bca81f8cde3a07c91e69ee13f Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Mon, 6 Feb 2017 18:14:08 -0800 Subject: [PATCH 04/16] Add tests and update baselines --- .../reference/arrowFunctionErrorSpan.js | 4 +++- .../reference/commentOnArrayElement1.js | 17 ++++++++++++++++ .../reference/commentOnArrayElement1.symbols | 10 ++++++++++ .../reference/commentOnArrayElement1.types | 15 ++++++++++++++ .../reference/commentOnArrayElement2.js | 15 ++++++++++++++ .../reference/commentOnArrayElement2.symbols | 9 +++++++++ .../reference/commentOnArrayElement2.types | 14 +++++++++++++ .../reference/commentOnArrayElement3.js | 19 ++++++++++++++++++ .../reference/commentOnArrayElement3.symbols | 11 ++++++++++ .../reference/commentOnArrayElement3.types | 18 +++++++++++++++++ .../reference/commentOnParameter1.js | 20 +++++++++++++++++++ .../reference/commentOnParameter1.symbols | 16 +++++++++++++++ .../reference/commentOnParameter1.types | 16 +++++++++++++++ .../reference/commentOnParameter2.js | 18 +++++++++++++++++ .../reference/commentOnParameter2.symbols | 15 ++++++++++++++ .../reference/commentOnParameter2.types | 15 ++++++++++++++ .../reference/commentOnParameter3.js | 9 +++++++++ .../reference/commentOnParameter3.symbols | 12 +++++++++++ .../reference/commentOnParameter3.types | 12 +++++++++++ .../cases/compiler/commentOnArrayElement1.ts | 7 +++++++ .../cases/compiler/commentOnArrayElement2.ts | 6 ++++++ .../cases/compiler/commentOnArrayElement3.ts | 8 ++++++++ tests/cases/compiler/commentOnParameter1.ts | 9 +++++++++ tests/cases/compiler/commentOnParameter2.ts | 8 ++++++++ tests/cases/compiler/commentOnParameter3.ts | 5 +++++ 25 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/commentOnArrayElement1.js create mode 100644 tests/baselines/reference/commentOnArrayElement1.symbols create mode 100644 tests/baselines/reference/commentOnArrayElement1.types create mode 100644 tests/baselines/reference/commentOnArrayElement2.js create mode 100644 tests/baselines/reference/commentOnArrayElement2.symbols create mode 100644 tests/baselines/reference/commentOnArrayElement2.types create mode 100644 tests/baselines/reference/commentOnArrayElement3.js create mode 100644 tests/baselines/reference/commentOnArrayElement3.symbols create mode 100644 tests/baselines/reference/commentOnArrayElement3.types create mode 100644 tests/baselines/reference/commentOnParameter1.js create mode 100644 tests/baselines/reference/commentOnParameter1.symbols create mode 100644 tests/baselines/reference/commentOnParameter1.types create mode 100644 tests/baselines/reference/commentOnParameter2.js create mode 100644 tests/baselines/reference/commentOnParameter2.symbols create mode 100644 tests/baselines/reference/commentOnParameter2.types create mode 100644 tests/baselines/reference/commentOnParameter3.js create mode 100644 tests/baselines/reference/commentOnParameter3.symbols create mode 100644 tests/baselines/reference/commentOnParameter3.types create mode 100644 tests/cases/compiler/commentOnArrayElement1.ts create mode 100644 tests/cases/compiler/commentOnArrayElement2.ts create mode 100644 tests/cases/compiler/commentOnArrayElement3.ts create mode 100644 tests/cases/compiler/commentOnParameter1.ts create mode 100644 tests/cases/compiler/commentOnParameter2.ts create mode 100644 tests/cases/compiler/commentOnParameter3.ts diff --git a/tests/baselines/reference/arrowFunctionErrorSpan.js b/tests/baselines/reference/arrowFunctionErrorSpan.js index 2557113e89b..ca1f966f517 100644 --- a/tests/baselines/reference/arrowFunctionErrorSpan.js +++ b/tests/baselines/reference/arrowFunctionErrorSpan.js @@ -83,7 +83,9 @@ f(// comment 1 // comment 2 function () { // comment 4 -}); +} +// comment 5 +); // body is not a block f(function (_) { return 1 + 2; }); diff --git a/tests/baselines/reference/commentOnArrayElement1.js b/tests/baselines/reference/commentOnArrayElement1.js new file mode 100644 index 00000000000..960df336dbb --- /dev/null +++ b/tests/baselines/reference/commentOnArrayElement1.js @@ -0,0 +1,17 @@ +//// [commentOnArrayElement1.ts] +var array = [ + /* element 1*/ + 1 + /* end of element 1 */, + 2 + /* end of element 2 */ +]; + +//// [commentOnArrayElement1.js] +var array = [ + /* element 1*/ + 1 + /* end of element 1 */ , + 2 + /* end of element 2 */ +]; diff --git a/tests/baselines/reference/commentOnArrayElement1.symbols b/tests/baselines/reference/commentOnArrayElement1.symbols new file mode 100644 index 00000000000..a504aec5c32 --- /dev/null +++ b/tests/baselines/reference/commentOnArrayElement1.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/commentOnArrayElement1.ts === +var array = [ +>array : Symbol(array, Decl(commentOnArrayElement1.ts, 0, 3)) + + /* element 1*/ + 1 + /* end of element 1 */, + 2 + /* end of element 2 */ +]; diff --git a/tests/baselines/reference/commentOnArrayElement1.types b/tests/baselines/reference/commentOnArrayElement1.types new file mode 100644 index 00000000000..f6b541ec300 --- /dev/null +++ b/tests/baselines/reference/commentOnArrayElement1.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/commentOnArrayElement1.ts === +var array = [ +>array : number[] +>[ /* element 1*/ 1 /* end of element 1 */, 2 /* end of element 2 */] : number[] + + /* element 1*/ + 1 +>1 : 1 + + /* end of element 1 */, + 2 +>2 : 2 + + /* end of element 2 */ +]; diff --git a/tests/baselines/reference/commentOnArrayElement2.js b/tests/baselines/reference/commentOnArrayElement2.js new file mode 100644 index 00000000000..1c146caed65 --- /dev/null +++ b/tests/baselines/reference/commentOnArrayElement2.js @@ -0,0 +1,15 @@ +//// [commentOnArrayElement2.ts] +var array = [ + /* element 1*/ + 1 /* end of element 1 */, + 2 + /* end of element 2 */ +]; + +//// [commentOnArrayElement2.js] +var array = [ + /* element 1*/ + 1 /* end of element 1 */, + 2 + /* end of element 2 */ +]; diff --git a/tests/baselines/reference/commentOnArrayElement2.symbols b/tests/baselines/reference/commentOnArrayElement2.symbols new file mode 100644 index 00000000000..7a6c231664b --- /dev/null +++ b/tests/baselines/reference/commentOnArrayElement2.symbols @@ -0,0 +1,9 @@ +=== tests/cases/compiler/commentOnArrayElement2.ts === +var array = [ +>array : Symbol(array, Decl(commentOnArrayElement2.ts, 0, 3)) + + /* element 1*/ + 1 /* end of element 1 */, + 2 + /* end of element 2 */ +]; diff --git a/tests/baselines/reference/commentOnArrayElement2.types b/tests/baselines/reference/commentOnArrayElement2.types new file mode 100644 index 00000000000..85647da74e0 --- /dev/null +++ b/tests/baselines/reference/commentOnArrayElement2.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/commentOnArrayElement2.ts === +var array = [ +>array : number[] +>[ /* element 1*/ 1 /* end of element 1 */, 2 /* end of element 2 */] : number[] + + /* element 1*/ + 1 /* end of element 1 */, +>1 : 1 + + 2 +>2 : 2 + + /* end of element 2 */ +]; diff --git a/tests/baselines/reference/commentOnArrayElement3.js b/tests/baselines/reference/commentOnArrayElement3.js new file mode 100644 index 00000000000..e31f8adf26a --- /dev/null +++ b/tests/baselines/reference/commentOnArrayElement3.js @@ -0,0 +1,19 @@ +//// [commentOnArrayElement3.ts] +var array = [ + /* element 1*/ + 1 + /* end of element 1 */, + 2 + /* end of element 2 */, , + /* extra comment */ +]; + +//// [commentOnArrayElement3.js] +var array = [ + /* element 1*/ + 1 + /* end of element 1 */ , + 2 + /* end of element 2 */ , + , +]; diff --git a/tests/baselines/reference/commentOnArrayElement3.symbols b/tests/baselines/reference/commentOnArrayElement3.symbols new file mode 100644 index 00000000000..a1c61f7155a --- /dev/null +++ b/tests/baselines/reference/commentOnArrayElement3.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/commentOnArrayElement3.ts === +var array = [ +>array : Symbol(array, Decl(commentOnArrayElement3.ts, 0, 3)) + + /* element 1*/ + 1 + /* end of element 1 */, + 2 + /* end of element 2 */, , + /* extra comment */ +]; diff --git a/tests/baselines/reference/commentOnArrayElement3.types b/tests/baselines/reference/commentOnArrayElement3.types new file mode 100644 index 00000000000..cd75c5a8db9 --- /dev/null +++ b/tests/baselines/reference/commentOnArrayElement3.types @@ -0,0 +1,18 @@ +=== tests/cases/compiler/commentOnArrayElement3.ts === +var array = [ +>array : number[] +>[ /* element 1*/ 1 /* end of element 1 */, 2 /* end of element 2 */, , /* extra comment */] : number[] + + /* element 1*/ + 1 +>1 : 1 + + /* end of element 1 */, + 2 +>2 : 2 + + /* end of element 2 */, , +> : undefined + + /* extra comment */ +]; diff --git a/tests/baselines/reference/commentOnParameter1.js b/tests/baselines/reference/commentOnParameter1.js new file mode 100644 index 00000000000..10ae2af1264 --- /dev/null +++ b/tests/baselines/reference/commentOnParameter1.js @@ -0,0 +1,20 @@ +//// [commentOnParameter1.ts] +function commentedParameters( +/* Parameter a */ +a +/* End of parameter a */ +/* Parameter b */ +, +b +/* End of parameter b */ +){} + +//// [commentOnParameter1.js] +function commentedParameters( + /* Parameter a */ + a + /* End of parameter a */ + /* Parameter b */ + , b + /* End of parameter b */ +) { } diff --git a/tests/baselines/reference/commentOnParameter1.symbols b/tests/baselines/reference/commentOnParameter1.symbols new file mode 100644 index 00000000000..13d91ac7abb --- /dev/null +++ b/tests/baselines/reference/commentOnParameter1.symbols @@ -0,0 +1,16 @@ +=== tests/cases/compiler/commentOnParameter1.ts === +function commentedParameters( +>commentedParameters : Symbol(commentedParameters, Decl(commentOnParameter1.ts, 0, 0)) + +/* Parameter a */ +a +>a : Symbol(a, Decl(commentOnParameter1.ts, 0, 29)) + +/* End of parameter a */ +/* Parameter b */ +, +b +>b : Symbol(b, Decl(commentOnParameter1.ts, 5, 1)) + +/* End of parameter b */ +){} diff --git a/tests/baselines/reference/commentOnParameter1.types b/tests/baselines/reference/commentOnParameter1.types new file mode 100644 index 00000000000..2a98a9a3f6f --- /dev/null +++ b/tests/baselines/reference/commentOnParameter1.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/commentOnParameter1.ts === +function commentedParameters( +>commentedParameters : (a: any, b: any) => void + +/* Parameter a */ +a +>a : any + +/* End of parameter a */ +/* Parameter b */ +, +b +>b : any + +/* End of parameter b */ +){} diff --git a/tests/baselines/reference/commentOnParameter2.js b/tests/baselines/reference/commentOnParameter2.js new file mode 100644 index 00000000000..d0c024a6b3b --- /dev/null +++ b/tests/baselines/reference/commentOnParameter2.js @@ -0,0 +1,18 @@ +//// [commentOnParameter2.ts] +function commentedParameters( +/* Parameter a */ +a /* End of parameter a */ +/* Parameter b */ +, +b +/* End of parameter b */ +){} + +//// [commentOnParameter2.js] +function commentedParameters( + /* Parameter a */ + a /* End of parameter a */ + /* Parameter b */ + , b + /* End of parameter b */ +) { } diff --git a/tests/baselines/reference/commentOnParameter2.symbols b/tests/baselines/reference/commentOnParameter2.symbols new file mode 100644 index 00000000000..5a6e904ed0b --- /dev/null +++ b/tests/baselines/reference/commentOnParameter2.symbols @@ -0,0 +1,15 @@ +=== tests/cases/compiler/commentOnParameter2.ts === +function commentedParameters( +>commentedParameters : Symbol(commentedParameters, Decl(commentOnParameter2.ts, 0, 0)) + +/* Parameter a */ +a /* End of parameter a */ +>a : Symbol(a, Decl(commentOnParameter2.ts, 0, 29)) + +/* Parameter b */ +, +b +>b : Symbol(b, Decl(commentOnParameter2.ts, 4, 1)) + +/* End of parameter b */ +){} diff --git a/tests/baselines/reference/commentOnParameter2.types b/tests/baselines/reference/commentOnParameter2.types new file mode 100644 index 00000000000..2d4c14db809 --- /dev/null +++ b/tests/baselines/reference/commentOnParameter2.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/commentOnParameter2.ts === +function commentedParameters( +>commentedParameters : (a: any, b: any) => void + +/* Parameter a */ +a /* End of parameter a */ +>a : any + +/* Parameter b */ +, +b +>b : any + +/* End of parameter b */ +){} diff --git a/tests/baselines/reference/commentOnParameter3.js b/tests/baselines/reference/commentOnParameter3.js new file mode 100644 index 00000000000..56172af473c --- /dev/null +++ b/tests/baselines/reference/commentOnParameter3.js @@ -0,0 +1,9 @@ +//// [commentOnParameter3.ts] +function commentedParameters( +a /* parameter a */, +b /* parameter b */, +/* extra comment */ +) { } + +//// [commentOnParameter3.js] +function commentedParameters(a /* parameter a */, b /* parameter b */) { } diff --git a/tests/baselines/reference/commentOnParameter3.symbols b/tests/baselines/reference/commentOnParameter3.symbols new file mode 100644 index 00000000000..4dda5f6d0e8 --- /dev/null +++ b/tests/baselines/reference/commentOnParameter3.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/commentOnParameter3.ts === +function commentedParameters( +>commentedParameters : Symbol(commentedParameters, Decl(commentOnParameter3.ts, 0, 0)) + +a /* parameter a */, +>a : Symbol(a, Decl(commentOnParameter3.ts, 0, 29)) + +b /* parameter b */, +>b : Symbol(b, Decl(commentOnParameter3.ts, 1, 20)) + +/* extra comment */ +) { } diff --git a/tests/baselines/reference/commentOnParameter3.types b/tests/baselines/reference/commentOnParameter3.types new file mode 100644 index 00000000000..f5b23dbceb3 --- /dev/null +++ b/tests/baselines/reference/commentOnParameter3.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/commentOnParameter3.ts === +function commentedParameters( +>commentedParameters : (a: any, b: any) => void + +a /* parameter a */, +>a : any + +b /* parameter b */, +>b : any + +/* extra comment */ +) { } diff --git a/tests/cases/compiler/commentOnArrayElement1.ts b/tests/cases/compiler/commentOnArrayElement1.ts new file mode 100644 index 00000000000..3dc4ce29bf1 --- /dev/null +++ b/tests/cases/compiler/commentOnArrayElement1.ts @@ -0,0 +1,7 @@ +var array = [ + /* element 1*/ + 1 + /* end of element 1 */, + 2 + /* end of element 2 */ +]; \ No newline at end of file diff --git a/tests/cases/compiler/commentOnArrayElement2.ts b/tests/cases/compiler/commentOnArrayElement2.ts new file mode 100644 index 00000000000..80c7f8fb1a7 --- /dev/null +++ b/tests/cases/compiler/commentOnArrayElement2.ts @@ -0,0 +1,6 @@ +var array = [ + /* element 1*/ + 1 /* end of element 1 */, + 2 + /* end of element 2 */ +]; \ No newline at end of file diff --git a/tests/cases/compiler/commentOnArrayElement3.ts b/tests/cases/compiler/commentOnArrayElement3.ts new file mode 100644 index 00000000000..26de853f3e9 --- /dev/null +++ b/tests/cases/compiler/commentOnArrayElement3.ts @@ -0,0 +1,8 @@ +var array = [ + /* element 1*/ + 1 + /* end of element 1 */, + 2 + /* end of element 2 */, , + /* extra comment */ +]; \ No newline at end of file diff --git a/tests/cases/compiler/commentOnParameter1.ts b/tests/cases/compiler/commentOnParameter1.ts new file mode 100644 index 00000000000..6a17c90950c --- /dev/null +++ b/tests/cases/compiler/commentOnParameter1.ts @@ -0,0 +1,9 @@ +function commentedParameters( +/* Parameter a */ +a +/* End of parameter a */ +/* Parameter b */ +, +b +/* End of parameter b */ +){} \ No newline at end of file diff --git a/tests/cases/compiler/commentOnParameter2.ts b/tests/cases/compiler/commentOnParameter2.ts new file mode 100644 index 00000000000..2722eab554b --- /dev/null +++ b/tests/cases/compiler/commentOnParameter2.ts @@ -0,0 +1,8 @@ +function commentedParameters( +/* Parameter a */ +a /* End of parameter a */ +/* Parameter b */ +, +b +/* End of parameter b */ +){} \ No newline at end of file diff --git a/tests/cases/compiler/commentOnParameter3.ts b/tests/cases/compiler/commentOnParameter3.ts new file mode 100644 index 00000000000..57eda10f338 --- /dev/null +++ b/tests/cases/compiler/commentOnParameter3.ts @@ -0,0 +1,5 @@ +function commentedParameters( +a /* parameter a */, +b /* parameter b */, +/* extra comment */ +) { } \ No newline at end of file From 80eae169ee2d2b114ed25f9af275923f5e4c511f Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Tue, 7 Feb 2017 11:56:44 -0800 Subject: [PATCH 05/16] Emit leading comment before brace token --- src/compiler/emitter.ts | 2 ++ .../reference/amdImportAsPrimaryExpression.js | 1 + tests/baselines/reference/argsInScope.js | 1 + .../reference/commentLeadingCloseBrace.js | 24 +++++++++++++ .../commentLeadingCloseBrace.symbols | 21 ++++++++++++ .../reference/commentLeadingCloseBrace.types | 30 ++++++++++++++++ .../commonJSImportAsPrimaryExpression.js | 1 + .../reference/duplicateLocalVariable1.js | 1 + .../jsFileCompilationLetBeingRenamed.js | 1 + .../narrowExceptionVariableInCatchClause.js | 1 + tests/baselines/reference/noCatchBlock.js | 2 ++ tests/baselines/reference/noCatchBlock.js.map | 2 +- .../reference/noCatchBlock.sourcemap.txt | 34 ++++++++++++++----- tests/baselines/reference/objectRestForOf.js | 1 + .../baselines/reference/parserRealSource14.js | 1 + tests/baselines/reference/recursiveReturns.js | 1 + .../reference/sourceMap-SkippedNode.js | 2 ++ .../reference/sourceMap-SkippedNode.js.map | 2 +- .../sourceMap-SkippedNode.sourcemap.txt | 34 ++++++++++++++----- .../compiler/commentLeadingCloseBrace.ts | 11 ++++++ 20 files changed, 155 insertions(+), 18 deletions(-) create mode 100644 tests/baselines/reference/commentLeadingCloseBrace.js create mode 100644 tests/baselines/reference/commentLeadingCloseBrace.symbols create mode 100644 tests/baselines/reference/commentLeadingCloseBrace.types create mode 100644 tests/cases/compiler/commentLeadingCloseBrace.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d3e46f0827d..7adac106e8c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1347,6 +1347,8 @@ namespace ts { else { writeToken(SyntaxKind.OpenBraceToken, node.pos, /*contextNode*/ node); emitBlockStatements(node); + // We have to call emitLeadingComments explicitly here because otherwise leading comments of the close brace token will not be emitted + emitLeadingComments(node.statements.end, /*isEmittedNode*/true); writeToken(SyntaxKind.CloseBraceToken, node.statements.end, /*contextNode*/ node); } } diff --git a/tests/baselines/reference/amdImportAsPrimaryExpression.js b/tests/baselines/reference/amdImportAsPrimaryExpression.js index 3c2e9c041fa..25f390c0b32 100644 --- a/tests/baselines/reference/amdImportAsPrimaryExpression.js +++ b/tests/baselines/reference/amdImportAsPrimaryExpression.js @@ -26,5 +26,6 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports", "./foo_0"], function (require, exports, foo) { "use strict"; if (foo.E1.A === 0) { + // Should cause runtime import - interesting optimization possibility, as gets inlined to 0. } }); diff --git a/tests/baselines/reference/argsInScope.js b/tests/baselines/reference/argsInScope.js index 90906426d24..27405a47d87 100644 --- a/tests/baselines/reference/argsInScope.js +++ b/tests/baselines/reference/argsInScope.js @@ -17,6 +17,7 @@ var C = (function () { } C.prototype.P = function (ii, j, k) { for (var i = 0; i < arguments.length; i++) { + // WScript.Echo("param: " + arguments[i]); } }; return C; diff --git a/tests/baselines/reference/commentLeadingCloseBrace.js b/tests/baselines/reference/commentLeadingCloseBrace.js new file mode 100644 index 00000000000..9fc696219e1 --- /dev/null +++ b/tests/baselines/reference/commentLeadingCloseBrace.js @@ -0,0 +1,24 @@ +//// [commentLeadingCloseBrace.ts] +declare function commentedParameters(...args): any; + +function ifelse() { + if (commentedParameters(1, 2)) { + /*comment1*/ + commentedParameters(3, 4); + /*comment2*/ + } else { + commentedParameters(5, 6); + } +} + +//// [commentLeadingCloseBrace.js] +function ifelse() { + if (commentedParameters(1, 2)) { + /*comment1*/ + commentedParameters(3, 4); + /*comment2*/ + } + else { + commentedParameters(5, 6); + } +} diff --git a/tests/baselines/reference/commentLeadingCloseBrace.symbols b/tests/baselines/reference/commentLeadingCloseBrace.symbols new file mode 100644 index 00000000000..72dcfb1e047 --- /dev/null +++ b/tests/baselines/reference/commentLeadingCloseBrace.symbols @@ -0,0 +1,21 @@ +=== tests/cases/compiler/commentLeadingCloseBrace.ts === +declare function commentedParameters(...args): any; +>commentedParameters : Symbol(commentedParameters, Decl(commentLeadingCloseBrace.ts, 0, 0)) +>args : Symbol(args, Decl(commentLeadingCloseBrace.ts, 0, 37)) + +function ifelse() { +>ifelse : Symbol(ifelse, Decl(commentLeadingCloseBrace.ts, 0, 51)) + + if (commentedParameters(1, 2)) { +>commentedParameters : Symbol(commentedParameters, Decl(commentLeadingCloseBrace.ts, 0, 0)) + + /*comment1*/ + commentedParameters(3, 4); +>commentedParameters : Symbol(commentedParameters, Decl(commentLeadingCloseBrace.ts, 0, 0)) + + /*comment2*/ + } else { + commentedParameters(5, 6); +>commentedParameters : Symbol(commentedParameters, Decl(commentLeadingCloseBrace.ts, 0, 0)) + } +} diff --git a/tests/baselines/reference/commentLeadingCloseBrace.types b/tests/baselines/reference/commentLeadingCloseBrace.types new file mode 100644 index 00000000000..444320737a6 --- /dev/null +++ b/tests/baselines/reference/commentLeadingCloseBrace.types @@ -0,0 +1,30 @@ +=== tests/cases/compiler/commentLeadingCloseBrace.ts === +declare function commentedParameters(...args): any; +>commentedParameters : (...args: any[]) => any +>args : any[] + +function ifelse() { +>ifelse : () => void + + if (commentedParameters(1, 2)) { +>commentedParameters(1, 2) : any +>commentedParameters : (...args: any[]) => any +>1 : 1 +>2 : 2 + + /*comment1*/ + commentedParameters(3, 4); +>commentedParameters(3, 4) : any +>commentedParameters : (...args: any[]) => any +>3 : 3 +>4 : 4 + + /*comment2*/ + } else { + commentedParameters(5, 6); +>commentedParameters(5, 6) : any +>commentedParameters : (...args: any[]) => any +>5 : 5 +>6 : 6 + } +} diff --git a/tests/baselines/reference/commonJSImportAsPrimaryExpression.js b/tests/baselines/reference/commonJSImportAsPrimaryExpression.js index b8cf42ea762..1eb7b5ff214 100644 --- a/tests/baselines/reference/commonJSImportAsPrimaryExpression.js +++ b/tests/baselines/reference/commonJSImportAsPrimaryExpression.js @@ -27,4 +27,5 @@ exports.C1 = C1; "use strict"; var foo = require("./foo_0"); if (foo.C1.s1) { +// Should cause runtime import } diff --git a/tests/baselines/reference/duplicateLocalVariable1.js b/tests/baselines/reference/duplicateLocalVariable1.js index 734b01eaed7..432830d85b6 100644 --- a/tests/baselines/reference/duplicateLocalVariable1.js +++ b/tests/baselines/reference/duplicateLocalVariable1.js @@ -391,6 +391,7 @@ var TestRunner = (function () { } } if (testResult === false) { + //console.log(e.message); } } if ((testcase.errorMessageRegEx !== undefined) && !exception) { diff --git a/tests/baselines/reference/jsFileCompilationLetBeingRenamed.js b/tests/baselines/reference/jsFileCompilationLetBeingRenamed.js index c9e16f35981..bb2aa10dc95 100644 --- a/tests/baselines/reference/jsFileCompilationLetBeingRenamed.js +++ b/tests/baselines/reference/jsFileCompilationLetBeingRenamed.js @@ -9,5 +9,6 @@ function foo(a) { //// [out.js] function foo(a) { for (var a_1 = 0; a_1 < 10; a_1++) { + // do something } } diff --git a/tests/baselines/reference/narrowExceptionVariableInCatchClause.js b/tests/baselines/reference/narrowExceptionVariableInCatchClause.js index 5808ed76826..18344df5994 100644 --- a/tests/baselines/reference/narrowExceptionVariableInCatchClause.js +++ b/tests/baselines/reference/narrowExceptionVariableInCatchClause.js @@ -27,6 +27,7 @@ function tryCatch() { //// [narrowExceptionVariableInCatchClause.js] function tryCatch() { try { + // do stuff... } catch (err) { if (isFooError(err)) { diff --git a/tests/baselines/reference/noCatchBlock.js b/tests/baselines/reference/noCatchBlock.js index 7b0404c3cad..158ac1257f3 100644 --- a/tests/baselines/reference/noCatchBlock.js +++ b/tests/baselines/reference/noCatchBlock.js @@ -8,7 +8,9 @@ try { //// [noCatchBlock.js] try { +// ... } finally { +// N.B. No 'catch' block } //# sourceMappingURL=noCatchBlock.js.map \ No newline at end of file diff --git a/tests/baselines/reference/noCatchBlock.js.map b/tests/baselines/reference/noCatchBlock.js.map index 149a2167f46..ddac2894e0b 100644 --- a/tests/baselines/reference/noCatchBlock.js.map +++ b/tests/baselines/reference/noCatchBlock.js.map @@ -1,2 +1,2 @@ //// [noCatchBlock.js.map] -{"version":3,"file":"noCatchBlock.js","sourceRoot":"","sources":["noCatchBlock.ts"],"names":[],"mappings":"AACA,IAAI,CAAC;AAEL,CAAC;QAAS,CAAC;AAEX,CAAC"} \ No newline at end of file +{"version":3,"file":"noCatchBlock.js","sourceRoot":"","sources":["noCatchBlock.ts"],"names":[],"mappings":"AACA,IAAI,CAAC;AACJ,MAAM;AACP,CAAC;QAAS,CAAC;AACV,wBAAwB;AACzB,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/noCatchBlock.sourcemap.txt b/tests/baselines/reference/noCatchBlock.sourcemap.txt index 18cb0d5a479..a75c119ca9f 100644 --- a/tests/baselines/reference/noCatchBlock.sourcemap.txt +++ b/tests/baselines/reference/noCatchBlock.sourcemap.txt @@ -12,6 +12,7 @@ sourceFile:noCatchBlock.ts 1 > 2 >^^^^ 3 > ^ +4 > ^^-> 1 > > 2 >try @@ -20,34 +21,51 @@ sourceFile:noCatchBlock.ts 2 >Emitted(1, 5) Source(2, 5) + SourceIndex(0) 3 >Emitted(1, 6) Source(2, 6) + SourceIndex(0) --- +>>>// ... +1-> +2 >^^^^^^ +1-> + > +2 >// ... +1->Emitted(2, 1) Source(3, 2) + SourceIndex(0) +2 >Emitted(2, 7) Source(3, 8) + SourceIndex(0) +--- >>>} 1 > 2 >^ 3 > ^^^^^^^^^-> 1 > - > // ... > 2 >} -1 >Emitted(2, 1) Source(4, 1) + SourceIndex(0) -2 >Emitted(2, 2) Source(4, 2) + SourceIndex(0) +1 >Emitted(3, 1) Source(4, 1) + SourceIndex(0) +2 >Emitted(3, 2) Source(4, 2) + SourceIndex(0) --- >>>finally { 1->^^^^^^^^ 2 > ^ +3 > ^^^^^^^^^^^^^^^^-> 1-> finally 2 > { -1->Emitted(3, 9) Source(4, 11) + SourceIndex(0) -2 >Emitted(3, 10) Source(4, 12) + SourceIndex(0) +1->Emitted(4, 9) Source(4, 11) + SourceIndex(0) +2 >Emitted(4, 10) Source(4, 12) + SourceIndex(0) +--- +>>>// N.B. No 'catch' block +1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^ +1-> + > +2 >// N.B. No 'catch' block +1->Emitted(5, 1) Source(5, 2) + SourceIndex(0) +2 >Emitted(5, 25) Source(5, 26) + SourceIndex(0) --- >>>} 1 > 2 >^ 3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > - > // N.B. No 'catch' block > 2 >} -1 >Emitted(4, 1) Source(6, 1) + SourceIndex(0) -2 >Emitted(4, 2) Source(6, 2) + SourceIndex(0) +1 >Emitted(6, 1) Source(6, 1) + SourceIndex(0) +2 >Emitted(6, 2) Source(6, 2) + SourceIndex(0) --- >>>//# sourceMappingURL=noCatchBlock.js.map \ No newline at end of file diff --git a/tests/baselines/reference/objectRestForOf.js b/tests/baselines/reference/objectRestForOf.js index f8a88fe2868..5f0399b2df2 100644 --- a/tests/baselines/reference/objectRestForOf.js +++ b/tests/baselines/reference/objectRestForOf.js @@ -37,4 +37,5 @@ for (let _b of array) { } for (const norest of array.map(a => (Object.assign({}, a, { x: 'a string' })))) { [norest.x, norest.y]; +// x is now a string. who knows why. } diff --git a/tests/baselines/reference/parserRealSource14.js b/tests/baselines/reference/parserRealSource14.js index 907efc6f26a..4e4e23e81c3 100644 --- a/tests/baselines/reference/parserRealSource14.js +++ b/tests/baselines/reference/parserRealSource14.js @@ -1011,6 +1011,7 @@ var TypeScript; ctx.path.push(cur); } else { + //logger.log("TODO: Ignoring node because minChar, limChar not better than previous node in stack"); } } // The AST walker skips comments, but we might be in one, so check the pre/post comments for this node manually diff --git a/tests/baselines/reference/recursiveReturns.js b/tests/baselines/reference/recursiveReturns.js index 18c9ed4dd7c..56762a9ad2d 100644 --- a/tests/baselines/reference/recursiveReturns.js +++ b/tests/baselines/reference/recursiveReturns.js @@ -23,6 +23,7 @@ function R1() { function R2() { R2(); } function R3(n) { if (n == 0) { + //return; } else { R3(n--); diff --git a/tests/baselines/reference/sourceMap-SkippedNode.js b/tests/baselines/reference/sourceMap-SkippedNode.js index 656b5a244e9..daac27cf49f 100644 --- a/tests/baselines/reference/sourceMap-SkippedNode.js +++ b/tests/baselines/reference/sourceMap-SkippedNode.js @@ -7,7 +7,9 @@ try { //// [sourceMap-SkippedNode.js] try { +// ... } finally { +// N.B. No 'catch' block } //# sourceMappingURL=sourceMap-SkippedNode.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMap-SkippedNode.js.map b/tests/baselines/reference/sourceMap-SkippedNode.js.map index 77340424640..b86b3905a73 100644 --- a/tests/baselines/reference/sourceMap-SkippedNode.js.map +++ b/tests/baselines/reference/sourceMap-SkippedNode.js.map @@ -1,2 +1,2 @@ //// [sourceMap-SkippedNode.js.map] -{"version":3,"file":"sourceMap-SkippedNode.js","sourceRoot":"","sources":["sourceMap-SkippedNode.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC;AAEL,CAAC;QAAS,CAAC;AAEX,CAAC"} \ No newline at end of file +{"version":3,"file":"sourceMap-SkippedNode.js","sourceRoot":"","sources":["sourceMap-SkippedNode.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC;AACL,MAAM;AACN,CAAC;QAAS,CAAC;AACX,wBAAwB;AACxB,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMap-SkippedNode.sourcemap.txt b/tests/baselines/reference/sourceMap-SkippedNode.sourcemap.txt index f68320a531f..b48a5f09f4a 100644 --- a/tests/baselines/reference/sourceMap-SkippedNode.sourcemap.txt +++ b/tests/baselines/reference/sourceMap-SkippedNode.sourcemap.txt @@ -12,6 +12,7 @@ sourceFile:sourceMap-SkippedNode.ts 1 > 2 >^^^^ 3 > ^ +4 > ^^-> 1 > 2 >try 3 > { @@ -19,34 +20,51 @@ sourceFile:sourceMap-SkippedNode.ts 2 >Emitted(1, 5) Source(1, 5) + SourceIndex(0) 3 >Emitted(1, 6) Source(1, 6) + SourceIndex(0) --- +>>>// ... +1-> +2 >^^^^^^ +1-> + > +2 >// ... +1->Emitted(2, 1) Source(2, 1) + SourceIndex(0) +2 >Emitted(2, 7) Source(2, 7) + SourceIndex(0) +--- >>>} 1 > 2 >^ 3 > ^^^^^^^^^-> 1 > - >// ... > 2 >} -1 >Emitted(2, 1) Source(3, 1) + SourceIndex(0) -2 >Emitted(2, 2) Source(3, 2) + SourceIndex(0) +1 >Emitted(3, 1) Source(3, 1) + SourceIndex(0) +2 >Emitted(3, 2) Source(3, 2) + SourceIndex(0) --- >>>finally { 1->^^^^^^^^ 2 > ^ +3 > ^^^^^^^^^^^^^^^^-> 1-> finally 2 > { -1->Emitted(3, 9) Source(3, 11) + SourceIndex(0) -2 >Emitted(3, 10) Source(3, 12) + SourceIndex(0) +1->Emitted(4, 9) Source(3, 11) + SourceIndex(0) +2 >Emitted(4, 10) Source(3, 12) + SourceIndex(0) +--- +>>>// N.B. No 'catch' block +1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^ +1-> + > +2 >// N.B. No 'catch' block +1->Emitted(5, 1) Source(4, 1) + SourceIndex(0) +2 >Emitted(5, 25) Source(4, 25) + SourceIndex(0) --- >>>} 1 > 2 >^ 3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > - >// N.B. No 'catch' block > 2 >} -1 >Emitted(4, 1) Source(5, 1) + SourceIndex(0) -2 >Emitted(4, 2) Source(5, 2) + SourceIndex(0) +1 >Emitted(6, 1) Source(5, 1) + SourceIndex(0) +2 >Emitted(6, 2) Source(5, 2) + SourceIndex(0) --- >>>//# sourceMappingURL=sourceMap-SkippedNode.js.map \ No newline at end of file diff --git a/tests/cases/compiler/commentLeadingCloseBrace.ts b/tests/cases/compiler/commentLeadingCloseBrace.ts new file mode 100644 index 00000000000..bdf7a604a9b --- /dev/null +++ b/tests/cases/compiler/commentLeadingCloseBrace.ts @@ -0,0 +1,11 @@ +declare function commentedParameters(...args): any; + +function ifelse() { + if (commentedParameters(1, 2)) { + /*comment1*/ + commentedParameters(3, 4); + /*comment2*/ + } else { + commentedParameters(5, 6); + } +} \ No newline at end of file From f4080a4f9e310fbbe24e5d2813bfebc1c362b85b Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 7 Feb 2017 18:23:22 -0800 Subject: [PATCH 06/16] Add test for #13925 --- .../reference/capturedLetConstInLoop13.js | 52 ++++++++++++++++ .../capturedLetConstInLoop13.symbols | 48 +++++++++++++++ .../reference/capturedLetConstInLoop13.types | 59 +++++++++++++++++++ .../compiler/capturedLetConstInLoop13.ts | 22 +++++++ 4 files changed, 181 insertions(+) create mode 100644 tests/baselines/reference/capturedLetConstInLoop13.js create mode 100644 tests/baselines/reference/capturedLetConstInLoop13.symbols create mode 100644 tests/baselines/reference/capturedLetConstInLoop13.types create mode 100644 tests/cases/compiler/capturedLetConstInLoop13.ts diff --git a/tests/baselines/reference/capturedLetConstInLoop13.js b/tests/baselines/reference/capturedLetConstInLoop13.js new file mode 100644 index 00000000000..a2e0921ab1d --- /dev/null +++ b/tests/baselines/reference/capturedLetConstInLoop13.js @@ -0,0 +1,52 @@ +//// [capturedLetConstInLoop13.ts] +class Main { + + constructor() { + this.register("a", "b", "c"); + } + + private register(...names: string[]): void { + for (let name of names) { + + this.bar({ + [name + ".a"]: () => { this.foo(name); }, + }); + } + } + + private bar(a: any): void { } + + private foo(name: string): void { } + +} + +new Main(); + +//// [capturedLetConstInLoop13.js] +var Main = (function () { + function Main() { + this.register("a", "b", "c"); + } + Main.prototype.register = function () { + var _this = this; + var names = []; + for (var _i = 0; _i < arguments.length; _i++) { + names[_i] = arguments[_i]; + } + var _loop_1 = function (name) { + this_1.bar((_a = {}, + _a[name + ".a"] = function () { _this.foo(name); }, + _a)); + var _a; + }; + var this_1 = this; + for (var _a = 0, names_1 = names; _a < names_1.length; _a++) { + var name = names_1[_a]; + _loop_1(name); + } + }; + Main.prototype.bar = function (a) { }; + Main.prototype.foo = function (name) { }; + return Main; +}()); +new Main(); diff --git a/tests/baselines/reference/capturedLetConstInLoop13.symbols b/tests/baselines/reference/capturedLetConstInLoop13.symbols new file mode 100644 index 00000000000..c7a824d26fa --- /dev/null +++ b/tests/baselines/reference/capturedLetConstInLoop13.symbols @@ -0,0 +1,48 @@ +=== tests/cases/compiler/capturedLetConstInLoop13.ts === +class Main { +>Main : Symbol(Main, Decl(capturedLetConstInLoop13.ts, 0, 0)) + + constructor() { + this.register("a", "b", "c"); +>this.register : Symbol(Main.register, Decl(capturedLetConstInLoop13.ts, 4, 5)) +>this : Symbol(Main, Decl(capturedLetConstInLoop13.ts, 0, 0)) +>register : Symbol(Main.register, Decl(capturedLetConstInLoop13.ts, 4, 5)) + } + + private register(...names: string[]): void { +>register : Symbol(Main.register, Decl(capturedLetConstInLoop13.ts, 4, 5)) +>names : Symbol(names, Decl(capturedLetConstInLoop13.ts, 6, 21)) + + for (let name of names) { +>name : Symbol(name, Decl(capturedLetConstInLoop13.ts, 7, 16)) +>names : Symbol(names, Decl(capturedLetConstInLoop13.ts, 6, 21)) + + this.bar({ +>this.bar : Symbol(Main.bar, Decl(capturedLetConstInLoop13.ts, 13, 5)) +>this : Symbol(Main, Decl(capturedLetConstInLoop13.ts, 0, 0)) +>bar : Symbol(Main.bar, Decl(capturedLetConstInLoop13.ts, 13, 5)) + + [name + ".a"]: () => { this.foo(name); }, +>name : Symbol(name, Decl(capturedLetConstInLoop13.ts, 7, 16)) +>this.foo : Symbol(Main.foo, Decl(capturedLetConstInLoop13.ts, 15, 33)) +>this : Symbol(Main, Decl(capturedLetConstInLoop13.ts, 0, 0)) +>foo : Symbol(Main.foo, Decl(capturedLetConstInLoop13.ts, 15, 33)) +>name : Symbol(name, Decl(capturedLetConstInLoop13.ts, 7, 16)) + + }); + } + } + + private bar(a: any): void { } +>bar : Symbol(Main.bar, Decl(capturedLetConstInLoop13.ts, 13, 5)) +>a : Symbol(a, Decl(capturedLetConstInLoop13.ts, 15, 16)) + + private foo(name: string): void { } +>foo : Symbol(Main.foo, Decl(capturedLetConstInLoop13.ts, 15, 33)) +>name : Symbol(name, Decl(capturedLetConstInLoop13.ts, 17, 16)) + +} + +new Main(); +>Main : Symbol(Main, Decl(capturedLetConstInLoop13.ts, 0, 0)) + diff --git a/tests/baselines/reference/capturedLetConstInLoop13.types b/tests/baselines/reference/capturedLetConstInLoop13.types new file mode 100644 index 00000000000..e6f97255d75 --- /dev/null +++ b/tests/baselines/reference/capturedLetConstInLoop13.types @@ -0,0 +1,59 @@ +=== tests/cases/compiler/capturedLetConstInLoop13.ts === +class Main { +>Main : Main + + constructor() { + this.register("a", "b", "c"); +>this.register("a", "b", "c") : void +>this.register : (...names: string[]) => void +>this : this +>register : (...names: string[]) => void +>"a" : "a" +>"b" : "b" +>"c" : "c" + } + + private register(...names: string[]): void { +>register : (...names: string[]) => void +>names : string[] + + for (let name of names) { +>name : string +>names : string[] + + this.bar({ +>this.bar({ [name + ".a"]: () => { this.foo(name); }, }) : void +>this.bar : (a: any) => void +>this : this +>bar : (a: any) => void +>{ [name + ".a"]: () => { this.foo(name); }, } : { [x: string]: () => void; } + + [name + ".a"]: () => { this.foo(name); }, +>name + ".a" : string +>name : string +>".a" : ".a" +>() => { this.foo(name); } : () => void +>this.foo(name) : void +>this.foo : (name: string) => void +>this : this +>foo : (name: string) => void +>name : string + + }); + } + } + + private bar(a: any): void { } +>bar : (a: any) => void +>a : any + + private foo(name: string): void { } +>foo : (name: string) => void +>name : string + +} + +new Main(); +>new Main() : Main +>Main : typeof Main + diff --git a/tests/cases/compiler/capturedLetConstInLoop13.ts b/tests/cases/compiler/capturedLetConstInLoop13.ts new file mode 100644 index 00000000000..0aa00b0e1a0 --- /dev/null +++ b/tests/cases/compiler/capturedLetConstInLoop13.ts @@ -0,0 +1,22 @@ +class Main { + + constructor() { + this.register("a", "b", "c"); + } + + private register(...names: string[]): void { + for (let name of names) { + + this.bar({ + [name + ".a"]: () => { this.foo(name); }, + }); + } + } + + private bar(a: any): void { } + + private foo(name: string): void { } + +} + +new Main(); \ No newline at end of file From f4583313d9bf6ff3ed1e5464277c73f5bd124234 Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 8 Feb 2017 06:13:32 -0800 Subject: [PATCH 07/16] Use `!!` to convert to boolean --- 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 3deddf1f2cc..c7f455bd753 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -911,7 +911,7 @@ namespace FourSlash { function rangeToReferenceEntry(r: Range) { let { isWriteAccess, isDefinition } = (r.marker && r.marker.data) || { isWriteAccess: false, isDefinition: false }; - isWriteAccess = isWriteAccess || false; isDefinition = isDefinition || false; + isWriteAccess = !!isWriteAccess; isDefinition = !!isDefinition; return { fileName: r.fileName, textSpan: { start: r.start, length: r.end - r.start }, isWriteAccess, isDefinition } } } From a928ad3bd36e8aea806b307ff0b4b2d683f12ee8 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Wed, 8 Feb 2017 10:17:58 -0800 Subject: [PATCH 08/16] Address code review: move only expose emitLeadingCommentsOfPosition --- src/compiler/comments.ts | 16 ++++++++++------ src/compiler/emitter.ts | 17 +++++++---------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/compiler/comments.ts b/src/compiler/comments.ts index 8e17bf2d91b..dcb471dcfcc 100644 --- a/src/compiler/comments.ts +++ b/src/compiler/comments.ts @@ -9,7 +9,7 @@ namespace ts { emitNodeWithComments(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void): void; emitBodyWithDetachedComments(node: Node, detachedRange: TextRange, emitCallback: (node: Node) => void): void; emitTrailingCommentsOfPosition(pos: number): void; - emitLeadingComments(pos: number, isEmittedNode: boolean): void; + emitLeadingCommentsOfPosition(pos: number): void; } export function createCommentWriter(printerOptions: PrinterOptions, emitPos: ((pos: number) => void) | undefined): CommentWriter { @@ -33,7 +33,7 @@ namespace ts { emitNodeWithComments, emitBodyWithDetachedComments, emitTrailingCommentsOfPosition, - emitLeadingComments, + emitLeadingCommentsOfPosition, }; function emitNodeWithComments(hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) { @@ -169,10 +169,6 @@ namespace ts { } function emitLeadingComments(pos: number, isEmittedNode: boolean) { - if (disabled) { - return; - } - hasWrittenComment = false; if (isEmittedNode) { @@ -216,6 +212,14 @@ namespace ts { } } + function emitLeadingCommentsOfPosition(pos: number) { + if (disabled || pos === -1) { + return; + } + + emitLeadingComments(pos, /*isEmittedNode*/ true); + } + function emitTrailingComments(pos: number) { forEachTrailingCommentToEmit(pos, emitTrailingComment); } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 7adac106e8c..fcb3fb826c9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1,4 +1,4 @@ -/// +/// /// /// /// @@ -211,7 +211,7 @@ namespace ts { emitNodeWithComments, emitBodyWithDetachedComments, emitTrailingCommentsOfPosition, - emitLeadingComments, + emitLeadingCommentsOfPosition, } = comments; let currentSourceFile: SourceFile; @@ -1348,7 +1348,7 @@ namespace ts { writeToken(SyntaxKind.OpenBraceToken, node.pos, /*contextNode*/ node); emitBlockStatements(node); // We have to call emitLeadingComments explicitly here because otherwise leading comments of the close brace token will not be emitted - emitLeadingComments(node.statements.end, /*isEmittedNode*/true); + emitLeadingCommentsOfPosition(node.statements.end); writeToken(SyntaxKind.CloseBraceToken, node.statements.end, /*contextNode*/ node); } } @@ -2235,10 +2235,10 @@ namespace ts { // function commentedParameters( // /* Parameter a */ // a - // /* End of parameter a */ -> this comment doesn't consider to be trailing comment of parameter "a" due to newline + // /* End of parameter a */ -> this comment isn't considered to be trailing comment of parameter "a" due to newline // , - if (emitLeadingComments && delimiter && previousSibling.end !== parentNode.end) { - emitLeadingComments(previousSibling.end, /*isEmittedNode*/ previousSibling.kind !== SyntaxKind.NotEmittedStatement); + if (emitLeadingCommentsOfPosition && delimiter && previousSibling.end !== parentNode.end) { + emitLeadingCommentsOfPosition(previousSibling.end); } write(delimiter); @@ -2294,10 +2294,7 @@ namespace ts { // /* end of element 2 */ // ]; if (previousSibling && delimiter && previousSibling.end !== parentNode.end) { - emitLeadingComments(previousSibling.end, /*isEmittedNode*/ previousSibling.kind !== SyntaxKind.NotEmittedStatement); - if (hasTrailingComma) { - emitLeadingComments(previousSibling.end, /*isEmittedNode*/ previousSibling.kind !== SyntaxKind.NotEmittedStatement); - } + emitLeadingCommentsOfPosition(previousSibling.end); } // Decrease the indent, if requested. From bb71dcdde8bf95611cfe98d8b33738250f4fb5b8 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 8 Feb 2017 11:01:32 -0800 Subject: [PATCH 09/16] add projectUsesOutFile field to protocol.CompileOnSaveAffectedFileListSingleProject (#13915) --- .../unittests/tsserverProjectSystem.ts | 48 +++++++++++++++++++ src/server/protocol.ts | 5 ++ src/server/session.ts | 3 +- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 5ed0d981511..93027675bd6 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -3031,6 +3031,54 @@ namespace ts.projectSystem { }); }); + describe("emit with outFile or out setting", () => { + function test(opts: CompilerOptions, expectedUsesOutFile: boolean) { + const f1 = { + path: "/a/a.ts", + content: "let x = 1" + }; + const f2 = { + path: "/a/b.ts", + content: "let y = 1" + }; + const config = { + path: "/a/tsconfig.json", + content: JSON.stringify({ + compilerOptions: opts, + compileOnSave: true + }) + }; + const host = createServerHost([f1, f2, config]); + const session = createSession(host); + session.executeCommand({ + seq: 1, + type: "request", + command: "open", + arguments: { file: f1.path } + }); + checkNumberOfProjects(session.getProjectService(), { configuredProjects: 1 }); + const { response } = session.executeCommand({ + seq: 2, + type: "request", + command: "compileOnSaveAffectedFileList", + arguments: { file: f1.path } + }); + assert.equal((response).length, 1, "expected output for 1 project"); + assert.equal((response)[0].fileNames.length, 2, "expected output for 1 project"); + assert.equal((response)[0].projectUsesOutFile, expectedUsesOutFile, "usesOutFile"); + } + + it ("projectUsesOutFile should not be returned if not set", () => { + test({}, /*expectedUsesOutFile*/ false); + }); + it ("projectUsesOutFile should be true if outFile is set", () => { + test({ outFile: "/a/out.js" }, /*expectedUsesOutFile*/ true); + }); + it ("projectUsesOutFile should be true if out is set", () => { + test({ out: "/a/out.js" }, /*expectedUsesOutFile*/ true); + }); + }); + describe("import helpers", () => { it("should not crash in tsserver", () => { const f1 = { diff --git a/src/server/protocol.ts b/src/server/protocol.ts index e3fe17362d7..c1b78e9dbaa 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -1239,6 +1239,11 @@ namespace ts.server.protocol { * List of files names that should be recompiled */ fileNames: string[]; + + /** + * true if project uses outFile or out compiler option + */ + projectUsesOutFile: boolean; } /** diff --git a/src/server/session.ts b/src/server/session.ts index 825ad8506d7..5d745fc7965 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1040,7 +1040,8 @@ namespace ts.server { if (project.compileOnSaveEnabled && project.languageServiceEnabled) { result.push({ projectFileName: project.getProjectName(), - fileNames: project.getCompileOnSaveAffectedFileList(info) + fileNames: project.getCompileOnSaveAffectedFileList(info), + projectUsesOutFile: !!project.getCompilerOptions().outFile || !!project.getCompilerOptions().out }); } } From 125dd57a757612367bcf495ed3070bb932ae75ed Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 8 Feb 2017 13:28:23 -0800 Subject: [PATCH 10/16] Fix assigned type of assignment nested in literals Fixes #12946 --- src/compiler/checker.ts | 10 +++++- .../reference/assignmentNestedInLiterals.js | 13 +++++++ .../assignmentNestedInLiterals.symbols | 25 +++++++++++++ .../assignmentNestedInLiterals.types | 35 +++++++++++++++++++ .../compiler/assignmentNestedInLiterals.ts | 6 ++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/assignmentNestedInLiterals.js create mode 100644 tests/baselines/reference/assignmentNestedInLiterals.symbols create mode 100644 tests/baselines/reference/assignmentNestedInLiterals.types create mode 100644 tests/cases/compiler/assignmentNestedInLiterals.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 4423b574e31..428a4e6eeef 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9469,11 +9469,19 @@ namespace ts { } function getAssignedTypeOfBinaryExpression(node: BinaryExpression): Type { - return node.parent.kind === SyntaxKind.ArrayLiteralExpression || node.parent.kind === SyntaxKind.PropertyAssignment ? + const isDestructuringDefaultAssignment = + node.parent.kind === SyntaxKind.ArrayLiteralExpression && isDestructuringAssignmentTarget(node.parent) || + node.parent.kind === SyntaxKind.PropertyAssignment && isDestructuringAssignmentTarget(node.parent.parent); + return isDestructuringDefaultAssignment ? getTypeWithDefault(getAssignedType(node), node.right) : getTypeOfExpression(node.right); } + function isDestructuringAssignmentTarget(parent: Node) { + return parent.parent.kind === SyntaxKind.BinaryExpression && (parent.parent as BinaryExpression).left === parent || + parent.parent.kind === SyntaxKind.ForOfStatement && (parent.parent as ForOfStatement).initializer === parent; + } + function getAssignedTypeOfArrayLiteralElement(node: ArrayLiteralExpression, element: Expression): Type { return getTypeOfDestructuredArrayElement(getAssignedType(node), indexOf(node.elements, element)); } diff --git a/tests/baselines/reference/assignmentNestedInLiterals.js b/tests/baselines/reference/assignmentNestedInLiterals.js new file mode 100644 index 00000000000..cd4bc6c6699 --- /dev/null +++ b/tests/baselines/reference/assignmentNestedInLiterals.js @@ -0,0 +1,13 @@ +//// [assignmentNestedInLiterals.ts] +var target, x, y; +target = [x = 1, y = x]; + +var aegis, a, b; +aegis = { x: a = 1, y: b = a }; + + +//// [assignmentNestedInLiterals.js] +var target, x, y; +target = [x = 1, y = x]; +var aegis, a, b; +aegis = { x: a = 1, y: b = a }; diff --git a/tests/baselines/reference/assignmentNestedInLiterals.symbols b/tests/baselines/reference/assignmentNestedInLiterals.symbols new file mode 100644 index 00000000000..90edd9ed04f --- /dev/null +++ b/tests/baselines/reference/assignmentNestedInLiterals.symbols @@ -0,0 +1,25 @@ +=== tests/cases/compiler/assignmentNestedInLiterals.ts === +var target, x, y; +>target : Symbol(target, Decl(assignmentNestedInLiterals.ts, 0, 3)) +>x : Symbol(x, Decl(assignmentNestedInLiterals.ts, 0, 11)) +>y : Symbol(y, Decl(assignmentNestedInLiterals.ts, 0, 14)) + +target = [x = 1, y = x]; +>target : Symbol(target, Decl(assignmentNestedInLiterals.ts, 0, 3)) +>x : Symbol(x, Decl(assignmentNestedInLiterals.ts, 0, 11)) +>y : Symbol(y, Decl(assignmentNestedInLiterals.ts, 0, 14)) +>x : Symbol(x, Decl(assignmentNestedInLiterals.ts, 0, 11)) + +var aegis, a, b; +>aegis : Symbol(aegis, Decl(assignmentNestedInLiterals.ts, 3, 3)) +>a : Symbol(a, Decl(assignmentNestedInLiterals.ts, 3, 10)) +>b : Symbol(b, Decl(assignmentNestedInLiterals.ts, 3, 13)) + +aegis = { x: a = 1, y: b = a }; +>aegis : Symbol(aegis, Decl(assignmentNestedInLiterals.ts, 3, 3)) +>x : Symbol(x, Decl(assignmentNestedInLiterals.ts, 4, 9)) +>a : Symbol(a, Decl(assignmentNestedInLiterals.ts, 3, 10)) +>y : Symbol(y, Decl(assignmentNestedInLiterals.ts, 4, 19)) +>b : Symbol(b, Decl(assignmentNestedInLiterals.ts, 3, 13)) +>a : Symbol(a, Decl(assignmentNestedInLiterals.ts, 3, 10)) + diff --git a/tests/baselines/reference/assignmentNestedInLiterals.types b/tests/baselines/reference/assignmentNestedInLiterals.types new file mode 100644 index 00000000000..8c4d5aadc7d --- /dev/null +++ b/tests/baselines/reference/assignmentNestedInLiterals.types @@ -0,0 +1,35 @@ +=== tests/cases/compiler/assignmentNestedInLiterals.ts === +var target, x, y; +>target : any +>x : any +>y : any + +target = [x = 1, y = x]; +>target = [x = 1, y = x] : number[] +>target : any +>[x = 1, y = x] : number[] +>x = 1 : 1 +>x : any +>1 : 1 +>y = x : number +>y : any +>x : number + +var aegis, a, b; +>aegis : any +>a : any +>b : any + +aegis = { x: a = 1, y: b = a }; +>aegis = { x: a = 1, y: b = a } : { x: number; y: number; } +>aegis : any +>{ x: a = 1, y: b = a } : { x: number; y: number; } +>x : number +>a = 1 : 1 +>a : any +>1 : 1 +>y : number +>b = a : number +>b : any +>a : number + diff --git a/tests/cases/compiler/assignmentNestedInLiterals.ts b/tests/cases/compiler/assignmentNestedInLiterals.ts new file mode 100644 index 00000000000..5b1f52cb450 --- /dev/null +++ b/tests/cases/compiler/assignmentNestedInLiterals.ts @@ -0,0 +1,6 @@ +// @noImplicitAny: true +var target, x, y; +target = [x = 1, y = x]; + +var aegis, a, b; +aegis = { x: a = 1, y: b = a }; From 8b8c490ff6b5cd89cee0d9049c733e6bbba1a719 Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Wed, 8 Feb 2017 13:36:19 -0800 Subject: [PATCH 11/16] Address code review: fix indentation --- src/compiler/emitter.ts | 2 ++ .../reference/amdImportAsPrimaryExpression.js | 2 +- tests/baselines/reference/argsInScope.js | 2 +- .../reference/commentLeadingCloseBrace.js | 2 +- .../commonJSImportAsPrimaryExpression.js | 2 +- .../reference/duplicateLocalVariable1.js | 2 +- .../jsFileCompilationLetBeingRenamed.js | 2 +- .../narrowExceptionVariableInCatchClause.js | 2 +- tests/baselines/reference/noCatchBlock.js | 4 +-- tests/baselines/reference/noCatchBlock.js.map | 2 +- .../reference/noCatchBlock.sourcemap.txt | 28 +++++++++---------- tests/baselines/reference/objectRestForOf.js | 2 +- .../baselines/reference/parserRealSource14.js | 2 +- tests/baselines/reference/recursiveReturns.js | 2 +- .../reference/sourceMap-SkippedNode.js | 4 +-- .../reference/sourceMap-SkippedNode.js.map | 2 +- .../sourceMap-SkippedNode.sourcemap.txt | 28 +++++++++---------- 17 files changed, 46 insertions(+), 44 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index fcb3fb826c9..03804dfeebe 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1348,7 +1348,9 @@ namespace ts { writeToken(SyntaxKind.OpenBraceToken, node.pos, /*contextNode*/ node); emitBlockStatements(node); // We have to call emitLeadingComments explicitly here because otherwise leading comments of the close brace token will not be emitted + increaseIndent(); emitLeadingCommentsOfPosition(node.statements.end); + decreaseIndent(); writeToken(SyntaxKind.CloseBraceToken, node.statements.end, /*contextNode*/ node); } } diff --git a/tests/baselines/reference/amdImportAsPrimaryExpression.js b/tests/baselines/reference/amdImportAsPrimaryExpression.js index 25f390c0b32..6ff3216fb58 100644 --- a/tests/baselines/reference/amdImportAsPrimaryExpression.js +++ b/tests/baselines/reference/amdImportAsPrimaryExpression.js @@ -26,6 +26,6 @@ define(["require", "exports"], function (require, exports) { define(["require", "exports", "./foo_0"], function (require, exports, foo) { "use strict"; if (foo.E1.A === 0) { - // Should cause runtime import - interesting optimization possibility, as gets inlined to 0. + // Should cause runtime import - interesting optimization possibility, as gets inlined to 0. } }); diff --git a/tests/baselines/reference/argsInScope.js b/tests/baselines/reference/argsInScope.js index 27405a47d87..a38bc778039 100644 --- a/tests/baselines/reference/argsInScope.js +++ b/tests/baselines/reference/argsInScope.js @@ -17,7 +17,7 @@ var C = (function () { } C.prototype.P = function (ii, j, k) { for (var i = 0; i < arguments.length; i++) { - // WScript.Echo("param: " + arguments[i]); + // WScript.Echo("param: " + arguments[i]); } }; return C; diff --git a/tests/baselines/reference/commentLeadingCloseBrace.js b/tests/baselines/reference/commentLeadingCloseBrace.js index 9fc696219e1..d5f5afbb884 100644 --- a/tests/baselines/reference/commentLeadingCloseBrace.js +++ b/tests/baselines/reference/commentLeadingCloseBrace.js @@ -16,7 +16,7 @@ function ifelse() { if (commentedParameters(1, 2)) { /*comment1*/ commentedParameters(3, 4); - /*comment2*/ + /*comment2*/ } else { commentedParameters(5, 6); diff --git a/tests/baselines/reference/commonJSImportAsPrimaryExpression.js b/tests/baselines/reference/commonJSImportAsPrimaryExpression.js index 1eb7b5ff214..0cbb7470dfc 100644 --- a/tests/baselines/reference/commonJSImportAsPrimaryExpression.js +++ b/tests/baselines/reference/commonJSImportAsPrimaryExpression.js @@ -27,5 +27,5 @@ exports.C1 = C1; "use strict"; var foo = require("./foo_0"); if (foo.C1.s1) { -// Should cause runtime import + // Should cause runtime import } diff --git a/tests/baselines/reference/duplicateLocalVariable1.js b/tests/baselines/reference/duplicateLocalVariable1.js index 432830d85b6..39848b3bb6a 100644 --- a/tests/baselines/reference/duplicateLocalVariable1.js +++ b/tests/baselines/reference/duplicateLocalVariable1.js @@ -391,7 +391,7 @@ var TestRunner = (function () { } } if (testResult === false) { - //console.log(e.message); + //console.log(e.message); } } if ((testcase.errorMessageRegEx !== undefined) && !exception) { diff --git a/tests/baselines/reference/jsFileCompilationLetBeingRenamed.js b/tests/baselines/reference/jsFileCompilationLetBeingRenamed.js index bb2aa10dc95..a87dad3c914 100644 --- a/tests/baselines/reference/jsFileCompilationLetBeingRenamed.js +++ b/tests/baselines/reference/jsFileCompilationLetBeingRenamed.js @@ -9,6 +9,6 @@ function foo(a) { //// [out.js] function foo(a) { for (var a_1 = 0; a_1 < 10; a_1++) { - // do something + // do something } } diff --git a/tests/baselines/reference/narrowExceptionVariableInCatchClause.js b/tests/baselines/reference/narrowExceptionVariableInCatchClause.js index 18344df5994..b7dbf717e34 100644 --- a/tests/baselines/reference/narrowExceptionVariableInCatchClause.js +++ b/tests/baselines/reference/narrowExceptionVariableInCatchClause.js @@ -27,7 +27,7 @@ function tryCatch() { //// [narrowExceptionVariableInCatchClause.js] function tryCatch() { try { - // do stuff... + // do stuff... } catch (err) { if (isFooError(err)) { diff --git a/tests/baselines/reference/noCatchBlock.js b/tests/baselines/reference/noCatchBlock.js index 158ac1257f3..ecc9c7f8c7e 100644 --- a/tests/baselines/reference/noCatchBlock.js +++ b/tests/baselines/reference/noCatchBlock.js @@ -8,9 +8,9 @@ try { //// [noCatchBlock.js] try { -// ... + // ... } finally { -// N.B. No 'catch' block + // N.B. No 'catch' block } //# sourceMappingURL=noCatchBlock.js.map \ No newline at end of file diff --git a/tests/baselines/reference/noCatchBlock.js.map b/tests/baselines/reference/noCatchBlock.js.map index ddac2894e0b..392ec588108 100644 --- a/tests/baselines/reference/noCatchBlock.js.map +++ b/tests/baselines/reference/noCatchBlock.js.map @@ -1,2 +1,2 @@ //// [noCatchBlock.js.map] -{"version":3,"file":"noCatchBlock.js","sourceRoot":"","sources":["noCatchBlock.ts"],"names":[],"mappings":"AACA,IAAI,CAAC;AACJ,MAAM;AACP,CAAC;QAAS,CAAC;AACV,wBAAwB;AACzB,CAAC"} \ No newline at end of file +{"version":3,"file":"noCatchBlock.js","sourceRoot":"","sources":["noCatchBlock.ts"],"names":[],"mappings":"AACA,IAAI,CAAC;IACJ,MAAM;AACP,CAAC;QAAS,CAAC;IACV,wBAAwB;AACzB,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/noCatchBlock.sourcemap.txt b/tests/baselines/reference/noCatchBlock.sourcemap.txt index a75c119ca9f..5210f12d734 100644 --- a/tests/baselines/reference/noCatchBlock.sourcemap.txt +++ b/tests/baselines/reference/noCatchBlock.sourcemap.txt @@ -12,7 +12,7 @@ sourceFile:noCatchBlock.ts 1 > 2 >^^^^ 3 > ^ -4 > ^^-> +4 > ^^^^^^-> 1 > > 2 >try @@ -21,14 +21,14 @@ sourceFile:noCatchBlock.ts 2 >Emitted(1, 5) Source(2, 5) + SourceIndex(0) 3 >Emitted(1, 6) Source(2, 6) + SourceIndex(0) --- ->>>// ... -1-> -2 >^^^^^^ +>>> // ... +1->^^^^ +2 > ^^^^^^ 1-> > -2 >// ... -1->Emitted(2, 1) Source(3, 2) + SourceIndex(0) -2 >Emitted(2, 7) Source(3, 8) + SourceIndex(0) +2 > // ... +1->Emitted(2, 5) Source(3, 2) + SourceIndex(0) +2 >Emitted(2, 11) Source(3, 8) + SourceIndex(0) --- >>>} 1 > @@ -43,20 +43,20 @@ sourceFile:noCatchBlock.ts >>>finally { 1->^^^^^^^^ 2 > ^ -3 > ^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^-> 1-> finally 2 > { 1->Emitted(4, 9) Source(4, 11) + SourceIndex(0) 2 >Emitted(4, 10) Source(4, 12) + SourceIndex(0) --- ->>>// N.B. No 'catch' block -1-> -2 >^^^^^^^^^^^^^^^^^^^^^^^^ +>>> // N.B. No 'catch' block +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^ 1-> > -2 >// N.B. No 'catch' block -1->Emitted(5, 1) Source(5, 2) + SourceIndex(0) -2 >Emitted(5, 25) Source(5, 26) + SourceIndex(0) +2 > // N.B. No 'catch' block +1->Emitted(5, 5) Source(5, 2) + SourceIndex(0) +2 >Emitted(5, 29) Source(5, 26) + SourceIndex(0) --- >>>} 1 > diff --git a/tests/baselines/reference/objectRestForOf.js b/tests/baselines/reference/objectRestForOf.js index 5f0399b2df2..7ff72db06e5 100644 --- a/tests/baselines/reference/objectRestForOf.js +++ b/tests/baselines/reference/objectRestForOf.js @@ -37,5 +37,5 @@ for (let _b of array) { } for (const norest of array.map(a => (Object.assign({}, a, { x: 'a string' })))) { [norest.x, norest.y]; -// x is now a string. who knows why. + // x is now a string. who knows why. } diff --git a/tests/baselines/reference/parserRealSource14.js b/tests/baselines/reference/parserRealSource14.js index 4e4e23e81c3..635d122db04 100644 --- a/tests/baselines/reference/parserRealSource14.js +++ b/tests/baselines/reference/parserRealSource14.js @@ -1011,7 +1011,7 @@ var TypeScript; ctx.path.push(cur); } else { - //logger.log("TODO: Ignoring node because minChar, limChar not better than previous node in stack"); + //logger.log("TODO: Ignoring node because minChar, limChar not better than previous node in stack"); } } // The AST walker skips comments, but we might be in one, so check the pre/post comments for this node manually diff --git a/tests/baselines/reference/recursiveReturns.js b/tests/baselines/reference/recursiveReturns.js index 56762a9ad2d..d2619e18796 100644 --- a/tests/baselines/reference/recursiveReturns.js +++ b/tests/baselines/reference/recursiveReturns.js @@ -23,7 +23,7 @@ function R1() { function R2() { R2(); } function R3(n) { if (n == 0) { - //return; + //return; } else { R3(n--); diff --git a/tests/baselines/reference/sourceMap-SkippedNode.js b/tests/baselines/reference/sourceMap-SkippedNode.js index daac27cf49f..f25c0d75c82 100644 --- a/tests/baselines/reference/sourceMap-SkippedNode.js +++ b/tests/baselines/reference/sourceMap-SkippedNode.js @@ -7,9 +7,9 @@ try { //// [sourceMap-SkippedNode.js] try { -// ... + // ... } finally { -// N.B. No 'catch' block + // N.B. No 'catch' block } //# sourceMappingURL=sourceMap-SkippedNode.js.map \ No newline at end of file diff --git a/tests/baselines/reference/sourceMap-SkippedNode.js.map b/tests/baselines/reference/sourceMap-SkippedNode.js.map index b86b3905a73..f3444919d41 100644 --- a/tests/baselines/reference/sourceMap-SkippedNode.js.map +++ b/tests/baselines/reference/sourceMap-SkippedNode.js.map @@ -1,2 +1,2 @@ //// [sourceMap-SkippedNode.js.map] -{"version":3,"file":"sourceMap-SkippedNode.js","sourceRoot":"","sources":["sourceMap-SkippedNode.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC;AACL,MAAM;AACN,CAAC;QAAS,CAAC;AACX,wBAAwB;AACxB,CAAC"} \ No newline at end of file +{"version":3,"file":"sourceMap-SkippedNode.js","sourceRoot":"","sources":["sourceMap-SkippedNode.ts"],"names":[],"mappings":"AAAA,IAAI,CAAC;IACL,MAAM;AACN,CAAC;QAAS,CAAC;IACX,wBAAwB;AACxB,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMap-SkippedNode.sourcemap.txt b/tests/baselines/reference/sourceMap-SkippedNode.sourcemap.txt index b48a5f09f4a..c54676a697e 100644 --- a/tests/baselines/reference/sourceMap-SkippedNode.sourcemap.txt +++ b/tests/baselines/reference/sourceMap-SkippedNode.sourcemap.txt @@ -12,7 +12,7 @@ sourceFile:sourceMap-SkippedNode.ts 1 > 2 >^^^^ 3 > ^ -4 > ^^-> +4 > ^^^^^^-> 1 > 2 >try 3 > { @@ -20,14 +20,14 @@ sourceFile:sourceMap-SkippedNode.ts 2 >Emitted(1, 5) Source(1, 5) + SourceIndex(0) 3 >Emitted(1, 6) Source(1, 6) + SourceIndex(0) --- ->>>// ... -1-> -2 >^^^^^^ +>>> // ... +1->^^^^ +2 > ^^^^^^ 1-> > -2 >// ... -1->Emitted(2, 1) Source(2, 1) + SourceIndex(0) -2 >Emitted(2, 7) Source(2, 7) + SourceIndex(0) +2 > // ... +1->Emitted(2, 5) Source(2, 1) + SourceIndex(0) +2 >Emitted(2, 11) Source(2, 7) + SourceIndex(0) --- >>>} 1 > @@ -42,20 +42,20 @@ sourceFile:sourceMap-SkippedNode.ts >>>finally { 1->^^^^^^^^ 2 > ^ -3 > ^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^^^^^^^^^^^^^^-> 1-> finally 2 > { 1->Emitted(4, 9) Source(3, 11) + SourceIndex(0) 2 >Emitted(4, 10) Source(3, 12) + SourceIndex(0) --- ->>>// N.B. No 'catch' block -1-> -2 >^^^^^^^^^^^^^^^^^^^^^^^^ +>>> // N.B. No 'catch' block +1->^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^ 1-> > -2 >// N.B. No 'catch' block -1->Emitted(5, 1) Source(4, 1) + SourceIndex(0) -2 >Emitted(5, 25) Source(4, 25) + SourceIndex(0) +2 > // N.B. No 'catch' block +1->Emitted(5, 5) Source(4, 1) + SourceIndex(0) +2 >Emitted(5, 29) Source(4, 25) + SourceIndex(0) --- >>>} 1 > From a46cb033db7ad608c81e2541052cc1e3633ecadc Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 8 Feb 2017 16:14:36 -0800 Subject: [PATCH 12/16] Add for-of test case --- .../reference/assignmentNestedInLiterals.js | 8 ++++++++ .../reference/assignmentNestedInLiterals.symbols | 12 ++++++++++++ .../reference/assignmentNestedInLiterals.types | 16 ++++++++++++++++ .../cases/compiler/assignmentNestedInLiterals.ts | 4 ++++ 4 files changed, 40 insertions(+) diff --git a/tests/baselines/reference/assignmentNestedInLiterals.js b/tests/baselines/reference/assignmentNestedInLiterals.js index cd4bc6c6699..8a048082565 100644 --- a/tests/baselines/reference/assignmentNestedInLiterals.js +++ b/tests/baselines/reference/assignmentNestedInLiterals.js @@ -4,6 +4,10 @@ target = [x = 1, y = x]; var aegis, a, b; aegis = { x: a = 1, y: b = a }; + +var kowloona, c, d; +for (kowloona of [c = 1, d = c]) { +} //// [assignmentNestedInLiterals.js] @@ -11,3 +15,7 @@ var target, x, y; target = [x = 1, y = x]; var aegis, a, b; aegis = { x: a = 1, y: b = a }; +var kowloona, c, d; +for (var _i = 0, _a = [c = 1, d = c]; _i < _a.length; _i++) { + kowloona = _a[_i]; +} diff --git a/tests/baselines/reference/assignmentNestedInLiterals.symbols b/tests/baselines/reference/assignmentNestedInLiterals.symbols index 90edd9ed04f..761930ab9ce 100644 --- a/tests/baselines/reference/assignmentNestedInLiterals.symbols +++ b/tests/baselines/reference/assignmentNestedInLiterals.symbols @@ -23,3 +23,15 @@ aegis = { x: a = 1, y: b = a }; >b : Symbol(b, Decl(assignmentNestedInLiterals.ts, 3, 13)) >a : Symbol(a, Decl(assignmentNestedInLiterals.ts, 3, 10)) +var kowloona, c, d; +>kowloona : Symbol(kowloona, Decl(assignmentNestedInLiterals.ts, 6, 3)) +>c : Symbol(c, Decl(assignmentNestedInLiterals.ts, 6, 13)) +>d : Symbol(d, Decl(assignmentNestedInLiterals.ts, 6, 16)) + +for (kowloona of [c = 1, d = c]) { +>kowloona : Symbol(kowloona, Decl(assignmentNestedInLiterals.ts, 6, 3)) +>c : Symbol(c, Decl(assignmentNestedInLiterals.ts, 6, 13)) +>d : Symbol(d, Decl(assignmentNestedInLiterals.ts, 6, 16)) +>c : Symbol(c, Decl(assignmentNestedInLiterals.ts, 6, 13)) +} + diff --git a/tests/baselines/reference/assignmentNestedInLiterals.types b/tests/baselines/reference/assignmentNestedInLiterals.types index 8c4d5aadc7d..8ab73f80691 100644 --- a/tests/baselines/reference/assignmentNestedInLiterals.types +++ b/tests/baselines/reference/assignmentNestedInLiterals.types @@ -33,3 +33,19 @@ aegis = { x: a = 1, y: b = a }; >b : any >a : number +var kowloona, c, d; +>kowloona : any +>c : any +>d : any + +for (kowloona of [c = 1, d = c]) { +>kowloona : any +>[c = 1, d = c] : number[] +>c = 1 : 1 +>c : any +>1 : 1 +>d = c : number +>d : any +>c : number +} + diff --git a/tests/cases/compiler/assignmentNestedInLiterals.ts b/tests/cases/compiler/assignmentNestedInLiterals.ts index 5b1f52cb450..09d8c94488f 100644 --- a/tests/cases/compiler/assignmentNestedInLiterals.ts +++ b/tests/cases/compiler/assignmentNestedInLiterals.ts @@ -4,3 +4,7 @@ target = [x = 1, y = x]; var aegis, a, b; aegis = { x: a = 1, y: b = a }; + +var kowloona, c, d; +for (kowloona of [c = 1, d = c]) { +} From 2480e8d492ecd90849b189f98e57eb63ad1918c3 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 8 Feb 2017 20:35:01 -0800 Subject: [PATCH 13/16] do secondary lookup only if module has non-relative name --- Jakefile.js | 1 - src/harness/unittests/typingsInstaller.ts | 39 +++++++++++++++++++++++ src/server/lsHost.ts | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Jakefile.js b/Jakefile.js index f422a995725..4fd3be57e4f 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -37,7 +37,6 @@ if (process.env.path !== undefined) { } function filesFromConfig(configPath) { - console.log(configPath); var configText = fs.readFileSync(configPath).toString(); var config = ts.parseConfigFileTextToJson(configPath, configText, /*stripComments*/ true); if (config.error) { diff --git a/src/harness/unittests/typingsInstaller.ts b/src/harness/unittests/typingsInstaller.ts index 2b79141c3e3..29076df80f2 100644 --- a/src/harness/unittests/typingsInstaller.ts +++ b/src/harness/unittests/typingsInstaller.ts @@ -46,6 +46,45 @@ namespace ts.projectSystem { import typingsName = server.typingsInstaller.typingsName; + describe("local module", () => { + it("should not be picked up", () => { + const f1 = { + path: "/a/app.js", + content: "const c = require('./config');" + }; + const f2 = { + path: "/a/config.js", + content: "export let x = 1" + }; + const typesCache = "/cache" + const typesConfig = { + path: typesCache + "/node_modules/@types/config/index.d.ts", + content: "export let y: number;" + }; + const config = { + path: "/a/jsconfig.json", + content: JSON.stringify({ + compilerOptions: { moduleResolution: "commonjs" }, + typeAcquisition: { enable: true } + }) + }; + const host = createServerHost([f1, f2, config, typesConfig]); + const installer = new (class extends Installer { + constructor() { + super(host, { typesRegistry: createTypesRegistry("config"), globalTypingsCacheLocation: typesCache }); + } + installWorker(_requestId: number, _args: string[], _cwd: string, _cb: server.typingsInstaller.RequestCompletedAction) { + assert(false, "should not be called") + } + })(); + const service = createProjectService(host, { typingsInstaller: installer }); + service.openClientFile(f1.path); + service.checkNumberOfProjects({ configuredProjects: 1 }); + checkProjectActualFiles(service.configuredProjects[0], [f1.path, f2.path]); + installer.installAll(0); + }); + }); + describe("typingsInstaller", () => { it("configured projects (typings installed) 1", () => { const file1 = { diff --git a/src/server/lsHost.ts b/src/server/lsHost.ts index 9d8c9c08cb6..eee80d82e7f 100644 --- a/src/server/lsHost.ts +++ b/src/server/lsHost.ts @@ -28,7 +28,7 @@ namespace ts.server { : undefined; const primaryResult = resolveModuleName(moduleName, containingFile, compilerOptions, host); // return result immediately only if it is .ts, .tsx or .d.ts - if (!(primaryResult.resolvedModule && extensionIsTypeScript(primaryResult.resolvedModule.extension)) && globalCache !== undefined) { + if (moduleHasNonRelativeName(moduleName) && !(primaryResult.resolvedModule && extensionIsTypeScript(primaryResult.resolvedModule.extension)) && globalCache !== undefined) { // otherwise try to load typings from @types // create different collection of failed lookup locations for second pass From 8da2bd97bd0389fffb62d852d6e8ddeda53df47c Mon Sep 17 00:00:00 2001 From: Kanchalai Tanglertsampan Date: Thu, 9 Feb 2017 12:32:50 -0800 Subject: [PATCH 14/16] Address code review --- src/compiler/emitter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 03804dfeebe..e881c94cc83 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2239,7 +2239,7 @@ namespace ts { // a // /* End of parameter a */ -> this comment isn't considered to be trailing comment of parameter "a" due to newline // , - if (emitLeadingCommentsOfPosition && delimiter && previousSibling.end !== parentNode.end) { + if (delimiter && previousSibling.end !== parentNode.end) { emitLeadingCommentsOfPosition(previousSibling.end); } write(delimiter); From 84fc29f9005f969f84480e3d142a88087d6b9f71 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 9 Feb 2017 12:46:09 -0800 Subject: [PATCH 15/16] Fix lint failures detected by tslint@4.4.2 --- src/compiler/sys.ts | 2 +- src/harness/fourslash.ts | 2 +- src/harness/harnessLanguageService.ts | 4 ++-- src/harness/unittests/tsserverProjectSystem.ts | 2 +- src/server/cancellationToken/cancellationToken.ts | 2 +- src/services/codefixes/unusedIdentifierFixes.ts | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 8ac797507b1..c90a3484a8a 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -486,7 +486,7 @@ namespace ts { // (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643) let options: any; if (!directoryExists(directoryName) || (isUNCPath(directoryName) && process.platform === "win32")) { - // do nothing if either + // do nothing if either // - target folder does not exist // - this is UNC path on Windows (https://github.com/Microsoft/TypeScript/issues/13874) return noOpFileWatcher; diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index c7f455bd753..fc85fb7276c 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -183,7 +183,7 @@ namespace FourSlash { // The current caret position in the active file public currentCaretPosition = 0; - public lastKnownMarker: string = ""; + public lastKnownMarker = ""; // The file that's currently 'opened' public activeFile: FourSlashFile; diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index cd44fbf7a3a..59930fd98ba 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -5,7 +5,7 @@ namespace Harness.LanguageService { export class ScriptInfo { - public version: number = 1; + public version = 1; public editRanges: { length: number; textChangeRange: ts.TextChangeRange; }[] = []; private lineMap: number[] = undefined; @@ -594,7 +594,7 @@ namespace Harness.LanguageService { class SessionServerHost implements ts.server.ServerHost, ts.server.Logger { args: string[] = []; newLine: string; - useCaseSensitiveFileNames: boolean = false; + useCaseSensitiveFileNames = false; constructor(private host: NativeLanguageServiceHost) { this.newLine = this.host.getNewLine(); diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 93027675bd6..e6f4abde382 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -3115,7 +3115,7 @@ namespace ts.projectSystem { let options = project.getCompilerOptions(); assert.isTrue(options.maxNodeModuleJsDepth === 2); - // Assert the option sticks + // Assert the option sticks projectService.setCompilerOptionsForInferredProjects({ target: ScriptTarget.ES2016 }); project = projectService.inferredProjects[0]; options = project.getCompilerOptions(); diff --git a/src/server/cancellationToken/cancellationToken.ts b/src/server/cancellationToken/cancellationToken.ts index 6d3dec67cc6..de59f3a1bce 100644 --- a/src/server/cancellationToken/cancellationToken.ts +++ b/src/server/cancellationToken/cancellationToken.ts @@ -1,7 +1,7 @@ /// -// TODO: extract services types +// TODO: extract services types interface HostCancellationToken { isCancellationRequested(): boolean; } diff --git a/src/services/codefixes/unusedIdentifierFixes.ts b/src/services/codefixes/unusedIdentifierFixes.ts index 0ca01a81eb1..6c0bc04eca8 100644 --- a/src/services/codefixes/unusedIdentifierFixes.ts +++ b/src/services/codefixes/unusedIdentifierFixes.ts @@ -94,9 +94,9 @@ namespace ts.codefix { return removeSingleItem(namedImports.elements, token); } - // handle case where "import d, * as ns from './file'" + // handle case where "import d, * as ns from './file'" // or "'import {a, b as ns} from './file'" - case SyntaxKind.ImportClause: // this covers both 'import |d|' and 'import |d,| *' + case SyntaxKind.ImportClause: // this covers both 'import |d|' and 'import |d,| *' const importClause = token.parent; if (!importClause.namedBindings) { // |import d from './file'| or |import * as ns from './file'| const importDecl = findImportDeclaration(importClause); From 24ddbe4b60a2d755a604a5f485206eb704e4599b Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 9 Feb 2017 14:55:07 -0800 Subject: [PATCH 16/16] Widen after sub-type-reduction took place --- src/compiler/checker.ts | 6 ++--- .../jsFileClassPropertyType3.errors.txt | 22 +++++++++++++++++++ .../reference/multipleDeclarations.types | 2 +- .../compiler/jsFileClassPropertyType3.ts | 18 +++++++++++++++ 4 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/jsFileClassPropertyType3.errors.txt create mode 100644 tests/cases/compiler/jsFileClassPropertyType3.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 10c5f5422e3..831126adfa1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -3378,7 +3378,7 @@ namespace ts { } // Return the inferred type for a variable, parameter, or property declaration - function getWidenedTypeForJSSpecialPropertyDeclaration(declaration: Declaration): Type { + function getTypeForJSSpecialPropertyDeclaration(declaration: Declaration): Type { const expression = declaration.kind === SyntaxKind.BinaryExpression ? declaration : declaration.kind === SyntaxKind.PropertyAccessExpression ? getAncestor(declaration, SyntaxKind.BinaryExpression) : undefined; @@ -3395,7 +3395,7 @@ namespace ts { } } - return getWidenedType(getWidenedLiteralType(checkExpressionCached(expression.right))); + return getWidenedLiteralType(checkExpressionCached(expression.right)); } // Return the type implied by a binding pattern element. This is the type of the initializer of the element if @@ -3552,7 +3552,7 @@ namespace ts { // * className.prototype.method = expr if (declaration.kind === SyntaxKind.BinaryExpression || declaration.kind === SyntaxKind.PropertyAccessExpression && declaration.parent.kind === SyntaxKind.BinaryExpression) { - type = getUnionType(map(symbol.declarations, getWidenedTypeForJSSpecialPropertyDeclaration), /*subtypeReduction*/ true); + type = getWidenedType(getUnionType(map(symbol.declarations, getTypeForJSSpecialPropertyDeclaration), /*subtypeReduction*/ true)); } else { type = getWidenedTypeForVariableLikeDeclaration(declaration, /*reportErrors*/ true); diff --git a/tests/baselines/reference/jsFileClassPropertyType3.errors.txt b/tests/baselines/reference/jsFileClassPropertyType3.errors.txt new file mode 100644 index 00000000000..bf225095b01 --- /dev/null +++ b/tests/baselines/reference/jsFileClassPropertyType3.errors.txt @@ -0,0 +1,22 @@ +tests/cases/compiler/bar.ts(2,1): error TS2322: Type '"string"' is not assignable to type 'number'. + + +==== tests/cases/compiler/foo.js (0 errors) ==== + + class C { + constructor() { + if (cond) { + this.p = null; + } + else { + this.p = 0; + } + } + } + +==== tests/cases/compiler/bar.ts (1 errors) ==== + + (new C()).p = "string"; // Error + ~~~~~~~~~~~ +!!! error TS2322: Type '"string"' is not assignable to type 'number'. + \ No newline at end of file diff --git a/tests/baselines/reference/multipleDeclarations.types b/tests/baselines/reference/multipleDeclarations.types index c11bd13dffe..195bdc2ad0d 100644 --- a/tests/baselines/reference/multipleDeclarations.types +++ b/tests/baselines/reference/multipleDeclarations.types @@ -21,7 +21,7 @@ C.prototype.m = function() { this.nothing(); >this.nothing() : any >this.nothing : any ->this : { m: any; } +>this : { m: () => void; } >nothing : any } class X { diff --git a/tests/cases/compiler/jsFileClassPropertyType3.ts b/tests/cases/compiler/jsFileClassPropertyType3.ts new file mode 100644 index 00000000000..7c240e942fb --- /dev/null +++ b/tests/cases/compiler/jsFileClassPropertyType3.ts @@ -0,0 +1,18 @@ +// @allowJs: true +// @noEmit: true + +// @filename: foo.js +class C { + constructor() { + if (cond) { + this.p = null; + } + else { + this.p = 0; + } + } +} + +// @filename: bar.ts + +(new C()).p = "string"; // Error