From fd86f40d05cc6f6abff9c89c5340d3a07941eb6f Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 23 May 2019 09:33:07 -0700 Subject: [PATCH 01/44] Include declarationSpan as relevant declaration span when defintion or other places are declaration name Fixes #30849 --- src/server/protocol.ts | 24 +- src/server/session.ts | 237 ++++++++++-------- src/services/findAllReferences.ts | 116 +++++++-- src/services/goToDefinition.ts | 6 +- src/services/services.ts | 23 +- src/services/types.ts | 8 + .../unittests/tsserver/declarationFileMaps.ts | 195 ++++++++++---- src/testRunner/unittests/tsserver/helpers.ts | 67 ++++- .../unittests/tsserver/projectReferences.ts | 56 +++-- src/testRunner/unittests/tsserver/rename.ts | 107 ++++++-- src/testRunner/unittests/tsserver/symLinks.ts | 18 +- .../reference/api/tsserverlibrary.d.ts | 31 ++- tests/baselines/reference/api/typescript.d.ts | 7 + 13 files changed, 658 insertions(+), 237 deletions(-) diff --git a/src/server/protocol.ts b/src/server/protocol.ts index 486208c2819..37bb8d0c045 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -872,8 +872,16 @@ namespace ts.server.protocol { file: string; } + export interface DeclarationTextSpan extends TextSpan { + declarationStart?: Location; + declarationEnd?: Location; + } + + export interface DeclarationFileSpan extends FileSpan, DeclarationTextSpan { + } + export interface DefinitionInfoAndBoundSpan { - definitions: ReadonlyArray; + definitions: ReadonlyArray; textSpan: TextSpan; } @@ -881,7 +889,7 @@ namespace ts.server.protocol { * Definition response message. Gives text range for definition. */ export interface DefinitionResponse extends Response { - body?: FileSpan[]; + body?: DeclarationFileSpan[]; } export interface DefinitionInfoAndBoundSpanReponse extends Response { @@ -892,14 +900,14 @@ namespace ts.server.protocol { * Definition response message. Gives text range for definition. */ export interface TypeDefinitionResponse extends Response { - body?: FileSpan[]; + body?: DeclarationFileSpan[]; } /** * Implementation response message. Gives text range for implementations. */ export interface ImplementationResponse extends Response { - body?: FileSpan[]; + body?: DeclarationFileSpan[]; } /** @@ -942,7 +950,7 @@ namespace ts.server.protocol { } /** @deprecated */ - export interface OccurrencesResponseItem extends FileSpan { + export interface OccurrencesResponseItem extends DeclarationFileSpan { /** * True if the occurrence is a write location, false otherwise. */ @@ -972,7 +980,7 @@ namespace ts.server.protocol { /** * Span augmented with extra information that denotes the kind of the highlighting to be used for span. */ - export interface HighlightSpan extends TextSpan { + export interface HighlightSpan extends DeclarationTextSpan { kind: HighlightSpanKind; } @@ -1007,7 +1015,7 @@ namespace ts.server.protocol { command: CommandTypes.References; } - export interface ReferencesResponseItem extends FileSpan { + export interface ReferencesResponseItem extends DeclarationFileSpan { /** Text of line containing the reference. Including this * with the response avoids latency of editor loading files * to show text of reference line (the server already has @@ -1150,7 +1158,7 @@ namespace ts.server.protocol { locs: RenameTextSpan[]; } - export interface RenameTextSpan extends TextSpan { + export interface RenameTextSpan extends DeclarationTextSpan { readonly prefixText?: string; readonly suffixText?: string; } diff --git a/src/server/session.ts b/src/server/session.ts index 2e9d6948b1a..118a1d93468 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -354,13 +354,17 @@ namespace ts.server { defaultProject, initialLocation, ({ project, location }, getMappedLocation) => { - for (const outputReferencedSymbol of project.getLanguageService().findReferences(location.fileName, location.pos) || emptyArray) { + for (const outputReferencedSymbol of project.getLanguageService().findReferences(location.fileName, location.pos) || emptyArray) { const mappedDefinitionFile = getMappedLocation(project, documentSpanLocation(outputReferencedSymbol.definition)); - const definition: ReferencedSymbolDefinitionInfo = mappedDefinitionFile === undefined ? outputReferencedSymbol.definition : { - ...outputReferencedSymbol.definition, - textSpan: createTextSpan(mappedDefinitionFile.pos, outputReferencedSymbol.definition.textSpan.length), - fileName: mappedDefinitionFile.fileName, - }; + const definition: ReferencedSymbolDefinitionInfo = mappedDefinitionFile === undefined ? + outputReferencedSymbol.definition : + { + ...outputReferencedSymbol.definition, + textSpan: createTextSpan(mappedDefinitionFile.pos, outputReferencedSymbol.definition.textSpan.length), + fileName: mappedDefinitionFile.fileName, + declarationSpan: getMappedDeclarationSpan(outputReferencedSymbol.definition, project) + }; + let symbolToAddTo = find(outputs, o => documentSpansEqual(o.definition, definition)); if (!symbolToAddTo) { symbolToAddTo = { definition, references: [] }; @@ -481,9 +485,39 @@ namespace ts.server { return { fileName, pos: textSpan.start }; } - function getMappedLocation(location: DocumentPosition, projectService: ProjectService, project: Project): DocumentPosition | undefined { + function getMappedLocation(location: DocumentPosition, project: Project): DocumentPosition | undefined { const mapsTo = project.getSourceMapper().tryGetSourcePosition(location); - return mapsTo && projectService.fileExists(toNormalizedPath(mapsTo.fileName)) ? mapsTo : undefined; + return mapsTo && project.projectService.fileExists(toNormalizedPath(mapsTo.fileName)) ? mapsTo : undefined; + } + + function getMappedDocumentSpan(documentSpan: DocumentSpan, project: Project): DocumentSpan | undefined { + const newPosition = getMappedLocation(documentSpanLocation(documentSpan), project); + if (!newPosition) return undefined; + return { + fileName: newPosition.fileName, + textSpan: { + start: newPosition.pos, + length: documentSpan.textSpan.length + }, + originalFileName: documentSpan.fileName, + originalTextSpan: documentSpan.textSpan, + declarationSpan: getMappedDeclarationSpan(documentSpan, project), + originalDeclarationSpan: documentSpan.declarationSpan + }; + } + + function getMappedDeclarationSpan(documentSpan: DocumentSpan, project: Project): TextSpan | undefined { + const declarationSpanStart = documentSpan.declarationSpan && getMappedLocation( + { fileName: documentSpan.fileName, pos: documentSpan.declarationSpan.start }, + project + ); + const declarationSpanEnd = documentSpan.declarationSpan && getMappedLocation( + { fileName: documentSpan.fileName, pos: documentSpan.declarationSpan.start + documentSpan.declarationSpan.length }, + project + ); + return declarationSpanStart && declarationSpanEnd ? + { start: declarationSpanStart.pos, length: declarationSpanEnd.pos - declarationSpanStart.pos } : + undefined; } export interface SessionOptions { @@ -937,7 +971,7 @@ namespace ts.server { : diagnostics.map(d => formatDiag(file, project, d)); } - private getDefinition(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): ReadonlyArray | ReadonlyArray { + private getDefinition(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): ReadonlyArray | ReadonlyArray { const { file, project } = this.getFileAndProject(args); const position = this.getPositionInFile(args, file); const definitions = this.mapDefinitionInfoLocations(project.getLanguageService().getDefinitionAtPosition(file, position) || emptyArray, project); @@ -946,19 +980,13 @@ namespace ts.server { private mapDefinitionInfoLocations(definitions: ReadonlyArray, project: Project): ReadonlyArray { return definitions.map((info): DefinitionInfo => { - const newLoc = getMappedLocation(documentSpanLocation(info), this.projectService, project); - return !newLoc ? info : { + const newDocumentSpan = getMappedDocumentSpan(info, project); + return !newDocumentSpan ? info : { + ...newDocumentSpan, containerKind: info.containerKind, containerName: info.containerName, - fileName: newLoc.fileName, kind: info.kind, name: info.name, - textSpan: { - start: newLoc.pos, - length: info.textSpan.length - }, - originalFileName: info.fileName, - originalTextSpan: info.textSpan, }; }); } @@ -983,7 +1011,7 @@ namespace ts.server { if (simplifiedResult) { return { definitions: this.mapDefinitionInfo(definitions, project), - textSpan: this.toLocationTextSpan(textSpan, scriptInfo) + textSpan: toProcolTextSpan(textSpan, scriptInfo) }; } @@ -998,8 +1026,8 @@ namespace ts.server { return project.getLanguageService().getEmitOutput(file); } - private mapDefinitionInfo(definitions: ReadonlyArray, project: Project): ReadonlyArray { - return definitions.map(def => this.toFileSpan(def.fileName, def.textSpan, project)); + private mapDefinitionInfo(definitions: ReadonlyArray, project: Project): ReadonlyArray { + return definitions.map(def => this.toDeclarationFileSpan(def.fileName, def.textSpan, def.declarationSpan, project)); } /* @@ -1017,7 +1045,9 @@ namespace ts.server { fileName: def.originalFileName, textSpan: def.originalTextSpan, targetFileName: def.fileName, - targetTextSpan: def.textSpan + targetTextSpan: def.textSpan, + declarationSpan: def.originalDeclarationSpan, + targetDeclarationSpan: def.declarationSpan }; } return def; @@ -1035,7 +1065,18 @@ namespace ts.server { }; } - private getTypeDefinition(args: protocol.FileLocationRequestArgs): ReadonlyArray { + private toDeclarationFileSpan(fileName: string, textSpan: TextSpan, declarationSpan: TextSpan | undefined, project: Project): protocol.DeclarationFileSpan { + const result = this.toFileSpan(fileName, textSpan, project) as protocol.DeclarationFileSpan; + if (declarationSpan) { + const declaration = this.toFileSpan(fileName, declarationSpan, project); + result.declarationStart = declaration.start; + result.declarationEnd = declaration.end; + } + return result; + + } + + private getTypeDefinition(args: protocol.FileLocationRequestArgs): ReadonlyArray { const { file, project } = this.getFileAndProject(args); const position = this.getPositionInFile(args, file); @@ -1045,27 +1086,21 @@ namespace ts.server { private mapImplementationLocations(implementations: ReadonlyArray, project: Project): ReadonlyArray { return implementations.map((info): ImplementationLocation => { - const newLoc = getMappedLocation(documentSpanLocation(info), this.projectService, project); - return !newLoc ? info : { - fileName: newLoc.fileName, + const newDocumentSpan = getMappedDocumentSpan(info, project); + return !newDocumentSpan ? info : { + ...newDocumentSpan, kind: info.kind, displayParts: info.displayParts, - textSpan: { - start: newLoc.pos, - length: info.textSpan.length - }, - originalFileName: info.fileName, - originalTextSpan: info.textSpan, }; }); } - private getImplementation(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): ReadonlyArray | ReadonlyArray { + private getImplementation(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): ReadonlyArray | ReadonlyArray { const { file, project } = this.getFileAndProject(args); const position = this.getPositionInFile(args, file); const implementations = this.mapImplementationLocations(project.getLanguageService().getImplementationAtPosition(file, position) || emptyArray, project); if (simplifiedResult) { - return implementations.map(({ fileName, textSpan }) => this.toFileSpan(fileName, textSpan, project)); + return implementations.map(({ fileName, textSpan, declarationSpan }) => this.toDeclarationFileSpan(fileName, textSpan, declarationSpan, project)); } return implementations.map(Session.mapToOriginalLocation); @@ -1083,14 +1118,11 @@ namespace ts.server { } return occurrences.map(occurrence => { - const { fileName, isWriteAccess, textSpan, isInString } = occurrence; + const { fileName, isWriteAccess, textSpan, isInString, declarationSpan } = occurrence; const scriptInfo = project.getScriptInfo(fileName)!; - const result: protocol.OccurrencesResponseItem = { - start: scriptInfo.positionToLineOffset(textSpan.start), - end: scriptInfo.positionToLineOffset(textSpanEnd(textSpan)), - file: fileName, - isWriteAccess, - }; + const result = toProtocolDeclarationTextSpan(textSpan, declarationSpan, scriptInfo) as protocol.OccurrencesResponseItem; + result.file = fileName; + result.isWriteAccess = isWriteAccess; // no need to serialize the property if it is not true if (isInString) { result.isInString = isInString; @@ -1139,33 +1171,20 @@ namespace ts.server { const position = this.getPositionInFile(args, file); const documentHighlights = project.getLanguageService().getDocumentHighlights(file, position, args.filesToSearch); - if (!documentHighlights) { - return emptyArray; - } - - if (simplifiedResult) { - return documentHighlights.map(convertToDocumentHighlightsItem); - } - else { - return documentHighlights; - } - - function convertToDocumentHighlightsItem(documentHighlights: DocumentHighlights): protocol.DocumentHighlightsItem { - const { fileName, highlightSpans } = documentHighlights; + if (!documentHighlights) return emptyArray; + if (!simplifiedResult) return documentHighlights; + return documentHighlights.map(({ fileName, highlightSpans }) => { const scriptInfo = project.getScriptInfo(fileName)!; return { file: fileName, - highlightSpans: highlightSpans.map(convertHighlightSpan) + highlightSpans: highlightSpans.map(({ textSpan, kind, declarationSpan }) => { + const result = toProtocolDeclarationTextSpan(textSpan, declarationSpan, scriptInfo) as protocol.HighlightSpan; + result.kind = kind; + return result; + }) }; - - function convertHighlightSpan(highlightSpan: HighlightSpan): protocol.HighlightSpan { - const { textSpan, kind } = highlightSpan; - const start = scriptInfo.positionToLineOffset(textSpan.start); - const end = scriptInfo.positionToLineOffset(textSpanEnd(textSpan)); - return { start, end, kind }; - } - } + }); } private setCompilerOptionsForInferredProjects(args: protocol.SetCompilerOptionsForInferredProjectsArgs): void { @@ -1258,7 +1277,7 @@ namespace ts.server { if (info.canRename) { const { canRename, fileToRename, displayName, fullDisplayName, kind, kindModifiers, triggerSpan } = info; return identity( - { canRename, fileToRename, displayName, fullDisplayName, kind, kindModifiers, triggerSpan: this.toLocationTextSpan(triggerSpan, scriptInfo) }); + { canRename, fileToRename, displayName, fullDisplayName, kind, kindModifiers, triggerSpan: toProcolTextSpan(triggerSpan, scriptInfo) }); } else { return info; @@ -1267,11 +1286,11 @@ namespace ts.server { private toSpanGroups(locations: ReadonlyArray): ReadonlyArray { const map = createMap(); - for (const { fileName, textSpan, originalTextSpan: _, originalFileName: _1, ...prefixSuffixText } of locations) { + for (const { fileName, textSpan, declarationSpan, originalDeclarationSpan: _2, originalTextSpan: _, originalFileName: _1, ...prefixSuffixText } of locations) { let group = map.get(fileName); if (!group) map.set(fileName, group = { file: fileName, locs: [] }); const scriptInfo = Debug.assertDefined(this.projectService.getScriptInfo(fileName)); - group.locs.push({ ...this.toLocationTextSpan(textSpan, scriptInfo), ...prefixSuffixText }); + group.locs.push({ ...toProtocolDeclarationTextSpan(textSpan, declarationSpan, scriptInfo), ...prefixSuffixText }); } return arrayFrom(map.values()); } @@ -1286,30 +1305,32 @@ namespace ts.server { { fileName: args.file, pos: position }, ); - if (simplifiedResult) { - const defaultProject = this.getDefaultProject(args); - const scriptInfo = defaultProject.getScriptInfoForNormalizedPath(file)!; - const nameInfo = defaultProject.getLanguageService().getQuickInfoAtPosition(file, position); - const symbolDisplayString = nameInfo ? displayPartsToString(nameInfo.displayParts) : ""; - const nameSpan = nameInfo && nameInfo.textSpan; - const symbolStartOffset = nameSpan ? scriptInfo.positionToLineOffset(nameSpan.start).offset : 0; - const symbolName = nameSpan ? scriptInfo.getSnapshot().getText(nameSpan.start, textSpanEnd(nameSpan)) : ""; - const refs: ReadonlyArray = flatMap(references, referencedSymbol => - referencedSymbol.references.map(({ fileName, textSpan, isWriteAccess, isDefinition }): protocol.ReferencesResponseItem => { - const scriptInfo = Debug.assertDefined(this.projectService.getScriptInfo(fileName)); - const start = scriptInfo.positionToLineOffset(textSpan.start); - const lineSpan = scriptInfo.lineToTextSpan(start.line - 1); - const lineText = scriptInfo.getSnapshot().getText(lineSpan.start, textSpanEnd(lineSpan)).replace(/\r|\n/g, ""); - return { ...toFileSpan(fileName, textSpan, scriptInfo), lineText, isWriteAccess, isDefinition }; - })); - const result: protocol.ReferencesResponseBody = { refs, symbolName, symbolStartOffset, symbolDisplayString }; - return result; - } - else { - return references; - } - } + if (!simplifiedResult) return references; + const defaultProject = this.getDefaultProject(args); + const scriptInfo = defaultProject.getScriptInfoForNormalizedPath(file)!; + const nameInfo = defaultProject.getLanguageService().getQuickInfoAtPosition(file, position); + const symbolDisplayString = nameInfo ? displayPartsToString(nameInfo.displayParts) : ""; + const nameSpan = nameInfo && nameInfo.textSpan; + const symbolStartOffset = nameSpan ? scriptInfo.positionToLineOffset(nameSpan.start).offset : 0; + const symbolName = nameSpan ? scriptInfo.getSnapshot().getText(nameSpan.start, textSpanEnd(nameSpan)) : ""; + const refs: ReadonlyArray = flatMap(references, referencedSymbol => + referencedSymbol.references.map(({ fileName, textSpan, declarationSpan, isWriteAccess, isDefinition }): protocol.ReferencesResponseItem => { + const scriptInfo = Debug.assertDefined(this.projectService.getScriptInfo(fileName)); + const span = toProtocolDeclarationTextSpan(textSpan, declarationSpan, scriptInfo); + const lineSpan = scriptInfo.lineToTextSpan(span.start.line - 1); + const lineText = scriptInfo.getSnapshot().getText(lineSpan.start, textSpanEnd(lineSpan)).replace(/\r|\n/g, ""); + return { + file: fileName, + ...span, + lineText, + isWriteAccess, + isDefinition + }; + })); + const result: protocol.ReferencesResponseBody = { refs, symbolName, symbolStartOffset, symbolDisplayString }; + return result; + } /** * @param fileName is the name of the file to be opened * @param fileContent is a version of the file content that is known to be more up to date than the one on disk @@ -1357,8 +1378,8 @@ namespace ts.server { if (simplifiedResult) { const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file)!; return spans.map(s => ({ - textSpan: this.toLocationTextSpan(s.textSpan, scriptInfo), - hintSpan: this.toLocationTextSpan(s.hintSpan, scriptInfo), + textSpan: toProcolTextSpan(s.textSpan, scriptInfo), + hintSpan: toProcolTextSpan(s.hintSpan, scriptInfo), bannerText: s.bannerText, autoCollapse: s.autoCollapse, kind: s.kind @@ -1547,7 +1568,7 @@ namespace ts.server { const entries = mapDefined(completions.entries, entry => { if (completions.isMemberCompletion || startsWith(entry.name.toLowerCase(), prefix.toLowerCase())) { const { name, kind, kindModifiers, sortText, insertText, replacementSpan, hasAction, source, isRecommended } = entry; - const convertedSpan = replacementSpan ? this.toLocationTextSpan(replacementSpan, scriptInfo) : undefined; + const convertedSpan = replacementSpan ? toProcolTextSpan(replacementSpan, scriptInfo) : undefined; // Use `hasAction || undefined` to avoid serializing `false`. return { name, kind, kindModifiers, sortText, insertText, replacementSpan: convertedSpan, hasAction: hasAction || undefined, source, isRecommended }; } @@ -1710,7 +1731,7 @@ namespace ts.server { text: item.text, kind: item.kind, kindModifiers: item.kindModifiers, - spans: item.spans.map(span => this.toLocationTextSpan(span, scriptInfo)), + spans: item.spans.map(span => toProcolTextSpan(span, scriptInfo)), childItems: this.mapLocationNavigationBarItems(item.childItems, scriptInfo), indent: item.indent })); @@ -1731,19 +1752,12 @@ namespace ts.server { text: tree.text, kind: tree.kind, kindModifiers: tree.kindModifiers, - spans: tree.spans.map(span => this.toLocationTextSpan(span, scriptInfo)), - nameSpan: tree.nameSpan && this.toLocationTextSpan(tree.nameSpan, scriptInfo), + spans: tree.spans.map(span => toProcolTextSpan(span, scriptInfo)), + nameSpan: tree.nameSpan && toProcolTextSpan(tree.nameSpan, scriptInfo), childItems: map(tree.childItems, item => this.toLocationNavigationTree(item, scriptInfo)) }; } - private toLocationTextSpan(span: TextSpan, scriptInfo: ScriptInfo): protocol.TextSpan { - return { - start: scriptInfo.positionToLineOffset(span.start), - end: scriptInfo.positionToLineOffset(textSpanEnd(span)) - }; - } - private getNavigationTree(args: protocol.FileRequestArgs, simplifiedResult: boolean): protocol.NavigationTree | NavigationTree | undefined { const { file, languageService } = this.getFileAndLanguageServiceForSyntacticOperation(args); const tree = languageService.getNavigationTree(file); @@ -2001,7 +2015,7 @@ namespace ts.server { return !spans ? undefined : simplifiedResult - ? spans.map(span => this.toLocationTextSpan(span, scriptInfo)) + ? spans.map(span => toProcolTextSpan(span, scriptInfo)) : spans; } @@ -2073,7 +2087,7 @@ namespace ts.server { private mapSelectionRange(selectionRange: SelectionRange, scriptInfo: ScriptInfo): protocol.SelectionRange { const result: protocol.SelectionRange = { - textSpan: this.toLocationTextSpan(selectionRange.textSpan, scriptInfo), + textSpan: toProcolTextSpan(selectionRange.textSpan, scriptInfo), }; if (selectionRange.parent) { result.parent = this.mapSelectionRange(selectionRange.parent, scriptInfo); @@ -2558,8 +2572,19 @@ namespace ts.server { readonly project: Project; } - function toFileSpan(fileName: string, textSpan: TextSpan, scriptInfo: ScriptInfo): protocol.FileSpan { - return { file: fileName, start: scriptInfo.positionToLineOffset(textSpan.start), end: scriptInfo.positionToLineOffset(textSpanEnd(textSpan)) }; + function toProcolTextSpan(textSpan: TextSpan, scriptInfo: ScriptInfo): protocol.TextSpan { + return { + start: scriptInfo.positionToLineOffset(textSpan.start), + end: scriptInfo.positionToLineOffset(textSpanEnd(textSpan)) + }; + } + + function toProtocolDeclarationTextSpan(span: TextSpan, declarationSpan: TextSpan | undefined, scriptInfo: ScriptInfo): protocol.DeclarationTextSpan { + const result = toProcolTextSpan(span, scriptInfo) as protocol.DeclarationTextSpan; + if (!declarationSpan) return result; + result.declarationStart = scriptInfo.positionToLineOffset(declarationSpan.start); + result.declarationEnd = scriptInfo.positionToLineOffset(textSpanEnd(declarationSpan)); + return result; } function convertTextChangeToCodeEdit(change: TextChange, scriptInfo: ScriptInfoOrConfig): protocol.CodeEdit { diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index cf0046d2688..b29061076ff 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -19,6 +19,7 @@ namespace ts.FindAllReferences { export interface NodeEntry { readonly kind: NodeEntryKind; readonly node: Node; + readonly declaration?: Node; } export interface SpanEntry { readonly kind: EntryKind.Span; @@ -26,7 +27,47 @@ namespace ts.FindAllReferences { readonly textSpan: TextSpan; } export function nodeEntry(node: Node, kind: NodeEntryKind = EntryKind.Node): NodeEntry { - return { kind, node: (node as NamedDeclaration).name || node }; + const declaration = getDeclarationForDeclarationSpan( + isDeclaration(node) ? + node : + node.parent && isDeclaration(node.parent) && node.parent.name === node ? + node.parent : + undefined + ); + return { kind, node: (node as NamedDeclaration).name || node, declaration }; + } + + export function getDeclarationForDeclarationSpan(node: NamedDeclaration | undefined): Node | undefined { + if (!node) return undefined; + switch (node.kind) { + case SyntaxKind.VariableDeclaration: + return !isVariableDeclarationList(node.parent) || node.parent.declarations.length !== 1 ? + node : + isVariableStatement(node.parent.parent) ? + node.parent.parent : + node.parent; + + case SyntaxKind.BindingElement: + return getDeclarationForDeclarationSpan(node.parent.parent as NamedDeclaration); + + case SyntaxKind.ImportSpecifier: + return node.parent.parent.parent; + + case SyntaxKind.ExportSpecifier: + case SyntaxKind.NamespaceImport: + return node.parent.parent; + + case SyntaxKind.ImportClause: + return node.parent; + + // Not really interesting definition + // Should we show whole object literal instead? + case SyntaxKind.ShorthandPropertyAssignment: + return undefined; + + default: + return node; + } } export interface Options { @@ -123,7 +164,16 @@ namespace ts.FindAllReferences { const { symbol } = def; const { displayParts, kind } = getDefinitionKindAndDisplayParts(symbol, checker, originalNode); const name = displayParts.map(p => p.text).join(""); - return { node: symbol.declarations ? getNameOfDeclaration(first(symbol.declarations)) || first(symbol.declarations) : originalNode, name, kind, displayParts }; + const declaration = symbol.declarations ? first(symbol.declarations) : undefined; + return { + node: declaration ? + getNameOfDeclaration(declaration) || declaration : + originalNode, + name, + kind, + displayParts, + declaration: getDeclarationForDeclarationSpan(declaration) + }; } case DefinitionKind.Label: { const { node } = def; @@ -150,9 +200,21 @@ namespace ts.FindAllReferences { } })(); - const { node, name, kind, displayParts } = info; + const { node, name, kind, displayParts, declaration } = info; const sourceFile = node.getSourceFile(); - return { containerKind: ScriptElementKind.unknown, containerName: "", fileName: sourceFile.fileName, kind, name, textSpan: getTextSpan(isComputedPropertyName(node) ? node.expression : node, sourceFile), displayParts }; + const result: ReferencedSymbolDefinitionInfo = { + containerKind: ScriptElementKind.unknown, + containerName: "", + fileName: sourceFile.fileName, + kind, + name, + textSpan: getTextSpan(isComputedPropertyName(node) ? node.expression : node, sourceFile), + displayParts + }; + if (declaration) { + result.declarationSpan = getTextSpan(declaration, sourceFile); + } + return result; } function getDefinitionKindAndDisplayParts(symbol: Symbol, checker: TypeChecker, node: Node): { displayParts: SymbolDisplayPart[], kind: ScriptElementKind } { @@ -168,14 +230,13 @@ namespace ts.FindAllReferences { } export function toReferenceEntry(entry: Entry): ReferenceEntry { - const { textSpan, fileName } = entryToDocumentSpan(entry); + const documentSpan = entryToDocumentSpan(entry); if (entry.kind === EntryKind.Span) { - return { textSpan, fileName, isWriteAccess: false, isDefinition: false }; + return { ...documentSpan, isWriteAccess: false, isDefinition: false }; } const { kind, node } = entry; return { - textSpan, - fileName, + ...documentSpan, isWriteAccess: isWriteAccessForReference(node), isDefinition: node.kind === SyntaxKind.DefaultKeyword || !!getDeclarationFromName(node) @@ -190,7 +251,11 @@ namespace ts.FindAllReferences { } else { const sourceFile = entry.node.getSourceFile(); - return { textSpan: getTextSpan(entry.node, sourceFile), fileName: sourceFile.fileName }; + const result: DocumentSpan = { textSpan: getTextSpan(entry.node, sourceFile), fileName: sourceFile.fileName }; + if (entry.declaration) { + result.declarationSpan = getTextSpan(entry.declaration, sourceFile); + } + return result; } } @@ -223,14 +288,16 @@ namespace ts.FindAllReferences { } function toImplementationLocation(entry: Entry, checker: TypeChecker): ImplementationLocation { + const documentSpan = entryToDocumentSpan(entry); if (entry.kind !== EntryKind.Span) { const { node } = entry; - const sourceFile = node.getSourceFile(); - return { textSpan: getTextSpan(node, sourceFile), fileName: sourceFile.fileName, ...implementationKindDisplayParts(node, checker) }; + return { + ...documentSpan, + ...implementationKindDisplayParts(node, checker) + }; } else { - const { textSpan, fileName } = entry; - return { textSpan, fileName, kind: ScriptElementKind.unknown, displayParts: [] }; + return { ...documentSpan, kind: ScriptElementKind.unknown, displayParts: [] }; } } @@ -257,20 +324,27 @@ namespace ts.FindAllReferences { } export function toHighlightSpan(entry: Entry): { fileName: string, span: HighlightSpan } { + const documentSpan = entryToDocumentSpan(entry); if (entry.kind === EntryKind.Span) { - const { fileName, textSpan } = entry; - return { fileName, span: { textSpan, kind: HighlightSpanKind.reference } }; + return { + fileName: documentSpan.fileName, + span: { + textSpan: documentSpan.textSpan, + kind: HighlightSpanKind.reference + } + }; } - const { node, kind } = entry; - const sourceFile = node.getSourceFile(); - const writeAccess = isWriteAccessForReference(node); + const writeAccess = isWriteAccessForReference(entry.node); const span: HighlightSpan = { - textSpan: getTextSpan(node, sourceFile), + textSpan: documentSpan.textSpan, kind: writeAccess ? HighlightSpanKind.writtenReference : HighlightSpanKind.reference, - isInString: kind === EntryKind.StringLiteral ? true : undefined, + isInString: entry.kind === EntryKind.StringLiteral ? true : undefined, }; - return { fileName: sourceFile.fileName, span }; + if (documentSpan.declarationSpan) { + span.declarationSpan = documentSpan.declarationSpan; + } + return { fileName: documentSpan.fileName, span }; } function getTextSpan(node: Node, sourceFile: SourceFile): TextSpan { diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index 8f495aadfe1..7a04184c5d9 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -279,7 +279,11 @@ namespace ts.GoToDefinition { kind: symbolKind, name: symbolName, containerKind: undefined!, // TODO: GH#18217 - containerName + containerName, + declarationSpan: createTextSpanFromNode( + FindAllReferences.getDeclarationForDeclarationSpan(declaration)!, + sourceFile + ) }; } diff --git a/src/services/services.ts b/src/services/services.ts index 6c882bbb28f..cae6ce7ac47 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1544,13 +1544,22 @@ namespace ts { /// References and Occurrences function getOccurrencesAtPosition(fileName: string, position: number): ReadonlyArray | undefined { - return flatMap(getDocumentHighlights(fileName, position, [fileName]), entry => entry.highlightSpans.map(highlightSpan => ({ - fileName: entry.fileName, - textSpan: highlightSpan.textSpan, - isWriteAccess: highlightSpan.kind === HighlightSpanKind.writtenReference, - isDefinition: false, - isInString: highlightSpan.isInString, - }))); + return flatMap( + getDocumentHighlights(fileName, position, [fileName]), + entry => entry.highlightSpans.map(highlightSpan => { + const result: ReferenceEntry = { + fileName: entry.fileName, + textSpan: highlightSpan.textSpan, + isWriteAccess: highlightSpan.kind === HighlightSpanKind.writtenReference, + isDefinition: false, + isInString: highlightSpan.isInString, + }; + if (highlightSpan.declarationSpan) { + result.declarationSpan = highlightSpan.declarationSpan; + } + return result; + }) + ); } function getDocumentHighlights(fileName: string, position: number, filesToSearch: ReadonlyArray): DocumentHighlights[] | undefined { diff --git a/src/services/types.ts b/src/services/types.ts index 8dee6c4f053..8a185cddced 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -613,6 +613,13 @@ namespace ts { */ originalTextSpan?: TextSpan; originalFileName?: string; + + /** + * If DocumentSpan.textSpan is the span for name of the declaration, + * then this is the span for relevant declaration + */ + declarationSpan?: TextSpan; + originalDeclarationSpan?: TextSpan; } export interface RenameLocation extends DocumentSpan { @@ -647,6 +654,7 @@ namespace ts { fileName?: string; isInString?: true; textSpan: TextSpan; + declarationSpan?: TextSpan; kind: HighlightSpanKind; } diff --git a/src/testRunner/unittests/tsserver/declarationFileMaps.ts b/src/testRunner/unittests/tsserver/declarationFileMaps.ts index 200d7af0240..1ab0928630c 100644 --- a/src/testRunner/unittests/tsserver/declarationFileMaps.ts +++ b/src/testRunner/unittests/tsserver/declarationFileMaps.ts @@ -1,28 +1,43 @@ namespace ts.projectSystem { - function protocolFileSpanFromSubstring(file: File, substring: string, options?: SpanFromSubstringOptions): protocol.FileSpan { - return { file: file.path, ...protocolTextSpanFromSubstring(file.content, substring, options) }; + interface DocumentSpanFromSubstring { + file: File; + text: string; + options?: SpanFromSubstringOptions; + declarationText?: string; + declarationOptions?: SpanFromSubstringOptions; + } + function documentSpanFromSubstring({ file, text, declarationText, options, declarationOptions }: DocumentSpanFromSubstring): DocumentSpan { + const result: DocumentSpan = { fileName: file.path, textSpan: textSpanFromSubstring(file.content, text, options) }; + if (declarationText) { + const declarationSpan = documentSpanFromSubstring({ file, text: declarationText, options: declarationOptions }); + result.declarationSpan = declarationSpan.textSpan; + } + return result; } - function documentSpanFromSubstring(file: File, substring: string, options?: SpanFromSubstringOptions): DocumentSpan { - return { fileName: file.path, textSpan: textSpanFromSubstring(file.content, substring, options) }; + function renameLocation(input: DocumentSpanFromSubstring): RenameLocation { + return documentSpanFromSubstring(input); } - function renameLocation(file: File, substring: string, options?: SpanFromSubstringOptions): RenameLocation { - return documentSpanFromSubstring(file, substring, options); + interface MakeReferenceItem extends DocumentSpanFromSubstring { + isDefinition: boolean; + lineText: string; } - - function makeReferenceItem(file: File, isDefinition: boolean, text: string, lineText: string, options?: SpanFromSubstringOptions): protocol.ReferencesResponseItem { + function makeReferenceItem({ isDefinition, lineText, ...rest }: MakeReferenceItem): protocol.ReferencesResponseItem { return { - ...protocolFileSpanFromSubstring(file, text, options), + ...protocolDeclarationFileSpanFromSubstring(rest), isDefinition, isWriteAccess: isDefinition, lineText, }; } - function makeReferenceEntry(file: File, isDefinition: boolean, text: string, options?: SpanFromSubstringOptions): ReferenceEntry { + interface MakeReferenceEntry extends DocumentSpanFromSubstring { + isDefinition: boolean; + } + function makeReferenceEntry({ isDefinition, ...rest }: MakeReferenceEntry): ReferenceEntry { return { - ...documentSpanFromSubstring(file, text, options), + ...documentSpanFromSubstring(rest), isDefinition, isWriteAccess: isDefinition, isInString: undefined, @@ -190,7 +205,13 @@ namespace ts.projectSystem { it("goToDefinition", () => { const session = makeSampleProjects(); const response = executeSessionRequest(session, protocol.CommandTypes.Definition, protocolFileLocationFromSubstring(userTs, "fnA()")); - assert.deepEqual(response, [protocolFileSpanFromSubstring(aTs, "fnA")]); + assert.deepEqual(response, [ + protocolDeclarationFileSpanFromSubstring({ + file: aTs, + text: "fnA", + declarationText: "export function fnA() {}" + }) + ]); verifySingleInferredProject(session); }); @@ -199,7 +220,13 @@ namespace ts.projectSystem { const response = executeSessionRequest(session, protocol.CommandTypes.DefinitionAndBoundSpan, protocolFileLocationFromSubstring(userTs, "fnA()")); assert.deepEqual(response, { textSpan: protocolTextSpanFromSubstring(userTs.content, "fnA"), - definitions: [protocolFileSpanFromSubstring(aTs, "fnA")], + definitions: [ + protocolDeclarationFileSpanFromSubstring({ + file: aTs, + text: "fnA", + declarationText: "export function fnA() {}" + }) + ], }); verifySingleInferredProject(session); }); @@ -209,7 +236,13 @@ namespace ts.projectSystem { const response = executeSessionRequest(session, protocol.CommandTypes.DefinitionAndBoundSpan, protocolFileLocationFromSubstring(userTs, "fnA()")); assert.deepEqual(response, { textSpan: protocolTextSpanFromSubstring(userTs.content, "fnA"), - definitions: [protocolFileSpanFromSubstring(aTs, "fnA")], + definitions: [ + protocolDeclarationFileSpanFromSubstring({ + file: aTs, + text: "fnA", + declarationText: "export function fnA() {}" + }) + ], }); checkNumberOfProjects(session.getProjectService(), { configuredProjects: 1 }); verifyUserTsConfigProject(session); @@ -230,14 +263,25 @@ namespace ts.projectSystem { it("goToType", () => { const session = makeSampleProjects(); const response = executeSessionRequest(session, protocol.CommandTypes.TypeDefinition, protocolFileLocationFromSubstring(userTs, "instanceA")); - assert.deepEqual(response, [protocolFileSpanFromSubstring(aTs, "IfaceA")]); + assert.deepEqual(response, [ + protocolDeclarationFileSpanFromSubstring({ + file: aTs, + text: "IfaceA", + declarationText: "export interface IfaceA {}" + }) + ]); verifySingleInferredProject(session); }); it("goToImplementation", () => { const session = makeSampleProjects(); const response = executeSessionRequest(session, protocol.CommandTypes.Implementation, protocolFileLocationFromSubstring(userTs, "fnA()")); - assert.deepEqual(response, [protocolFileSpanFromSubstring(aTs, "fnA")]); + assert.deepEqual(response, [ + protocolDeclarationFileSpanFromSubstring({ + file: aTs, + text: "fnA", + declarationText: "export function fnA() {}" + })]); verifySingleInferredProject(session); }); @@ -245,7 +289,13 @@ namespace ts.projectSystem { const session = makeSampleProjects(); const response = executeSessionRequest(session, CommandNames.Definition, protocolFileLocationFromSubstring(userTs, "fnB()")); // bTs does not exist, so stick with bDts - assert.deepEqual(response, [protocolFileSpanFromSubstring(bDts, "fnB")]); + assert.deepEqual(response, [ + protocolDeclarationFileSpanFromSubstring({ + file: bDts, + text: "fnB", + declarationText: "export declare function fnB(): void;" + }) + ]); verifySingleInferredProject(session); }); @@ -254,7 +304,10 @@ namespace ts.projectSystem { const response = executeSessionRequest(session, CommandNames.Navto, { file: userTs.path, searchValue: "fn" }); assert.deepEqual | undefined>(response, [ { - ...protocolFileSpanFromSubstring(bDts, "export declare function fnB(): void;"), + ...protocolFileSpanFromSubstring({ + file: bDts, + text: "export declare function fnB(): void;" + }), name: "fnB", matchKind: "prefix", isCaseSensitive: true, @@ -262,7 +315,10 @@ namespace ts.projectSystem { kindModifiers: "export,declare", }, { - ...protocolFileSpanFromSubstring(userTs, "export function fnUser() { a.fnA(); b.fnB(); a.instanceA; }"), + ...protocolFileSpanFromSubstring({ + file: userTs, + text: "export function fnUser() { a.fnA(); b.fnB(); a.instanceA; }" + }), name: "fnUser", matchKind: "prefix", isCaseSensitive: true, @@ -270,7 +326,10 @@ namespace ts.projectSystem { kindModifiers: "export", }, { - ...protocolFileSpanFromSubstring(aTs, "export function fnA() {}"), + ...protocolFileSpanFromSubstring({ + file: aTs, + text: "export function fnA() {}" + }), name: "fnA", matchKind: "prefix", isCaseSensitive: true, @@ -282,9 +341,20 @@ namespace ts.projectSystem { verifyATsConfigOriginalProject(session); }); - const referenceATs = (aTs: File): protocol.ReferencesResponseItem => makeReferenceItem(aTs, /*isDefinition*/ true, "fnA", "export function fnA() {}"); + const referenceATs = (aTs: File): protocol.ReferencesResponseItem => makeReferenceItem({ + file: aTs, + isDefinition: true, + text: "fnA", + declarationText: "export function fnA() {}", + lineText: "export function fnA() {}" + }); const referencesUserTs = (userTs: File): ReadonlyArray => [ - makeReferenceItem(userTs, /*isDefinition*/ false, "fnA", "export function fnUser() { a.fnA(); b.fnB(); a.instanceA; }"), + makeReferenceItem({ + file: userTs, + isDefinition: false, + text: "fnA", + lineText: "export function fnUser() { a.fnA(); b.fnB(); a.instanceA; }" + }), ]; it("findAllReferences", () => { @@ -325,7 +395,11 @@ namespace ts.projectSystem { assert.deepEqual>(responseFull, [ { definition: { - ...documentSpanFromSubstring(aTs, "fnA"), + ...documentSpanFromSubstring({ + file: aTs, + text: "fnA", + declarationText: "export function fnA() {}" + }), kind: ScriptElementKind.functionElement, name: "function fnA(): void", containerKind: ScriptElementKind.unknown, @@ -342,8 +416,8 @@ namespace ts.projectSystem { ], }, references: [ - makeReferenceEntry(userTs, /*isDefinition*/ false, "fnA"), - makeReferenceEntry(aTs, /*isDefinition*/ true, "fnA"), + makeReferenceEntry({ file: userTs, /*isDefinition*/ isDefinition: false, text: "fnA" }), + makeReferenceEntry({ file: aTs, /*isDefinition*/ isDefinition: true, text: "fnA", declarationText: "export function fnA() {}" }), ], }, ]); @@ -374,6 +448,12 @@ namespace ts.projectSystem { assert.deepEqual>(responseFull, [ { definition: { + ...documentSpanFromSubstring({ + file: aTs, + text: "f", + options: { index: 1 }, + declarationText: "function f() {}" + }), containerKind: ScriptElementKind.unknown, containerName: "", displayParts: [ @@ -386,10 +466,8 @@ namespace ts.projectSystem { spacePart(), keywordPart(SyntaxKind.VoidKeyword), ], - fileName: aTs.path, kind: ScriptElementKind.functionElement, name: "function f(): void", - textSpan: { start: 9, length: 1 }, }, references: [ { @@ -399,13 +477,13 @@ namespace ts.projectSystem { isWriteAccess: false, textSpan: { start: 0, length: 1 }, }, - { - fileName: aTs.path, - isDefinition: true, - isInString: undefined, - isWriteAccess: true, - textSpan: { start: 9, length: 1 }, - }, + makeReferenceEntry({ + file: aTs, + text: "f", + options: { index: 1 }, + declarationText: "function f() {}", + isDefinition: true + }) ], } ]); @@ -417,8 +495,19 @@ namespace ts.projectSystem { const response = executeSessionRequest(session, protocol.CommandTypes.References, protocolFileLocationFromSubstring(userTs, "fnB()")); assert.deepEqual(response, { refs: [ - makeReferenceItem(bDts, /*isDefinition*/ true, "fnB", "export declare function fnB(): void;"), - makeReferenceItem(userTs, /*isDefinition*/ false, "fnB", "export function fnUser() { a.fnA(); b.fnB(); a.instanceA; }"), + makeReferenceItem({ + file: bDts, + isDefinition: true, + text: "fnB", + declarationText: "export declare function fnB(): void;", + lineText: "export declare function fnB(): void;" + }), + makeReferenceItem({ + file: userTs, + isDefinition: false, + text: "fnB", + lineText: "export function fnUser() { a.fnA(); b.fnB(); a.instanceA; }" + }), ], symbolName: "fnB", symbolStartOffset: protocolLocationFromSubstring(userTs.content, "fnB()").offset, @@ -429,11 +518,22 @@ namespace ts.projectSystem { const renameATs = (aTs: File): protocol.SpanGroup => ({ file: aTs.path, - locs: [protocolRenameSpanFromSubstring(aTs.content, "fnA")], + locs: [ + protocolRenameSpanFromSubstring({ + fileText: aTs.content, + text: "fnA", + declarationText: "export function fnA() {}" + }) + ], }); const renameUserTs = (userTs: File): protocol.SpanGroup => ({ file: userTs.path, - locs: [protocolRenameSpanFromSubstring(userTs.content, "fnA")], + locs: [ + protocolRenameSpanFromSubstring({ + fileText: userTs.content, + text: "fnA" + }) + ], }); it("renameLocations", () => { @@ -477,8 +577,8 @@ namespace ts.projectSystem { const session = makeSampleProjects(); const response = executeSessionRequest(session, protocol.CommandTypes.RenameLocationsFull, protocolFileLocationFromSubstring(userTs, "fnA()")); assert.deepEqual>(response, [ - renameLocation(userTs, "fnA"), - renameLocation(aTs, "fnA"), + renameLocation({ file: userTs, text: "fnA" }), + renameLocation({ file: aTs, text: "fnA", declarationText: "export function fnA() {}" }), ]); verifyATsConfigOriginalProject(session); }); @@ -499,11 +599,22 @@ namespace ts.projectSystem { locs: [ { file: bDts.path, - locs: [protocolRenameSpanFromSubstring(bDts.content, "fnB")], + locs: [ + protocolRenameSpanFromSubstring({ + fileText: bDts.content, + text: "fnB", + declarationText: "export declare function fnB(): void;" + }) + ], }, { file: userTs.path, - locs: [protocolRenameSpanFromSubstring(userTs.content, "fnB")], + locs: [ + protocolRenameSpanFromSubstring({ + fileText: userTs.content, + text: "fnB" + }) + ], }, ], }); diff --git a/src/testRunner/unittests/tsserver/helpers.ts b/src/testRunner/unittests/tsserver/helpers.ts index 3cd1d605996..e9c06a7e859 100644 --- a/src/testRunner/unittests/tsserver/helpers.ts +++ b/src/testRunner/unittests/tsserver/helpers.ts @@ -505,13 +505,66 @@ namespace ts.projectSystem { return { start: toLocation(span.start), end: toLocation(textSpanEnd(span)) }; } - export function protocolRenameSpanFromSubstring( - str: string, - substring: string, - options?: SpanFromSubstringOptions, - prefixSuffixText?: { readonly prefixText?: string, readonly suffixText?: string }, - ): protocol.RenameTextSpan { - return { ...protocolTextSpanFromSubstring(str, substring, options), ...prefixSuffixText }; + export interface DocumentSpanFromSubstring { + file: File; + text: string; + options?: SpanFromSubstringOptions; + } + export function protocolFileSpanFromSubstring({ file, text, options }: DocumentSpanFromSubstring): protocol.FileSpan { + return { file: file.path, ...protocolTextSpanFromSubstring(file.content, text, options) }; + } + + interface DeclarationFileSpanFromSubString { + file: File; + text: string; + options?: SpanFromSubstringOptions; + declarationText?: string; + declarationOptions?: SpanFromSubstringOptions; + } + export function protocolDeclarationFileSpanFromSubstring({ declarationText, declarationOptions, ...rest }: DeclarationFileSpanFromSubString): protocol.DeclarationFileSpan { + const result = protocolFileSpanFromSubstring(rest); + if (!declarationText) return result; + const declarationSpan = protocolFileSpanFromSubstring({ file: rest.file, text: declarationText, options: declarationOptions }); + return { + ...result, + declarationStart: declarationSpan.start, + declarationEnd: declarationSpan.end + }; + } + + export interface ProtocolDeclarationTextSpanFromString { + fileText: string; + text: string; + options?: SpanFromSubstringOptions; + declarationText?: string; + declarationOptions?: SpanFromSubstringOptions; + } + export function protocolDeclarationTextSpanFromSubstring({ fileText, text, options, declarationText, declarationOptions }: ProtocolDeclarationTextSpanFromString): protocol.DeclarationTextSpan { + const span = textSpanFromSubstring(fileText, text, options); + const toLocation = protocolToLocation(fileText); + const result: protocol.DeclarationTextSpan = { + start: toLocation(span.start), + end: toLocation(textSpanEnd(span)) + }; + if (declarationText) { + const span = textSpanFromSubstring(fileText, declarationText, declarationOptions); + result.declarationStart = toLocation(span.start); + result.declarationEnd = toLocation(textSpanEnd(span)); + } + return result; + } + + export interface ProtocolRenameSpanFromSubstring extends ProtocolDeclarationTextSpanFromString { + prefixSuffixText?: { + readonly prefixText?: string; + readonly suffixText?: string; + }; + } + export function protocolRenameSpanFromSubstring({ prefixSuffixText, ...rest }: ProtocolRenameSpanFromSubstring): protocol.RenameTextSpan { + return { + ...protocolDeclarationTextSpanFromSubstring(rest), + ...prefixSuffixText + }; } export function textSpanFromSubstring(str: string, substring: string, options?: SpanFromSubstringOptions): TextSpan { diff --git a/src/testRunner/unittests/tsserver/projectReferences.ts b/src/testRunner/unittests/tsserver/projectReferences.ts index e39c510216d..af6e9d7281e 100644 --- a/src/testRunner/unittests/tsserver/projectReferences.ts +++ b/src/testRunner/unittests/tsserver/projectReferences.ts @@ -69,21 +69,24 @@ namespace ts.projectSystem { openFilesForSession([containerCompositeExec[1]], session); const service = session.getProjectService(); checkNumberOfProjects(service, { configuredProjects: 1 }); - const locationOfMyConst = protocolLocationFromSubstring(containerCompositeExec[1].content, "myConst"); + const { file: myConstFile, start: myConstStart, end: myConstEnd } = protocolFileSpanFromSubstring({ + file: containerCompositeExec[1], + text: "myConst", + }); const response = session.executeCommandSeq({ command: protocol.CommandTypes.Rename, - arguments: { - file: containerCompositeExec[1].path, - ...locationOfMyConst - } + arguments: { file: myConstFile, ...myConstStart } }).response as protocol.RenameResponseBody; - - const myConstLen = "myConst".length; - const locationOfMyConstInLib = protocolLocationFromSubstring(containerLib[1].content, "myConst"); + const locationOfMyConstInLib = protocolDeclarationFileSpanFromSubstring({ + file: containerLib[1], + text: "myConst", + declarationText: "export const myConst = 30;" + }); + const { file: _, ...renameTextOfMyConstInLib } = locationOfMyConstInLib; assert.deepEqual(response.locs, [ - { file: containerCompositeExec[1].path, locs: [{ start: locationOfMyConst, end: { line: locationOfMyConst.line, offset: locationOfMyConst.offset + myConstLen } }] }, - { file: containerLib[1].path, locs: [{ start: locationOfMyConstInLib, end: { line: locationOfMyConstInLib.line, offset: locationOfMyConstInLib.offset + myConstLen } }] } + { file: myConstFile, locs: [{ start: myConstStart, end: myConstEnd }] }, + { file: locationOfMyConstInLib.file, locs: [renameTextOfMyConstInLib] } ]); }); }); @@ -169,7 +172,7 @@ fn5(); } function gotoDefintinionFromMainTs(fn: number): SessionAction { const textSpan = usageSpan(fn); - const definition: protocol.FileSpan = { file: dependencyTs.path, ...definitionSpan(fn) }; + const definition: protocol.FileSpan = { file: dependencyTs.path, ...declarationSpan(fn) }; const declareSpaceLength = "declare ".length; return { reqName: "goToDef", @@ -184,7 +187,13 @@ fn5(); }, expectedResponseNoMap: { // To the dts - definitions: [{ file: dtsPath, start: { line: fn, offset: definition.start.offset + declareSpaceLength }, end: { line: fn, offset: definition.end.offset + declareSpaceLength } }], + definitions: [{ + file: dtsPath, + start: { line: fn, offset: definition.start.offset + declareSpaceLength }, + end: { line: fn, offset: definition.end.offset + declareSpaceLength }, + declarationStart: { line: fn, offset: 1 }, + declarationEnd: { line: fn, offset: 37 } + }], textSpan }, expectedResponseNoDts: { @@ -195,18 +204,29 @@ fn5(); }; } - function definitionSpan(fn: number): protocol.TextSpan { - return { start: { line: fn, offset: 17 }, end: { line: fn, offset: 20 } }; + function declarationSpan(fn: number): protocol.DeclarationTextSpan { + return { + start: { line: fn, offset: 17 }, + end: { line: fn, offset: 20 }, + declarationStart: { line: fn, offset: 1 }, + declarationEnd: { line: fn, offset: 26 } + }; } - function importSpan(fn: number): protocol.TextSpan { - return { start: { line: fn + 1, offset: 5 }, end: { line: fn + 1, offset: 8 } }; + function importSpan(fn: number): protocol.DeclarationTextSpan { + return { + start: { line: fn + 1, offset: 5 }, + end: { line: fn + 1, offset: 8 }, + declarationStart: { line: 1, offset: 1 }, + declarationEnd: { line: 7, offset: 27 } + }; } function usageSpan(fn: number): protocol.TextSpan { return { start: { line: fn + 8, offset: 1 }, end: { line: fn + 8, offset: 4 } }; } function renameFromDependencyTs(fn: number): SessionAction { - const triggerSpan = definitionSpan(fn); + const defSpan = declarationSpan(fn); + const { declarationStart: _, declarationEnd: _1, ...triggerSpan } = defSpan; return { reqName: "rename", request: { @@ -224,7 +244,7 @@ fn5(); triggerSpan }, locs: [ - { file: dependencyTs.path, locs: [triggerSpan] } + { file: dependencyTs.path, locs: [defSpan] } ] } }; diff --git a/src/testRunner/unittests/tsserver/rename.ts b/src/testRunner/unittests/tsserver/rename.ts index f565524aded..67464499a5b 100644 --- a/src/testRunner/unittests/tsserver/rename.ts +++ b/src/testRunner/unittests/tsserver/rename.ts @@ -14,7 +14,15 @@ namespace ts.projectSystem { canRename: false, localizedErrorMessage: "You cannot rename this element." }, - locs: [{ file: bTs.path, locs: [protocolRenameSpanFromSubstring(bTs.content, "./a")] }], + locs: [{ + file: bTs.path, + locs: [ + protocolRenameSpanFromSubstring({ + fileText: bTs.content, + text: "./a" + }) + ] + }], }); // rename succeeds with allowRenameOfImportPath enabled in host @@ -30,7 +38,15 @@ namespace ts.projectSystem { kindModifiers: "", triggerSpan: protocolTextSpanFromSubstring(bTs.content, "a", { index: 1 }), }, - locs: [{ file: bTs.path, locs: [protocolRenameSpanFromSubstring(bTs.content, "./a")] }], + locs: [{ + file: bTs.path, + locs: [ + protocolRenameSpanFromSubstring({ + fileText: bTs.content, + text: "./a" + }) + ] + }], }); // rename succeeds with allowRenameOfImportPath enabled in file @@ -47,7 +63,15 @@ namespace ts.projectSystem { kindModifiers: "", triggerSpan: protocolTextSpanFromSubstring(bTs.content, "a", { index: 1 }), }, - locs: [{ file: bTs.path, locs: [protocolRenameSpanFromSubstring(bTs.content, "./a")] }], + locs: [{ + file: bTs.path, + locs: [ + protocolRenameSpanFromSubstring({ + fileText: bTs.content, + text: "./a" + }) + ] + }], }); }); @@ -73,8 +97,16 @@ namespace ts.projectSystem { { file: aTs.path, locs: [ - protocolRenameSpanFromSubstring(aTs.content, "x"), - protocolRenameSpanFromSubstring(aTs.content, "x", { index: 1 }), + protocolRenameSpanFromSubstring({ + fileText: aTs.content, + text: "x", + declarationText: "const x = 0;" + }), + protocolRenameSpanFromSubstring({ + fileText: aTs.content, + text: "x", + options: { index: 1 } + }), ], }, ], @@ -97,8 +129,17 @@ namespace ts.projectSystem { { file: aTs.path, locs: [ - protocolRenameSpanFromSubstring(aTs.content, "x"), - protocolRenameSpanFromSubstring(aTs.content, "x", { index: 1 }, { prefixText: "x: " }), + protocolRenameSpanFromSubstring({ + fileText: aTs.content, + text: "x", + declarationText: "const x = 0;" + }), + protocolRenameSpanFromSubstring({ + fileText: aTs.content, + text: "x", + options: { index: 1 }, + prefixSuffixText: { prefixText: "x: " } + }), ], }, ], @@ -122,8 +163,17 @@ namespace ts.projectSystem { { file: aTs.path, locs: [ - protocolRenameSpanFromSubstring(aTs.content, "x"), - protocolRenameSpanFromSubstring(aTs.content, "x", { index: 1 }, { prefixText: "x: " }), + protocolRenameSpanFromSubstring({ + fileText: aTs.content, + text: "x", + declarationText: "const x = 0;" + }), + protocolRenameSpanFromSubstring({ + fileText: aTs.content, + text: "x", + options: { index: 1 }, + prefixSuffixText: { prefixText: "x: " } + }), ], }, ], @@ -154,8 +204,18 @@ namespace ts.projectSystem { { file: aTs.path, locs: [ - protocolRenameSpanFromSubstring(aTs.content, "x"), - protocolRenameSpanFromSubstring(aTs.content, "x", { index: 2 }, { suffixText: " as x" }), + protocolRenameSpanFromSubstring({ + fileText: aTs.content, + text: "x", + declarationText: "const x = 1;" + }), + protocolRenameSpanFromSubstring({ + fileText: aTs.content, + text: "x", + options: { index: 2 }, + declarationText: "export { x };", + prefixSuffixText: { suffixText: " as x" } + }), ], }, ], @@ -177,15 +237,32 @@ namespace ts.projectSystem { { file: bTs.path, locs: [ - protocolRenameSpanFromSubstring(bTs.content, "x"), - protocolRenameSpanFromSubstring(bTs.content, "x", { index: 1 }) + protocolRenameSpanFromSubstring({ + fileText: bTs.content, + text: "x", + declarationText: `import { x } from "./a";` + }), + protocolRenameSpanFromSubstring({ + fileText: bTs.content, + text: "x", + options: { index: 1 }, + }) ] }, { file: aTs.path, locs: [ - protocolRenameSpanFromSubstring(aTs.content, "x"), - protocolRenameSpanFromSubstring(aTs.content, "x", { index: 2 }), + protocolRenameSpanFromSubstring({ + fileText: aTs.content, + text: "x", + declarationText: "const x = 1;" + }), + protocolRenameSpanFromSubstring({ + fileText: aTs.content, + text: "x", + options: { index: 2 }, + declarationText: "export { x };", + }), ], }, ], diff --git a/src/testRunner/unittests/tsserver/symLinks.ts b/src/testRunner/unittests/tsserver/symLinks.ts index e331c94ca1a..1297b8ee0ac 100644 --- a/src/testRunner/unittests/tsserver/symLinks.ts +++ b/src/testRunner/unittests/tsserver/symLinks.ts @@ -58,10 +58,22 @@ namespace ts.projectSystem { assert.equal(aFile.content, bFile.content); const abLocs: protocol.RenameTextSpan[] = [ - protocolRenameSpanFromSubstring(aFile.content, "C"), - protocolRenameSpanFromSubstring(aFile.content, "C", { index: 1 }), + protocolRenameSpanFromSubstring({ + fileText: aFile.content, + text: "C", + declarationText: `import {C} from "./c/fc";` + }), + protocolRenameSpanFromSubstring({ + fileText: aFile.content, + text: "C", + options: { index: 1 } + }), ]; - const span = protocolRenameSpanFromSubstring(cFile.content, "C"); + const span = protocolRenameSpanFromSubstring({ + fileText: cFile.content, + text: "C", + declarationText: "export const C = 8" + }); const cLocs: protocol.RenameTextSpan[] = [span]; assert.deepEqual(response, { info: { diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 4b06bc9e839..d2db2d24b0d 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -5070,6 +5070,12 @@ declare namespace ts { */ originalTextSpan?: TextSpan; originalFileName?: string; + /** + * If DocumentSpan.textSpan is the span for name of the declaration, + * then this is the span for relevant declaration + */ + declarationSpan?: TextSpan; + originalDeclarationSpan?: TextSpan; } interface RenameLocation extends DocumentSpan { readonly prefixText?: string; @@ -5098,6 +5104,7 @@ declare namespace ts { fileName?: string; isInString?: true; textSpan: TextSpan; + declarationSpan?: TextSpan; kind: HighlightSpanKind; } interface NavigateToItem { @@ -6391,15 +6398,21 @@ declare namespace ts.server.protocol { */ file: string; } + interface DeclarationTextSpan extends TextSpan { + declarationStart?: Location; + declarationEnd?: Location; + } + interface DeclarationFileSpan extends FileSpan, DeclarationTextSpan { + } interface DefinitionInfoAndBoundSpan { - definitions: ReadonlyArray; + definitions: ReadonlyArray; textSpan: TextSpan; } /** * Definition response message. Gives text range for definition. */ interface DefinitionResponse extends Response { - body?: FileSpan[]; + body?: DeclarationFileSpan[]; } interface DefinitionInfoAndBoundSpanReponse extends Response { body?: DefinitionInfoAndBoundSpan; @@ -6408,13 +6421,13 @@ declare namespace ts.server.protocol { * Definition response message. Gives text range for definition. */ interface TypeDefinitionResponse extends Response { - body?: FileSpan[]; + body?: DeclarationFileSpan[]; } /** * Implementation response message. Gives text range for implementations. */ interface ImplementationResponse extends Response { - body?: FileSpan[]; + body?: DeclarationFileSpan[]; } /** * Request to get brace completion for a location in the file. @@ -6451,7 +6464,7 @@ declare namespace ts.server.protocol { command: CommandTypes.Occurrences; } /** @deprecated */ - interface OccurrencesResponseItem extends FileSpan { + interface OccurrencesResponseItem extends DeclarationFileSpan { /** * True if the occurrence is a write location, false otherwise. */ @@ -6477,7 +6490,7 @@ declare namespace ts.server.protocol { /** * Span augmented with extra information that denotes the kind of the highlighting to be used for span. */ - interface HighlightSpan extends TextSpan { + interface HighlightSpan extends DeclarationTextSpan { kind: HighlightSpanKind; } /** @@ -6507,7 +6520,7 @@ declare namespace ts.server.protocol { interface ReferencesRequest extends FileLocationRequest { command: CommandTypes.References; } - interface ReferencesResponseItem extends FileSpan { + interface ReferencesResponseItem extends DeclarationFileSpan { /** Text of line containing the reference. Including this * with the response avoids latency of editor loading files * to show text of reference line (the server already has @@ -6622,7 +6635,7 @@ declare namespace ts.server.protocol { /** The text spans in this group */ locs: RenameTextSpan[]; } - interface RenameTextSpan extends TextSpan { + interface RenameTextSpan extends DeclarationTextSpan { readonly prefixText?: string; readonly suffixText?: string; } @@ -8979,6 +8992,7 @@ declare namespace ts.server { private mapDefinitionInfo; private static mapToOriginalLocation; private toFileSpan; + private toDeclarationFileSpan; private getTypeDefinition; private mapImplementationLocations; private getImplementation; @@ -9036,7 +9050,6 @@ declare namespace ts.server { private mapLocationNavigationBarItems; private getNavigationBarItems; private toLocationNavigationTree; - private toLocationTextSpan; private getNavigationTree; private getNavigateToItems; private getFullNavigateToItems; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index f70916a882b..9b560c0ef09 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -5070,6 +5070,12 @@ declare namespace ts { */ originalTextSpan?: TextSpan; originalFileName?: string; + /** + * If DocumentSpan.textSpan is the span for name of the declaration, + * then this is the span for relevant declaration + */ + declarationSpan?: TextSpan; + originalDeclarationSpan?: TextSpan; } interface RenameLocation extends DocumentSpan { readonly prefixText?: string; @@ -5098,6 +5104,7 @@ declare namespace ts { fileName?: string; isInString?: true; textSpan: TextSpan; + declarationSpan?: TextSpan; kind: HighlightSpanKind; } interface NavigateToItem { From 1d830ffe7a6fa15674359d8d09a65848cc8ce6a7 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 24 May 2019 16:29:27 -0700 Subject: [PATCH 02/44] Start fixing fourslash tests --- src/harness/fourslash.ts | 12 ++++++++---- tests/cases/fourslash/untypedModuleImport.ts | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 8a0a2bffbd4..c48da8bee56 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -955,14 +955,18 @@ namespace FourSlash { const fullExpected = ts.map(parts, ({ definition, ranges }) => ({ definition: typeof definition === "string" ? definition : { ...definition, range: ts.createTextSpanFromRange(definition.range) }, references: ranges.map(r => { - const { isWriteAccess = false, isDefinition = false, isInString } = (r.marker && r.marker.data || {}) as { isWriteAccess?: boolean, isDefinition?: boolean, isInString?: true }; - return { + const { isWriteAccess = false, isDefinition = false, isInString, declarationRange } = (r.marker && r.marker.data || {}) as { isWriteAccess?: boolean, isDefinition?: boolean, isInString?: true, declarationRange?: number }; + const result: ts.ReferenceEntry = { fileName: r.fileName, textSpan: ts.createTextSpanFromRange(r), isWriteAccess, isDefinition, ...(isInString ? { isInString: true } : undefined), }; + if (declarationRange !== undefined) { + result.declarationSpan = ts.createTextSpanFromRange(this.getRanges()[declarationRange]); + } + return result; }), })); @@ -1011,7 +1015,7 @@ Actual: ${stringify(fullActual)}`); }; if ((actual === undefined) !== (expected === undefined)) { - fail(`Expected ${expected}, got ${actual}`); + fail(`Expected ${stringify(expected)}, got ${stringify(actual)}`); } for (const key in actual) { @@ -1021,7 +1025,7 @@ Actual: ${stringify(fullActual)}`); recur(ak, ek, path ? path + "." + key : key); } else if (ak !== ek) { - fail(`Expected '${key}' to be '${ek}', got '${ak}'`); + fail(`Expected '${key}' to be '${stringify(ek)}', got '${stringify(ak)}'`); } } } diff --git a/tests/cases/fourslash/untypedModuleImport.ts b/tests/cases/fourslash/untypedModuleImport.ts index 5501cec4792..e64d37d0e6c 100644 --- a/tests/cases/fourslash/untypedModuleImport.ts +++ b/tests/cases/fourslash/untypedModuleImport.ts @@ -4,7 +4,7 @@ ////{} // @Filename: a.ts -////import /*foo*/[|{| "isWriteAccess": true, "isDefinition": true |}foo|] from /*fooModule*/"[|{| "isInString": true |}foo|]"; +////[|import /*foo*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRange": 0 |}foo|] from /*fooModule*/"[|{| "isInString": true |}foo|]";|] ////[|foo|](); goTo.file("a.ts"); @@ -13,7 +13,7 @@ verify.numberOfErrorsInCurrentFile(0); goTo.marker("fooModule"); verify.goToDefinitionIs([]); verify.quickInfoIs(""); -const [r0, r1, r2] = test.ranges(); +const [r00, r0, r1, r2] = test.ranges(); verify.singleReferenceGroup('"foo"', [r1]); goTo.marker("foo"); From 6a961b5bc5b4938ab46a9c3df5546574af775c70 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 28 May 2019 15:38:21 -0700 Subject: [PATCH 03/44] More tests --- src/harness/fourslash.ts | 9 ++++++-- src/services/findAllReferences.ts | 9 +++++++- tests/cases/fourslash/tsxRename1.ts | 8 +++---- tests/cases/fourslash/tsxRename2.ts | 7 +++--- tests/cases/fourslash/tsxRename3.ts | 7 +++--- tests/cases/fourslash/tsxRename4.ts | 8 +++---- tests/cases/fourslash/tsxRename5.ts | 5 ++-- tests/cases/fourslash/tsxRename6.ts | 6 +++-- tests/cases/fourslash/tsxRename7.ts | 9 ++++---- tests/cases/fourslash/tsxRename9.ts | 36 +++++++++++++++++++++-------- 10 files changed, 70 insertions(+), 34 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index c48da8bee56..edbb485a30b 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1191,9 +1191,14 @@ Actual: ${stringify(fullActual)}`); const sort = (locations: ReadonlyArray | undefined) => locations && ts.sort(locations, (r1, r2) => ts.compareStringsCaseSensitive(r1.fileName, r2.fileName) || r1.textSpan.start - r2.textSpan.start); - assert.deepEqual(sort(references), sort(ranges.map((rangeOrOptions): ts.RenameLocation => { + assert.deepEqual(sort(references), sort(ranges.map(rangeOrOptions => { const { range, ...prefixSuffixText } = "range" in rangeOrOptions ? rangeOrOptions : { range: rangeOrOptions }; - return { fileName: range.fileName, textSpan: ts.createTextSpanFromRange(range), ...prefixSuffixText }; + const result: ts.RenameLocation = { fileName: range.fileName, textSpan: ts.createTextSpanFromRange(range), ...prefixSuffixText }; + const { declarationRange } = (range.marker && range.marker.data || {}) as { declarationRange?: number; }; + if (declarationRange !== undefined) { + result.declarationSpan = ts.createTextSpanFromRange(this.getRanges()[declarationRange]); + } + return result; }))); } } diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index b29061076ff..72ac25c2e21 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -27,6 +27,8 @@ namespace ts.FindAllReferences { readonly textSpan: TextSpan; } export function nodeEntry(node: Node, kind: NodeEntryKind = EntryKind.Node): NodeEntry { + // TODO(shkamat):: + // JSXOpeningElement or JSXElement for tagName ? const declaration = getDeclarationForDeclarationSpan( isDeclaration(node) ? node : @@ -60,8 +62,13 @@ namespace ts.FindAllReferences { case SyntaxKind.ImportClause: return node.parent; + case SyntaxKind.JsxAttribute: + return (node as JsxAttribute).initializer === undefined ? + undefined : + node; + // Not really interesting definition - // Should we show whole object literal instead? + // TODO(shkamat):: Should we show whole object literal instead? case SyntaxKind.ShorthandPropertyAssignment: return undefined; diff --git a/tests/cases/fourslash/tsxRename1.ts b/tests/cases/fourslash/tsxRename1.ts index 4323e99df59..bdf2cf6d2ef 100644 --- a/tests/cases/fourslash/tsxRename1.ts +++ b/tests/cases/fourslash/tsxRename1.ts @@ -4,13 +4,13 @@ //// declare module JSX { //// interface Element { } //// interface IntrinsicElements { -//// [|div|]: { +//// [|[|{| "declarationRange": 0 |}div|]: { //// name?: string; //// isOpen?: boolean; -//// }; +//// };|] //// span: { n: string; }; //// } //// } //// var x = <[|div|] />; - -verify.rangesAreRenameLocations(); +const rangesByText = test.rangesByText(); +verify.rangesAreRenameLocations(rangesByText.get("div")); diff --git a/tests/cases/fourslash/tsxRename2.ts b/tests/cases/fourslash/tsxRename2.ts index e5e0688150c..7a578b3383d 100644 --- a/tests/cases/fourslash/tsxRename2.ts +++ b/tests/cases/fourslash/tsxRename2.ts @@ -5,12 +5,13 @@ //// interface Element { } //// interface IntrinsicElements { //// div: { -//// [|name|]?: string; +//// [|[|{| "declarationRange": 0 |}name|]?: string;|] //// isOpen?: boolean; //// }; //// span: { n: string; }; //// } //// } -//// var x =
; +//// var x =
; -verify.rangesAreRenameLocations(); +const rangesByText = test.rangesByText(); +verify.rangesAreRenameLocations(rangesByText.get("name")); diff --git a/tests/cases/fourslash/tsxRename3.ts b/tests/cases/fourslash/tsxRename3.ts index b997ea2fdca..5a8d0d7a19d 100644 --- a/tests/cases/fourslash/tsxRename3.ts +++ b/tests/cases/fourslash/tsxRename3.ts @@ -9,11 +9,12 @@ //// } //// class MyClass { //// props: { -//// [|name|]?: string; +//// [|[|{| "declarationRange": 0 |}name|]?: string;|] //// size?: number; //// } //// //// -//// var x = ; +//// var x = ; -verify.rangesAreRenameLocations(); +const rangesByText = test.rangesByText(); +verify.rangesAreRenameLocations(rangesByText.get("name")); diff --git a/tests/cases/fourslash/tsxRename4.ts b/tests/cases/fourslash/tsxRename4.ts index e46c2b7ebcb..1a932768b17 100644 --- a/tests/cases/fourslash/tsxRename4.ts +++ b/tests/cases/fourslash/tsxRename4.ts @@ -9,7 +9,7 @@ //// div: {}; //// } ////} -////class [|MyClass|] {} +////[|class [|{| "declarationRange": 0 |}MyClass|] {}|] //// ////<[|MyClass|]>; ////<[|MyClass|]/>; @@ -18,6 +18,6 @@ verify.noErrors(); -const [r0, r1, r2, r3, d0, d1] = test.ranges(); -verify.rangesAreRenameLocations([r0, r1, r2, r3]); -verify.rangesAreRenameLocations([d0, d1]); +const rangesByText = test.rangesByText(); +verify.rangesAreRenameLocations(rangesByText.get("MyClass")); +verify.rangesAreRenameLocations(rangesByText.get("div")); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxRename5.ts b/tests/cases/fourslash/tsxRename5.ts index a4c70b4b1c3..5ccfcd61953 100644 --- a/tests/cases/fourslash/tsxRename5.ts +++ b/tests/cases/fourslash/tsxRename5.ts @@ -13,7 +13,8 @@ //// size?: number; //// } //// -//// var [|nn|]: string; +//// [|var [|{| "declarationRange": 0 |}nn|]: string;|] //// var x = ; -verify.rangesAreRenameLocations(); +const rangesByText = test.rangesByText(); +verify.rangesAreRenameLocations(rangesByText.get("nn")); diff --git a/tests/cases/fourslash/tsxRename6.ts b/tests/cases/fourslash/tsxRename6.ts index 6f999c12760..f8c2ab41ebf 100644 --- a/tests/cases/fourslash/tsxRename6.ts +++ b/tests/cases/fourslash/tsxRename6.ts @@ -15,11 +15,13 @@ //// propString: string //// optional?: boolean //// } -//// declare function [|Opt|](attributes: OptionPropBag): JSX.Element; +//// [|declare function [|{| "declarationRange": 0 |}Opt|](attributes: OptionPropBag): JSX.Element;|] //// let opt = <[|Opt|] />; //// let opt1 = <[|Opt|] propx={100} propString />; //// let opt2 = <[|Opt|] propx={100} optional/>; //// let opt3 = <[|Opt|] wrong />; //// let opt4 = <[|Opt|] propx={100} propString="hi" />; -verify.rangesAreRenameLocations(); +//verify.rangesAreRenameLocations(); +const rangesByText = test.rangesByText(); +verify.rangesAreRenameLocations(rangesByText.get("Opt")); diff --git a/tests/cases/fourslash/tsxRename7.ts b/tests/cases/fourslash/tsxRename7.ts index 5533db1b4db..8565487c240 100644 --- a/tests/cases/fourslash/tsxRename7.ts +++ b/tests/cases/fourslash/tsxRename7.ts @@ -11,14 +11,15 @@ //// interface ElementAttributesProperty { props; } //// } //// interface OptionPropBag { -//// [|propx|]: number +//// [|[|{| "declarationRange": 0 |}propx|]: number|] //// propString: string //// optional?: boolean //// } //// declare function Opt(attributes: OptionPropBag): JSX.Element; //// let opt = ; -//// let opt1 = ; -//// let opt2 = ; +//// let opt1 = ; +//// let opt2 = ; //// let opt3 = ; -verify.rangesAreRenameLocations(); +const rangesByText = test.rangesByText(); +verify.rangesAreRenameLocations(rangesByText.get("propx")); diff --git a/tests/cases/fourslash/tsxRename9.ts b/tests/cases/fourslash/tsxRename9.ts index b39b009634d..763b9af68a2 100644 --- a/tests/cases/fourslash/tsxRename9.ts +++ b/tests/cases/fourslash/tsxRename9.ts @@ -15,19 +15,37 @@ //// className?: string; //// } //// interface ButtonProps extends ClickableProps { -//// [|onClick|](event?: React.MouseEvent): void; +//// [|[|{| "declarationRange": 0 |}onClick|](event?: React.MouseEvent): void;|] //// } //// interface LinkProps extends ClickableProps { -//// [|goTo|]: string; +//// [|[|{| "declarationRange": 2 |}goTo|]: string;|] //// } -//// declare function [|MainButton|](buttonProps: ButtonProps): JSX.Element; -//// declare function [|MainButton|](linkProps: LinkProps): JSX.Element; -//// declare function [|MainButton|](props: ButtonProps | LinkProps): JSX.Element; +//// [|declare function [|{| "declarationRange": 4 |}MainButton|](buttonProps: ButtonProps): JSX.Element;|] +//// [|declare function [|{| "declarationRange": 6 |}MainButton|](linkProps: LinkProps): JSX.Element;|] +//// [|declare function [|{| "declarationRange": 8 |}MainButton|](props: ButtonProps | LinkProps): JSX.Element;|] //// let opt = <[|MainButton|] />; //// let opt = <[|MainButton|] children="chidlren" />; -//// let opt = <[|MainButton|] [|onClick|]={()=>{}} />; -//// let opt = <[|MainButton|] [|onClick|]={()=>{}} [|ignore-prop|] />; -//// let opt = <[|MainButton|] [|goTo|]="goTo" />; +//// let opt = <[|MainButton|] [|[|{| "declarationRange": 13 |}onClick|]={()=>{}}|] />; +//// let opt = <[|MainButton|] [|[|{| "declarationRange": 16 |}onClick|]={()=>{}}|] [|ignore-prop|] />; +//// let opt = <[|MainButton|] [|[|{| "declarationRange": 20 |}goTo|]="goTo"|] />; //// let opt = <[|MainButton|] [|wrong|] />; -verify.rangesWithSameTextAreRenameLocations(); +const [ + onClickDef_0, onClick_1, + goToDef_2, goTo_3, + mainButtonDef_4, mainButton_5, + mainButtonDef_6, mainButton_7, + mainButtonDef_8, mainButton_9, + mainButton_10, + mainButton_11, + mainButton_12, onClickDef_13, onClick_14, + mainButton_15, onClickDef_16, onClick_17, ignoreProp_18, + mainButton_19, goToDef_20, goTo_21, + mainButton_22, wrong_23 +] = test.ranges(); +const rangesByText = test.rangesByText(); +verify.rangesAreRenameLocations(rangesByText.get("onClick")); +verify.rangesAreRenameLocations(rangesByText.get("goTo")); +verify.rangesAreRenameLocations(rangesByText.get("MainButton")); +verify.rangesAreRenameLocations(rangesByText.get("ignore-prop")); +verify.rangesAreRenameLocations(rangesByText.get("wrong")); \ No newline at end of file From 8948fe415f05e8fcfeacbbfec3130121c9b62028 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 30 May 2019 12:45:11 -0700 Subject: [PATCH 04/44] Rename declarationRange to declarationRangeIndex --- src/harness/fourslash.ts | 12 ++++++------ tests/cases/fourslash/tsxRename1.ts | 2 +- tests/cases/fourslash/tsxRename2.ts | 4 ++-- tests/cases/fourslash/tsxRename3.ts | 4 ++-- tests/cases/fourslash/tsxRename4.ts | 2 +- tests/cases/fourslash/tsxRename5.ts | 2 +- tests/cases/fourslash/tsxRename6.ts | 2 +- tests/cases/fourslash/tsxRename7.ts | 6 +++--- tests/cases/fourslash/tsxRename9.ts | 16 ++++++++-------- tests/cases/fourslash/untypedModuleImport.ts | 2 +- 10 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index edbb485a30b..51e6c2dbe29 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -955,7 +955,7 @@ namespace FourSlash { const fullExpected = ts.map(parts, ({ definition, ranges }) => ({ definition: typeof definition === "string" ? definition : { ...definition, range: ts.createTextSpanFromRange(definition.range) }, references: ranges.map(r => { - const { isWriteAccess = false, isDefinition = false, isInString, declarationRange } = (r.marker && r.marker.data || {}) as { isWriteAccess?: boolean, isDefinition?: boolean, isInString?: true, declarationRange?: number }; + const { isWriteAccess = false, isDefinition = false, isInString, declarationRangeIndex } = (r.marker && r.marker.data || {}) as { isWriteAccess?: boolean, isDefinition?: boolean, isInString?: true, declarationRangeIndex?: number }; const result: ts.ReferenceEntry = { fileName: r.fileName, textSpan: ts.createTextSpanFromRange(r), @@ -963,8 +963,8 @@ namespace FourSlash { isDefinition, ...(isInString ? { isInString: true } : undefined), }; - if (declarationRange !== undefined) { - result.declarationSpan = ts.createTextSpanFromRange(this.getRanges()[declarationRange]); + if (declarationRangeIndex !== undefined) { + result.declarationSpan = ts.createTextSpanFromRange(this.getRanges()[declarationRangeIndex]); } return result; }), @@ -1194,9 +1194,9 @@ Actual: ${stringify(fullActual)}`); assert.deepEqual(sort(references), sort(ranges.map(rangeOrOptions => { const { range, ...prefixSuffixText } = "range" in rangeOrOptions ? rangeOrOptions : { range: rangeOrOptions }; const result: ts.RenameLocation = { fileName: range.fileName, textSpan: ts.createTextSpanFromRange(range), ...prefixSuffixText }; - const { declarationRange } = (range.marker && range.marker.data || {}) as { declarationRange?: number; }; - if (declarationRange !== undefined) { - result.declarationSpan = ts.createTextSpanFromRange(this.getRanges()[declarationRange]); + const { declarationRangeIndex } = (range.marker && range.marker.data || {}) as { declarationRangeIndex?: number; }; + if (declarationRangeIndex !== undefined) { + result.declarationSpan = ts.createTextSpanFromRange(this.getRanges()[declarationRangeIndex]); } return result; }))); diff --git a/tests/cases/fourslash/tsxRename1.ts b/tests/cases/fourslash/tsxRename1.ts index bdf2cf6d2ef..25a4032032d 100644 --- a/tests/cases/fourslash/tsxRename1.ts +++ b/tests/cases/fourslash/tsxRename1.ts @@ -4,7 +4,7 @@ //// declare module JSX { //// interface Element { } //// interface IntrinsicElements { -//// [|[|{| "declarationRange": 0 |}div|]: { +//// [|[|{| "declarationRangeIndex": 0 |}div|]: { //// name?: string; //// isOpen?: boolean; //// };|] diff --git a/tests/cases/fourslash/tsxRename2.ts b/tests/cases/fourslash/tsxRename2.ts index 7a578b3383d..e79e7746d52 100644 --- a/tests/cases/fourslash/tsxRename2.ts +++ b/tests/cases/fourslash/tsxRename2.ts @@ -5,13 +5,13 @@ //// interface Element { } //// interface IntrinsicElements { //// div: { -//// [|[|{| "declarationRange": 0 |}name|]?: string;|] +//// [|[|{| "declarationRangeIndex": 0 |}name|]?: string;|] //// isOpen?: boolean; //// }; //// span: { n: string; }; //// } //// } -//// var x =
; +//// var x =
; const rangesByText = test.rangesByText(); verify.rangesAreRenameLocations(rangesByText.get("name")); diff --git a/tests/cases/fourslash/tsxRename3.ts b/tests/cases/fourslash/tsxRename3.ts index 5a8d0d7a19d..7970c314f45 100644 --- a/tests/cases/fourslash/tsxRename3.ts +++ b/tests/cases/fourslash/tsxRename3.ts @@ -9,12 +9,12 @@ //// } //// class MyClass { //// props: { -//// [|[|{| "declarationRange": 0 |}name|]?: string;|] +//// [|[|{| "declarationRangeIndex": 0 |}name|]?: string;|] //// size?: number; //// } //// //// -//// var x = ; +//// var x = ; const rangesByText = test.rangesByText(); verify.rangesAreRenameLocations(rangesByText.get("name")); diff --git a/tests/cases/fourslash/tsxRename4.ts b/tests/cases/fourslash/tsxRename4.ts index 1a932768b17..cfd9b379fb7 100644 --- a/tests/cases/fourslash/tsxRename4.ts +++ b/tests/cases/fourslash/tsxRename4.ts @@ -9,7 +9,7 @@ //// div: {}; //// } ////} -////[|class [|{| "declarationRange": 0 |}MyClass|] {}|] +////[|class [|{| "declarationRangeIndex": 0 |}MyClass|] {}|] //// ////<[|MyClass|]>; ////<[|MyClass|]/>; diff --git a/tests/cases/fourslash/tsxRename5.ts b/tests/cases/fourslash/tsxRename5.ts index 5ccfcd61953..d57da4b083a 100644 --- a/tests/cases/fourslash/tsxRename5.ts +++ b/tests/cases/fourslash/tsxRename5.ts @@ -13,7 +13,7 @@ //// size?: number; //// } //// -//// [|var [|{| "declarationRange": 0 |}nn|]: string;|] +//// [|var [|{| "declarationRangeIndex": 0 |}nn|]: string;|] //// var x = ; const rangesByText = test.rangesByText(); diff --git a/tests/cases/fourslash/tsxRename6.ts b/tests/cases/fourslash/tsxRename6.ts index f8c2ab41ebf..3b0068d16b9 100644 --- a/tests/cases/fourslash/tsxRename6.ts +++ b/tests/cases/fourslash/tsxRename6.ts @@ -15,7 +15,7 @@ //// propString: string //// optional?: boolean //// } -//// [|declare function [|{| "declarationRange": 0 |}Opt|](attributes: OptionPropBag): JSX.Element;|] +//// [|declare function [|{| "declarationRangeIndex": 0 |}Opt|](attributes: OptionPropBag): JSX.Element;|] //// let opt = <[|Opt|] />; //// let opt1 = <[|Opt|] propx={100} propString />; //// let opt2 = <[|Opt|] propx={100} optional/>; diff --git a/tests/cases/fourslash/tsxRename7.ts b/tests/cases/fourslash/tsxRename7.ts index 8565487c240..57b5da71cfc 100644 --- a/tests/cases/fourslash/tsxRename7.ts +++ b/tests/cases/fourslash/tsxRename7.ts @@ -11,14 +11,14 @@ //// interface ElementAttributesProperty { props; } //// } //// interface OptionPropBag { -//// [|[|{| "declarationRange": 0 |}propx|]: number|] +//// [|[|{| "declarationRangeIndex": 0 |}propx|]: number|] //// propString: string //// optional?: boolean //// } //// declare function Opt(attributes: OptionPropBag): JSX.Element; //// let opt = ; -//// let opt1 = ; -//// let opt2 = ; +//// let opt1 = ; +//// let opt2 = ; //// let opt3 = ; const rangesByText = test.rangesByText(); diff --git a/tests/cases/fourslash/tsxRename9.ts b/tests/cases/fourslash/tsxRename9.ts index 763b9af68a2..8de7a1c6d86 100644 --- a/tests/cases/fourslash/tsxRename9.ts +++ b/tests/cases/fourslash/tsxRename9.ts @@ -15,19 +15,19 @@ //// className?: string; //// } //// interface ButtonProps extends ClickableProps { -//// [|[|{| "declarationRange": 0 |}onClick|](event?: React.MouseEvent): void;|] +//// [|[|{| "declarationRangeIndex": 0 |}onClick|](event?: React.MouseEvent): void;|] //// } //// interface LinkProps extends ClickableProps { -//// [|[|{| "declarationRange": 2 |}goTo|]: string;|] +//// [|[|{| "declarationRangeIndex": 2 |}goTo|]: string;|] //// } -//// [|declare function [|{| "declarationRange": 4 |}MainButton|](buttonProps: ButtonProps): JSX.Element;|] -//// [|declare function [|{| "declarationRange": 6 |}MainButton|](linkProps: LinkProps): JSX.Element;|] -//// [|declare function [|{| "declarationRange": 8 |}MainButton|](props: ButtonProps | LinkProps): JSX.Element;|] +//// [|declare function [|{| "declarationRangeIndex": 4 |}MainButton|](buttonProps: ButtonProps): JSX.Element;|] +//// [|declare function [|{| "declarationRangeIndex": 6 |}MainButton|](linkProps: LinkProps): JSX.Element;|] +//// [|declare function [|{| "declarationRangeIndex": 8 |}MainButton|](props: ButtonProps | LinkProps): JSX.Element;|] //// let opt = <[|MainButton|] />; //// let opt = <[|MainButton|] children="chidlren" />; -//// let opt = <[|MainButton|] [|[|{| "declarationRange": 13 |}onClick|]={()=>{}}|] />; -//// let opt = <[|MainButton|] [|[|{| "declarationRange": 16 |}onClick|]={()=>{}}|] [|ignore-prop|] />; -//// let opt = <[|MainButton|] [|[|{| "declarationRange": 20 |}goTo|]="goTo"|] />; +//// let opt = <[|MainButton|] [|[|{| "declarationRangeIndex": 13 |}onClick|]={()=>{}}|] />; +//// let opt = <[|MainButton|] [|[|{| "declarationRangeIndex": 16 |}onClick|]={()=>{}}|] [|ignore-prop|] />; +//// let opt = <[|MainButton|] [|[|{| "declarationRangeIndex": 20 |}goTo|]="goTo"|] />; //// let opt = <[|MainButton|] [|wrong|] />; const [ diff --git a/tests/cases/fourslash/untypedModuleImport.ts b/tests/cases/fourslash/untypedModuleImport.ts index e64d37d0e6c..783e020e3fc 100644 --- a/tests/cases/fourslash/untypedModuleImport.ts +++ b/tests/cases/fourslash/untypedModuleImport.ts @@ -4,7 +4,7 @@ ////{} // @Filename: a.ts -////[|import /*foo*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRange": 0 |}foo|] from /*fooModule*/"[|{| "isInString": true |}foo|]";|] +////[|import /*foo*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|] from /*fooModule*/"[|{| "isInString": true |}foo|]";|] ////[|foo|](); goTo.file("a.ts"); From f37ae23f7efb5e357746750785cda7daebbbf6d5 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 30 May 2019 13:17:57 -0700 Subject: [PATCH 05/44] More test fixes --- tests/cases/fourslash/tsxFindAllReferences1.ts | 12 ++++++++---- tests/cases/fourslash/tsxFindAllReferences10.ts | 12 ++++++++---- tests/cases/fourslash/tsxFindAllReferences2.ts | 10 +++++++--- tests/cases/fourslash/tsxFindAllReferences3.ts | 10 +++++++--- tests/cases/fourslash/tsxFindAllReferences4.ts | 10 +++++++--- tests/cases/fourslash/tsxFindAllReferences5.ts | 8 ++++++-- tests/cases/fourslash/tsxFindAllReferences7.ts | 12 ++++++++---- tests/cases/fourslash/tsxFindAllReferences8.ts | 12 ++++++++---- tests/cases/fourslash/tsxFindAllReferences9.ts | 7 ++++--- .../tsxFindAllReferencesUnionElementType1.ts | 5 +++-- .../tsxFindAllReferencesUnionElementType2.ts | 5 +++-- 11 files changed, 69 insertions(+), 34 deletions(-) diff --git a/tests/cases/fourslash/tsxFindAllReferences1.ts b/tests/cases/fourslash/tsxFindAllReferences1.ts index 550dd05606c..1602bc7dae9 100644 --- a/tests/cases/fourslash/tsxFindAllReferences1.ts +++ b/tests/cases/fourslash/tsxFindAllReferences1.ts @@ -4,16 +4,20 @@ //// declare module JSX { //// interface Element { } //// interface IntrinsicElements { -//// [|{| "isWriteAccess": true, "isDefinition": true |}div|]: { +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}div|]: { //// name?: string; //// isOpen?: boolean; -//// }; +//// };|] //// span: { n: string; }; //// } //// } //// var x = <[|div|] />; -verify.singleReferenceGroup(`(property) JSX.IntrinsicElements.div: { +const rangesByText = test.rangesByText(); +verify.singleReferenceGroup( + `(property) JSX.IntrinsicElements.div: { name?: string; isOpen?: boolean; -}`); +}`, + rangesByText.get("div") +); diff --git a/tests/cases/fourslash/tsxFindAllReferences10.ts b/tests/cases/fourslash/tsxFindAllReferences10.ts index 58459c7df1f..29e57b97bd2 100644 --- a/tests/cases/fourslash/tsxFindAllReferences10.ts +++ b/tests/cases/fourslash/tsxFindAllReferences10.ts @@ -15,7 +15,7 @@ //// className?: string; //// } //// interface ButtonProps extends ClickableProps { -//// [|{| "isDefinition": true |}onClick|](event?: React.MouseEvent): void; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}onClick|](event?: React.MouseEvent): void;|] //// } //// interface LinkProps extends ClickableProps { //// goTo: string; @@ -25,9 +25,13 @@ //// declare function MainButton(props: ButtonProps | LinkProps): JSX.Element; //// let opt = ; //// let opt = ; -//// let opt = {}} />; -//// let opt = {}} ignore-prop />; +//// let opt = {}}|] />; +//// let opt = {}}|] ignore-prop />; //// let opt = ; //// let opt = ; -verify.singleReferenceGroup("(method) ButtonProps.onClick(event?: any): void"); +const rangesByText = test.rangesByText(); +verify.singleReferenceGroup( + "(method) ButtonProps.onClick(event?: any): void", + rangesByText.get("onClick") +); diff --git a/tests/cases/fourslash/tsxFindAllReferences2.ts b/tests/cases/fourslash/tsxFindAllReferences2.ts index e7fda5ab308..d83cb426992 100644 --- a/tests/cases/fourslash/tsxFindAllReferences2.ts +++ b/tests/cases/fourslash/tsxFindAllReferences2.ts @@ -5,12 +5,16 @@ //// interface Element { } //// interface IntrinsicElements { //// div: { -//// [|{| "isWriteAccess": true, "isDefinition": true |}name|]?: string; +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}name|]?: string;|] //// isOpen?: boolean; //// }; //// span: { n: string; }; //// } //// } -//// var x =
; +//// var x =
; -verify.singleReferenceGroup("(property) name?: string"); +const rangesByText = test.rangesByText(); +verify.singleReferenceGroup( + "(property) name ?: string", + rangesByText.get("name") +); diff --git a/tests/cases/fourslash/tsxFindAllReferences3.ts b/tests/cases/fourslash/tsxFindAllReferences3.ts index e2f9215466a..c519d5da99b 100644 --- a/tests/cases/fourslash/tsxFindAllReferences3.ts +++ b/tests/cases/fourslash/tsxFindAllReferences3.ts @@ -9,11 +9,15 @@ //// } //// class MyClass { //// props: { -//// [|{| "isDefinition": true |}name|]?: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}name|]?: string;|] //// size?: number; //// } //// //// -//// var x = ; +//// var x = ; -verify.singleReferenceGroup("(property) name?: string"); +const rangesByText = test.rangesByText(); +verify.singleReferenceGroup( + "(property) name?: string", + rangesByText.get("name") +); diff --git a/tests/cases/fourslash/tsxFindAllReferences4.ts b/tests/cases/fourslash/tsxFindAllReferences4.ts index c932ea57f36..5d7ce7419bb 100644 --- a/tests/cases/fourslash/tsxFindAllReferences4.ts +++ b/tests/cases/fourslash/tsxFindAllReferences4.ts @@ -7,13 +7,17 @@ //// } //// interface ElementAttributesProperty { props } //// } -//// class [|{| "isWriteAccess": true, "isDefinition": true |}MyClass|] { +//// [|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}MyClass|] { //// props: { //// name?: string; //// size?: number; -//// } +//// }|] //// //// //// var x = <[|MyClass|] name='hello'>; -verify.singleReferenceGroup("class MyClass"); +const rangesByText = test.rangesByText(); +verify.singleReferenceGroup( + "class MyClass", + rangesByText.get("MyClass") +); diff --git a/tests/cases/fourslash/tsxFindAllReferences5.ts b/tests/cases/fourslash/tsxFindAllReferences5.ts index 9358dd73dc5..265b1a015f3 100644 --- a/tests/cases/fourslash/tsxFindAllReferences5.ts +++ b/tests/cases/fourslash/tsxFindAllReferences5.ts @@ -15,11 +15,15 @@ //// propString: string //// optional?: boolean //// } -//// declare function [|{| "isWriteAccess": true, "isDefinition": true |}Opt|](attributes: OptionPropBag): JSX.Element; +//// [|declare function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Opt|](attributes: OptionPropBag): JSX.Element;|] //// let opt = <[|Opt|] />; //// let opt1 = <[|Opt|] propx={100} propString />; //// let opt2 = <[|Opt|] propx={100} optional/>; //// let opt3 = <[|Opt|] wrong />; //// let opt4 = <[|Opt|] propx={100} propString="hi" />; -verify.singleReferenceGroup("function Opt(attributes: OptionPropBag): JSX.Element"); +const rangesByText = test.rangesByText(); +verify.singleReferenceGroup( + "function Opt(attributes: OptionPropBag): JSX.Element", + rangesByText.get("Opt") +); diff --git a/tests/cases/fourslash/tsxFindAllReferences7.ts b/tests/cases/fourslash/tsxFindAllReferences7.ts index 471cf747258..22c19e1cc29 100644 --- a/tests/cases/fourslash/tsxFindAllReferences7.ts +++ b/tests/cases/fourslash/tsxFindAllReferences7.ts @@ -11,14 +11,18 @@ //// interface ElementAttributesProperty { props; } //// } //// interface OptionPropBag { -//// [|{| "isDefinition": true |}propx|]: number +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}propx|]: number|] //// propString: string //// optional?: boolean //// } //// declare function Opt(attributes: OptionPropBag): JSX.Element; //// let opt = ; -//// let opt1 = ; -//// let opt2 = ; +//// let opt1 = ; +//// let opt2 = ; //// let opt3 = ; -verify.singleReferenceGroup("(property) OptionPropBag.propx: number"); +const rangesByText = test.rangesByText(); +verify.singleReferenceGroup( + "(property) OptionPropBag.propx: number", + rangesByText.get("propx") +); diff --git a/tests/cases/fourslash/tsxFindAllReferences8.ts b/tests/cases/fourslash/tsxFindAllReferences8.ts index 0c216488892..b509a9565a0 100644 --- a/tests/cases/fourslash/tsxFindAllReferences8.ts +++ b/tests/cases/fourslash/tsxFindAllReferences8.ts @@ -20,9 +20,9 @@ //// interface LinkProps extends ClickableProps { //// goTo: string; //// } -//// declare function [|{| "isWriteAccess": true, "isDefinition": true |}MainButton|](buttonProps: ButtonProps): JSX.Element; -//// declare function [|{| "isWriteAccess": true, "isDefinition": true |}MainButton|](linkProps: LinkProps): JSX.Element; -//// declare function [|{| "isWriteAccess": true, "isDefinition": true |}MainButton|](props: ButtonProps | LinkProps): JSX.Element; +//// [|declare function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}MainButton|](buttonProps: ButtonProps): JSX.Element;|] +//// [|declare function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}MainButton|](linkProps: LinkProps): JSX.Element;|] +//// [|declare function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}MainButton|](props: ButtonProps | LinkProps): JSX.Element;|] //// let opt = <[|MainButton|] />; //// let opt = <[|MainButton|] children="chidlren" />; //// let opt = <[|MainButton|] onClick={()=>{}} />; @@ -30,4 +30,8 @@ //// let opt = <[|MainButton|] goTo="goTo" />; //// let opt = <[|MainButton|] wrong />; -verify.singleReferenceGroup("function MainButton(buttonProps: ButtonProps): JSX.Element (+2 overloads)"); +const rangesByText = test.rangesByText(); +verify.singleReferenceGroup( + "function MainButton(buttonProps: ButtonProps): JSX.Element (+2 overloads)", + rangesByText.get("MainButton") +); diff --git a/tests/cases/fourslash/tsxFindAllReferences9.ts b/tests/cases/fourslash/tsxFindAllReferences9.ts index bb45ce590cf..e10eb420926 100644 --- a/tests/cases/fourslash/tsxFindAllReferences9.ts +++ b/tests/cases/fourslash/tsxFindAllReferences9.ts @@ -18,7 +18,7 @@ //// onClick(event?: React.MouseEvent): void; //// } //// interface LinkProps extends ClickableProps { -//// [|{| "isDefinition": true |}goTo|]: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}goTo|]: string;|] //// } //// declare function MainButton(buttonProps: ButtonProps): JSX.Element; //// declare function MainButton(linkProps: LinkProps): JSX.Element; @@ -27,8 +27,9 @@ //// let opt = ; //// let opt = {}} />; //// let opt = {}} ignore-prop />; -//// let opt = ; +//// let opt = ; //// let opt = ; //// let opt = ; -verify.singleReferenceGroup("(property) LinkProps.goTo: string"); +const rangesByText = test.rangesByText(); +verify.singleReferenceGroup("(property) LinkProps.goTo: string", rangesByText.get("goTo")); diff --git a/tests/cases/fourslash/tsxFindAllReferencesUnionElementType1.ts b/tests/cases/fourslash/tsxFindAllReferencesUnionElementType1.ts index 87adbc11873..9da352c64b1 100644 --- a/tests/cases/fourslash/tsxFindAllReferencesUnionElementType1.ts +++ b/tests/cases/fourslash/tsxFindAllReferencesUnionElementType1.ts @@ -18,11 +18,12 @@ //// return

World

; //// } -//// var [|{| "isWriteAccess": true, "isDefinition": true |}SFCComp|] = SFC1 || SFC2; +//// [|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}SFCComp|] = SFC1 || SFC2;|] //// <[|SFCComp|] x={ "hi" } /> +const [, r1, r2] = test.ranges(); verify.singleReferenceGroup(`var SFCComp: ((prop: { x: number; }) => JSX.Element) | ((prop: { x: boolean; -}) => JSX.Element)`); +}) => JSX.Element)`, [r1, r2]); diff --git a/tests/cases/fourslash/tsxFindAllReferencesUnionElementType2.ts b/tests/cases/fourslash/tsxFindAllReferencesUnionElementType2.ts index 2498c8bf996..80291feb451 100644 --- a/tests/cases/fourslash/tsxFindAllReferencesUnionElementType2.ts +++ b/tests/cases/fourslash/tsxFindAllReferencesUnionElementType2.ts @@ -17,7 +17,8 @@ //// private method() { } //// } -//// var [|{| "isWriteAccess": true, "isDefinition": true |}RCComp|] = RC1 || RC2; +//// [|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}RCComp|] = RC1 || RC2;|] //// <[|RCComp|] /> -verify.singleReferenceGroup("var RCComp: typeof RC1"); +const [, r1, r2 ] = test.ranges(); +verify.singleReferenceGroup("var RCComp: typeof RC1", [r1, r2]); From bbfbf8fa952d7ac5d9a074071af41471cc3af6a5 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 30 May 2019 14:18:18 -0700 Subject: [PATCH 06/44] Use import export sepcifier as declaration for the property name of import export as well --- src/services/findAllReferences.ts | 31 ++++++++++++++----- .../fourslash/transitiveExportImports.ts | 10 +++--- .../fourslash/transitiveExportImports2.ts | 10 +++--- .../fourslash/transitiveExportImports3.ts | 10 +++--- .../cases/fourslash/tsxFindAllReferences2.ts | 2 +- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 72ac25c2e21..f8606e2bf1c 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -27,16 +27,31 @@ namespace ts.FindAllReferences { readonly textSpan: TextSpan; } export function nodeEntry(node: Node, kind: NodeEntryKind = EntryKind.Node): NodeEntry { + return { + kind, + node: (node as NamedDeclaration).name || node, + declaration: getDeclarationForDeclarationSpanForNode(node) + }; + } + + function getDeclarationForDeclarationSpanForNode(node: Node): Node | undefined { + if (isDeclaration(node)) { + return getDeclarationForDeclarationSpan(node); + } + // TODO(shkamat):: // JSXOpeningElement or JSXElement for tagName ? - const declaration = getDeclarationForDeclarationSpan( - isDeclaration(node) ? - node : - node.parent && isDeclaration(node.parent) && node.parent.name === node ? - node.parent : - undefined - ); - return { kind, node: (node as NamedDeclaration).name || node, declaration }; + if (!node.parent || !isDeclaration(node.parent)) { + return undefined; + } + + if (node.parent.name === node || // node is name of declaration, use parent + // Property name of the import export specifier use import/export specifier + isImportOrExportSpecifier(node.parent) && node.parent.propertyName === node) { + return getDeclarationForDeclarationSpan(node.parent); + } + + return undefined; } export function getDeclarationForDeclarationSpan(node: NamedDeclaration | undefined): Node | undefined { diff --git a/tests/cases/fourslash/transitiveExportImports.ts b/tests/cases/fourslash/transitiveExportImports.ts index 9cdfb2e3a12..fb5480b28c8 100644 --- a/tests/cases/fourslash/transitiveExportImports.ts +++ b/tests/cases/fourslash/transitiveExportImports.ts @@ -1,22 +1,22 @@ /// // @Filename: a.ts -////class [|{| "isWriteAccess": true, "isDefinition": true |}A|] { -////} +////[|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}A|] { +////}|] ////export = [|A|]; // @Filename: b.ts -////export import [|{| "isWriteAccess": true, "isDefinition": true |}b|] = require('./a'); +////[|export import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}b|] = require('./a');|] // @Filename: c.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}b|] = require('./b'); +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}b|] = require('./b');|] ////var a = new [|b|]./**/[|b|](); goTo.marker(); verify.quickInfoExists(); verify.noErrors(); -const [a0, a1, b0, c0, c1, c2] = test.ranges(); +const [a0Def, a0, a1, b0Def, b0, c0Def, c0, c1, c2] = test.ranges(); const aRanges = [a0, a1]; const bRanges = [b0, c2]; const cRanges = [c0, c1]; diff --git a/tests/cases/fourslash/transitiveExportImports2.ts b/tests/cases/fourslash/transitiveExportImports2.ts index 7ec1e61c02b..8070ad73e04 100644 --- a/tests/cases/fourslash/transitiveExportImports2.ts +++ b/tests/cases/fourslash/transitiveExportImports2.ts @@ -1,20 +1,20 @@ /// // @Filename: a.ts -////namespace [|{| "isWriteAccess": true, "isDefinition": true |}A|] { +////[|namespace [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}A|] { //// export const x = 0; -////} +////}|] // @Filename: b.ts -////export import [|{| "isWriteAccess": true, "isDefinition": true |}B|] = [|A|]; +////[|export import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}B|] = [|A|];|] ////[|B|].x; // @Filename: c.ts -////import { [|{| "isWriteAccess": true, "isDefinition": true |}B|] } from "./b"; +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}B|] } from "./b";|] verify.noErrors(); -const [A0, B0, A1, B1, B2] = test.ranges(); +const [A0Def, A0, B0Def, B0, A1, B1, B2Def, B2] = test.ranges(); const aRanges = [A0, A1]; const bRanges = [B0, B1]; const cRanges = [B2]; diff --git a/tests/cases/fourslash/transitiveExportImports3.ts b/tests/cases/fourslash/transitiveExportImports3.ts index c5d6dfe9afc..ab8c5e8ca1b 100644 --- a/tests/cases/fourslash/transitiveExportImports3.ts +++ b/tests/cases/fourslash/transitiveExportImports3.ts @@ -1,16 +1,16 @@ /// // @Filename: a.ts -////export function [|{| "isWriteAccess": true, "isDefinition": true |}f|]() {} +////[|export function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}f|]() {}|] // @Filename: b.ts -////export { [|f|] as [|{| "isWriteAccess": true, "isDefinition": true |}g|] } from "./a"; -////import { [|{| "isWriteAccess": true, "isDefinition": true |}f|] } from "./a"; -////import { [|{| "isWriteAccess": true, "isDefinition": true |}g|] } from "./b"; +////[|export { [|{| "declarationRangeIndex": 2 |}f|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}g|] } from "./a";|] +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}f|] } from "./a";|] +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 7 |}g|] } from "./b";|] verify.noErrors(); -const [f0, f1, g0, f2, g1] = test.ranges(); +const [f0Def, f0, f1Def, f1, g0, f2Def, f2, g1Def, g1] = test.ranges(); const af = { definition: "function f(): void", ranges: [f0, f1] }; const g0Group = { definition: "(alias) function g(): void\nexport g", ranges: [g0] }; diff --git a/tests/cases/fourslash/tsxFindAllReferences2.ts b/tests/cases/fourslash/tsxFindAllReferences2.ts index d83cb426992..f1b71e51811 100644 --- a/tests/cases/fourslash/tsxFindAllReferences2.ts +++ b/tests/cases/fourslash/tsxFindAllReferences2.ts @@ -15,6 +15,6 @@ const rangesByText = test.rangesByText(); verify.singleReferenceGroup( - "(property) name ?: string", + "(property) name?: string", rangesByText.get("name") ); From 2fc1143fe728fed2e9ce298eaf360a44d1de2a53 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 31 May 2019 10:23:07 -0700 Subject: [PATCH 07/44] More tests --- tests/cases/fourslash/renameRest.ts | 6 ++++-- tests/cases/fourslash/renameStringPropertyNames.ts | 7 ++++--- tests/cases/fourslash/renameThis.ts | 6 +++--- tests/cases/fourslash/renameUMDModuleAlias1.ts | 5 +++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tests/cases/fourslash/renameRest.ts b/tests/cases/fourslash/renameRest.ts index 60fc1bbb227..da1f590dd70 100644 --- a/tests/cases/fourslash/renameRest.ts +++ b/tests/cases/fourslash/renameRest.ts @@ -1,11 +1,13 @@ /// ////interface Gen { //// x: number; -//// [|parent|]: Gen; +//// [|[|{| "declarationRangeIndex": 0 |}parent|]: Gen;|] //// millenial: string; ////} ////let t: Gen; ////var { x, ...rest } = t; ////rest.[|parent|]; -verify.rangesAreRenameLocations(); + +const rangesByText = test.rangesByText(); +verify.rangesAreRenameLocations(rangesByText.get("parent")); diff --git a/tests/cases/fourslash/renameStringPropertyNames.ts b/tests/cases/fourslash/renameStringPropertyNames.ts index 13863b043e7..8d34ee458ea 100644 --- a/tests/cases/fourslash/renameStringPropertyNames.ts +++ b/tests/cases/fourslash/renameStringPropertyNames.ts @@ -1,15 +1,16 @@ /// ////var o = { -//// [|prop|]: 0 +//// [|[|{| "declarationRangeIndex": 0 |}prop|]: 0|] ////}; //// ////o = { -//// "[|prop|]": 1 +//// [|"[|{| "declarationRangeIndex": 2 |}prop|]": 1|] ////}; //// ////o["[|prop|]"]; ////o['[|prop|]']; ////o.[|prop|]; -verify.rangesAreRenameLocations(); +const rangesByText = test.rangesByText(); +verify.rangesAreRenameLocations(rangesByText.get("prop")); diff --git a/tests/cases/fourslash/renameThis.ts b/tests/cases/fourslash/renameThis.ts index e626294bf46..7a209c0d6cc 100644 --- a/tests/cases/fourslash/renameThis.ts +++ b/tests/cases/fourslash/renameThis.ts @@ -1,12 +1,12 @@ /// -////function f([|this|]) { +////function f([|{| "declarationRangeIndex": 0 |}this|]) { //// return [|this|]; ////} ////this/**/; -////const _ = { [|this|]: 0 }.[|this|]; +////const _ = { [|[|{| "declarationRangeIndex": 2 |}this|]: 0|] }.[|this|]; -const [r0, r1, r2, r3] = test.ranges() +const [r0, r1, r2Def, r2, r3] = test.ranges() verify.rangesAreRenameLocations([r0, r1]); // Trying to rename a non-parameter 'this' should fail diff --git a/tests/cases/fourslash/renameUMDModuleAlias1.ts b/tests/cases/fourslash/renameUMDModuleAlias1.ts index c44e459b008..510e117007b 100644 --- a/tests/cases/fourslash/renameUMDModuleAlias1.ts +++ b/tests/cases/fourslash/renameUMDModuleAlias1.ts @@ -4,10 +4,11 @@ //// export function doThing(): string; //// export function doTheOtherThing(): void; -//// export as namespace [|myLib|]; +//// [|export as namespace [|{| "declarationRangeIndex": 0 |}myLib|];|] // @Filename: 1.ts //// /// //// [|myLib|].doThing(); -verify.rangesAreRenameLocations(); +const rangesByText = test.rangesByText(); +verify.rangesAreRenameLocations(rangesByText.get("myLib")); From 15ce996cf5e513901308d17e94b841f82b48a2a1 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 31 May 2019 10:36:58 -0700 Subject: [PATCH 08/44] Export assignment identifier use ExportAssigment as declaration --- src/services/findAllReferences.ts | 6 ++++-- tests/cases/fourslash/renameReExportDefault.ts | 12 ++++++------ tests/cases/fourslash/transitiveExportImports.ts | 8 ++++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index f8606e2bf1c..453fd31ac98 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -41,13 +41,15 @@ namespace ts.FindAllReferences { // TODO(shkamat):: // JSXOpeningElement or JSXElement for tagName ? - if (!node.parent || !isDeclaration(node.parent)) { + if (!node.parent || (!isDeclaration(node.parent) && !isExportAssignment(node.parent))) { return undefined; } if (node.parent.name === node || // node is name of declaration, use parent // Property name of the import export specifier use import/export specifier - isImportOrExportSpecifier(node.parent) && node.parent.propertyName === node) { + isImportOrExportSpecifier(node.parent) && node.parent.propertyName === node || + // Is assignment of export assignment + isExportAssignment(node.parent) && node.parent.expression === node) { return getDeclarationForDeclarationSpan(node.parent); } diff --git a/tests/cases/fourslash/renameReExportDefault.ts b/tests/cases/fourslash/renameReExportDefault.ts index 0eb5b81d209..0e00a269b37 100644 --- a/tests/cases/fourslash/renameReExportDefault.ts +++ b/tests/cases/fourslash/renameReExportDefault.ts @@ -2,17 +2,17 @@ // @Filename: /a.ts ////export { default } from "./b"; -////export { default as [|b|] } from "./b"; +////[|export { default as [|{| "declarationRangeIndex": 0 |}b|] } from "./b";|] ////export { default as bee } from "./b"; -////import { default as [|b|] } from "./b"; +////[|import { default as [|{| "declarationRangeIndex": 2 |}b|] } from "./b";|] ////import { default as bee } from "./b"; -////import [|b|] from "./b"; +////[|import [|{| "declarationRangeIndex": 4 |}b|] from "./b";|] // @Filename: /b.ts -////const [|b|] = 0; -////export default [|b|]; +////[|const [|{| "declarationRangeIndex": 6 |}b|] = 0;|] +////[|export default [|{| "declarationRangeIndex": 8 |}b|];|] -const [r0, r1, r2, r3, r4] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3, r4Def, r4] = test.ranges(); verify.renameLocations(r0, [r0]); verify.renameLocations(r1, [r1]); verify.renameLocations(r2, [r2]); diff --git a/tests/cases/fourslash/transitiveExportImports.ts b/tests/cases/fourslash/transitiveExportImports.ts index fb5480b28c8..f492f28862a 100644 --- a/tests/cases/fourslash/transitiveExportImports.ts +++ b/tests/cases/fourslash/transitiveExportImports.ts @@ -3,20 +3,20 @@ // @Filename: a.ts ////[|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}A|] { ////}|] -////export = [|A|]; +////[|export = [|{| "declarationRangeIndex": 2 |}A|];|] // @Filename: b.ts -////[|export import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}b|] = require('./a');|] +////[|export import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}b|] = require('./a');|] // @Filename: c.ts -////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}b|] = require('./b');|] +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}b|] = require('./b');|] ////var a = new [|b|]./**/[|b|](); goTo.marker(); verify.quickInfoExists(); verify.noErrors(); -const [a0Def, a0, a1, b0Def, b0, c0Def, c0, c1, c2] = test.ranges(); +const [a0Def, a0, a1Def, a1, b0Def, b0, c0Def, c0, c1, c2] = test.ranges(); const aRanges = [a0, a1]; const bRanges = [b0, c2]; const cRanges = [c0, c1]; From bbd2d00b351614151d64d375d311e423fb4ee4b9 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 31 May 2019 11:32:25 -0700 Subject: [PATCH 09/44] More tests --- tests/cases/fourslash/renameObjectSpread.ts | 6 +++--- tests/cases/fourslash/renameObjectSpreadAssignment.ts | 6 +++--- .../cases/fourslash/renameParameterPropertyDeclaration1.ts | 5 +++-- .../cases/fourslash/renameParameterPropertyDeclaration2.ts | 5 +++-- .../cases/fourslash/renameParameterPropertyDeclaration3.ts | 5 +++-- .../cases/fourslash/renameParameterPropertyDeclaration4.ts | 4 ++-- .../cases/fourslash/renameParameterPropertyDeclaration5.ts | 5 +++-- .../renamePropertyAccessExpressionHeritageClause.ts | 5 +++-- 8 files changed, 23 insertions(+), 18 deletions(-) diff --git a/tests/cases/fourslash/renameObjectSpread.ts b/tests/cases/fourslash/renameObjectSpread.ts index f3af6e0280f..389de34cfc5 100644 --- a/tests/cases/fourslash/renameObjectSpread.ts +++ b/tests/cases/fourslash/renameObjectSpread.ts @@ -1,13 +1,13 @@ /// -////interface A1 { [|a|]: number }; -////interface A2 { [|a|]?: number }; +////interface A1 { [|[|{| "declarationRangeIndex": 0 |}a|]: number|] }; +////interface A2 { [|[|{| "declarationRangeIndex": 2 |}a|]?: number|] }; ////let a1: A1; ////let a2: A2; ////let a12 = { ...a1, ...a2 }; ////a12.[|a|]; -const [r0, r1, r2] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2] = test.ranges(); // A1 unions with A2, so rename A1.a and a12.a verify.renameLocations(r0, [r0, r2]); // A1 unions with A2, so rename A2.a and a12.a diff --git a/tests/cases/fourslash/renameObjectSpreadAssignment.ts b/tests/cases/fourslash/renameObjectSpreadAssignment.ts index 9d55e43afa5..c326a38ce6c 100644 --- a/tests/cases/fourslash/renameObjectSpreadAssignment.ts +++ b/tests/cases/fourslash/renameObjectSpreadAssignment.ts @@ -2,10 +2,10 @@ ////interface A1 { a: number }; ////interface A2 { a?: number }; -////let [|a1|]: A1; -////let [|a2|]: A2; +////[|let [|{| "declarationRangeIndex": 0 |}a1|]: A1;|] +////[|let [|{| "declarationRangeIndex": 2 |}a2|]: A2;|] ////let a12 = { ...[|a1|], ...[|a2|] }; -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2, r3] = test.ranges(); verify.rangesAreRenameLocations([r0, r2]); verify.rangesAreRenameLocations([r1, r3]); diff --git a/tests/cases/fourslash/renameParameterPropertyDeclaration1.ts b/tests/cases/fourslash/renameParameterPropertyDeclaration1.ts index 14f8a240bfb..90939afbaa0 100644 --- a/tests/cases/fourslash/renameParameterPropertyDeclaration1.ts +++ b/tests/cases/fourslash/renameParameterPropertyDeclaration1.ts @@ -1,10 +1,11 @@ /// //// class Foo { -//// constructor(private [|privateParam|]: number) { +//// constructor([|private [|{| "declarationRangeIndex": 0 |}privateParam|]: number|]) { //// let localPrivate = [|privateParam|]; //// this.[|privateParam|] += 10; //// } //// } -verify.rangesAreRenameLocations(); +const [rDef, ...rest] = test.ranges(); +verify.rangesAreRenameLocations(rest); diff --git a/tests/cases/fourslash/renameParameterPropertyDeclaration2.ts b/tests/cases/fourslash/renameParameterPropertyDeclaration2.ts index ce31ad6c9c5..a131106e4bf 100644 --- a/tests/cases/fourslash/renameParameterPropertyDeclaration2.ts +++ b/tests/cases/fourslash/renameParameterPropertyDeclaration2.ts @@ -1,10 +1,11 @@ /// //// class Foo { -//// constructor(public [|publicParam|]: number) { +//// constructor([|public [|{| "declarationRangeIndex": 0 |}publicParam|]: number|]) { //// let publicParam = [|publicParam|]; //// this.[|publicParam|] += 10; //// } //// } -verify.rangesAreRenameLocations(); +const [rDef, ...rest] = test.ranges(); +verify.rangesAreRenameLocations(rest); diff --git a/tests/cases/fourslash/renameParameterPropertyDeclaration3.ts b/tests/cases/fourslash/renameParameterPropertyDeclaration3.ts index 6291eff2605..73ab9b40c51 100644 --- a/tests/cases/fourslash/renameParameterPropertyDeclaration3.ts +++ b/tests/cases/fourslash/renameParameterPropertyDeclaration3.ts @@ -1,10 +1,11 @@ /// //// class Foo { -//// constructor(protected [|protectedParam|]: number) { +//// constructor([|protected [|{| "declarationRangeIndex": 0 |}protectedParam|]: number|]) { //// let protectedParam = [|protectedParam|]; //// this.[|protectedParam|] += 10; //// } //// } -verify.rangesAreRenameLocations(); +const [rDef, ...rest] = test.ranges(); +verify.rangesAreRenameLocations(rest); diff --git a/tests/cases/fourslash/renameParameterPropertyDeclaration4.ts b/tests/cases/fourslash/renameParameterPropertyDeclaration4.ts index 292c82a2d52..02cd24d64b5 100644 --- a/tests/cases/fourslash/renameParameterPropertyDeclaration4.ts +++ b/tests/cases/fourslash/renameParameterPropertyDeclaration4.ts @@ -1,10 +1,10 @@ /// //// class Foo { -//// constructor(protected { [|protectedParam|] }) { +//// constructor([|protected { [|{| "declarationRangeIndex": 0 |}protectedParam|] }|]) { //// let myProtectedParam = [|protectedParam|]; //// } //// } -const [r0, r1] = test.ranges(); +const [r0Def, r0, r1] = test.ranges(); verify.renameLocations([r0, r1], [{ range: r0, prefixText: "protectedParam: " }, r1]); diff --git a/tests/cases/fourslash/renameParameterPropertyDeclaration5.ts b/tests/cases/fourslash/renameParameterPropertyDeclaration5.ts index f989e7c3fd9..f92fd53b6f9 100644 --- a/tests/cases/fourslash/renameParameterPropertyDeclaration5.ts +++ b/tests/cases/fourslash/renameParameterPropertyDeclaration5.ts @@ -1,9 +1,10 @@ /// //// class Foo { -//// constructor(protected [ [|protectedParam|] ]) { +//// constructor([|protected [ [|{| "declarationRangeIndex": 0 |}protectedParam|] ]|]) { //// let myProtectedParam = [|protectedParam|]; //// } //// } -verify.rangesAreRenameLocations(); +const [rDef, ...rest] = test.ranges(); +verify.rangesAreRenameLocations(rest); diff --git a/tests/cases/fourslash/renamePropertyAccessExpressionHeritageClause.ts b/tests/cases/fourslash/renamePropertyAccessExpressionHeritageClause.ts index 04b741a4b97..ae6a1c70b90 100644 --- a/tests/cases/fourslash/renamePropertyAccessExpressionHeritageClause.ts +++ b/tests/cases/fourslash/renamePropertyAccessExpressionHeritageClause.ts @@ -2,9 +2,10 @@ //// class B {} //// function foo() { -//// return {[|B|]: B}; +//// return {[|[|{| "declarationRangeIndex": 0 |}B|]: B|]}; //// } //// class C extends (foo()).[|B|] {} //// class C1 extends foo().[|B|] {} -verify.rangesAreRenameLocations(); \ No newline at end of file +const ranges = test.rangesByText(); +verify.rangesAreRenameLocations(ranges.get("B")); \ No newline at end of file From 6c04a0d14e369075d63b7096712b406bcf0ad0cb Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 31 May 2019 11:33:36 -0700 Subject: [PATCH 10/44] For property name of binding element use binding element as preview node --- src/services/findAllReferences.ts | 8 ++++---- .../fourslash/renameObjectBindingElementPropertyName01.ts | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 453fd31ac98..743b8915ae0 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -40,15 +40,15 @@ namespace ts.FindAllReferences { } // TODO(shkamat):: - // JSXOpeningElement or JSXElement for tagName ? + // JSXOpeningElement or JSXElement for tagName ? if (!node.parent || (!isDeclaration(node.parent) && !isExportAssignment(node.parent))) { return undefined; } if (node.parent.name === node || // node is name of declaration, use parent - // Property name of the import export specifier use import/export specifier - isImportOrExportSpecifier(node.parent) && node.parent.propertyName === node || - // Is assignment of export assignment + // Property name of the import export specifier or binding pattern, use parent + ((isImportOrExportSpecifier(node.parent) || isBindingElement(node.parent)) + && node.parent.propertyName === node) || isExportAssignment(node.parent) && node.parent.expression === node) { return getDeclarationForDeclarationSpan(node.parent); } diff --git a/tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts b/tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts index 4ae87f19db5..526838995c3 100644 --- a/tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts +++ b/tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts @@ -1,11 +1,12 @@ /// ////interface I { -//// [|property1|]: number; +//// [|[|{| "declarationRangeIndex": 0 |}property1|]: number;|] //// property2: string; ////} //// ////var foo: I; -////var { [|property1|]: prop1 } = foo; +////[|var { [|{| "declarationRangeIndex": 2 |}property1|]: prop1 } = foo;|] -verify.rangesAreRenameLocations(); + +verify.rangesAreRenameLocations(test.rangesByText().get("property1")); From bcf7752c1f3d87b893c6de772f844fadc6f40bc6 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 31 May 2019 11:57:43 -0700 Subject: [PATCH 11/44] More tests --- tests/cases/fourslash/renameJsSpecialAssignmentRhs1.ts | 2 +- tests/cases/fourslash/renameJsSpecialAssignmentRhs2.ts | 2 +- .../cases/fourslash/renameLocationsForClassExpression01.ts | 7 ++++--- .../fourslash/renameLocationsForFunctionExpression01.ts | 7 ++++--- .../fourslash/renameLocationsForFunctionExpression02.ts | 7 ++++--- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/cases/fourslash/renameJsSpecialAssignmentRhs1.ts b/tests/cases/fourslash/renameJsSpecialAssignmentRhs1.ts index 013cfe34cd5..db3f1fc66e8 100644 --- a/tests/cases/fourslash/renameJsSpecialAssignmentRhs1.ts +++ b/tests/cases/fourslash/renameJsSpecialAssignmentRhs1.ts @@ -5,7 +5,7 @@ //// set: function (x) { //// this._x = x; //// }, -//// copy: function ([|x|]) { +//// copy: function ([|{| "declarationRangeIndex": 0 |}x|]) { //// this._x = [|x|].prop; //// } ////}; diff --git a/tests/cases/fourslash/renameJsSpecialAssignmentRhs2.ts b/tests/cases/fourslash/renameJsSpecialAssignmentRhs2.ts index 013cfe34cd5..db3f1fc66e8 100644 --- a/tests/cases/fourslash/renameJsSpecialAssignmentRhs2.ts +++ b/tests/cases/fourslash/renameJsSpecialAssignmentRhs2.ts @@ -5,7 +5,7 @@ //// set: function (x) { //// this._x = x; //// }, -//// copy: function ([|x|]) { +//// copy: function ([|{| "declarationRangeIndex": 0 |}x|]) { //// this._x = [|x|].prop; //// } ////}; diff --git a/tests/cases/fourslash/renameLocationsForClassExpression01.ts b/tests/cases/fourslash/renameLocationsForClassExpression01.ts index b0f2f509500..6379306608e 100644 --- a/tests/cases/fourslash/renameLocationsForClassExpression01.ts +++ b/tests/cases/fourslash/renameLocationsForClassExpression01.ts @@ -3,7 +3,7 @@ ////class Foo { ////} //// -////var x = class [|Foo|] { +////var x = [|class [|{| "declarationRangeIndex": 0 |}Foo|] { //// doIt() { //// return [|Foo|]; //// } @@ -11,7 +11,7 @@ //// static doItStatically() { //// return [|Foo|].y; //// } -////} +////}|] //// ////var y = class { //// getSomeName() { @@ -20,4 +20,5 @@ ////} ////var z = class Foo {} -verify.rangesAreRenameLocations(); +const [rDef, ...rest] = test.ranges(); +verify.rangesAreRenameLocations(rest); diff --git a/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts b/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts index 1e02e3f5284..e32a080683a 100644 --- a/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts +++ b/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts @@ -1,7 +1,8 @@ /// -////var x = function [|f|](g: any, h: any) { +////var x = [|function [|{| "declarationRangeIndex": 0 |}f|](g: any, h: any) { //// [|f|]([|f|], g); -////} +////}|] -verify.rangesAreRenameLocations(); +const [rDef, ...rest] = test.ranges(); +verify.rangesAreRenameLocations(rest); diff --git a/tests/cases/fourslash/renameLocationsForFunctionExpression02.ts b/tests/cases/fourslash/renameLocationsForFunctionExpression02.ts index a258bcd803d..ab835b5305c 100644 --- a/tests/cases/fourslash/renameLocationsForFunctionExpression02.ts +++ b/tests/cases/fourslash/renameLocationsForFunctionExpression02.ts @@ -3,11 +3,12 @@ ////function f() { //// ////} -////var x = function [|f|](g: any, h: any) { +////var x = [|function [|{| "declarationRangeIndex": 0 |}f|](g: any, h: any) { //// //// let helper = function f(): any { f(); } //// //// let foo = () => [|f|]([|f|], g); -////} +////}|] -verify.rangesAreRenameLocations(); +const [rDef, ...rest] = test.ranges(); +verify.rangesAreRenameLocations(rest); From 9703b3d6c12d969ee41ec916d421f900a7f10781 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 31 May 2019 12:34:08 -0700 Subject: [PATCH 12/44] Show property assignment for special property assignments in js files --- src/services/findAllReferences.ts | 27 ++++++++++++++++--- tests/cases/fourslash/renameJsExports01.ts | 7 ++--- tests/cases/fourslash/renameJsExports02.ts | 6 ++--- tests/cases/fourslash/renameJsExports03.ts | 12 ++++----- .../fourslash/renameJsPropertyAssignment.ts | 5 ++-- .../fourslash/renameJsPropertyAssignment2.ts | 5 ++-- .../fourslash/renameJsPropertyAssignment3.ts | 5 ++-- .../fourslash/renameJsPrototypeProperty01.ts | 7 ++--- .../fourslash/renameJsPrototypeProperty02.ts | 7 ++--- .../cases/fourslash/renameJsThisProperty01.ts | 7 ++--- .../cases/fourslash/renameJsThisProperty03.ts | 7 ++--- .../cases/fourslash/renameJsThisProperty05.ts | 7 ++--- .../cases/fourslash/renameJsThisProperty06.ts | 7 ++--- 13 files changed, 70 insertions(+), 39 deletions(-) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 743b8915ae0..b52777cb6fa 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -41,11 +41,27 @@ namespace ts.FindAllReferences { // TODO(shkamat):: // JSXOpeningElement or JSXElement for tagName ? - if (!node.parent || (!isDeclaration(node.parent) && !isExportAssignment(node.parent))) { + if (!node.parent) return undefined; + + if (!isDeclaration(node.parent) && !isExportAssignment(node.parent)) { + // Special property assignment in javascript + if (isInJSFile(node)) { + const binaryExpression = isBinaryExpression(node.parent) ? + node.parent : + isPropertyAccessExpression(node.parent) && + isBinaryExpression(node.parent.parent) && + node.parent.parent.left === node.parent ? + node.parent.parent : + undefined; + return binaryExpression && getAssignmentDeclarationKind(binaryExpression) !== AssignmentDeclarationKind.None ? + getDeclarationForDeclarationSpan(binaryExpression) : + undefined; + } return undefined; } - if (node.parent.name === node || // node is name of declaration, use parent + if (isConstructorDeclaration(node.parent) || + node.parent.name === node || // node is name of declaration, use parent // Property name of the import export specifier or binding pattern, use parent ((isImportOrExportSpecifier(node.parent) || isBindingElement(node.parent)) && node.parent.propertyName === node) || @@ -56,7 +72,7 @@ namespace ts.FindAllReferences { return undefined; } - export function getDeclarationForDeclarationSpan(node: NamedDeclaration | undefined): Node | undefined { + export function getDeclarationForDeclarationSpan(node: NamedDeclaration | BinaryExpression | undefined): Node | undefined { if (!node) return undefined; switch (node.kind) { case SyntaxKind.VariableDeclaration: @@ -84,6 +100,11 @@ namespace ts.FindAllReferences { undefined : node; + case SyntaxKind.BinaryExpression: + return isExpressionStatement(node.parent) ? + node.parent : + undefined; + // Not really interesting definition // TODO(shkamat):: Should we show whole object literal instead? case SyntaxKind.ShorthandPropertyAssignment: diff --git a/tests/cases/fourslash/renameJsExports01.ts b/tests/cases/fourslash/renameJsExports01.ts index e1b71d232a6..be5e4f6ea05 100644 --- a/tests/cases/fourslash/renameJsExports01.ts +++ b/tests/cases/fourslash/renameJsExports01.ts @@ -2,11 +2,12 @@ // @allowJs: true // @Filename: a.js -////exports.[|{| "isWriteAccess": true, "isDefinition": true |}area|] = function (r) { return r * r; } +////[|exports.[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}area|] = function (r) { return r * r; }|] // @Filename: b.js ////var mod = require('./a'); ////var t = mod./**/[|area|](10); -verify.singleReferenceGroup("(property) area: (r: any) => number"); -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.singleReferenceGroup("(property) area: (r: any) => number", ranges); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameJsExports02.ts b/tests/cases/fourslash/renameJsExports02.ts index 94c84980784..3628a9c8101 100644 --- a/tests/cases/fourslash/renameJsExports02.ts +++ b/tests/cases/fourslash/renameJsExports02.ts @@ -2,12 +2,12 @@ // @allowJs: true // @Filename: a.js -////module.exports = class [|{| "isWriteAccess": true, "isDefinition": true |}A|] {} +////module.exports = [|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}A|] {}|] // @Filename: b.js -////const [|{| "isWriteAccess": true, "isDefinition": true |}A|] = require("./a"); +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}A|] = require("./a");|] -const [r0, r1] = test.ranges(); +const [rDef, r0, r1Def, r1] = test.ranges(); verify.referenceGroups(r0, [ { definition: "(local class) A", ranges: [r0] }, { definition: "const A: typeof A", ranges: [r1] } diff --git a/tests/cases/fourslash/renameJsExports03.ts b/tests/cases/fourslash/renameJsExports03.ts index c4378cfaa1a..308f3c55ada 100644 --- a/tests/cases/fourslash/renameJsExports03.ts +++ b/tests/cases/fourslash/renameJsExports03.ts @@ -2,16 +2,16 @@ // @allowJs: true // @Filename: a.js -////class [|{| "isWriteAccess": true, "isDefinition": true |}A|] { -//// [|constructor|]() { } -////} -////module.exports = [|A|]; +////[|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}A|] { +//// [|[|{| "declarationRangeIndex": 2 |}constructor|]() { }|] +////}|] +////[|module.exports = [|{| "declarationRangeIndex": 4 |}A|];|] // @Filename: b.js -////const [|{| "isWriteAccess": true, "isDefinition": true |}A|] = require("./a"); +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}A|] = require("./a");|] ////new [|A|]; -const [r0, r1, r2, r3, r4] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3, r4] = test.ranges(); verify.referenceGroups([r0, r2], [ { definition: "class A", ranges: [r0, r2] }, { definition: "const A: typeof A", ranges: [r3, r4] } diff --git a/tests/cases/fourslash/renameJsPropertyAssignment.ts b/tests/cases/fourslash/renameJsPropertyAssignment.ts index 87daae544e1..a764bc18fd9 100644 --- a/tests/cases/fourslash/renameJsPropertyAssignment.ts +++ b/tests/cases/fourslash/renameJsPropertyAssignment.ts @@ -4,7 +4,8 @@ // @Filename: a.js ////function bar() { ////} -////bar.[|foo|] = "foo"; +////[|bar.[|{| "declarationRangeIndex": 0 |}foo|] = "foo";|] ////console.log(bar.[|foo|]); -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameJsPropertyAssignment2.ts b/tests/cases/fourslash/renameJsPropertyAssignment2.ts index eaea2b9aa27..dbd1749b3ed 100644 --- a/tests/cases/fourslash/renameJsPropertyAssignment2.ts +++ b/tests/cases/fourslash/renameJsPropertyAssignment2.ts @@ -4,7 +4,8 @@ // @Filename: a.js ////class Minimatch { ////} -////Minimatch.[|staticProperty|] = "string"; +////[|Minimatch.[|{| "declarationRangeIndex": 0 |}staticProperty|] = "string";|] ////console.log(Minimatch.[|staticProperty|]); -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameJsPropertyAssignment3.ts b/tests/cases/fourslash/renameJsPropertyAssignment3.ts index cedf69c7eee..462fbd06c8c 100644 --- a/tests/cases/fourslash/renameJsPropertyAssignment3.ts +++ b/tests/cases/fourslash/renameJsPropertyAssignment3.ts @@ -4,7 +4,8 @@ // @Filename: a.js ////var C = class { ////} -////C.[|staticProperty|] = "string"; +////[|C.[|{| "declarationRangeIndex": 0 |}staticProperty|] = "string";|] ////console.log(C.[|staticProperty|]); -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameJsPrototypeProperty01.ts b/tests/cases/fourslash/renameJsPrototypeProperty01.ts index 1700f15619d..b171ccdf005 100644 --- a/tests/cases/fourslash/renameJsPrototypeProperty01.ts +++ b/tests/cases/fourslash/renameJsPrototypeProperty01.ts @@ -4,8 +4,9 @@ // @Filename: a.js ////function bar() { ////} -////bar.prototype.[|x|] = 10; +////[|bar.prototype.[|{| "declarationRangeIndex": 0 |}x|] = 10;|] ////var t = new bar(); -////t.[|x|] = 11; +////[|t.[|{| "declarationRangeIndex": 2 |}x|] = 11;|] -verify.rangesAreRenameLocations(); +const [r0Def, r0, r1Def, r1] = test.ranges(); +verify.rangesAreRenameLocations([r0, r1]); diff --git a/tests/cases/fourslash/renameJsPrototypeProperty02.ts b/tests/cases/fourslash/renameJsPrototypeProperty02.ts index 1700f15619d..b171ccdf005 100644 --- a/tests/cases/fourslash/renameJsPrototypeProperty02.ts +++ b/tests/cases/fourslash/renameJsPrototypeProperty02.ts @@ -4,8 +4,9 @@ // @Filename: a.js ////function bar() { ////} -////bar.prototype.[|x|] = 10; +////[|bar.prototype.[|{| "declarationRangeIndex": 0 |}x|] = 10;|] ////var t = new bar(); -////t.[|x|] = 11; +////[|t.[|{| "declarationRangeIndex": 2 |}x|] = 11;|] -verify.rangesAreRenameLocations(); +const [r0Def, r0, r1Def, r1] = test.ranges(); +verify.rangesAreRenameLocations([r0, r1]); diff --git a/tests/cases/fourslash/renameJsThisProperty01.ts b/tests/cases/fourslash/renameJsThisProperty01.ts index 5680dbf08fd..7cd55020e20 100644 --- a/tests/cases/fourslash/renameJsThisProperty01.ts +++ b/tests/cases/fourslash/renameJsThisProperty01.ts @@ -3,9 +3,10 @@ // @allowJs: true // @Filename: a.js ////function bar() { -//// this.[|x|] = 10; +//// [|this.[|{| "declarationRangeIndex": 0 |}x|] = 10;|] ////} ////var t = new bar(); -////t.[|x|] = 11; +////[|t.[|{| "declarationRangeIndex": 2 |}x|] = 11;|] -verify.rangesAreRenameLocations(); +const [r0Def, r0, r1Def, r1] = test.ranges(); +verify.rangesAreRenameLocations([r0, r1]); diff --git a/tests/cases/fourslash/renameJsThisProperty03.ts b/tests/cases/fourslash/renameJsThisProperty03.ts index 8633c61132c..da5fc01e57a 100644 --- a/tests/cases/fourslash/renameJsThisProperty03.ts +++ b/tests/cases/fourslash/renameJsThisProperty03.ts @@ -4,10 +4,11 @@ // @Filename: a.js ////class C { //// constructor(y) { -//// this.[|x|] = y; +//// [|this.[|{| "declarationRangeIndex": 0 |}x|] = y;|] //// } ////} ////var t = new C(12); -////t.[|x|] = 11; +////[|t.[|{| "declarationRangeIndex": 2 |}x|] = 11;|] -verify.rangesAreRenameLocations(); +const [rDef, r0, r1Def, r1] = test.ranges(); +verify.rangesAreRenameLocations([r0, r1]); diff --git a/tests/cases/fourslash/renameJsThisProperty05.ts b/tests/cases/fourslash/renameJsThisProperty05.ts index 861919ec777..95a514e0abc 100644 --- a/tests/cases/fourslash/renameJsThisProperty05.ts +++ b/tests/cases/fourslash/renameJsThisProperty05.ts @@ -7,8 +7,9 @@ //// this.x = y; //// } ////} -////C.prototype.[|z|] = 1; +////[|C.prototype.[|{| "declarationRangeIndex": 0 |}z|] = 1;|] ////var t = new C(12); -////t.[|z|] = 11; +////[|t.[|{| "declarationRangeIndex": 2 |}z|] = 11;|] -verify.rangesAreRenameLocations(); +const [r0Def, r0, r1Def, r1] = test.ranges(); +verify.rangesAreRenameLocations([r0, r1]); diff --git a/tests/cases/fourslash/renameJsThisProperty06.ts b/tests/cases/fourslash/renameJsThisProperty06.ts index 7269a50f4f0..e7ae3256139 100644 --- a/tests/cases/fourslash/renameJsThisProperty06.ts +++ b/tests/cases/fourslash/renameJsThisProperty06.ts @@ -7,8 +7,9 @@ //// this.x = y; //// } ////} -////C.prototype.[|z|] = 1; +////[|C.prototype.[|{| "declarationRangeIndex": 0 |}z|] = 1;|] ////var t = new C(12); -////t.[|z|] = 11; +////[|t.[|{| "declarationRangeIndex": 2 |}z|] = 11;|] -verify.rangesAreRenameLocations(); +const [r0Def, r0, r1Def, r1] = test.ranges(); +verify.rangesAreRenameLocations([r0, r1]); From b61813ea1d6c99438dfd267d34df9d74cb1fa265 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 31 May 2019 14:40:59 -0700 Subject: [PATCH 13/44] More test cases --- .../fourslash/renameForDefaultExport01.ts | 6 ++--- .../fourslash/renameForDefaultExport02.ts | 6 ++--- .../fourslash/renameForDefaultExport03.ts | 12 ++++----- .../cases/fourslash/renameImportAndExport.ts | 6 ++--- .../renameImportAndExportInDiffFiles.ts | 8 +++--- .../fourslash/renameImportAndShorthand.ts | 4 +-- .../renameImportNamespaceAndShorthand.ts | 4 +-- .../fourslash/renameImportOfExportEquals.ts | 16 +++++------ .../fourslash/renameImportOfExportEquals2.ts | 27 ++++++++++--------- .../cases/fourslash/renameImportOfReExport.ts | 8 +++--- .../fourslash/renameImportOfReExport2.ts | 6 ++--- tests/cases/fourslash/renameImportRequire.ts | 10 +++---- .../fourslash/renameInheritedProperties1.ts | 5 ++-- .../fourslash/renameInheritedProperties2.ts | 5 ++-- .../fourslash/renameInheritedProperties3.ts | 5 ++-- .../fourslash/renameInheritedProperties4.ts | 5 ++-- .../fourslash/renameInheritedProperties5.ts | 5 ++-- .../fourslash/renameInheritedProperties6.ts | 5 ++-- .../fourslash/renameInheritedProperties7.ts | 5 ++-- .../fourslash/renameInheritedProperties8.ts | 6 ++--- 20 files changed, 82 insertions(+), 72 deletions(-) diff --git a/tests/cases/fourslash/renameForDefaultExport01.ts b/tests/cases/fourslash/renameForDefaultExport01.ts index 1256a9698fa..04169d093e5 100644 --- a/tests/cases/fourslash/renameForDefaultExport01.ts +++ b/tests/cases/fourslash/renameForDefaultExport01.ts @@ -1,7 +1,7 @@ /// -////export default class [|DefaultExportedClass|] { -////} +////[|export default class [|{| "declarationRangeIndex": 0 |}DefaultExportedClass|] { +////}|] /////* //// * Commenting [|{| "inComment": true |}DefaultExportedClass|] //// */ @@ -10,5 +10,5 @@ //// ////var y = new [|DefaultExportedClass|]; -const ranges = test.ranges(); +const ranges = test.rangesByText().get("DefaultExportedClass"); verify.renameLocations(ranges.filter(r => !(r.marker && r.marker.data.inComment)), { findInComments: true, ranges }); diff --git a/tests/cases/fourslash/renameForDefaultExport02.ts b/tests/cases/fourslash/renameForDefaultExport02.ts index a6f6116ec1a..1b97657da67 100644 --- a/tests/cases/fourslash/renameForDefaultExport02.ts +++ b/tests/cases/fourslash/renameForDefaultExport02.ts @@ -1,8 +1,8 @@ /// -////export default function /*1*/[|DefaultExportedFunction|]() { +////[|export default function /*1*/[|{| "declarationRangeIndex": 0 |}DefaultExportedFunction|]() { //// return /*2*/[|DefaultExportedFunction|] -////} +////}|] /////** //// * Commenting [|{| "inComment": true |}DefaultExportedFunction|] //// */ @@ -11,5 +11,5 @@ //// ////var y = /*4*/[|DefaultExportedFunction|](); -const ranges = test.ranges(); +const ranges = test.rangesByText().get("DefaultExportedFunction"); verify.renameLocations(ranges.filter(r => !(r.marker && r.marker.data.inComment)), { findInComments: true, ranges }); diff --git a/tests/cases/fourslash/renameForDefaultExport03.ts b/tests/cases/fourslash/renameForDefaultExport03.ts index edc22bb0db0..f9f859d2396 100644 --- a/tests/cases/fourslash/renameForDefaultExport03.ts +++ b/tests/cases/fourslash/renameForDefaultExport03.ts @@ -1,10 +1,10 @@ /// -////function /*1*/[|f|]() { +////[|function /*1*/[|{| "declarationRangeIndex": 0 |}f|]() { //// return 100; -////} +////}|] //// -////export default /*2*/[|f|]; +////[|export default /*2*/[|{| "declarationRangeIndex": 2 |}f|];|] //// ////var x: typeof /*3*/[|f|]; //// @@ -13,9 +13,9 @@ /////** //// * Commenting [|{| "inComment": true |}f|] //// */ -////namespace /*5*/[|f|] { +////[|namespace /*5*/[|{| "declarationRangeIndex": 7 |}f|] { //// var local = 100; -////} +////}|] -const ranges = test.ranges(); +const ranges = test.rangesByText().get("f"); verify.renameLocations(ranges.filter(r => !(r.marker && r.marker.data.inComment)), { findInComments: true, ranges }); diff --git a/tests/cases/fourslash/renameImportAndExport.ts b/tests/cases/fourslash/renameImportAndExport.ts index 6a9cac061a4..bae23ec2d1a 100644 --- a/tests/cases/fourslash/renameImportAndExport.ts +++ b/tests/cases/fourslash/renameImportAndExport.ts @@ -1,8 +1,8 @@ /// -////import [|a|] from "module"; -////export { [|a|] }; +////[|import [|{| "declarationRangeIndex": 0 |}a|] from "module";|] +////[|export { [|{| "declarationRangeIndex": 2 |}a|] };|] -const [r0, r1] = test.ranges(); +const [r0Def, r0, r1Def, r1] = test.ranges(); verify.renameLocations(r0, [r0, { range: r1, suffixText: " as a" }]); verify.renameLocations(r1, [{ range: r1, prefixText: "a as " }]); diff --git a/tests/cases/fourslash/renameImportAndExportInDiffFiles.ts b/tests/cases/fourslash/renameImportAndExportInDiffFiles.ts index 28297fc7255..c2578a80849 100644 --- a/tests/cases/fourslash/renameImportAndExportInDiffFiles.ts +++ b/tests/cases/fourslash/renameImportAndExportInDiffFiles.ts @@ -1,13 +1,13 @@ /// // @Filename: a.ts -////export var [|{| "isDefinition": true |}a|]; +////[|export var [|{| "isDefinition": true, "declarationRangeIndex": 0 |}a|];|] // @Filename: b.ts -////import { [|{| "isWriteAccess": true, "isDefinition": true |}a|] } from './a'; -////export { [|{| "isWriteAccess": true, "isDefinition": true |}a|] }; +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}a|] } from './a';|] +////[|export { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}a|] };|] -const [r0, r1, r2] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2] = test.ranges(); const vars = { definition: "var a: any", ranges: [r0] }; const imports = { definition: "(alias) var a: any\nimport a", ranges: [r1, r2] }; verify.referenceGroups(r0, [vars, imports]); diff --git a/tests/cases/fourslash/renameImportAndShorthand.ts b/tests/cases/fourslash/renameImportAndShorthand.ts index 01be6650b3b..be3ee23fb10 100644 --- a/tests/cases/fourslash/renameImportAndShorthand.ts +++ b/tests/cases/fourslash/renameImportAndShorthand.ts @@ -1,7 +1,7 @@ /// -////import [|foo|] from 'bar'; +////[|import [|{| "declarationRangeIndex": 0 |}foo|] from 'bar';|] ////const bar = { [|foo|] }; -const [r0, r1] = test.ranges(); +const [r0Def, r0, r1] = test.ranges(); verify.renameLocations([r0, r1], [r0, { range: r1, prefixText: "foo: " }]); diff --git a/tests/cases/fourslash/renameImportNamespaceAndShorthand.ts b/tests/cases/fourslash/renameImportNamespaceAndShorthand.ts index e577d82d3ae..942d6a5ffde 100644 --- a/tests/cases/fourslash/renameImportNamespaceAndShorthand.ts +++ b/tests/cases/fourslash/renameImportNamespaceAndShorthand.ts @@ -1,7 +1,7 @@ /// -////import * as [|foo|] from 'bar'; +////[|import * as [|{| "declarationRangeIndex": 0 |}foo|] from 'bar';|] ////const bar = { [|foo|] }; -const [r0, r1] = test.ranges(); +const [r0Def, r0, r1] = test.ranges(); verify.renameLocations([r0, r1], [r0, { range: r1, prefixText: "foo: " }]); diff --git a/tests/cases/fourslash/renameImportOfExportEquals.ts b/tests/cases/fourslash/renameImportOfExportEquals.ts index 6dfe8270c6b..230c50d71fd 100644 --- a/tests/cases/fourslash/renameImportOfExportEquals.ts +++ b/tests/cases/fourslash/renameImportOfExportEquals.ts @@ -1,21 +1,21 @@ /// -////declare namespace [|{| "isWriteAccess": true, "isDefinition": true |}N|] { -//// export var [|{| "isWriteAccess": true, "isDefinition": true |}x|]: number; -////} +////[|declare namespace [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}N|] { +//// [|export var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}x|]: number;|] +////}|] ////declare module "mod" { -//// export = [|N|]; +//// [|export = [|{| "declarationRangeIndex": 4 |}N|];|] ////} ////declare module "a" { -//// import * as [|{| "isWriteAccess": true, "isDefinition": true |}N|] from "mod"; -//// export { [|{| "isWriteAccess": true, "isDefinition": true |}N|] }; // Renaming N here would rename +//// [|import * as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}N|] from "mod";|] +//// [|export { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 8 |}N|] };|] // Renaming N here would rename ////} ////declare module "b" { -//// import { [|{| "isWriteAccess": true, "isDefinition": true |}N|] } from "a"; +//// [|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 10 |}N|] } from "a";|] //// export const y: typeof [|N|].[|x|]; ////} -const [N0, x0, N1, a0, a1, b0, b1, x1] = test.ranges(); +const [N0Def, N0, x0Def, x0, N1Def, N1, a0Def, a0, a1Def, a1, b0Def, b0, b1, x1] = test.ranges(); const nRanges = [N0, N1]; const aRanges = [a0, a1]; const bRanges = [b0, b1]; diff --git a/tests/cases/fourslash/renameImportOfExportEquals2.ts b/tests/cases/fourslash/renameImportOfExportEquals2.ts index dfb472caab8..67cb06b761b 100644 --- a/tests/cases/fourslash/renameImportOfExportEquals2.ts +++ b/tests/cases/fourslash/renameImportOfExportEquals2.ts @@ -1,27 +1,27 @@ /// -////declare namespace [|{| "isWriteAccess": true, "isDefinition": true |}N|] { +////[|declare namespace [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}N|] { //// export var x: number; -////} +////}|] ////declare module "mod" { -//// export = [|N|]; +//// [|export = [|{| "declarationRangeIndex": 2 |}N|];|] ////} ////declare module "a" { -//// import * as [|{| "isWriteAccess": true, "isDefinition": true |}O|] from "mod"; -//// export { [|O|] as [|{| "isWriteAccess": true, "isDefinition": true |}P|] }; // Renaming N here would rename +//// [|import * as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}O|] from "mod";|] +//// [|export { [|{| "declarationRangeIndex": 6 |}O|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}P|] };|] // Renaming N here would rename ////} ////declare module "b" { -//// import { [|P|] as [|{| "isWriteAccess": true, "isDefinition": true |}Q|] } from "a"; +//// [|import { [|{| "declarationRangeIndex": 9 |}P|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 9 |}Q|] } from "a";|] //// export const y: typeof [|Q|].x; ////} verify.noErrors(); -const [N0, N1, O0, O1, P0, P1, Q0, Q1] = test.ranges(); -const nRanges = [N0, N1]; -const oRanges = [O0, O1]; -const pRanges = [P0, P1]; -const qRanges = [Q0, Q1]; +const ranges = test.rangesByText(); +const nRanges = ranges.get("N");// [N0, N1]; +const oRanges = ranges.get("O");// [O0, O1]; +const pRanges = ranges.get("P");//[P0, P1]; +const qRanges = ranges.get("Q");//[Q0, Q1]; const ns = { definition: "namespace N", ranges: nRanges }; const os = { definition: "(alias) namespace O\nimport O", ranges: oRanges }; @@ -33,4 +33,7 @@ verify.referenceGroups(oRanges, [os, ps, qs]); verify.referenceGroups(pRanges, [ps, qs]); verify.referenceGroups(qRanges, [qs]); -verify.rangesWithSameTextAreRenameLocations(); +verify.rangesAreRenameLocations(nRanges); +verify.rangesAreRenameLocations(oRanges); +verify.rangesAreRenameLocations(pRanges); +verify.rangesAreRenameLocations(qRanges); diff --git a/tests/cases/fourslash/renameImportOfReExport.ts b/tests/cases/fourslash/renameImportOfReExport.ts index ced67d43b9c..9d181b3892f 100644 --- a/tests/cases/fourslash/renameImportOfReExport.ts +++ b/tests/cases/fourslash/renameImportOfReExport.ts @@ -2,20 +2,20 @@ // @noLib: true ////declare module "a" { -//// export class [|{| "isWriteAccess": true, "isDefinition": true |}C|] {} +//// [|export class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}C|] {}|] ////} ////declare module "b" { -//// export { [|{| "isWriteAccess": true, "isDefinition": true |}C|] } from "a"; +//// [|export { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}C|] } from "a";|] ////} ////declare module "c" { -//// import { [|{| "isWriteAccess": true, "isDefinition": true |}C|] } from "b"; +//// [|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}C|] } from "b";|] //// export function f(c: [|C|]): void; ////} verify.noErrors(); const ranges = test.ranges(); -const [r0, r1, r2, r3] = ranges; +const [r0Def, r0, r1Def, r1, r2Def, r2, r3] = ranges; const importRanges = [r2, r3]; verify.renameLocations(r0, [r0, { range: r1, suffixText: " as C" }]); //, r1 verify.renameLocations(r1, [{ range: r1, prefixText: "C as " }, r2, r3]); diff --git a/tests/cases/fourslash/renameImportOfReExport2.ts b/tests/cases/fourslash/renameImportOfReExport2.ts index a6389d4aeb8..fe3926fbf9b 100644 --- a/tests/cases/fourslash/renameImportOfReExport2.ts +++ b/tests/cases/fourslash/renameImportOfReExport2.ts @@ -1,13 +1,13 @@ /// ////declare module "a" { -//// export class [|{| "isWriteAccess": true, "isDefinition": true |}C|] {} +//// [|export class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}C|] {}|] ////} ////declare module "b" { -//// export { [|C|] as [|{| "isWriteAccess": true, "isDefinition": true |}D|] } from "a"; +//// [|export { [|{| "declarationRangeIndex": 2 |}C|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}D|] } from "a";|] ////} ////declare module "c" { -//// import { [|{| "isWriteAccess": true, "isDefinition": true |}D|] } from "b"; +//// [|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}D|] } from "b";|] //// export function f(c: [|D|]): void; ////} diff --git a/tests/cases/fourslash/renameImportRequire.ts b/tests/cases/fourslash/renameImportRequire.ts index 915143263dd..11b729c72d6 100644 --- a/tests/cases/fourslash/renameImportRequire.ts +++ b/tests/cases/fourslash/renameImportRequire.ts @@ -1,16 +1,16 @@ /// // @Filename: /a.ts -////import [|e|] = require("mod4"); +////[|import [|{| "declarationRangeIndex": 0 |}e|] = require("mod4");|] ////[|e|]; ////a = { [|e|] }; -////export { [|e|] }; +////[|export { [|{| "declarationRangeIndex": 4 |}e|] };|] // @Filename: /b.ts -////import { [|e|] } from "./a"; -////export { [|e|] }; +////[|import { [|{| "declarationRangeIndex": 6 |}e|] } from "./a";|] +////[|export { [|{| "declarationRangeIndex": 8 |}e|] };|] -const [r0, r1, r2, r3, r4, r5] = test.ranges(); +const [r0Def, r0, r1, r2, r3Def, r3, r4Def, r4, r5Def, r5] = test.ranges(); verify.renameLocations([r0, r1, r2], [r0, r1, { range: r2, prefixText: "e: " }, { range: r3, suffixText: " as e" }]); verify.renameLocations(r3, [{ range: r3, prefixText: "e as " }, r4, { range: r5, suffixText: " as e" }]); verify.renameLocations(r4, [{ range: r4, prefixText: "e as " }, { range: r5, suffixText: " as e" }]); diff --git a/tests/cases/fourslash/renameInheritedProperties1.ts b/tests/cases/fourslash/renameInheritedProperties1.ts index b42335277a9..2cd8ec23781 100644 --- a/tests/cases/fourslash/renameInheritedProperties1.ts +++ b/tests/cases/fourslash/renameInheritedProperties1.ts @@ -1,10 +1,11 @@ /// //// class class1 extends class1 { -//// [|propName|]: string; +//// [|[|{| "declarationRangeIndex": 0 |}propName|]: string;|] //// } //// //// var v: class1; //// v.[|propName|]; -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameInheritedProperties2.ts b/tests/cases/fourslash/renameInheritedProperties2.ts index bcc4c5fc323..de6c6e14d15 100644 --- a/tests/cases/fourslash/renameInheritedProperties2.ts +++ b/tests/cases/fourslash/renameInheritedProperties2.ts @@ -1,10 +1,11 @@ /// //// class class1 extends class1 { -//// [|doStuff|]() { } +//// [|[|{| "declarationRangeIndex": 0 |}doStuff|]() { }|] //// } //// //// var v: class1; //// v.[|doStuff|](); -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameInheritedProperties3.ts b/tests/cases/fourslash/renameInheritedProperties3.ts index f1ec547d6ed..9d8e9b65476 100644 --- a/tests/cases/fourslash/renameInheritedProperties3.ts +++ b/tests/cases/fourslash/renameInheritedProperties3.ts @@ -1,10 +1,11 @@ /// //// interface interface1 extends interface1 { -//// [|propName|]: string; +//// [|[|{| "declarationRangeIndex": 0 |}propName|]: string;|] //// } //// //// var v: interface1; //// v.[|propName|]; -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameInheritedProperties4.ts b/tests/cases/fourslash/renameInheritedProperties4.ts index 42d9acfdb53..1fe0bc9de7b 100644 --- a/tests/cases/fourslash/renameInheritedProperties4.ts +++ b/tests/cases/fourslash/renameInheritedProperties4.ts @@ -1,10 +1,11 @@ /// //// interface interface1 extends interface1 { -//// [|doStuff|](): string; +//// [|[|{| "declarationRangeIndex": 0 |}doStuff|](): string;|] //// } //// //// var v: interface1; //// v.[|doStuff|](); -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameInheritedProperties5.ts b/tests/cases/fourslash/renameInheritedProperties5.ts index e153742d4ed..352201999a4 100644 --- a/tests/cases/fourslash/renameInheritedProperties5.ts +++ b/tests/cases/fourslash/renameInheritedProperties5.ts @@ -4,10 +4,11 @@ //// propC: number; //// } //// interface D extends C { -//// [|propD|]: string; +//// [|[|{| "declarationRangeIndex": 0 |}propD|]: string;|] //// } //// var d: D; //// d.[|propD|]; -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameInheritedProperties6.ts b/tests/cases/fourslash/renameInheritedProperties6.ts index 59318334cb0..5f997f3c664 100644 --- a/tests/cases/fourslash/renameInheritedProperties6.ts +++ b/tests/cases/fourslash/renameInheritedProperties6.ts @@ -4,9 +4,10 @@ //// propD: number; //// } //// interface D extends C { -//// [|propC|]: number; +//// [|[|{| "declarationRangeIndex": 0 |}propC|]: number;|] //// } //// var d: D; //// d.[|propC|]; -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameInheritedProperties7.ts b/tests/cases/fourslash/renameInheritedProperties7.ts index bc0521458f8..94becfd2e5b 100644 --- a/tests/cases/fourslash/renameInheritedProperties7.ts +++ b/tests/cases/fourslash/renameInheritedProperties7.ts @@ -1,7 +1,7 @@ /// //// class C extends D { -//// [|prop1|]: string; +//// [|[|{| "declarationRangeIndex": 0 |}prop1|]: string;|] //// } //// //// class D extends C { @@ -11,4 +11,5 @@ //// var c: C; //// c.[|prop1|]; -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameInheritedProperties8.ts b/tests/cases/fourslash/renameInheritedProperties8.ts index 7cde300bf0b..f27ded79dae 100644 --- a/tests/cases/fourslash/renameInheritedProperties8.ts +++ b/tests/cases/fourslash/renameInheritedProperties8.ts @@ -1,14 +1,14 @@ /// //// class C implements D { -//// [|prop1|]: string; +//// [|[|{| "declarationRangeIndex": 0 |}prop1|]: string;|] //// } //// //// interface D extends C { -//// [|prop1|]: string; +//// [|[|{| "declarationRangeIndex": 2 |}prop1|]: string;|] //// } //// //// var c: C; //// c.[|prop1|]; -verify.rangesAreRenameLocations(); +verify.rangesAreRenameLocations(test.rangesByText().get("prop1")); From dfb613c6d6efe76b1b5f9055bdb66cf198c5c83c Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 31 May 2019 16:00:54 -0700 Subject: [PATCH 14/44] Use for-of declaration list + expression as span for preview --- src/services/findAllReferences.ts | 30 ++++++++++++++----- src/services/goToDefinition.ts | 8 ++--- src/services/utilities.ts | 4 +-- ...renameDestructuringNestedBindingElement.ts | 8 ++--- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index b52777cb6fa..fd6d3a109d5 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -16,10 +16,15 @@ namespace ts.FindAllReferences { export const enum EntryKind { Span, Node, StringLiteral, SearchedLocalFoundProperty, SearchedPropertyFoundLocal } export type NodeEntryKind = EntryKind.Node | EntryKind.StringLiteral | EntryKind.SearchedLocalFoundProperty | EntryKind.SearchedPropertyFoundLocal; export type Entry = NodeEntry | SpanEntry; + export interface DeclarationNodeWithStartAndEnd { + start: Node; + end: Node; + } + export type DeclarationNode = Node | DeclarationNodeWithStartAndEnd; export interface NodeEntry { readonly kind: NodeEntryKind; readonly node: Node; - readonly declaration?: Node; + readonly declaration?: DeclarationNode; } export interface SpanEntry { readonly kind: EntryKind.Span; @@ -34,7 +39,11 @@ namespace ts.FindAllReferences { }; } - function getDeclarationForDeclarationSpanForNode(node: Node): Node | undefined { + export function isDeclarationNodeWithStartAndEnd(node: DeclarationNode): node is DeclarationNodeWithStartAndEnd { + return node && (node as Node).kind === undefined; + } + + function getDeclarationForDeclarationSpanForNode(node: Node): DeclarationNode | undefined { if (isDeclaration(node)) { return getDeclarationForDeclarationSpan(node); } @@ -72,7 +81,7 @@ namespace ts.FindAllReferences { return undefined; } - export function getDeclarationForDeclarationSpan(node: NamedDeclaration | BinaryExpression | undefined): Node | undefined { + export function getDeclarationForDeclarationSpan(node: NamedDeclaration | BinaryExpression | undefined): DeclarationNode | undefined { if (!node) return undefined; switch (node.kind) { case SyntaxKind.VariableDeclaration: @@ -80,6 +89,8 @@ namespace ts.FindAllReferences { node : isVariableStatement(node.parent.parent) ? node.parent.parent : + isForInOrOfStatement(node.parent.parent) ? + { start: node.parent.parent.initializer, end: node.parent.parent.expression } : node.parent; case SyntaxKind.BindingElement: @@ -257,7 +268,9 @@ namespace ts.FindAllReferences { displayParts }; if (declaration) { - result.declarationSpan = getTextSpan(declaration, sourceFile); + result.declarationSpan = isDeclarationNodeWithStartAndEnd(declaration) ? + getTextSpan(declaration.start, sourceFile, declaration.end) : + getTextSpan(declaration, sourceFile); } return result; } @@ -298,7 +311,9 @@ namespace ts.FindAllReferences { const sourceFile = entry.node.getSourceFile(); const result: DocumentSpan = { textSpan: getTextSpan(entry.node, sourceFile), fileName: sourceFile.fileName }; if (entry.declaration) { - result.declarationSpan = getTextSpan(entry.declaration, sourceFile); + result.declarationSpan = isDeclarationNodeWithStartAndEnd(entry.declaration) ? + getTextSpan(entry.declaration.start, sourceFile, entry.declaration.end) : + getTextSpan(entry.declaration, sourceFile); } return result; } @@ -392,10 +407,11 @@ namespace ts.FindAllReferences { return { fileName: documentSpan.fileName, span }; } - function getTextSpan(node: Node, sourceFile: SourceFile): TextSpan { + function getTextSpan(node: Node, sourceFile: SourceFile, endNode?: Node): TextSpan { let start = node.getStart(sourceFile); - let end = node.getEnd(); + let end = (endNode || node).getEnd(); if (node.kind === SyntaxKind.StringLiteral) { + Debug.assert(endNode === undefined); start += 1; end -= 1; } diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index 7a04184c5d9..f64a2469156 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -273,6 +273,7 @@ namespace ts.GoToDefinition { function createDefinitionInfoFromName(declaration: Declaration, symbolKind: ScriptElementKind, symbolName: string, containerName: string): DefinitionInfo { const name = getNameOfDeclaration(declaration) || declaration; const sourceFile = name.getSourceFile(); + const declarationNode = FindAllReferences.getDeclarationForDeclarationSpan(declaration)!; return { fileName: sourceFile.fileName, textSpan: createTextSpanFromNode(name, sourceFile), @@ -280,10 +281,9 @@ namespace ts.GoToDefinition { name: symbolName, containerKind: undefined!, // TODO: GH#18217 containerName, - declarationSpan: createTextSpanFromNode( - FindAllReferences.getDeclarationForDeclarationSpan(declaration)!, - sourceFile - ) + declarationSpan: FindAllReferences.isDeclarationNodeWithStartAndEnd(declarationNode) ? + createTextSpanFromNode(declarationNode.start, sourceFile, declarationNode.end) : + createTextSpanFromNode(declarationNode, sourceFile), }; } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 5506b45d380..35fca7f0e65 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1190,8 +1190,8 @@ namespace ts { return !!range && shouldBeReference === tripleSlashDirectivePrefixRegex.test(sourceFile.text.substring(range.pos, range.end)); } - export function createTextSpanFromNode(node: Node, sourceFile?: SourceFile): TextSpan { - return createTextSpanFromBounds(node.getStart(sourceFile), node.getEnd()); + export function createTextSpanFromNode(node: Node, sourceFile?: SourceFile, endNode?: Node): TextSpan { + return createTextSpanFromBounds(node.getStart(sourceFile), (endNode || node).getEnd()); } export function createTextRangeFromNode(node: Node, sourceFile: SourceFile): TextRange { diff --git a/tests/cases/fourslash/renameDestructuringNestedBindingElement.ts b/tests/cases/fourslash/renameDestructuringNestedBindingElement.ts index 6643382f6c9..f262f44c6f0 100644 --- a/tests/cases/fourslash/renameDestructuringNestedBindingElement.ts +++ b/tests/cases/fourslash/renameDestructuringNestedBindingElement.ts @@ -3,18 +3,18 @@ ////interface MultiRobot { //// name: string; //// skills: { -//// [|primary|]: string; +//// [|[|{| "declarationRangeIndex": 0|}primary|]: string;|] //// secondary: string; //// }; ////} ////let multiRobots: MultiRobot[]; -////for (let { skills: {[|primary|]: primaryA, secondary: secondaryA } } of multiRobots) { +////for ([|let { skills: {[|{| "declarationRangeIndex": 2|}primary|]: primaryA, secondary: secondaryA } } of multiRobots|]) { //// console.log(primaryA); ////} -////for (let { skills: {[|primary|], secondary } } of multiRobots) { +////for ([|let { skills: {[|{| "declarationRangeIndex": 4|}primary|], secondary } } of multiRobots|]) { //// console.log([|primary|]); ////} -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3] = test.ranges(); verify.renameLocations([r0, r1], [r0, r1, { range: r2, suffixText: ": primary" }]); verify.renameLocations([r2, r3], [{ range: r2, prefixText: "primary: " }, r3]); From c0537d9bad3d1a190c023a1e1b75d6b04a7d1973 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Fri, 31 May 2019 16:19:27 -0700 Subject: [PATCH 15/44] More tests --- .../fourslash/renameDestructuringClassProperty.ts | 10 +++++----- .../fourslash/renameDestructuringDeclarationInFor.ts | 8 ++++---- .../fourslash/renameDestructuringDeclarationInForOf.ts | 8 ++++---- .../fourslash/renameDestructuringFunctionParameter.ts | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/cases/fourslash/renameDestructuringClassProperty.ts b/tests/cases/fourslash/renameDestructuringClassProperty.ts index ac708e55471..1cab702903f 100644 --- a/tests/cases/fourslash/renameDestructuringClassProperty.ts +++ b/tests/cases/fourslash/renameDestructuringClassProperty.ts @@ -1,22 +1,22 @@ /// ////class A { -//// [|foo|]: string; +//// [|[|{| "declarationRangeIndex": 0 |}foo|]: string;|] ////} ////class B { //// syntax1(a: A): void { -//// let { [|foo|] } = a; +//// [|let { [|{| "declarationRangeIndex": 2 |}foo|] } = a;|] //// } //// syntax2(a: A): void { -//// let { [|foo|]: foo } = a; +//// [|let { [|{| "declarationRangeIndex": 4 |}foo|]: foo } = a;|] //// } //// syntax11(a: A): void { -//// let { [|foo|] } = a; +//// [|let { [|{| "declarationRangeIndex": 6 |}foo|] } = a;|] //// [|foo|] = "newString"; //// } ////} -const [r0, r1, r2, r3, r4] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3, r4] = test.ranges(); verify.renameLocations([r0, r2], [r0, { range: r1, suffixText: ": foo" }, r2, { range: r3, suffixText: ": foo" }]); verify.renameLocations(r1, [{ range: r1, prefixText: "foo: " }]); verify.renameLocations([r3, r4], [{ range: r3, prefixText: "foo: " }, r4]); diff --git a/tests/cases/fourslash/renameDestructuringDeclarationInFor.ts b/tests/cases/fourslash/renameDestructuringDeclarationInFor.ts index 02bc0f50826..bde0f348736 100644 --- a/tests/cases/fourslash/renameDestructuringDeclarationInFor.ts +++ b/tests/cases/fourslash/renameDestructuringDeclarationInFor.ts @@ -1,18 +1,18 @@ /// ////interface I { -//// [|property1|]: number; +//// [|[|{| "declarationRangeIndex": 0 |}property1|]: number;|] //// property2: string; ////} ////var elems: I[]; //// ////var p2: number, property1: number; -////for (let { [|property1|]: p2 } = elems[0]; p2 < 100; p2++) { +////for ([|let { [|{| "declarationRangeIndex": 2 |}property1|]: p2 } = elems[0]|]; p2 < 100; p2++) { ////} -////for (let { [|property1|] } = elems[0]; p2 < 100; p2++) { +////for ([|let { [|{| "declarationRangeIndex": 4 |}property1|] } = elems[0]|]; p2 < 100; p2++) { //// [|property1|] = p2; ////} -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3] = test.ranges(); verify.renameLocations([r0, r1], [r0, r1, { range: r2, suffixText: ": property1" }]); verify.renameLocations([r2, r3], [{ range: r2, prefixText: "property1: " }, r3]); diff --git a/tests/cases/fourslash/renameDestructuringDeclarationInForOf.ts b/tests/cases/fourslash/renameDestructuringDeclarationInForOf.ts index a8e21c83cf3..b2ad6e01b31 100644 --- a/tests/cases/fourslash/renameDestructuringDeclarationInForOf.ts +++ b/tests/cases/fourslash/renameDestructuringDeclarationInForOf.ts @@ -1,17 +1,17 @@ /// ////interface I { -//// [|property1|]: number; +//// [|[|{| "declarationRangeIndex": 0 |}property1|]: number;|] //// property2: string; ////} ////var elems: I[]; //// -////for (let { [|property1|] } of elems) { +////for ([|let { [|{| "declarationRangeIndex": 2 |}property1|] } of elems|]) { //// [|property1|]++; ////} -////for (let { [|property1|]: p2 } of elems) { +////for ([|let { [|{| "declarationRangeIndex": 5 |}property1|]: p2 } of elems|]) { ////} -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2, r3Def, r3] = test.ranges(); verify.renameLocations([r0, r3], [r0, { range: r1, suffixText: ": property1" }, r3]); verify.renameLocations([r1, r2], [{ range: r1, prefixText: "property1: " }, r2]); diff --git a/tests/cases/fourslash/renameDestructuringFunctionParameter.ts b/tests/cases/fourslash/renameDestructuringFunctionParameter.ts index d6a732176d2..79d2b40193b 100644 --- a/tests/cases/fourslash/renameDestructuringFunctionParameter.ts +++ b/tests/cases/fourslash/renameDestructuringFunctionParameter.ts @@ -1,10 +1,10 @@ /// -////function f({[|a|]}: {[|a|]}) { +////function f([|{[|{| "declarationRangeIndex": 0 |}a|]}: {[|{| "declarationRangeIndex": 2 |}a|]}|]) { //// f({[|a|]}); ////} -const [r0, r1, r2] = test.ranges(); +const [r0Def, r0, r1, r2] = test.ranges(); // renames the local verify.renameLocations([r0, r2], [{ range: r0, prefixText: "a: " }, { range: r2, prefixText: "a: " }]); // renames the property From 0fee3b023d021365235b537baf58792ccce6ab0c Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 3 Jun 2019 13:22:14 -0700 Subject: [PATCH 16/44] Handle destructuring assignments --- src/services/findAllReferences.ts | 27 ++++++++++++++----- .../renameDestructuringAssignment.ts | 6 ++--- .../renameDestructuringAssignmentInFor.ts | 10 +++---- .../renameDestructuringAssignmentInForOf.ts | 10 +++---- ...ructuringAssignmentNestedInArrayLiteral.ts | 10 +++---- ...enameDestructuringAssignmentNestedInFor.ts | 10 +++---- ...nameDestructuringAssignmentNestedInFor2.ts | 10 +++---- ...ameDestructuringAssignmentNestedInForOf.ts | 10 +++---- ...meDestructuringAssignmentNestedInForOf2.ts | 10 +++---- 9 files changed, 59 insertions(+), 44 deletions(-) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index fd6d3a109d5..c3a8cc15b08 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -81,7 +81,7 @@ namespace ts.FindAllReferences { return undefined; } - export function getDeclarationForDeclarationSpan(node: NamedDeclaration | BinaryExpression | undefined): DeclarationNode | undefined { + export function getDeclarationForDeclarationSpan(node: NamedDeclaration | BinaryExpression | ForInOrOfStatement | undefined): DeclarationNode | undefined { if (!node) return undefined; switch (node.kind) { case SyntaxKind.VariableDeclaration: @@ -90,8 +90,8 @@ namespace ts.FindAllReferences { isVariableStatement(node.parent.parent) ? node.parent.parent : isForInOrOfStatement(node.parent.parent) ? - { start: node.parent.parent.initializer, end: node.parent.parent.expression } : - node.parent; + getDeclarationForDeclarationSpan(node.parent.parent) : + node.parent; case SyntaxKind.BindingElement: return getDeclarationForDeclarationSpan(node.parent.parent as NamedDeclaration); @@ -114,12 +114,27 @@ namespace ts.FindAllReferences { case SyntaxKind.BinaryExpression: return isExpressionStatement(node.parent) ? node.parent : - undefined; + node; - // Not really interesting definition + case SyntaxKind.ForOfStatement: + case SyntaxKind.ForInStatement: + return { + start: (node as ForInOrOfStatement).initializer, + end: (node as ForInOrOfStatement).expression + }; + + case SyntaxKind.PropertyAssignment: // TODO(shkamat):: Should we show whole object literal instead? case SyntaxKind.ShorthandPropertyAssignment: - return undefined; + return isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent) ? + getDeclarationForDeclarationSpan( + findAncestor(node.parent, node => + isBinaryExpression(node) || isForInOrOfStatement(node) + ) as BinaryExpression | ForInOrOfStatement + ) : + node.kind === SyntaxKind.PropertyAssignment ? + node : + undefined; default: return node; diff --git a/tests/cases/fourslash/renameDestructuringAssignment.ts b/tests/cases/fourslash/renameDestructuringAssignment.ts index 89a44a3a9d9..7833f4166a2 100644 --- a/tests/cases/fourslash/renameDestructuringAssignment.ts +++ b/tests/cases/fourslash/renameDestructuringAssignment.ts @@ -1,10 +1,10 @@ /// ////interface I { -//// [|x|]: number; +//// [|[|{| "declarationRangeIndex": 0 |}x|]: number;|] ////} ////var a: I; ////var x; -////({ [|x|]: x } = a); +////([|{ [|{| "declarationRangeIndex": 2 |}x|]: x } = a|]); -verify.rangesAreRenameLocations(); +verify.rangesAreRenameLocations(test.rangesByText().get("x")); diff --git a/tests/cases/fourslash/renameDestructuringAssignmentInFor.ts b/tests/cases/fourslash/renameDestructuringAssignmentInFor.ts index 2c8ad51f486..0ed560bb3fb 100644 --- a/tests/cases/fourslash/renameDestructuringAssignmentInFor.ts +++ b/tests/cases/fourslash/renameDestructuringAssignmentInFor.ts @@ -1,20 +1,20 @@ /// ////interface I { -//// [|property1|]: number; +//// [|[|{| "declarationRangeIndex": 0 |}property1|]: number;|] //// property2: string; ////} ////var elems: I[]; //// -////var p2: number, [|property1|]: number; -////for ({ [|property1|] } = elems[0]; p2 < 100; p2++) { +////var p2: number, [|[|{| "declarationRangeIndex": 2 |}property1|]: number|]; +////for ([|{ [|{| "declarationRangeIndex": 4 |}property1|] } = elems[0]|]; p2 < 100; p2++) { //// p2 = [|property1|]++; ////} -////for ({ [|property1|]: p2 } = elems[0]; p2 < 100; p2++) { +////for ([|{ [|{| "declarationRangeIndex": 7 |}property1|]: p2 } = elems[0]|]; p2 < 100; p2++) { ////} verify.noErrors(); const ranges = test.ranges(); -const [r0, r1, r2, r3, r4] = ranges; +const [r0Def, r0, r1Def, r1, r2Def, r2, r3, r4Def, r4] = ranges; verify.renameLocations([r0, r4], [r0, { range: r2, suffixText: ": property1" }, r4]); verify.renameLocations([r1, r2, r3], [r1, { range: r2, prefixText: "property1: " }, r3]); diff --git a/tests/cases/fourslash/renameDestructuringAssignmentInForOf.ts b/tests/cases/fourslash/renameDestructuringAssignmentInForOf.ts index 38703a68b99..80bc064ac0b 100644 --- a/tests/cases/fourslash/renameDestructuringAssignmentInForOf.ts +++ b/tests/cases/fourslash/renameDestructuringAssignmentInForOf.ts @@ -1,20 +1,20 @@ /// ////interface I { -//// [|property1|]: number; +//// [|[|{| "declarationRangeIndex": 0 |}property1|]: number;|] //// property2: string; ////} ////var elems: I[]; //// -////var [|property1|]: number, p2: number; -////for ({ [|property1|] } of elems) { +////var [|[|{| "declarationRangeIndex": 2 |}property1|]: number|], p2: number; +////for ([|{ [|{| "declarationRangeIndex": 4 |}property1|] } of elems|]) { //// [|property1|]++; ////} -////for ({ [|property1|]: p2 } of elems) { +////for ([|{ [|{| "declarationRangeIndex": 7 |}property1|]: p2 } of elems|]) { ////} verify.noErrors(); const ranges = test.ranges(); -const [r0, r1, r2, r3, r4] = ranges; +const [r0Def, r0, r1Def, r1, r2Def, r2, r3, r4Def, r4] = ranges; verify.renameLocations([r0, r4], [r0, { range: r2, suffixText: ": property1" }, r4]); verify.renameLocations([r1, r2, r3], [r1, { range: r2, prefixText: "property1: " }, r3]); diff --git a/tests/cases/fourslash/renameDestructuringAssignmentNestedInArrayLiteral.ts b/tests/cases/fourslash/renameDestructuringAssignmentNestedInArrayLiteral.ts index 292aaf1bf6d..2b8b882407c 100644 --- a/tests/cases/fourslash/renameDestructuringAssignmentNestedInArrayLiteral.ts +++ b/tests/cases/fourslash/renameDestructuringAssignmentNestedInArrayLiteral.ts @@ -1,15 +1,15 @@ /// ////interface I { -//// [|property1|]: number; +//// [|[|{| "declarationRangeIndex": 0 |}property1|]: number;|] //// property2: string; ////} -////var elems: I[], p1: number, [|property1|]: number; -////[{ [|property1|]: p1 }] = elems; -////[{ [|property1|] }] = elems; +////var elems: I[], p1: number, [|[|{| "declarationRangeIndex": 2 |}property1|]: number|]; +////[|[{ [|{| "declarationRangeIndex": 4 |}property1|]: p1 }] = elems;|] +////[|[{ [|{| "declarationRangeIndex": 6 |}property1|] }] = elems;|] const ranges = test.ranges(); -const [r0, r1, r2, r3] = ranges; +const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3] = ranges; verify.renameLocations([r0, r2], [r0, r2, { range: r3, suffixText: ": property1" }]); verify.renameLocations([r1, r3], [r1, { range: r3, prefixText: "property1: " }]); diff --git a/tests/cases/fourslash/renameDestructuringAssignmentNestedInFor.ts b/tests/cases/fourslash/renameDestructuringAssignmentNestedInFor.ts index e83487d15d2..5a2f4699942 100644 --- a/tests/cases/fourslash/renameDestructuringAssignmentNestedInFor.ts +++ b/tests/cases/fourslash/renameDestructuringAssignmentNestedInFor.ts @@ -3,20 +3,20 @@ ////interface MultiRobot { //// name: string; //// skills: { -//// [|primary|]: string; +//// [|[|{| "declarationRangeIndex": 0 |}primary|]: string;|] //// secondary: string; //// }; ////} -////let multiRobot: MultiRobot, [|primary|]: string, secondary: string, primaryA: string, secondaryA: string, i: number; -////for ({ skills: { [|primary|]: primaryA, secondary: secondaryA } } = multiRobot, i = 0; i < 1; i++) { +////let multiRobot: MultiRobot, [|[|{| "declarationRangeIndex": 2 |}primary|]: string|], secondary: string, primaryA: string, secondaryA: string, i: number; +////for ([|{ skills: { [|{| "declarationRangeIndex": 4 |}primary|]: primaryA, secondary: secondaryA } } = multiRobot|], i = 0; i < 1; i++) { //// primaryA; ////} -////for ({ skills: { [|primary|], secondary } } = multiRobot, i = 0; i < 1; i++) { +////for ([|{ skills: { [|{| "declarationRangeIndex": 6 |}primary|], secondary } } = multiRobot|], i = 0; i < 1; i++) { //// [|primary|]; ////} verify.noErrors(); const ranges = test.ranges(); -const [r0, r1, r2, r3, r4] = ranges; +const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3, r4] = ranges; verify.renameLocations([r0, r2], [r0, r2, { range: r3, suffixText: ": primary" }]); verify.renameLocations([r1, r3, r4], [r1, { range: r3, prefixText: "primary: " }, r4]); diff --git a/tests/cases/fourslash/renameDestructuringAssignmentNestedInFor2.ts b/tests/cases/fourslash/renameDestructuringAssignmentNestedInFor2.ts index e83487d15d2..5a2f4699942 100644 --- a/tests/cases/fourslash/renameDestructuringAssignmentNestedInFor2.ts +++ b/tests/cases/fourslash/renameDestructuringAssignmentNestedInFor2.ts @@ -3,20 +3,20 @@ ////interface MultiRobot { //// name: string; //// skills: { -//// [|primary|]: string; +//// [|[|{| "declarationRangeIndex": 0 |}primary|]: string;|] //// secondary: string; //// }; ////} -////let multiRobot: MultiRobot, [|primary|]: string, secondary: string, primaryA: string, secondaryA: string, i: number; -////for ({ skills: { [|primary|]: primaryA, secondary: secondaryA } } = multiRobot, i = 0; i < 1; i++) { +////let multiRobot: MultiRobot, [|[|{| "declarationRangeIndex": 2 |}primary|]: string|], secondary: string, primaryA: string, secondaryA: string, i: number; +////for ([|{ skills: { [|{| "declarationRangeIndex": 4 |}primary|]: primaryA, secondary: secondaryA } } = multiRobot|], i = 0; i < 1; i++) { //// primaryA; ////} -////for ({ skills: { [|primary|], secondary } } = multiRobot, i = 0; i < 1; i++) { +////for ([|{ skills: { [|{| "declarationRangeIndex": 6 |}primary|], secondary } } = multiRobot|], i = 0; i < 1; i++) { //// [|primary|]; ////} verify.noErrors(); const ranges = test.ranges(); -const [r0, r1, r2, r3, r4] = ranges; +const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3, r4] = ranges; verify.renameLocations([r0, r2], [r0, r2, { range: r3, suffixText: ": primary" }]); verify.renameLocations([r1, r3, r4], [r1, { range: r3, prefixText: "primary: " }, r4]); diff --git a/tests/cases/fourslash/renameDestructuringAssignmentNestedInForOf.ts b/tests/cases/fourslash/renameDestructuringAssignmentNestedInForOf.ts index 6a9eb6235b7..7a7786d5a99 100644 --- a/tests/cases/fourslash/renameDestructuringAssignmentNestedInForOf.ts +++ b/tests/cases/fourslash/renameDestructuringAssignmentNestedInForOf.ts @@ -3,20 +3,20 @@ ////interface MultiRobot { //// name: string; //// skills: { -//// [|primary|]: string; +//// [|[|{| "declarationRangeIndex": 0 |}primary|]: string;|] //// secondary: string; //// }; ////} ////let multiRobots: MultiRobot[]; -////let [|primary|]: string, secondary: string, primaryA: string, secondaryA: string; -////for ({ skills: { [|primary|]: primaryA, secondary: secondaryA } } of multiRobots) { +////let [|[|{| "declarationRangeIndex": 2 |}primary|]: string|], secondary: string, primaryA: string, secondaryA: string; +////for ([|{ skills: { [|{| "declarationRangeIndex": 4 |}primary|]: primaryA, secondary: secondaryA } } of multiRobots|]) { //// primaryA; ////} -////for ({ skills: { [|primary|], secondary } } of multiRobots) { +////for ([|{ skills: { [|{| "declarationRangeIndex": 6 |}primary|], secondary } } of multiRobots|]) { //// [|primary|]; ////} verify.noErrors(); -const [r0, r1, r2, r3, r4] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3, r4] = test.ranges(); verify.renameLocations([r0, r2], [r0, r2, { range: r3, suffixText: ": primary" }]); verify.renameLocations([r1, r3, r4], [r1, { range: r3, prefixText: "primary: " }, r4]) diff --git a/tests/cases/fourslash/renameDestructuringAssignmentNestedInForOf2.ts b/tests/cases/fourslash/renameDestructuringAssignmentNestedInForOf2.ts index 7c5c288ea78..897c0ba871c 100644 --- a/tests/cases/fourslash/renameDestructuringAssignmentNestedInForOf2.ts +++ b/tests/cases/fourslash/renameDestructuringAssignmentNestedInForOf2.ts @@ -3,19 +3,19 @@ ////interface MultiRobot { //// name: string; //// skills: { -//// [|primary|]: string; +//// [|[|{| "declarationRangeIndex": 0 |}primary|]: string;|] //// secondary: string; //// }; ////} -////let multiRobots: MultiRobot[], [|primary|]: string; -////for ({ skills: { [|primary|]: primaryA, secondary: secondaryA } } of multiRobots) { +////let multiRobots: MultiRobot[], [|[|{| "declarationRangeIndex": 2 |}primary|]: string|]; +////for ([|{ skills: { [|{| "declarationRangeIndex": 4 |}primary|]: primaryA, secondary: secondaryA } } of multiRobots|]) { //// console.log(primaryA); ////} -////for ({ skills: { [|primary|], secondary } } of multiRobots) { +////for ([|{ skills: { [|{| "declarationRangeIndex": 6 |}primary|], secondary } } of multiRobots|]) { //// console.log([|primary|]); ////} const ranges = test.ranges(); -const [r0, r1, r2, r3, r4] = ranges; +const [r0Def, r0, r1Def, r1,r2Def, r2, r3Def, r3, r4] = ranges; verify.renameLocations([r0, r2], [r0, r2, { range: r3, suffixText: ": primary" }]); verify.renameLocations([r1, r3, r4], [r1, { range: r3, prefixText: "primary: " }, r4]); From 01bbc4de2e8ec4641323fd90b77b784eed732056 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 3 Jun 2019 13:49:42 -0700 Subject: [PATCH 17/44] More tests --- tests/cases/fourslash/renameCrossJsTs01.ts | 6 +++--- tests/cases/fourslash/renameDefaultImport.ts | 11 +++++------ .../fourslash/renameDefaultImportDifferentName.ts | 9 ++++----- tests/cases/fourslash/renameDefaultLibDontWork.ts | 4 ++-- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/cases/fourslash/renameCrossJsTs01.ts b/tests/cases/fourslash/renameCrossJsTs01.ts index fbe0d4395cd..b4b3448d8c8 100644 --- a/tests/cases/fourslash/renameCrossJsTs01.ts +++ b/tests/cases/fourslash/renameCrossJsTs01.ts @@ -2,12 +2,12 @@ // @allowJs: true // @Filename: a.js -////exports.[|area|] = function (r) { return r * r; } +////[|exports.[|{| "declarationRangeIndex": 0 |}area|] = function (r) { return r * r; }|] // @Filename: b.ts -////import { [|area|] } from './a'; +////[|import { [|{| "declarationRangeIndex": 2 |}area|] } from './a';|] ////var t = [|area|](10); -const [r0, r1, r2] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2] = test.ranges(); verify.renameLocations(r0, [r0, r1, r2]); verify.renameLocations([r1, r2], [{ range: r1, prefixText: "area as " }, r2]); diff --git a/tests/cases/fourslash/renameDefaultImport.ts b/tests/cases/fourslash/renameDefaultImport.ts index a3a698ec4c4..9c2a2d67dc1 100644 --- a/tests/cases/fourslash/renameDefaultImport.ts +++ b/tests/cases/fourslash/renameDefaultImport.ts @@ -1,26 +1,25 @@ /// // @Filename: B.ts -////export default class /*1*/[|{| "isWriteAccess": true, "isDefinition": true |}B|] { +////[|export default class /*1*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}B|] { //// test() { //// } -////} +////}|] // @Filename: A.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}B|] from "./B"; +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}B|] from "./B";|] ////let b = new [|B|](); ////b.test(); goTo.marker("1"); verify.occurrencesAtPositionCount(1); -const ranges = test.ranges(); -const [C, B0, B1] = ranges; +const [CDef, C, B0Def, B0, B1] = test.ranges();; const classes = { definition: "class B", ranges: [C] }; const imports = { definition: "(alias) class B\nimport B", ranges: [B0, B1] }; verify.referenceGroups(C, [classes, imports]); verify.referenceGroups([B0, B1], [imports, classes]); -verify.renameLocations(C, ranges); +verify.renameLocations(C, [C, B0, B1]); verify.rangesAreRenameLocations([B0, B1]); diff --git a/tests/cases/fourslash/renameDefaultImportDifferentName.ts b/tests/cases/fourslash/renameDefaultImportDifferentName.ts index 11473ade501..8c05efe3add 100644 --- a/tests/cases/fourslash/renameDefaultImportDifferentName.ts +++ b/tests/cases/fourslash/renameDefaultImportDifferentName.ts @@ -1,21 +1,20 @@ /// // @Filename: B.ts -////export default class /*1*/[|{| "isWriteAccess": true, "isDefinition": true |}C|] { +////[|export default class /*1*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}C|] { //// test() { //// } -////} +////}|] // @Filename: A.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}B|] from "./B"; +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}B|] from "./B";|] ////let b = new [|B|](); ////b.test(); goTo.marker("1"); verify.occurrencesAtPositionCount(1); -const ranges = test.ranges(); -const [C, B0, B1] = ranges; +const [CDef, C, B0Def, B0, B1] = test.ranges(); const bRanges = [B0, B1]; const classes = { definition: "class C", ranges: [C] }; const imports = { definition: "(alias) class B\nimport B", ranges: [B0, B1] }; diff --git a/tests/cases/fourslash/renameDefaultLibDontWork.ts b/tests/cases/fourslash/renameDefaultLibDontWork.ts index 5d2cfb43eb4..02d7e1d19ea 100644 --- a/tests/cases/fourslash/renameDefaultLibDontWork.ts +++ b/tests/cases/fourslash/renameDefaultLibDontWork.ts @@ -4,8 +4,8 @@ // "test" is a comment on the default library. // @Filename: file1.ts -//// var [|test|] = "foo"; +//// [|var [|{| "declarationRangeIndex": 0 |}test|] = "foo";|] //// console.log([|test|]); -const ranges = test.ranges(); +const [r0Def, ...ranges] = test.ranges(); verify.renameLocations(ranges[0], { findInComments: true, ranges }); \ No newline at end of file From e41533acc700248ba3c6854549bcd443eae9bdf5 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 3 Jun 2019 14:06:30 -0700 Subject: [PATCH 18/44] Handle computed property names --- src/services/findAllReferences.ts | 13 ++++++---- .../renameContextuallyTypedProperties.ts | 24 +++++++++---------- .../renameContextuallyTypedProperties2.ts | 24 +++++++++---------- 3 files changed, 33 insertions(+), 28 deletions(-) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index c3a8cc15b08..8ef72440bcc 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -62,11 +62,16 @@ namespace ts.FindAllReferences { node.parent.parent.left === node.parent ? node.parent.parent : undefined; - return binaryExpression && getAssignmentDeclarationKind(binaryExpression) !== AssignmentDeclarationKind.None ? - getDeclarationForDeclarationSpan(binaryExpression) : - undefined; + if (binaryExpression && getAssignmentDeclarationKind(binaryExpression) !== AssignmentDeclarationKind.None) { + return getDeclarationForDeclarationSpan(binaryExpression); + } } - return undefined; + + // Handle computed property name + const propertyName = findAncestor(node, isComputedPropertyName); + return propertyName ? + getDeclarationForDeclarationSpan(propertyName.parent) : + undefined; } if (isConstructorDeclaration(node.parent) || diff --git a/tests/cases/fourslash/renameContextuallyTypedProperties.ts b/tests/cases/fourslash/renameContextuallyTypedProperties.ts index 4ce3c2b0738..118c53be2b7 100644 --- a/tests/cases/fourslash/renameContextuallyTypedProperties.ts +++ b/tests/cases/fourslash/renameContextuallyTypedProperties.ts @@ -1,58 +1,58 @@ /// ////interface I { -//// [|prop1|]: () => void; +//// [|[|{| "declarationRangeIndex": 0 |}prop1|]: () => void;|] //// prop2(): void; ////} //// ////var o1: I = { -//// [|prop1|]() { }, +//// [|[|{| "declarationRangeIndex": 2 |}prop1|]() { }|], //// prop2() { } ////}; //// ////var o2: I = { -//// [|prop1|]: () => { }, +//// [|[|{| "declarationRangeIndex": 4 |}prop1|]: () => { }|], //// prop2: () => { } ////}; //// ////var o3: I = { -//// get [|prop1|]() { return () => { }; }, +//// [|get [|{| "declarationRangeIndex": 6 |}prop1|]() { return () => { }; }|], //// get prop2() { return () => { }; } ////}; //// ////var o4: I = { -//// set [|prop1|](v) { }, +//// [|set [|{| "declarationRangeIndex": 8 |}prop1|](v) { }|], //// set prop2(v) { } ////}; //// ////var o5: I = { -//// "[|prop1|]"() { }, +//// [|"[|{| "declarationRangeIndex": 10 |}prop1|]"() { }|], //// "prop2"() { } ////}; //// ////var o6: I = { -//// "[|prop1|]": function () { }, +//// [|"[|{| "declarationRangeIndex": 12 |}prop1|]": function () { }|], //// "prop2": function () { } ////}; //// ////var o7: I = { -//// ["[|prop1|]"]: function () { }, +//// [|["[|{| "declarationRangeIndex": 14 |}prop1|]"]: function () { }|], //// ["prop2"]: function () { } ////}; //// ////var o8: I = { -//// ["[|prop1|]"]() { }, +//// [|["[|{| "declarationRangeIndex": 16 |}prop1|]"]() { }|], //// ["prop2"]() { } ////}; //// ////var o9: I = { -//// get ["[|prop1|]"]() { return () => { }; }, +//// [|get ["[|{| "declarationRangeIndex": 18 |}prop1|]"]() { return () => { }; }|], //// get ["prop2"]() { return () => { }; } ////}; //// ////var o10: I = { -//// set ["[|prop1|]"](v) { }, +//// [|set ["[|{| "declarationRangeIndex": 20 |}prop1|]"](v) { }|], //// set ["prop2"](v) { } ////}; -verify.rangesAreRenameLocations(); +verify.rangesAreRenameLocations(test.rangesByText().get("prop1")); diff --git a/tests/cases/fourslash/renameContextuallyTypedProperties2.ts b/tests/cases/fourslash/renameContextuallyTypedProperties2.ts index 01e638395a0..5439a2215d2 100644 --- a/tests/cases/fourslash/renameContextuallyTypedProperties2.ts +++ b/tests/cases/fourslash/renameContextuallyTypedProperties2.ts @@ -2,57 +2,57 @@ ////interface I { //// prop1: () => void; -//// [|prop2|](): void; +//// [|[|{| "declarationRangeIndex": 0 |}prop2|](): void;|] ////} //// ////var o1: I = { //// prop1() { }, -//// [|prop2|]() { } +//// [|[|{| "declarationRangeIndex": 2 |}prop2|]() { }|] ////}; //// ////var o2: I = { //// prop1: () => { }, -//// [|prop2|]: () => { } +//// [|[|{| "declarationRangeIndex": 4 |}prop2|]: () => { }|] ////}; //// ////var o3: I = { //// get prop1() { return () => { }; }, -//// get [|prop2|]() { return () => { }; } +//// [|get [|{| "declarationRangeIndex": 6 |}prop2|]() { return () => { }; }|] ////}; //// ////var o4: I = { //// set prop1(v) { }, -//// set [|prop2|](v) { } +//// [|set [|{| "declarationRangeIndex": 8 |}prop2|](v) { }|] ////}; //// ////var o5: I = { //// "prop1"() { }, -//// "[|prop2|]"() { } +//// [|"[|{| "declarationRangeIndex": 10 |}prop2|]"() { }|] ////}; //// ////var o6: I = { //// "prop1": function () { }, -//// "[|prop2|]": function () { } +//// [|"[|{| "declarationRangeIndex": 12 |}prop2|]": function () { }|] ////}; //// ////var o7: I = { //// ["prop1"]: function () { }, -//// ["[|prop2|]"]: function () { } +//// [|["[|{| "declarationRangeIndex": 14 |}prop2|]"]: function () { }|] ////}; //// ////var o8: I = { //// ["prop1"]() { }, -//// ["[|prop2|]"]() { } +//// [|["[|{| "declarationRangeIndex": 16 |}prop2|]"]() { }|] ////}; //// ////var o9: I = { //// get ["prop1"]() { return () => { }; }, -//// get ["[|prop2|]"]() { return () => { }; } +//// [|get ["[|{| "declarationRangeIndex": 18 |}prop2|]"]() { return () => { }; }|] ////}; //// ////var o10: I = { //// set ["prop1"](v) { }, -//// set ["[|prop2|]"](v) { } +//// [|set ["[|{| "declarationRangeIndex": 20 |}prop2|]"](v) { }|] ////}; -verify.rangesAreRenameLocations(); +verify.rangesAreRenameLocations(test.rangesByText().get("prop2")); From 34624a0587e34696ea8702a4697677e5ff3e9039 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Mon, 3 Jun 2019 14:13:47 -0700 Subject: [PATCH 19/44] More Tests --- tests/cases/fourslash/localGetReferences.ts | 42 +++++++++++++++---- tests/cases/fourslash/referenceToClass.ts | 7 ++-- .../cases/fourslash/referencesBloomFilters.ts | 6 +-- .../fourslash/referencesBloomFilters2.ts | 6 +-- .../fourslash/referencesBloomFilters3.ts | 4 +- .../cases/fourslash/referencesForAmbients.ts | 14 +++---- .../cases/fourslash/referencesForAmbients2.ts | 4 +- .../fourslash/referencesForClassLocal.ts | 4 +- .../fourslash/referencesForClassMembers.ts | 8 ++-- ...esForClassMembersExtendingAbstractClass.ts | 8 ++-- ...cesForClassMembersExtendingGenericClass.ts | 8 ++-- .../fourslash/referencesForClassParameter.ts | 4 +- ...ontextuallyTypedObjectLiteralProperties.ts | 18 ++++---- ...ncesForContextuallyTypedUnionProperties.ts | 20 ++++----- ...cesForContextuallyTypedUnionProperties2.ts | 16 +++---- tests/cases/fourslash/referencesForEnums.ts | 6 +-- .../fourslash/referencesForExportedValues.ts | 4 +- .../referencesForExternalModuleNames.ts | 6 +-- .../referencesForFunctionOverloads.ts | 8 ++-- .../referencesForFunctionParameter.ts | 4 +- tests/cases/fourslash/referencesForGlobals.ts | 4 +- .../cases/fourslash/referencesForGlobals2.ts | 6 +-- .../cases/fourslash/referencesForGlobals3.ts | 6 +-- .../cases/fourslash/referencesForGlobals4.ts | 6 +-- .../cases/fourslash/referencesForGlobals5.ts | 4 +- .../referencesForGlobalsInExternalModule.ts | 10 ++--- .../referencesForIllegalAssignment.ts | 4 +- tests/cases/fourslash/referencesForImports.ts | 6 +-- .../fourslash/referencesForIndexProperty.ts | 4 +- .../fourslash/referencesForIndexProperty3.ts | 4 +- .../referencesForInheritedProperties.ts | 13 +++--- .../referencesForInheritedProperties2.ts | 13 +++--- .../referencesForInheritedProperties3.ts | 4 +- .../referencesForInheritedProperties4.ts | 4 +- .../referencesForInheritedProperties5.ts | 8 ++-- .../referencesForInheritedProperties6.ts | 9 ++-- .../referencesForInheritedProperties7.ts | 14 +++---- .../referencesForInheritedProperties8.ts | 8 ++-- .../referencesForInheritedProperties9.ts | 6 +-- .../referencesForMergedDeclarations.ts | 14 +++---- .../referencesForMergedDeclarations2.ts | 4 +- .../referencesForMergedDeclarations3.ts | 10 ++--- .../referencesForMergedDeclarations4.ts | 10 ++--- .../referencesForMergedDeclarations5.ts | 12 +++--- .../referencesForMergedDeclarations6.ts | 6 +-- .../referencesForMergedDeclarations7.ts | 10 ++--- .../referencesForMergedDeclarations8.ts | 4 +- ...eferencesForNumericLiteralPropertyNames.ts | 8 ++-- .../referencesForObjectLiteralProperties.ts | 5 ++- .../cases/fourslash/referencesForOverrides.ts | 34 +++++++-------- .../referencesForPropertiesOfGenericType.ts | 5 ++- tests/cases/fourslash/referencesForStatic.ts | 5 ++- ...rencesForStaticsAndMembersWithSameNames.ts | 14 +++---- ...referencesForStringLiteralPropertyNames.ts | 8 ++-- ...eferencesForStringLiteralPropertyNames2.ts | 4 +- ...eferencesForStringLiteralPropertyNames3.ts | 7 ++-- ...eferencesForStringLiteralPropertyNames4.ts | 4 +- ...eferencesForStringLiteralPropertyNames5.ts | 4 +- ...eferencesForStringLiteralPropertyNames7.ts | 10 ++--- .../fourslash/referencesForUnionProperties.ts | 8 ++-- tests/cases/fourslash/remoteGetReferences.ts | 30 ++++++++++--- .../fourslash/renameAcrossMultipleProjects.ts | 5 ++- tests/cases/fourslash/renameAlias.ts | 5 ++- tests/cases/fourslash/renameAlias2.ts | 5 ++- tests/cases/fourslash/renameAlias3.ts | 5 ++- .../fourslash/renameAliasExternalModule.ts | 5 ++- .../fourslash/renameAliasExternalModule2.ts | 8 ++-- .../fourslash/renameAliasExternalModule3.ts | 5 ++- .../fourslash/renameCommentsAndStrings1.ts | 7 ++-- .../fourslash/renameCommentsAndStrings2.ts | 6 +-- .../fourslash/renameCommentsAndStrings3.ts | 6 +-- .../fourslash/renameCommentsAndStrings4.ts | 6 +-- 72 files changed, 331 insertions(+), 278 deletions(-) diff --git a/tests/cases/fourslash/localGetReferences.ts b/tests/cases/fourslash/localGetReferences.ts index a434a6b0820..401599368af 100644 --- a/tests/cases/fourslash/localGetReferences.ts +++ b/tests/cases/fourslash/localGetReferences.ts @@ -3,15 +3,15 @@ // @Filename: localGetReferences_1.ts ////// Comment Refence Test: g/*1*/lobalVar ////// References to a variable declared in global. -////var [|{| "isWriteAccess": true, "isDefinition": true |}globalVar|]: number = 2; +////[|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}globalVar|]: number = 2;|] //// ////class fooCls { //// // References to static variable declared in a class. -//// static [|{| "isWriteAccess": true, "isDefinition": true |}clsSVar|] = 1; +//// [|static [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}clsSVar|] = 1;|] //// // References to a variable declared in a class. -//// [|{| "isWriteAccess": true, "isDefinition": true |}clsVar|] = 1; +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}clsVar|] = 1;|] //// -//// constructor (public [|{| "isWriteAccess": true, "isDefinition": true |}clsParam|]: number) { +//// constructor ([|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}clsParam|]: number|]) { //// //Increments //// [|{| "isWriteAccess": true |}globalVar|]++; //// this.[|{| "isWriteAccess": true |}clsVar|]++; @@ -23,9 +23,9 @@ ////} //// ////// References to a function parameter. -////function [|{| "isWriteAccess": true, "isDefinition": true |}foo|]([|{| "isWriteAccess": true, "isDefinition": true |}x|]: number) { +////[|function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 12 |}foo|]([|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 14 |}x|]: number|]) { //// // References to a variable declared in a function. -//// var [|{| "isWriteAccess": true, "isDefinition": true |}fnVar|] = 1; +//// [|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 16 |}fnVar|] = 1;|] //// //// //Increments //// fooCls.[|{| "isWriteAccess": true |}clsSVar|]++; @@ -35,7 +35,7 @@ //// //// //Return //// return [|{| "isWriteAccess": true |}x|]++; -////} +////}|] //// ////module modTest { //// //Declare @@ -85,7 +85,7 @@ /////*3*/err = err++; /////*4*/ //////Shadowed fn Parameter -////function shdw([|{| "isWriteAccess": true, "isDefinition": true, "shadow": true |}globalVar|]: number) { +////function shdw([|[|{| "isWriteAccess": true, "isDefinition": true, "shadow": true, "declarationRangeIndex": 39 |}globalVar|]: number|]) { //// //Increments //// [|{| "isWriteAccess": true, "shadow": true |}globalVar|]++; //// return [|{| "shadow": true |}globalVar|]; @@ -117,7 +117,7 @@ ////array.forEach( //// //// -////function([|{| "isWriteAccess": true, "isDefinition": true |}str|]) { +////function([|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 43 |}str|]) { //// //// //// @@ -198,6 +198,30 @@ goTo.marker("4"); verify.noReferences(); test.rangesByText().forEach((ranges, text) => { + switch (text) { + case "var globalVar: number = 2;": + case "static clsSVar = 1;": + case "clsVar = 1;": + case "public clsParam: number": + case `function foo(x: number) { + // References to a variable declared in a function. + var fnVar = 1; + + //Increments + fooCls.clsSVar++; + globalVar++; + modTest.modVar++; + fnVar++; + + //Return + return x++; +}`: + case "x: number": + case "var fnVar = 1;": + case "globalVar: number": + return; + } + if (text === "globalVar") { verify.singleReferenceGroup("(parameter) globalVar: number", ranges.filter(isShadow)); verify.singleReferenceGroup("var globalVar: number", ranges.filter(r => !isShadow(r))); diff --git a/tests/cases/fourslash/referenceToClass.ts b/tests/cases/fourslash/referenceToClass.ts index d74f24703d2..c1623313d84 100644 --- a/tests/cases/fourslash/referenceToClass.ts +++ b/tests/cases/fourslash/referenceToClass.ts @@ -3,10 +3,10 @@ // Class references should work across file and not find local variables. // @Filename: referenceToClass_1.ts -////class [|{| "isWriteAccess": true, "isDefinition": true |}foo|] { +////[|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|] { //// public n: [|foo|]; //// public foo: number; -////} +////}|] //// ////class bar { //// public n: [|foo|]; @@ -20,4 +20,5 @@ // @Filename: referenceToClass_2.ts ////var k: [|foo|]; -verify.singleReferenceGroup("class foo"); +const [rDef, ...ranges] = test.ranges(); +verify.singleReferenceGroup("class foo", ranges); diff --git a/tests/cases/fourslash/referencesBloomFilters.ts b/tests/cases/fourslash/referencesBloomFilters.ts index 1b96ef6f1c9..908339d6dce 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 = { [|{| "isWriteAccess": true, "isDefinition": true |}searchProp|] : 1 }; +////var container = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}searchProp|] : 1|] }; // @Filename: expression.ts ////function blah() { return (1 + 2 + container.[|searchProp|]()) === 2; }; @@ -12,6 +12,6 @@ ////function blah2() { container["[|searchProp|]"] }; // @Filename: redeclaration.ts -////container = { "[|{| "isWriteAccess": true, "isDefinition": true |}searchProp|]" : 18 }; +////container = { [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}searchProp|]" : 18|] }; -verify.singleReferenceGroup("(property) searchProp: number"); +verify.singleReferenceGroup("(property) searchProp: number", test.rangesByText().get("searchProp")); diff --git a/tests/cases/fourslash/referencesBloomFilters2.ts b/tests/cases/fourslash/referencesBloomFilters2.ts index 6f1dfa16e80..36890b2b87c 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 = { [|{| "isWriteAccess": true, "isDefinition": true |}42|]: 1 }; +////var container = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}42|]: 1|] }; // @Filename: expression.ts ////function blah() { return (container[[|42|]]) === 2; }; @@ -12,6 +12,6 @@ ////function blah2() { container["[|42|]"] }; // @Filename: redeclaration.ts -////container = { "[|{| "isWriteAccess": true, "isDefinition": true |}42|]" : 18 }; +////container = { [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}42|]" : 18|] }; -verify.singleReferenceGroup("(property) 42: number"); +verify.singleReferenceGroup("(property) 42: number", test.rangesByText().get("42")); diff --git a/tests/cases/fourslash/referencesBloomFilters3.ts b/tests/cases/fourslash/referencesBloomFilters3.ts index d7d335cde02..9d871047e86 100644 --- a/tests/cases/fourslash/referencesBloomFilters3.ts +++ b/tests/cases/fourslash/referencesBloomFilters3.ts @@ -4,9 +4,9 @@ // @Filename: declaration.ts -////enum Test { "[|{| "isWriteAccess": true, "isDefinition": true |}42|]" = 1 }; +////enum Test { [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}42|]" = 1|] }; // @Filename: expression.ts ////(Test[[|42|]]); -verify.singleReferenceGroup('(enum member) Test["42"] = 1'); +verify.singleReferenceGroup('(enum member) Test["42"] = 1', test.rangesByText().get("42")); diff --git a/tests/cases/fourslash/referencesForAmbients.ts b/tests/cases/fourslash/referencesForAmbients.ts index 89036befce3..77ff23cab98 100644 --- a/tests/cases/fourslash/referencesForAmbients.ts +++ b/tests/cases/fourslash/referencesForAmbients.ts @@ -1,20 +1,20 @@ /// -////declare module "[|{| "isWriteAccess": true, "isDefinition": true |}foo|]" { -//// var [|{| "isWriteAccess": true, "isDefinition": true |}f|]: number; -////} +////[|declare module "[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|]" { +//// [|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}f|]: number;|] +////}|] //// -////declare module "[|{| "isWriteAccess": true, "isDefinition": true |}bar|]" { -//// export import [|{| "isWriteAccess": true, "isDefinition": true |}foo|] = require("[|foo|]"); +////[|declare module "[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}bar|]" { +//// [|export import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}foo|] = require("[|foo|]");|] //// var f2: typeof [|foo|].[|f|]; -////} +////}|] //// ////declare module "baz" { //// import bar = require("[|bar|]"); //// var f2: typeof bar.[|foo|]; ////} -const [moduleFoo0, f0, moduleBar0, foo0, moduleFoo1, foo1, f1, moduleBar1, foo2] = test.ranges(); +const [moduleFoo0Def, moduleFoo0, f0Def, f0, moduleBar0Def, moduleBar0, foo0Def, foo0, moduleFoo1, foo1, f1, moduleBar1, foo2] = test.ranges(); verify.singleReferenceGroup('module "foo"', [moduleFoo0, moduleFoo1]); verify.singleReferenceGroup('module "bar"', [moduleBar0, moduleBar1]); verify.singleReferenceGroup('(alias) module "foo"\nimport foo = require("foo")', [foo0, foo1, foo2]); diff --git a/tests/cases/fourslash/referencesForAmbients2.ts b/tests/cases/fourslash/referencesForAmbients2.ts index 8654d90f854..3ec5b88a0a6 100644 --- a/tests/cases/fourslash/referencesForAmbients2.ts +++ b/tests/cases/fourslash/referencesForAmbients2.ts @@ -2,7 +2,7 @@ // @Filename: /defA.ts ////declare module "a" { -//// export type [|{| "isWriteAccess": true, "isDefinition": true |}T|] = number; +//// [|export type [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}T|] = number;|] ////} // @Filename: /defB.ts @@ -18,4 +18,4 @@ ////} verify.noErrors(); -verify.singleReferenceGroup("type T = number"); +verify.singleReferenceGroup("type T = number", test.rangesByText().get("T")); diff --git a/tests/cases/fourslash/referencesForClassLocal.ts b/tests/cases/fourslash/referencesForClassLocal.ts index 9e2576413f2..6897f069245 100644 --- a/tests/cases/fourslash/referencesForClassLocal.ts +++ b/tests/cases/fourslash/referencesForClassLocal.ts @@ -5,7 +5,7 @@ ////var n = 14; //// ////class foo { -//// private [|{| "isWriteAccess": true, "isDefinition": true |}n|] = 0; +//// [|private [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}n|] = 0;|] //// //// public bar() { //// this.[|{| "isWriteAccess": true |}n|] = 9; @@ -20,4 +20,4 @@ //// } ////} -verify.singleReferenceGroup("(property) foo.n: number"); +verify.singleReferenceGroup("(property) foo.n: number", test.rangesByText().get("n")); diff --git a/tests/cases/fourslash/referencesForClassMembers.ts b/tests/cases/fourslash/referencesForClassMembers.ts index e60c03524a1..bdee20544d7 100644 --- a/tests/cases/fourslash/referencesForClassMembers.ts +++ b/tests/cases/fourslash/referencesForClassMembers.ts @@ -1,12 +1,12 @@ /// ////class Base { -//// [|{| "isDefinition": true |}a|]: number; -//// [|{| "isWriteAccess": true, "isDefinition": true |}method|](): void { } +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}a|]: number;|] +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}method|](): void { }|] ////} ////class MyClass extends Base { -//// [|{| "isDefinition": true |}a|]; -//// [|{| "isWriteAccess": true, "isDefinition": true |}method|]() { } +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 4 |}a|];|] +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}method|]() { }|] ////} //// ////var c: MyClass; diff --git a/tests/cases/fourslash/referencesForClassMembersExtendingAbstractClass.ts b/tests/cases/fourslash/referencesForClassMembersExtendingAbstractClass.ts index 12df996629d..95405ccb0c4 100644 --- a/tests/cases/fourslash/referencesForClassMembersExtendingAbstractClass.ts +++ b/tests/cases/fourslash/referencesForClassMembersExtendingAbstractClass.ts @@ -1,12 +1,12 @@ /// ////abstract class Base { -//// abstract [|{| "isDefinition": true |}a|]: number; -//// abstract [|{| "isDefinition": true |}method|](): void; +//// [|abstract [|{| "isDefinition": true, "declarationRangeIndex": 0 |}a|]: number;|] +//// [|abstract [|{| "isDefinition": true, "declarationRangeIndex": 2 |}method|](): void;|] ////} ////class MyClass extends Base { -//// [|{| "isDefinition": true |}a|]; -//// [|{| "isWriteAccess": true, "isDefinition": true |}method|]() { } +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 4 |}a|];|] +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}method|]() { }|] ////} //// ////var c: MyClass; diff --git a/tests/cases/fourslash/referencesForClassMembersExtendingGenericClass.ts b/tests/cases/fourslash/referencesForClassMembersExtendingGenericClass.ts index 103b66ff74b..bfa6b8d6fb5 100644 --- a/tests/cases/fourslash/referencesForClassMembersExtendingGenericClass.ts +++ b/tests/cases/fourslash/referencesForClassMembersExtendingGenericClass.ts @@ -1,12 +1,12 @@ /// ////class Base { -//// [|{| "isDefinition": true |}a|]: this; -//// [|{| "isWriteAccess": true, "isDefinition": true |}method|](a?:T, b?:U): this { } +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}a|]: this;|] +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}method|](a?:T, b?:U): this { }|] ////} ////class MyClass extends Base { -//// [|{| "isDefinition": true |}a|]; -//// [|{| "isWriteAccess": true, "isDefinition": true |}method|]() { } +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 4 |}a|];|] +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}method|]() { }|] ////} //// ////var c: MyClass; diff --git a/tests/cases/fourslash/referencesForClassParameter.ts b/tests/cases/fourslash/referencesForClassParameter.ts index ec1e1bb2f0e..53cfba57c14 100644 --- a/tests/cases/fourslash/referencesForClassParameter.ts +++ b/tests/cases/fourslash/referencesForClassParameter.ts @@ -7,7 +7,7 @@ ////class p { } //// ////class foo { -//// constructor (public [|{| "isWriteAccess": true, "isDefinition": true |}p|]: any) { +//// constructor ([|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}p|]: any|]) { //// } //// //// public f(p) { @@ -19,4 +19,4 @@ ////var n = new foo(undefined); ////n.[|{| "isWriteAccess": true |}p|] = null; -verify.singleReferenceGroup("(property) foo.p: any"); +verify.singleReferenceGroup("(property) foo.p: any", test.rangesByText().get("p")); diff --git a/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts b/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts index 67f09a9dcd1..9c510e4a097 100644 --- a/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts +++ b/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts @@ -1,28 +1,28 @@ /// -////interface IFoo { [|{| "isDefinition": true |}xy|]: number; } +////interface IFoo { [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}xy|]: number;|] } //// ////// Assignment -////var a1: IFoo = { [|{| "isWriteAccess": true, "isDefinition": true |}xy|]: 0 }; -////var a2: IFoo = { [|{| "isWriteAccess": true, "isDefinition": true |}xy|]: 0 }; +////var a1: IFoo = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}xy|]: 0|] }; +////var a2: IFoo = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}xy|]: 0|] }; //// ////// Function call ////function consumer(f: IFoo) { } -////consumer({ [|{| "isWriteAccess": true, "isDefinition": true |}xy|]: 1 }); +////consumer({ [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}xy|]: 1|] }); //// ////// Type cast -////var c = { [|{| "isWriteAccess": true, "isDefinition": true |}xy|]: 0 }; +////var c = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 8 |}xy|]: 0|] }; //// ////// Array literal -////var ar: IFoo[] = [{ [|{| "isWriteAccess": true, "isDefinition": true |}xy|]: 1 }, { [|{| "isWriteAccess": true, "isDefinition": true |}xy|]: 2 }]; +////var ar: IFoo[] = [{ [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 10 |}xy|]: 1|] }, { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 12 |}xy|]: 2|] }]; //// ////// Nested object literal -////var ob: { ifoo: IFoo } = { ifoo: { [|{| "isWriteAccess": true, "isDefinition": true |}xy|]: 0 } }; +////var ob: { ifoo: IFoo } = { ifoo: { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 14 |}xy|]: 0|] } }; //// ////// Widened type -////var w: IFoo = { [|{| "isWriteAccess": true, "isDefinition": true, "type": "undefined" |}xy|]: undefined }; +////var w: IFoo = { [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "undefined", "declarationRangeIndex": 16 |}xy|]: undefined|] }; //// ////// Untped -- should not be included ////var u = { xy: 0 }; -verify.singleReferenceGroup("(property) IFoo.xy: number"); +verify.singleReferenceGroup("(property) IFoo.xy: number", test.rangesByText().get("xy")); diff --git a/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts index b0bb5d62b4d..da1adb8f98d 100644 --- a/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts +++ b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties.ts @@ -2,39 +2,39 @@ ////interface A { //// a: number; -//// [|{| "isDefinition": true |}common|]: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}common|]: string;|] ////} //// ////interface B { //// b: number; -//// [|{| "isDefinition": true |}common|]: number; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}common|]: number;|] ////} //// ////// Assignment -////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 }; +////var v1: A | B = { a: 0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "string", "declarationRangeIndex": 4 |}common|]: ""|] }; +////var v2: A | B = { b: 0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "declarationRangeIndex": 6 |}common|]: 3|] }; //// ////// Function call ////function consumer(f: A | B) { } -////consumer({ a: 0, b: 0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}common|]: 1 }); +////consumer({ a: 0, b: 0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "declarationRangeIndex": 8 |}common|]: 1|] }); //// ////// Type cast -////var c = { [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}common|]: 0, b: 0 }; +////var c = { [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "declarationRangeIndex": 10 |}common|]: 0|], b: 0 }; //// ////// Array literal -////var ar: Array = [{ a: 0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "string" |}common|]: "" }, { b: 0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}common|]: 0 }]; +////var ar: Array = [{ a: 0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "string", "declarationRangeIndex": 12 |}common|]: ""|] }, { b: 0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "declarationRangeIndex": 14 |}common|]: 0|] }]; //// ////// Nested object literal -////var ob: { aorb: A|B } = { aorb: { b: 0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}common|]: 0 } }; +////var ob: { aorb: A|B } = { aorb: { b: 0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "declarationRangeIndex": 16 |}common|]: 0|] } }; //// ////// Widened type -////var w: A|B = { a:0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "undefined" |}common|]: undefined }; +////var w: A|B = { a:0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "undefined", "declarationRangeIndex": 18 |}common|]: undefined|] }; //// ////// Untped -- should not be included ////var u1 = { a: 0, b: 0, common: "" }; ////var u2 = { b: 0, common: 0 }; -const [aCommon, bCommon, ...unionRefs] = test.ranges(); +const [aCommon, bCommon, ...unionRefs] = test.rangesByText().get("common"); verify.referenceGroups(aCommon, [ { definition: "(property) A.common: string", ranges: [aCommon] }, { definition: "(property) common: string | number", ranges: unionRefs }, diff --git a/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts index a9741d3e39d..850561acf5c 100644 --- a/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts +++ b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts @@ -6,32 +6,32 @@ ////} //// ////interface B { -//// [|{| "isDefinition": true |}b|]: number; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}b|]: number;|] //// common: number; ////} //// ////// Assignment ////var v1: A | B = { a: 0, common: "" }; -////var v2: A | B = { [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}b|]: 0, common: 3 }; +////var v2: A | B = { [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "declarationRangeIndex": 2 |}b|]: 0|], common: 3 }; //// ////// Function call ////function consumer(f: A | B) { } -////consumer({ a: 0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}b|]: 0, common: 1 }); +////consumer({ a: 0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "declarationRangeIndex": 4 |}b|]: 0|], common: 1 }); //// ////// Type cast -////var c = { common: 0, [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}b|]: 0 }; +////var c = { common: 0, [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "declarationRangeIndex": 6 |}b|]: 0|] }; //// ////// Array literal -////var ar: Array = [{ a: 0, common: "" }, { [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}b|]: 0, common: 0 }]; +////var ar: Array = [{ a: 0, common: "" }, { [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "declarationRangeIndex": 8 |}b|]: 0|], common: 0 }]; //// ////// Nested object literal -////var ob: { aorb: A|B } = { aorb: { [|{| "isWriteAccess": true, "isDefinition": true, "type": "number" |}b|]: 0, common: 0 } }; +////var ob: { aorb: A|B } = { aorb: { [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "declarationRangeIndex": 10 |}b|]: 0|], common: 0 } }; //// ////// Widened type -////var w: A|B = { [|{| "isWriteAccess": true, "isDefinition": true, "type": "undefined" |}b|]:undefined, common: undefined }; +////var w: A|B = { [|[|{| "isWriteAccess": true, "isDefinition": true, "type": "undefined", "declarationRangeIndex": 12 |}b|]:undefined|], common: undefined }; //// ////// Untped -- should not be included ////var u1 = { a: 0, b: 0, common: "" }; ////var u2 = { b: 0, common: 0 }; -verify.singleReferenceGroup("(property) B.b: number"); +verify.singleReferenceGroup("(property) B.b: number", test.rangesByText().get("b")); diff --git a/tests/cases/fourslash/referencesForEnums.ts b/tests/cases/fourslash/referencesForEnums.ts index af4fec8aae8..2b948613704 100644 --- a/tests/cases/fourslash/referencesForEnums.ts +++ b/tests/cases/fourslash/referencesForEnums.ts @@ -1,9 +1,9 @@ /// ////enum E { -//// [|{| "isWriteAccess": true, "isDefinition": true |}value1|] = 1, -//// "[|{| "isWriteAccess": true, "isDefinition": true |}value2|]" = [|value1|], -//// [|{| "isWriteAccess": true, "isDefinition": true |}111|] = 11 +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}value1|] = 1|], +//// [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}value2|]" = [|value1|]|], +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}111|] = 11|] ////} //// ////E.[|value1|]; diff --git a/tests/cases/fourslash/referencesForExportedValues.ts b/tests/cases/fourslash/referencesForExportedValues.ts index ff00f844260..787440606fd 100644 --- a/tests/cases/fourslash/referencesForExportedValues.ts +++ b/tests/cases/fourslash/referencesForExportedValues.ts @@ -1,7 +1,7 @@ /// ////module M { -//// export var [|{| "isWriteAccess": true, "isDefinition": true |}variable|] = 0; +//// [|export var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}variable|] = 0;|] //// //// // local use //// var x = [|variable|]; @@ -10,4 +10,4 @@ ////// external use ////M.[|variable|] -verify.singleReferenceGroup("var M.variable: number"); +verify.singleReferenceGroup("var M.variable: number", test.rangesByText().get("variable")); diff --git a/tests/cases/fourslash/referencesForExternalModuleNames.ts b/tests/cases/fourslash/referencesForExternalModuleNames.ts index 90db189e04a..2929391228e 100644 --- a/tests/cases/fourslash/referencesForExternalModuleNames.ts +++ b/tests/cases/fourslash/referencesForExternalModuleNames.ts @@ -1,11 +1,11 @@ /// // @Filename: referencesForGlobals_1.ts -////declare module "[|{| "isWriteAccess": true, "isDefinition": true |}foo|]" { +////[|declare module "[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|]" { //// var f: number; -////} +////}|] // @Filename: referencesForGlobals_2.ts ////import f = require("[|foo|]"); -verify.singleReferenceGroup('module "foo"'); +verify.singleReferenceGroup('module "foo"', test.rangesByText().get("foo")); diff --git a/tests/cases/fourslash/referencesForFunctionOverloads.ts b/tests/cases/fourslash/referencesForFunctionOverloads.ts index 2a1ea032e20..b086014a050 100644 --- a/tests/cases/fourslash/referencesForFunctionOverloads.ts +++ b/tests/cases/fourslash/referencesForFunctionOverloads.ts @@ -2,9 +2,9 @@ // Function overloads should be highlighted together. -////function [|{| "isDefinition": true |}foo|](x: string); -////function [|{| "isWriteAccess": true, "isDefinition": true |}foo|](x: string, y: number) { +////[|function [|{| "isDefinition": true, "declarationRangeIndex": 0 |}foo|](x: string);|] +////[|function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}foo|](x: string, y: number) { //// [|foo|]('', 43); -////} +////}|] -verify.singleReferenceGroup("function foo(x: string): any"); +verify.singleReferenceGroup("function foo(x: string): any", test.rangesByText().get("foo")); diff --git a/tests/cases/fourslash/referencesForFunctionParameter.ts b/tests/cases/fourslash/referencesForFunctionParameter.ts index 24582a68e08..267965e7044 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, [|{| "isWriteAccess": true, "isDefinition": true |}n|]: number) { +////function n(x: number, [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}n|]: number|]) { //// [|{| "isWriteAccess": true |}n|] = 32; //// x = [|n|]; ////} -verify.singleReferenceGroup("(parameter) n: number"); +verify.singleReferenceGroup("(parameter) n: number", test.rangesByText().get("n")); diff --git a/tests/cases/fourslash/referencesForGlobals.ts b/tests/cases/fourslash/referencesForGlobals.ts index dc5bc4deb6f..43cac1876be 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 [|{| "isWriteAccess": true, "isDefinition": true |}global|] = 2; +////[|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}global|] = 2;|] //// ////class foo { //// constructor (public global) { } @@ -25,4 +25,4 @@ // @Filename: referencesForGlobals_2.ts ////var m = [|global|]; -verify.singleReferenceGroup("var global: number"); +verify.singleReferenceGroup("var global: number", test.rangesByText().get("global")); diff --git a/tests/cases/fourslash/referencesForGlobals2.ts b/tests/cases/fourslash/referencesForGlobals2.ts index e08be585c7a..d2b5c093f50 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 [|{| "isWriteAccess": true, "isDefinition": true |}globalClass|] { +////[|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}globalClass|] { //// public f() { } -////} +////}|] // @Filename: referencesForGlobals_2.ts ////var c = [|globalClass|](); -verify.singleReferenceGroup("class globalClass"); +verify.singleReferenceGroup("class globalClass", test.rangesByText().get("globalClass")); diff --git a/tests/cases/fourslash/referencesForGlobals3.ts b/tests/cases/fourslash/referencesForGlobals3.ts index 38edddc8255..5ade69a8841 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 [|{| "isWriteAccess": true, "isDefinition": true |}globalInterface|] { +////[|interface [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}globalInterface|] { //// f(); -////} +////}|] // @Filename: referencesForGlobals_2.ts ////var i: [|globalInterface|]; -verify.singleReferenceGroup("interface globalInterface"); +verify.singleReferenceGroup("interface globalInterface", test.rangesByText().get("globalInterface")); diff --git a/tests/cases/fourslash/referencesForGlobals4.ts b/tests/cases/fourslash/referencesForGlobals4.ts index b8356461699..cba70e1f441 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 [|{| "isWriteAccess": true, "isDefinition": true |}globalModule|] { +////[|module [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}globalModule|] { //// export f() { }; -////} +////}|] // @Filename: referencesForGlobals_2.ts ////var m = [|globalModule|]; -verify.singleReferenceGroup("namespace globalModule"); +verify.singleReferenceGroup("namespace globalModule", test.rangesByText().get("globalModule")); diff --git a/tests/cases/fourslash/referencesForGlobals5.ts b/tests/cases/fourslash/referencesForGlobals5.ts index 0d205b4b9b2..34a46148d8a 100644 --- a/tests/cases/fourslash/referencesForGlobals5.ts +++ b/tests/cases/fourslash/referencesForGlobals5.ts @@ -7,9 +7,9 @@ //// export var x; ////} //// -////import [|{| "isWriteAccess": true, "isDefinition": true |}globalAlias|] = globalModule; +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}globalAlias|] = globalModule;|] // @Filename: referencesForGlobals_2.ts ////var m = [|globalAlias|]; -verify.singleReferenceGroup("(alias) namespace globalAlias\nimport globalAlias = globalModule"); +verify.singleReferenceGroup("(alias) namespace globalAlias\nimport globalAlias = globalModule", test.rangesByText().get("globalAlias")); diff --git a/tests/cases/fourslash/referencesForGlobalsInExternalModule.ts b/tests/cases/fourslash/referencesForGlobalsInExternalModule.ts index 7bfbb0ff881..f4b9d07117c 100644 --- a/tests/cases/fourslash/referencesForGlobalsInExternalModule.ts +++ b/tests/cases/fourslash/referencesForGlobalsInExternalModule.ts @@ -2,18 +2,18 @@ // Global variable reference. -////var [|{| "isWriteAccess": true, "isDefinition": true |}topLevelVar|] = 2; +////[|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}topLevelVar|] = 2;|] ////var topLevelVar2 = [|topLevelVar|]; //// -////class [|{| "isWriteAccess": true, "isDefinition": true |}topLevelClass|] { } +////[|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}topLevelClass|] { }|] ////var c = new [|topLevelClass|](); //// -////interface [|{| "isWriteAccess": true, "isDefinition": true |}topLevelInterface|] { } +////[|interface [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}topLevelInterface|] { }|] ////var i: [|topLevelInterface|]; //// -////module [|{| "isWriteAccess": true, "isDefinition": true |}topLevelModule|] { +////[|module [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 9 |}topLevelModule|] { //// export var x; -////} +////}|] ////var x = [|topLevelModule|].x; //// ////export = x; diff --git a/tests/cases/fourslash/referencesForIllegalAssignment.ts b/tests/cases/fourslash/referencesForIllegalAssignment.ts index f65cd5bf1a6..a0c0a610bc5 100644 --- a/tests/cases/fourslash/referencesForIllegalAssignment.ts +++ b/tests/cases/fourslash/referencesForIllegalAssignment.ts @@ -2,7 +2,7 @@ ////f/*1*/oo = fo/*2*/o; -////var [|{| "isWriteAccess": true, "isDefinition": true |}bar|] = function () { }; +////[|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}bar|] = function () { };|] ////[|{| "isWriteAccess": true |}bar|] = [|bar|] + 1; goTo.marker("1"); @@ -11,4 +11,4 @@ verify.noReferences(); goTo.marker("2"); verify.noReferences(); -verify.singleReferenceGroup("var bar: () => void"); +verify.singleReferenceGroup("var bar: () => void", test.rangesByText().get("bar")); diff --git a/tests/cases/fourslash/referencesForImports.ts b/tests/cases/fourslash/referencesForImports.ts index 54cbb0f1155..0b763b09775 100644 --- a/tests/cases/fourslash/referencesForImports.ts +++ b/tests/cases/fourslash/referencesForImports.ts @@ -5,11 +5,11 @@ //// export = $; ////} -////import [|{| "isWriteAccess": true, "isDefinition": true |}$|] = require("jquery"); +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}$|] = require("jquery");|] ////[|$|]("a"); -////import [|{| "isWriteAccess": true, "isDefinition": true |}$|] = require("jquery"); +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}$|] = require("jquery");|] -const [r0, r1, r2] = test.ranges(); +const [r0Def, r0, r1, r2Def, r2] = test.ranges(); 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 4bc0b3620ea..4d21e1d6aef 100644 --- a/tests/cases/fourslash/referencesForIndexProperty.ts +++ b/tests/cases/fourslash/referencesForIndexProperty.ts @@ -3,8 +3,8 @@ // References a class property using string index access ////class Foo { -//// [|{| "isDefinition": true |}property|]: number; -//// [|{| "isWriteAccess": true, "isDefinition": true |}method|](): void { } +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}property|]: number;|] +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}method|](): void { }|] ////} //// ////var f: Foo; diff --git a/tests/cases/fourslash/referencesForIndexProperty3.ts b/tests/cases/fourslash/referencesForIndexProperty3.ts index 69417700ed0..2d0d4fec089 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 { -//// [|{| "isDefinition": true |}toMyString|](); +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}toMyString|]();|] ////} //// ////var y: Object; @@ -12,4 +12,4 @@ ////var x = {}; ////x["[|toMyString|]"](); -verify.singleReferenceGroup("(method) Object.toMyString(): any"); +verify.singleReferenceGroup("(method) Object.toMyString(): any", test.rangesByText().get("toMyString")); diff --git a/tests/cases/fourslash/referencesForInheritedProperties.ts b/tests/cases/fourslash/referencesForInheritedProperties.ts index 88d7ea7537d..47e642d01e2 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties.ts @@ -1,17 +1,17 @@ /// ////interface interface1 { -//// [|{| "isDefinition": true |}doStuff|](): void; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}doStuff|](): void;|] ////} //// ////interface interface2 extends interface1{ -//// [|{| "isDefinition": true |}doStuff|](): void; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}doStuff|](): void;|] ////} //// ////class class1 implements interface2 { -//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}doStuff|]() { //// -//// } +//// }|] ////} //// ////class class2 extends class1 { @@ -21,9 +21,8 @@ ////var v: class2; ////v.[|doStuff|](); -const ranges = test.ranges(); -const [r0, r1, r2, r3] = ranges; -verify.referenceGroups(ranges, [ +const [r0Def, r0, r1Def, r1, r2Def, r2, r3] = test.ranges(); +verify.referenceGroups([r0, r1, r2, r3], [ { definition: "(method) interface1.doStuff(): void", ranges: [r0] }, { definition: "(method) interface2.doStuff(): void", ranges: [r1] }, { definition: "(method) class1.doStuff(): void", ranges: [r2, r3] } diff --git a/tests/cases/fourslash/referencesForInheritedProperties2.ts b/tests/cases/fourslash/referencesForInheritedProperties2.ts index 712c7f2ecf2..31b875f4509 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties2.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties2.ts @@ -3,20 +3,20 @@ // extends statement in a diffrent declaration ////interface interface1 { -//// [|{| "isDefinition": true |}doStuff|](): void; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}doStuff|](): void;|] ////} //// ////interface interface2 { -//// [|{| "isDefinition": true |}doStuff|](): void; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}doStuff|](): void;|] ////} //// ////interface interface2 extends interface1 { ////} //// ////class class1 implements interface2 { -//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}doStuff|]() { //// -//// } +//// }|] ////} //// ////class class2 extends class1 { @@ -26,9 +26,8 @@ ////var v: class2; ////v.[|doStuff|](); -const ranges = test.ranges(); -const [r0, r1, r2, r3] = ranges; -verify.referenceGroups(ranges, [ +const [r0Def, r0, r1Def, r1, r2Def, r2, r3] = test.ranges(); +verify.referenceGroups([r0, r1, r2, r3], [ { definition: "(method) interface1.doStuff(): void", ranges: [r0] }, { definition: "(method) interface2.doStuff(): void", ranges: [r1] }, { definition: "(method) class1.doStuff(): void", ranges: [r2, r3] } diff --git a/tests/cases/fourslash/referencesForInheritedProperties3.ts b/tests/cases/fourslash/referencesForInheritedProperties3.ts index 0eabc6cda9e..42de1905874 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties3.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties3.ts @@ -1,8 +1,8 @@ /// //// interface interface1 extends interface1 { -//// [|{| "isDefinition": true |}doStuff|](): void; -//// [|{| "isDefinition": true |}propName|]: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}doStuff|](): void;|] +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}propName|]: string;|] //// } //// //// var v: interface1; diff --git a/tests/cases/fourslash/referencesForInheritedProperties4.ts b/tests/cases/fourslash/referencesForInheritedProperties4.ts index f6a7d48f9d1..5c00529cd1b 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties4.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties4.ts @@ -1,8 +1,8 @@ /// //// class class1 extends class1 { -//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } -//// [|{| "isDefinition": true |}propName|]: string; +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}doStuff|]() { }|] +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}propName|]: string;|] //// } //// //// var c: class1; diff --git a/tests/cases/fourslash/referencesForInheritedProperties5.ts b/tests/cases/fourslash/referencesForInheritedProperties5.ts index 232b654c63f..c86b8d01b85 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties5.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties5.ts @@ -1,12 +1,12 @@ /// //// interface interface1 extends interface1 { -//// [|{| "isDefinition": true |}doStuff|](): void; -//// [|{| "isDefinition": true |}propName|]: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}doStuff|](): void;|] +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}propName|]: string;|] //// } //// interface interface2 extends interface1 { -//// [|{| "isDefinition": true |}doStuff|](): void; -//// [|{| "isDefinition": true |}propName|]: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 4 |}doStuff|](): void;|] +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 6 |}propName|]: string;|] //// } //// //// var v: interface1; diff --git a/tests/cases/fourslash/referencesForInheritedProperties6.ts b/tests/cases/fourslash/referencesForInheritedProperties6.ts index a84a6a0b296..c71a17119f9 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties6.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties6.ts @@ -1,18 +1,17 @@ /// ////class class1 extends class1 { -//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}doStuff|]() { }|] ////} ////class class2 extends class1 { -//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}doStuff|]() { }|] ////} //// ////var v: class2; ////v.[|doStuff|](); -const ranges = test.ranges(); -const [m0, m1, m2] = ranges; -verify.referenceGroups(ranges, [ +const [m0Def, m0, m1Def, m1, m2] = test.ranges(); +verify.referenceGroups([m0, m1, m2], [ { definition: "(method) class1.doStuff(): void", ranges: [m0] }, { definition: "(method) class2.doStuff(): void", ranges: [m1, m2] } ]); diff --git a/tests/cases/fourslash/referencesForInheritedProperties7.ts b/tests/cases/fourslash/referencesForInheritedProperties7.ts index 25402d36b6e..a2efe171339 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties7.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties7.ts @@ -1,23 +1,23 @@ /// //// class class1 extends class1 { -//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } -//// [|{| "isDefinition": true |}propName|]: string; +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}doStuff|]() { }|] +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}propName|]: string;|] //// } //// interface interface1 extends interface1 { -//// [|{| "isDefinition": true |}doStuff|](): void; -//// [|{| "isDefinition": true |}propName|]: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 4 |}doStuff|](): void;|] +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 6 |}propName|]: string;|] //// } //// class class2 extends class1 implements interface1 { -//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } -//// [|{| "isDefinition": true |}propName|]: string; +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 8 |}doStuff|]() { }|] +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 10 |}propName|]: string;|] //// } //// //// var v: class2; //// v.[|doStuff|](); //// v.[|propName|]; -const [r0, r1, r2, r3, r4, r5, r6, r7] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3, r4Def, r4, r5Def, r5, r6, r7] = test.ranges(); const c1DoStuff = { definition: "(method) class1.doStuff(): void", ranges: [r0] }; const c2DoStuff = { definition: "(method) class2.doStuff(): void", ranges: [r4, r6] }; const c1PropName = { definition: "(property) class1.propName: string", ranges: [r1] }; diff --git a/tests/cases/fourslash/referencesForInheritedProperties8.ts b/tests/cases/fourslash/referencesForInheritedProperties8.ts index 331a90f9181..86aa3500a1c 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties8.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties8.ts @@ -1,17 +1,17 @@ /// //// interface C extends D { -//// [|{| "isDefinition": true |}propD|]: number; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}propD|]: number;|] //// } //// interface D extends C { -//// [|{| "isDefinition": true |}propD|]: string; -//// [|{| "isDefinition": true |}propC|]: number; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}propD|]: string;|] +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 4 |}propC|]: number;|] //// } //// var d: D; //// d.[|propD|]; //// d.[|propC|]; -const [d0, d1, c0, d2, c1] = test.ranges(); +const [d0Def, d0, d1Def, d1, c0Def, c0, d2, c1] = test.ranges(); verify.referenceGroups([d0, d1, d2], [ { definition: "(property) C.propD: number", ranges: [d0] }, { definition: "(property) D.propD: string", ranges: [d1, d2] }, diff --git a/tests/cases/fourslash/referencesForInheritedProperties9.ts b/tests/cases/fourslash/referencesForInheritedProperties9.ts index 3648be2f989..5bbcefb7753 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties9.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties9.ts @@ -1,16 +1,16 @@ /// //// class D extends C { -//// [|{| "isDefinition": true |}prop1|]: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}prop1|]: string;|] //// } //// //// class C extends D { -//// [|{| "isDefinition": true |}prop1|]: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}prop1|]: string;|] //// } //// //// var c: C; //// c.[|prop1|]; -const [r0, r1, r2] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2] = test.ranges(); verify.singleReferenceGroup("(property) D.prop1: string", [r0]); verify.singleReferenceGroup("(property) C.prop1: string", [r1, r2]); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations.ts b/tests/cases/fourslash/referencesForMergedDeclarations.ts index 5346a85f24f..3fb29fe0c7d 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations.ts @@ -1,20 +1,20 @@ /// -////interface [|{| "isWriteAccess": true, "isDefinition": true |}Foo|] { -////} +////[|interface [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Foo|] { +////}|] //// -////module [|{| "isWriteAccess": true, "isDefinition": true |}Foo|] { +////[|module [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}Foo|] { //// export interface Bar { } -////} +////}|] //// -////function [|{| "isWriteAccess": true, "isDefinition": true |}Foo|](): void { -////} +////[|function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}Foo|](): void { +////}|] //// ////var f1: [|Foo|].Bar; ////var f2: [|Foo|]; ////[|Foo|].bind(this); -const [type1, namespace1, value1, namespace2, type2, value2] = test.ranges(); +const [type1Def, type1, namespace1Def, namespace1, value1Def, value1, namespace2, type2, value2] = test.ranges(); verify.singleReferenceGroup("interface Foo\nnamespace Foo", [type1, type2]); verify.singleReferenceGroup("namespace Foo", [namespace1, namespace2]); verify.singleReferenceGroup("namespace Foo\nfunction Foo(): void", [value1, value2]); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations2.ts b/tests/cases/fourslash/referencesForMergedDeclarations2.ts index 1a4bc59c9b2..24ea93b30d5 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations2.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations2.ts @@ -6,7 +6,7 @@ //// ////function ATest() { } //// -////import [|{| "isWriteAccess": true, "isDefinition": true |}alias|] = ATest; // definition +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}alias|] = ATest;|] // definition //// ////var a: [|alias|].Bar; // namespace ////[|alias|].call(this); // value @@ -15,4 +15,4 @@ verify.singleReferenceGroup([ "(alias) function alias(): void", "(alias) namespace alias", "import alias = ATest" -].join("\n")); +].join("\n"), test.rangesByText().get("alias")); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations3.ts b/tests/cases/fourslash/referencesForMergedDeclarations3.ts index 27c442b5bcc..4013c5bd49b 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations3.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations3.ts @@ -2,16 +2,16 @@ // class and uninstantiated module -////class [|{| "isWriteAccess": true, "isDefinition": true |}testClass|] { +////[|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}testClass|] { //// static staticMethod() { } //// method() { } -////} +////}|] //// -////module [|{| "isWriteAccess": true, "isDefinition": true |}testClass|] { +////[|module [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}testClass|] { //// export interface Bar { //// //// } -////} +////}|] //// ////var c1: [|testClass|]; ////var c2: [|testClass|].Bar; @@ -20,7 +20,7 @@ ////[|testClass|].bind(this); ////new [|testClass|](); -const [class0, module0, class1, module1, class2, class3, class4, class5] = test.ranges(); +const [class0Def, class0, module0Def, module0, class1, module1, class2, class3, class4, class5] = test.ranges(); verify.singleReferenceGroup("class testClass\nnamespace testClass", [module0, module1]); const classes = [class0, class1, class2, class3, class4, class5]; verify.referenceGroups(classes, [{ definition: "class testClass\nnamespace testClass", ranges: classes }]); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations4.ts b/tests/cases/fourslash/referencesForMergedDeclarations4.ts index 14189120197..f67f2aa62e4 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations4.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations4.ts @@ -2,17 +2,17 @@ // class and instantiated module -////class [|{| "isWriteAccess": true, "isDefinition": true |}testClass|] { +////[|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}testClass|] { //// static staticMethod() { } //// method() { } -////} +////}|] //// -////module [|{| "isWriteAccess": true, "isDefinition": true |}testClass|] { +////[|module [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}testClass|] { //// export interface Bar { //// //// } //// export var s = 0; -////} +////}|] //// ////var c1: [|testClass|]; ////var c2: [|testClass|].Bar; @@ -22,4 +22,4 @@ ////[|testClass|].s; ////new [|testClass|](); -verify.singleReferenceGroup("class testClass\nnamespace testClass"); +verify.singleReferenceGroup("class testClass\nnamespace testClass", test.rangesByText().get("testClass")); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations5.ts b/tests/cases/fourslash/referencesForMergedDeclarations5.ts index 40b43eb6819..6b3e7a8c766 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations5.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations5.ts @@ -1,14 +1,14 @@ /// -////interface [|{| "isWriteAccess": true, "isDefinition": true |}Foo|] { } -////module [|{| "isWriteAccess": true, "isDefinition": true |}Foo|] { export interface Bar { } } -////function [|{| "isWriteAccess": true, "isDefinition": true |}Foo|]() { } +////[|interface [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Foo|] { }|] +////[|module [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}Foo|] { export interface Bar { } }|] +////[|function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}Foo|]() { }|] //// -////export = [|Foo|]; +////[|export = [|{| "declarationRangeIndex": 6 |}Foo|];|] const ranges = test.ranges(); -const [r0, r1, r2, r3] = ranges; +const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3] = ranges; verify.referenceGroups(r0, [{ definition: "interface Foo\nnamespace Foo", ranges: [r0, r3] }]); verify.referenceGroups(r1, [{ definition: "namespace Foo", ranges: [r1, r3] }]); verify.referenceGroups(r2, [{ definition: "namespace Foo\nfunction Foo(): void", ranges: [r2, r3] }]); -verify.referenceGroups(r3, [{ definition: "interface Foo\nnamespace Foo\nfunction Foo(): void", ranges }]); +verify.referenceGroups(r3, [{ definition: "interface Foo\nnamespace Foo\nfunction Foo(): void", ranges: [r0, r1, r2, r3] }]); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations6.ts b/tests/cases/fourslash/referencesForMergedDeclarations6.ts index 79ee0128ab6..91fc90f8e8f 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations6.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations6.ts @@ -1,13 +1,13 @@ /// ////interface Foo { } -////module [|{| "isWriteAccess": true, "isDefinition": true |}Foo|] { +////[|module [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Foo|] { //// export interface Bar { } //// export module Bar { export interface Baz { } } //// export function Bar() { } -////} +////}|] //// ////// module ////import a1 = [|Foo|]; -verify.singleReferenceGroup("namespace Foo"); +verify.singleReferenceGroup("namespace Foo", test.rangesByText().get("Foo")); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations7.ts b/tests/cases/fourslash/referencesForMergedDeclarations7.ts index c119992c8bc..8a35ead235c 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations7.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations7.ts @@ -2,17 +2,17 @@ ////interface Foo { } ////module Foo { -//// export interface [|{| "isWriteAccess": true, "isDefinition": true |}Bar|] { } -//// export module [|{| "isWriteAccess": true, "isDefinition": true |}Bar|] { export interface Baz { } } -//// export function [|{| "isWriteAccess": true, "isDefinition": true |}Bar|]() { } +//// [|export interface [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Bar|] { }|] +//// [|export module [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}Bar|] { export interface Baz { } }|] +//// [|export function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}Bar|]() { }|] ////} //// ////// module, value and type ////import a2 = Foo.[|Bar|]; const ranges = test.ranges(); -const [r0, r1, r2, r3] = ranges; +const [r0Def, r0, r1Def, r1, r2Def, r2, r3] = ranges; verify.referenceGroups(r0, [{ definition: "interface Foo.Bar\nnamespace Foo.Bar", ranges: [r0, r3] }]); verify.referenceGroups(r1, [{ definition: "namespace Foo.Bar", ranges: [r1, r3] }]); verify.referenceGroups(r2, [{ definition: "namespace Foo.Bar\nfunction Foo.Bar(): void", ranges: [r2, r3] }]); -verify.referenceGroups(r3, [{ definition: "interface Foo.Bar\nnamespace Foo.Bar\nfunction Foo.Bar(): void", ranges }]); +verify.referenceGroups(r3, [{ definition: "interface Foo.Bar\nnamespace Foo.Bar\nfunction Foo.Bar(): void", ranges: [r0, r1, r2, r3] }]); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations8.ts b/tests/cases/fourslash/referencesForMergedDeclarations8.ts index 4b4716c08a5..4485cd8d0de 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 [|{| "isWriteAccess": true, "isDefinition": true |}Bar|] { export interface Baz { } } +//// [|export module [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Bar|] { export interface Baz { } }|] //// export function Bar() { } ////} //// ////// module ////import a3 = Foo.[|Bar|].Baz; -verify.singleReferenceGroup("namespace Foo.Bar"); +verify.singleReferenceGroup("namespace Foo.Bar", test.rangesByText().get("Bar")); diff --git a/tests/cases/fourslash/referencesForNumericLiteralPropertyNames.ts b/tests/cases/fourslash/referencesForNumericLiteralPropertyNames.ts index 1f28714daa1..1a9998be1e5 100644 --- a/tests/cases/fourslash/referencesForNumericLiteralPropertyNames.ts +++ b/tests/cases/fourslash/referencesForNumericLiteralPropertyNames.ts @@ -1,12 +1,12 @@ /// ////class Foo { -//// public [|{| "isDefinition": true |}12|]: any; +//// [|public [|{| "isDefinition": true, "declarationRangeIndex": 0 |}12|]: any;|] ////} //// ////var x: Foo; ////x[[|12|]]; -////x = { "[|{| "isWriteAccess": true, "isDefinition": true |}12|]": 0 }; -////x = { [|{| "isWriteAccess": true, "isDefinition": true |}12|]: 0 }; +////x = { [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}12|]": 0|] }; +////x = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}12|]: 0|] }; -verify.singleReferenceGroup("(property) Foo[12]: any"); +verify.singleReferenceGroup("(property) Foo[12]: any", test.rangesByText().get("12")); diff --git a/tests/cases/fourslash/referencesForObjectLiteralProperties.ts b/tests/cases/fourslash/referencesForObjectLiteralProperties.ts index 804faaebe6e..ed365a63706 100644 --- a/tests/cases/fourslash/referencesForObjectLiteralProperties.ts +++ b/tests/cases/fourslash/referencesForObjectLiteralProperties.ts @@ -2,10 +2,11 @@ // References to an object literal property -////var x = { [|{| "isWriteAccess": true, "isDefinition": true |}add|]: 0, b: "string" }; +////var x = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}add|]: 0|], b: "string" }; ////x["[|add|]"]; ////x.[|add|]; ////var y = x; ////y.[|add|]; -verify.singleReferenceGroup("(property) add: number"); +const [rDef, ...ranges] = test.ranges(); +verify.singleReferenceGroup("(property) add: number", ranges); diff --git a/tests/cases/fourslash/referencesForOverrides.ts b/tests/cases/fourslash/referencesForOverrides.ts index d5d9ea0a6b6..f0dcc3e3621 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 [|{| "isWriteAccess": true, "isDefinition": true |}foo|](): void { -//// } +//// [|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|](): void { +//// }|] //// } //// export class Bar extends Foo { -//// public [|{| "isWriteAccess": true, "isDefinition": true |}foo|](): void { -//// } +//// [|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}foo|](): void { +//// }|] //// } //// } //// //// module SimpleInterfaceTest { //// export interface IFoo { -//// [|{| "isDefinition": true |}ifoo|](): void; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 4 |}ifoo|](): void;|] //// } //// export interface IBar extends IFoo { -//// [|{| "isDefinition": true |}ifoo|](): void; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 6 |}ifoo|](): void;|] //// } //// } //// //// module SimpleClassInterfaceTest { //// export interface IFoo { -//// [|{| "isDefinition": true |}icfoo|](): void; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 8 |}icfoo|](): void;|] //// } //// export class Bar implements IFoo { -//// public [|{| "isWriteAccess": true, "isDefinition": true |}icfoo|](): void { -//// } +//// [|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 10 |}icfoo|](): void { +//// }|] //// } //// } //// //// module Test { //// export interface IBase { -//// [|{| "isDefinition": true |}field|]: string; -//// [|{| "isDefinition": true |}method|](): void; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 12 |}field|]: string;|] +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 14 |}method|](): void;|] //// } //// //// export interface IBlah extends IBase { -//// [|{| "isDefinition": true |}field|]: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 16 |}field|]: string;|] //// } //// //// export interface IBlah2 extends IBlah { -//// [|{| "isDefinition": true |}field|]: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 18 |}field|]: string;|] //// } //// //// export interface IDerived extends IBlah2 { -//// [|{| "isDefinition": true |}method|](): void; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 20 |}method|](): void;|] //// } //// //// export class Bar implements IDerived { -//// public [|{| "isDefinition": true |}field|]: string; -//// public [|{| "isWriteAccess": true, "isDefinition": true |}method|](): void { } +//// [|public [|{| "isDefinition": true, "declarationRangeIndex": 22 |}field|]: string;|] +//// [|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 24 |}method|](): void { }|] //// } //// //// export class BarBlah extends Bar { -//// public [|{| "isDefinition": true |}field|]: string; +//// [|public [|{| "isDefinition": true, "declarationRangeIndex": 26 |}field|]: string;|] //// } //// } //// diff --git a/tests/cases/fourslash/referencesForPropertiesOfGenericType.ts b/tests/cases/fourslash/referencesForPropertiesOfGenericType.ts index be00bb7593f..7fc42dce34e 100644 --- a/tests/cases/fourslash/referencesForPropertiesOfGenericType.ts +++ b/tests/cases/fourslash/referencesForPropertiesOfGenericType.ts @@ -1,7 +1,7 @@ /// ////interface IFoo { -//// [|{| "isDefinition": true |}doSomething|](v: T): T; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}doSomething|](v: T): T;|] ////} //// ////var x: IFoo; @@ -10,4 +10,5 @@ ////var y: IFoo; ////y.[|doSomething|](12); -verify.singleReferenceGroup("(method) IFoo.doSomething(v: T): T"); +const [rDef, ...ranges] = test.ranges(); +verify.singleReferenceGroup("(method) IFoo.doSomething(v: T): T", ranges); diff --git a/tests/cases/fourslash/referencesForStatic.ts b/tests/cases/fourslash/referencesForStatic.ts index 1c82d2fde6c..7bc1ec13e9c 100644 --- a/tests/cases/fourslash/referencesForStatic.ts +++ b/tests/cases/fourslash/referencesForStatic.ts @@ -6,7 +6,7 @@ ////var n = 43; //// ////class foo { -//// static [|{| "isWriteAccess": true, "isDefinition": true |}n|] = ''; +//// [|static [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}n|] = '';|] //// //// public bar() { //// foo.[|{| "isWriteAccess": true |}n|] = "'"; @@ -30,4 +30,5 @@ // @Filename: referencesOnStatic_2.ts ////var q = foo.[|n|]; -verify.singleReferenceGroup("(property) foo.n: string"); +const [rDef, ...ranges] = test.ranges(); +verify.singleReferenceGroup("(property) foo.n: string", ranges); diff --git a/tests/cases/fourslash/referencesForStaticsAndMembersWithSameNames.ts b/tests/cases/fourslash/referencesForStaticsAndMembersWithSameNames.ts index 816b866421a..146fc87581c 100644 --- a/tests/cases/fourslash/referencesForStaticsAndMembersWithSameNames.ts +++ b/tests/cases/fourslash/referencesForStaticsAndMembersWithSameNames.ts @@ -3,13 +3,13 @@ ////module FindRef4 { //// module MixedStaticsClassTest { //// export class Foo { -//// [|{| "isDefinition": true |}bar|]: Foo; -//// static [|{| "isDefinition": true |}bar|]: Foo; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}bar|]: Foo;|] +//// [|static [|{| "isDefinition": true, "declarationRangeIndex": 2 |}bar|]: Foo;|] //// -//// public [|{| "isWriteAccess": true, "isDefinition": true |}foo|](): void { -//// } -//// public static [|{| "isWriteAccess": true, "isDefinition": true |}foo|](): void { -//// } +//// [|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}foo|](): void { +//// }|] +//// [|public static [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}foo|](): void { +//// }|] //// } //// } //// @@ -25,7 +25,7 @@ //// } ////} -const [fooBar, fooStaticBar, fooFoo, fooStaticFoo, xFoo, xBar, staticFoo, staticBar] = test.ranges(); +const [fooBarDef, fooBar, fooStaticBarDef, fooStaticBar, fooFooDef, fooFoo, fooStaticFooDef, fooStaticFoo, xFoo, xBar, staticFoo, staticBar] = test.ranges(); // References to a member method with the same name as a static. verify.singleReferenceGroup("(method) MixedStaticsClassTest.Foo.foo(): void", [fooFoo, xFoo]); diff --git a/tests/cases/fourslash/referencesForStringLiteralPropertyNames.ts b/tests/cases/fourslash/referencesForStringLiteralPropertyNames.ts index 88c9a74bc6e..036637ec75f 100644 --- a/tests/cases/fourslash/referencesForStringLiteralPropertyNames.ts +++ b/tests/cases/fourslash/referencesForStringLiteralPropertyNames.ts @@ -1,13 +1,13 @@ /// ////class Foo { -//// public "[|{| "isDefinition": true |}ss|]": any; +//// [|public "[|{| "isDefinition": true, "declarationRangeIndex": 0 |}ss|]": any;|] ////} //// ////var x: Foo; ////x.[|ss|]; ////x["[|ss|]"]; -////x = { "[|{| "isWriteAccess": true, "isDefinition": true |}ss|]": 0 }; -////x = { [|{| "isWriteAccess": true, "isDefinition": true |}ss|]: 0 }; +////x = { [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}ss|]": 0|] }; +////x = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}ss|]: 0|] }; -verify.singleReferenceGroup('(property) Foo["ss"]: any'); +verify.singleReferenceGroup('(property) Foo["ss"]: any', test.rangesByText().get("ss")); diff --git a/tests/cases/fourslash/referencesForStringLiteralPropertyNames2.ts b/tests/cases/fourslash/referencesForStringLiteralPropertyNames2.ts index ce5d474b9dc..cc142bebb69 100644 --- a/tests/cases/fourslash/referencesForStringLiteralPropertyNames2.ts +++ b/tests/cases/fourslash/referencesForStringLiteralPropertyNames2.ts @@ -1,10 +1,10 @@ /// ////class Foo { -//// "[|{| "isWriteAccess": true, "isDefinition": true |}blah|]"() { return 0; } +//// [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}blah|]"() { return 0; }|] ////} //// ////var x: Foo; ////x.[|blah|]; -verify.singleReferenceGroup('(method) Foo["blah"](): number'); +verify.singleReferenceGroup('(method) Foo["blah"](): number', test.rangesByText().get("blah")); diff --git a/tests/cases/fourslash/referencesForStringLiteralPropertyNames3.ts b/tests/cases/fourslash/referencesForStringLiteralPropertyNames3.ts index 22fa6b30cbc..050503a1e34 100644 --- a/tests/cases/fourslash/referencesForStringLiteralPropertyNames3.ts +++ b/tests/cases/fourslash/referencesForStringLiteralPropertyNames3.ts @@ -1,11 +1,12 @@ /// ////class Foo2 { -//// get "[|{| "isWriteAccess": true, "isDefinition": true |}42|]"() { return 0; } -//// set [|{| "isWriteAccess": true, "isDefinition": true |}42|](n) { } +//// [|get "[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}42|]"() { return 0; }|] +//// [|set [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}42|](n) { }|] ////} //// ////var y: Foo2; ////y[[|42|]]; -verify.singleReferenceGroup('(property) Foo2["42"]: number'); + +verify.singleReferenceGroup('(property) Foo2["42"]: number', test.rangesByText().get("42")); diff --git a/tests/cases/fourslash/referencesForStringLiteralPropertyNames4.ts b/tests/cases/fourslash/referencesForStringLiteralPropertyNames4.ts index a7589ba29a0..b4503030213 100644 --- a/tests/cases/fourslash/referencesForStringLiteralPropertyNames4.ts +++ b/tests/cases/fourslash/referencesForStringLiteralPropertyNames4.ts @@ -1,10 +1,10 @@ /// -////var x = { "[|{| "isWriteAccess": true, "isDefinition": true |}someProperty|]": 0 } +////var x = { [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}someProperty|]": 0|] } ////x["[|someProperty|]"] = 3; ////x.[|{| "isWriteAccess": true |}someProperty|] = 5; -const ranges = test.ranges(); +const [rDef, ...ranges] = test.ranges(); const [r0, r1, r2] = ranges; verify.referenceGroups(r0, [{ definition: '(property) "someProperty": number', ranges }]); verify.referenceGroups([r1, r2], [ diff --git a/tests/cases/fourslash/referencesForStringLiteralPropertyNames5.ts b/tests/cases/fourslash/referencesForStringLiteralPropertyNames5.ts index 22d35006c25..fc2174df21a 100644 --- a/tests/cases/fourslash/referencesForStringLiteralPropertyNames5.ts +++ b/tests/cases/fourslash/referencesForStringLiteralPropertyNames5.ts @@ -1,10 +1,10 @@ /// -////var x = { "[|{| "isWriteAccess": true, "isDefinition": true |}someProperty|]": 0 } +////var x = { [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}someProperty|]": 0|] } ////x["[|someProperty|]"] = 3; ////x.[|{| "isWriteAccess": true, "isDefinition": false |}someProperty|] = 5; -const ranges = test.ranges(); +const [r0Def, ...ranges] = test.ranges(); const [r0, r1, r2] = ranges; verify.referenceGroups(r0, [{ definition: '(property) "someProperty": number', ranges }]); verify.referenceGroups([r1, r2], [ diff --git a/tests/cases/fourslash/referencesForStringLiteralPropertyNames7.ts b/tests/cases/fourslash/referencesForStringLiteralPropertyNames7.ts index 98a6dc2ac47..4f6cd66fc73 100644 --- a/tests/cases/fourslash/referencesForStringLiteralPropertyNames7.ts +++ b/tests/cases/fourslash/referencesForStringLiteralPropertyNames7.ts @@ -4,13 +4,13 @@ // @allowJs: true // @checkJs: true -////var x = { "[|{| "isWriteAccess": true, "isDefinition": true |}someProperty|]": 0 } +////var x = { [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}someProperty|]": 0|] } ////x["[|someProperty|]"] = 3; -////x.[|{| "isWriteAccess": true, "isDefinition": true |}someProperty|] = 5; +////[|x.[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}someProperty|] = 5;|] -const ranges = test.ranges(); -const [r0, r1, r2] = ranges; +const [r0Def, r0, r1, r2Def, r2] = test.ranges(); +const ranges = [r0, r1, r2]; verify.referenceGroups(r0, [{ definition: '(property) "someProperty": number', ranges }]); verify.referenceGroups([r1, r2], [ - { definition: '(property) "someProperty": number', ranges: [r0, r1, r2] }, + { definition: '(property) "someProperty": number', ranges }, ]); diff --git a/tests/cases/fourslash/referencesForUnionProperties.ts b/tests/cases/fourslash/referencesForUnionProperties.ts index 7efff1aabd0..afaf78eb995 100644 --- a/tests/cases/fourslash/referencesForUnionProperties.ts +++ b/tests/cases/fourslash/referencesForUnionProperties.ts @@ -1,16 +1,16 @@ /// ////interface One { -//// common: { [|{| "isDefinition": true |}a|]: number; }; +//// common: { [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}a|]: number;|] }; ////} //// ////interface Base { -//// [|{| "isDefinition": true |}a|]: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}a|]: string;|] //// b: string; ////} //// ////interface HasAOrB extends Base { -//// [|{| "isDefinition": true |}a|]: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 4 |}a|]: string;|] //// b: string; ////} //// @@ -22,7 +22,7 @@ //// ////x.common.[|a|]; -const [one, base, hasAOrB, x] = test.ranges(); +const [oneDef, one, baseDef, base, hasAOrBDef, hasAOrB, x] = test.ranges(); verify.referenceGroups(one, [ { definition: "(property) a: number", ranges: [one] }, { definition: "(property) a: string | number", ranges: [x] }, diff --git a/tests/cases/fourslash/remoteGetReferences.ts b/tests/cases/fourslash/remoteGetReferences.ts index c9b8c3b4e2f..0c4e63d75f2 100644 --- a/tests/cases/fourslash/remoteGetReferences.ts +++ b/tests/cases/fourslash/remoteGetReferences.ts @@ -119,12 +119,12 @@ ////}); // @Filename: remoteGetReferences_2.ts -////var [|{| "isWriteAccess": true, "isDefinition": true |}remoteglobalVar|]: number = 2; +////[|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 10 |}remoteglobalVar|]: number = 2;|] //// -////class [|{| "isWriteAccess": true, "isDefinition": true |}remotefooCls|] { +////[|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 12 |}remotefooCls|] { //// //Declare -//// [|{| "isWriteAccess": true, "isDefinition": true |}remoteclsVar|] = 1; -//// static [|{| "isWriteAccess": true, "isDefinition": true |}remoteclsSVar|] = 1; +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 14 |}remoteclsVar|] = 1;|] +//// [|static [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 16 |}remoteclsSVar|] = 1;|] //// //// constructor(public remoteclsParam: number) { //// //Increments @@ -134,7 +134,7 @@ //// this.remoteclsParam++; //// remotemodTest.remotemodVar++; //// } -////} +////}|] //// ////function remotefoo(remotex: number) { //// //Declare @@ -178,6 +178,26 @@ ////} test.rangesByText().forEach((ranges, text) => { + // Definitions + if (text === "var remoteglobalVar: number = 2;" || + text === `class remotefooCls { + //Declare + remoteclsVar = 1; + static remoteclsSVar = 1; + + constructor(public remoteclsParam: number) { + //Increments + remoteglobalVar++; + this.remoteclsVar++; + remotefooCls.remoteclsSVar++; + this.remoteclsParam++; + remotemodTest.remotemodVar++; + } +}` || + text == "remoteclsVar = 1;" || + text === "static remoteclsSVar = 1;" + ) return; + const definition = (() => { switch (text) { case "remotefooCls": return "class remotefooCls"; diff --git a/tests/cases/fourslash/renameAcrossMultipleProjects.ts b/tests/cases/fourslash/renameAcrossMultipleProjects.ts index 2cc5824a843..272fe2bb393 100644 --- a/tests/cases/fourslash/renameAcrossMultipleProjects.ts +++ b/tests/cases/fourslash/renameAcrossMultipleProjects.ts @@ -1,7 +1,7 @@ /// //@Filename: a.ts -////var [|x|]: number; +////[|var [|{| "declarationRangeIndex": 0 |}x|]: number;|] //@Filename: b.ts /////// @@ -11,4 +11,5 @@ /////// ////[|x|]++; -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameAlias.ts b/tests/cases/fourslash/renameAlias.ts index 3869b1522b5..18b9ff47010 100644 --- a/tests/cases/fourslash/renameAlias.ts +++ b/tests/cases/fourslash/renameAlias.ts @@ -1,7 +1,8 @@ /// ////module SomeModule { export class SomeClass { } } -////import [|M|] = SomeModule; +////[|import [|{| "declarationRangeIndex": 0 |}M|] = SomeModule;|] ////import C = [|M|].SomeClass; -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameAlias2.ts b/tests/cases/fourslash/renameAlias2.ts index f97121f5f7d..4559976af80 100644 --- a/tests/cases/fourslash/renameAlias2.ts +++ b/tests/cases/fourslash/renameAlias2.ts @@ -1,7 +1,8 @@ /// -////module [|SomeModule|] { export class SomeClass { } } +////[|module [|{| "declarationRangeIndex": 0 |}SomeModule|] { export class SomeClass { } }|] ////import M = [|SomeModule|]; ////import C = M.SomeClass; -verify.rangesAreRenameLocations(); \ No newline at end of file +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); \ No newline at end of file diff --git a/tests/cases/fourslash/renameAlias3.ts b/tests/cases/fourslash/renameAlias3.ts index af3bafef115..70e3446dbe0 100644 --- a/tests/cases/fourslash/renameAlias3.ts +++ b/tests/cases/fourslash/renameAlias3.ts @@ -1,7 +1,8 @@ /// -////module SomeModule { export class [|SomeClass|] { } } +////module SomeModule { [|export class [|{| "declarationRangeIndex": 0 |}SomeClass|] { }|] } ////import M = SomeModule; ////import C = M.[|SomeClass|]; -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameAliasExternalModule.ts b/tests/cases/fourslash/renameAliasExternalModule.ts index 49cc6396717..8d753febc2b 100644 --- a/tests/cases/fourslash/renameAliasExternalModule.ts +++ b/tests/cases/fourslash/renameAliasExternalModule.ts @@ -5,7 +5,8 @@ ////export = SomeModule; // @Filename: b.ts -////import [|M|] = require("./a"); +////[|import [|{| "declarationRangeIndex": 0 |}M|] = require("./a");|] ////import C = [|M|].SomeClass; -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameAliasExternalModule2.ts b/tests/cases/fourslash/renameAliasExternalModule2.ts index 8416d12f4b2..e5e772179f5 100644 --- a/tests/cases/fourslash/renameAliasExternalModule2.ts +++ b/tests/cases/fourslash/renameAliasExternalModule2.ts @@ -1,13 +1,13 @@ /// // @Filename: a.ts -////module [|SomeModule|] { export class SomeClass { } } -////export = [|SomeModule|]; +////[|module [|{| "declarationRangeIndex": 0 |}SomeModule|] { export class SomeClass { } }|] +////[|export = [|{| "declarationRangeIndex": 2 |}SomeModule|];|] // @Filename: b.ts -////import [|M|] = require("./a"); +////[|import [|{| "declarationRangeIndex": 4 |}M|] = require("./a");|] ////import C = [|M|].SomeClass; -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3] = test.ranges(); verify.rangesAreRenameLocations([r0, r1]); verify.rangesAreRenameLocations([r2, r3]); diff --git a/tests/cases/fourslash/renameAliasExternalModule3.ts b/tests/cases/fourslash/renameAliasExternalModule3.ts index 53b28e7983e..6966b94b8a6 100644 --- a/tests/cases/fourslash/renameAliasExternalModule3.ts +++ b/tests/cases/fourslash/renameAliasExternalModule3.ts @@ -1,11 +1,12 @@ /// // @Filename: a.ts -////module SomeModule { export class [|SomeClass|] { } } +////module SomeModule { [|export class [|{| "declarationRangeIndex": 0 |}SomeClass|] { }|] } ////export = SomeModule; // @Filename: b.ts ////import M = require("./a"); ////import C = M.[|SomeClass|]; -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameCommentsAndStrings1.ts b/tests/cases/fourslash/renameCommentsAndStrings1.ts index cd350e3046c..7d3f5890b7d 100644 --- a/tests/cases/fourslash/renameCommentsAndStrings1.ts +++ b/tests/cases/fourslash/renameCommentsAndStrings1.ts @@ -2,9 +2,10 @@ /////// -////function [|Bar|]() { +////[|function [|{| "declarationRangeIndex": 0 |}Bar|]() { //// // This is a reference to Bar in a comment. //// "this is a reference to Bar in a string" -////} +////}|] -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/renameCommentsAndStrings2.ts b/tests/cases/fourslash/renameCommentsAndStrings2.ts index e31c3b76900..85e748988d9 100644 --- a/tests/cases/fourslash/renameCommentsAndStrings2.ts +++ b/tests/cases/fourslash/renameCommentsAndStrings2.ts @@ -2,10 +2,10 @@ /////// -////function [|Bar|]() { +////[|function [|{| "declarationRangeIndex": 0 |}Bar|]() { //// // This is a reference to Bar in a comment. //// "this is a reference to [|Bar|] in a string" -////} +////}|] -const ranges = test.ranges(); +const [rDef, ...ranges] = test.ranges(); verify.renameLocations(ranges[0], { findInStrings: true, ranges }) diff --git a/tests/cases/fourslash/renameCommentsAndStrings3.ts b/tests/cases/fourslash/renameCommentsAndStrings3.ts index 7d88ddf2438..c2d8482adbe 100644 --- a/tests/cases/fourslash/renameCommentsAndStrings3.ts +++ b/tests/cases/fourslash/renameCommentsAndStrings3.ts @@ -2,10 +2,10 @@ /////// -////function [|Bar|]() { +////[|function [|{| "declarationRangeIndex": 0 |}Bar|]() { //// // This is a reference to [|Bar|] in a comment. //// "this is a reference to Bar in a string" -////} +////}|] -const ranges = test.ranges(); +const [rDef, ...ranges] = test.ranges(); verify.renameLocations(ranges[0], { findInComments: true, ranges }); diff --git a/tests/cases/fourslash/renameCommentsAndStrings4.ts b/tests/cases/fourslash/renameCommentsAndStrings4.ts index eab53149d6d..0e04f22bde6 100644 --- a/tests/cases/fourslash/renameCommentsAndStrings4.ts +++ b/tests/cases/fourslash/renameCommentsAndStrings4.ts @@ -2,7 +2,7 @@ /////// -////function [|Bar|]() { +////[|function [|{| "declarationRangeIndex": 0 |}Bar|]() { //// // This is a reference to [|Bar|] in a comment. //// "this is a reference to [|Bar|] in a string"; //// `Foo [|Bar|] Baz.`; @@ -10,7 +10,7 @@ //// const Bar = 0; //// `[|Bar|] ba ${Bar} bara [|Bar|] berbobo ${Bar} araura [|Bar|] ara!`; //// } -////} +////}|] -const ranges = test.ranges(); +const [rDef, ...ranges] = test.ranges(); verify.renameLocations(ranges[0], { findInStrings: true, findInComments: true, ranges }); From 424f2c9e006cb1489d109f7877c30bc9a4b7a3e6 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 4 Jun 2019 12:24:34 -0700 Subject: [PATCH 20/44] More tests --- src/harness/fourslash.ts | 8 ++++---- tests/cases/fourslash/fourslash.ts | 2 +- tests/cases/fourslash/javaScriptClass2.ts | 6 +++--- tests/cases/fourslash/jsDocServices.ts | 11 ++++++----- .../fourslash/jsdocTypedefTagSemanticMeaning0.ts | 6 +++--- .../fourslash/jsdocTypedefTagSemanticMeaning1.ts | 4 ++-- tests/cases/fourslash/jsdocTypedefTagServices.ts | 13 +++++++------ tests/cases/fourslash/jsxSpreadReference.ts | 5 +++-- .../referenceInParameterPropertyDeclaration.ts | 8 +++++--- 9 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 51e6c2dbe29..5610eaf1510 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2709,8 +2709,8 @@ Actual: ${stringify(fullActual)}`); return this.languageService.getDocumentHighlights(this.activeFile.fileName, this.currentCaretPosition, filesToSearch); } - public verifyRangesAreOccurrences(isWriteAccess?: boolean) { - const ranges = this.getRanges(); + public verifyRangesAreOccurrences(isWriteAccess?: boolean, ranges?: Range[]) { + ranges = ranges || this.getRanges(); for (const r of ranges) { this.goToRangeStart(r); this.verifyOccurrencesAtPositionListCount(ranges.length); @@ -4084,8 +4084,8 @@ namespace FourSlashInterface { this.state.verifyOccurrencesAtPositionListCount(expectedCount); } - public rangesAreOccurrences(isWriteAccess?: boolean) { - this.state.verifyRangesAreOccurrences(isWriteAccess); + public rangesAreOccurrences(isWriteAccess?: boolean, ranges?: FourSlash.Range[]) { + this.state.verifyRangesAreOccurrences(isWriteAccess, ranges); } public rangesWithSameTextAreRenameLocations() { diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index fa9cdd61c2f..b01f8842dee 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -228,7 +228,7 @@ declare namespace FourSlashInterface { */ referenceGroups(starts: ArrayOrSingle | ArrayOrSingle, parts: ReadonlyArray): void; singleReferenceGroup(definition: ReferencesDefinition, ranges?: Range[]): void; - rangesAreOccurrences(isWriteAccess?: boolean): void; + rangesAreOccurrences(isWriteAccess?: boolean, ranges?: Range[]): void; rangesWithSameTextAreRenameLocations(): void; rangesAreRenameLocations(options?: Range[] | { findInStrings?: boolean, findInComments?: boolean, ranges?: Range[] }); findReferencesDefinitionDisplayPartsAtCaretAre(expected: ts.SymbolDisplayPart[]): void; diff --git a/tests/cases/fourslash/javaScriptClass2.ts b/tests/cases/fourslash/javaScriptClass2.ts index dcdac24c7b8..130976dfe57 100644 --- a/tests/cases/fourslash/javaScriptClass2.ts +++ b/tests/cases/fourslash/javaScriptClass2.ts @@ -6,12 +6,12 @@ // @Filename: Foo.js //// class Foo { //// constructor() { -//// this.[|union|] = 'foo'; -//// this.[|union|] = 100; +//// [|this.[|{| "declarationRangeIndex": 0 |}union|] = 'foo';|] +//// [|this.[|{| "declarationRangeIndex": 2 |}union|] = 100;|] //// } //// method() { return this.[|union|]; } //// } //// var x = new Foo(); //// x.[|union|]; -verify.rangesAreRenameLocations(); +verify.rangesAreRenameLocations(test.rangesByText().get("union")); diff --git a/tests/cases/fourslash/jsDocServices.ts b/tests/cases/fourslash/jsDocServices.ts index df1e985f876..75c8957b5eb 100644 --- a/tests/cases/fourslash/jsDocServices.ts +++ b/tests/cases/fourslash/jsDocServices.ts @@ -7,11 +7,12 @@ /////** //// * @param /*use*/[|foo|] I pity the foo //// */ -////function f([|/*def*/{| "isWriteAccess": true, "isDefinition": true |}foo|]: I) { +////function f([|[|/*def*/{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 1 |}foo|]: I|]) { //// return [|foo|]; ////} -const ranges = test.ranges(); +const [r0, r1Def, r1, r2] = test.ranges(); +const ranges = [r0, r1, r2]; goTo.marker("use"); verify.goToDefinitionIs("def"); verify.goToType("use", "I"); @@ -19,6 +20,6 @@ verify.goToType("use", "I"); goTo.marker("use"); verify.quickInfoIs("(parameter) foo: I", "I pity the foo"); -verify.singleReferenceGroup("(parameter) foo: I"); -verify.rangesAreDocumentHighlights(); -verify.rangesAreRenameLocations(); +verify.singleReferenceGroup("(parameter) foo: I", ranges); +verify.rangesAreDocumentHighlights(ranges); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning0.ts b/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning0.ts index c45f4aadc80..5cde088e8b2 100644 --- a/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning0.ts +++ b/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning0.ts @@ -3,14 +3,14 @@ // @allowJs: true // @Filename: a.js -/////** @typedef {number} [|{| "isWriteAccess": true, "isDefinition": true |}T|] */ +/////** [|@typedef {number} [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}T|]|] */ -////const [|{| "isWriteAccess": true, "isDefinition": true |}T|] = 1; +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}T|] = 1;|] /////** @type {[|T|]} */ ////const n = [|T|]; -const [t0, v0, t1, v1] = test.ranges(); +const [t0Def, t0, v0Def, v0, t1, v1] = test.ranges(); verify.singleReferenceGroup("type T = number", [t0, t1]); verify.singleReferenceGroup("const T: 1", [v0, v1]); diff --git a/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning1.ts b/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning1.ts index f052d4bd870..60bef778045 100644 --- a/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning1.ts +++ b/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning1.ts @@ -4,9 +4,9 @@ // @Filename: a.js /////** @typedef {number} */ -////const [|{| "isWriteAccess": true, "isDefinition": true |}T|] = 1; +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}T|] = 1;|] /////** @type {[|T|]} */ ////const n = [|T|]; -verify.singleReferenceGroup("type T = number\nconst T: 1"); +verify.singleReferenceGroup("type T = number\nconst T: 1", test.rangesByText().get("T")); diff --git a/tests/cases/fourslash/jsdocTypedefTagServices.ts b/tests/cases/fourslash/jsdocTypedefTagServices.ts index e4b262c3ee4..282569dfb91 100644 --- a/tests/cases/fourslash/jsdocTypedefTagServices.ts +++ b/tests/cases/fourslash/jsdocTypedefTagServices.ts @@ -5,9 +5,9 @@ /////** //// * Doc comment -//// * @typedef /*def*/[|{| "isWriteAccess": true, "isDefinition": true |}Product|] +//// * [|@typedef /*def*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Product|] //// * @property {string} title -//// */ +//// |]*/ /////** //// * @type {[|/*use*/Product|]} @@ -18,11 +18,12 @@ const desc = `type Product = { title: string; }`; +const [r0Def, ...ranges] = test.ranges(); verify.quickInfoAt("use", desc, "Doc comment"); verify.goToDefinition("use", "def"); -verify.rangesAreOccurrences(); -verify.rangesAreDocumentHighlights(); -verify.singleReferenceGroup(desc); -verify.rangesAreRenameLocations(); +verify.rangesAreOccurrences(/*isWriteAccesss*/ undefined, ranges); +verify.rangesAreDocumentHighlights(ranges); +verify.singleReferenceGroup(desc, ranges); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/jsxSpreadReference.ts b/tests/cases/fourslash/jsxSpreadReference.ts index 915dbdcecdf..3b8b9e9425a 100644 --- a/tests/cases/fourslash/jsxSpreadReference.ts +++ b/tests/cases/fourslash/jsxSpreadReference.ts @@ -14,8 +14,9 @@ //// } //// } //// -//// var [|/*dst*/nn|]: {name?: string; size?: number}; +//// [|var [|/*dst*/{| "declarationRangeIndex": 0 |}nn|]: {name?: string; size?: number};|] //// var x = ; verify.goToDefinition("src", "dst"); -verify.rangesAreRenameLocations(); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations(ranges); diff --git a/tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts b/tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts index 63494352ff4..c2c633926d5 100644 --- a/tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts +++ b/tests/cases/fourslash/referenceInParameterPropertyDeclaration.ts @@ -2,9 +2,9 @@ // @Filename: file1.ts //// class Foo { -//// 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) { +//// constructor([|private [|{| "isWriteAccess": true, "isDefinition": true, "type": "number", "declarationRangeIndex": 0 |}privateParam|]: number|], +//// [|public [|{| "isWriteAccess": true, "isDefinition": true, "type": "string", "declarationRangeIndex": 2 |}publicParam|]: string|], +//// [|protected [|{| "isWriteAccess": true, "isDefinition": true, "type": "boolean", "declarationRangeIndex": 4 |}protectedParam|]: boolean|]) { //// //// let localPrivate = [|privateParam|]; //// this.[|{| "isWriteAccess": true |}privateParam|] += 10; @@ -18,6 +18,8 @@ //// } test.rangesByText().forEach((ranges, text) => { + if (text !== "privateParam" && text !== "publicParam" && text !== "protectedParam") return; + const [r0, r1, r2] = ranges; const type = r0.marker.data.type; verify.referenceGroups(ranges, [ From eaeeb06f9a22e88af7a590599c8be9483839cc59 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 4 Jun 2019 13:45:22 -0700 Subject: [PATCH 21/44] Handle when declarationSpan from declarationNode is undefined --- src/services/goToDefinition.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index f64a2469156..05bd62e363f 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -273,18 +273,21 @@ namespace ts.GoToDefinition { function createDefinitionInfoFromName(declaration: Declaration, symbolKind: ScriptElementKind, symbolName: string, containerName: string): DefinitionInfo { const name = getNameOfDeclaration(declaration) || declaration; const sourceFile = name.getSourceFile(); - const declarationNode = FindAllReferences.getDeclarationForDeclarationSpan(declaration)!; - return { + const result: DefinitionInfo = { fileName: sourceFile.fileName, textSpan: createTextSpanFromNode(name, sourceFile), kind: symbolKind, name: symbolName, containerKind: undefined!, // TODO: GH#18217 containerName, - declarationSpan: FindAllReferences.isDeclarationNodeWithStartAndEnd(declarationNode) ? - createTextSpanFromNode(declarationNode.start, sourceFile, declarationNode.end) : - createTextSpanFromNode(declarationNode, sourceFile), }; + const declarationNode = FindAllReferences.getDeclarationForDeclarationSpan(declaration); + if (declarationNode) { + result.declarationSpan = FindAllReferences.isDeclarationNodeWithStartAndEnd(declarationNode) ? + createTextSpanFromNode(declarationNode.start, sourceFile, declarationNode.end) : + createTextSpanFromNode(declarationNode, sourceFile); + } + return result; } function createDefinitionFromSignatureDeclaration(typeChecker: TypeChecker, decl: SignatureDeclaration): DefinitionInfo { From cc1cb54e4bce8c71cd61c53f903a712f96b3dfa2 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 4 Jun 2019 13:58:27 -0700 Subject: [PATCH 22/44] More tests --- tests/cases/fourslash/findAllRefsUnionProperty.ts | 10 +++++----- .../findAllRefsWithLeadingUnderscoreNames1.ts | 4 ++-- .../findAllRefsWithLeadingUnderscoreNames2.ts | 4 ++-- .../findAllRefsWithLeadingUnderscoreNames3.ts | 4 ++-- .../findAllRefsWithLeadingUnderscoreNames4.ts | 4 ++-- .../findAllRefsWithLeadingUnderscoreNames5.ts | 4 ++-- .../findAllRefsWithLeadingUnderscoreNames6.ts | 4 ++-- .../findAllRefsWithLeadingUnderscoreNames7.ts | 6 +++--- .../findAllRefsWithLeadingUnderscoreNames8.ts | 6 +++--- .../findAllRefsWithLeadingUnderscoreNames9.ts | 6 +++--- .../findAllRefsWithShorthandPropertyAssignment.ts | 6 +++--- .../findAllRefsWithShorthandPropertyAssignment2.ts | 6 +++--- .../findAllRefs_importType_exportEquals.ts | 10 +++++----- tests/cases/fourslash/findAllRefs_importType_js.ts | 6 +++--- .../findAllRefs_importType_meaningAtLocation.ts | 6 +++--- .../fourslash/findAllRefs_importType_named.ts | 6 +++--- tests/cases/fourslash/findAllRefs_jsEnum.ts | 4 ++-- .../findReferencesAcrossMultipleProjects.ts | 4 ++-- tests/cases/fourslash/findReferencesAfterEdit.ts | 6 +++--- tests/cases/fourslash/findReferencesJSXTagName.ts | 8 ++++---- tests/cases/fourslash/findReferencesJSXTagName2.ts | 4 ++-- tests/cases/fourslash/findReferencesJSXTagName3.ts | 9 ++++----- .../getOccurrencesIsDefinitionOfArrowFunction.ts | 4 ++-- .../getOccurrencesIsDefinitionOfBindingPattern.ts | 4 ++-- .../fourslash/getOccurrencesIsDefinitionOfClass.ts | 6 +++--- ...getOccurrencesIsDefinitionOfComputedProperty.ts | 4 ++-- .../fourslash/getOccurrencesIsDefinitionOfEnum.ts | 6 +++--- .../getOccurrencesIsDefinitionOfExport.ts | 6 +++--- .../getOccurrencesIsDefinitionOfFunction.ts | 6 +++--- .../getOccurrencesIsDefinitionOfInterface.ts | 6 +++--- ...OccurrencesIsDefinitionOfInterfaceClassMerge.ts | 14 +++++++------- .../getOccurrencesIsDefinitionOfNamespace.ts | 6 +++--- ...OccurrencesIsDefinitionOfNumberNamedProperty.ts | 4 ++-- .../getOccurrencesIsDefinitionOfParameter.ts | 4 ++-- ...OccurrencesIsDefinitionOfStringNamedProperty.ts | 4 ++-- .../getOccurrencesIsDefinitionOfTypeAlias.ts | 4 ++-- .../getOccurrencesIsDefinitionOfVariable.ts | 4 ++-- 37 files changed, 104 insertions(+), 105 deletions(-) diff --git a/tests/cases/fourslash/findAllRefsUnionProperty.ts b/tests/cases/fourslash/findAllRefsUnionProperty.ts index 3b7813f638b..61f4df03047 100644 --- a/tests/cases/fourslash/findAllRefsUnionProperty.ts +++ b/tests/cases/fourslash/findAllRefsUnionProperty.ts @@ -1,11 +1,11 @@ /// ////type T = -//// | { [|{| "isDefinition": true |}type|]: "a", [|{| "isDefinition": true |}prop|]: number } -//// | { [|{| "isDefinition": true |}type|]: "b", [|{| "isDefinition": true |}prop|]: string }; +//// | { [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}type|]: "a",|] [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}prop|]: number|] } +//// | { [|[|{| "isDefinition": true, "declarationRangeIndex": 4 |}type|]: "b",|] [|[|{| "isDefinition": true, "declarationRangeIndex": 6 |}prop|]: string|] }; ////const tt: T = { -//// [|{| "isWriteAccess": true, "isDefinition": true |}type|]: "a", -//// [|{| "isWriteAccess": true, "isDefinition": true |}prop|]: 0, +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 8 |}type|]: "a"|], +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 10 |}prop|]: 0|], ////}; ////declare const t: T; ////if (t.[|type|] === "a") { @@ -14,7 +14,7 @@ //// t.[|type|]; ////} -const [t0, p0, t1, p1, t2, p2, t3, t4, t5] = test.ranges(); +const [t0Def, t0, p0Def, p0, t1Def, t1, p1Def, p1, t2Def, t2, p2Def, p2, t3, t4, t5] = test.ranges(); const a = { definition: { text: '(property) type: "a"', range: t0 }, ranges: [t0, t2, t4] }; const b = { definition: { text: '(property) type: "b"', range: t1 }, ranges: [t1, t5] }; diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames1.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames1.ts index 4a1bf374c05..2ae0cc4ac71 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames1.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames1.ts @@ -1,10 +1,10 @@ /// ////class Foo { -//// public [|{| "isWriteAccess": true, "isDefinition": true |}_bar|]() { return 0; } +//// [|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}_bar|]() { return 0; }|] ////} //// ////var x: Foo; ////x.[|_bar|]; -verify.singleReferenceGroup("(method) Foo._bar(): number"); +verify.singleReferenceGroup("(method) Foo._bar(): number", test.rangesByText().get("_bar")); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames2.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames2.ts index ec120254fde..038e66449d4 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames2.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames2.ts @@ -1,10 +1,10 @@ /// ////class Foo { -//// public [|{| "isWriteAccess": true, "isDefinition": true |}__bar|]() { return 0; } +//// [|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}__bar|]() { return 0; }|] ////} //// ////var x: Foo; ////x.[|__bar|]; -verify.singleReferenceGroup("(method) Foo.__bar(): number"); +verify.singleReferenceGroup("(method) Foo.__bar(): number", test.rangesByText().get("__bar")); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames3.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames3.ts index e6f46b128e7..9c7815dea01 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames3.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames3.ts @@ -1,10 +1,10 @@ /// ////class Foo { -//// public [|{| "isWriteAccess": true, "isDefinition": true |}___bar|]() { return 0; } +//// [|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}___bar|]() { return 0; }|] ////} //// ////var x: Foo; ////x.[|___bar|]; -verify.singleReferenceGroup("(method) Foo.___bar(): number"); +verify.singleReferenceGroup("(method) Foo.___bar(): number", test.rangesByText().get("___bar")); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames4.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames4.ts index 593d61f3fbe..5c6566a8a0f 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames4.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames4.ts @@ -1,10 +1,10 @@ /// ////class Foo { -//// public [|{| "isWriteAccess": true, "isDefinition": true |}____bar|]() { return 0; } +//// [|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}____bar|]() { return 0; }|] ////} //// ////var x: Foo; ////x.[|____bar|]; -verify.singleReferenceGroup("(method) Foo.____bar(): number"); +verify.singleReferenceGroup("(method) Foo.____bar(): number", test.rangesByText().get("____bar")); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames5.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames5.ts index cf171662596..f3c807483cd 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames5.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames5.ts @@ -3,7 +3,7 @@ ////class Foo { //// public _bar; //// public __bar; -//// public [|{| "isDefinition": true |}___bar|]; +//// [|public [|{| "isDefinition": true, "declarationRangeIndex": 0 |}___bar|];|] //// public ____bar; ////} //// @@ -13,4 +13,4 @@ ////x.[|___bar|]; ////x.____bar; -verify.singleReferenceGroup("(property) Foo.___bar: any"); +verify.singleReferenceGroup("(property) Foo.___bar: any", test.rangesByText().get("___bar")); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames6.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames6.ts index 77197480eb1..be8859c01a0 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames6.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames6.ts @@ -2,7 +2,7 @@ ////class Foo { //// public _bar; -//// public [|{| "isDefinition": true |}__bar|]; +//// [|public [|{| "isDefinition": true, "declarationRangeIndex": 0 |}__bar|];|] //// public ___bar; //// public ____bar; ////} @@ -13,4 +13,4 @@ ////x.___bar; ////x.____bar; -verify.singleReferenceGroup("(property) Foo.__bar: any"); +verify.singleReferenceGroup("(property) Foo.__bar: any", test.rangesByText().get("__bar")); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames7.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames7.ts index dac42f4fc7c..b6de0be25c9 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames7.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames7.ts @@ -1,7 +1,7 @@ /// -////function [|{| "isWriteAccess": true, "isDefinition": true |}__foo|]() { +////[|function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}__foo|]() { //// [|__foo|](); -////} +////}|] -verify.singleReferenceGroup("function __foo(): void"); +verify.singleReferenceGroup("function __foo(): void", test.rangesByText().get("__foo")); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames8.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames8.ts index 8c92275e27f..945fa91e6d6 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames8.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames8.ts @@ -1,7 +1,7 @@ /// -////(function [|{| "isWriteAccess": true, "isDefinition": true |}__foo|]() { +////([|function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}__foo|]() { //// [|__foo|](); -////}) +////}|]) -verify.singleReferenceGroup("(local function) __foo(): void"); +verify.singleReferenceGroup("(local function) __foo(): void", test.rangesByText().get("__foo")); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames9.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames9.ts index bc5799e61cf..2ff0420cc16 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames9.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames9.ts @@ -1,7 +1,7 @@ /// -////(function [|{| "isWriteAccess": true, "isDefinition": true |}___foo|]() { +////([|function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}___foo|]() { //// [|___foo|](); -////}) +////}|]) -verify.singleReferenceGroup("(local function) ___foo(): void"); +verify.singleReferenceGroup("(local function) ___foo(): void", test.rangesByText().get("___foo")); diff --git a/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment.ts b/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment.ts index b25c08cd692..490b87d624d 100644 --- a/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment.ts +++ b/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment.ts @@ -1,12 +1,12 @@ /// -//// var [|{| "isWriteAccess": true, "isDefinition": true |}name|] = "Foo"; +//// [|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}name|] = "Foo";|] //// //// var obj = { [|{| "isWriteAccess": true, "isDefinition": true |}name|] }; -//// var obj1 = { [|{| "isWriteAccess": true, "isDefinition": true |}name|]:[|name|] }; +//// var obj1 = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}name|]:[|name|]|] }; //// obj.[|name|]; -const [r0, r1, r2, r3, r4] = test.ranges(); +const [r0Def, r0, r1, r2Def, r2, r3, r4] = test.ranges(); verify.referenceGroups([r0, r3], [{ definition: "var name: string", ranges: [r0, r1, r3] }]); verify.referenceGroups(r1, [ { definition: "var name: string", ranges: [r0, r1, r3] }, diff --git a/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment2.ts b/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment2.ts index f19640698cd..39804714464 100644 --- a/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment2.ts +++ b/tests/cases/fourslash/findAllRefsWithShorthandPropertyAssignment2.ts @@ -1,15 +1,15 @@ /// -//// var [|{| "isWriteAccess": true, "isDefinition": true |}dx|] = "Foo"; +//// [|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}dx|] = "Foo";|] //// -//// module M { export var [|{| "isDefinition": true |}dx|]; } +//// module M { [|export var [|{| "isDefinition": true, "declarationRangeIndex": 2 |}dx|];|] } //// module M { //// var z = 100; //// export var y = { [|{| "isWriteAccess": true, "isDefinition": true |}dx|], z }; //// } //// M.y.[|dx|]; -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2, r3] = test.ranges(); verify.singleReferenceGroup("var dx: string", [r0]); verify.referenceGroups(r1, [{ definition: "var M.dx: any", ranges: [r1, r2] }]); verify.referenceGroups(r2, [ diff --git a/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts b/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts index 3734b7a2e88..0d60c153ce9 100644 --- a/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts +++ b/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts @@ -1,11 +1,11 @@ /// // @Filename: /a.ts -////type [|{| "isWriteAccess": true, "isDefinition": true |}T|] = number; -////namespace [|{| "isWriteAccess": true, "isDefinition": true |}T|] { +////[|type [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}T|] = number;|] +////[|namespace [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}T|] { //// export type U = string; -////} -////[|export|] = [|T|]; +////}|] +////[|[|export|] = [|{| "declarationRangeIndex": 4 |}T|];|] // @Filename: /b.ts ////const x: import("[|./[|a|]|]") = 0; @@ -13,7 +13,7 @@ verify.noErrors(); -const [r0, r1, rExport, r2, r3, r3b, r4, r4b] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, rExport, r2, r3, r3b, r4, r4b] = test.ranges(); verify.referenceGroups(r0, [{ definition: "type T = number\nnamespace T", ranges: [r0, r2, r3] }]); verify.referenceGroups(r1, [{ definition: "namespace T", ranges: [r1, r2] }]); const t: FourSlashInterface.ReferenceGroup = { definition: "type T = number\nnamespace T", ranges: [r0, r1, r2, r3] }; diff --git a/tests/cases/fourslash/findAllRefs_importType_js.ts b/tests/cases/fourslash/findAllRefs_importType_js.ts index b1f612c8e45..79f99da90a4 100644 --- a/tests/cases/fourslash/findAllRefs_importType_js.ts +++ b/tests/cases/fourslash/findAllRefs_importType_js.ts @@ -4,8 +4,8 @@ // @checkJs: true // @Filename: /a.js -////[|module|].exports = class [|{| "isWriteAccess": true, "isDefinition": true |}C|] {}; -////module.exports.[|{| "isWriteAccess": true, "isDefinition": true |}D|] = class [|{| "isWriteAccess": true, "isDefinition": true |}D|] {}; +////[|[|{| "declarationRangeIndex": 0 |}module|].exports = [|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}C|] {}|];|] +////[|module.exports.[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}D|] = [|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}D|] {}|];|] // @Filename: /b.js /////** @type {import("[|./a|]")} */ @@ -17,7 +17,7 @@ verify.noErrors(); // TODO: GH#24025 -const [rModule, r0, r1, r2, r3, r4, r5] = test.ranges(); +const [rModuleDef, rModule, r0Def, r0, r1Def, r1, r2Def, r2, r3, r4, r5] = test.ranges(); verify.referenceGroups(rModule, [{ definition: 'module "/a"', ranges: [r3, r4, rModule] }]); verify.referenceGroups(r0, [ { definition: "(local class) C", ranges: [r0] }, diff --git a/tests/cases/fourslash/findAllRefs_importType_meaningAtLocation.ts b/tests/cases/fourslash/findAllRefs_importType_meaningAtLocation.ts index 4c79999a866..367a6f0febd 100644 --- a/tests/cases/fourslash/findAllRefs_importType_meaningAtLocation.ts +++ b/tests/cases/fourslash/findAllRefs_importType_meaningAtLocation.ts @@ -1,13 +1,13 @@ /// // @Filename: /a.ts -////export type [|{| "isWriteAccess": true, "isDefinition": true |}T|] = 0; -////export const [|{| "isWriteAccess": true, "isDefinition": true |}T|] = 0; +////[|export type [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}T|] = 0;|] +////[|export const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}T|] = 0;|] // @Filename: /b.ts ////const x: import("./a").[|T|] = 0; ////const x: typeof import("./a").[|T|] = 0; -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2, r3] = test.ranges(); verify.singleReferenceGroup("type T = 0", [r0, r2]); verify.singleReferenceGroup("const T: 0", [r1, r3]); diff --git a/tests/cases/fourslash/findAllRefs_importType_named.ts b/tests/cases/fourslash/findAllRefs_importType_named.ts index ed4d4a1427b..ae3b7585764 100644 --- a/tests/cases/fourslash/findAllRefs_importType_named.ts +++ b/tests/cases/fourslash/findAllRefs_importType_named.ts @@ -1,13 +1,13 @@ /// // @Filename: /a.ts -////export type [|{| "isWriteAccess": true, "isDefinition": true |}T|] = number; -////export type [|{| "isWriteAccess": true, "isDefinition": true |}U|] = string; +////[|export type [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}T|] = number;|] +////[|export type [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}U|] = string;|] // @Filename: /b.ts ////const x: import("./a").[|T|] = 0; ////const x: import("./a").[|U|] = 0; -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2, r3] = test.ranges(); verify.singleReferenceGroup("type T = number", [r0, r2]); verify.singleReferenceGroup("type U = string", [r1, r3]); diff --git a/tests/cases/fourslash/findAllRefs_jsEnum.ts b/tests/cases/fourslash/findAllRefs_jsEnum.ts index c77b24256bf..79c007c2947 100644 --- a/tests/cases/fourslash/findAllRefs_jsEnum.ts +++ b/tests/cases/fourslash/findAllRefs_jsEnum.ts @@ -4,7 +4,7 @@ // @Filename: /a.js /////** @enum {string} */ -////const [|{| "isWriteAccess": true, "isDefinition": true |}E|] = { A: "" }; +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}E|] = { A: "" };|] ////[|E|]["A"]; /////** @type {[|E|]} */ ////const e = [|E|].A; @@ -13,4 +13,4 @@ verify.singleReferenceGroup( `enum E const E: { A: string; -}`); +}`, test.rangesByText().get("E")); diff --git a/tests/cases/fourslash/findReferencesAcrossMultipleProjects.ts b/tests/cases/fourslash/findReferencesAcrossMultipleProjects.ts index 2141399705f..b94b8629620 100644 --- a/tests/cases/fourslash/findReferencesAcrossMultipleProjects.ts +++ b/tests/cases/fourslash/findReferencesAcrossMultipleProjects.ts @@ -1,7 +1,7 @@ /// //@Filename: a.ts -////var [|{| "isDefinition": true |}x|]: number; +////[|var [|{| "isDefinition": true, "declarationRangeIndex": 0 |}x|]: number;|] //@Filename: b.ts /////// @@ -11,4 +11,4 @@ /////// ////[|{| "isWriteAccess": true |}x|]++; -verify.singleReferenceGroup("var x: number"); +verify.singleReferenceGroup("var x: number", test.rangesByText().get("x")); diff --git a/tests/cases/fourslash/findReferencesAfterEdit.ts b/tests/cases/fourslash/findReferencesAfterEdit.ts index 3787617692a..9a8717eb1e3 100644 --- a/tests/cases/fourslash/findReferencesAfterEdit.ts +++ b/tests/cases/fourslash/findReferencesAfterEdit.ts @@ -2,7 +2,7 @@ // @Filename: a.ts ////interface A { -//// [|{| "isDefinition": true |}foo|]: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}foo|]: string;|] ////} // @Filename: b.ts @@ -12,9 +12,9 @@ //// x.[|foo|] ////} -verify.singleReferenceGroup("(property) A.foo: string"); +verify.singleReferenceGroup("(property) A.foo: string", test.rangesByText().get("foo")); goTo.marker(""); edit.insert("\n"); -verify.singleReferenceGroup("(property) A.foo: string"); +verify.singleReferenceGroup("(property) A.foo: string", test.rangesByText().get("foo")); diff --git a/tests/cases/fourslash/findReferencesJSXTagName.ts b/tests/cases/fourslash/findReferencesJSXTagName.ts index 8547ad8b330..ec011671c9e 100644 --- a/tests/cases/fourslash/findReferencesJSXTagName.ts +++ b/tests/cases/fourslash/findReferencesJSXTagName.ts @@ -1,17 +1,17 @@ /// // @Filename: index.tsx -////import { [|{| "isWriteAccess": true, "isDefinition": true |}SubmissionComp|] } from "./RedditSubmission" +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}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 [|{| "isWriteAccess": true, "isDefinition": true |}SubmissionComp|] = (submission: SubmissionProps) => -////
; +////export const [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}SubmissionComp|] = (submission: SubmissionProps) => +////
; -const [r0, r1, r2] = test.ranges(); +const [r0Def, r0, r1, r2Def, r2] = test.ranges(); const imports = { definition: "(alias) const SubmissionComp: (submission: any) => any\nimport SubmissionComp", ranges: [r0, r1] }; const def = { definition: "const SubmissionComp: (submission: any) => any", ranges: [r2] }; verify.referenceGroups([r0, r1], [imports, def]); diff --git a/tests/cases/fourslash/findReferencesJSXTagName2.ts b/tests/cases/fourslash/findReferencesJSXTagName2.ts index a8882b60088..46133d8e339 100644 --- a/tests/cases/fourslash/findReferencesJSXTagName2.ts +++ b/tests/cases/fourslash/findReferencesJSXTagName2.ts @@ -1,9 +1,9 @@ /// // @Filename: index.tsx -////const [|{| "isWriteAccess": true, "isDefinition": true |}obj|] = {Component: () =>
}; +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}obj|] = {Component: () =>
};|] ////const element = <[|obj|].Component/>; verify.singleReferenceGroup(`const obj: { Component: () => any; -}`); +}`, test.rangesByText().get("obj")); diff --git a/tests/cases/fourslash/findReferencesJSXTagName3.ts b/tests/cases/fourslash/findReferencesJSXTagName3.ts index 58715ade2fa..afd90562777 100644 --- a/tests/cases/fourslash/findReferencesJSXTagName3.ts +++ b/tests/cases/fourslash/findReferencesJSXTagName3.ts @@ -6,22 +6,21 @@ ////namespace JSX { //// export interface Element { } //// export interface IntrinsicElements { -//// [|{| "isDefinition": true |}div|]: any; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}div|]: any;|] //// } ////} //// -////const [|{| "isWriteAccess": true, "isDefinition": true |}Comp|] = () => +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}Comp|] = () => //// <[|div|]> //// Some content //// <[|div|]>More content -//// ; +//// ;|] //// ////const x = <[|Comp|]> //// Content ////; -const ranges = test.ranges(); -const [d0, c0, d1, d2, d3, d4, c1, c2] = test.ranges(); +const [d0Def, d0, c0Def, c0, d1, d2, d3, d4, c1, c2] = test.ranges(); const allD = [d0, d1, d2, d3, d4]; const allC = [c0, c1, c2]; diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts index b1acb76ad2c..a50b2ca1149 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts @@ -1,5 +1,5 @@ /// -////var [|{| "isWriteAccess": true, "isDefinition": true |}f|] = x => x + 1; +////[|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}f|] = x => x + 1;|] ////[|f|](12); -verify.singleReferenceGroup("var f: (x: any) => any"); +verify.singleReferenceGroup("var f: (x: any) => any", test.rangesByText().get("f")); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfBindingPattern.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfBindingPattern.ts index 32fec74d162..44a7c70e001 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfBindingPattern.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfBindingPattern.ts @@ -1,8 +1,8 @@ /// -////const { [|{| "isWriteAccess": true, "isDefinition": true |}x|], y } = { [|{| "isWriteAccess": true, "isDefinition": true |}x|]: 1, y: 2 }; +////[|const { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|], y } = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}x|]: 1|], y: 2 };|] ////const z = [|x|]; -const [r0, r1, r2] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2] = test.ranges(); const local = { definition: "const x: number", ranges: [r0, r2] }; const prop = { definition: "(property) x: number", ranges: [r1] }; verify.referenceGroups(r0, [local, prop]); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts index 302ed5ce6f5..add271f14e4 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts @@ -1,10 +1,10 @@ /// -////class [|{| "isWriteAccess": true, "isDefinition": true |}C|] { +////[|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}C|] { //// n: number; //// constructor() { //// this.n = 12; //// } -////} +////}|] ////let c = new [|C|](); -verify.singleReferenceGroup("class C"); +verify.singleReferenceGroup("class C", test.rangesByText().get("C")); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts index 88ab38e5428..d67dfe74c95 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts @@ -1,6 +1,6 @@ /// -////let o = { ["[|{| "isWriteAccess": true, "isDefinition": true |}foo|]"]: 12 }; +////let o = { [|["[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|]"]: 12|] }; ////let y = o.[|foo|]; ////let z = o['[|foo|]']; -verify.singleReferenceGroup('(property) ["foo"]: number'); +verify.singleReferenceGroup('(property) ["foo"]: number', test.rangesByText().get("foo")); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts index 325674d8ee7..d1721c3b88b 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts @@ -1,8 +1,8 @@ /// -////enum [|{| "isWriteAccess": true, "isDefinition": true |}E|] { +////[|enum [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}E|] { //// First, //// Second -////} +////}|] ////let first = [|E|].First; -verify.singleReferenceGroup("enum E"); +verify.singleReferenceGroup("enum E", test.rangesByText().get("E")); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfExport.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfExport.ts index e31bc46eae6..1f0439b8d50 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfExport.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfExport.ts @@ -1,12 +1,12 @@ /// // @Filename: m.ts -////export var [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 12; +////[|export var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|] = 12;|] // @Filename: main.ts -////import { [|{| "isWriteAccess": true, "isDefinition": true |}x|] } from "./m"; +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}x|] } from "./m";|] ////const y = [|x|]; const ranges = test.ranges(); -const [r0, r1, r2] = ranges; +const [r0Def, r0, r1Def, r1, r2] = ranges; const defs = { definition: "var x: number", ranges: [r0] }; const imports = { definition: "(alias) var x: number\nimport x", ranges: [r1, r2] }; verify.referenceGroups(r0, [defs, imports]); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts index 4c91bc08ef8..71746119230 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts @@ -1,6 +1,6 @@ /// -////function [|{| "isWriteAccess": true, "isDefinition": true |}func|](x: number) { -////} +////[|function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}func|](x: number) { +////}|] ////[|func|](x) -verify.singleReferenceGroup("function func(x: number): void"); +verify.singleReferenceGroup("function func(x: number): void", test.rangesByText().get("func")); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts index 826890c4da9..57c96da1e8b 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts @@ -1,7 +1,7 @@ /// -////interface [|{| "isWriteAccess": true, "isDefinition": true |}I|] { +////[|interface [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}I|] { //// p: number; -////} +////}|] ////let i: [|I|] = { p: 12 }; -verify.singleReferenceGroup("interface I"); +verify.singleReferenceGroup("interface I", test.rangesByText().get("I")); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts index 0e363a216eb..2ec89979df4 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts @@ -1,16 +1,16 @@ /// -////interface [|{| "isWriteAccess": true, "isDefinition": true |}Numbers|] { +////[|interface [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Numbers|] { //// p: number; -////} -////interface [|{| "isWriteAccess": true, "isDefinition": true |}Numbers|] { +////}|] +////[|interface [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}Numbers|] { //// m: number; -////} -////class [|{| "isWriteAccess": true, "isDefinition": true |}Numbers|] { +////}|] +////[|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}Numbers|] { //// f(n: number) { //// return this.p + this.m + n; //// } -////} +////}|] ////let i: [|Numbers|] = new [|Numbers|](); ////let x = i.f(i.p + i.m); -verify.singleReferenceGroup("class Numbers\ninterface Numbers"); +verify.singleReferenceGroup("class Numbers\ninterface Numbers", test.rangesByText().get("Numbers")); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts index 04d00e6c19f..0fc07b3bb6b 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts @@ -1,7 +1,7 @@ /// -////namespace [|{| "isWriteAccess": true, "isDefinition": true |}Numbers|] { +////[|namespace [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Numbers|] { //// export var n = 12; -////} +////}|] ////let x = [|Numbers|].n + 1; -verify.singleReferenceGroup("namespace Numbers"); +verify.singleReferenceGroup("namespace Numbers", test.rangesByText().get("Numbers")); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts index 33bdad09e1a..249d768bf11 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts @@ -1,5 +1,5 @@ /// -////let o = { [|{| "isWriteAccess": true, "isDefinition": true |}1|]: 12 }; +////let o = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}1|]: 12|] }; ////let y = o[[|1|]]; -verify.singleReferenceGroup("(property) 1: number"); +verify.singleReferenceGroup("(property) 1: number", test.rangesByText().get("1")); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts index 8afa67bfe64..b18fc51f8eb 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts @@ -1,6 +1,6 @@ /// -////function f([|{| "isWriteAccess": true, "isDefinition": true |}x|]: number) { +////function f([|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|]: number|]) { //// return [|x|] + 1 ////} -verify.singleReferenceGroup("(parameter) x: number"); +verify.singleReferenceGroup("(parameter) x: number", test.rangesByText().get("x")); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts index cf88d476fef..7ca03f00482 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts @@ -1,5 +1,5 @@ /// -////let o = { "[|{| "isWriteAccess": true, "isDefinition": true |}x|]": 12 }; +////let o = { [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|]": 12|] }; ////let y = o.[|x|]; -verify.singleReferenceGroup('(property) "x": number'); +verify.singleReferenceGroup('(property) "x": number', test.rangesByText().get("x")); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts index 18a4ec0396c..cf69914507b 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts @@ -1,5 +1,5 @@ /// -////type [|{| "isWriteAccess": true, "isDefinition": true |}Alias|]= number; +////[|type [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Alias|]= number;|] ////let n: [|Alias|] = 12; -verify.singleReferenceGroup("type Alias = number"); +verify.singleReferenceGroup("type Alias = number", test.rangesByText().get("Alias")); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts index 2faf5b53e1b..b3a3ab4cc17 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts @@ -1,5 +1,5 @@ /// -////var [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 0; +////[|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|] = 0;|] ////var assignmentRightHandSide = [|x|]; ////var assignmentRightHandSide2 = 1 + [|x|]; //// @@ -17,4 +17,4 @@ ////[|{| "isWriteAccess": true |}x|] += 1; ////[|{| "isWriteAccess": true |}x|] <<= 1; -verify.singleReferenceGroup("var x: number"); +verify.singleReferenceGroup("var x: number", test.rangesByText().get("x")); From 004488c0c923f3d1e6519621acaa4969b3e52c57 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 4 Jun 2019 15:21:31 -0700 Subject: [PATCH 23/44] Set declaration span only if its not same as own span --- src/services/findAllReferences.ts | 33 ++++++++----------- src/services/goToDefinition.ts | 11 +++---- tests/cases/fourslash/localGetReferences.ts | 2 +- .../renameDestructuringFunctionParameter.ts | 2 +- .../renameJsSpecialAssignmentRhs1.ts | 2 +- .../renameJsSpecialAssignmentRhs2.ts | 2 +- tests/cases/fourslash/renameThis.ts | 2 +- 7 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 8ef72440bcc..14e47b2c4d1 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -111,11 +111,6 @@ namespace ts.FindAllReferences { case SyntaxKind.ImportClause: return node.parent; - case SyntaxKind.JsxAttribute: - return (node as JsxAttribute).initializer === undefined ? - undefined : - node; - case SyntaxKind.BinaryExpression: return isExpressionStatement(node.parent) ? node.parent : @@ -129,7 +124,6 @@ namespace ts.FindAllReferences { }; case SyntaxKind.PropertyAssignment: - // TODO(shkamat):: Should we show whole object literal instead? case SyntaxKind.ShorthandPropertyAssignment: return isArrayLiteralOrObjectLiteralDestructuringPattern(node.parent) ? getDeclarationForDeclarationSpan( @@ -137,15 +131,24 @@ namespace ts.FindAllReferences { isBinaryExpression(node) || isForInOrOfStatement(node) ) as BinaryExpression | ForInOrOfStatement ) : - node.kind === SyntaxKind.PropertyAssignment ? - node : - undefined; + node; default: return node; } } + export function setDeclarationSpan(span: DocumentSpan, sourceFile: SourceFile, declaration?: DeclarationNode) { + if (declaration) { + const declarationSpan = isDeclarationNodeWithStartAndEnd(declaration) ? + getTextSpan(declaration.start, sourceFile, declaration.end) : + getTextSpan(declaration, sourceFile); + if (declarationSpan.start !== span.textSpan.start || declarationSpan.length !== span.textSpan.length) { + span.declarationSpan = declarationSpan; + } + } + } + export interface Options { readonly findInStrings?: boolean; readonly findInComments?: boolean; @@ -287,11 +290,7 @@ namespace ts.FindAllReferences { textSpan: getTextSpan(isComputedPropertyName(node) ? node.expression : node, sourceFile), displayParts }; - if (declaration) { - result.declarationSpan = isDeclarationNodeWithStartAndEnd(declaration) ? - getTextSpan(declaration.start, sourceFile, declaration.end) : - getTextSpan(declaration, sourceFile); - } + setDeclarationSpan(result, sourceFile, declaration); return result; } @@ -330,11 +329,7 @@ namespace ts.FindAllReferences { else { const sourceFile = entry.node.getSourceFile(); const result: DocumentSpan = { textSpan: getTextSpan(entry.node, sourceFile), fileName: sourceFile.fileName }; - if (entry.declaration) { - result.declarationSpan = isDeclarationNodeWithStartAndEnd(entry.declaration) ? - getTextSpan(entry.declaration.start, sourceFile, entry.declaration.end) : - getTextSpan(entry.declaration, sourceFile); - } + setDeclarationSpan(result, sourceFile, entry.declaration); return result; } } diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index 05bd62e363f..4970ae573bf 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -281,12 +281,11 @@ namespace ts.GoToDefinition { containerKind: undefined!, // TODO: GH#18217 containerName, }; - const declarationNode = FindAllReferences.getDeclarationForDeclarationSpan(declaration); - if (declarationNode) { - result.declarationSpan = FindAllReferences.isDeclarationNodeWithStartAndEnd(declarationNode) ? - createTextSpanFromNode(declarationNode.start, sourceFile, declarationNode.end) : - createTextSpanFromNode(declarationNode, sourceFile); - } + FindAllReferences.setDeclarationSpan( + result, + sourceFile, + FindAllReferences.getDeclarationForDeclarationSpan(declaration) + ); return result; } diff --git a/tests/cases/fourslash/localGetReferences.ts b/tests/cases/fourslash/localGetReferences.ts index 401599368af..dd783693987 100644 --- a/tests/cases/fourslash/localGetReferences.ts +++ b/tests/cases/fourslash/localGetReferences.ts @@ -117,7 +117,7 @@ ////array.forEach( //// //// -////function([|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 43 |}str|]) { +////function([|{| "isWriteAccess": true, "isDefinition": true |}str|]) { //// //// //// diff --git a/tests/cases/fourslash/renameDestructuringFunctionParameter.ts b/tests/cases/fourslash/renameDestructuringFunctionParameter.ts index 79d2b40193b..80d82512ac5 100644 --- a/tests/cases/fourslash/renameDestructuringFunctionParameter.ts +++ b/tests/cases/fourslash/renameDestructuringFunctionParameter.ts @@ -1,6 +1,6 @@ /// -////function f([|{[|{| "declarationRangeIndex": 0 |}a|]}: {[|{| "declarationRangeIndex": 2 |}a|]}|]) { +////function f([|{[|{| "declarationRangeIndex": 0 |}a|]}: {[|a|]}|]) { //// f({[|a|]}); ////} diff --git a/tests/cases/fourslash/renameJsSpecialAssignmentRhs1.ts b/tests/cases/fourslash/renameJsSpecialAssignmentRhs1.ts index db3f1fc66e8..013cfe34cd5 100644 --- a/tests/cases/fourslash/renameJsSpecialAssignmentRhs1.ts +++ b/tests/cases/fourslash/renameJsSpecialAssignmentRhs1.ts @@ -5,7 +5,7 @@ //// set: function (x) { //// this._x = x; //// }, -//// copy: function ([|{| "declarationRangeIndex": 0 |}x|]) { +//// copy: function ([|x|]) { //// this._x = [|x|].prop; //// } ////}; diff --git a/tests/cases/fourslash/renameJsSpecialAssignmentRhs2.ts b/tests/cases/fourslash/renameJsSpecialAssignmentRhs2.ts index db3f1fc66e8..013cfe34cd5 100644 --- a/tests/cases/fourslash/renameJsSpecialAssignmentRhs2.ts +++ b/tests/cases/fourslash/renameJsSpecialAssignmentRhs2.ts @@ -5,7 +5,7 @@ //// set: function (x) { //// this._x = x; //// }, -//// copy: function ([|{| "declarationRangeIndex": 0 |}x|]) { +//// copy: function ([|x|]) { //// this._x = [|x|].prop; //// } ////}; diff --git a/tests/cases/fourslash/renameThis.ts b/tests/cases/fourslash/renameThis.ts index 7a209c0d6cc..82bfae820dc 100644 --- a/tests/cases/fourslash/renameThis.ts +++ b/tests/cases/fourslash/renameThis.ts @@ -1,6 +1,6 @@ /// -////function f([|{| "declarationRangeIndex": 0 |}this|]) { +////function f([|this|]) { //// return [|this|]; ////} ////this/**/; From 35c049949fbf5c1302db1549a3e14ac60d80bab0 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 5 Jun 2019 12:38:15 -0700 Subject: [PATCH 24/44] More tests --- .../fourslash/findAllRefsOnDecorators.ts | 6 ++-- .../fourslash/findAllRefsOnDefinition.ts | 6 ++-- .../fourslash/findAllRefsOnDefinition2.ts | 4 +-- .../fourslash/findAllRefsOnImportAliases.ts | 10 +++---- .../findAllRefsOnPrivateParameterProperty1.ts | 4 +-- ...indAllRefsParameterPropertyDeclaration1.ts | 4 +-- ...indAllRefsParameterPropertyDeclaration2.ts | 4 +-- ...indAllRefsParameterPropertyDeclaration3.ts | 4 +-- ...arameterPropertyDeclaration_inheritance.ts | 6 ++-- .../findAllRefsPrefixSuffixPreference.ts | 12 ++++---- ...sPropertyContextuallyTypedByTypeParam01.ts | 8 ++--- .../fourslash/findAllRefsReExportLocal.ts | 10 +++---- ...findAllRefsReExportRightNameWrongSymbol.ts | 12 ++++---- .../fourslash/findAllRefsReExportStar.ts | 6 ++-- .../fourslash/findAllRefsReExport_broken.ts | 4 +-- .../fourslash/findAllRefsReExport_broken2.ts | 4 +-- tests/cases/fourslash/findAllRefsReExports.ts | 29 +++++++++++++------ .../cases/fourslash/findAllRefsReExports2.ts | 6 ++-- ...efsRedeclaredPropertyInDerivedInterface.ts | 13 ++++----- .../findAllRefsRenameImportWithSameName.ts | 6 ++-- .../cases/fourslash/findAllRefsRootSymbols.ts | 8 ++--- .../cases/fourslash/findAllRefsThisKeyword.ts | 4 +-- tests/cases/fourslash/findAllRefsTypedef.ts | 6 ++-- .../findAllRefsTypedef_importType.ts | 4 +-- .../fourslash/findAllRefsTypeofImport.ts | 4 +-- 25 files changed, 97 insertions(+), 87 deletions(-) diff --git a/tests/cases/fourslash/findAllRefsOnDecorators.ts b/tests/cases/fourslash/findAllRefsOnDecorators.ts index 95bf1072014..aa8c0e0c9d2 100644 --- a/tests/cases/fourslash/findAllRefsOnDecorators.ts +++ b/tests/cases/fourslash/findAllRefsOnDecorators.ts @@ -1,9 +1,9 @@ /// // @Filename: a.ts -////function [|{| "isWriteAccess": true, "isDefinition": true |}decorator|](target) { +////[|function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}decorator|](target) { //// return target; -////} +////}|] ////[|decorator|](); // @Filename: b.ts @@ -13,4 +13,4 @@ //// method() {} ////} -verify.singleReferenceGroup("function decorator(target: any): any"); +verify.singleReferenceGroup("function decorator(target: any): any", test.rangesByText().get("decorator")); diff --git a/tests/cases/fourslash/findAllRefsOnDefinition.ts b/tests/cases/fourslash/findAllRefsOnDefinition.ts index 91582b92884..da7640224e2 100644 --- a/tests/cases/fourslash/findAllRefsOnDefinition.ts +++ b/tests/cases/fourslash/findAllRefsOnDefinition.ts @@ -7,9 +7,9 @@ //// //// } //// -//// public [|{| "isWriteAccess": true, "isDefinition": true |}start|](){ +//// [|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}start|](){ //// return this; -//// } +//// }|] //// //// public stop(){ //// return this; @@ -23,4 +23,4 @@ ////second.[|start|](); ////second.stop(); -verify.singleReferenceGroup("(method) Test.start(): this"); +verify.singleReferenceGroup("(method) Test.start(): this", test.rangesByText().get("start")); diff --git a/tests/cases/fourslash/findAllRefsOnDefinition2.ts b/tests/cases/fourslash/findAllRefsOnDefinition2.ts index 9a0fd390c1e..b300213150a 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 [|{| "isWriteAccess": true, "isDefinition": true |}start|] { } +//// [|export interface [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}start|] { }|] //// //// export interface stop { } ////} @@ -14,4 +14,4 @@ ////var start: Second.Test.[|start|]; ////var stop: Second.Test.stop; -verify.singleReferenceGroup("interface Test.start"); +verify.singleReferenceGroup("interface Test.start", test.rangesByText().get("start")); diff --git a/tests/cases/fourslash/findAllRefsOnImportAliases.ts b/tests/cases/fourslash/findAllRefsOnImportAliases.ts index 17f947ffdc3..88d9bfa3f3a 100644 --- a/tests/cases/fourslash/findAllRefsOnImportAliases.ts +++ b/tests/cases/fourslash/findAllRefsOnImportAliases.ts @@ -1,19 +1,19 @@ /// //@Filename: a.ts -////export class [|{| "isWriteAccess": true, "isDefinition": true |}Class|] { -////} +////[|export class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Class|] { +////}|] //@Filename: b.ts -////import { [|{| "isWriteAccess": true, "isDefinition": true |}Class|] } from "./a"; +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}Class|] } from "./a";|] //// ////var c = new [|Class|](); //@Filename: c.ts -////export { [|{| "isWriteAccess": true, "isDefinition": true |}Class|] } from "./a"; +////[|export { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}Class|] } from "./a";|] const ranges = test.ranges(); -const [r0, r1, r2, r3] = ranges; +const [r0Def, r0, r1Def, r1, r2, r3Def, r3] = ranges; const classes = { definition: "class Class", ranges: [r0] }; const imports = { definition: "(alias) class Class\nimport Class", ranges: [r1, r2] }; const reExports = { definition: "(alias) class Class\nexport Class", ranges: [r3] }; diff --git a/tests/cases/fourslash/findAllRefsOnPrivateParameterProperty1.ts b/tests/cases/fourslash/findAllRefsOnPrivateParameterProperty1.ts index df33f2888e6..d438a87717d 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 [|{| "isWriteAccess": true, "isDefinition": true |}z|]: number) { +//// constructor(private x: number, public y: number, [|private [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}z|]: number|]) { //// } //// //// func() { @@ -9,4 +9,4 @@ //// } ////} -verify.singleReferenceGroup("(property) ABCD.z: number"); +verify.singleReferenceGroup("(property) ABCD.z: number", test.rangesByText().get("z")); diff --git a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration1.ts b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration1.ts index 89bb40b6830..49812d2810f 100644 --- a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration1.ts +++ b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration1.ts @@ -1,13 +1,13 @@ /// //// class Foo { -//// constructor(private [|{| "isWriteAccess": true, "isDefinition": true |}privateParam|]: number) { +//// constructor([|private [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}privateParam|]: number|]) { //// let localPrivate = [|privateParam|]; //// this.[|{| "isWriteAccess": true |}privateParam|] += 10; //// } //// } -const ranges = test.ranges(); +const [rDef, ...ranges] = test.ranges(); const [r0, r1, r2] = ranges; verify.referenceGroups(ranges, [ { definition: "(property) Foo.privateParam: number", ranges: [r0, r2] }, diff --git a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration2.ts b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration2.ts index 519ca74c5c4..7ee352cfcde 100644 --- a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration2.ts +++ b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration2.ts @@ -1,13 +1,13 @@ /// //// class Foo { -//// constructor(public [|{| "isWriteAccess": true, "isDefinition": true |}publicParam|]: number) { +//// constructor([|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}publicParam|]: number|]) { //// let localPublic = [|publicParam|]; //// this.[|{| "isWriteAccess": true |}publicParam|] += 10; //// } //// } -const ranges = test.ranges(); +const [rDef, ...ranges] = test.ranges(); const [r0, r1, r2] = ranges; verify.referenceGroups(ranges, [ { definition: "(property) Foo.publicParam: number", ranges: [r0, r2] }, diff --git a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration3.ts b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration3.ts index 7addc2ba7a0..3d58989a0f3 100644 --- a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration3.ts +++ b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration3.ts @@ -1,13 +1,13 @@ /// //// class Foo { -//// constructor(protected [|{| "isWriteAccess": true, "isDefinition": true |}protectedParam|]: number) { +//// constructor([|protected [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}protectedParam|]: number|]) { //// let localProtected = [|protectedParam|]; //// this.[|{| "isWriteAccess": true |}protectedParam|] += 10; //// } //// } -const ranges = test.ranges(); +const [rDef, ...ranges] = test.ranges(); const [r0, r1, r2] = ranges; verify.referenceGroups(ranges, [ { definition: "(property) Foo.protectedParam: number", ranges: [r0, r2] }, diff --git a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration_inheritance.ts b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration_inheritance.ts index 9d7cfd51185..e8998dbbf70 100644 --- a/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration_inheritance.ts +++ b/tests/cases/fourslash/findAllRefsParameterPropertyDeclaration_inheritance.ts @@ -1,17 +1,17 @@ /// ////class C { -//// constructor(public [|{| "isWriteAccess": true, "isDefinition": true |}x|]: string) { +//// constructor([|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|]: string|]) { //// [|x|]; //// } ////} ////class D extends C { -//// constructor(public [|{| "isWriteAccess": true, "isDefinition": true |}x|]: string) { +//// constructor([|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}x|]: string|]) { //// super([|x|]); //// } ////} -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1, r2Def, r2, r3] = test.ranges(); verify.referenceGroups(r0, [ { definition: "(property) C.x: string", ranges: [r0] }, { definition: "(parameter) x: string", ranges: [r1] }, diff --git a/tests/cases/fourslash/findAllRefsPrefixSuffixPreference.ts b/tests/cases/fourslash/findAllRefsPrefixSuffixPreference.ts index 3745eff4e5d..1d920552375 100644 --- a/tests/cases/fourslash/findAllRefsPrefixSuffixPreference.ts +++ b/tests/cases/fourslash/findAllRefsPrefixSuffixPreference.ts @@ -2,22 +2,22 @@ // @Filename: /file1.ts ////declare function log(s: string | number): void; -////const [|{| "isWriteAccess": true, "isDefinition": true |}q|] = 1; -////export { [|{| "isWriteAccess": true, "isDefinition": true |}q|] }; +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}q|] = 1;|] +////[|export { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}q|] };|] ////const x = { -//// [|{| "isWriteAccess": true, "isDefinition": true |}z|]: 'value' +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}z|]: 'value'|] ////} -////const { [|{| "isWriteAccess": true, "isDefinition": true |}z|] } = x; +////[|const { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}z|] } = x;|] ////log([|z|]); // @Filename: /file2.ts ////declare function log(s: string | number): void; -////import { [|{| "isWriteAccess": true, "isDefinition": true |}q|] } from "./file1"; +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 9 |}q|] } from "./file1";|] ////log([|q|] + 1); verify.noErrors(); -const [q0, q1, z0, z1, z2, q2, q3] = test.ranges(); +const [q0Def, q0, q1Def, q1, z0Def, z0, z1Def, z1, z2, q2Def, q2, q3] = test.ranges(); const qFile1Ranges = [q0, q1]; const qFile2Ranges = [q2, q3]; const qFile1ReferenceGroup: FourSlashInterface.ReferenceGroup = { diff --git a/tests/cases/fourslash/findAllRefsPropertyContextuallyTypedByTypeParam01.ts b/tests/cases/fourslash/findAllRefsPropertyContextuallyTypedByTypeParam01.ts index d4aefb58ac3..8b8a82c169f 100644 --- a/tests/cases/fourslash/findAllRefsPropertyContextuallyTypedByTypeParam01.ts +++ b/tests/cases/fourslash/findAllRefsPropertyContextuallyTypedByTypeParam01.ts @@ -1,12 +1,12 @@ /// ////interface IFoo { -//// [|{| "isDefinition": true |}a|]: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}a|]: string;|] ////} ////class C { //// method() { //// var x: T = { -//// [|{| "isWriteAccess": true, "isDefinition": true |}a|]: "" +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}a|]: ""|] //// }; //// x.[|a|]; //// } @@ -14,7 +14,7 @@ //// //// ////var x: IFoo = { -//// [|{| "isWriteAccess": true, "isDefinition": true |}a|]: "ss" +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}a|]: "ss"|] ////}; -verify.singleReferenceGroup("(property) IFoo.a: string"); +verify.singleReferenceGroup("(property) IFoo.a: string", test.rangesByText().get("a")); diff --git a/tests/cases/fourslash/findAllRefsReExportLocal.ts b/tests/cases/fourslash/findAllRefsReExportLocal.ts index 502c7fdde46..e7601fd072b 100644 --- a/tests/cases/fourslash/findAllRefsReExportLocal.ts +++ b/tests/cases/fourslash/findAllRefsReExportLocal.ts @@ -3,17 +3,17 @@ // @noLib: true // @Filename: /a.ts -////var [|{| "isDefinition": true |}x|]; -////export { [|{| "isWriteAccess": true, "isDefinition": true |}x|] }; -////export { [|x|] as [|{| "isWriteAccess": true, "isDefinition": true |}y|] }; +////[|var [|{| "isDefinition": true, "declarationRangeIndex": 0 |}x|];|] +////[|export { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}x|] };|] +////[|export { [|{| "declarationRangeIndex": 4 |}x|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}y|] };|] // @Filename: /b.ts -////import { [|{| "isWriteAccess": true, "isDefinition": true |}x|], [|{| "isWriteAccess": true, "isDefinition": true |}y|] } from "./a"; +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 7 |}x|], [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 7 |}y|] } from "./a";|] ////[|x|]; [|y|]; verify.noErrors(); -const [ax0, ax1, ax2, ay, bx0, by0, bx1, by1] = test.ranges(); +const [ax0Def, ax0, ax1Def, ax1, ax2Def, ax2, ay, bx0Def, bx0, by0, bx1, by1] = test.ranges(); const axRanges = [ax0, ax1, ax2]; const bxRanges = [bx0, bx1]; const byRanges = [by0, by1]; diff --git a/tests/cases/fourslash/findAllRefsReExportRightNameWrongSymbol.ts b/tests/cases/fourslash/findAllRefsReExportRightNameWrongSymbol.ts index c44bdd2fffc..8649f8b3b3d 100644 --- a/tests/cases/fourslash/findAllRefsReExportRightNameWrongSymbol.ts +++ b/tests/cases/fourslash/findAllRefsReExportRightNameWrongSymbol.ts @@ -1,21 +1,21 @@ /// // @Filename: /a.ts -////export const [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 0; +////[|export const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|] = 0;|] // @Filename: /b.ts -////export const [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 0; +////[|export const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}x|] = 0;|] //@Filename: /c.ts -////export { [|{| "isWriteAccess": true, "isDefinition": true |}x|] } from "./b"; -////import { [|{| "isWriteAccess": true, "isDefinition": true |}x|] } from "./a"; +////[|export { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}x|] } from "./b";|] +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}x|] } from "./a";|] ////[|x|]; // @Filename: /d.ts -////import { [|{| "isWriteAccess": true, "isDefinition": true |}x|] } from "./c"; +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 9 |}x|] } from "./c";|] verify.noErrors(); -const [a, b, cFromB, cFromA, cUse, d] = test.ranges(); +const [aDef, a, bDef, b, cFromBDef, cFromB, cFromADef, cFromA, cUse, dDef, d] = test.ranges(); const cFromARanges = [cFromA, cUse]; const aGroup = { definition: "const x: 0", ranges: [a] }; diff --git a/tests/cases/fourslash/findAllRefsReExportStar.ts b/tests/cases/fourslash/findAllRefsReExportStar.ts index a82f91cc5b0..759ef38cabe 100644 --- a/tests/cases/fourslash/findAllRefsReExportStar.ts +++ b/tests/cases/fourslash/findAllRefsReExportStar.ts @@ -1,17 +1,17 @@ /// // @Filename: /a.ts -////export function [|{| "isWriteAccess": true, "isDefinition": true |}foo|](): void {} +////[|export function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|](): void {}|] // @Filename: /b.ts ////export * from "./a"; // @Filename: /c.ts -////import { [|{| "isWriteAccess": true, "isDefinition": true |}foo|] } from "./b"; +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}foo|] } from "./b";|] verify.noErrors(); const ranges = test.ranges(); -const [r0, r1] = ranges; +const [r0Def, r0, r1Def, r1] = ranges; const a = { definition: "function foo(): void", ranges: [r0] }; const c = { definition: "(alias) function foo(): void\nimport foo", ranges: [r1] }; verify.referenceGroups(r0, [a, c]); diff --git a/tests/cases/fourslash/findAllRefsReExport_broken.ts b/tests/cases/fourslash/findAllRefsReExport_broken.ts index 92e4fcaa57c..3e57c60bdec 100644 --- a/tests/cases/fourslash/findAllRefsReExport_broken.ts +++ b/tests/cases/fourslash/findAllRefsReExport_broken.ts @@ -1,6 +1,6 @@ /// // @Filename: /a.ts -////export { [|{| "isWriteAccess": true, "isDefinition": true |}x|] }; +////[|export { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|] };|] -verify.singleReferenceGroup("export x"); +verify.singleReferenceGroup("export x", test.rangesByText().get("x")); diff --git a/tests/cases/fourslash/findAllRefsReExport_broken2.ts b/tests/cases/fourslash/findAllRefsReExport_broken2.ts index 1a6649465fb..bb8291403f8 100644 --- a/tests/cases/fourslash/findAllRefsReExport_broken2.ts +++ b/tests/cases/fourslash/findAllRefsReExport_broken2.ts @@ -1,6 +1,6 @@ /// // @Filename: /a.ts -////export { [|{| "isWriteAccess": true, "isDefinition": true |}x|] } from "nonsense"; +////[|export { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|] } from "nonsense";|] -verify.singleReferenceGroup("export x"); +verify.singleReferenceGroup("export x", test.rangesByText().get("x")); diff --git a/tests/cases/fourslash/findAllRefsReExports.ts b/tests/cases/fourslash/findAllRefsReExports.ts index 89e65d5bb37..69f2cff209c 100644 --- a/tests/cases/fourslash/findAllRefsReExports.ts +++ b/tests/cases/fourslash/findAllRefsReExports.ts @@ -1,26 +1,36 @@ /// // @Filename: /a.ts -////export function [|{| "isWriteAccess": true, "isDefinition": true |}foo|](): void {} +////[|export function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|](): void {}|] // @Filename: /b.ts -////export { [|foo|] as [|{| "isWriteAccess": true, "isDefinition": true |}bar|] } from "./a"; +////[|export { [|{| "declarationRangeIndex": 2 |}foo|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}bar|] } from "./a";|] // @Filename: /c.ts -////export { [|foo|] as [|{| "isWriteAccess": true, "isDefinition": true |}default|] } from "./a"; +////[|export { [|{| "declarationRangeIndex": 5 |}foo|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}default|] } from "./a";|] // @Filename: /d.ts -////export { [|{| "isWriteAccess": true, "isDefinition": true |}default|] } from "./c"; +////[|export { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 8 |}default|] } from "./c";|] // @Filename: /e.ts -////import { [|{| "isWriteAccess": true, "isDefinition": true |}bar|] } from "./b"; -////import [|{| "isWriteAccess": true, "isDefinition": true |}baz|] from "./c"; -////import { [|default|] as [|{| "isWriteAccess": true, "isDefinition": true |}bang|] } from "./c"; -////import [|{| "isWriteAccess": true, "isDefinition": true |}boom|] from "./d"; +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 10 |}bar|] } from "./b";|] +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 12 |}baz|] from "./c";|] +////[|import { [|{| "declarationRangeIndex": 14 |}default|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 14 |}bang|] } from "./c";|] +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 17 |}boom|] from "./d";|] ////[|bar|](); [|baz|](); [|bang|](); [|boom|](); verify.noErrors(); -const [foo0, foo1, bar0, foo2, defaultC, defaultD, bar1, baz0, defaultE, bang0, boom0, bar2, baz1, bang1, boom1] = test.ranges(); +const [ + foo0Def, foo0, + foo1Def, foo1, bar0, + foo2Def, foo2, defaultC, + defaultDDef, defaultD, + bar1Def, bar1, + baz0Def, baz0, + defaultEDef, defaultE, bang0, + boom0Def, boom0, + bar2, baz1, bang1, boom1 +] = test.ranges(); const a = { definition: "function foo(): void", ranges: [foo0, foo1, foo2] }; const b = { definition: "(alias) function bar(): void\nexport bar", ranges: [bar0] }; const c = { definition: "(alias) function foo(): void\nexport default", ranges: [defaultC, defaultE] }; @@ -43,6 +53,7 @@ verify.referenceGroups([bang0, bang1], [eBang]); verify.referenceGroups([boom0, boom1], [eBoom, d, a, b, eBar, c, eBaz, eBang]); test.rangesByText().forEach((ranges, text) => { + if (text.indexOf("export") === 0 || text.indexOf("import") === 0) return; switch (text) { case "default": for (const range of ranges) { diff --git a/tests/cases/fourslash/findAllRefsReExports2.ts b/tests/cases/fourslash/findAllRefsReExports2.ts index 31aa07fa29e..018bc6f6e08 100644 --- a/tests/cases/fourslash/findAllRefsReExports2.ts +++ b/tests/cases/fourslash/findAllRefsReExports2.ts @@ -1,13 +1,13 @@ /// // @Filename: /a.ts -////export function [|{| "isWriteAccess": true, "isDefinition": true |}foo|](): void {} +////[|export function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|](): void {}|] // @Filename: /b.ts -////import { [|foo|] as [|{| "isWriteAccess": true, "isDefinition": true |}oof|] } from "./a"; +////[|import { [|{| "declarationRangeIndex": 2 |}foo|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}oof|] } from "./a";|] verify.noErrors(); -const [r0, r1, r2] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2] = test.ranges(); verify.referenceGroups(r0, [ { definition: "function foo(): void", ranges: [r0, r1] }, { definition: "(alias) function oof(): void\nimport oof", ranges: [r2] } diff --git a/tests/cases/fourslash/findAllRefsRedeclaredPropertyInDerivedInterface.ts b/tests/cases/fourslash/findAllRefsRedeclaredPropertyInDerivedInterface.ts index dff05b219be..7afa3d2ef03 100644 --- a/tests/cases/fourslash/findAllRefsRedeclaredPropertyInDerivedInterface.ts +++ b/tests/cases/fourslash/findAllRefsRedeclaredPropertyInDerivedInterface.ts @@ -3,17 +3,16 @@ // @noLib: true ////interface A { -//// readonly [|{| "isDefinition": true |}x|]: number | string; +//// [|readonly [|{| "isDefinition": true, "declarationRangeIndex": 0 |}x|]: number | string;|] ////} ////interface B extends A { -//// readonly [|{| "isDefinition": true |}x|]: number; +//// [|readonly [|{| "isDefinition": true, "declarationRangeIndex": 2 |}x|]: number;|] ////} -////const a: A = { [|{| "isWriteAccess": true, "isDefinition": true |}x|]: 0 }; -////const b: B = { [|{| "isWriteAccess": true, "isDefinition": true |}x|]: 0 }; +////const a: A = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}x|]: 0|] }; +////const b: B = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}x|]: 0|] }; -const ranges = test.ranges(); -const [r0, r1, r2, r3] = ranges; -verify.referenceGroups(ranges, [ +const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3] = test.ranges(); +verify.referenceGroups([r0, r1, r2, r3], [ { definition: "(property) A.x: string | number", ranges: [r0, r2] }, { definition: "(property) B.x: number", ranges: [r1, r3] }, ]); diff --git a/tests/cases/fourslash/findAllRefsRenameImportWithSameName.ts b/tests/cases/fourslash/findAllRefsRenameImportWithSameName.ts index 38c3aaf9398..b161c467d73 100644 --- a/tests/cases/fourslash/findAllRefsRenameImportWithSameName.ts +++ b/tests/cases/fourslash/findAllRefsRenameImportWithSameName.ts @@ -1,14 +1,14 @@ /// // @Filename: /a.ts -////export const [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 0; +////[|export const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|] = 0;|] //@Filename: /b.ts -////import { [|x|] as [|{| "isWriteAccess": true, "isDefinition": true |}x|] } from "./a"; +////[|import { [|{| "declarationRangeIndex": 2 |}x|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}x|] } from "./a";|] ////[|x|]; verify.noErrors(); -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2, r3] = test.ranges(); const aRanges = [r0, r1]; const bRanges = [r2, r3]; const aGroup = { definition: "const x: 0", ranges: aRanges }; diff --git a/tests/cases/fourslash/findAllRefsRootSymbols.ts b/tests/cases/fourslash/findAllRefsRootSymbols.ts index 18fbb8e212c..3718562cb7f 100644 --- a/tests/cases/fourslash/findAllRefsRootSymbols.ts +++ b/tests/cases/fourslash/findAllRefsRootSymbols.ts @@ -1,11 +1,11 @@ /// -////interface I { [|{| "isDefinition": true |}x|]: {}; } -////interface J { [|{| "isDefinition": true |}x|]: {}; } -////declare const o: (I | J) & { [|{| "isWriteAccess": true, "isDefinition": true |}x|]: string }; +////interface I { [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}x|]: {};|] } +////interface J { [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}x|]: {};|] } +////declare const o: (I | J) & { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}x|]: string|] }; ////o.[|x|]; -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3] = test.ranges(); const i = { definition: "(property) I.x: {}", ranges: [r0] }; const j = { definition: "(property) J.x: {}", ranges: [r1] }; const anon = { definition: "(property) x: string", ranges: [r2] }; diff --git a/tests/cases/fourslash/findAllRefsThisKeyword.ts b/tests/cases/fourslash/findAllRefsThisKeyword.ts index b0045e91bc1..25601011ad2 100644 --- a/tests/cases/fourslash/findAllRefsThisKeyword.ts +++ b/tests/cases/fourslash/findAllRefsThisKeyword.ts @@ -21,10 +21,10 @@ //// } ////} ////// These are *not* real uses of the 'this' keyword, they are identifiers. -////const x = { [|{| "isWriteAccess": true, "isDefinition": true |}this|]: 0 } +////const x = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 9 |}this|]: 0|] } ////x.[|this|]; -const [glob, f0, f1, g0, g1, x, y, constructor, method, propDef, propUse] = test.ranges(); +const [glob, f0, f1, g0, g1, x, y, constructor, method, propDefDef, propDef, propUse] = test.ranges(); verify.singleReferenceGroup("this: typeof globalThis", [glob]); verify.singleReferenceGroup("(parameter) this: any", [f0, f1]); verify.singleReferenceGroup("(parameter) this: any", [g0, g1]); diff --git a/tests/cases/fourslash/findAllRefsTypedef.ts b/tests/cases/fourslash/findAllRefsTypedef.ts index 2e7d8601656..3ca4e51cacd 100644 --- a/tests/cases/fourslash/findAllRefsTypedef.ts +++ b/tests/cases/fourslash/findAllRefsTypedef.ts @@ -5,11 +5,11 @@ // @Filename: /a.js /////** //// * @typedef I {Object} -//// * @prop [|{| "isDefinition": true |}p|] {number} -//// */ +//// * [|@prop [|{| "isDefinition": true, "declarationRangeIndex": 0 |}p|] {number} +//// |]*/ //// /////** @type {I} */ ////let x; ////x.[|p|]; -verify.singleReferenceGroup("(property) p: number"); +verify.singleReferenceGroup("(property) p: number", test.rangesByText().get("p")); diff --git a/tests/cases/fourslash/findAllRefsTypedef_importType.ts b/tests/cases/fourslash/findAllRefsTypedef_importType.ts index ddd0cb7c966..aad77aeb712 100644 --- a/tests/cases/fourslash/findAllRefsTypedef_importType.ts +++ b/tests/cases/fourslash/findAllRefsTypedef_importType.ts @@ -4,11 +4,11 @@ // @Filename: /a.js ////module.exports = 0; -/////** @typedef {number} [|{| "isWriteAccess": true, "isDefinition": true |}Foo|] */ +/////** [|@typedef {number} [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Foo|]|] */ ////const dummy = 0; // @Filename: /b.js /////** @type {import('./a').[|Foo|]} */ ////const x = 0; -verify.singleReferenceGroup("type Foo = number"); +verify.singleReferenceGroup("type Foo = number", test.rangesByText().get("Foo")); diff --git a/tests/cases/fourslash/findAllRefsTypeofImport.ts b/tests/cases/fourslash/findAllRefsTypeofImport.ts index 77bd2d51a8c..133d2275a31 100644 --- a/tests/cases/fourslash/findAllRefsTypeofImport.ts +++ b/tests/cases/fourslash/findAllRefsTypeofImport.ts @@ -1,8 +1,8 @@ /// // @Filename: /a.ts -////export const [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 0; +////[|export const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|] = 0;|] ////declare const a: typeof import("./a"); ////a.[|x|]; -verify.singleReferenceGroup("const x: 0"); +verify.singleReferenceGroup("const x: 0", test.rangesByText().get("x")); From edffcce785044047b49669746c285f41958ff2a4 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 5 Jun 2019 13:45:03 -0700 Subject: [PATCH 25/44] Take optional texts to verify parameter for rangesWithSameTextAreRenameLocations --- src/harness/fourslash.ts | 13 +++++++--- .../fourslash/findAllRefsOnImportAliases2.ts | 8 +++--- tests/cases/fourslash/fourslash.ts | 2 +- tests/cases/fourslash/javaScriptClass2.ts | 2 +- tests/cases/fourslash/jsxSpreadReference.ts | 3 +-- .../fourslash/renameAcrossMultipleProjects.ts | 3 +-- tests/cases/fourslash/renameAlias.ts | 3 +-- tests/cases/fourslash/renameAlias2.ts | 3 +-- tests/cases/fourslash/renameAlias3.ts | 3 +-- .../fourslash/renameAliasExternalModule.ts | 3 +-- .../fourslash/renameAliasExternalModule3.ts | 3 +-- .../fourslash/renameCommentsAndStrings1.ts | 3 +-- .../renameContextuallyTypedProperties.ts | 2 +- .../renameContextuallyTypedProperties2.ts | 2 +- .../renameDestructuringAssignment.ts | 2 +- .../fourslash/renameImportOfExportEquals2.ts | 5 +--- .../fourslash/renameInheritedProperties1.ts | 3 +-- .../fourslash/renameInheritedProperties2.ts | 3 +-- .../fourslash/renameInheritedProperties3.ts | 3 +-- .../fourslash/renameInheritedProperties4.ts | 3 +-- .../fourslash/renameInheritedProperties5.ts | 3 +-- .../fourslash/renameInheritedProperties6.ts | 3 +-- .../fourslash/renameInheritedProperties7.ts | 3 +-- .../fourslash/renameInheritedProperties8.ts | 2 +- .../fourslash/renameJsPropertyAssignment.ts | 3 +-- .../fourslash/renameJsPropertyAssignment2.ts | 3 +-- .../fourslash/renameJsPropertyAssignment3.ts | 3 +-- .../fourslash/renameJsPrototypeProperty01.ts | 3 +-- .../fourslash/renameJsPrototypeProperty02.ts | 3 +-- .../cases/fourslash/renameJsThisProperty01.ts | 3 +-- .../cases/fourslash/renameJsThisProperty03.ts | 3 +-- .../cases/fourslash/renameJsThisProperty05.ts | 3 +-- .../cases/fourslash/renameJsThisProperty06.ts | 3 +-- .../renameLocationsForClassExpression01.ts | 3 +-- .../renameLocationsForFunctionExpression01.ts | 3 +-- .../renameLocationsForFunctionExpression02.ts | 3 +-- ...enameObjectBindingElementPropertyName01.ts | 2 +- .../renameParameterPropertyDeclaration1.ts | 3 +-- .../renameParameterPropertyDeclaration2.ts | 3 +-- .../renameParameterPropertyDeclaration3.ts | 3 +-- .../renameParameterPropertyDeclaration5.ts | 3 +-- ...ePropertyAccessExpressionHeritageClause.ts | 3 +-- tests/cases/fourslash/renameRest.ts | 4 +-- .../fourslash/renameStringPropertyNames.ts | 3 +-- .../cases/fourslash/renameUMDModuleAlias1.ts | 3 +-- tests/cases/fourslash/tsxRename1.ts | 3 +-- tests/cases/fourslash/tsxRename2.ts | 3 +-- tests/cases/fourslash/tsxRename3.ts | 3 +-- tests/cases/fourslash/tsxRename4.ts | 5 +--- tests/cases/fourslash/tsxRename5.ts | 3 +-- tests/cases/fourslash/tsxRename6.ts | 4 +-- tests/cases/fourslash/tsxRename7.ts | 3 +-- tests/cases/fourslash/tsxRename9.ts | 26 +++++-------------- 53 files changed, 70 insertions(+), 126 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 5610eaf1510..ace3df96daa 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2720,8 +2720,13 @@ Actual: ${stringify(fullActual)}`); } } - public verifyRangesWithSameTextAreRenameLocations() { - this.rangesByText().forEach(ranges => this.verifyRangesAreRenameLocations(ranges)); + public verifyRangesWithSameTextAreRenameLocations(...texts: string[]) { + if (texts.length) { + texts.forEach(text => this.verifyRangesAreRenameLocations(this.rangesByText().get(text)!)); + } + else { + this.rangesByText().forEach(ranges => this.verifyRangesAreRenameLocations(ranges)); + } } public verifyRangesWithSameTextAreDocumentHighlights() { @@ -4088,8 +4093,8 @@ namespace FourSlashInterface { this.state.verifyRangesAreOccurrences(isWriteAccess, ranges); } - public rangesWithSameTextAreRenameLocations() { - this.state.verifyRangesWithSameTextAreRenameLocations(); + public rangesWithSameTextAreRenameLocations(...texts: string[]) { + this.state.verifyRangesWithSameTextAreRenameLocations(...texts); } public rangesAreRenameLocations(options?: FourSlash.Range[] | { findInStrings?: boolean, findInComments?: boolean, ranges?: FourSlash.Range[] }) { diff --git a/tests/cases/fourslash/findAllRefsOnImportAliases2.ts b/tests/cases/fourslash/findAllRefsOnImportAliases2.ts index 7be887c6af2..6faccc01dc9 100644 --- a/tests/cases/fourslash/findAllRefsOnImportAliases2.ts +++ b/tests/cases/fourslash/findAllRefsOnImportAliases2.ts @@ -1,14 +1,14 @@ /// //@Filename: a.ts -////export class [|{| "isWriteAccess": true, "isDefinition": true |}Class|] {} +////[|export class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Class|] {}|] //@Filename: b.ts -////import { [|Class|] as [|{| "isWriteAccess": true, "isDefinition": true |}C2|] } from "./a"; +////[|import { [|{| "declarationRangeIndex": 2 |}Class|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}C2|] } from "./a";|] ////var c = new [|C2|](); //@Filename: c.ts -////export { [|Class|] as [|{| "isWriteAccess": true, "isDefinition": true |}C3|] } from "./a"; +////[|export { [|{| "declarationRangeIndex": 6 |}Class|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}C3|] } from "./a";|] const ranges = test.rangesByText(); const classRanges = ranges.get("Class"); @@ -26,4 +26,4 @@ verify.referenceGroups(c2Ranges, [c2s]) verify.referenceGroups(c3Ranges, [c3s]); -verify.rangesWithSameTextAreRenameLocations(); +verify.rangesWithSameTextAreRenameLocations("Class", "C2", "C3"); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index b01f8842dee..249d6d909c1 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -229,7 +229,7 @@ declare namespace FourSlashInterface { referenceGroups(starts: ArrayOrSingle | ArrayOrSingle, parts: ReadonlyArray): void; singleReferenceGroup(definition: ReferencesDefinition, ranges?: Range[]): void; rangesAreOccurrences(isWriteAccess?: boolean, ranges?: Range[]): void; - rangesWithSameTextAreRenameLocations(): void; + rangesWithSameTextAreRenameLocations(...texts: string[]): void; rangesAreRenameLocations(options?: Range[] | { findInStrings?: boolean, findInComments?: boolean, ranges?: Range[] }); findReferencesDefinitionDisplayPartsAtCaretAre(expected: ts.SymbolDisplayPart[]): void; noSignatureHelp(...markers: string[]): void; diff --git a/tests/cases/fourslash/javaScriptClass2.ts b/tests/cases/fourslash/javaScriptClass2.ts index 130976dfe57..d13a7727214 100644 --- a/tests/cases/fourslash/javaScriptClass2.ts +++ b/tests/cases/fourslash/javaScriptClass2.ts @@ -14,4 +14,4 @@ //// var x = new Foo(); //// x.[|union|]; -verify.rangesAreRenameLocations(test.rangesByText().get("union")); +verify.rangesWithSameTextAreRenameLocations("union"); diff --git a/tests/cases/fourslash/jsxSpreadReference.ts b/tests/cases/fourslash/jsxSpreadReference.ts index 3b8b9e9425a..310b5cbadb4 100644 --- a/tests/cases/fourslash/jsxSpreadReference.ts +++ b/tests/cases/fourslash/jsxSpreadReference.ts @@ -18,5 +18,4 @@ //// var x = ; verify.goToDefinition("src", "dst"); -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("nn"); diff --git a/tests/cases/fourslash/renameAcrossMultipleProjects.ts b/tests/cases/fourslash/renameAcrossMultipleProjects.ts index 272fe2bb393..adad26a957a 100644 --- a/tests/cases/fourslash/renameAcrossMultipleProjects.ts +++ b/tests/cases/fourslash/renameAcrossMultipleProjects.ts @@ -11,5 +11,4 @@ /////// ////[|x|]++; -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("x"); diff --git a/tests/cases/fourslash/renameAlias.ts b/tests/cases/fourslash/renameAlias.ts index 18b9ff47010..58dfc4c460e 100644 --- a/tests/cases/fourslash/renameAlias.ts +++ b/tests/cases/fourslash/renameAlias.ts @@ -4,5 +4,4 @@ ////[|import [|{| "declarationRangeIndex": 0 |}M|] = SomeModule;|] ////import C = [|M|].SomeClass; -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("M"); diff --git a/tests/cases/fourslash/renameAlias2.ts b/tests/cases/fourslash/renameAlias2.ts index 4559976af80..25540f45304 100644 --- a/tests/cases/fourslash/renameAlias2.ts +++ b/tests/cases/fourslash/renameAlias2.ts @@ -4,5 +4,4 @@ ////import M = [|SomeModule|]; ////import C = M.SomeClass; -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); \ No newline at end of file +verify.rangesWithSameTextAreRenameLocations("SomeModule"); \ No newline at end of file diff --git a/tests/cases/fourslash/renameAlias3.ts b/tests/cases/fourslash/renameAlias3.ts index 70e3446dbe0..d20b58c75e8 100644 --- a/tests/cases/fourslash/renameAlias3.ts +++ b/tests/cases/fourslash/renameAlias3.ts @@ -4,5 +4,4 @@ ////import M = SomeModule; ////import C = M.[|SomeClass|]; -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("SomeClass"); diff --git a/tests/cases/fourslash/renameAliasExternalModule.ts b/tests/cases/fourslash/renameAliasExternalModule.ts index 8d753febc2b..71bce0dd282 100644 --- a/tests/cases/fourslash/renameAliasExternalModule.ts +++ b/tests/cases/fourslash/renameAliasExternalModule.ts @@ -8,5 +8,4 @@ ////[|import [|{| "declarationRangeIndex": 0 |}M|] = require("./a");|] ////import C = [|M|].SomeClass; -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("M"); diff --git a/tests/cases/fourslash/renameAliasExternalModule3.ts b/tests/cases/fourslash/renameAliasExternalModule3.ts index 6966b94b8a6..1d2df353a3f 100644 --- a/tests/cases/fourslash/renameAliasExternalModule3.ts +++ b/tests/cases/fourslash/renameAliasExternalModule3.ts @@ -8,5 +8,4 @@ ////import M = require("./a"); ////import C = M.[|SomeClass|]; -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("SomeClass"); diff --git a/tests/cases/fourslash/renameCommentsAndStrings1.ts b/tests/cases/fourslash/renameCommentsAndStrings1.ts index 7d3f5890b7d..cef7088b09c 100644 --- a/tests/cases/fourslash/renameCommentsAndStrings1.ts +++ b/tests/cases/fourslash/renameCommentsAndStrings1.ts @@ -7,5 +7,4 @@ //// "this is a reference to Bar in a string" ////}|] -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("Bar"); diff --git a/tests/cases/fourslash/renameContextuallyTypedProperties.ts b/tests/cases/fourslash/renameContextuallyTypedProperties.ts index 118c53be2b7..4b5b03dbe94 100644 --- a/tests/cases/fourslash/renameContextuallyTypedProperties.ts +++ b/tests/cases/fourslash/renameContextuallyTypedProperties.ts @@ -55,4 +55,4 @@ //// set ["prop2"](v) { } ////}; -verify.rangesAreRenameLocations(test.rangesByText().get("prop1")); +verify.rangesWithSameTextAreRenameLocations("prop1"); diff --git a/tests/cases/fourslash/renameContextuallyTypedProperties2.ts b/tests/cases/fourslash/renameContextuallyTypedProperties2.ts index 5439a2215d2..44bc668fd25 100644 --- a/tests/cases/fourslash/renameContextuallyTypedProperties2.ts +++ b/tests/cases/fourslash/renameContextuallyTypedProperties2.ts @@ -55,4 +55,4 @@ //// [|set ["[|{| "declarationRangeIndex": 20 |}prop2|]"](v) { }|] ////}; -verify.rangesAreRenameLocations(test.rangesByText().get("prop2")); +verify.rangesWithSameTextAreRenameLocations("prop2"); diff --git a/tests/cases/fourslash/renameDestructuringAssignment.ts b/tests/cases/fourslash/renameDestructuringAssignment.ts index 7833f4166a2..cc4a9eb6fe1 100644 --- a/tests/cases/fourslash/renameDestructuringAssignment.ts +++ b/tests/cases/fourslash/renameDestructuringAssignment.ts @@ -7,4 +7,4 @@ ////var x; ////([|{ [|{| "declarationRangeIndex": 2 |}x|]: x } = a|]); -verify.rangesAreRenameLocations(test.rangesByText().get("x")); +verify.rangesWithSameTextAreRenameLocations("x"); diff --git a/tests/cases/fourslash/renameImportOfExportEquals2.ts b/tests/cases/fourslash/renameImportOfExportEquals2.ts index 67cb06b761b..df915f45fb7 100644 --- a/tests/cases/fourslash/renameImportOfExportEquals2.ts +++ b/tests/cases/fourslash/renameImportOfExportEquals2.ts @@ -33,7 +33,4 @@ verify.referenceGroups(oRanges, [os, ps, qs]); verify.referenceGroups(pRanges, [ps, qs]); verify.referenceGroups(qRanges, [qs]); -verify.rangesAreRenameLocations(nRanges); -verify.rangesAreRenameLocations(oRanges); -verify.rangesAreRenameLocations(pRanges); -verify.rangesAreRenameLocations(qRanges); +verify.rangesWithSameTextAreRenameLocations("N", "O", "P", "Q"); \ No newline at end of file diff --git a/tests/cases/fourslash/renameInheritedProperties1.ts b/tests/cases/fourslash/renameInheritedProperties1.ts index 2cd8ec23781..784d77cb609 100644 --- a/tests/cases/fourslash/renameInheritedProperties1.ts +++ b/tests/cases/fourslash/renameInheritedProperties1.ts @@ -7,5 +7,4 @@ //// var v: class1; //// v.[|propName|]; -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("propName"); diff --git a/tests/cases/fourslash/renameInheritedProperties2.ts b/tests/cases/fourslash/renameInheritedProperties2.ts index de6c6e14d15..632ff0b30ca 100644 --- a/tests/cases/fourslash/renameInheritedProperties2.ts +++ b/tests/cases/fourslash/renameInheritedProperties2.ts @@ -7,5 +7,4 @@ //// var v: class1; //// v.[|doStuff|](); -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("doStuff"); diff --git a/tests/cases/fourslash/renameInheritedProperties3.ts b/tests/cases/fourslash/renameInheritedProperties3.ts index 9d8e9b65476..511bf8e0a01 100644 --- a/tests/cases/fourslash/renameInheritedProperties3.ts +++ b/tests/cases/fourslash/renameInheritedProperties3.ts @@ -7,5 +7,4 @@ //// var v: interface1; //// v.[|propName|]; -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("propName"); diff --git a/tests/cases/fourslash/renameInheritedProperties4.ts b/tests/cases/fourslash/renameInheritedProperties4.ts index 1fe0bc9de7b..e3ac0da7e63 100644 --- a/tests/cases/fourslash/renameInheritedProperties4.ts +++ b/tests/cases/fourslash/renameInheritedProperties4.ts @@ -7,5 +7,4 @@ //// var v: interface1; //// v.[|doStuff|](); -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("doStuff"); diff --git a/tests/cases/fourslash/renameInheritedProperties5.ts b/tests/cases/fourslash/renameInheritedProperties5.ts index 352201999a4..2c6340eaab2 100644 --- a/tests/cases/fourslash/renameInheritedProperties5.ts +++ b/tests/cases/fourslash/renameInheritedProperties5.ts @@ -9,6 +9,5 @@ //// var d: D; //// d.[|propD|]; -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("propD"); diff --git a/tests/cases/fourslash/renameInheritedProperties6.ts b/tests/cases/fourslash/renameInheritedProperties6.ts index 5f997f3c664..a07587bb9ff 100644 --- a/tests/cases/fourslash/renameInheritedProperties6.ts +++ b/tests/cases/fourslash/renameInheritedProperties6.ts @@ -9,5 +9,4 @@ //// var d: D; //// d.[|propC|]; -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("propC"); diff --git a/tests/cases/fourslash/renameInheritedProperties7.ts b/tests/cases/fourslash/renameInheritedProperties7.ts index 94becfd2e5b..38d36a5416c 100644 --- a/tests/cases/fourslash/renameInheritedProperties7.ts +++ b/tests/cases/fourslash/renameInheritedProperties7.ts @@ -11,5 +11,4 @@ //// var c: C; //// c.[|prop1|]; -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("prop1"); diff --git a/tests/cases/fourslash/renameInheritedProperties8.ts b/tests/cases/fourslash/renameInheritedProperties8.ts index f27ded79dae..4762178aacf 100644 --- a/tests/cases/fourslash/renameInheritedProperties8.ts +++ b/tests/cases/fourslash/renameInheritedProperties8.ts @@ -11,4 +11,4 @@ //// var c: C; //// c.[|prop1|]; -verify.rangesAreRenameLocations(test.rangesByText().get("prop1")); +verify.rangesWithSameTextAreRenameLocations("prop1"); diff --git a/tests/cases/fourslash/renameJsPropertyAssignment.ts b/tests/cases/fourslash/renameJsPropertyAssignment.ts index a764bc18fd9..75b1a486255 100644 --- a/tests/cases/fourslash/renameJsPropertyAssignment.ts +++ b/tests/cases/fourslash/renameJsPropertyAssignment.ts @@ -7,5 +7,4 @@ ////[|bar.[|{| "declarationRangeIndex": 0 |}foo|] = "foo";|] ////console.log(bar.[|foo|]); -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("foo"); diff --git a/tests/cases/fourslash/renameJsPropertyAssignment2.ts b/tests/cases/fourslash/renameJsPropertyAssignment2.ts index dbd1749b3ed..0539fcf87d6 100644 --- a/tests/cases/fourslash/renameJsPropertyAssignment2.ts +++ b/tests/cases/fourslash/renameJsPropertyAssignment2.ts @@ -7,5 +7,4 @@ ////[|Minimatch.[|{| "declarationRangeIndex": 0 |}staticProperty|] = "string";|] ////console.log(Minimatch.[|staticProperty|]); -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("staticProperty"); diff --git a/tests/cases/fourslash/renameJsPropertyAssignment3.ts b/tests/cases/fourslash/renameJsPropertyAssignment3.ts index 462fbd06c8c..acd44682b41 100644 --- a/tests/cases/fourslash/renameJsPropertyAssignment3.ts +++ b/tests/cases/fourslash/renameJsPropertyAssignment3.ts @@ -7,5 +7,4 @@ ////[|C.[|{| "declarationRangeIndex": 0 |}staticProperty|] = "string";|] ////console.log(C.[|staticProperty|]); -const [rDef, ...ranges] = test.ranges(); -verify.rangesAreRenameLocations(ranges); +verify.rangesWithSameTextAreRenameLocations("staticProperty"); diff --git a/tests/cases/fourslash/renameJsPrototypeProperty01.ts b/tests/cases/fourslash/renameJsPrototypeProperty01.ts index b171ccdf005..519c161e727 100644 --- a/tests/cases/fourslash/renameJsPrototypeProperty01.ts +++ b/tests/cases/fourslash/renameJsPrototypeProperty01.ts @@ -8,5 +8,4 @@ ////var t = new bar(); ////[|t.[|{| "declarationRangeIndex": 2 |}x|] = 11;|] -const [r0Def, r0, r1Def, r1] = test.ranges(); -verify.rangesAreRenameLocations([r0, r1]); +verify.rangesWithSameTextAreRenameLocations("x"); diff --git a/tests/cases/fourslash/renameJsPrototypeProperty02.ts b/tests/cases/fourslash/renameJsPrototypeProperty02.ts index b171ccdf005..519c161e727 100644 --- a/tests/cases/fourslash/renameJsPrototypeProperty02.ts +++ b/tests/cases/fourslash/renameJsPrototypeProperty02.ts @@ -8,5 +8,4 @@ ////var t = new bar(); ////[|t.[|{| "declarationRangeIndex": 2 |}x|] = 11;|] -const [r0Def, r0, r1Def, r1] = test.ranges(); -verify.rangesAreRenameLocations([r0, r1]); +verify.rangesWithSameTextAreRenameLocations("x"); diff --git a/tests/cases/fourslash/renameJsThisProperty01.ts b/tests/cases/fourslash/renameJsThisProperty01.ts index 7cd55020e20..d08e11455bc 100644 --- a/tests/cases/fourslash/renameJsThisProperty01.ts +++ b/tests/cases/fourslash/renameJsThisProperty01.ts @@ -8,5 +8,4 @@ ////var t = new bar(); ////[|t.[|{| "declarationRangeIndex": 2 |}x|] = 11;|] -const [r0Def, r0, r1Def, r1] = test.ranges(); -verify.rangesAreRenameLocations([r0, r1]); +verify.rangesWithSameTextAreRenameLocations("x"); diff --git a/tests/cases/fourslash/renameJsThisProperty03.ts b/tests/cases/fourslash/renameJsThisProperty03.ts index da5fc01e57a..14150674e91 100644 --- a/tests/cases/fourslash/renameJsThisProperty03.ts +++ b/tests/cases/fourslash/renameJsThisProperty03.ts @@ -10,5 +10,4 @@ ////var t = new C(12); ////[|t.[|{| "declarationRangeIndex": 2 |}x|] = 11;|] -const [rDef, r0, r1Def, r1] = test.ranges(); -verify.rangesAreRenameLocations([r0, r1]); +verify.rangesWithSameTextAreRenameLocations("x"); diff --git a/tests/cases/fourslash/renameJsThisProperty05.ts b/tests/cases/fourslash/renameJsThisProperty05.ts index 95a514e0abc..1277df32288 100644 --- a/tests/cases/fourslash/renameJsThisProperty05.ts +++ b/tests/cases/fourslash/renameJsThisProperty05.ts @@ -11,5 +11,4 @@ ////var t = new C(12); ////[|t.[|{| "declarationRangeIndex": 2 |}z|] = 11;|] -const [r0Def, r0, r1Def, r1] = test.ranges(); -verify.rangesAreRenameLocations([r0, r1]); +verify.rangesWithSameTextAreRenameLocations("z"); diff --git a/tests/cases/fourslash/renameJsThisProperty06.ts b/tests/cases/fourslash/renameJsThisProperty06.ts index e7ae3256139..ab773cc2764 100644 --- a/tests/cases/fourslash/renameJsThisProperty06.ts +++ b/tests/cases/fourslash/renameJsThisProperty06.ts @@ -11,5 +11,4 @@ ////var t = new C(12); ////[|t.[|{| "declarationRangeIndex": 2 |}z|] = 11;|] -const [r0Def, r0, r1Def, r1] = test.ranges(); -verify.rangesAreRenameLocations([r0, r1]); +verify.rangesWithSameTextAreRenameLocations("z"); diff --git a/tests/cases/fourslash/renameLocationsForClassExpression01.ts b/tests/cases/fourslash/renameLocationsForClassExpression01.ts index 6379306608e..b6bdb7eccb0 100644 --- a/tests/cases/fourslash/renameLocationsForClassExpression01.ts +++ b/tests/cases/fourslash/renameLocationsForClassExpression01.ts @@ -20,5 +20,4 @@ ////} ////var z = class Foo {} -const [rDef, ...rest] = test.ranges(); -verify.rangesAreRenameLocations(rest); +verify.rangesWithSameTextAreRenameLocations("Foo"); diff --git a/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts b/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts index e32a080683a..f0ff6ee222d 100644 --- a/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts +++ b/tests/cases/fourslash/renameLocationsForFunctionExpression01.ts @@ -4,5 +4,4 @@ //// [|f|]([|f|], g); ////}|] -const [rDef, ...rest] = test.ranges(); -verify.rangesAreRenameLocations(rest); +verify.rangesWithSameTextAreRenameLocations("f"); diff --git a/tests/cases/fourslash/renameLocationsForFunctionExpression02.ts b/tests/cases/fourslash/renameLocationsForFunctionExpression02.ts index ab835b5305c..0eb34d2baf9 100644 --- a/tests/cases/fourslash/renameLocationsForFunctionExpression02.ts +++ b/tests/cases/fourslash/renameLocationsForFunctionExpression02.ts @@ -10,5 +10,4 @@ //// let foo = () => [|f|]([|f|], g); ////}|] -const [rDef, ...rest] = test.ranges(); -verify.rangesAreRenameLocations(rest); +verify.rangesWithSameTextAreRenameLocations("f"); diff --git a/tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts b/tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts index 526838995c3..b9f733e3bf5 100644 --- a/tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts +++ b/tests/cases/fourslash/renameObjectBindingElementPropertyName01.ts @@ -9,4 +9,4 @@ ////[|var { [|{| "declarationRangeIndex": 2 |}property1|]: prop1 } = foo;|] -verify.rangesAreRenameLocations(test.rangesByText().get("property1")); +verify.rangesWithSameTextAreRenameLocations("property1"); diff --git a/tests/cases/fourslash/renameParameterPropertyDeclaration1.ts b/tests/cases/fourslash/renameParameterPropertyDeclaration1.ts index 90939afbaa0..c3dfb37ca6f 100644 --- a/tests/cases/fourslash/renameParameterPropertyDeclaration1.ts +++ b/tests/cases/fourslash/renameParameterPropertyDeclaration1.ts @@ -7,5 +7,4 @@ //// } //// } -const [rDef, ...rest] = test.ranges(); -verify.rangesAreRenameLocations(rest); +verify.rangesWithSameTextAreRenameLocations("privateParam"); diff --git a/tests/cases/fourslash/renameParameterPropertyDeclaration2.ts b/tests/cases/fourslash/renameParameterPropertyDeclaration2.ts index a131106e4bf..a4e8acc3074 100644 --- a/tests/cases/fourslash/renameParameterPropertyDeclaration2.ts +++ b/tests/cases/fourslash/renameParameterPropertyDeclaration2.ts @@ -7,5 +7,4 @@ //// } //// } -const [rDef, ...rest] = test.ranges(); -verify.rangesAreRenameLocations(rest); +verify.rangesWithSameTextAreRenameLocations("publicParam"); diff --git a/tests/cases/fourslash/renameParameterPropertyDeclaration3.ts b/tests/cases/fourslash/renameParameterPropertyDeclaration3.ts index 73ab9b40c51..3d8b5510c98 100644 --- a/tests/cases/fourslash/renameParameterPropertyDeclaration3.ts +++ b/tests/cases/fourslash/renameParameterPropertyDeclaration3.ts @@ -7,5 +7,4 @@ //// } //// } -const [rDef, ...rest] = test.ranges(); -verify.rangesAreRenameLocations(rest); +verify.rangesWithSameTextAreRenameLocations("protectedParam"); diff --git a/tests/cases/fourslash/renameParameterPropertyDeclaration5.ts b/tests/cases/fourslash/renameParameterPropertyDeclaration5.ts index f92fd53b6f9..8cacfbad0fa 100644 --- a/tests/cases/fourslash/renameParameterPropertyDeclaration5.ts +++ b/tests/cases/fourslash/renameParameterPropertyDeclaration5.ts @@ -6,5 +6,4 @@ //// } //// } -const [rDef, ...rest] = test.ranges(); -verify.rangesAreRenameLocations(rest); +verify.rangesWithSameTextAreRenameLocations("protectedParam"); diff --git a/tests/cases/fourslash/renamePropertyAccessExpressionHeritageClause.ts b/tests/cases/fourslash/renamePropertyAccessExpressionHeritageClause.ts index ae6a1c70b90..32993d730e7 100644 --- a/tests/cases/fourslash/renamePropertyAccessExpressionHeritageClause.ts +++ b/tests/cases/fourslash/renamePropertyAccessExpressionHeritageClause.ts @@ -7,5 +7,4 @@ //// class C extends (foo()).[|B|] {} //// class C1 extends foo().[|B|] {} -const ranges = test.rangesByText(); -verify.rangesAreRenameLocations(ranges.get("B")); \ No newline at end of file +verify.rangesWithSameTextAreRenameLocations("B"); \ No newline at end of file diff --git a/tests/cases/fourslash/renameRest.ts b/tests/cases/fourslash/renameRest.ts index da1f590dd70..8540586857b 100644 --- a/tests/cases/fourslash/renameRest.ts +++ b/tests/cases/fourslash/renameRest.ts @@ -8,6 +8,4 @@ ////var { x, ...rest } = t; ////rest.[|parent|]; - -const rangesByText = test.rangesByText(); -verify.rangesAreRenameLocations(rangesByText.get("parent")); +verify.rangesWithSameTextAreRenameLocations("parent"); diff --git a/tests/cases/fourslash/renameStringPropertyNames.ts b/tests/cases/fourslash/renameStringPropertyNames.ts index 8d34ee458ea..609d45c62b3 100644 --- a/tests/cases/fourslash/renameStringPropertyNames.ts +++ b/tests/cases/fourslash/renameStringPropertyNames.ts @@ -12,5 +12,4 @@ ////o['[|prop|]']; ////o.[|prop|]; -const rangesByText = test.rangesByText(); -verify.rangesAreRenameLocations(rangesByText.get("prop")); +verify.rangesWithSameTextAreRenameLocations("prop"); diff --git a/tests/cases/fourslash/renameUMDModuleAlias1.ts b/tests/cases/fourslash/renameUMDModuleAlias1.ts index 510e117007b..36c67241a10 100644 --- a/tests/cases/fourslash/renameUMDModuleAlias1.ts +++ b/tests/cases/fourslash/renameUMDModuleAlias1.ts @@ -10,5 +10,4 @@ //// /// //// [|myLib|].doThing(); -const rangesByText = test.rangesByText(); -verify.rangesAreRenameLocations(rangesByText.get("myLib")); +verify.rangesWithSameTextAreRenameLocations("myLib"); diff --git a/tests/cases/fourslash/tsxRename1.ts b/tests/cases/fourslash/tsxRename1.ts index 25a4032032d..047bc391a38 100644 --- a/tests/cases/fourslash/tsxRename1.ts +++ b/tests/cases/fourslash/tsxRename1.ts @@ -12,5 +12,4 @@ //// } //// } //// var x = <[|div|] />; -const rangesByText = test.rangesByText(); -verify.rangesAreRenameLocations(rangesByText.get("div")); +verify.rangesWithSameTextAreRenameLocations("div"); diff --git a/tests/cases/fourslash/tsxRename2.ts b/tests/cases/fourslash/tsxRename2.ts index e79e7746d52..c6cb9d16ca8 100644 --- a/tests/cases/fourslash/tsxRename2.ts +++ b/tests/cases/fourslash/tsxRename2.ts @@ -13,5 +13,4 @@ //// } //// var x =
; -const rangesByText = test.rangesByText(); -verify.rangesAreRenameLocations(rangesByText.get("name")); +verify.rangesWithSameTextAreRenameLocations("name"); diff --git a/tests/cases/fourslash/tsxRename3.ts b/tests/cases/fourslash/tsxRename3.ts index 7970c314f45..c7c68abfa00 100644 --- a/tests/cases/fourslash/tsxRename3.ts +++ b/tests/cases/fourslash/tsxRename3.ts @@ -16,5 +16,4 @@ //// //// var x = ; -const rangesByText = test.rangesByText(); -verify.rangesAreRenameLocations(rangesByText.get("name")); +verify.rangesWithSameTextAreRenameLocations("name"); diff --git a/tests/cases/fourslash/tsxRename4.ts b/tests/cases/fourslash/tsxRename4.ts index cfd9b379fb7..0bc9fa10f0c 100644 --- a/tests/cases/fourslash/tsxRename4.ts +++ b/tests/cases/fourslash/tsxRename4.ts @@ -17,7 +17,4 @@ ////<[|div|]> verify.noErrors(); - -const rangesByText = test.rangesByText(); -verify.rangesAreRenameLocations(rangesByText.get("MyClass")); -verify.rangesAreRenameLocations(rangesByText.get("div")); \ No newline at end of file +verify.rangesWithSameTextAreRenameLocations("MyClass", "div"); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxRename5.ts b/tests/cases/fourslash/tsxRename5.ts index d57da4b083a..953e950e6a6 100644 --- a/tests/cases/fourslash/tsxRename5.ts +++ b/tests/cases/fourslash/tsxRename5.ts @@ -16,5 +16,4 @@ //// [|var [|{| "declarationRangeIndex": 0 |}nn|]: string;|] //// var x = ; -const rangesByText = test.rangesByText(); -verify.rangesAreRenameLocations(rangesByText.get("nn")); +verify.rangesWithSameTextAreRenameLocations("nn"); diff --git a/tests/cases/fourslash/tsxRename6.ts b/tests/cases/fourslash/tsxRename6.ts index 3b0068d16b9..1cafd1332b0 100644 --- a/tests/cases/fourslash/tsxRename6.ts +++ b/tests/cases/fourslash/tsxRename6.ts @@ -22,6 +22,4 @@ //// let opt3 = <[|Opt|] wrong />; //// let opt4 = <[|Opt|] propx={100} propString="hi" />; -//verify.rangesAreRenameLocations(); -const rangesByText = test.rangesByText(); -verify.rangesAreRenameLocations(rangesByText.get("Opt")); +verify.rangesWithSameTextAreRenameLocations("Opt"); diff --git a/tests/cases/fourslash/tsxRename7.ts b/tests/cases/fourslash/tsxRename7.ts index 57b5da71cfc..13b16cf0ba5 100644 --- a/tests/cases/fourslash/tsxRename7.ts +++ b/tests/cases/fourslash/tsxRename7.ts @@ -21,5 +21,4 @@ //// let opt2 = ; //// let opt3 = ; -const rangesByText = test.rangesByText(); -verify.rangesAreRenameLocations(rangesByText.get("propx")); +verify.rangesWithSameTextAreRenameLocations("propx"); diff --git a/tests/cases/fourslash/tsxRename9.ts b/tests/cases/fourslash/tsxRename9.ts index 8de7a1c6d86..29a54d51cae 100644 --- a/tests/cases/fourslash/tsxRename9.ts +++ b/tests/cases/fourslash/tsxRename9.ts @@ -30,22 +30,10 @@ //// let opt = <[|MainButton|] [|[|{| "declarationRangeIndex": 20 |}goTo|]="goTo"|] />; //// let opt = <[|MainButton|] [|wrong|] />; -const [ - onClickDef_0, onClick_1, - goToDef_2, goTo_3, - mainButtonDef_4, mainButton_5, - mainButtonDef_6, mainButton_7, - mainButtonDef_8, mainButton_9, - mainButton_10, - mainButton_11, - mainButton_12, onClickDef_13, onClick_14, - mainButton_15, onClickDef_16, onClick_17, ignoreProp_18, - mainButton_19, goToDef_20, goTo_21, - mainButton_22, wrong_23 -] = test.ranges(); -const rangesByText = test.rangesByText(); -verify.rangesAreRenameLocations(rangesByText.get("onClick")); -verify.rangesAreRenameLocations(rangesByText.get("goTo")); -verify.rangesAreRenameLocations(rangesByText.get("MainButton")); -verify.rangesAreRenameLocations(rangesByText.get("ignore-prop")); -verify.rangesAreRenameLocations(rangesByText.get("wrong")); \ No newline at end of file +verify.rangesWithSameTextAreRenameLocations( + "onClick", + "goTo", + "MainButton", + "ignore-prop", + "wrong" +); \ No newline at end of file From 6dc2ba793913ee372b8c7669493240365d00cfe3 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 5 Jun 2019 14:10:51 -0700 Subject: [PATCH 26/44] Take optional string of range text for singleReferenceGroup --- src/harness/fourslash.ts | 6 +++--- tests/cases/fourslash/findAllRefsOnDecorators.ts | 2 +- tests/cases/fourslash/findAllRefsOnDefinition.ts | 2 +- tests/cases/fourslash/findAllRefsOnDefinition2.ts | 2 +- .../findAllRefsOnPrivateParameterProperty1.ts | 2 +- ...dAllRefsPropertyContextuallyTypedByTypeParam01.ts | 2 +- tests/cases/fourslash/findAllRefsReExport_broken.ts | 2 +- tests/cases/fourslash/findAllRefsReExport_broken2.ts | 2 +- tests/cases/fourslash/findAllRefsTypedef.ts | 2 +- .../cases/fourslash/findAllRefsTypedef_importType.ts | 2 +- tests/cases/fourslash/findAllRefsTypeofImport.ts | 2 +- .../findAllRefsWithLeadingUnderscoreNames1.ts | 2 +- .../findAllRefsWithLeadingUnderscoreNames2.ts | 2 +- .../findAllRefsWithLeadingUnderscoreNames3.ts | 2 +- .../findAllRefsWithLeadingUnderscoreNames4.ts | 2 +- .../findAllRefsWithLeadingUnderscoreNames5.ts | 2 +- .../findAllRefsWithLeadingUnderscoreNames6.ts | 2 +- .../findAllRefsWithLeadingUnderscoreNames7.ts | 2 +- .../findAllRefsWithLeadingUnderscoreNames8.ts | 2 +- .../findAllRefsWithLeadingUnderscoreNames9.ts | 2 +- tests/cases/fourslash/findAllRefs_jsEnum.ts | 2 +- .../findReferencesAcrossMultipleProjects.ts | 2 +- tests/cases/fourslash/findReferencesAfterEdit.ts | 4 ++-- tests/cases/fourslash/findReferencesJSXTagName2.ts | 2 +- tests/cases/fourslash/fourslash.ts | 2 +- .../getOccurrencesIsDefinitionOfArrowFunction.ts | 2 +- .../fourslash/getOccurrencesIsDefinitionOfClass.ts | 2 +- .../getOccurrencesIsDefinitionOfComputedProperty.ts | 2 +- .../fourslash/getOccurrencesIsDefinitionOfEnum.ts | 2 +- .../getOccurrencesIsDefinitionOfFunction.ts | 2 +- .../getOccurrencesIsDefinitionOfInterface.ts | 2 +- ...etOccurrencesIsDefinitionOfInterfaceClassMerge.ts | 2 +- .../getOccurrencesIsDefinitionOfNamespace.ts | 2 +- ...etOccurrencesIsDefinitionOfNumberNamedProperty.ts | 2 +- .../getOccurrencesIsDefinitionOfParameter.ts | 2 +- ...etOccurrencesIsDefinitionOfStringNamedProperty.ts | 2 +- .../getOccurrencesIsDefinitionOfTypeAlias.ts | 2 +- .../getOccurrencesIsDefinitionOfVariable.ts | 2 +- .../fourslash/jsdocTypedefTagSemanticMeaning1.ts | 2 +- tests/cases/fourslash/referenceToClass.ts | 3 +-- tests/cases/fourslash/referencesBloomFilters.ts | 2 +- tests/cases/fourslash/referencesBloomFilters2.ts | 2 +- tests/cases/fourslash/referencesBloomFilters3.ts | 2 +- tests/cases/fourslash/referencesForAmbients2.ts | 2 +- tests/cases/fourslash/referencesForClassLocal.ts | 2 +- tests/cases/fourslash/referencesForClassParameter.ts | 2 +- ...cesForContextuallyTypedObjectLiteralProperties.ts | 2 +- ...referencesForContextuallyTypedUnionProperties2.ts | 2 +- tests/cases/fourslash/referencesForEnums.ts | 7 +++---- tests/cases/fourslash/referencesForExportedValues.ts | 2 +- .../fourslash/referencesForExternalModuleNames.ts | 2 +- .../fourslash/referencesForFunctionOverloads.ts | 2 +- .../fourslash/referencesForFunctionParameter.ts | 2 +- tests/cases/fourslash/referencesForGlobals.ts | 2 +- tests/cases/fourslash/referencesForGlobals2.ts | 2 +- tests/cases/fourslash/referencesForGlobals3.ts | 2 +- tests/cases/fourslash/referencesForGlobals4.ts | 2 +- tests/cases/fourslash/referencesForGlobals5.ts | 2 +- .../referencesForGlobalsInExternalModule.ts | 12 ++++-------- .../fourslash/referencesForIllegalAssignment.ts | 2 +- tests/cases/fourslash/referencesForIndexProperty.ts | 5 ++--- tests/cases/fourslash/referencesForIndexProperty3.ts | 2 +- .../fourslash/referencesForInheritedProperties3.ts | 5 ++--- .../fourslash/referencesForInheritedProperties4.ts | 6 ++---- tests/cases/fourslash/referencesForLabel6.ts | 5 ++--- .../fourslash/referencesForMergedDeclarations2.ts | 2 +- .../fourslash/referencesForMergedDeclarations4.ts | 2 +- .../fourslash/referencesForMergedDeclarations6.ts | 2 +- .../fourslash/referencesForMergedDeclarations8.ts | 2 +- .../referencesForNumericLiteralPropertyNames.ts | 2 +- .../referencesForObjectLiteralProperties.ts | 3 +-- .../referencesForPropertiesOfGenericType.ts | 3 +-- tests/cases/fourslash/referencesForStatic.ts | 3 +-- .../referencesForStringLiteralPropertyNames.ts | 2 +- .../referencesForStringLiteralPropertyNames2.ts | 2 +- .../referencesForStringLiteralPropertyNames3.ts | 3 +-- tests/cases/fourslash/renameJsExports01.ts | 5 ++--- tests/cases/fourslash/tsxFindAllReferences1.ts | 5 +---- tests/cases/fourslash/tsxFindAllReferences10.ts | 6 +----- tests/cases/fourslash/tsxFindAllReferences2.ts | 6 +----- tests/cases/fourslash/tsxFindAllReferences3.ts | 6 +----- tests/cases/fourslash/tsxFindAllReferences4.ts | 6 +----- tests/cases/fourslash/tsxFindAllReferences5.ts | 3 +-- tests/cases/fourslash/tsxFindAllReferences7.ts | 6 +----- tests/cases/fourslash/tsxFindAllReferences8.ts | 3 +-- tests/cases/fourslash/tsxFindAllReferences9.ts | 3 +-- .../tsxFindAllReferencesUnionElementType1.ts | 3 +-- .../tsxFindAllReferencesUnionElementType2.ts | 3 +-- 88 files changed, 101 insertions(+), 145 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index ace3df96daa..7842798dbef 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -1001,8 +1001,8 @@ namespace FourSlash { assert.deepEqual | undefined>(refs, expected); } - public verifySingleReferenceGroup(definition: FourSlashInterface.ReferenceGroupDefinition, ranges?: Range[]) { - ranges = ranges || this.getRanges(); + public verifySingleReferenceGroup(definition: FourSlashInterface.ReferenceGroupDefinition, ranges?: Range[] | string) { + ranges = ts.isString(ranges) ? this.rangesByText().get(ranges)! : ranges || this.getRanges(); this.verifyReferenceGroups(ranges, [{ definition, ranges }]); } @@ -3971,7 +3971,7 @@ namespace FourSlashInterface { this.state.verifyGetReferencesForServerTest(expected); } - public singleReferenceGroup(definition: ReferenceGroupDefinition, ranges?: FourSlash.Range[]) { + public singleReferenceGroup(definition: ReferenceGroupDefinition, ranges?: FourSlash.Range[] | string) { this.state.verifySingleReferenceGroup(definition, ranges); } diff --git a/tests/cases/fourslash/findAllRefsOnDecorators.ts b/tests/cases/fourslash/findAllRefsOnDecorators.ts index aa8c0e0c9d2..0bb91f507ec 100644 --- a/tests/cases/fourslash/findAllRefsOnDecorators.ts +++ b/tests/cases/fourslash/findAllRefsOnDecorators.ts @@ -13,4 +13,4 @@ //// method() {} ////} -verify.singleReferenceGroup("function decorator(target: any): any", test.rangesByText().get("decorator")); +verify.singleReferenceGroup("function decorator(target: any): any", "decorator"); diff --git a/tests/cases/fourslash/findAllRefsOnDefinition.ts b/tests/cases/fourslash/findAllRefsOnDefinition.ts index da7640224e2..007b571fd03 100644 --- a/tests/cases/fourslash/findAllRefsOnDefinition.ts +++ b/tests/cases/fourslash/findAllRefsOnDefinition.ts @@ -23,4 +23,4 @@ ////second.[|start|](); ////second.stop(); -verify.singleReferenceGroup("(method) Test.start(): this", test.rangesByText().get("start")); +verify.singleReferenceGroup("(method) Test.start(): this", "start"); diff --git a/tests/cases/fourslash/findAllRefsOnDefinition2.ts b/tests/cases/fourslash/findAllRefsOnDefinition2.ts index b300213150a..1d58dd7c701 100644 --- a/tests/cases/fourslash/findAllRefsOnDefinition2.ts +++ b/tests/cases/fourslash/findAllRefsOnDefinition2.ts @@ -14,4 +14,4 @@ ////var start: Second.Test.[|start|]; ////var stop: Second.Test.stop; -verify.singleReferenceGroup("interface Test.start", test.rangesByText().get("start")); +verify.singleReferenceGroup("interface Test.start", "start"); diff --git a/tests/cases/fourslash/findAllRefsOnPrivateParameterProperty1.ts b/tests/cases/fourslash/findAllRefsOnPrivateParameterProperty1.ts index d438a87717d..f335f21a0b7 100644 --- a/tests/cases/fourslash/findAllRefsOnPrivateParameterProperty1.ts +++ b/tests/cases/fourslash/findAllRefsOnPrivateParameterProperty1.ts @@ -9,4 +9,4 @@ //// } ////} -verify.singleReferenceGroup("(property) ABCD.z: number", test.rangesByText().get("z")); +verify.singleReferenceGroup("(property) ABCD.z: number", "z"); diff --git a/tests/cases/fourslash/findAllRefsPropertyContextuallyTypedByTypeParam01.ts b/tests/cases/fourslash/findAllRefsPropertyContextuallyTypedByTypeParam01.ts index 8b8a82c169f..ec666c1d8a6 100644 --- a/tests/cases/fourslash/findAllRefsPropertyContextuallyTypedByTypeParam01.ts +++ b/tests/cases/fourslash/findAllRefsPropertyContextuallyTypedByTypeParam01.ts @@ -17,4 +17,4 @@ //// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}a|]: "ss"|] ////}; -verify.singleReferenceGroup("(property) IFoo.a: string", test.rangesByText().get("a")); +verify.singleReferenceGroup("(property) IFoo.a: string", "a"); diff --git a/tests/cases/fourslash/findAllRefsReExport_broken.ts b/tests/cases/fourslash/findAllRefsReExport_broken.ts index 3e57c60bdec..e8d35239795 100644 --- a/tests/cases/fourslash/findAllRefsReExport_broken.ts +++ b/tests/cases/fourslash/findAllRefsReExport_broken.ts @@ -3,4 +3,4 @@ // @Filename: /a.ts ////[|export { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|] };|] -verify.singleReferenceGroup("export x", test.rangesByText().get("x")); +verify.singleReferenceGroup("export x", "x"); diff --git a/tests/cases/fourslash/findAllRefsReExport_broken2.ts b/tests/cases/fourslash/findAllRefsReExport_broken2.ts index bb8291403f8..5ae6afca6a9 100644 --- a/tests/cases/fourslash/findAllRefsReExport_broken2.ts +++ b/tests/cases/fourslash/findAllRefsReExport_broken2.ts @@ -3,4 +3,4 @@ // @Filename: /a.ts ////[|export { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|] } from "nonsense";|] -verify.singleReferenceGroup("export x", test.rangesByText().get("x")); +verify.singleReferenceGroup("export x", "x"); diff --git a/tests/cases/fourslash/findAllRefsTypedef.ts b/tests/cases/fourslash/findAllRefsTypedef.ts index 3ca4e51cacd..19dd6611ba7 100644 --- a/tests/cases/fourslash/findAllRefsTypedef.ts +++ b/tests/cases/fourslash/findAllRefsTypedef.ts @@ -12,4 +12,4 @@ ////let x; ////x.[|p|]; -verify.singleReferenceGroup("(property) p: number", test.rangesByText().get("p")); +verify.singleReferenceGroup("(property) p: number", "p"); diff --git a/tests/cases/fourslash/findAllRefsTypedef_importType.ts b/tests/cases/fourslash/findAllRefsTypedef_importType.ts index aad77aeb712..ad2df19bd07 100644 --- a/tests/cases/fourslash/findAllRefsTypedef_importType.ts +++ b/tests/cases/fourslash/findAllRefsTypedef_importType.ts @@ -11,4 +11,4 @@ /////** @type {import('./a').[|Foo|]} */ ////const x = 0; -verify.singleReferenceGroup("type Foo = number", test.rangesByText().get("Foo")); +verify.singleReferenceGroup("type Foo = number", "Foo"); diff --git a/tests/cases/fourslash/findAllRefsTypeofImport.ts b/tests/cases/fourslash/findAllRefsTypeofImport.ts index 133d2275a31..4d381bedc17 100644 --- a/tests/cases/fourslash/findAllRefsTypeofImport.ts +++ b/tests/cases/fourslash/findAllRefsTypeofImport.ts @@ -5,4 +5,4 @@ ////declare const a: typeof import("./a"); ////a.[|x|]; -verify.singleReferenceGroup("const x: 0", test.rangesByText().get("x")); +verify.singleReferenceGroup("const x: 0", "x"); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames1.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames1.ts index 2ae0cc4ac71..7da05388de2 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames1.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames1.ts @@ -7,4 +7,4 @@ ////var x: Foo; ////x.[|_bar|]; -verify.singleReferenceGroup("(method) Foo._bar(): number", test.rangesByText().get("_bar")); +verify.singleReferenceGroup("(method) Foo._bar(): number", "_bar"); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames2.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames2.ts index 038e66449d4..9d64e11d64e 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames2.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames2.ts @@ -7,4 +7,4 @@ ////var x: Foo; ////x.[|__bar|]; -verify.singleReferenceGroup("(method) Foo.__bar(): number", test.rangesByText().get("__bar")); +verify.singleReferenceGroup("(method) Foo.__bar(): number", "__bar"); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames3.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames3.ts index 9c7815dea01..e93dfe75b9d 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames3.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames3.ts @@ -7,4 +7,4 @@ ////var x: Foo; ////x.[|___bar|]; -verify.singleReferenceGroup("(method) Foo.___bar(): number", test.rangesByText().get("___bar")); +verify.singleReferenceGroup("(method) Foo.___bar(): number", "___bar"); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames4.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames4.ts index 5c6566a8a0f..131cff144e4 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames4.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames4.ts @@ -7,4 +7,4 @@ ////var x: Foo; ////x.[|____bar|]; -verify.singleReferenceGroup("(method) Foo.____bar(): number", test.rangesByText().get("____bar")); +verify.singleReferenceGroup("(method) Foo.____bar(): number", "____bar"); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames5.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames5.ts index f3c807483cd..389772051e5 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames5.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames5.ts @@ -13,4 +13,4 @@ ////x.[|___bar|]; ////x.____bar; -verify.singleReferenceGroup("(property) Foo.___bar: any", test.rangesByText().get("___bar")); +verify.singleReferenceGroup("(property) Foo.___bar: any", "___bar"); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames6.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames6.ts index be8859c01a0..77fd15f1296 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames6.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames6.ts @@ -13,4 +13,4 @@ ////x.___bar; ////x.____bar; -verify.singleReferenceGroup("(property) Foo.__bar: any", test.rangesByText().get("__bar")); +verify.singleReferenceGroup("(property) Foo.__bar: any", "__bar"); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames7.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames7.ts index b6de0be25c9..2616d6f7f3c 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames7.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames7.ts @@ -4,4 +4,4 @@ //// [|__foo|](); ////}|] -verify.singleReferenceGroup("function __foo(): void", test.rangesByText().get("__foo")); +verify.singleReferenceGroup("function __foo(): void", "__foo"); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames8.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames8.ts index 945fa91e6d6..3785099aa2f 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames8.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames8.ts @@ -4,4 +4,4 @@ //// [|__foo|](); ////}|]) -verify.singleReferenceGroup("(local function) __foo(): void", test.rangesByText().get("__foo")); +verify.singleReferenceGroup("(local function) __foo(): void", "__foo"); diff --git a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames9.ts b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames9.ts index 2ff0420cc16..f4506809e76 100644 --- a/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames9.ts +++ b/tests/cases/fourslash/findAllRefsWithLeadingUnderscoreNames9.ts @@ -4,4 +4,4 @@ //// [|___foo|](); ////}|]) -verify.singleReferenceGroup("(local function) ___foo(): void", test.rangesByText().get("___foo")); +verify.singleReferenceGroup("(local function) ___foo(): void", "___foo"); diff --git a/tests/cases/fourslash/findAllRefs_jsEnum.ts b/tests/cases/fourslash/findAllRefs_jsEnum.ts index 79c007c2947..c82c2507108 100644 --- a/tests/cases/fourslash/findAllRefs_jsEnum.ts +++ b/tests/cases/fourslash/findAllRefs_jsEnum.ts @@ -13,4 +13,4 @@ verify.singleReferenceGroup( `enum E const E: { A: string; -}`, test.rangesByText().get("E")); +}`, "E"); diff --git a/tests/cases/fourslash/findReferencesAcrossMultipleProjects.ts b/tests/cases/fourslash/findReferencesAcrossMultipleProjects.ts index b94b8629620..94b07d9305e 100644 --- a/tests/cases/fourslash/findReferencesAcrossMultipleProjects.ts +++ b/tests/cases/fourslash/findReferencesAcrossMultipleProjects.ts @@ -11,4 +11,4 @@ /////// ////[|{| "isWriteAccess": true |}x|]++; -verify.singleReferenceGroup("var x: number", test.rangesByText().get("x")); +verify.singleReferenceGroup("var x: number", "x"); diff --git a/tests/cases/fourslash/findReferencesAfterEdit.ts b/tests/cases/fourslash/findReferencesAfterEdit.ts index 9a8717eb1e3..9193f10f33d 100644 --- a/tests/cases/fourslash/findReferencesAfterEdit.ts +++ b/tests/cases/fourslash/findReferencesAfterEdit.ts @@ -12,9 +12,9 @@ //// x.[|foo|] ////} -verify.singleReferenceGroup("(property) A.foo: string", test.rangesByText().get("foo")); +verify.singleReferenceGroup("(property) A.foo: string", "foo"); goTo.marker(""); edit.insert("\n"); -verify.singleReferenceGroup("(property) A.foo: string", test.rangesByText().get("foo")); +verify.singleReferenceGroup("(property) A.foo: string", "foo"); diff --git a/tests/cases/fourslash/findReferencesJSXTagName2.ts b/tests/cases/fourslash/findReferencesJSXTagName2.ts index 46133d8e339..8036b943cc8 100644 --- a/tests/cases/fourslash/findReferencesJSXTagName2.ts +++ b/tests/cases/fourslash/findReferencesJSXTagName2.ts @@ -6,4 +6,4 @@ verify.singleReferenceGroup(`const obj: { Component: () => any; -}`, test.rangesByText().get("obj")); +}`, "obj"); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 249d6d909c1..b431bd6306e 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -227,7 +227,7 @@ declare namespace FourSlashInterface { * This uses the 'findReferences' command instead of 'getReferencesAtPosition', so references are grouped by their definition. */ referenceGroups(starts: ArrayOrSingle | ArrayOrSingle, parts: ReadonlyArray): void; - singleReferenceGroup(definition: ReferencesDefinition, ranges?: Range[]): void; + singleReferenceGroup(definition: ReferencesDefinition, ranges?: Range[] | string): void; rangesAreOccurrences(isWriteAccess?: boolean, ranges?: Range[]): void; rangesWithSameTextAreRenameLocations(...texts: string[]): void; rangesAreRenameLocations(options?: Range[] | { findInStrings?: boolean, findInComments?: boolean, ranges?: Range[] }); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts index a50b2ca1149..094191f09ce 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfArrowFunction.ts @@ -2,4 +2,4 @@ ////[|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}f|] = x => x + 1;|] ////[|f|](12); -verify.singleReferenceGroup("var f: (x: any) => any", test.rangesByText().get("f")); +verify.singleReferenceGroup("var f: (x: any) => any", "f"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts index add271f14e4..7d4c3517767 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfClass.ts @@ -7,4 +7,4 @@ ////}|] ////let c = new [|C|](); -verify.singleReferenceGroup("class C", test.rangesByText().get("C")); +verify.singleReferenceGroup("class C", "C"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts index d67dfe74c95..23f3eca6cf6 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfComputedProperty.ts @@ -3,4 +3,4 @@ ////let y = o.[|foo|]; ////let z = o['[|foo|]']; -verify.singleReferenceGroup('(property) ["foo"]: number', test.rangesByText().get("foo")); +verify.singleReferenceGroup('(property) ["foo"]: number', "foo"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts index d1721c3b88b..0b76608e523 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfEnum.ts @@ -5,4 +5,4 @@ ////}|] ////let first = [|E|].First; -verify.singleReferenceGroup("enum E", test.rangesByText().get("E")); +verify.singleReferenceGroup("enum E", "E"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts index 71746119230..e45dcf110d4 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfFunction.ts @@ -3,4 +3,4 @@ ////}|] ////[|func|](x) -verify.singleReferenceGroup("function func(x: number): void", test.rangesByText().get("func")); +verify.singleReferenceGroup("function func(x: number): void", "func"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts index 57c96da1e8b..974cc7d4589 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterface.ts @@ -4,4 +4,4 @@ ////}|] ////let i: [|I|] = { p: 12 }; -verify.singleReferenceGroup("interface I", test.rangesByText().get("I")); +verify.singleReferenceGroup("interface I", "I"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts index 2ec89979df4..df19e7473e9 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfInterfaceClassMerge.ts @@ -13,4 +13,4 @@ ////let i: [|Numbers|] = new [|Numbers|](); ////let x = i.f(i.p + i.m); -verify.singleReferenceGroup("class Numbers\ninterface Numbers", test.rangesByText().get("Numbers")); +verify.singleReferenceGroup("class Numbers\ninterface Numbers", "Numbers"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts index 0fc07b3bb6b..b0f5030f454 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNamespace.ts @@ -4,4 +4,4 @@ ////}|] ////let x = [|Numbers|].n + 1; -verify.singleReferenceGroup("namespace Numbers", test.rangesByText().get("Numbers")); +verify.singleReferenceGroup("namespace Numbers", "Numbers"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts index 249d768bf11..4ace81eb773 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfNumberNamedProperty.ts @@ -2,4 +2,4 @@ ////let o = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}1|]: 12|] }; ////let y = o[[|1|]]; -verify.singleReferenceGroup("(property) 1: number", test.rangesByText().get("1")); +verify.singleReferenceGroup("(property) 1: number", "1"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts index b18fc51f8eb..8ac460150bc 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfParameter.ts @@ -3,4 +3,4 @@ //// return [|x|] + 1 ////} -verify.singleReferenceGroup("(parameter) x: number", test.rangesByText().get("x")); +verify.singleReferenceGroup("(parameter) x: number", "x"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts index 7ca03f00482..267cc1cdcbe 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfStringNamedProperty.ts @@ -2,4 +2,4 @@ ////let o = { [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|]": 12|] }; ////let y = o.[|x|]; -verify.singleReferenceGroup('(property) "x": number', test.rangesByText().get("x")); +verify.singleReferenceGroup('(property) "x": number', "x"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts index cf69914507b..122c6c8ea16 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfTypeAlias.ts @@ -2,4 +2,4 @@ ////[|type [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Alias|]= number;|] ////let n: [|Alias|] = 12; -verify.singleReferenceGroup("type Alias = number", test.rangesByText().get("Alias")); +verify.singleReferenceGroup("type Alias = number", "Alias"); diff --git a/tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts b/tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts index b3a3ab4cc17..f3667912506 100644 --- a/tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts +++ b/tests/cases/fourslash/getOccurrencesIsDefinitionOfVariable.ts @@ -17,4 +17,4 @@ ////[|{| "isWriteAccess": true |}x|] += 1; ////[|{| "isWriteAccess": true |}x|] <<= 1; -verify.singleReferenceGroup("var x: number", test.rangesByText().get("x")); +verify.singleReferenceGroup("var x: number", "x"); diff --git a/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning1.ts b/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning1.ts index 60bef778045..d5da73d588e 100644 --- a/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning1.ts +++ b/tests/cases/fourslash/jsdocTypedefTagSemanticMeaning1.ts @@ -9,4 +9,4 @@ /////** @type {[|T|]} */ ////const n = [|T|]; -verify.singleReferenceGroup("type T = number\nconst T: 1", test.rangesByText().get("T")); +verify.singleReferenceGroup("type T = number\nconst T: 1", "T"); diff --git a/tests/cases/fourslash/referenceToClass.ts b/tests/cases/fourslash/referenceToClass.ts index c1623313d84..7e0228cd8f5 100644 --- a/tests/cases/fourslash/referenceToClass.ts +++ b/tests/cases/fourslash/referenceToClass.ts @@ -20,5 +20,4 @@ // @Filename: referenceToClass_2.ts ////var k: [|foo|]; -const [rDef, ...ranges] = test.ranges(); -verify.singleReferenceGroup("class foo", ranges); +verify.singleReferenceGroup("class foo", "foo"); diff --git a/tests/cases/fourslash/referencesBloomFilters.ts b/tests/cases/fourslash/referencesBloomFilters.ts index 908339d6dce..374964a236f 100644 --- a/tests/cases/fourslash/referencesBloomFilters.ts +++ b/tests/cases/fourslash/referencesBloomFilters.ts @@ -14,4 +14,4 @@ // @Filename: redeclaration.ts ////container = { [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}searchProp|]" : 18|] }; -verify.singleReferenceGroup("(property) searchProp: number", test.rangesByText().get("searchProp")); +verify.singleReferenceGroup("(property) searchProp: number", "searchProp"); diff --git a/tests/cases/fourslash/referencesBloomFilters2.ts b/tests/cases/fourslash/referencesBloomFilters2.ts index 36890b2b87c..9dbb8b6605b 100644 --- a/tests/cases/fourslash/referencesBloomFilters2.ts +++ b/tests/cases/fourslash/referencesBloomFilters2.ts @@ -14,4 +14,4 @@ // @Filename: redeclaration.ts ////container = { [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}42|]" : 18|] }; -verify.singleReferenceGroup("(property) 42: number", test.rangesByText().get("42")); +verify.singleReferenceGroup("(property) 42: number", "42"); diff --git a/tests/cases/fourslash/referencesBloomFilters3.ts b/tests/cases/fourslash/referencesBloomFilters3.ts index 9d871047e86..b8888ca27ad 100644 --- a/tests/cases/fourslash/referencesBloomFilters3.ts +++ b/tests/cases/fourslash/referencesBloomFilters3.ts @@ -9,4 +9,4 @@ // @Filename: expression.ts ////(Test[[|42|]]); -verify.singleReferenceGroup('(enum member) Test["42"] = 1', test.rangesByText().get("42")); +verify.singleReferenceGroup('(enum member) Test["42"] = 1', "42"); diff --git a/tests/cases/fourslash/referencesForAmbients2.ts b/tests/cases/fourslash/referencesForAmbients2.ts index 3ec5b88a0a6..c0945e9a076 100644 --- a/tests/cases/fourslash/referencesForAmbients2.ts +++ b/tests/cases/fourslash/referencesForAmbients2.ts @@ -18,4 +18,4 @@ ////} verify.noErrors(); -verify.singleReferenceGroup("type T = number", test.rangesByText().get("T")); +verify.singleReferenceGroup("type T = number", "T"); diff --git a/tests/cases/fourslash/referencesForClassLocal.ts b/tests/cases/fourslash/referencesForClassLocal.ts index 6897f069245..5562666f091 100644 --- a/tests/cases/fourslash/referencesForClassLocal.ts +++ b/tests/cases/fourslash/referencesForClassLocal.ts @@ -20,4 +20,4 @@ //// } ////} -verify.singleReferenceGroup("(property) foo.n: number", test.rangesByText().get("n")); +verify.singleReferenceGroup("(property) foo.n: number", "n"); diff --git a/tests/cases/fourslash/referencesForClassParameter.ts b/tests/cases/fourslash/referencesForClassParameter.ts index 53cfba57c14..8fdf9b98154 100644 --- a/tests/cases/fourslash/referencesForClassParameter.ts +++ b/tests/cases/fourslash/referencesForClassParameter.ts @@ -19,4 +19,4 @@ ////var n = new foo(undefined); ////n.[|{| "isWriteAccess": true |}p|] = null; -verify.singleReferenceGroup("(property) foo.p: any", test.rangesByText().get("p")); +verify.singleReferenceGroup("(property) foo.p: any", "p"); diff --git a/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts b/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts index 9c510e4a097..5345d6e8aa3 100644 --- a/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts +++ b/tests/cases/fourslash/referencesForContextuallyTypedObjectLiteralProperties.ts @@ -25,4 +25,4 @@ ////// Untped -- should not be included ////var u = { xy: 0 }; -verify.singleReferenceGroup("(property) IFoo.xy: number", test.rangesByText().get("xy")); +verify.singleReferenceGroup("(property) IFoo.xy: number", "xy"); diff --git a/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts index 850561acf5c..0ad5f327995 100644 --- a/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts +++ b/tests/cases/fourslash/referencesForContextuallyTypedUnionProperties2.ts @@ -34,4 +34,4 @@ ////var u1 = { a: 0, b: 0, common: "" }; ////var u2 = { b: 0, common: 0 }; -verify.singleReferenceGroup("(property) B.b: number", test.rangesByText().get("b")); +verify.singleReferenceGroup("(property) B.b: number", "b"); diff --git a/tests/cases/fourslash/referencesForEnums.ts b/tests/cases/fourslash/referencesForEnums.ts index 2b948613704..464de3e40be 100644 --- a/tests/cases/fourslash/referencesForEnums.ts +++ b/tests/cases/fourslash/referencesForEnums.ts @@ -11,7 +11,6 @@ ////E.[|value2|]; ////E[[|111|]]; -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")); +verify.singleReferenceGroup("(enum member) E.value1 = 1", "value1"); +verify.singleReferenceGroup("(enum member) E[\"value2\"] = 1", "value2"); +verify.singleReferenceGroup("(enum member) E[111] = 11", "111"); diff --git a/tests/cases/fourslash/referencesForExportedValues.ts b/tests/cases/fourslash/referencesForExportedValues.ts index 787440606fd..547de612c58 100644 --- a/tests/cases/fourslash/referencesForExportedValues.ts +++ b/tests/cases/fourslash/referencesForExportedValues.ts @@ -10,4 +10,4 @@ ////// external use ////M.[|variable|] -verify.singleReferenceGroup("var M.variable: number", test.rangesByText().get("variable")); +verify.singleReferenceGroup("var M.variable: number", "variable"); diff --git a/tests/cases/fourslash/referencesForExternalModuleNames.ts b/tests/cases/fourslash/referencesForExternalModuleNames.ts index 2929391228e..6fafec9f690 100644 --- a/tests/cases/fourslash/referencesForExternalModuleNames.ts +++ b/tests/cases/fourslash/referencesForExternalModuleNames.ts @@ -8,4 +8,4 @@ // @Filename: referencesForGlobals_2.ts ////import f = require("[|foo|]"); -verify.singleReferenceGroup('module "foo"', test.rangesByText().get("foo")); +verify.singleReferenceGroup('module "foo"', "foo"); diff --git a/tests/cases/fourslash/referencesForFunctionOverloads.ts b/tests/cases/fourslash/referencesForFunctionOverloads.ts index b086014a050..da9ad0e70f5 100644 --- a/tests/cases/fourslash/referencesForFunctionOverloads.ts +++ b/tests/cases/fourslash/referencesForFunctionOverloads.ts @@ -7,4 +7,4 @@ //// [|foo|]('', 43); ////}|] -verify.singleReferenceGroup("function foo(x: string): any", test.rangesByText().get("foo")); +verify.singleReferenceGroup("function foo(x: string): any", "foo"); diff --git a/tests/cases/fourslash/referencesForFunctionParameter.ts b/tests/cases/fourslash/referencesForFunctionParameter.ts index 267965e7044..d7fbc947fac 100644 --- a/tests/cases/fourslash/referencesForFunctionParameter.ts +++ b/tests/cases/fourslash/referencesForFunctionParameter.ts @@ -8,4 +8,4 @@ //// x = [|n|]; ////} -verify.singleReferenceGroup("(parameter) n: number", test.rangesByText().get("n")); +verify.singleReferenceGroup("(parameter) n: number", "n"); diff --git a/tests/cases/fourslash/referencesForGlobals.ts b/tests/cases/fourslash/referencesForGlobals.ts index 43cac1876be..540ab767317 100644 --- a/tests/cases/fourslash/referencesForGlobals.ts +++ b/tests/cases/fourslash/referencesForGlobals.ts @@ -25,4 +25,4 @@ // @Filename: referencesForGlobals_2.ts ////var m = [|global|]; -verify.singleReferenceGroup("var global: number", test.rangesByText().get("global")); +verify.singleReferenceGroup("var global: number", "global"); diff --git a/tests/cases/fourslash/referencesForGlobals2.ts b/tests/cases/fourslash/referencesForGlobals2.ts index d2b5c093f50..c5e56d01ed7 100644 --- a/tests/cases/fourslash/referencesForGlobals2.ts +++ b/tests/cases/fourslash/referencesForGlobals2.ts @@ -10,4 +10,4 @@ // @Filename: referencesForGlobals_2.ts ////var c = [|globalClass|](); -verify.singleReferenceGroup("class globalClass", test.rangesByText().get("globalClass")); +verify.singleReferenceGroup("class globalClass", "globalClass"); diff --git a/tests/cases/fourslash/referencesForGlobals3.ts b/tests/cases/fourslash/referencesForGlobals3.ts index 5ade69a8841..28c6277869d 100644 --- a/tests/cases/fourslash/referencesForGlobals3.ts +++ b/tests/cases/fourslash/referencesForGlobals3.ts @@ -10,4 +10,4 @@ // @Filename: referencesForGlobals_2.ts ////var i: [|globalInterface|]; -verify.singleReferenceGroup("interface globalInterface", test.rangesByText().get("globalInterface")); +verify.singleReferenceGroup("interface globalInterface", "globalInterface"); diff --git a/tests/cases/fourslash/referencesForGlobals4.ts b/tests/cases/fourslash/referencesForGlobals4.ts index cba70e1f441..5aee51ef4b5 100644 --- a/tests/cases/fourslash/referencesForGlobals4.ts +++ b/tests/cases/fourslash/referencesForGlobals4.ts @@ -10,4 +10,4 @@ // @Filename: referencesForGlobals_2.ts ////var m = [|globalModule|]; -verify.singleReferenceGroup("namespace globalModule", test.rangesByText().get("globalModule")); +verify.singleReferenceGroup("namespace globalModule", "globalModule"); diff --git a/tests/cases/fourslash/referencesForGlobals5.ts b/tests/cases/fourslash/referencesForGlobals5.ts index 34a46148d8a..e49d412d905 100644 --- a/tests/cases/fourslash/referencesForGlobals5.ts +++ b/tests/cases/fourslash/referencesForGlobals5.ts @@ -12,4 +12,4 @@ // @Filename: referencesForGlobals_2.ts ////var m = [|globalAlias|]; -verify.singleReferenceGroup("(alias) namespace globalAlias\nimport globalAlias = globalModule", test.rangesByText().get("globalAlias")); +verify.singleReferenceGroup("(alias) namespace globalAlias\nimport globalAlias = globalModule", "globalAlias"); diff --git a/tests/cases/fourslash/referencesForGlobalsInExternalModule.ts b/tests/cases/fourslash/referencesForGlobalsInExternalModule.ts index f4b9d07117c..2c1caf040c0 100644 --- a/tests/cases/fourslash/referencesForGlobalsInExternalModule.ts +++ b/tests/cases/fourslash/referencesForGlobalsInExternalModule.ts @@ -18,11 +18,7 @@ //// ////export = x; -const ranges = test.rangesByText(); -verify.singleReferenceGroup("var topLevelVar: number", ranges.get("topLevelVar")); - -const topLevelClass = ranges.get("topLevelClass"); -verify.singleReferenceGroup("class topLevelClass", topLevelClass); - -verify.singleReferenceGroup("interface topLevelInterface", ranges.get("topLevelInterface")); -verify.singleReferenceGroup("namespace topLevelModule", ranges.get("topLevelModule")); +verify.singleReferenceGroup("var topLevelVar: number", "topLevelVar"); +verify.singleReferenceGroup("class topLevelClass", "topLevelClass"); +verify.singleReferenceGroup("interface topLevelInterface", "topLevelInterface"); +verify.singleReferenceGroup("namespace topLevelModule", "topLevelModule"); diff --git a/tests/cases/fourslash/referencesForIllegalAssignment.ts b/tests/cases/fourslash/referencesForIllegalAssignment.ts index a0c0a610bc5..760f440bb02 100644 --- a/tests/cases/fourslash/referencesForIllegalAssignment.ts +++ b/tests/cases/fourslash/referencesForIllegalAssignment.ts @@ -11,4 +11,4 @@ verify.noReferences(); goTo.marker("2"); verify.noReferences(); -verify.singleReferenceGroup("var bar: () => void", test.rangesByText().get("bar")); +verify.singleReferenceGroup("var bar: () => void", "bar"); diff --git a/tests/cases/fourslash/referencesForIndexProperty.ts b/tests/cases/fourslash/referencesForIndexProperty.ts index 4d21e1d6aef..52560baeff9 100644 --- a/tests/cases/fourslash/referencesForIndexProperty.ts +++ b/tests/cases/fourslash/referencesForIndexProperty.ts @@ -11,6 +11,5 @@ ////f["[|property|]"]; ////f["[|method|]"]; -const ranges = test.rangesByText(); -verify.singleReferenceGroup("(property) Foo.property: number", ranges.get("property")); -verify.singleReferenceGroup("(method) Foo.method(): void", ranges.get("method")); +verify.singleReferenceGroup("(property) Foo.property: number", "property"); +verify.singleReferenceGroup("(method) Foo.method(): void", "method"); diff --git a/tests/cases/fourslash/referencesForIndexProperty3.ts b/tests/cases/fourslash/referencesForIndexProperty3.ts index 2d0d4fec089..fc1fe34749d 100644 --- a/tests/cases/fourslash/referencesForIndexProperty3.ts +++ b/tests/cases/fourslash/referencesForIndexProperty3.ts @@ -12,4 +12,4 @@ ////var x = {}; ////x["[|toMyString|]"](); -verify.singleReferenceGroup("(method) Object.toMyString(): any", test.rangesByText().get("toMyString")); +verify.singleReferenceGroup("(method) Object.toMyString(): any", "toMyString"); diff --git a/tests/cases/fourslash/referencesForInheritedProperties3.ts b/tests/cases/fourslash/referencesForInheritedProperties3.ts index 42de1905874..8dda63e69b4 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties3.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties3.ts @@ -9,6 +9,5 @@ //// v.[|propName|]; //// v.[|doStuff|](); -const ranges = test.rangesByText(); -verify.singleReferenceGroup("(method) interface1.doStuff(): void", ranges.get("doStuff")); -verify.singleReferenceGroup("(property) interface1.propName: string", ranges.get("propName")); +verify.singleReferenceGroup("(method) interface1.doStuff(): void", "doStuff"); +verify.singleReferenceGroup("(property) interface1.propName: string", "propName"); diff --git a/tests/cases/fourslash/referencesForInheritedProperties4.ts b/tests/cases/fourslash/referencesForInheritedProperties4.ts index 5c00529cd1b..e252cb522f1 100644 --- a/tests/cases/fourslash/referencesForInheritedProperties4.ts +++ b/tests/cases/fourslash/referencesForInheritedProperties4.ts @@ -9,7 +9,5 @@ //// c.[|doStuff|](); //// c.[|propName|]; -const ranges = test.rangesByText(); -const [r0, r1] = ranges.get("doStuff"); -verify.singleReferenceGroup("(method) class1.doStuff(): void", ranges.get("doStuff")); -verify.singleReferenceGroup("(property) class1.propName: string", ranges.get("propName")); +verify.singleReferenceGroup("(method) class1.doStuff(): void", "doStuff"); +verify.singleReferenceGroup("(property) class1.propName: string", "propName"); diff --git a/tests/cases/fourslash/referencesForLabel6.ts b/tests/cases/fourslash/referencesForLabel6.ts index 0255c07943c..a8f71480975 100644 --- a/tests/cases/fourslash/referencesForLabel6.ts +++ b/tests/cases/fourslash/referencesForLabel6.ts @@ -7,6 +7,5 @@ //// break labelc; ////} -const ranges = test.rangesByText(); -verify.singleReferenceGroup("labela", ranges.get("labela")); -verify.singleReferenceGroup("labelb", ranges.get("labelb")); +verify.singleReferenceGroup("labela", "labela"); +verify.singleReferenceGroup("labelb", "labelb"); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations2.ts b/tests/cases/fourslash/referencesForMergedDeclarations2.ts index 24ea93b30d5..5521bb96990 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations2.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations2.ts @@ -15,4 +15,4 @@ verify.singleReferenceGroup([ "(alias) function alias(): void", "(alias) namespace alias", "import alias = ATest" -].join("\n"), test.rangesByText().get("alias")); +].join("\n"), "alias"); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations4.ts b/tests/cases/fourslash/referencesForMergedDeclarations4.ts index f67f2aa62e4..880c714421e 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations4.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations4.ts @@ -22,4 +22,4 @@ ////[|testClass|].s; ////new [|testClass|](); -verify.singleReferenceGroup("class testClass\nnamespace testClass", test.rangesByText().get("testClass")); +verify.singleReferenceGroup("class testClass\nnamespace testClass", "testClass"); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations6.ts b/tests/cases/fourslash/referencesForMergedDeclarations6.ts index 91fc90f8e8f..4d6edf4df4c 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations6.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations6.ts @@ -10,4 +10,4 @@ ////// module ////import a1 = [|Foo|]; -verify.singleReferenceGroup("namespace Foo", test.rangesByText().get("Foo")); +verify.singleReferenceGroup("namespace Foo", "Foo"); diff --git a/tests/cases/fourslash/referencesForMergedDeclarations8.ts b/tests/cases/fourslash/referencesForMergedDeclarations8.ts index 4485cd8d0de..81996361158 100644 --- a/tests/cases/fourslash/referencesForMergedDeclarations8.ts +++ b/tests/cases/fourslash/referencesForMergedDeclarations8.ts @@ -10,4 +10,4 @@ ////// module ////import a3 = Foo.[|Bar|].Baz; -verify.singleReferenceGroup("namespace Foo.Bar", test.rangesByText().get("Bar")); +verify.singleReferenceGroup("namespace Foo.Bar", "Bar"); diff --git a/tests/cases/fourslash/referencesForNumericLiteralPropertyNames.ts b/tests/cases/fourslash/referencesForNumericLiteralPropertyNames.ts index 1a9998be1e5..8f9ab78eb02 100644 --- a/tests/cases/fourslash/referencesForNumericLiteralPropertyNames.ts +++ b/tests/cases/fourslash/referencesForNumericLiteralPropertyNames.ts @@ -9,4 +9,4 @@ ////x = { [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}12|]": 0|] }; ////x = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}12|]: 0|] }; -verify.singleReferenceGroup("(property) Foo[12]: any", test.rangesByText().get("12")); +verify.singleReferenceGroup("(property) Foo[12]: any", "12"); diff --git a/tests/cases/fourslash/referencesForObjectLiteralProperties.ts b/tests/cases/fourslash/referencesForObjectLiteralProperties.ts index ed365a63706..60b1c808376 100644 --- a/tests/cases/fourslash/referencesForObjectLiteralProperties.ts +++ b/tests/cases/fourslash/referencesForObjectLiteralProperties.ts @@ -8,5 +8,4 @@ ////var y = x; ////y.[|add|]; -const [rDef, ...ranges] = test.ranges(); -verify.singleReferenceGroup("(property) add: number", ranges); +verify.singleReferenceGroup("(property) add: number", "add"); diff --git a/tests/cases/fourslash/referencesForPropertiesOfGenericType.ts b/tests/cases/fourslash/referencesForPropertiesOfGenericType.ts index 7fc42dce34e..e8ae86b2cef 100644 --- a/tests/cases/fourslash/referencesForPropertiesOfGenericType.ts +++ b/tests/cases/fourslash/referencesForPropertiesOfGenericType.ts @@ -10,5 +10,4 @@ ////var y: IFoo; ////y.[|doSomething|](12); -const [rDef, ...ranges] = test.ranges(); -verify.singleReferenceGroup("(method) IFoo.doSomething(v: T): T", ranges); +verify.singleReferenceGroup("(method) IFoo.doSomething(v: T): T", "doSomething"); diff --git a/tests/cases/fourslash/referencesForStatic.ts b/tests/cases/fourslash/referencesForStatic.ts index 7bc1ec13e9c..2e0a6182edb 100644 --- a/tests/cases/fourslash/referencesForStatic.ts +++ b/tests/cases/fourslash/referencesForStatic.ts @@ -30,5 +30,4 @@ // @Filename: referencesOnStatic_2.ts ////var q = foo.[|n|]; -const [rDef, ...ranges] = test.ranges(); -verify.singleReferenceGroup("(property) foo.n: string", ranges); +verify.singleReferenceGroup("(property) foo.n: string", "n"); diff --git a/tests/cases/fourslash/referencesForStringLiteralPropertyNames.ts b/tests/cases/fourslash/referencesForStringLiteralPropertyNames.ts index 036637ec75f..564f33bad48 100644 --- a/tests/cases/fourslash/referencesForStringLiteralPropertyNames.ts +++ b/tests/cases/fourslash/referencesForStringLiteralPropertyNames.ts @@ -10,4 +10,4 @@ ////x = { [|"[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}ss|]": 0|] }; ////x = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}ss|]: 0|] }; -verify.singleReferenceGroup('(property) Foo["ss"]: any', test.rangesByText().get("ss")); +verify.singleReferenceGroup('(property) Foo["ss"]: any', "ss"); diff --git a/tests/cases/fourslash/referencesForStringLiteralPropertyNames2.ts b/tests/cases/fourslash/referencesForStringLiteralPropertyNames2.ts index cc142bebb69..24e4e29ba8a 100644 --- a/tests/cases/fourslash/referencesForStringLiteralPropertyNames2.ts +++ b/tests/cases/fourslash/referencesForStringLiteralPropertyNames2.ts @@ -7,4 +7,4 @@ ////var x: Foo; ////x.[|blah|]; -verify.singleReferenceGroup('(method) Foo["blah"](): number', test.rangesByText().get("blah")); +verify.singleReferenceGroup('(method) Foo["blah"](): number', "blah"); diff --git a/tests/cases/fourslash/referencesForStringLiteralPropertyNames3.ts b/tests/cases/fourslash/referencesForStringLiteralPropertyNames3.ts index 050503a1e34..23519a0facf 100644 --- a/tests/cases/fourslash/referencesForStringLiteralPropertyNames3.ts +++ b/tests/cases/fourslash/referencesForStringLiteralPropertyNames3.ts @@ -8,5 +8,4 @@ ////var y: Foo2; ////y[[|42|]]; - -verify.singleReferenceGroup('(property) Foo2["42"]: number', test.rangesByText().get("42")); +verify.singleReferenceGroup('(property) Foo2["42"]: number', "42"); \ No newline at end of file diff --git a/tests/cases/fourslash/renameJsExports01.ts b/tests/cases/fourslash/renameJsExports01.ts index be5e4f6ea05..2a081525bbe 100644 --- a/tests/cases/fourslash/renameJsExports01.ts +++ b/tests/cases/fourslash/renameJsExports01.ts @@ -8,6 +8,5 @@ ////var mod = require('./a'); ////var t = mod./**/[|area|](10); -const [rDef, ...ranges] = test.ranges(); -verify.singleReferenceGroup("(property) area: (r: any) => number", ranges); -verify.rangesAreRenameLocations(ranges); +verify.singleReferenceGroup("(property) area: (r: any) => number", "area"); +verify.rangesWithSameTextAreRenameLocations("area"); diff --git a/tests/cases/fourslash/tsxFindAllReferences1.ts b/tests/cases/fourslash/tsxFindAllReferences1.ts index 1602bc7dae9..e943c4e69bf 100644 --- a/tests/cases/fourslash/tsxFindAllReferences1.ts +++ b/tests/cases/fourslash/tsxFindAllReferences1.ts @@ -13,11 +13,8 @@ //// } //// var x = <[|div|] />; -const rangesByText = test.rangesByText(); verify.singleReferenceGroup( `(property) JSX.IntrinsicElements.div: { name?: string; isOpen?: boolean; -}`, - rangesByText.get("div") -); +}`, "div"); diff --git a/tests/cases/fourslash/tsxFindAllReferences10.ts b/tests/cases/fourslash/tsxFindAllReferences10.ts index 29e57b97bd2..bbef12be7cc 100644 --- a/tests/cases/fourslash/tsxFindAllReferences10.ts +++ b/tests/cases/fourslash/tsxFindAllReferences10.ts @@ -30,8 +30,4 @@ //// let opt = ; //// let opt = ; -const rangesByText = test.rangesByText(); -verify.singleReferenceGroup( - "(method) ButtonProps.onClick(event?: any): void", - rangesByText.get("onClick") -); +verify.singleReferenceGroup("(method) ButtonProps.onClick(event?: any): void", "onClick"); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxFindAllReferences2.ts b/tests/cases/fourslash/tsxFindAllReferences2.ts index f1b71e51811..4c6dc5a81bf 100644 --- a/tests/cases/fourslash/tsxFindAllReferences2.ts +++ b/tests/cases/fourslash/tsxFindAllReferences2.ts @@ -13,8 +13,4 @@ //// } //// var x =
; -const rangesByText = test.rangesByText(); -verify.singleReferenceGroup( - "(property) name?: string", - rangesByText.get("name") -); +verify.singleReferenceGroup("(property) name?: string", "name"); diff --git a/tests/cases/fourslash/tsxFindAllReferences3.ts b/tests/cases/fourslash/tsxFindAllReferences3.ts index c519d5da99b..299161bf1f0 100644 --- a/tests/cases/fourslash/tsxFindAllReferences3.ts +++ b/tests/cases/fourslash/tsxFindAllReferences3.ts @@ -16,8 +16,4 @@ //// //// var x = ; -const rangesByText = test.rangesByText(); -verify.singleReferenceGroup( - "(property) name?: string", - rangesByText.get("name") -); +verify.singleReferenceGroup("(property) name?: string", "name"); diff --git a/tests/cases/fourslash/tsxFindAllReferences4.ts b/tests/cases/fourslash/tsxFindAllReferences4.ts index 5d7ce7419bb..e761be8eb4d 100644 --- a/tests/cases/fourslash/tsxFindAllReferences4.ts +++ b/tests/cases/fourslash/tsxFindAllReferences4.ts @@ -16,8 +16,4 @@ //// //// var x = <[|MyClass|] name='hello'>; -const rangesByText = test.rangesByText(); -verify.singleReferenceGroup( - "class MyClass", - rangesByText.get("MyClass") -); +verify.singleReferenceGroup("class MyClass", "MyClass"); diff --git a/tests/cases/fourslash/tsxFindAllReferences5.ts b/tests/cases/fourslash/tsxFindAllReferences5.ts index 265b1a015f3..ee3e0e7e4bd 100644 --- a/tests/cases/fourslash/tsxFindAllReferences5.ts +++ b/tests/cases/fourslash/tsxFindAllReferences5.ts @@ -22,8 +22,7 @@ //// let opt3 = <[|Opt|] wrong />; //// let opt4 = <[|Opt|] propx={100} propString="hi" />; -const rangesByText = test.rangesByText(); verify.singleReferenceGroup( "function Opt(attributes: OptionPropBag): JSX.Element", - rangesByText.get("Opt") + "Opt" ); diff --git a/tests/cases/fourslash/tsxFindAllReferences7.ts b/tests/cases/fourslash/tsxFindAllReferences7.ts index 22c19e1cc29..c7e916cc8f1 100644 --- a/tests/cases/fourslash/tsxFindAllReferences7.ts +++ b/tests/cases/fourslash/tsxFindAllReferences7.ts @@ -21,8 +21,4 @@ //// let opt2 = ; //// let opt3 = ; -const rangesByText = test.rangesByText(); -verify.singleReferenceGroup( - "(property) OptionPropBag.propx: number", - rangesByText.get("propx") -); +verify.singleReferenceGroup("(property) OptionPropBag.propx: number", "propx"); diff --git a/tests/cases/fourslash/tsxFindAllReferences8.ts b/tests/cases/fourslash/tsxFindAllReferences8.ts index b509a9565a0..a5683cfb330 100644 --- a/tests/cases/fourslash/tsxFindAllReferences8.ts +++ b/tests/cases/fourslash/tsxFindAllReferences8.ts @@ -30,8 +30,7 @@ //// let opt = <[|MainButton|] goTo="goTo" />; //// let opt = <[|MainButton|] wrong />; -const rangesByText = test.rangesByText(); verify.singleReferenceGroup( "function MainButton(buttonProps: ButtonProps): JSX.Element (+2 overloads)", - rangesByText.get("MainButton") + "MainButton" ); diff --git a/tests/cases/fourslash/tsxFindAllReferences9.ts b/tests/cases/fourslash/tsxFindAllReferences9.ts index e10eb420926..ba55331d892 100644 --- a/tests/cases/fourslash/tsxFindAllReferences9.ts +++ b/tests/cases/fourslash/tsxFindAllReferences9.ts @@ -31,5 +31,4 @@ //// let opt = ; //// let opt = ; -const rangesByText = test.rangesByText(); -verify.singleReferenceGroup("(property) LinkProps.goTo: string", rangesByText.get("goTo")); +verify.singleReferenceGroup("(property) LinkProps.goTo: string", "goTo"); diff --git a/tests/cases/fourslash/tsxFindAllReferencesUnionElementType1.ts b/tests/cases/fourslash/tsxFindAllReferencesUnionElementType1.ts index 9da352c64b1..dc85960bb6d 100644 --- a/tests/cases/fourslash/tsxFindAllReferencesUnionElementType1.ts +++ b/tests/cases/fourslash/tsxFindAllReferencesUnionElementType1.ts @@ -21,9 +21,8 @@ //// [|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}SFCComp|] = SFC1 || SFC2;|] //// <[|SFCComp|] x={ "hi" } /> -const [, r1, r2] = test.ranges(); verify.singleReferenceGroup(`var SFCComp: ((prop: { x: number; }) => JSX.Element) | ((prop: { x: boolean; -}) => JSX.Element)`, [r1, r2]); +}) => JSX.Element)`, "SFCComp"); diff --git a/tests/cases/fourslash/tsxFindAllReferencesUnionElementType2.ts b/tests/cases/fourslash/tsxFindAllReferencesUnionElementType2.ts index 80291feb451..ffb33919fd4 100644 --- a/tests/cases/fourslash/tsxFindAllReferencesUnionElementType2.ts +++ b/tests/cases/fourslash/tsxFindAllReferencesUnionElementType2.ts @@ -20,5 +20,4 @@ //// [|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}RCComp|] = RC1 || RC2;|] //// <[|RCComp|] /> -const [, r1, r2 ] = test.ranges(); -verify.singleReferenceGroup("var RCComp: typeof RC1", [r1, r2]); +verify.singleReferenceGroup("var RCComp: typeof RC1", "RCComp"); From d1dc8373532049e94d42ce146e91229cd302e3d2 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 5 Jun 2019 14:43:33 -0700 Subject: [PATCH 27/44] Cache ranges by text --- src/harness/fourslash.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 7842798dbef..2061bbd69ba 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -42,6 +42,7 @@ namespace FourSlash { * is a range with `text in range` "selected". */ ranges: Range[]; + rangesByText?: ts.MultiMap; } export interface Marker { @@ -1002,7 +1003,7 @@ namespace FourSlash { } public verifySingleReferenceGroup(definition: FourSlashInterface.ReferenceGroupDefinition, ranges?: Range[] | string) { - ranges = ts.isString(ranges) ? this.rangesByText().get(ranges)! : ranges || this.getRanges(); + ranges = ts.isString(ranges) ? this.rangesByText().get(ranges)! : ranges || this.getRanges(); this.verifyReferenceGroups(ranges, [{ definition, ranges }]); } @@ -1853,6 +1854,7 @@ Actual: ${stringify(fullActual)}`); range.end = updatePosition(range.end, editStart, editEnd, newText); } } + this.testData.rangesByText = undefined; } private removeWhitespace(text: string): string { @@ -2035,7 +2037,9 @@ Actual: ${stringify(fullActual)}`); } public rangesByText(): ts.Map { + if (this.testData.rangesByText) return this.testData.rangesByText; const result = ts.createMultiMap(); + this.testData.rangesByText = result; for (const range of this.getRanges()) { const text = this.rangeText(range); result.add(text, range); From e1e160354733f621f5ef0df7e88367c43c553a0b Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 5 Jun 2019 15:01:34 -0700 Subject: [PATCH 28/44] More tests --- .../findAllRefsForComputedProperties.ts | 11 +++++------ .../findAllRefsForComputedProperties2.ts | 11 +++++------ .../fourslash/findAllRefsForDefaultExport.ts | 7 +++---- .../fourslash/findAllRefsForDefaultExport01.ts | 6 +++--- .../fourslash/findAllRefsForDefaultExport02.ts | 11 +++++------ .../fourslash/findAllRefsForDefaultExport03.ts | 12 ++++++------ .../fourslash/findAllRefsForDefaultExport08.ts | 6 +++--- .../findAllRefsForDefaultExport_reExport.ts | 10 +++++----- ...rt_reExport_allowSyntheticDefaultImports.ts | 10 +++++----- .../findAllRefsForFunctionExpression01.ts | 6 +++--- .../fourslash/findAllRefsForMappedType.ts | 8 ++++---- .../fourslash/findAllRefsForModuleGlobal.ts | 4 ++-- .../findAllRefsForObjectLiteralProperties.ts | 6 +++--- .../fourslash/findAllRefsForObjectSpread.ts | 8 ++++---- tests/cases/fourslash/findAllRefsForRest.ts | 4 ++-- .../fourslash/findAllRefsForUMDModuleAlias1.ts | 4 ++-- .../findAllRefsForVariableInExtendsClause01.ts | 4 ++-- .../findAllRefsForVariableInExtendsClause02.ts | 4 ++-- .../findAllRefsGlobalModuleAugmentation.ts | 4 ++-- .../fourslash/findAllRefsImportDefault.ts | 10 +++++----- .../cases/fourslash/findAllRefsImportEquals.ts | 4 ++-- .../findAllRefsImportEqualsJsonFile.ts | 6 +++--- .../cases/fourslash/findAllRefsImportNamed.ts | 6 +++--- .../findAllRefsImportStarOfExportEquals.ts | 15 +++++++-------- tests/cases/fourslash/findAllRefsImportType.ts | 4 ++-- .../fourslash/findAllRefsInClassExpression.ts | 6 +++--- .../fourslash/findAllRefsIndexedAccessTypes.ts | 9 ++++----- .../findAllRefsInheritedProperties1.ts | 6 +++--- .../findAllRefsInheritedProperties2.ts | 6 +++--- .../findAllRefsInheritedProperties3.ts | 14 +++++++------- .../findAllRefsInheritedProperties4.ts | 8 ++++---- .../findAllRefsInheritedProperties5.ts | 8 ++++---- .../fourslash/findAllRefsInsideTemplates1.ts | 4 ++-- .../fourslash/findAllRefsInsideTemplates2.ts | 4 ++-- .../fourslash/findAllRefsInsideWithBlock.ts | 4 ++-- .../fourslash/findAllRefsJsDocTypeDef_js.ts | 4 ++-- tests/cases/fourslash/findAllRefsMappedType.ts | 4 ++-- .../fourslash/findAllRefsModuleAugmentation.ts | 4 ++-- .../fourslash/findAllRefsModuleDotExports.ts | 5 +++-- .../fourslash/findAllRefsNoImportClause.ts | 4 ++-- ...llRefsObjectBindingElementPropertyName01.ts | 6 +++--- ...llRefsObjectBindingElementPropertyName02.ts | 6 +++--- ...llRefsObjectBindingElementPropertyName03.ts | 12 +++++++----- ...llRefsObjectBindingElementPropertyName04.ts | 9 ++++----- ...llRefsObjectBindingElementPropertyName06.ts | 18 ++++++++++-------- ...llRefsObjectBindingElementPropertyName07.ts | 4 ++-- ...llRefsObjectBindingElementPropertyName10.ts | 6 +++--- .../fourslash/findAllRefsOfConstructor.ts | 8 ++++---- .../fourslash/findAllRefsOfConstructor2.ts | 10 +++++----- .../findAllRefsOfConstructor_multipleFiles.ts | 12 ++++++------ .../findAllRefsOfConstructor_withModifier.ts | 4 ++-- 51 files changed, 182 insertions(+), 184 deletions(-) diff --git a/tests/cases/fourslash/findAllRefsForComputedProperties.ts b/tests/cases/fourslash/findAllRefsForComputedProperties.ts index 3c442b8b63a..d8a5ef9771f 100644 --- a/tests/cases/fourslash/findAllRefsForComputedProperties.ts +++ b/tests/cases/fourslash/findAllRefsForComputedProperties.ts @@ -1,20 +1,19 @@ /// ////interface I { -//// ["[|{| "isDefinition": true |}prop1|]"]: () => void; +//// [|["[|{| "isDefinition": true, "declarationRangeIndex": 0 |}prop1|]"]: () => void;|] ////} //// ////class C implements I { -//// ["[|{| "isDefinition": true |}prop1|]"]: any; +//// [|["[|{| "isDefinition": true, "declarationRangeIndex": 2 |}prop1|]"]: any;|] ////} //// ////var x: I = { -//// ["[|{| "isWriteAccess": true, "isDefinition": true |}prop1|]"]: function () { }, +//// [|["[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}prop1|]"]: function () { }|], ////} -const ranges = test.ranges(); -const [r0, r1, r2] = ranges; -verify.referenceGroups(ranges, [ +const [r0Def, r0, r1Def, r1, r2Def, r2] = test.ranges(); +verify.referenceGroups([r0, r1, r2], [ { definition: { text: '(property) I["prop1"]: () => void', range: r0 }, ranges: [r0, r2] }, { definition: { text: '(property) C["prop1"]: any', range: r1 }, ranges: [r1] }, ]); diff --git a/tests/cases/fourslash/findAllRefsForComputedProperties2.ts b/tests/cases/fourslash/findAllRefsForComputedProperties2.ts index 21f9d2c92ba..8b66fd635e4 100644 --- a/tests/cases/fourslash/findAllRefsForComputedProperties2.ts +++ b/tests/cases/fourslash/findAllRefsForComputedProperties2.ts @@ -1,20 +1,19 @@ /// ////interface I { -//// [[|{| "isDefinition": true |}42|]](): void; +//// [|[[|{| "isDefinition": true, "declarationRangeIndex": 0 |}42|]](): void;|] ////} //// ////class C implements I { -//// [[|{| "isDefinition": true |}42|]]: any; +//// [|[[|{| "isDefinition": true, "declarationRangeIndex": 2 |}42|]]: any;|] ////} //// ////var x: I = { -//// ["[|{| "isWriteAccess": true, "isDefinition": true |}42|]"]: function () { } +//// [|["[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}42|]"]: function () { }|] ////} -const ranges = test.ranges(); -const [r0, r1, r2] = ranges; -verify.referenceGroups(ranges, [ +const [r0Def, r0, r1Def, r1, r2Def, r2] = test.ranges(); +verify.referenceGroups([r0, r1, r2], [ { definition: { text: '(method) I[42](): void', range: r0 }, ranges: [r0, r2] }, { definition: { text: '(property) C[42]: any', range: r1 }, ranges: [r1] }, ]); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport.ts b/tests/cases/fourslash/findAllRefsForDefaultExport.ts index 71c566a6f42..6570fa2857d 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport.ts @@ -1,17 +1,16 @@ /// // @Filename: a.ts -////export default function /*def*/[|{| "isWriteAccess": true, "isDefinition": true |}f|]() {} +////[|export default function /*def*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}f|]() {}|] // @Filename: b.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}g|] from "./a"; +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}g|] from "./a";|] ////[|/*ref*/g|](); // @Filename: c.ts ////import { f } from "./a"; -const ranges = test.ranges(); -const [r0, r1, r2] = ranges; +const [r0Def, r0, r1Def, r1, r2] = test.ranges(); verify.referenceGroups(r0, [ { definition: "function f(): void", ranges: [r0] }, { definition: "(alias) function g(): void\nimport g", ranges: [r1, r2] } diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport01.ts b/tests/cases/fourslash/findAllRefsForDefaultExport01.ts index 419262bd10f..96b906ba9cb 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport01.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport01.ts @@ -1,10 +1,10 @@ /// -////export default class [|{| "isWriteAccess": true, "isDefinition": true |}DefaultExportedClass|] { -////} +////[|export default class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}DefaultExportedClass|] { +////}|] //// ////var x: [|DefaultExportedClass|]; //// ////var y = new [|DefaultExportedClass|]; -verify.singleReferenceGroup("class DefaultExportedClass"); +verify.singleReferenceGroup("class DefaultExportedClass", "DefaultExportedClass"); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport02.ts b/tests/cases/fourslash/findAllRefsForDefaultExport02.ts index c664b470938..1e00bb4f68d 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport02.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport02.ts @@ -1,19 +1,18 @@ /// -////export default function [|{| "isWriteAccess": true, "isDefinition": true |}DefaultExportedFunction|]() { +////[|export default function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}DefaultExportedFunction|]() { //// return [|DefaultExportedFunction|]; -////} +////}|] //// ////var x: typeof [|DefaultExportedFunction|]; //// ////var y = [|DefaultExportedFunction|](); //// -////namespace [|{| "isWriteAccess": true, "isDefinition": true |}DefaultExportedFunction|] { -////} +////[|namespace [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}DefaultExportedFunction|] { +////}|] -const ranges = test.ranges(); -const [r0, r1, r2, r3, r4] = ranges; +const [r0Def, r0, r1, r2, r3, r4Def, r4] = test.ranges(); const fnRanges = [r0, r1, r2, r3]; verify.singleReferenceGroup("function DefaultExportedFunction(): () => typeof DefaultExportedFunction", fnRanges); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport03.ts b/tests/cases/fourslash/findAllRefsForDefaultExport03.ts index 75cbe556e36..1e8ddbc1507 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport03.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport03.ts @@ -1,17 +1,17 @@ /// -////function [|{| "isWriteAccess": true, "isDefinition": true |}f|]() { +////[|function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}f|]() { //// return 100; -////} +////}|] //// -////export default [|f|]; +////[|export default [|{| "declarationRangeIndex": 2 |}f|];|] //// ////var x: typeof [|f|]; //// ////var y = [|f|](); //// -////namespace [|{| "isWriteAccess": true, "isDefinition": true |}f|] { +////[|namespace [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}f|] { //// var local = 100; -////} +////}|] -verify.singleReferenceGroup("namespace f\nfunction f(): number"); +verify.singleReferenceGroup("namespace f\nfunction f(): number", "f"); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport08.ts b/tests/cases/fourslash/findAllRefsForDefaultExport08.ts index 5583ba34c95..d94a0ce5d3c 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport08.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport08.ts @@ -7,11 +7,11 @@ //// ////var y = new DefaultExportedClass; //// -////namespace [|{| "isWriteAccess": true, "isDefinition": true |}DefaultExportedClass|] { -////} +////[|namespace [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}DefaultExportedClass|] { +////}|] verify.noErrors(); // The namespace and class do not merge, // so the namespace should be all alone. -verify.singleReferenceGroup("class DefaultExportedClass\nnamespace DefaultExportedClass"); +verify.singleReferenceGroup("class DefaultExportedClass\nnamespace DefaultExportedClass", "DefaultExportedClass"); diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport_reExport.ts b/tests/cases/fourslash/findAllRefsForDefaultExport_reExport.ts index 2abd33b7d6e..d9dd9d06736 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport_reExport.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport_reExport.ts @@ -1,16 +1,16 @@ /// // @Filename: /export.ts -////const [|{| "isWriteAccess": true, "isDefinition": true |}foo|] = 1; -////export default [|foo|]; +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|] = 1;|] +////[|export default [|{| "declarationRangeIndex": 2 |}foo|];|] // @Filename: /re-export.ts -////export { [|{| "isWriteAccess": true, "isDefinition": true |}default|] } from "./export"; +////[|export { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}default|] } from "./export";|] // @Filename: /re-export-dep.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}fooDefault|] from "./re-export"; +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}fooDefault|] from "./re-export";|] -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3] = test.ranges(); verify.referenceGroups([r0, r1], [ { definition: "const foo: 1", ranges: [r0, r1] }, { definition: "(alias) const foo: 1\nexport default", ranges: [r2], }, diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport_reExport_allowSyntheticDefaultImports.ts b/tests/cases/fourslash/findAllRefsForDefaultExport_reExport_allowSyntheticDefaultImports.ts index 386eca5eae0..e49f7ca41bc 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport_reExport_allowSyntheticDefaultImports.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport_reExport_allowSyntheticDefaultImports.ts @@ -3,18 +3,18 @@ // @allowSyntheticDefaultImports: true // @Filename: /export.ts -////const [|{| "isWriteAccess": true, "isDefinition": true |}foo|] = 1; -////export = [|foo|]; +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|] = 1;|] +////[|export = [|{| "declarationRangeIndex": 2 |}foo|];|] // @Filename: /re-export.ts -////export { [|{| "isWriteAccess": true, "isDefinition": true |}default|] } from "./export"; +////[|export { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}default|] } from "./export";|] // @Filename: /re-export-dep.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}fooDefault|] from "./re-export"; +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}fooDefault|] from "./re-export";|] verify.noErrors(); -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3] = test.ranges(); verify.referenceGroups([r0, r1], [ { definition: "const foo: 1", ranges: [r0, r1] }, { definition: "(alias) const foo: 1\nexport default", ranges: [r2], }, diff --git a/tests/cases/fourslash/findAllRefsForFunctionExpression01.ts b/tests/cases/fourslash/findAllRefsForFunctionExpression01.ts index ddb98711629..16caacc2aad 100644 --- a/tests/cases/fourslash/findAllRefsForFunctionExpression01.ts +++ b/tests/cases/fourslash/findAllRefsForFunctionExpression01.ts @@ -1,12 +1,12 @@ /// // @Filename: file1.ts -////var foo = function [|{| "isWriteAccess": true, "isDefinition": true |}foo|](a = [|foo|](), b = () => [|foo|]) { +////var foo = [|function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|](a = [|foo|](), b = () => [|foo|]) { //// [|foo|]([|foo|], [|foo|]); -////} +////}|] // @Filename: file2.ts /////// ////foo(); -verify.singleReferenceGroup("(local function) foo(a?: void, b?: () => (a?: void, b?: ...) => void): void"); +verify.singleReferenceGroup("(local function) foo(a?: void, b?: () => (a?: void, b?: ...) => void): void", "foo"); diff --git a/tests/cases/fourslash/findAllRefsForMappedType.ts b/tests/cases/fourslash/findAllRefsForMappedType.ts index 8965fa046ea..8a64a730801 100644 --- a/tests/cases/fourslash/findAllRefsForMappedType.ts +++ b/tests/cases/fourslash/findAllRefsForMappedType.ts @@ -1,9 +1,9 @@ /// -////interface T { [|{| "isDefinition": true |}a|]: number }; +////interface T { [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}a|]: number|] }; ////type U = { [K in keyof T]: string }; ////type V = { [K in keyof U]: boolean }; -////const u: U = { [|{| "isWriteAccess": true, "isDefinition": true |}a|]: "" } -////const v: V = { [|{| "isWriteAccess": true, "isDefinition": true |}a|]: true } +////const u: U = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}a|]: ""|] } +////const v: V = { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}a|]: true|] } -verify.singleReferenceGroup("(property) T.a: number"); +verify.singleReferenceGroup("(property) T.a: number", "a"); diff --git a/tests/cases/fourslash/findAllRefsForModuleGlobal.ts b/tests/cases/fourslash/findAllRefsForModuleGlobal.ts index 817064c3f14..4c7aa3939c1 100644 --- a/tests/cases/fourslash/findAllRefsForModuleGlobal.ts +++ b/tests/cases/fourslash/findAllRefsForModuleGlobal.ts @@ -6,7 +6,7 @@ // @Filename: /b.ts /////// ////import { x } from "[|foo|]"; -////declare module "[|{| "isWriteAccess": true, "isDefinition": true |}foo|]" {} +////[|declare module "[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}foo|]" {}|] verify.noErrors(); -verify.singleReferenceGroup('module "/node_modules/foo/index"'); +verify.singleReferenceGroup('module "/node_modules/foo/index"', "foo"); diff --git a/tests/cases/fourslash/findAllRefsForObjectLiteralProperties.ts b/tests/cases/fourslash/findAllRefsForObjectLiteralProperties.ts index 2d9d9e267c5..5a6557d65d9 100644 --- a/tests/cases/fourslash/findAllRefsForObjectLiteralProperties.ts +++ b/tests/cases/fourslash/findAllRefsForObjectLiteralProperties.ts @@ -1,11 +1,11 @@ /// ////var x = { -//// [|{| "isWriteAccess": true, "isDefinition": true |}property|]: {} +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}property|]: {}|] ////}; //// ////x.[|property|]; //// -////let {[|property|]: pVar} = x; +////[|let {[|{| "declarationRangeIndex": 3 |}property|]: pVar} = x;|] -verify.singleReferenceGroup("(property) property: {}"); +verify.singleReferenceGroup("(property) property: {}", "property"); diff --git a/tests/cases/fourslash/findAllRefsForObjectSpread.ts b/tests/cases/fourslash/findAllRefsForObjectSpread.ts index 12c338ca529..5995d0d7cb0 100644 --- a/tests/cases/fourslash/findAllRefsForObjectSpread.ts +++ b/tests/cases/fourslash/findAllRefsForObjectSpread.ts @@ -1,14 +1,14 @@ /// -////interface A1 { readonly [|{| "isDefinition": true |}a|]: string }; -////interface A2 { [|{| "isDefinition": true |}a|]?: number }; +////interface A1 { [|readonly [|{| "isDefinition": true, "declarationRangeIndex": 0 |}a|]: string|] }; +////interface A2 { [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}a|]?: number|] }; ////let a1: A1; ////let a2: A2; ////let a12 = { ...a1, ...a2 }; ////a12.[|a|]; ////a1.[|a|]; -const ranges = test.ranges(); -const [r0, r1, r2, r3] = ranges; + +const [r0Def, r0, r1Def, r1, r2, r3] = test.ranges(); // members of spread types only refer to themselves and the resulting property verify.referenceGroups(r0, [{ definition: "(property) A1.a: string", ranges: [r0, r2, r3] }]); diff --git a/tests/cases/fourslash/findAllRefsForRest.ts b/tests/cases/fourslash/findAllRefsForRest.ts index 3dac71374f0..b39071c13c1 100644 --- a/tests/cases/fourslash/findAllRefsForRest.ts +++ b/tests/cases/fourslash/findAllRefsForRest.ts @@ -1,11 +1,11 @@ /// ////interface Gen { //// x: number -//// [|{| "isDefinition": true |}parent|]: Gen; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}parent|]: Gen;|] //// millenial: string; ////} ////let t: Gen; ////var { x, ...rest } = t; ////rest.[|parent|]; -verify.singleReferenceGroup("(property) Gen.parent: Gen"); +verify.singleReferenceGroup("(property) Gen.parent: Gen", "parent"); diff --git a/tests/cases/fourslash/findAllRefsForUMDModuleAlias1.ts b/tests/cases/fourslash/findAllRefsForUMDModuleAlias1.ts index 99ca347eac4..97188a5bac8 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 [|{| "isWriteAccess": true, "isDefinition": true |}myLib|]; +//// [|export as namespace [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}myLib|];|] // @Filename: 1.ts //// /// //// [|myLib|].doThing(); -verify.singleReferenceGroup("export namespace myLib"); +verify.singleReferenceGroup("export namespace myLib", "myLib"); diff --git a/tests/cases/fourslash/findAllRefsForVariableInExtendsClause01.ts b/tests/cases/fourslash/findAllRefsForVariableInExtendsClause01.ts index a61f925c97e..d72a1695cca 100644 --- a/tests/cases/fourslash/findAllRefsForVariableInExtendsClause01.ts +++ b/tests/cases/fourslash/findAllRefsForVariableInExtendsClause01.ts @@ -1,6 +1,6 @@ /// -////var [|{| "isWriteAccess": true, "isDefinition": true |}Base|] = class { }; +////[|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Base|] = class { };|] ////class C extends [|Base|] { } -verify.singleReferenceGroup("var Base: typeof Base"); +verify.singleReferenceGroup("var Base: typeof Base", "Base"); diff --git a/tests/cases/fourslash/findAllRefsForVariableInExtendsClause02.ts b/tests/cases/fourslash/findAllRefsForVariableInExtendsClause02.ts index 5685df0c4e1..c2fd4bd077b 100644 --- a/tests/cases/fourslash/findAllRefsForVariableInExtendsClause02.ts +++ b/tests/cases/fourslash/findAllRefsForVariableInExtendsClause02.ts @@ -1,9 +1,9 @@ /// -////interface [|{| "isWriteAccess": true, "isDefinition": true |}Base|] { } +////[|interface [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Base|] { }|] ////namespace n { //// var Base = class { }; //// interface I extends [|Base|] { } ////} -verify.singleReferenceGroup("interface Base"); +verify.singleReferenceGroup("interface Base", "Base"); diff --git a/tests/cases/fourslash/findAllRefsGlobalModuleAugmentation.ts b/tests/cases/fourslash/findAllRefsGlobalModuleAugmentation.ts index c2f4982b653..82016acd9f0 100644 --- a/tests/cases/fourslash/findAllRefsGlobalModuleAugmentation.ts +++ b/tests/cases/fourslash/findAllRefsGlobalModuleAugmentation.ts @@ -3,11 +3,11 @@ // @Filename: /a.ts ////export {}; ////declare global { -//// function [|{| "isWriteAccess": true, "isDefinition": true |}f|](): void; +//// [|function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}f|](): void;|] ////} // @Filename: /b.ts ////[|f|](); verify.noErrors(); -verify.singleReferenceGroup("function f(): void"); +verify.singleReferenceGroup("function f(): void", "f"); diff --git a/tests/cases/fourslash/findAllRefsImportDefault.ts b/tests/cases/fourslash/findAllRefsImportDefault.ts index 15b3bda8ddf..253bbd4ae3f 100644 --- a/tests/cases/fourslash/findAllRefsImportDefault.ts +++ b/tests/cases/fourslash/findAllRefsImportDefault.ts @@ -1,17 +1,17 @@ /// // @Filename: f.ts -////export { [|foo|] as [|{| "isWriteAccess": true, "isDefinition": true |}default|] }; -////function /*start*/[|{| "isWriteAccess": true, "isDefinition": true |}foo|](a: number, b: number) { +////[|export { [|{| "declarationRangeIndex": 0 |}foo|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}default|] };|] +////[|function /*start*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}foo|](a: number, b: number) { //// return a + b; -////} +////}|] // @Filename: b.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}bar|] from "./f"; +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}bar|] from "./f";|] ////[|bar|](1, 2); verify.noErrors(); -const [ foo0, foo1, foo2, bar0, bar1 ] = test.ranges(); +const [ foo0Def, foo0, foo1, foo2Def, foo2, bar0Def, bar0, bar1 ] = test.ranges(); const fooGroup = { definition: "function foo(a: number, b: number): number", ranges: [foo0, foo2] }; const exportDefaultGroup = { definition: "(alias) function foo(a: number, b: number): number\nexport default", ranges: [foo1] }; const barGroup = { definition: "(alias) function bar(a: number, b: number): number\nimport bar", ranges: [bar0, bar1]}; diff --git a/tests/cases/fourslash/findAllRefsImportEquals.ts b/tests/cases/fourslash/findAllRefsImportEquals.ts index c6884c78b8c..c085874d910 100644 --- a/tests/cases/fourslash/findAllRefsImportEquals.ts +++ b/tests/cases/fourslash/findAllRefsImportEquals.ts @@ -1,7 +1,7 @@ /// ////import j = N./**/ [|q|]; -////namespace N { export const [|{| "isWriteAccess": true, "isDefinition": true |}q|] = 0; } +////namespace N { [|export const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 1 |}q|] = 0;|] } goTo.marker(); -verify.referenceGroups("", [{ definition: "const N.q: 0", ranges: test.ranges() }]); +verify.referenceGroups("", [{ definition: "const N.q: 0", ranges: test.rangesByText().get("q") }]); diff --git a/tests/cases/fourslash/findAllRefsImportEqualsJsonFile.ts b/tests/cases/fourslash/findAllRefsImportEqualsJsonFile.ts index 3c3c0dbb2e4..7b6e0e5bbc0 100644 --- a/tests/cases/fourslash/findAllRefsImportEqualsJsonFile.ts +++ b/tests/cases/fourslash/findAllRefsImportEqualsJsonFile.ts @@ -5,11 +5,11 @@ // @resolveJsonModule: true // @Filename: /a.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}j|] = require("[|./j.json|]"); +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}j|] = require("[|./j.json|]");|] ////[|j|]; // @Filename: /b.js -////const [|{| "isWriteAccess": true, "isDefinition": true |}j|] = require("[|./j.json|]"); +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}j|] = require("[|./j.json|]");|] ////[|j|]; // @Filename: /j.json @@ -17,7 +17,7 @@ verify.noErrors(); -const [r0, r1, r2, r3, r4, r5, r6] = test.ranges(); +const [r0Def, r0, r1, r2, r3Def, r3, r4, r5, r6] = test.ranges(); verify.singleReferenceGroup('import j = require("./j.json")', [r0, r2]); verify.referenceGroups([r1, r4], [{ definition: 'module "/j"', ranges: [r1, r4, r6] }]); verify.singleReferenceGroup('const j: {\n "x": number;\n}', [r3, r5]); diff --git a/tests/cases/fourslash/findAllRefsImportNamed.ts b/tests/cases/fourslash/findAllRefsImportNamed.ts index 5d18a8de164..50a88c2ed48 100644 --- a/tests/cases/fourslash/findAllRefsImportNamed.ts +++ b/tests/cases/fourslash/findAllRefsImportNamed.ts @@ -1,15 +1,15 @@ /// // @Filename: f.ts -////export { [|foo|] as [|{| "isWriteAccess": true, "isDefinition": true |}foo|] } -////function /*start*/[|{| "isWriteAccess": true, "isDefinition": true |}foo|](a: number, b: number) { } +////[|export { [|{| "declarationRangeIndex": 0 |}foo|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|] }|] +////[|function /*start*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}foo|](a: number, b: number) { }|] // @Filename: b.ts ////import x = require("./f"); ////x.[|foo|](1, 2); verify.noErrors(); -const [ foo0, foo1, foo2, foo3 ] = test.ranges(); +const [ foo0Def, foo0, foo1, foo2Def, foo2, foo3 ] = test.ranges(); const fooGroup = { definition: "function foo(a: number, b: number): void", ranges: [foo0, foo2] }; const exportFooGroup = { definition: "(alias) function foo(a: number, b: number): void\nexport foo", ranges: [foo1, foo3] }; verify.referenceGroups("start", [fooGroup, exportFooGroup]); diff --git a/tests/cases/fourslash/findAllRefsImportStarOfExportEquals.ts b/tests/cases/fourslash/findAllRefsImportStarOfExportEquals.ts index 7cab65bc388..56255873bc1 100644 --- a/tests/cases/fourslash/findAllRefsImportStarOfExportEquals.ts +++ b/tests/cases/fourslash/findAllRefsImportStarOfExportEquals.ts @@ -2,27 +2,26 @@ // @allowSyntheticDefaultimports: true // @Filename: /node_modules/a/index.d.ts -////declare function [|{| "isWriteAccess": true, "isDefinition": true |}a|](): void; -////declare namespace [|{| "isWriteAccess": true, "isDefinition": true |}a|] { +////[|declare function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}a|](): void;|] +////[|declare namespace [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}a|] { //// export const x: number; -////} -////export = [|a|]; +////}|] +////[|export = [|{| "declarationRangeIndex": 4 |}a|];|] // Import with different name and we find local refs // @Filename: /b.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}b|] from "a"; +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}b|] from "a";|] ////[|b|](); ////[|b|].x; // Import with same name and we find all refs // @Filename: /c.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}a|] from "a"; +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 10 |}a|] from "a";|] ////[|a|](); ////[|a|].x; verify.noErrors(); -const ranges = test.ranges(); -const [a0, a1, a2, b0, b1, b2, c0, c1, c2] = ranges; +const [a0Def, a0, a1Def, a1, a2Def, a2, b0Def, b0, b1, b2, c0Def, c0, c1, c2] = test.ranges(); const aRanges = [a0, a1, a2]; const bRanges = [b0, b1, b2]; const cRanges = [c0, c1, c2]; diff --git a/tests/cases/fourslash/findAllRefsImportType.ts b/tests/cases/fourslash/findAllRefsImportType.ts index 9f1fa09436e..ad21110fa0f 100644 --- a/tests/cases/fourslash/findAllRefsImportType.ts +++ b/tests/cases/fourslash/findAllRefsImportType.ts @@ -4,9 +4,9 @@ // @Filename: /a.js ////module.exports = 0; -////export type [|{| "isWriteAccess": true, "isDefinition": true |}N|] = number; +////[|export type [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}N|] = number;|] // @Filename: /b.js ////type T = import("./a").[|N|]; -verify.singleReferenceGroup("type N = number"); +verify.singleReferenceGroup("type N = number", "N"); diff --git a/tests/cases/fourslash/findAllRefsInClassExpression.ts b/tests/cases/fourslash/findAllRefsInClassExpression.ts index 8adc64e8e6d..a6e6de3d1f1 100644 --- a/tests/cases/fourslash/findAllRefsInClassExpression.ts +++ b/tests/cases/fourslash/findAllRefsInClassExpression.ts @@ -1,11 +1,11 @@ /// -////interface I { [|{| "isDefinition": true |}boom|](): void; } +////interface I { [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}boom|](): void;|] } ////new class C implements I { -//// [|{| "isWriteAccess": true, "isDefinition": true |}boom|](){} +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}boom|](){}|] ////} -const [r0, r1] = test.ranges(); +const [r0Def, r0, r1Def, r1] = test.ranges(); verify.referenceGroups([r0, r1], [ { definition: "(method) I.boom(): void", ranges: [r0] }, { definition: "(method) C.boom(): void", ranges: [r1] } diff --git a/tests/cases/fourslash/findAllRefsIndexedAccessTypes.ts b/tests/cases/fourslash/findAllRefsIndexedAccessTypes.ts index 49dac247294..34a17d8306d 100644 --- a/tests/cases/fourslash/findAllRefsIndexedAccessTypes.ts +++ b/tests/cases/fourslash/findAllRefsIndexedAccessTypes.ts @@ -1,14 +1,13 @@ /// ////interface I { -//// [|{| "isDefinition": true |}0|]: number; -//// [|{| "isDefinition": true |}s|]: string; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}0|]: number;|] +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}s|]: string;|] ////} ////interface J { //// a: I[[|0|]], //// b: I["[|s|]"], ////} -const [n0, s0, n1, s1] = test.ranges(); -verify.singleReferenceGroup("(property) I[0]: number", [n0, n1]); -verify.singleReferenceGroup("(property) I.s: string", [s0, s1]); +verify.singleReferenceGroup("(property) I[0]: number", "0"); +verify.singleReferenceGroup("(property) I.s: string", "s"); diff --git a/tests/cases/fourslash/findAllRefsInheritedProperties1.ts b/tests/cases/fourslash/findAllRefsInheritedProperties1.ts index 9e58a37c589..42bf6bcb70a 100644 --- a/tests/cases/fourslash/findAllRefsInheritedProperties1.ts +++ b/tests/cases/fourslash/findAllRefsInheritedProperties1.ts @@ -1,14 +1,14 @@ /// //// class class1 extends class1 { -//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } -//// [|{| "isDefinition": true |}propName|]: string; +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}doStuff|]() { }|] +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}propName|]: string;|] //// } //// //// var v: class1; //// v.[|doStuff|](); //// v.[|propName|]; -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2, r3] = test.ranges(); verify.singleReferenceGroup("(method) class1.doStuff(): void", [r0, r2]); verify.singleReferenceGroup("(property) class1.propName: string", [r1, r3]); diff --git a/tests/cases/fourslash/findAllRefsInheritedProperties2.ts b/tests/cases/fourslash/findAllRefsInheritedProperties2.ts index 2e776e48acd..3ba54ab0193 100644 --- a/tests/cases/fourslash/findAllRefsInheritedProperties2.ts +++ b/tests/cases/fourslash/findAllRefsInheritedProperties2.ts @@ -1,14 +1,14 @@ /// //// interface interface1 extends interface1 { -//// [|{| "isDefinition": true |}doStuff|](): void; // r0 -//// [|{| "isDefinition": true |}propName|]: string; // r1 +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}doStuff|](): void;|] // r0 +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}propName|]: string;|] // r1 //// } //// //// var v: interface1; //// v.[|doStuff|](); // r2 //// v.[|propName|]; // r3 -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2, r3] = test.ranges(); 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 ea5b1ce7bf4..d7019164aeb 100644 --- a/tests/cases/fourslash/findAllRefsInheritedProperties3.ts +++ b/tests/cases/fourslash/findAllRefsInheritedProperties3.ts @@ -1,23 +1,23 @@ /// //// class class1 extends class1 { -//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } // r0 -//// [|{| "isDefinition": true |}propName|]: string; // r1 +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}doStuff|]() { }|] // r0 +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}propName|]: string;|] // r1 //// } //// interface interface1 extends interface1 { -//// [|{| "isDefinition": true |}doStuff|](): void; // r2 -//// [|{| "isDefinition": true |}propName|]: string; // r3 +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 4 |}doStuff|](): void;|] // r2 +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 6 |}propName|]: string;|] // r3 //// } //// class class2 extends class1 implements interface1 { -//// [|{| "isWriteAccess": true, "isDefinition": true |}doStuff|]() { } // r4 -//// [|{| "isDefinition": true |}propName|]: string; // r5 +//// [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 8 |}doStuff|]() { }|] // r4 +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 10 |}propName|]: string;|] // r5 //// } //// //// var v: class2; //// v.[|doStuff|](); // r6 //// v.[|propName|]; // r7 -const [r0, r1, r2, r3, r4, r5, r6, r7] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3, r4Def, r4, r5Def, r5, r6, r7] = test.ranges(); verify.referenceGroups(r0, [ { definition: "(method) class1.doStuff(): void", ranges: [r0] }, { definition: "(method) class2.doStuff(): void", ranges: [r4, r6] }, diff --git a/tests/cases/fourslash/findAllRefsInheritedProperties4.ts b/tests/cases/fourslash/findAllRefsInheritedProperties4.ts index 2528fef1939..fde757d28d3 100644 --- a/tests/cases/fourslash/findAllRefsInheritedProperties4.ts +++ b/tests/cases/fourslash/findAllRefsInheritedProperties4.ts @@ -1,19 +1,19 @@ /// //// interface C extends D { -//// [|{| "isDefinition": true |}prop0|]: string; // r0 -//// [|{| "isDefinition": true |}prop1|]: number; // r1 +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}prop0|]: string;|] // r0 +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}prop1|]: number;|] // r1 //// } //// //// interface D extends C { -//// [|{| "isDefinition": true |}prop0|]: string; // r2 +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 4 |}prop0|]: string;|] // r2 //// } //// //// var d: D; //// d.[|prop0|]; // r3 //// d.[|prop1|]; // r4 -const [r0, r1, r2, r3, r4] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3, r4] = test.ranges(); verify.referenceGroups([r0, r2, r3], [ { definition: "(property) C.prop0: string", ranges: [r0] }, { definition: "(property) D.prop0: string", ranges: [r2, r3] } diff --git a/tests/cases/fourslash/findAllRefsInheritedProperties5.ts b/tests/cases/fourslash/findAllRefsInheritedProperties5.ts index 343328405d5..e917871f465 100644 --- a/tests/cases/fourslash/findAllRefsInheritedProperties5.ts +++ b/tests/cases/fourslash/findAllRefsInheritedProperties5.ts @@ -1,19 +1,19 @@ /// //// class C extends D { -//// [|{| "isDefinition": true |}prop0|]: string; // r0 -//// [|{| "isDefinition": true |}prop1|]: number; // r1 +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}prop0|]: string;|] // r0 +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 2 |}prop1|]: number;|] // r1 //// } //// //// class D extends C { -//// [|{| "isDefinition": true |}prop0|]: string; // r2 +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 4 |}prop0|]: string;|] // r2 //// } //// //// var d: D; //// d.[|prop0|]; // r3 //// d.[|prop1|]; // r4 -const [r0, r1, r2, r3, r4] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3, r4] = test.ranges(); verify.singleReferenceGroup("(property) C.prop0: string", [r0]); verify.singleReferenceGroup("(property) C.prop1: number", [r1]); verify.singleReferenceGroup("(property) D.prop0: string", [r2, r3]); diff --git a/tests/cases/fourslash/findAllRefsInsideTemplates1.ts b/tests/cases/fourslash/findAllRefsInsideTemplates1.ts index 8d41961c6fd..44ad694d9bc 100644 --- a/tests/cases/fourslash/findAllRefsInsideTemplates1.ts +++ b/tests/cases/fourslash/findAllRefsInsideTemplates1.ts @@ -1,6 +1,6 @@ /// -////var [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 10; +////[|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|] = 10;|] ////var y = `${ [|x|] } ${ [|x|] }` -verify.singleReferenceGroup("var x: number"); +verify.singleReferenceGroup("var x: number", "x"); diff --git a/tests/cases/fourslash/findAllRefsInsideTemplates2.ts b/tests/cases/fourslash/findAllRefsInsideTemplates2.ts index 24a4a7c131b..09475e4cead 100644 --- a/tests/cases/fourslash/findAllRefsInsideTemplates2.ts +++ b/tests/cases/fourslash/findAllRefsInsideTemplates2.ts @@ -1,6 +1,6 @@ /// -////function [|{| "isWriteAccess": true, "isDefinition": true |}f|](...rest: any[]) { } +////[|function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}f|](...rest: any[]) { }|] ////[|f|] `${ [|f|] } ${ [|f|] }` -verify.singleReferenceGroup("function f(...rest: any[]): void"); +verify.singleReferenceGroup("function f(...rest: any[]): void", "f"); diff --git a/tests/cases/fourslash/findAllRefsInsideWithBlock.ts b/tests/cases/fourslash/findAllRefsInsideWithBlock.ts index 52936248095..c31ab04376d 100644 --- a/tests/cases/fourslash/findAllRefsInsideWithBlock.ts +++ b/tests/cases/fourslash/findAllRefsInsideWithBlock.ts @@ -1,6 +1,6 @@ /// -////var [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 0; +////[|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|] = 0;|] //// ////with ({}) { //// var y = x; // Reference of x here should not be picked @@ -9,4 +9,4 @@ //// ////[|{| "isWriteAccess": true |}x|] = [|x|] + 1; -verify.singleReferenceGroup("var x: number"); +verify.singleReferenceGroup("var x: number", "x"); diff --git a/tests/cases/fourslash/findAllRefsJsDocTypeDef_js.ts b/tests/cases/fourslash/findAllRefsJsDocTypeDef_js.ts index a2d0cad3886..f03511adf51 100644 --- a/tests/cases/fourslash/findAllRefsJsDocTypeDef_js.ts +++ b/tests/cases/fourslash/findAllRefsJsDocTypeDef_js.ts @@ -5,7 +5,7 @@ // @allowJs: true // @Filename: /a.js -/////** @typedef {number} [|{| "isWriteAccess": true, "isDefinition": true |}T|] */ +/////** [|@typedef {number} [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}T|]|] */ //// /////** //// * @return {[|T|]} @@ -17,4 +17,4 @@ //// */ ////function f2(obj) { return 0; } -verify.singleReferenceGroup("type T = number"); +verify.singleReferenceGroup("type T = number", "T"); diff --git a/tests/cases/fourslash/findAllRefsMappedType.ts b/tests/cases/fourslash/findAllRefsMappedType.ts index 8c6c59150af..21090b0f32b 100644 --- a/tests/cases/fourslash/findAllRefsMappedType.ts +++ b/tests/cases/fourslash/findAllRefsMappedType.ts @@ -1,10 +1,10 @@ /// -////interface T { [|{| "isDefinition": true |}a|]: number; } +////interface T { [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}a|]: number;|] } ////type U = { readonly [K in keyof T]?: string }; ////declare const t: T; ////t.[|a|]; ////declare const u: U; ////u.[|a|]; -verify.singleReferenceGroup("(property) T.a: number"); +verify.singleReferenceGroup("(property) T.a: number", "a"); diff --git a/tests/cases/fourslash/findAllRefsModuleAugmentation.ts b/tests/cases/fourslash/findAllRefsModuleAugmentation.ts index c5adab35669..df8fb0ed615 100644 --- a/tests/cases/fourslash/findAllRefsModuleAugmentation.ts +++ b/tests/cases/fourslash/findAllRefsModuleAugmentation.ts @@ -1,7 +1,7 @@ /// // @Filename: /node_modules/foo/index.d.ts -////export type [|{| "isWriteAccess": true, "isDefinition": true |}T|] = number; +////[|export type [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}T|] = number;|] // @Filename: /a.ts ////import * as foo from "foo"; @@ -10,4 +10,4 @@ ////} verify.noErrors(); -verify.singleReferenceGroup("type T = number"); +verify.singleReferenceGroup("type T = number", "T"); diff --git a/tests/cases/fourslash/findAllRefsModuleDotExports.ts b/tests/cases/fourslash/findAllRefsModuleDotExports.ts index bc1bd705c2f..ca30b341b90 100644 --- a/tests/cases/fourslash/findAllRefsModuleDotExports.ts +++ b/tests/cases/fourslash/findAllRefsModuleDotExports.ts @@ -6,6 +6,7 @@ ////const b = require("[|./b|]"); // @Filename: /b.js -////[|module|].exports = 0; +////[|[|{| "declarationRangeIndex": 1 |}module|].exports = 0;|] -verify.singleReferenceGroup('module "/b"') +const [r0, rDef, r1] = test.ranges(); +verify.singleReferenceGroup('module "/b"', [r0, r1]); diff --git a/tests/cases/fourslash/findAllRefsNoImportClause.ts b/tests/cases/fourslash/findAllRefsNoImportClause.ts index b98f5d02d01..fc133afc4d8 100644 --- a/tests/cases/fourslash/findAllRefsNoImportClause.ts +++ b/tests/cases/fourslash/findAllRefsNoImportClause.ts @@ -3,9 +3,9 @@ // https://github.com/Microsoft/TypeScript/issues/15452 // @Filename: /a.ts -////export const [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 0; +////[|export const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|] = 0;|] // @Filename: /b.ts ////import "./a"; -verify.singleReferenceGroup("const x: 0"); +verify.singleReferenceGroup("const x: 0", "x"); diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName01.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName01.ts index 5a72ca1c1ec..404acea3ca4 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName01.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName01.ts @@ -1,11 +1,11 @@ /// ////interface I { -//// [|{| "isDefinition": true |}property1|]: number; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}property1|]: number;|] //// property2: string; ////} //// ////var foo: I; -////var { [|property1|]: prop1 } = foo; +////[|var { [|{| "declarationRangeIndex": 2 |}property1|]: prop1 } = foo;|] -verify.singleReferenceGroup("(property) I.property1: number"); +verify.singleReferenceGroup("(property) I.property1: number", "property1"); diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName02.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName02.ts index 76b6d046b8e..95bfdc51d82 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName02.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName02.ts @@ -1,11 +1,11 @@ /// ////interface I { -//// [|{| "isDefinition": true |}property1|]: number; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}property1|]: number;|] //// property2: string; ////} //// ////var foo: I; -////var { [|property1|]: {} } = foo; +////[|var { [|{| "declarationRangeIndex": 2 |}property1|]: {} } = foo;|] -verify.singleReferenceGroup("(property) I.property1: number"); +verify.singleReferenceGroup("(property) I.property1: number", "property1"); diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName03.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName03.ts index f82eca087bb..aa209d15b54 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName03.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName03.ts @@ -1,16 +1,18 @@ /// ////interface I { -//// [|{| "isDefinition": true |}property1|]: number; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}property1|]: number;|] //// property2: string; ////} //// ////var foo: I; -////var [{ [|property1|]: prop1 }, { [|{| "isWriteAccess": true, "isDefinition": true |}property1|], property2 } ] = [foo, foo]; +////[|var [{ [|{| "declarationRangeIndex": 2 |}property1|]: prop1 }, { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}property1|], property2 } ] = [foo, foo];|] -const ranges = test.ranges(); -const [r0, r1, r2] = ranges; -verify.referenceGroups([r0, r1], [{ definition: "(property) I.property1: number", ranges }]); +const [r0Def, r0, r1Def, r1, r2] = test.ranges(); +verify.referenceGroups([r0, r1], [{ + definition: "(property) I.property1: number", + ranges: [r0, r1, r2] +}]); 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 c3bebdb2623..b3fc306e47b 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName04.ts @@ -1,19 +1,18 @@ /// ////interface I { -//// [|{| "isDefinition": true |}property1|]: number; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}property1|]: number;|] //// property2: string; ////} //// -////function f({ [|property1|]: p1 }: I, -//// { [|{| "isWriteAccess": true, "isDefinition": true |}property1|] }: I, +////function f([|{ [|{| "declarationRangeIndex": 2 |}property1|]: p1 }: I|], +//// [|{ [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}property1|] }: I|], //// { property1: p2 }) { //// //// return [|property1|] + 1; ////} -const ranges = test.ranges(); -const [r0, r1, r2, r3] = ranges; +const [r0Def, r0, r1Def, r1, r2Def, r2, r3] = test.ranges(); verify.referenceGroups([r0, r1], [{ definition: "(property) I.property1: number", ranges: [r0, r1, r2] }]); verify.referenceGroups(r2, [ { definition: "(property) I.property1: number", ranges: [r0, r1] }, diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts index 62d1637f3b3..2cf78e46c96 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName06.ts @@ -1,24 +1,26 @@ /// ////interface I { -//// [|{| "isDefinition": true |}property1|]: number; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}property1|]: number;|] //// property2: string; ////} //// ////var elems: I[]; -////for (let { [|property1|]: p } of elems) { +////for ([|let { [|{| "declarationRangeIndex": 2 |}property1|]: p } of elems|]) { ////} -////for (let { [|{| "isWriteAccess": true, "isDefinition": true |}property1|] } of elems) { +////for ([|let { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}property1|] } of elems|]) { ////} -////for (var { [|property1|]: p1 } of elems) { +////for ([|var { [|{| "declarationRangeIndex": 6 |}property1|]: p1 } of elems|]) { ////} ////var p2; -////for ({ [|{| "isWriteAccess": true, "isDefinition": true |}property1|] : p2 } of elems) { +////for ([|{ [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 8 |}property1|] : p2 } of elems|]) { ////} -const ranges = test.ranges(); -const [r0, r1, r2, r3, r4] = ranges; -verify.referenceGroups([r0, r1, r3, r4], [{ definition: "(property) I.property1: number", ranges }]); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3, r4Def, r4] = test.ranges(); +verify.referenceGroups([r0, r1, r3, r4], [{ + definition: "(property) I.property1: number", + ranges: [r0, r1, r2, r3, r4] +}]); verify.referenceGroups(r2, [ { definition: "(property) I.property1: number", ranges: [r0, r1, r3, r4] }, { definition: "let property1: number", ranges: [r2] } diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName07.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName07.ts index 18fa4e43273..318f26dc864 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName07.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName07.ts @@ -2,6 +2,6 @@ ////let p, b; //// -////p, [{ [|{| "isDefinition": true |}a|]: p, b }] = [{ [|{| "isWriteAccess": true, "isDefinition": true |}a|]: 10, b: true }]; +////p, [|[{ [|{| "isDefinition": true, "declarationRangeIndex": 0 |}a|]: p, b }] = [{ [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}a|]: 10|], b: true }]|]; -verify.singleReferenceGroup("(property) a: any"); +verify.singleReferenceGroup("(property) a: any", "a"); diff --git a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts index 7d31cfd4345..37c3a6ab0e1 100644 --- a/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts +++ b/tests/cases/fourslash/findAllRefsObjectBindingElementPropertyName10.ts @@ -1,11 +1,11 @@ /// ////interface Recursive { -//// [|{| "isDefinition": true |}next|]?: Recursive; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}next|]?: Recursive;|] //// value: any; ////} //// -////function f ({ [|next|]: { [|next|]: x} }: Recursive) { +////function f ([|{ [|{| "declarationRangeIndex": 2 |}next|]: { [|{| "declarationRangeIndex": 2 |}next|]: x} }: Recursive|]) { ////} -verify.singleReferenceGroup("(property) Recursive.next?: Recursive"); +verify.singleReferenceGroup("(property) Recursive.next?: Recursive", "next"); diff --git a/tests/cases/fourslash/findAllRefsOfConstructor.ts b/tests/cases/fourslash/findAllRefsOfConstructor.ts index 08846380749..26611ef9a03 100644 --- a/tests/cases/fourslash/findAllRefsOfConstructor.ts +++ b/tests/cases/fourslash/findAllRefsOfConstructor.ts @@ -2,13 +2,13 @@ ////class A { -//// [|constructor|](s: string) {} +//// [|[|{| "declarationRangeIndex": 0 |}constructor|](s: string) {}|] ////} ////class B extends A { } ////class C extends B { -//// [|constructor|]() { +//// [|[|{| "declarationRangeIndex": 2 |}constructor|]() { //// [|super|](""); -//// } +//// }|] ////} ////class D extends B { } ////class E implements A { } @@ -19,7 +19,7 @@ ////const e = new E(); verify.noErrors(); -const [aCtr, cCtr, cSuper, aNew, bNew, cNew, dNew] = test.ranges(); +const [aCtrDef, aCtr, cCtrDef, cCtr, cSuper, aNew, bNew, cNew, dNew] = test.ranges(); verify.referenceGroups(aCtr, [ { definition: "class A", ranges: [aCtr, aNew] }, { definition: "class B", ranges: [cSuper, bNew]}, diff --git a/tests/cases/fourslash/findAllRefsOfConstructor2.ts b/tests/cases/fourslash/findAllRefsOfConstructor2.ts index 17991cb555c..c51c7a1c098 100644 --- a/tests/cases/fourslash/findAllRefsOfConstructor2.ts +++ b/tests/cases/fourslash/findAllRefsOfConstructor2.ts @@ -2,15 +2,15 @@ ////class A { -//// [|constructor|](s: string) {} +//// [|[|{| "declarationRangeIndex": 0 |}constructor|](s: string) {}|] ////} ////class B extends A { -//// [|constructor|]() { [|super|](""); } +//// [|[|{| "declarationRangeIndex": 2 |}constructor|]() { [|super|](""); }|] ////} ////class C extends B { -//// [|constructor|]() { +//// [|[|{| "declarationRangeIndex": 5 |}constructor|]() { //// [|super|](); -//// } +//// }|] ////} ////class D extends B { } ////const a = new [|A|]("a"); @@ -19,7 +19,7 @@ ////const d = new [|D|](); verify.noErrors(); -const [aCtr, bCtr, bSuper, cCtr, cSuper, aNew, bNew, cNew, dNew] = test.ranges(); +const [aCtrDef, aCtr, bCtrDef, bCtr, bSuper, cCtrDef, cCtr, cSuper, aNew, bNew, cNew, dNew] = test.ranges(); verify.referenceGroups(aCtr, [{ definition: "class A", ranges: [aCtr, bSuper, aNew] }]); verify.referenceGroups(bCtr, [{ definition: "class B", ranges: [bCtr, cSuper, bNew]}, { definition: "class D", ranges: [dNew]}]); verify.referenceGroups(cCtr, [{ definition: "class C", ranges: [cCtr, cNew]}]); \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsOfConstructor_multipleFiles.ts b/tests/cases/fourslash/findAllRefsOfConstructor_multipleFiles.ts index a20d9fc1f29..9e2681a2249 100644 --- a/tests/cases/fourslash/findAllRefsOfConstructor_multipleFiles.ts +++ b/tests/cases/fourslash/findAllRefsOfConstructor_multipleFiles.ts @@ -3,26 +3,26 @@ // @Filename: f.ts ////class A { -//// [|constructor|](s: string) {} +//// [|[|{| "declarationRangeIndex": 0 |}constructor|](s: string) {}|] ////} ////class B extends A { } -////export { [|{| "isWriteAccess": true, "isDefinition": true |}A|], [|{| "isWriteAccess": true, "isDefinition": true |}B|] }; +////[|export { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}A|], [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}B|] };|] // @Filename: a.ts -////import { [|A|] as A1 } from "./f"; +////[|import { [|{| "declarationRangeIndex": 5 |}A|] as A1 } from "./f";|] ////const a1 = new [|A1|]("a1"); ////export default class extends A1 { } -////export { [|B|] as [|{| "isWriteAccess": true, "isDefinition": true |}B1|] } from "./f"; +////[|export { [|{| "declarationRangeIndex": 8 |}B|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 8 |}B1|] } from "./f";|] // @Filename: b.ts -////import [|B|], { B1 } from "./a"; +////[|import [|{| "declarationRangeIndex": 11 |}B|], { B1 } from "./a";|] ////const d = new [|B|]("b"); ////const d1 = new [|B1|]("b1"); verify.noErrors(); -const [aCtr, aExport, bExport, aImport, a1New, bReExport, b1Export, bDefault, bNew, b1New ] = test.ranges(); +const [aCtrDef, aCtr, exportDef, aExport, bExport, aImportDef, aImport, a1New, reExportDef, bReExport, b1Export, bDefaultDef, bDefault, bNew, b1New ] = test.ranges(); verify.referenceGroups(aCtr, [ { definition: "class A", ranges: [aCtr, aExport] }, { definition: "class B", ranges: [bExport]}, diff --git a/tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts b/tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts index c425029490f..0bbc5024345 100644 --- a/tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts +++ b/tests/cases/fourslash/findAllRefsOfConstructor_withModifier.ts @@ -1,9 +1,9 @@ /// ////class X { -//// public [|constructor|]() {} +//// [|public [|{| "declarationRangeIndex": 0 |}constructor|]() {}|] ////} ////var x = new [|X|](); -const ranges = test.ranges(); +const [rDef, ...ranges] = test.ranges(); verify.referenceGroups(ranges[0], [{ definition: "class X", ranges }]); From 1163a93ed6af2e31cc8c2908f114a8396689212c Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 5 Jun 2019 16:26:04 -0700 Subject: [PATCH 29/44] Handle default keyword of default export --- src/services/findAllReferences.ts | 7 ++++++- tests/cases/fourslash/findAllRefsForDefaultExport04.ts | 8 ++++---- .../fourslash/findAllRefsForDefaultExportAnonymous.ts | 6 +++--- .../fourslash/findAllRefsForDefaultExport_anonymous.ts | 6 +++--- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 14e47b2c4d1..62191137f25 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -79,7 +79,12 @@ namespace ts.FindAllReferences { // Property name of the import export specifier or binding pattern, use parent ((isImportOrExportSpecifier(node.parent) || isBindingElement(node.parent)) && node.parent.propertyName === node) || - isExportAssignment(node.parent) && node.parent.expression === node) { + isExportAssignment(node.parent) && ( + node.parent.expression === node || + (!node.parent.isExportEquals && node.kind === SyntaxKind.DefaultKeyword) + ) || + // Is default export + (node.kind === SyntaxKind.DefaultKeyword && hasModifier(node.parent, ModifierFlags.ExportDefault))) { return getDeclarationForDeclarationSpan(node.parent); } diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport04.ts b/tests/cases/fourslash/findAllRefsForDefaultExport04.ts index 279f2bd1e81..aa10ab1d59d 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport04.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport04.ts @@ -1,14 +1,14 @@ /// // @Filename: /a.ts -////const [|{| "isWriteAccess": true, "isDefinition": true |}a|] = 0; -////export [|{| "isWriteAccess": true, "isDefinition": true |}default|] [|a|]; +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}a|] = 0;|] +////[|export [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}default|] [|{| "declarationRangeIndex": 2 |}a|];|] // @Filename: /b.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}a|] from "./a"; +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}a|] from "./a";|] ////[|a|]; -const [r0, r1, r2, r3, r4] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2, r3Def, r3, r4] = test.ranges(); verify.referenceGroups([r0, r2], [ { definition: "const a: 0", ranges: [r0, r2] }, { definition: "(alias) const a: 0\nimport a", ranges: [r3, r4] } diff --git a/tests/cases/fourslash/findAllRefsForDefaultExportAnonymous.ts b/tests/cases/fourslash/findAllRefsForDefaultExportAnonymous.ts index 3beb5b59424..1820624374d 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExportAnonymous.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExportAnonymous.ts @@ -1,12 +1,12 @@ /// // @Filename: /a.ts -////export [|{| "isWriteAccess": true, "isDefinition": true |}default|] function() {} +////[|export [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}default|] function() {}|] // @Filename: /b.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}f|] from "./a"; +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}f|] from "./a";|] -const [r0, r1] = test.ranges(); +const [r0Def, r0, r1Def, r1] = test.ranges(); verify.referenceGroups(r0, [ { definition: "function default(): void", ranges: [r0] }, { definition: "import f", ranges: [r1] }, diff --git a/tests/cases/fourslash/findAllRefsForDefaultExport_anonymous.ts b/tests/cases/fourslash/findAllRefsForDefaultExport_anonymous.ts index 058bc419986..778203c1bcd 100644 --- a/tests/cases/fourslash/findAllRefsForDefaultExport_anonymous.ts +++ b/tests/cases/fourslash/findAllRefsForDefaultExport_anonymous.ts @@ -1,12 +1,12 @@ /// // @Filename: /a.ts -////export [|{| "isDefinition": true, "isWriteAccess": true |}default|] 1; +////[|export [|{| "isDefinition": true, "isWriteAccess": true, "declarationRangeIndex": 0 |}default|] 1;|] // @Filename: /b.ts -////import [|{| "isDefinition": true, "isWriteAccess": true |}a|] from "./a"; +////[|import [|{| "isDefinition": true, "isWriteAccess": true, "declarationRangeIndex": 2 |}a|] from "./a";|] -const [r0, r1] = test.ranges(); +const [r0Def, r0, r1Def, r1] = test.ranges(); verify.referenceGroups(r0, [ { definition: "(property) default: 1", ranges: [r0] }, { definition: "import a", ranges: [r1] }, From 64de998356c16cec75eaaab52e8778d868b159b3 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 6 Jun 2019 09:00:57 -0700 Subject: [PATCH 30/44] More tests --- tests/cases/fourslash/findAllRefsEnumAsNamespace.ts | 4 ++-- tests/cases/fourslash/findAllRefsExportAsNamespace.ts | 7 +++---- .../cases/fourslash/findAllRefsExportConstEqualToClass.ts | 8 ++++---- .../fourslash/findAllRefsExportDefaultClassConstructor.ts | 4 ++-- tests/cases/fourslash/findAllRefsExportNotAtTopLevel.ts | 4 ++-- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/cases/fourslash/findAllRefsEnumAsNamespace.ts b/tests/cases/fourslash/findAllRefsEnumAsNamespace.ts index a065f355d10..e98da5f8d9f 100644 --- a/tests/cases/fourslash/findAllRefsEnumAsNamespace.ts +++ b/tests/cases/fourslash/findAllRefsEnumAsNamespace.ts @@ -1,6 +1,6 @@ /// -////enum [|{| "isWriteAccess": true, "isDefinition": true |}E|] { A } +////[|enum [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}E|] { A }|] ////let e: [|E|].A; -verify.singleReferenceGroup("enum E"); +verify.singleReferenceGroup("enum E", "E"); diff --git a/tests/cases/fourslash/findAllRefsExportAsNamespace.ts b/tests/cases/fourslash/findAllRefsExportAsNamespace.ts index f6149f17d90..e97d3411ce4 100644 --- a/tests/cases/fourslash/findAllRefsExportAsNamespace.ts +++ b/tests/cases/fourslash/findAllRefsExportAsNamespace.ts @@ -3,19 +3,18 @@ // `export as namespace` results in global search. // @Filename: /node_modules/a/index.d.ts -////export function [|{| "isWriteAccess": true, "isDefinition": true |}f|](): void; +////[|export function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}f|](): void;|] ////export as namespace A; // @Filename: /b.ts -////import { [|{| "isWriteAccess": true, "isDefinition": true |}f|] } from "a"; +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}f|] } from "a";|] // @Filename: /c.ts ////A.[|f|](); verify.noErrors(); -const ranges = test.ranges(); -const [r0, r1, r2] = ranges; +const [r0Def, r0, r1Def, r1, r2] = test.ranges(); const globals = { definition: "function f(): void", ranges: [r0, r2] }; const imports = { definition: "(alias) function f(): void\nimport f", ranges: [r1] }; diff --git a/tests/cases/fourslash/findAllRefsExportConstEqualToClass.ts b/tests/cases/fourslash/findAllRefsExportConstEqualToClass.ts index 6be7ea0bdba..98ab1b3a456 100644 --- a/tests/cases/fourslash/findAllRefsExportConstEqualToClass.ts +++ b/tests/cases/fourslash/findAllRefsExportConstEqualToClass.ts @@ -1,13 +1,13 @@ /// // @Filename: /a.ts -////class [|{| "isWriteAccess": true, "isDefinition": true |}C|] {} -////export const [|{| "isWriteAccess": true, "isDefinition": true |}D|] = [|C|]; +////[|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}C|] {}|] +////[|export const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}D|] = [|C|];|] // @Filename: /b.ts -////import { [|{| "isWriteAccess": true, "isDefinition": true |}D|] } from "./a"; +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}D|] } from "./a";|] -const [C0, D0, C1, D1] = test.ranges(); +const [C0Def, C0, D0Def, D0, C1, D1Def, D1] = test.ranges(); verify.singleReferenceGroup("class C", [C0, C1]); diff --git a/tests/cases/fourslash/findAllRefsExportDefaultClassConstructor.ts b/tests/cases/fourslash/findAllRefsExportDefaultClassConstructor.ts index 0f269bd5f5b..e8754ff15be 100644 --- a/tests/cases/fourslash/findAllRefsExportDefaultClassConstructor.ts +++ b/tests/cases/fourslash/findAllRefsExportDefaultClassConstructor.ts @@ -1,5 +1,5 @@ ////export default class { -//// [|constructor|]() {} +//// [|[|{| "declarationRangeIndex": 0 |}constructor|]() {}|] ////} -verify.singleReferenceGroup("class default"); +verify.singleReferenceGroup("class default", "constructor"); diff --git a/tests/cases/fourslash/findAllRefsExportNotAtTopLevel.ts b/tests/cases/fourslash/findAllRefsExportNotAtTopLevel.ts index 7f9c258bbe2..a99116726f8 100644 --- a/tests/cases/fourslash/findAllRefsExportNotAtTopLevel.ts +++ b/tests/cases/fourslash/findAllRefsExportNotAtTopLevel.ts @@ -1,8 +1,8 @@ /// ////{ -//// export const [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 0; +//// [|export const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|] = 0;|] //// [|x|]; ////} -verify.singleReferenceGroup("const x: 0"); +verify.singleReferenceGroup("const x: 0", "x"); From e4a2dd510fa2c5b144d328d00cd264addf239b45 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 6 Jun 2019 09:09:39 -0700 Subject: [PATCH 31/44] Handle export keyword of export assignment --- src/services/findAllReferences.ts | 9 +++------ tests/cases/fourslash/findAllRefsExportEquals.ts | 8 ++++---- .../fourslash/findAllRefs_importType_exportEquals.ts | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index 62191137f25..ae31ab544f3 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -74,15 +74,12 @@ namespace ts.FindAllReferences { undefined; } - if (isConstructorDeclaration(node.parent) || - node.parent.name === node || // node is name of declaration, use parent + if (node.parent.name === node || // node is name of declaration, use parent + isConstructorDeclaration(node.parent) || + isExportAssignment(node.parent) || // Property name of the import export specifier or binding pattern, use parent ((isImportOrExportSpecifier(node.parent) || isBindingElement(node.parent)) && node.parent.propertyName === node) || - isExportAssignment(node.parent) && ( - node.parent.expression === node || - (!node.parent.isExportEquals && node.kind === SyntaxKind.DefaultKeyword) - ) || // Is default export (node.kind === SyntaxKind.DefaultKeyword && hasModifier(node.parent, ModifierFlags.ExportDefault))) { return getDeclarationForDeclarationSpan(node.parent); diff --git a/tests/cases/fourslash/findAllRefsExportEquals.ts b/tests/cases/fourslash/findAllRefsExportEquals.ts index 3580c8fe4ee..fd17a82633c 100644 --- a/tests/cases/fourslash/findAllRefsExportEquals.ts +++ b/tests/cases/fourslash/findAllRefsExportEquals.ts @@ -1,13 +1,13 @@ /// // @Filename: /a.ts -////type [|{| "isWriteAccess": true, "isDefinition": true |}T|] = number; -////[|export|] = [|T|]; +////[|type [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}T|] = number;|] +////[|[|{| "declarationRangeIndex": 2 |}export|] = [|{| "declarationRangeIndex": 2 |}T|];|] // @Filename: /b.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}T|] = require("[|./a|]"); +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}T|] = require("[|./a|]");|] -const [r0, r1, r2, r3, r4] = test.ranges(); +const [r0Def, r0, r12Def, r1, r2, r3Def, r3, r4] = test.ranges(); const mod = { definition: 'module "/a"', ranges: [r4, r1] }; const a = { definition: "type T = number", ranges: [r0, r2] }; const b = { definition: '(alias) type T = number\nimport T = require("./a")', ranges: [r3] }; diff --git a/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts b/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts index 0d60c153ce9..4597c3a8bc9 100644 --- a/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts +++ b/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts @@ -5,7 +5,7 @@ ////[|namespace [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}T|] { //// export type U = string; ////}|] -////[|[|export|] = [|{| "declarationRangeIndex": 4 |}T|];|] +////[|[|{| "declarationRangeIndex": 4 |}export|] = [|{| "declarationRangeIndex": 4 |}T|];|] // @Filename: /b.ts ////const x: import("[|./[|a|]|]") = 0; From 018026ad52fcc86e2ddd8241a2db80d29b9f0805 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 6 Jun 2019 09:49:31 -0700 Subject: [PATCH 32/44] More tests --- .../cases/fourslash/ambientShorthandFindAllRefs.ts | 7 +++---- .../cancellationWhenfindingAllRefsOnDefinition.ts | 6 +++--- tests/cases/fourslash/doubleUnderscoreRenames.ts | 8 ++++---- tests/cases/fourslash/duplicatePackageServices.ts | 14 +++++++------- .../fourslash/esModuleInteropFindAllReferences.ts | 4 ++-- .../fourslash/esModuleInteropFindAllReferences2.ts | 4 ++-- ...lReferPropertyAccessExpressionHeritageClause.ts | 4 ++-- .../fourslash/findAllReferencesDynamicImport2.ts | 6 +++--- .../fourslash/findAllReferencesDynamicImport3.ts | 6 +++--- .../fourslash/findAllReferencesJSDocFunctionNew.ts | 4 ++-- .../fourslash/findAllReferencesOfConstructor.ts | 9 ++++----- .../findAllReferencesOfConstructor_badOverload.ts | 6 +++--- .../fourslash/findAllReferencesOfJsonModule.ts | 4 ++-- .../findAllReferencesUmdModuleAsGlobalConst.ts | 7 ++++--- tests/cases/fourslash/findAllRefsBadImport.ts | 4 ++-- .../cases/fourslash/findAllRefsClassExpression0.ts | 8 ++++---- .../cases/fourslash/findAllRefsClassExpression1.ts | 6 +++--- .../cases/fourslash/findAllRefsClassExpression2.ts | 6 +++--- .../findAllRefsClassWithStaticThisAccess.ts | 6 +++--- .../fourslash/findAllRefsConstructorFunctions.ts | 6 +++--- tests/cases/fourslash/findAllRefsDeclareClass.ts | 6 +++--- tests/cases/fourslash/findAllRefsDefaultImport.ts | 6 +++--- .../findAllRefsDefaultImportThroughNamespace.ts | 6 +++--- tests/cases/fourslash/findAllRefsDefinition.ts | 4 ++-- .../fourslash/findAllRefsDestructureGeneric.ts | 6 +++--- .../fourslash/findAllRefsDestructureGetter.ts | 8 ++++---- .../fourslash/findAllRefsDestructureGetter2.ts | 8 ++++---- .../fourslash/shims-pp/getReferencesAtPosition.ts | 6 +++--- tests/cases/fourslash/shims-pp/getRenameInfo.ts | 6 +++--- .../fourslash/shims/getReferencesAtPosition.ts | 6 +++--- tests/cases/fourslash/shims/getRenameInfo.ts | 6 +++--- 31 files changed, 96 insertions(+), 97 deletions(-) diff --git a/tests/cases/fourslash/ambientShorthandFindAllRefs.ts b/tests/cases/fourslash/ambientShorthandFindAllRefs.ts index 14918f4a449..822a70ccaf6 100644 --- a/tests/cases/fourslash/ambientShorthandFindAllRefs.ts +++ b/tests/cases/fourslash/ambientShorthandFindAllRefs.ts @@ -4,13 +4,12 @@ ////declare module "jquery"; // @Filename: user.ts -////import {[|{| "isWriteAccess": true, "isDefinition": true |}x|]} from "jquery"; +////[|import {[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|]} from "jquery";|] // @Filename: user2.ts -////import {[|{| "isWriteAccess": true, "isDefinition": true |}x|]} from "jquery"; +////[|import {[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}x|]} from "jquery";|] -const ranges = test.ranges(); -const [r0, r1] = ranges; +const [r0Def, r0, r1Def, r1] = test.ranges(); // TODO: Want these to be in the same group, but that would require creating a symbol for `x`. verify.singleReferenceGroup("(alias) module \"jquery\"\nimport x", [r0]); verify.singleReferenceGroup("(alias) module \"jquery\"\nimport x", [r1]); \ No newline at end of file diff --git a/tests/cases/fourslash/cancellationWhenfindingAllRefsOnDefinition.ts b/tests/cases/fourslash/cancellationWhenfindingAllRefsOnDefinition.ts index 9334ab28b48..a6ff91fbbd5 100644 --- a/tests/cases/fourslash/cancellationWhenfindingAllRefsOnDefinition.ts +++ b/tests/cases/fourslash/cancellationWhenfindingAllRefsOnDefinition.ts @@ -7,9 +7,9 @@ //// //// } //// -//// public /**/[|{| "isWriteAccess": true, "isDefinition": true |}start|](){ +//// [|public /**/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}start|](){ //// return this; -//// } +//// }|] //// //// public stop(){ //// return this; @@ -33,5 +33,5 @@ cancellation.resetCancelled(); checkRefs(); function checkRefs() { - verify.singleReferenceGroup("(method) Test.start(): this"); + verify.singleReferenceGroup("(method) Test.start(): this", "start"); } diff --git a/tests/cases/fourslash/doubleUnderscoreRenames.ts b/tests/cases/fourslash/doubleUnderscoreRenames.ts index 5709be97b6f..6b50d65f124 100644 --- a/tests/cases/fourslash/doubleUnderscoreRenames.ts +++ b/tests/cases/fourslash/doubleUnderscoreRenames.ts @@ -1,12 +1,12 @@ /// // @Filename: fileA.ts -//// export function [|__foo|]() { -//// } +//// [|export function [|{| "declarationRangeIndex": 0 |}__foo|]() { +//// }|] //// // @Filename: fileB.ts -//// import { [|__foo|] as bar } from "./fileA"; +//// [|import { [|{| "declarationRangeIndex": 2 |}__foo|] as bar } from "./fileA";|] //// //// bar(); -verify.rangesAreRenameLocations(); +verify.rangesWithSameTextAreRenameLocations("__foo"); diff --git a/tests/cases/fourslash/duplicatePackageServices.ts b/tests/cases/fourslash/duplicatePackageServices.ts index 2ececda4e06..e5653f9da6d 100644 --- a/tests/cases/fourslash/duplicatePackageServices.ts +++ b/tests/cases/fourslash/duplicatePackageServices.ts @@ -2,25 +2,25 @@ // @noImplicitReferences: true // @Filename: /node_modules/a/index.d.ts -////import [|{| "name": "useAX", "isWriteAccess": true, "isDefinition": true |}X|] from "x"; +////[|import [|{| "name": "useAX", "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}X|] from "x";|] ////export function a(x: [|X|]): void; // @Filename: /node_modules/a/node_modules/x/index.d.ts -////export default class /*defAX*/[|{| "isWriteAccess": true, "isDefinition": true |}X|] { +////[|export default class /*defAX*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}X|] { //// private x: number; -////} +////}|] // @Filename: /node_modules/a/node_modules/x/package.json ////{ "name": "x", "version": "1.2.3" } // @Filename: /node_modules/b/index.d.ts -////import [|{| "name": "useBX", "isWriteAccess": true, "isDefinition": true |}X|] from "x"; +////[|import [|{| "name": "useBX", "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}X|] from "x";|] ////export const b: [|X|]; // @Filename: /node_modules/b/node_modules/x/index.d.ts -////export default class /*defBX*/[|{| "isWriteAccess": true, "isDefinition": true |}X|] { +////[|export default class /*defBX*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 8 |}X|] { //// private x: number; -////} +////}|] // @Filename: /node_modules/b/node_modules/x/package.json ////{ "name": "x", "version": "1.2.3" } @@ -35,7 +35,7 @@ verify.numberOfErrorsInCurrentFile(0); verify.goToDefinition("useAX", "defAX"); verify.goToDefinition("useBX", "defAX"); -const [r0, r1, r2, r3, r4, r5] = test.ranges(); +const [r0Def, r0, r1, r2Def, r2, r3Def, r3, r4, r5Def, r5] = test.ranges(); const aImport = { definition: "(alias) class X\nimport X", ranges: [r0, r1] }; const def = { definition: "class X", ranges: [r2] }; const bImport = { definition: "(alias) class X\nimport X", ranges: [r3, r4] }; diff --git a/tests/cases/fourslash/esModuleInteropFindAllReferences.ts b/tests/cases/fourslash/esModuleInteropFindAllReferences.ts index 4e493e58c24..e1ca3e4c9b1 100644 --- a/tests/cases/fourslash/esModuleInteropFindAllReferences.ts +++ b/tests/cases/fourslash/esModuleInteropFindAllReferences.ts @@ -4,11 +4,11 @@ // @Filename: /abc.d.ts ////declare module "a" { -//// export const [|{| "isWriteAccess": true, "isDefinition": true |}x|]: number; +//// [|export const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|]: number;|] ////} // @Filename: /b.ts ////import a from "a"; ////a.[|x|]; -verify.singleReferenceGroup("const x: number"); +verify.singleReferenceGroup("const x: number", "x"); diff --git a/tests/cases/fourslash/esModuleInteropFindAllReferences2.ts b/tests/cases/fourslash/esModuleInteropFindAllReferences2.ts index e55129a357c..02dbddd6b4e 100644 --- a/tests/cases/fourslash/esModuleInteropFindAllReferences2.ts +++ b/tests/cases/fourslash/esModuleInteropFindAllReferences2.ts @@ -6,10 +6,10 @@ // @Filename: /a.d.ts ////export as namespace abc; -////export const [|{| "isWriteAccess": true, "isDefinition": true |}x|]: number; +////[|export const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|]: number;|] // @Filename: /b.ts ////import a from "./a"; ////a.[|x|]; -verify.singleReferenceGroup('const x: number'); +verify.singleReferenceGroup('const x: number', "x"); diff --git a/tests/cases/fourslash/findAllReferPropertyAccessExpressionHeritageClause.ts b/tests/cases/fourslash/findAllReferPropertyAccessExpressionHeritageClause.ts index 61dfb1c33bc..9e9f552b528 100644 --- a/tests/cases/fourslash/findAllReferPropertyAccessExpressionHeritageClause.ts +++ b/tests/cases/fourslash/findAllReferPropertyAccessExpressionHeritageClause.ts @@ -2,9 +2,9 @@ //// class B {} //// function foo() { -//// return {[|{| "isWriteAccess": true, "isDefinition": true |}B|]: B}; +//// return {[|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}B|]: B|]}; //// } //// class C extends (foo()).[|B|] {} //// class C1 extends foo().[|B|] {} -verify.singleReferenceGroup("(property) B: typeof B"); +verify.singleReferenceGroup("(property) B: typeof B", "B"); diff --git a/tests/cases/fourslash/findAllReferencesDynamicImport2.ts b/tests/cases/fourslash/findAllReferencesDynamicImport2.ts index 6644a55ec1b..5e90911875b 100644 --- a/tests/cases/fourslash/findAllReferencesDynamicImport2.ts +++ b/tests/cases/fourslash/findAllReferencesDynamicImport2.ts @@ -1,12 +1,12 @@ /// // @Filename: foo.ts -//// export function [|{| "isWriteAccess": true, "isDefinition": true |}bar|]() { return "bar"; } +//// [|export function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}bar|]() { return "bar"; }|] //// var x = import("./foo"); //// x.then(foo => { //// foo.[|bar|](); //// }) -verify.singleReferenceGroup("function bar(): string"); -verify.rangesAreRenameLocations(); +verify.singleReferenceGroup("function bar(): string", "bar"); +verify.rangesWithSameTextAreRenameLocations("bar"); diff --git a/tests/cases/fourslash/findAllReferencesDynamicImport3.ts b/tests/cases/fourslash/findAllReferencesDynamicImport3.ts index 371369ac39c..1035ff40389 100644 --- a/tests/cases/fourslash/findAllReferencesDynamicImport3.ts +++ b/tests/cases/fourslash/findAllReferencesDynamicImport3.ts @@ -1,10 +1,10 @@ /// // @Filename: foo.ts -////export function [|{| "isWriteAccess": true, "isDefinition": true |}bar|]() { return "bar"; } -////import('./foo').then(({ [|{| "isWriteAccess": true, "isDefinition": true |}bar|] }) => undefined); +////[|export function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}bar|]() { return "bar"; }|] +////import('./foo').then(([|{ [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}bar|] }|]) => undefined); -const [r0, r1] = test.ranges(); +const [r0Def, r0, r1Def, r1] = test.ranges(); verify.referenceGroups(r0, [{ definition: "function bar(): string", ranges: [r0, r1] }]); verify.referenceGroups(r1, [ { definition: "function bar(): string", ranges: [r0] }, diff --git a/tests/cases/fourslash/findAllReferencesJSDocFunctionNew.ts b/tests/cases/fourslash/findAllReferencesJSDocFunctionNew.ts index b094714cefb..50066b9b136 100644 --- a/tests/cases/fourslash/findAllReferencesJSDocFunctionNew.ts +++ b/tests/cases/fourslash/findAllReferencesJSDocFunctionNew.ts @@ -1,8 +1,8 @@ /// // @allowJs: true // @Filename: Foo.js -/////** @type {function ([|{|"isWriteAccess": true, "isDefinition": true|}new|]: string, string): string} */ +/////** @type {function ([|[|{|"isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0|}new|]: string|], string): string} */ ////var f; -const [a0] = test.ranges(); +const [a0Def, a0] = test.ranges(); verify.singleReferenceGroup("(parameter) new: string", [a0]); diff --git a/tests/cases/fourslash/findAllReferencesOfConstructor.ts b/tests/cases/fourslash/findAllReferencesOfConstructor.ts index 3dffdeaffb9..ecaada06b1d 100644 --- a/tests/cases/fourslash/findAllReferencesOfConstructor.ts +++ b/tests/cases/fourslash/findAllReferencesOfConstructor.ts @@ -2,9 +2,9 @@ // @Filename: a.ts ////export class C { -//// [|constructor|](n: number); -//// [|constructor|](); -//// [|constructor|](n?: number){} +//// [|[|{| "declarationRangeIndex": 0 |}constructor|](n: number);|] +//// [|[|{| "declarationRangeIndex": 2 |}constructor|]();|] +//// [|[|{| "declarationRangeIndex": 4 |}constructor|](n?: number){}|] //// static f() { //// this.f(); //// new [|this|](); @@ -40,8 +40,7 @@ ////new a.[|C|](); ////class d extends a.C { constructor() { [|super|](); } -const ranges = test.ranges(); -const [a0, a1, a2, a3, a4, b0, c0, d0, d1] = ranges; +const [a0Def, a0, a1Def, a1, a2Def, a2, a3, a4, b0, c0, d0, d1] = test.ranges(); verify.referenceGroups([a0, a2], defs("class C")); verify.referenceGroups(a1, defs("class C")); diff --git a/tests/cases/fourslash/findAllReferencesOfConstructor_badOverload.ts b/tests/cases/fourslash/findAllReferencesOfConstructor_badOverload.ts index 2c4857145e1..ef4dc289359 100644 --- a/tests/cases/fourslash/findAllReferencesOfConstructor_badOverload.ts +++ b/tests/cases/fourslash/findAllReferencesOfConstructor_badOverload.ts @@ -1,8 +1,8 @@ /// ////class C { -//// [|constructor|](n: number); -//// [|constructor|](){} +//// [|[|{| "declarationRangeIndex": 0 |}constructor|](n: number);|] +//// [|[|{| "declarationRangeIndex": 2 |}constructor|](){}|] ////} -verify.singleReferenceGroup("class C"); +verify.singleReferenceGroup("class C", "constructor"); diff --git a/tests/cases/fourslash/findAllReferencesOfJsonModule.ts b/tests/cases/fourslash/findAllReferencesOfJsonModule.ts index 36f700b09e6..fd944097299 100644 --- a/tests/cases/fourslash/findAllReferencesOfJsonModule.ts +++ b/tests/cases/fourslash/findAllReferencesOfJsonModule.ts @@ -5,10 +5,10 @@ // @esModuleInterop: true // @Filename: /foo.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}settings|] from "./settings.json"; +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}settings|] from "./settings.json";|] ////[|settings|]; // @Filename: /settings.json //// {} -verify.singleReferenceGroup("import settings"); +verify.singleReferenceGroup("import settings", "settings"); diff --git a/tests/cases/fourslash/findAllReferencesUmdModuleAsGlobalConst.ts b/tests/cases/fourslash/findAllReferencesUmdModuleAsGlobalConst.ts index 464dcef1548..4876b1e0229 100644 --- a/tests/cases/fourslash/findAllReferencesUmdModuleAsGlobalConst.ts +++ b/tests/cases/fourslash/findAllReferencesUmdModuleAsGlobalConst.ts @@ -9,12 +9,12 @@ // @Filename: /node_modules/@types/three/index.d.ts ////export * from "./three-core"; -////export as namespace [|{| "isWriteAccess": true, "isDefinition": true |}THREE|]; +////[|export as namespace [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}THREE|];|] // @Filename: /typings/global.d.ts ////import * as _THREE from '[|three|]'; ////declare global { -//// const [|{| "isWriteAccess": true, "isDefinition": true |}THREE|]: typeof _THREE; +//// [|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}THREE|]: typeof _THREE;|] ////} // @Filename: /src/index.ts @@ -38,7 +38,8 @@ //// "files": ["/src/index.ts", "typings/global.d.ts"] ////} +const [r0Def, r0, r1, r2Def, ...rest] = test.ranges(); // GH#29533 // TODO:: this should be var THREE: typeof import instead of module name as var but thats existing issue and repros with quickInfo too. verify.singleReferenceGroup(`module "/node_modules/@types/three/index" -var "/node_modules/@types/three/index": typeof import("/node_modules/@types/three/index")`); \ No newline at end of file +var "/node_modules/@types/three/index": typeof import("/node_modules/@types/three/index")`, [r0, r1, ...rest]); \ No newline at end of file diff --git a/tests/cases/fourslash/findAllRefsBadImport.ts b/tests/cases/fourslash/findAllRefsBadImport.ts index a54454ea365..cde75d2df9a 100644 --- a/tests/cases/fourslash/findAllRefsBadImport.ts +++ b/tests/cases/fourslash/findAllRefsBadImport.ts @@ -1,7 +1,7 @@ /// -////import { [|ab|] as [|{| "isWriteAccess": true, "isDefinition": true |}cd|] } from "doesNotExist"; +////[|import { [|{| "declarationRangeIndex": 0 |}ab|] as [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}cd|] } from "doesNotExist";|] -const [r0, r1] = test.ranges(); +const [r0Def, r0, r1] = test.ranges(); verify.referenceGroups(r0, undefined); verify.singleReferenceGroup("import cd", [r1]); diff --git a/tests/cases/fourslash/findAllRefsClassExpression0.ts b/tests/cases/fourslash/findAllRefsClassExpression0.ts index e8d4aa671a3..9ccff25ab96 100644 --- a/tests/cases/fourslash/findAllRefsClassExpression0.ts +++ b/tests/cases/fourslash/findAllRefsClassExpression0.ts @@ -1,15 +1,15 @@ /// // @Filename: /a.ts -////export = class [|{| "isWriteAccess": true, "isDefinition": true |}A|] { +////export = [|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}A|] { //// m() { [|A|]; } -////}; +////}|]; // @Filename: /b.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}A|] = require("./a"); +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}A|] = require("./a");|] ////[|A|]; -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1, r2Def, r2, r3] = test.ranges(); const defs = { definition: "(local class) A", ranges: [r0, r1] }; const imports = { definition: '(alias) (local class) A\nimport A = require("./a")', ranges: [r2, r3] }; verify.referenceGroups([r0, r1], [defs, imports]); diff --git a/tests/cases/fourslash/findAllRefsClassExpression1.ts b/tests/cases/fourslash/findAllRefsClassExpression1.ts index 64aad512a5e..96bba426a25 100644 --- a/tests/cases/fourslash/findAllRefsClassExpression1.ts +++ b/tests/cases/fourslash/findAllRefsClassExpression1.ts @@ -3,13 +3,13 @@ // @allowJs: true // @Filename: /a.js -////module.exports = class [|{| "isWriteAccess": true, "isDefinition": true |}A|] {}; +////module.exports = [|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}A|] {}|]; // @Filename: /b.js -////import [|{| "isWriteAccess": true, "isDefinition": true |}A|] = require("./a"); +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}A|] = require("./a");|] ////[|A|]; -const [r0, r1, r2] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2] = test.ranges(); const defs = { definition: "(local class) A", ranges: [r0] }; const imports = { definition: '(alias) (local class) A\nimport A = require("./a")', ranges: [r1, r2] }; verify.referenceGroups([r0], [defs, imports]); diff --git a/tests/cases/fourslash/findAllRefsClassExpression2.ts b/tests/cases/fourslash/findAllRefsClassExpression2.ts index 1214e3f7c88..9432e9e7181 100644 --- a/tests/cases/fourslash/findAllRefsClassExpression2.ts +++ b/tests/cases/fourslash/findAllRefsClassExpression2.ts @@ -3,13 +3,13 @@ // @allowJs: true // @Filename: /a.js -////exports.[|{| "isWriteAccess": true, "isDefinition": true |}A|] = class {}; +////[|exports.[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}A|] = class {};|] // @Filename: /b.js -////import { [|{| "isWriteAccess": true, "isDefinition": true |}A|] } from "./a"; +////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}A|] } from "./a";|] ////[|A|]; -const [r0, r1, r2] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2] = test.ranges(); const defs = { definition: "class A\n(property) A: typeof A", ranges: [r0] }; const imports = { definition: "(alias) class A\n(alias) (property) A: typeof A\nimport A", ranges: [r1, r2] }; verify.referenceGroups([r0], [defs, imports]); diff --git a/tests/cases/fourslash/findAllRefsClassWithStaticThisAccess.ts b/tests/cases/fourslash/findAllRefsClassWithStaticThisAccess.ts index f2c432abc76..419f61836d3 100644 --- a/tests/cases/fourslash/findAllRefsClassWithStaticThisAccess.ts +++ b/tests/cases/fourslash/findAllRefsClassWithStaticThisAccess.ts @@ -1,6 +1,6 @@ /// -////class [|{| "isWriteAccess": true, "isDefinition": true |}C|] { +////[|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}C|] { //// static s() { //// [|this|]; //// } @@ -10,9 +10,9 @@ //// function inner() { this; } //// class Inner { x = this; } //// } -////} +////}|] -const [r0, r1, r2] = test.ranges(); +const [r0Def, r0, r1, r2] = test.ranges(); verify.referenceGroups(r0, [{ definition: "class C", ranges: [r0, r1, r2] }]); verify.singleReferenceGroup("this: typeof C", [r1, r2]); diff --git a/tests/cases/fourslash/findAllRefsConstructorFunctions.ts b/tests/cases/fourslash/findAllRefsConstructorFunctions.ts index 77fa674f65b..8f95f94da2b 100644 --- a/tests/cases/fourslash/findAllRefsConstructorFunctions.ts +++ b/tests/cases/fourslash/findAllRefsConstructorFunctions.ts @@ -4,11 +4,11 @@ // @Filename: /a.js ////function f() { -//// this.[|{| "isWriteAccess": true, "isDefinition": true |}x|] = 0; +//// [|this.[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|] = 0;|] ////} ////f.prototype.setX = function() { -//// this.[|{| "isWriteAccess": true, "isDefinition": true |}x|] = 1; +//// [|this.[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}x|] = 1;|] ////} ////f.prototype.useX = function() { this.[|x|]; } -verify.singleReferenceGroup("(property) f.x: number"); +verify.singleReferenceGroup("(property) f.x: number", "x"); diff --git a/tests/cases/fourslash/findAllRefsDeclareClass.ts b/tests/cases/fourslash/findAllRefsDeclareClass.ts index 9ef813634a5..4632f48c527 100644 --- a/tests/cases/fourslash/findAllRefsDeclareClass.ts +++ b/tests/cases/fourslash/findAllRefsDeclareClass.ts @@ -1,7 +1,7 @@ /// -////declare class [|{| "isWriteAccess": true, "isDefinition": true |}C|] { +////[|declare class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}C|] { //// static m(): void; -////} +////}|] -verify.singleReferenceGroup("class C"); +verify.singleReferenceGroup("class C", "C"); diff --git a/tests/cases/fourslash/findAllRefsDefaultImport.ts b/tests/cases/fourslash/findAllRefsDefaultImport.ts index b981f50bd16..23b7c8af76a 100644 --- a/tests/cases/fourslash/findAllRefsDefaultImport.ts +++ b/tests/cases/fourslash/findAllRefsDefaultImport.ts @@ -1,12 +1,12 @@ /// // @Filename: /a.ts -////export default function [|{| "isWriteAccess": true, "isDefinition": true |}a|]() {} +////[|export default function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}a|]() {}|] // @Filename: /b.ts -////import [|{| "isWriteAccess": true, "isDefinition": true |}a|], * as ns from "./a"; +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}a|], * as ns from "./a";|] -const [r0, r1] = test.ranges(); +const [r0Def, r0, r1Def, r1] = test.ranges(); const a: FourSlashInterface.ReferenceGroup = { definition: "function a(): void", ranges: [r0] }; const b: FourSlashInterface.ReferenceGroup = { definition: "(alias) function a(): void\nimport a", ranges: [r1] }; verify.referenceGroups(r0, [a, b]); diff --git a/tests/cases/fourslash/findAllRefsDefaultImportThroughNamespace.ts b/tests/cases/fourslash/findAllRefsDefaultImportThroughNamespace.ts index 722403f45cf..ca99174463b 100644 --- a/tests/cases/fourslash/findAllRefsDefaultImportThroughNamespace.ts +++ b/tests/cases/fourslash/findAllRefsDefaultImportThroughNamespace.ts @@ -1,7 +1,7 @@ /// // @Filename: /a.ts -////export [|{| "isWriteAccess": true, "isDefinition": true |}default|] function [|{| "isWriteAccess": true, "isDefinition": true |}f|]() {} +////[|export [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}default|] function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}f|]() {}|] // @Filename: /b.ts ////export import a = require("./a"); @@ -10,10 +10,10 @@ ////import { a } from "./b"; ////a.[|default|](); //// -////declare const x: { [|{| "isWriteAccess": true, "isDefinition": true |}default|]: number }; +////declare const x: { [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}default|]: number|] }; ////x.[|default|]; -const [r0, r1, r2, r3, r4] = test.ranges(); +const [r0Def, r0, r1, r2, r3Def, r3, r4] = test.ranges(); verify.referenceGroups([r0], [{ definition: "function f(): void", ranges: [r0, r2] }]); verify.singleReferenceGroup("function f(): void", [r1, r2]); diff --git a/tests/cases/fourslash/findAllRefsDefinition.ts b/tests/cases/fourslash/findAllRefsDefinition.ts index 7b7016e7049..4d9d50a618a 100644 --- a/tests/cases/fourslash/findAllRefsDefinition.ts +++ b/tests/cases/fourslash/findAllRefsDefinition.ts @@ -1,9 +1,9 @@ /// -////const [|{| "isWriteAccess": true, "isDefinition": true |}x|] = 0; +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}x|] = 0;|] ////[|x|]; -const ranges = test.ranges(); +const ranges = test.rangesByText().get("x"); verify.referenceGroups(ranges, [ { definition: { text: "const x: 0", range: ranges[0] }, diff --git a/tests/cases/fourslash/findAllRefsDestructureGeneric.ts b/tests/cases/fourslash/findAllRefsDestructureGeneric.ts index 3d7a84cb35a..d6e96155ec7 100644 --- a/tests/cases/fourslash/findAllRefsDestructureGeneric.ts +++ b/tests/cases/fourslash/findAllRefsDestructureGeneric.ts @@ -1,12 +1,12 @@ /// ////interface I { -//// [|{| "isDefinition": true |}x|]: boolean; +//// [|[|{| "isDefinition": true, "declarationRangeIndex": 0 |}x|]: boolean;|] ////} ////declare const i: I; -////const { [|{| "isWriteAccess": true, "isDefinition": true |}x|] } = i; +////[|const { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}x|] } = i;|] -const [r0, r1] = test.ranges(); +const [r0Def, r0, r1Def, r1] = test.ranges(); verify.referenceGroups(r0, [{ definition: "(property) I.x: boolean", ranges: [r0, r1] }]); verify.referenceGroups(r1, [ diff --git a/tests/cases/fourslash/findAllRefsDestructureGetter.ts b/tests/cases/fourslash/findAllRefsDestructureGetter.ts index 763d3cfb0e5..ed4a74d5d2b 100644 --- a/tests/cases/fourslash/findAllRefsDestructureGetter.ts +++ b/tests/cases/fourslash/findAllRefsDestructureGetter.ts @@ -1,14 +1,14 @@ /// ////class Test { -//// get [|{| "isDefinition": true, "isWriteAccess": true |}x|]() { return 0; } +//// [|get [|{| "isDefinition": true, "isWriteAccess": true, "declarationRangeIndex": 0 |}x|]() { return 0; }|] //// -//// set [|{| "isDefinition": true, "isWriteAccess": true |}y|](a: number) {} +//// [|set [|{| "isDefinition": true, "isWriteAccess": true, "declarationRangeIndex": 2 |}y|](a: number) {}|] ////} -////const { [|{| "isDefinition": true, "isWriteAccess": true |}x|], [|{| "isDefinition": true, "isWriteAccess": true |}y|] } = new Test(); +////[|const { [|{| "isDefinition": true, "isWriteAccess": true, "declarationRangeIndex": 4 |}x|], [|{| "isDefinition": true, "isWriteAccess": true, "declarationRangeIndex": 4 |}y|] } = new Test();|] ////[|x|]; [|y|]; -const [x0, y0, x1, y1, x2, y2] = test.ranges(); +const [x0Def, x0, y0Def, y0, xy1Def, x1, y1, x2, y2] = test.ranges(); verify.referenceGroups(x0, [{ definition: "(property) Test.x: number", ranges: [x0, x1] }]); verify.referenceGroups(x1, [ { definition: "(property) Test.x: number", ranges: [x0] }, diff --git a/tests/cases/fourslash/findAllRefsDestructureGetter2.ts b/tests/cases/fourslash/findAllRefsDestructureGetter2.ts index d26983a1091..8d6300e976f 100644 --- a/tests/cases/fourslash/findAllRefsDestructureGetter2.ts +++ b/tests/cases/fourslash/findAllRefsDestructureGetter2.ts @@ -4,13 +4,13 @@ // @Filename: /a.ts ////class C { -//// get [|{| "isWriteAccess": true, "isDefinition": true |}g|](): number { return 0; } +//// [|get [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}g|](): number { return 0; }|] //// -//// set [|{| "isWriteAccess": true, "isDefinition": true |}s|](value: number) {} +//// [|set [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}s|](value: number) {}|] ////} -////const { [|{| "isWriteAccess": true, "isDefinition": true |}g|], [|{| "isWriteAccess": true, "isDefinition": true |}s|] } = new C(); +////[|const { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}g|], [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}s|] } = new C();|] -const [g0, s0, g1, s1] = test.ranges(); +const [g0Def, g0, s0Def, s0, gs1Def, g1, s1] = test.ranges(); verify.quickInfoAt(g0, "(property) C.g: number"); verify.referenceGroups(g0, [{ definition: "(property) C.g: number", ranges: [g0, g1] }]); verify.referenceGroups(g1, [ diff --git a/tests/cases/fourslash/shims-pp/getReferencesAtPosition.ts b/tests/cases/fourslash/shims-pp/getReferencesAtPosition.ts index 7189738435f..fabe77c53ac 100644 --- a/tests/cases/fourslash/shims-pp/getReferencesAtPosition.ts +++ b/tests/cases/fourslash/shims-pp/getReferencesAtPosition.ts @@ -7,9 +7,9 @@ //// //// } //// -//// public [|{| "isWriteAccess": true, "isDefinition": true |}start|](){ +//// [|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}start|](){ //// return this; -//// } +//// }|] //// //// public stop(){ //// return this; @@ -23,4 +23,4 @@ ////second.[|start|](); ////second.stop(); -verify.singleReferenceGroup("(method) Test.start(): this"); +verify.singleReferenceGroup("(method) Test.start(): this", "start"); diff --git a/tests/cases/fourslash/shims-pp/getRenameInfo.ts b/tests/cases/fourslash/shims-pp/getRenameInfo.ts index aa04d69962a..2595a523f16 100644 --- a/tests/cases/fourslash/shims-pp/getRenameInfo.ts +++ b/tests/cases/fourslash/shims-pp/getRenameInfo.ts @@ -2,9 +2,9 @@ /////// -////function [|Bar|]() { +////[|function [|{| "declarationRangeIndex": 0 |}Bar|]() { //// // This is a reference to Bar in a comment. //// "this is a reference to Bar in a string" -////} +////}|] -verify.rangesAreRenameLocations(); +verify.rangesWithSameTextAreRenameLocations("Bar"); diff --git a/tests/cases/fourslash/shims/getReferencesAtPosition.ts b/tests/cases/fourslash/shims/getReferencesAtPosition.ts index 7189738435f..fabe77c53ac 100644 --- a/tests/cases/fourslash/shims/getReferencesAtPosition.ts +++ b/tests/cases/fourslash/shims/getReferencesAtPosition.ts @@ -7,9 +7,9 @@ //// //// } //// -//// public [|{| "isWriteAccess": true, "isDefinition": true |}start|](){ +//// [|public [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}start|](){ //// return this; -//// } +//// }|] //// //// public stop(){ //// return this; @@ -23,4 +23,4 @@ ////second.[|start|](); ////second.stop(); -verify.singleReferenceGroup("(method) Test.start(): this"); +verify.singleReferenceGroup("(method) Test.start(): this", "start"); diff --git a/tests/cases/fourslash/shims/getRenameInfo.ts b/tests/cases/fourslash/shims/getRenameInfo.ts index aa04d69962a..2595a523f16 100644 --- a/tests/cases/fourslash/shims/getRenameInfo.ts +++ b/tests/cases/fourslash/shims/getRenameInfo.ts @@ -2,9 +2,9 @@ /////// -////function [|Bar|]() { +////[|function [|{| "declarationRangeIndex": 0 |}Bar|]() { //// // This is a reference to Bar in a comment. //// "this is a reference to Bar in a string" -////} +////}|] -verify.rangesAreRenameLocations(); +verify.rangesWithSameTextAreRenameLocations("Bar"); From edad317395354f164593051186d19520db21135c Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 6 Jun 2019 10:23:13 -0700 Subject: [PATCH 33/44] Fourslash server tests --- src/harness/client.ts | 8 ++++++-- tests/cases/fourslash/server/jsdocCallbackTagRename01.ts | 6 +++--- tests/cases/fourslash/server/jsdocTypedefTagRename01.ts | 5 +++-- tests/cases/fourslash/server/jsdocTypedefTagRename02.ts | 5 +++-- tests/cases/fourslash/server/jsdocTypedefTagRename03.ts | 6 +++--- tests/cases/fourslash/server/rename01.ts | 6 +++--- tests/cases/fourslash/server/renameInConfiguredProject.ts | 5 +++-- 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/harness/client.ts b/src/harness/client.ts index d223f9f5fe3..ecfbbddecd0 100644 --- a/src/harness/client.ts +++ b/src/harness/client.ts @@ -395,8 +395,12 @@ namespace ts.server { const locations: RenameLocation[] = []; for (const entry of body.locs) { const fileName = entry.file; - for (const { start, end, ...prefixSuffixText } of entry.locs) { - locations.push({ textSpan: this.decodeSpan({ start, end }, fileName), fileName, ...prefixSuffixText }); + for (const { start, end, declarationStart, declarationEnd, ...prefixSuffixText } of entry.locs) { + const renameLocation: RenameLocation = { textSpan: this.decodeSpan({ start, end }, fileName), fileName, ...prefixSuffixText }; + if (declarationStart !== undefined) { + renameLocation.declarationSpan = this.decodeSpan({ start: declarationStart, end: declarationEnd! }, fileName); + } + locations.push(renameLocation); } } diff --git a/tests/cases/fourslash/server/jsdocCallbackTagRename01.ts b/tests/cases/fourslash/server/jsdocCallbackTagRename01.ts index bb7dd32cfc2..557d0d49298 100644 --- a/tests/cases/fourslash/server/jsdocCallbackTagRename01.ts +++ b/tests/cases/fourslash/server/jsdocCallbackTagRename01.ts @@ -4,12 +4,12 @@ // @Filename: jsDocCallback.js //// //// /** -//// * @callback [|FooCallback|] +//// * [|@callback [|{| "declarationRangeIndex": 0 |}FooCallback|] //// * @param {string} eventName - Rename should work -//// */ +//// |]*/ //// //// /** @type {/*1*/[|FooCallback|]} */ //// var t; -const ranges = test.ranges(); +const [rDef, ...ranges] = test.ranges(); verify.renameLocations(ranges[0], { findInStrings: false, findInComments: true, ranges }); diff --git a/tests/cases/fourslash/server/jsdocTypedefTagRename01.ts b/tests/cases/fourslash/server/jsdocTypedefTagRename01.ts index 38a35b58cbf..8bfd04bda81 100644 --- a/tests/cases/fourslash/server/jsdocTypedefTagRename01.ts +++ b/tests/cases/fourslash/server/jsdocTypedefTagRename01.ts @@ -4,11 +4,12 @@ // @Filename: jsDocTypedef_form1.js //// //// /** @typedef {(string | number)} */ -//// var [|NumberLike|]; +//// [|var [|{| "declarationRangeIndex": 0 |}NumberLike|];|] //// //// [|NumberLike|] = 10; //// //// /** @type {[|NumberLike|]} */ //// var numberLike; -verify.rangesAreRenameLocations({ findInComments: true }); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations({ findInComments: true, ranges }); diff --git a/tests/cases/fourslash/server/jsdocTypedefTagRename02.ts b/tests/cases/fourslash/server/jsdocTypedefTagRename02.ts index 38da754247f..dca1a21da9a 100644 --- a/tests/cases/fourslash/server/jsdocTypedefTagRename02.ts +++ b/tests/cases/fourslash/server/jsdocTypedefTagRename02.ts @@ -3,9 +3,10 @@ // @allowNonTsExtensions: true // @Filename: jsDocTypedef_form2.js //// -//// /** @typedef {(string | number)} [|NumberLike|] */ +//// /** [|@typedef {(string | number)} [|{| "declarationRangeIndex": 0 |}NumberLike|]|] */ //// //// /** @type {[|NumberLike|]} */ //// var numberLike; -verify.rangesAreRenameLocations({ findInComments: true }); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations({ findInComments: true, ranges }); diff --git a/tests/cases/fourslash/server/jsdocTypedefTagRename03.ts b/tests/cases/fourslash/server/jsdocTypedefTagRename03.ts index 7b61682e594..0540e9963e5 100644 --- a/tests/cases/fourslash/server/jsdocTypedefTagRename03.ts +++ b/tests/cases/fourslash/server/jsdocTypedefTagRename03.ts @@ -4,14 +4,14 @@ // @Filename: jsDocTypedef_form3.js //// //// /** -//// * @typedef /*1*/[|Person|] +//// * [|@typedef /*1*/[|{| "declarationRangeIndex": 0 |}Person|] //// * @type {Object} //// * @property {number} age //// * @property {string} name -//// */ +//// |]*/ //// //// /** @type {/*2*/[|Person|]} */ //// var person; goTo.file('jsDocTypedef_form3.js') -verify.rangesAreRenameLocations({ findInComments: true }); +verify.rangesAreRenameLocations({ findInComments: true, ranges: test.rangesByText().get("Person") }); diff --git a/tests/cases/fourslash/server/rename01.ts b/tests/cases/fourslash/server/rename01.ts index 74385c30da3..871a70c763a 100644 --- a/tests/cases/fourslash/server/rename01.ts +++ b/tests/cases/fourslash/server/rename01.ts @@ -2,10 +2,10 @@ /////// -////function [|Bar|]() { +////[|function [|{| "declarationRangeIndex": 0 |}Bar|]() { //// // This is a reference to [|Bar|] in a comment. //// "this is a reference to [|Bar|] in a string" -////} +////}|] -const ranges = test.ranges(); +const [rDef, ...ranges] = test.ranges(); verify.renameLocations(ranges[0], { findInStrings: true, findInComments: true, ranges }); diff --git a/tests/cases/fourslash/server/renameInConfiguredProject.ts b/tests/cases/fourslash/server/renameInConfiguredProject.ts index a235f783f4c..da576bcb30f 100644 --- a/tests/cases/fourslash/server/renameInConfiguredProject.ts +++ b/tests/cases/fourslash/server/renameInConfiguredProject.ts @@ -1,7 +1,7 @@ /// // @Filename: referencesForGlobals_1.ts -////var [|globalName|] = 0; +////[|var [|{| "declarationRangeIndex": 0 |}globalName|] = 0;|] // @Filename: referencesForGlobals_2.ts ////var y = [|globalName|]; @@ -9,4 +9,5 @@ // @Filename: tsconfig.json ////{ "files": ["referencesForGlobals_1.ts", "referencesForGlobals_2.ts"] } -verify.rangesAreRenameLocations({ findInStrings: true, findInComments: true }); +const [rDef, ...ranges] = test.ranges(); +verify.rangesAreRenameLocations({ findInStrings: true, findInComments: true, ranges }); From 768c9ed8d7f2faa7c1fcf979e497f17f8442f811 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 6 Jun 2019 10:57:09 -0700 Subject: [PATCH 34/44] Handle jsx Opening, Closing and Self closing tags --- src/services/findAllReferences.ts | 10 ++++++++-- src/services/services.ts | 10 ++++++++-- tests/cases/fourslash/findReferencesJSXTagName.ts | 6 +++--- tests/cases/fourslash/findReferencesJSXTagName3.ts | 12 ++++++------ tests/cases/fourslash/tsxFindAllReferences1.ts | 2 +- tests/cases/fourslash/tsxFindAllReferences4.ts | 2 +- tests/cases/fourslash/tsxFindAllReferences5.ts | 10 +++++----- tests/cases/fourslash/tsxFindAllReferences8.ts | 12 ++++++------ .../tsxFindAllReferencesUnionElementType1.ts | 2 +- .../tsxFindAllReferencesUnionElementType2.ts | 2 +- tests/cases/fourslash/tsxRename1.ts | 2 +- tests/cases/fourslash/tsxRename4.ts | 6 +++--- tests/cases/fourslash/tsxRename6.ts | 10 +++++----- tests/cases/fourslash/tsxRename9.ts | 12 ++++++------ 14 files changed, 55 insertions(+), 43 deletions(-) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index ae31ab544f3..a2eb4f3ec29 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -48,11 +48,17 @@ namespace ts.FindAllReferences { return getDeclarationForDeclarationSpan(node); } - // TODO(shkamat):: - // JSXOpeningElement or JSXElement for tagName ? if (!node.parent) return undefined; if (!isDeclaration(node.parent) && !isExportAssignment(node.parent)) { + // Jsx Tags + if (isJsxOpeningElement(node.parent) || isJsxClosingElement(node.parent)) { + return node.parent.parent; + } + else if (isJsxSelfClosingElement(node.parent)) { + return node.parent; + } + // Special property assignment in javascript if (isInJSFile(node)) { const binaryExpression = isBinaryExpression(node.parent) ? diff --git a/src/services/services.ts b/src/services/services.ts index cae6ce7ac47..032dee4a40c 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1577,8 +1577,14 @@ namespace ts { const node = getTouchingPropertyName(sourceFile, position); if (isIdentifier(node) && (isJsxOpeningElement(node.parent) || isJsxClosingElement(node.parent)) && isIntrinsicJsxName(node.escapedText)) { const { openingElement, closingElement } = node.parent.parent; - return [openingElement, closingElement].map((node): RenameLocation => - ({ fileName: sourceFile.fileName, textSpan: createTextSpanFromNode(node.tagName, sourceFile) })); + return [openingElement, closingElement].map(node => { + const result: RenameLocation = { + fileName: sourceFile.fileName, + textSpan: createTextSpanFromNode(node.tagName, sourceFile) + }; + FindAllReferences.setDeclarationSpan(result, sourceFile, node.parent); + return result; + }); } else { return getReferencesWorker(node, position, { findInStrings, findInComments, providePrefixAndSuffixTextForRename, isForRename: true }, diff --git a/tests/cases/fourslash/findReferencesJSXTagName.ts b/tests/cases/fourslash/findReferencesJSXTagName.ts index ec011671c9e..cd6675c7c3f 100644 --- a/tests/cases/fourslash/findReferencesJSXTagName.ts +++ b/tests/cases/fourslash/findReferencesJSXTagName.ts @@ -4,14 +4,14 @@ ////[|import { [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}SubmissionComp|] } from "./RedditSubmission"|] ////function displaySubreddit(subreddit: string) { //// let components = submissions -//// .map((value, index) => <[|SubmissionComp|] key={ index } elementPosition= { index } {...value.data} />); +//// .map((value, index) => [|<[|{| "declarationRangeIndex": 2 |}SubmissionComp|] key={ index } elementPosition= { index } {...value.data} />|]); ////} // @Filename: RedditSubmission.ts -////export const [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}SubmissionComp|] = (submission: SubmissionProps) => +////export const [|[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}SubmissionComp|] = (submission: SubmissionProps) => ////
; -const [r0Def, r0, r1, r2Def, r2] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2] = test.ranges(); const imports = { definition: "(alias) const SubmissionComp: (submission: any) => any\nimport SubmissionComp", ranges: [r0, r1] }; const def = { definition: "const SubmissionComp: (submission: any) => any", ranges: [r2] }; verify.referenceGroups([r0, r1], [imports, def]); diff --git a/tests/cases/fourslash/findReferencesJSXTagName3.ts b/tests/cases/fourslash/findReferencesJSXTagName3.ts index afd90562777..b4e87388f99 100644 --- a/tests/cases/fourslash/findReferencesJSXTagName3.ts +++ b/tests/cases/fourslash/findReferencesJSXTagName3.ts @@ -11,16 +11,16 @@ ////} //// ////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}Comp|] = () => -//// <[|div|]> +//// [|<[|{| "declarationRangeIndex": 4 |}div|]> //// Some content -//// <[|div|]>More content -//// ;|] +//// [|<[|{| "declarationRangeIndex": 6 |}div|]>More content|] +//// |];|] //// -////const x = <[|Comp|]> +////const x = [|<[|{| "declarationRangeIndex": 10 |}Comp|]> //// Content -////; +////|]; -const [d0Def, d0, c0Def, c0, d1, d2, d3, d4, c1, c2] = test.ranges(); +const [d0Def, d0, c0Def, c0, d1Def, d1, d2Def, d2, d3, d4, c1Def, c1, c2] = test.ranges(); const allD = [d0, d1, d2, d3, d4]; const allC = [c0, c1, c2]; diff --git a/tests/cases/fourslash/tsxFindAllReferences1.ts b/tests/cases/fourslash/tsxFindAllReferences1.ts index e943c4e69bf..f5d0a2e7488 100644 --- a/tests/cases/fourslash/tsxFindAllReferences1.ts +++ b/tests/cases/fourslash/tsxFindAllReferences1.ts @@ -11,7 +11,7 @@ //// span: { n: string; }; //// } //// } -//// var x = <[|div|] />; +//// var x = [|<[|{| "declarationRangeIndex": 2 |}div|] />|]; verify.singleReferenceGroup( `(property) JSX.IntrinsicElements.div: { diff --git a/tests/cases/fourslash/tsxFindAllReferences4.ts b/tests/cases/fourslash/tsxFindAllReferences4.ts index e761be8eb4d..38433bb7f21 100644 --- a/tests/cases/fourslash/tsxFindAllReferences4.ts +++ b/tests/cases/fourslash/tsxFindAllReferences4.ts @@ -14,6 +14,6 @@ //// }|] //// //// -//// var x = <[|MyClass|] name='hello'>; +//// var x = [|<[|{| "declarationRangeIndex" : 2 |}MyClass|] name='hello'>|]; verify.singleReferenceGroup("class MyClass", "MyClass"); diff --git a/tests/cases/fourslash/tsxFindAllReferences5.ts b/tests/cases/fourslash/tsxFindAllReferences5.ts index ee3e0e7e4bd..804943ec85d 100644 --- a/tests/cases/fourslash/tsxFindAllReferences5.ts +++ b/tests/cases/fourslash/tsxFindAllReferences5.ts @@ -16,11 +16,11 @@ //// optional?: boolean //// } //// [|declare function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}Opt|](attributes: OptionPropBag): JSX.Element;|] -//// let opt = <[|Opt|] />; -//// let opt1 = <[|Opt|] propx={100} propString />; -//// let opt2 = <[|Opt|] propx={100} optional/>; -//// let opt3 = <[|Opt|] wrong />; -//// let opt4 = <[|Opt|] propx={100} propString="hi" />; +//// let opt = [|<[|{| "declarationRangeIndex": 2 |}Opt|] />|]; +//// let opt1 = [|<[|{| "declarationRangeIndex": 4 |}Opt|] propx={100} propString />|]; +//// let opt2 = [|<[|{| "declarationRangeIndex": 6 |}Opt|] propx={100} optional/>|]; +//// let opt3 = [|<[|{| "declarationRangeIndex": 8 |}Opt|] wrong />|]; +//// let opt4 = [|<[|{| "declarationRangeIndex": 10 |}Opt|] propx={100} propString="hi" />|]; verify.singleReferenceGroup( "function Opt(attributes: OptionPropBag): JSX.Element", diff --git a/tests/cases/fourslash/tsxFindAllReferences8.ts b/tests/cases/fourslash/tsxFindAllReferences8.ts index a5683cfb330..6dcd94e726b 100644 --- a/tests/cases/fourslash/tsxFindAllReferences8.ts +++ b/tests/cases/fourslash/tsxFindAllReferences8.ts @@ -23,12 +23,12 @@ //// [|declare function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}MainButton|](buttonProps: ButtonProps): JSX.Element;|] //// [|declare function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}MainButton|](linkProps: LinkProps): JSX.Element;|] //// [|declare function [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}MainButton|](props: ButtonProps | LinkProps): JSX.Element;|] -//// let opt = <[|MainButton|] />; -//// let opt = <[|MainButton|] children="chidlren" />; -//// let opt = <[|MainButton|] onClick={()=>{}} />; -//// let opt = <[|MainButton|] onClick={()=>{}} ignore-prop />; -//// let opt = <[|MainButton|] goTo="goTo" />; -//// let opt = <[|MainButton|] wrong />; +//// let opt = [|<[|{| "declarationRangeIndex": 6 |}MainButton|] />|]; +//// let opt = [|<[|{| "declarationRangeIndex": 8 |}MainButton|] children="chidlren" />|]; +//// let opt = [|<[|{| "declarationRangeIndex": 10 |}MainButton|] onClick={()=>{}} />|]; +//// let opt = [|<[|{| "declarationRangeIndex": 12 |}MainButton|] onClick={()=>{}} ignore-prop />|]; +//// let opt = [|<[|{| "declarationRangeIndex": 14 |}MainButton|] goTo="goTo" />|]; +//// let opt = [|<[|{| "declarationRangeIndex": 16 |}MainButton|] wrong />|]; verify.singleReferenceGroup( "function MainButton(buttonProps: ButtonProps): JSX.Element (+2 overloads)", diff --git a/tests/cases/fourslash/tsxFindAllReferencesUnionElementType1.ts b/tests/cases/fourslash/tsxFindAllReferencesUnionElementType1.ts index dc85960bb6d..60b95f1b43e 100644 --- a/tests/cases/fourslash/tsxFindAllReferencesUnionElementType1.ts +++ b/tests/cases/fourslash/tsxFindAllReferencesUnionElementType1.ts @@ -19,7 +19,7 @@ //// } //// [|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}SFCComp|] = SFC1 || SFC2;|] -//// <[|SFCComp|] x={ "hi" } /> +//// [|<[|{| "declarationRangeIndex": 2 |}SFCComp|] x={ "hi" } />|] verify.singleReferenceGroup(`var SFCComp: ((prop: { x: number; diff --git a/tests/cases/fourslash/tsxFindAllReferencesUnionElementType2.ts b/tests/cases/fourslash/tsxFindAllReferencesUnionElementType2.ts index ffb33919fd4..cb4151aa3c5 100644 --- a/tests/cases/fourslash/tsxFindAllReferencesUnionElementType2.ts +++ b/tests/cases/fourslash/tsxFindAllReferencesUnionElementType2.ts @@ -18,6 +18,6 @@ //// } //// [|var [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}RCComp|] = RC1 || RC2;|] -//// <[|RCComp|] /> +//// [|<[|{| "declarationRangeIndex": 2 |}RCComp|] />|] verify.singleReferenceGroup("var RCComp: typeof RC1", "RCComp"); diff --git a/tests/cases/fourslash/tsxRename1.ts b/tests/cases/fourslash/tsxRename1.ts index 047bc391a38..e16c390f4e5 100644 --- a/tests/cases/fourslash/tsxRename1.ts +++ b/tests/cases/fourslash/tsxRename1.ts @@ -11,5 +11,5 @@ //// span: { n: string; }; //// } //// } -//// var x = <[|div|] />; +//// var x = [|<[|{| "declarationRangeIndex": 2 |}div|] />|]; verify.rangesWithSameTextAreRenameLocations("div"); diff --git a/tests/cases/fourslash/tsxRename4.ts b/tests/cases/fourslash/tsxRename4.ts index 0bc9fa10f0c..f9c33972ecd 100644 --- a/tests/cases/fourslash/tsxRename4.ts +++ b/tests/cases/fourslash/tsxRename4.ts @@ -11,10 +11,10 @@ ////} ////[|class [|{| "declarationRangeIndex": 0 |}MyClass|] {}|] //// -////<[|MyClass|]>; -////<[|MyClass|]/>; +////[|<[|{| "declarationRangeIndex": 2 |}MyClass|]>|]; +////[|<[|{| "declarationRangeIndex": 5 |}MyClass|]/>|]; //// -////<[|div|]> +////[|<[|{| "declarationRangeIndex": 7 |}div|]> |] verify.noErrors(); verify.rangesWithSameTextAreRenameLocations("MyClass", "div"); \ No newline at end of file diff --git a/tests/cases/fourslash/tsxRename6.ts b/tests/cases/fourslash/tsxRename6.ts index 1cafd1332b0..320f3e6ac6b 100644 --- a/tests/cases/fourslash/tsxRename6.ts +++ b/tests/cases/fourslash/tsxRename6.ts @@ -16,10 +16,10 @@ //// optional?: boolean //// } //// [|declare function [|{| "declarationRangeIndex": 0 |}Opt|](attributes: OptionPropBag): JSX.Element;|] -//// let opt = <[|Opt|] />; -//// let opt1 = <[|Opt|] propx={100} propString />; -//// let opt2 = <[|Opt|] propx={100} optional/>; -//// let opt3 = <[|Opt|] wrong />; -//// let opt4 = <[|Opt|] propx={100} propString="hi" />; +//// let opt = [|<[|{| "declarationRangeIndex": 2 |}Opt|] />|]; +//// let opt1 = [|<[|{| "declarationRangeIndex": 4 |}Opt|] propx={100} propString />|]; +//// let opt2 = [|<[|{| "declarationRangeIndex": 6 |}Opt|] propx={100} optional/>|]; +//// let opt3 = [|<[|{| "declarationRangeIndex": 8 |}Opt|] wrong />|]; +//// let opt4 = [|<[|{| "declarationRangeIndex": 10 |}Opt|] propx={100} propString="hi" />|]; verify.rangesWithSameTextAreRenameLocations("Opt"); diff --git a/tests/cases/fourslash/tsxRename9.ts b/tests/cases/fourslash/tsxRename9.ts index 29a54d51cae..0aa8ef8345f 100644 --- a/tests/cases/fourslash/tsxRename9.ts +++ b/tests/cases/fourslash/tsxRename9.ts @@ -23,12 +23,12 @@ //// [|declare function [|{| "declarationRangeIndex": 4 |}MainButton|](buttonProps: ButtonProps): JSX.Element;|] //// [|declare function [|{| "declarationRangeIndex": 6 |}MainButton|](linkProps: LinkProps): JSX.Element;|] //// [|declare function [|{| "declarationRangeIndex": 8 |}MainButton|](props: ButtonProps | LinkProps): JSX.Element;|] -//// let opt = <[|MainButton|] />; -//// let opt = <[|MainButton|] children="chidlren" />; -//// let opt = <[|MainButton|] [|[|{| "declarationRangeIndex": 13 |}onClick|]={()=>{}}|] />; -//// let opt = <[|MainButton|] [|[|{| "declarationRangeIndex": 16 |}onClick|]={()=>{}}|] [|ignore-prop|] />; -//// let opt = <[|MainButton|] [|[|{| "declarationRangeIndex": 20 |}goTo|]="goTo"|] />; -//// let opt = <[|MainButton|] [|wrong|] />; +//// let opt = [|<[|{| "declarationRangeIndex": 10 |}MainButton|] />|]; +//// let opt = [|<[|{| "declarationRangeIndex": 12 |}MainButton|] children="chidlren" />|]; +//// let opt = [|<[|{| "declarationRangeIndex": 14 |}MainButton|] [|[|{| "declarationRangeIndex": 16 |}onClick|]={()=>{}}|] />|]; +//// let opt = [|<[|{| "declarationRangeIndex": 18 |}MainButton|] [|[|{| "declarationRangeIndex": 20 |}onClick|]={()=>{}}|] [|ignore-prop|] />|]; +//// let opt = [|<[|{| "declarationRangeIndex": 23 |}MainButton|] [|[|{| "declarationRangeIndex": 25 |}goTo|]="goTo"|] />|]; +//// let opt = [|<[|{| "declarationRangeIndex": 27 |}MainButton|] [|wrong|] />|]; verify.rangesWithSameTextAreRenameLocations( "onClick", From a120c5901563a553d6bcf6fca54038c2dd52ad41 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 6 Jun 2019 11:59:18 -0700 Subject: [PATCH 35/44] Handle Lable --- src/services/findAllReferences.ts | 4 +++- tests/cases/fourslash/referencesForLabel.ts | 12 ++++++------ tests/cases/fourslash/referencesForLabel3.ts | 6 +++--- tests/cases/fourslash/referencesForLabel4.ts | 8 ++++---- tests/cases/fourslash/referencesForLabel5.ts | 16 ++++++++-------- tests/cases/fourslash/referencesForLabel6.ts | 6 +++--- 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index a2eb4f3ec29..a23c5575ce7 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -55,7 +55,9 @@ namespace ts.FindAllReferences { if (isJsxOpeningElement(node.parent) || isJsxClosingElement(node.parent)) { return node.parent.parent; } - else if (isJsxSelfClosingElement(node.parent)) { + else if (isJsxSelfClosingElement(node.parent) || + isLabeledStatement(node.parent) || + isBreakOrContinueStatement(node.parent)) { return node.parent; } diff --git a/tests/cases/fourslash/referencesForLabel.ts b/tests/cases/fourslash/referencesForLabel.ts index 1abcafda0f2..bc77f5b0031 100644 --- a/tests/cases/fourslash/referencesForLabel.ts +++ b/tests/cases/fourslash/referencesForLabel.ts @@ -2,14 +2,14 @@ // Valid References for a label -////[|label|]: while (true) { -//// if (false) break [|label|]; -//// if (true) continue [|label|]; -////} +////[|[|{| "declarationRangeIndex": 0 |}label|]: while (true) { +//// if (false) [|break [|{| "declarationRangeIndex": 2 |}label|];|] +//// if (true) [|continue [|{| "declarationRangeIndex": 4 |}label|];|] +////}|] //// -////[|label|]: while (false) { } +////[|[|{| "declarationRangeIndex": 6 |}label|]: while (false) { }|] ////var label = "label"; -const [r0, r1, r2, r3] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3] = test.ranges(); verify.singleReferenceGroup("label", [r0, r1, r2]); verify.singleReferenceGroup("label", [r3]); diff --git a/tests/cases/fourslash/referencesForLabel3.ts b/tests/cases/fourslash/referencesForLabel3.ts index 13622eb90c3..be700ed6df0 100644 --- a/tests/cases/fourslash/referencesForLabel3.ts +++ b/tests/cases/fourslash/referencesForLabel3.ts @@ -2,8 +2,8 @@ // References to unused label -////[|label|]: while (true) { +////[|[|{| "declarationRangeIndex": 0 |}label|]: while (true) { //// var label = "label"; -////} +////}|] -verify.singleReferenceGroup("label"); +verify.singleReferenceGroup("label", "label"); diff --git a/tests/cases/fourslash/referencesForLabel4.ts b/tests/cases/fourslash/referencesForLabel4.ts index 2ff159bc755..353e663b0d9 100644 --- a/tests/cases/fourslash/referencesForLabel4.ts +++ b/tests/cases/fourslash/referencesForLabel4.ts @@ -2,10 +2,10 @@ // References to a label outside function bounderies -////[|label|]: function foo(label) { +////[|[|{| "declarationRangeIndex": 0 |}label|]: function foo(label) { //// while (true) { -//// break [|label|]; +//// [|break [|{| "declarationRangeIndex": 2 |}label|];|] //// } -////} +////}|] -verify.singleReferenceGroup("label"); +verify.singleReferenceGroup("label", "label"); diff --git a/tests/cases/fourslash/referencesForLabel5.ts b/tests/cases/fourslash/referencesForLabel5.ts index bc986e3350d..91223507624 100644 --- a/tests/cases/fourslash/referencesForLabel5.ts +++ b/tests/cases/fourslash/referencesForLabel5.ts @@ -2,16 +2,16 @@ // References to shadowed label -////[|label|]: while (true) { -//// if (false) break [|label|]; +////[|[|{| "declarationRangeIndex": 0 |}label|]: while (true) { +//// if (false) [|break [|{| "declarationRangeIndex": 2 |}label|];|] //// function blah() { -////[|label|]: while (true) { -//// if (false) break [|label|]; -//// } +////[|[|{| "declarationRangeIndex": 4 |}label|]: while (true) { +//// if (false) [|break [|{| "declarationRangeIndex": 6 |}label|];|] +//// }|] //// } -//// if (false) break [|label|]; -//// } +//// if (false) [|break [|{| "declarationRangeIndex": 8 |}label|];|] +//// }|] -const [outer1, outer2, inner1, inner2, outer3] = test.ranges(); +const [ourter1Def, outer1, outer2Def, outer2, inner1Def, inner1, inner2Def, inner2, outer3Def, outer3] = test.ranges(); 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 a8f71480975..2597d8a7291 100644 --- a/tests/cases/fourslash/referencesForLabel6.ts +++ b/tests/cases/fourslash/referencesForLabel6.ts @@ -2,10 +2,10 @@ // References to labels with close names -////[|labela|]: while (true) { -////[|labelb|]: while (false) { break [|labelb|]; } +////[|[|{| "declarationRangeIndex": 0 |}labela|]: while (true) { +////[|[|{| "declarationRangeIndex": 2 |}labelb|]: while (false) { [|break [|{| "declarationRangeIndex": 4 |}labelb|];|] }|] //// break labelc; -////} +////}|] verify.singleReferenceGroup("labela", "labela"); verify.singleReferenceGroup("labelb", "labelb"); From a67b375d0efb3ecc0abaabc2f8a2f168a680e99e Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 6 Jun 2019 12:51:26 -0700 Subject: [PATCH 36/44] Handle module specifiers --- src/services/findAllReferences.ts | 33 +++++++++++++------ src/testRunner/unittests/tsserver/rename.ts | 9 +++-- .../findAllReferencesDynamicImport1.ts | 6 ++-- ...findAllReferencesUmdModuleAsGlobalConst.ts | 6 ++-- .../fourslash/findAllRefsExportEquals.ts | 2 +- tests/cases/fourslash/findAllRefsForModule.ts | 10 +++--- .../fourslash/findAllRefsForModuleGlobal.ts | 4 +-- .../findAllRefsImportEqualsJsonFile.ts | 4 +-- .../fourslash/findAllRefsModuleDotExports.ts | 6 ++-- .../findAllRefs_importType_exportEquals.ts | 6 ++-- .../fourslash/findAllRefs_importType_js.ts | 6 ++-- .../findAllRefs_importType_typeofImport.ts | 6 ++-- .../cases/fourslash/referencesForAmbients.ts | 6 ++-- .../referencesForExternalModuleNames.ts | 2 +- tests/cases/fourslash/untypedModuleImport.ts | 2 +- 15 files changed, 62 insertions(+), 46 deletions(-) diff --git a/src/services/findAllReferences.ts b/src/services/findAllReferences.ts index a23c5575ce7..b8971d74a41 100644 --- a/src/services/findAllReferences.ts +++ b/src/services/findAllReferences.ts @@ -51,16 +51,6 @@ namespace ts.FindAllReferences { if (!node.parent) return undefined; if (!isDeclaration(node.parent) && !isExportAssignment(node.parent)) { - // Jsx Tags - if (isJsxOpeningElement(node.parent) || isJsxClosingElement(node.parent)) { - return node.parent.parent; - } - else if (isJsxSelfClosingElement(node.parent) || - isLabeledStatement(node.parent) || - isBreakOrContinueStatement(node.parent)) { - return node.parent; - } - // Special property assignment in javascript if (isInJSFile(node)) { const binaryExpression = isBinaryExpression(node.parent) ? @@ -75,6 +65,29 @@ namespace ts.FindAllReferences { } } + // Jsx Tags + if (isJsxOpeningElement(node.parent) || isJsxClosingElement(node.parent)) { + return node.parent.parent; + } + else if (isJsxSelfClosingElement(node.parent) || + isLabeledStatement(node.parent) || + isBreakOrContinueStatement(node.parent)) { + return node.parent; + } + else if (isStringLiteralLike(node)) { + const validImport = tryGetImportFromModuleSpecifier(node); + if (validImport) { + const declOrStatement = findAncestor(validImport, node => + isDeclaration(node) || + isStatement(node) || + isJSDocTag(node) + )! as NamedDeclaration | Statement | JSDocTag; + return isDeclaration(declOrStatement) ? + getDeclarationForDeclarationSpan(declOrStatement) : + declOrStatement; + } + } + // Handle computed property name const propertyName = findAncestor(node, isComputedPropertyName); return propertyName ? diff --git a/src/testRunner/unittests/tsserver/rename.ts b/src/testRunner/unittests/tsserver/rename.ts index 67464499a5b..6f5633875fa 100644 --- a/src/testRunner/unittests/tsserver/rename.ts +++ b/src/testRunner/unittests/tsserver/rename.ts @@ -19,7 +19,8 @@ namespace ts.projectSystem { locs: [ protocolRenameSpanFromSubstring({ fileText: bTs.content, - text: "./a" + text: "./a", + declarationText: bTs.content }) ] }], @@ -43,7 +44,8 @@ namespace ts.projectSystem { locs: [ protocolRenameSpanFromSubstring({ fileText: bTs.content, - text: "./a" + text: "./a", + declarationText: bTs.content }) ] }], @@ -68,7 +70,8 @@ namespace ts.projectSystem { locs: [ protocolRenameSpanFromSubstring({ fileText: bTs.content, - text: "./a" + text: "./a", + declarationText: bTs.content }) ] }], diff --git a/tests/cases/fourslash/findAllReferencesDynamicImport1.ts b/tests/cases/fourslash/findAllReferencesDynamicImport1.ts index c2b6f359ba6..070621ef94b 100644 --- a/tests/cases/fourslash/findAllReferencesDynamicImport1.ts +++ b/tests/cases/fourslash/findAllReferencesDynamicImport1.ts @@ -3,7 +3,7 @@ // @Filename: foo.ts //// export function foo() { return "foo"; } -//// import("[|./foo|]") -//// var x = import("[|./foo|]") +//// [|import("[|{| "declarationRangeIndex": 0 |}./foo|]")|] +//// [|var x = import("[|{| "declarationRangeIndex": 2 |}./foo|]")|] -verify.singleReferenceGroup('module "/tests/cases/fourslash/foo"'); +verify.singleReferenceGroup('module "/tests/cases/fourslash/foo"', "./foo"); diff --git a/tests/cases/fourslash/findAllReferencesUmdModuleAsGlobalConst.ts b/tests/cases/fourslash/findAllReferencesUmdModuleAsGlobalConst.ts index 4876b1e0229..23435fa5cad 100644 --- a/tests/cases/fourslash/findAllReferencesUmdModuleAsGlobalConst.ts +++ b/tests/cases/fourslash/findAllReferencesUmdModuleAsGlobalConst.ts @@ -12,9 +12,9 @@ ////[|export as namespace [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}THREE|];|] // @Filename: /typings/global.d.ts -////import * as _THREE from '[|three|]'; +////[|import * as _THREE from '[|{| "declarationRangeIndex": 2 |}three|]';|] ////declare global { -//// [|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}THREE|]: typeof _THREE;|] +//// [|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}THREE|]: typeof _THREE;|] ////} // @Filename: /src/index.ts @@ -38,7 +38,7 @@ //// "files": ["/src/index.ts", "typings/global.d.ts"] ////} -const [r0Def, r0, r1, r2Def, ...rest] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, ...rest] = test.ranges(); // GH#29533 // TODO:: this should be var THREE: typeof import instead of module name as var but thats existing issue and repros with quickInfo too. verify.singleReferenceGroup(`module "/node_modules/@types/three/index" diff --git a/tests/cases/fourslash/findAllRefsExportEquals.ts b/tests/cases/fourslash/findAllRefsExportEquals.ts index fd17a82633c..d7d80564e5b 100644 --- a/tests/cases/fourslash/findAllRefsExportEquals.ts +++ b/tests/cases/fourslash/findAllRefsExportEquals.ts @@ -5,7 +5,7 @@ ////[|[|{| "declarationRangeIndex": 2 |}export|] = [|{| "declarationRangeIndex": 2 |}T|];|] // @Filename: /b.ts -////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}T|] = require("[|./a|]");|] +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 5 |}T|] = require("[|{| "declarationRangeIndex": 5 |}./a|]");|] const [r0Def, r0, r12Def, r1, r2, r3Def, r3, r4] = test.ranges(); const mod = { definition: 'module "/a"', ranges: [r4, r1] }; diff --git a/tests/cases/fourslash/findAllRefsForModule.ts b/tests/cases/fourslash/findAllRefsForModule.ts index a9a44d6ffaa..0449c6a4408 100644 --- a/tests/cases/fourslash/findAllRefsForModule.ts +++ b/tests/cases/fourslash/findAllRefsForModule.ts @@ -6,16 +6,16 @@ ////export const x = 0; // @Filename: /b.ts -////import { x } from "[|./a|]"; +////[|import { x } from "[|{| "declarationRangeIndex": 0 |}./a|]";|] // @Filename: /c/sub.js -////const a = require("[|../a|]"); +////[|const a = require("[|{| "declarationRangeIndex": 2 |}../a|]");|] // @Filename: /d.ts //// /// -const ranges = test.ranges(); -const [r0, r1, r2] = ranges; +const [r0Def, r0, r1Def, r1, r2] = test.ranges(); +const ranges = [r0, r1, r2]; verify.referenceGroups(ranges, [{ definition: 'module "/a"', ranges: [r0, r1, r2] }]); // Testing that it works with documentHighlights too -verify.rangesAreDocumentHighlights(); +verify.rangesAreDocumentHighlights(ranges); diff --git a/tests/cases/fourslash/findAllRefsForModuleGlobal.ts b/tests/cases/fourslash/findAllRefsForModuleGlobal.ts index 4c7aa3939c1..bdb0d62a5cb 100644 --- a/tests/cases/fourslash/findAllRefsForModuleGlobal.ts +++ b/tests/cases/fourslash/findAllRefsForModuleGlobal.ts @@ -5,8 +5,8 @@ // @Filename: /b.ts /////// -////import { x } from "[|foo|]"; -////[|declare module "[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 2 |}foo|]" {}|] +////[|import { x } from "[|{| "declarationRangeIndex": 1 |}foo|]";|] +////[|declare module "[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 3 |}foo|]" {}|] verify.noErrors(); verify.singleReferenceGroup('module "/node_modules/foo/index"', "foo"); diff --git a/tests/cases/fourslash/findAllRefsImportEqualsJsonFile.ts b/tests/cases/fourslash/findAllRefsImportEqualsJsonFile.ts index 7b6e0e5bbc0..97147e4a1f6 100644 --- a/tests/cases/fourslash/findAllRefsImportEqualsJsonFile.ts +++ b/tests/cases/fourslash/findAllRefsImportEqualsJsonFile.ts @@ -5,11 +5,11 @@ // @resolveJsonModule: true // @Filename: /a.ts -////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}j|] = require("[|./j.json|]");|] +////[|import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}j|] = require("[|{| "declarationRangeIndex": 0 |}./j.json|]");|] ////[|j|]; // @Filename: /b.js -////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}j|] = require("[|./j.json|]");|] +////[|const [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}j|] = require("[|{| "declarationRangeIndex": 4 |}./j.json|]");|] ////[|j|]; // @Filename: /j.json diff --git a/tests/cases/fourslash/findAllRefsModuleDotExports.ts b/tests/cases/fourslash/findAllRefsModuleDotExports.ts index ca30b341b90..165944ba356 100644 --- a/tests/cases/fourslash/findAllRefsModuleDotExports.ts +++ b/tests/cases/fourslash/findAllRefsModuleDotExports.ts @@ -3,10 +3,10 @@ // @allowJs: true // @Filename: /a.js -////const b = require("[|./b|]"); +////[|const b = require("[|{| "declarationRangeIndex": 0 |}./b|]");|] // @Filename: /b.js -////[|[|{| "declarationRangeIndex": 1 |}module|].exports = 0;|] +////[|[|{| "declarationRangeIndex": 2 |}module|].exports = 0;|] -const [r0, rDef, r1] = test.ranges(); +const [r0Def, r0, rDef, r1] = test.ranges(); verify.singleReferenceGroup('module "/b"', [r0, r1]); diff --git a/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts b/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts index 4597c3a8bc9..e2c86d60c9c 100644 --- a/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts +++ b/tests/cases/fourslash/findAllRefs_importType_exportEquals.ts @@ -8,12 +8,12 @@ ////[|[|{| "declarationRangeIndex": 4 |}export|] = [|{| "declarationRangeIndex": 4 |}T|];|] // @Filename: /b.ts -////const x: import("[|./[|a|]|]") = 0; -////const y: import("[|./[|a|]|]").U = ""; +////[|const x: import("[|{| "declarationRangeIndex": 7 |}./[|a|]|]") = 0;|] +////[|const y: import("[|{| "declarationRangeIndex": 10 |}./[|a|]|]").U = "";|] verify.noErrors(); -const [r0Def, r0, r1Def, r1, r2Def, rExport, r2, r3, r3b, r4, r4b] = test.ranges(); +const [r0Def, r0, r1Def, r1, r2Def, rExport, r2, r3Def, r3, r3b, r4Def, r4, r4b] = test.ranges(); verify.referenceGroups(r0, [{ definition: "type T = number\nnamespace T", ranges: [r0, r2, r3] }]); verify.referenceGroups(r1, [{ definition: "namespace T", ranges: [r1, r2] }]); const t: FourSlashInterface.ReferenceGroup = { definition: "type T = number\nnamespace T", ranges: [r0, r1, r2, r3] }; diff --git a/tests/cases/fourslash/findAllRefs_importType_js.ts b/tests/cases/fourslash/findAllRefs_importType_js.ts index 79f99da90a4..51d99aaae7a 100644 --- a/tests/cases/fourslash/findAllRefs_importType_js.ts +++ b/tests/cases/fourslash/findAllRefs_importType_js.ts @@ -8,16 +8,16 @@ ////[|module.exports.[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}D|] = [|class [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}D|] {}|];|] // @Filename: /b.js -/////** @type {import("[|./a|]")} */ +/////** [|@type {import("[|{| "declarationRangeIndex": 8 |}./a|]")}|] */ ////const x = 0; -/////** @type {import("[|./a|]").[|D|]} */ +/////** [|@type {import("[|{| "declarationRangeIndex": 10 |}./a|]").[|D|]}|] */ ////const y = 0; verify.noErrors(); // TODO: GH#24025 -const [rModuleDef, rModule, r0Def, r0, r1Def, r1, r2Def, r2, r3, r4, r5] = test.ranges(); +const [rModuleDef, rModule, r0Def, r0, r1Def, r1, r2Def, r2, r3Def, r3, r4Def, r4, r5] = test.ranges(); verify.referenceGroups(rModule, [{ definition: 'module "/a"', ranges: [r3, r4, rModule] }]); verify.referenceGroups(r0, [ { definition: "(local class) C", ranges: [r0] }, diff --git a/tests/cases/fourslash/findAllRefs_importType_typeofImport.ts b/tests/cases/fourslash/findAllRefs_importType_typeofImport.ts index beab9c7cfc4..082b34b6792 100644 --- a/tests/cases/fourslash/findAllRefs_importType_typeofImport.ts +++ b/tests/cases/fourslash/findAllRefs_importType_typeofImport.ts @@ -4,7 +4,7 @@ ////export const x = 0; // @Filename: /b.ts -////const x: typeof import("[|./a|]") = { x: 0 }; -////const y: typeof import("[|./a|]") = { x: 0 }; +////[|const x: typeof import("[|{| "declarationRangeIndex": 0 |}./a|]") = { x: 0 };|] +////[|const y: typeof import("[|{| "declarationRangeIndex": 2 |}./a|]") = { x: 0 };|] -verify.singleReferenceGroup('module "/a"'); +verify.singleReferenceGroup('module "/a"', "./a"); diff --git a/tests/cases/fourslash/referencesForAmbients.ts b/tests/cases/fourslash/referencesForAmbients.ts index 77ff23cab98..4631a659b00 100644 --- a/tests/cases/fourslash/referencesForAmbients.ts +++ b/tests/cases/fourslash/referencesForAmbients.ts @@ -5,16 +5,16 @@ ////}|] //// ////[|declare module "[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 4 |}bar|]" { -//// [|export import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}foo|] = require("[|foo|]");|] +//// [|export import [|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 6 |}foo|] = require("[|{| "declarationRangeIndex": 6 |}foo|]");|] //// var f2: typeof [|foo|].[|f|]; ////}|] //// ////declare module "baz" { -//// import bar = require("[|bar|]"); +//// [|import bar = require("[|{| "declarationRangeIndex": 11 |}bar|]");|] //// var f2: typeof bar.[|foo|]; ////} -const [moduleFoo0Def, moduleFoo0, f0Def, f0, moduleBar0Def, moduleBar0, foo0Def, foo0, moduleFoo1, foo1, f1, moduleBar1, foo2] = test.ranges(); +const [moduleFoo0Def, moduleFoo0, f0Def, f0, moduleBar0Def, moduleBar0, foo0Def, foo0, moduleFoo1, foo1, f1, moduleBar1Def, moduleBar1, foo2] = test.ranges(); verify.singleReferenceGroup('module "foo"', [moduleFoo0, moduleFoo1]); verify.singleReferenceGroup('module "bar"', [moduleBar0, moduleBar1]); verify.singleReferenceGroup('(alias) module "foo"\nimport foo = require("foo")', [foo0, foo1, foo2]); diff --git a/tests/cases/fourslash/referencesForExternalModuleNames.ts b/tests/cases/fourslash/referencesForExternalModuleNames.ts index 6fafec9f690..66fa11d45c3 100644 --- a/tests/cases/fourslash/referencesForExternalModuleNames.ts +++ b/tests/cases/fourslash/referencesForExternalModuleNames.ts @@ -6,6 +6,6 @@ ////}|] // @Filename: referencesForGlobals_2.ts -////import f = require("[|foo|]"); +////[|import f = require("[|{| "declarationRangeIndex": 2 |}foo|]");|] verify.singleReferenceGroup('module "foo"', "foo"); diff --git a/tests/cases/fourslash/untypedModuleImport.ts b/tests/cases/fourslash/untypedModuleImport.ts index 783e020e3fc..72452fac0ae 100644 --- a/tests/cases/fourslash/untypedModuleImport.ts +++ b/tests/cases/fourslash/untypedModuleImport.ts @@ -4,7 +4,7 @@ ////{} // @Filename: a.ts -////[|import /*foo*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|] from /*fooModule*/"[|{| "isInString": true |}foo|]";|] +////[|import /*foo*/[|{| "isWriteAccess": true, "isDefinition": true, "declarationRangeIndex": 0 |}foo|] from /*fooModule*/"[|{| "isInString": true, "declarationRangeIndex": 0 |}foo|]";|] ////[|foo|](); goTo.file("a.ts"); From bdf8d5c8cb17622b0a6910d7a9639b08671c6683 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Thu, 6 Jun 2019 15:13:16 -0700 Subject: [PATCH 37/44] Update DOM and baselines --- src/lib/dom.generated.d.ts | 3822 +++++++++-------- src/lib/dom.iterable.generated.d.ts | 124 +- src/lib/webworker.generated.d.ts | 714 +-- .../globalThisBlockscopedProperties.types | 2 +- tests/baselines/reference/importMeta.symbols | 2 +- tests/baselines/reference/importMeta.types | 2 +- .../baselines/reference/importMetaES5.symbols | 2 +- tests/baselines/reference/importMetaES5.types | 2 +- .../intersectionsOfLargeUnions2.errors.txt | 2 +- .../mappedTypeRecursiveInference.errors.txt | 8 +- .../multiExtendsSplitInterfaces1.symbols | 4 +- 11 files changed, 2519 insertions(+), 2165 deletions(-) diff --git a/src/lib/dom.generated.d.ts b/src/lib/dom.generated.d.ts index 18f38b53560..e527838fc76 100644 --- a/src/lib/dom.generated.d.ts +++ b/src/lib/dom.generated.d.ts @@ -250,6 +250,15 @@ interface ConvolverOptions extends AudioNodeOptions { disableNormalization?: boolean; } +interface CredentialCreationOptions { + signal?: AbortSignal; +} + +interface CredentialRequestOptions { + mediation?: CredentialMediationRequirement; + signal?: AbortSignal; +} + interface CustomEventInit extends EventInit { detail?: T; } @@ -432,7 +441,6 @@ interface EventModifierInit extends UIEventInit { modifierFnLock?: boolean; modifierHyper?: boolean; modifierNumLock?: boolean; - modifierOS?: boolean; modifierScrollLock?: boolean; modifierSuper?: boolean; modifierSymbol?: boolean; @@ -546,6 +554,12 @@ interface ImageEncodeOptions { type?: string; } +interface InputEventInit extends UIEventInit { + data?: string | null; + inputType?: string; + isComposing?: boolean; +} + interface IntersectionObserverEntryInit { boundingClientRect: DOMRectInit; intersectionRatio: number; @@ -589,6 +603,7 @@ interface KeyAlgorithm { interface KeyboardEventInit extends EventModifierInit { code?: string; + isComposing?: boolean; key?: string; location?: number; repeat?: boolean; @@ -780,12 +795,33 @@ interface MultiCacheQueryOptions extends CacheQueryOptions { } interface MutationObserverInit { + /** + * Set to a list of attribute local names (without namespace) if not all attribute mutations need to be observed and attributes is true or omitted. + */ attributeFilter?: string[]; + /** + * Set to true if attributes is true or omitted and target's attribute value before the mutation needs to be recorded. + */ attributeOldValue?: boolean; + /** + * Set to true if mutations to target's attributes are to be observed. Can be omitted if attributeOldValue or attributeFilter is specified. + */ attributes?: boolean; + /** + * Set to true if mutations to target's data are to be observed. Can be omitted if characterDataOldValue is specified. + */ characterData?: boolean; + /** + * Set to true if characterData is set to true or omitted and target's data before the mutation needs to be recorded. + */ characterDataOldValue?: boolean; + /** + * Set to true if mutations to target's children are to be observed. + */ childList?: boolean; + /** + * Set to true if mutations to not just target, but also target's descendants are to be observed. + */ subtree?: boolean; } @@ -1390,18 +1426,57 @@ interface RegistrationOptions { } interface RequestInit { + /** + * A BodyInit object or null to set request's body. + */ body?: BodyInit | null; + /** + * A string indicating how the request will interact with the browser's cache to set request's cache. + */ cache?: RequestCache; + /** + * A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials. + */ credentials?: RequestCredentials; + /** + * A Headers object, an object literal, or an array of two-item arrays to set request's headers. + */ headers?: HeadersInit; + /** + * A cryptographic hash of the resource to be fetched by request. Sets request's integrity. + */ integrity?: string; + /** + * A boolean to set request's keepalive. + */ keepalive?: boolean; + /** + * A string to set request's method. + */ method?: string; + /** + * A string to indicate whether the request will use CORS, or will be restricted to same-origin URLs. Sets request's mode. + */ mode?: RequestMode; + /** + * A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect. + */ redirect?: RequestRedirect; + /** + * A string whose value is a same-origin URL, "about:client", or the empty string, to set request's referrer. + */ referrer?: string; + /** + * A referrer policy to set request's referrerPolicy. + */ referrerPolicy?: ReferrerPolicy; + /** + * An AbortSignal to set request's signal. + */ signal?: AbortSignal | null; + /** + * Can only be null. Used to disassociate request from any Window. + */ window?: any; } @@ -1654,14 +1729,15 @@ interface WebAuthnExtensions { } interface WebGLContextAttributes { - alpha?: GLboolean; - antialias?: GLboolean; - depth?: GLboolean; + alpha?: boolean; + antialias?: boolean; + depth?: boolean; + desynchronized?: boolean; failIfMajorPerformanceCaveat?: boolean; powerPreference?: WebGLPowerPreference; - premultipliedAlpha?: GLboolean; - preserveDrawingBuffer?: GLboolean; - stencil?: GLboolean; + premultipliedAlpha?: boolean; + preserveDrawingBuffer?: boolean; + stencil?: boolean; } interface WebGLContextEventInit extends EventInit { @@ -1706,8 +1782,7 @@ interface AbortController { */ readonly signal: AbortSignal; /** - * Invoking this method will set this object's AbortSignal's aborted flag and - * signal to any observers that the associated activity is to be aborted. + * Invoking this method will set this object's AbortSignal's aborted flag and signal to any observers that the associated activity is to be aborted. */ abort(): void; } @@ -1724,8 +1799,7 @@ interface AbortSignalEventMap { /** A signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an AbortController object. */ interface AbortSignal extends EventTarget { /** - * Returns true if this AbortSignal's AbortController has signaled to abort, and false - * otherwise. + * Returns true if this AbortSignal's AbortController has signaled to abort, and false otherwise. */ readonly aborted: boolean; onabort: ((this: AbortSignal, ev: Event) => any) | null; @@ -1741,10 +1815,25 @@ declare var AbortSignal: { }; interface AbstractRange { + /** + * Returns true if range is collapsed, and false otherwise. + */ readonly collapsed: boolean; + /** + * Returns range's end node. + */ readonly endContainer: Node; + /** + * Returns range's end offset. + */ readonly endOffset: number; + /** + * Returns range's start node. + */ readonly startContainer: Node; + /** + * Returns range's start offset. + */ readonly startOffset: number; } @@ -1854,6 +1943,11 @@ declare var AnimationEvent: { new(type: string, animationEventInitDict?: AnimationEventInit): AnimationEvent; }; +interface AnimationFrameProvider { + cancelAnimationFrame(handle: number): void; + requestAnimationFrame(callback: FrameRequestCallback): number; +} + interface AnimationPlaybackEvent extends Event { readonly currentTime: number | null; readonly timelineTime: number | null; @@ -2343,7 +2437,7 @@ declare var BroadcastChannel: { new(name: string): BroadcastChannel; }; -/** An interface of the Streams API provides a built-in byte length queuing strategy that can be used when constructing streams. */ +/** This Streams API interface provides a built-in byte length queuing strategy that can be used when constructing streams. */ interface ByteLengthQueuingStrategy extends QueuingStrategy { highWaterMark: number; size(chunk: ArrayBufferView): number; @@ -2522,9 +2616,9 @@ declare var CSSRuleList: { /** An object that is a CSS declaration block, and exposes style information and various style-related methods and properties. */ interface CSSStyleDeclaration { - alignContent: string | null; - alignItems: string | null; - alignSelf: string | null; + alignContent: string; + alignItems: string; + alignSelf: string; alignmentBaseline: string | null; animation: string; animationDelay: string; @@ -2594,7 +2688,7 @@ interface CSSStyleDeclaration { clipPath: string | null; clipRule: string | null; color: string | null; - colorInterpolationFilters: string | null; + colorInterpolationFilters: string; columnCount: string; columnFill: string; columnGap: string; @@ -2611,7 +2705,7 @@ interface CSSStyleDeclaration { cssFloat: string | null; cssText: string; cursor: string; - direction: string | null; + direction: string; display: string | null; dominantBaseline: string | null; emptyCells: string | null; @@ -2619,7 +2713,7 @@ interface CSSStyleDeclaration { fill: string | null; fillOpacity: string | null; fillRule: string | null; - filter: string | null; + filter: string; flex: string | null; flexBasis: string | null; flexDirection: string | null; @@ -2627,20 +2721,27 @@ interface CSSStyleDeclaration { flexGrow: string | null; flexShrink: string | null; flexWrap: string | null; - floodColor: string | null; - floodOpacity: string | null; - font: string | null; - fontFamily: string | null; - fontFeatureSettings: string | null; - fontSize: string | null; - fontSizeAdjust: string | null; - fontStretch: string | null; - fontStyle: string | null; - fontVariant: string | null; - fontWeight: string | null; - gap: string | null; + floodColor: string; + floodOpacity: string; + font: string; + fontFamily: string; + fontFeatureSettings: string; + fontKerning: string; + fontSize: string; + fontSizeAdjust: string; + fontStretch: string; + fontStyle: string; + fontSynthesis: string; + fontVariant: string; + fontVariantCaps: string; + fontVariantEastAsian: string; + fontVariantLigatures: string; + fontVariantNumeric: string; + fontVariantPosition: string; + fontWeight: string; + gap: string; glyphOrientationHorizontal: string | null; - glyphOrientationVertical: string | null; + glyphOrientationVertical: string; grid: string | null; gridArea: string | null; gridAutoColumns: string | null; @@ -2648,24 +2749,25 @@ interface CSSStyleDeclaration { gridAutoRows: string | null; gridColumn: string | null; gridColumnEnd: string | null; - gridColumnGap: string | null; + gridColumnGap: string; gridColumnStart: string | null; - gridGap: string | null; + gridGap: string; gridRow: string | null; gridRowEnd: string | null; - gridRowGap: string | null; + gridRowGap: string; gridRowStart: string | null; gridTemplate: string | null; gridTemplateAreas: string | null; gridTemplateColumns: string | null; gridTemplateRows: string | null; height: string | null; + hyphens: string; imageOrientation: string; imageRendering: string; imeMode: string | null; - justifyContent: string | null; - justifyItems: string | null; - justifySelf: string | null; + justifyContent: string; + justifyItems: string; + justifySelf: string; kerning: string | null; layoutGrid: string | null; layoutGridChar: string | null; @@ -2674,9 +2776,9 @@ interface CSSStyleDeclaration { layoutGridType: string | null; left: string | null; readonly length: number; - letterSpacing: string | null; - lightingColor: string | null; - lineBreak: string | null; + letterSpacing: string; + lightingColor: string; + lineBreak: string; lineHeight: string | null; listStyle: string | null; listStyleImage: string | null; @@ -2755,6 +2857,8 @@ interface CSSStyleDeclaration { outlineStyle: string; outlineWidth: string; overflow: string | null; + overflowAnchor: string; + overflowWrap: string; overflowX: string | null; overflowY: string | null; padding: string | null; @@ -2769,13 +2873,16 @@ interface CSSStyleDeclaration { penAction: string | null; perspective: string | null; perspectiveOrigin: string | null; + placeContent: string; + placeItems: string; + placeSelf: string; pointerEvents: string | null; position: string | null; quotes: string | null; - resize: string | null; + resize: string; right: string | null; rotate: string | null; - rowGap: string | null; + rowGap: string; rubyAlign: string | null; rubyOverhang: string | null; rubyPosition: string | null; @@ -2791,24 +2898,34 @@ interface CSSStyleDeclaration { strokeMiterlimit: string | null; strokeOpacity: string | null; strokeWidth: string | null; + tabSize: string; tableLayout: string | null; - textAlign: string | null; - textAlignLast: string | null; + textAlign: string; + textAlignLast: string; textAnchor: string | null; - textCombineUpright: string | null; - textDecoration: string | null; - textIndent: string | null; - textJustify: string | null; + textCombineUpright: string; + textDecoration: string; + textDecorationColor: string; + textDecorationLine: string; + textDecorationStyle: string; + textEmphasis: string; + textEmphasisColor: string; + textEmphasisPosition: string; + textEmphasisStyle: string; + textIndent: string; + textJustify: string; textKashida: string | null; textKashidaSpace: string | null; + textOrientation: string; textOverflow: string; - textShadow: string | null; - textTransform: string | null; - textUnderlinePosition: string | null; + textShadow: string; + textTransform: string; + textUnderlinePosition: string; top: string | null; touchAction: string; - transform: string | null; - transformOrigin: string | null; + transform: string; + transformBox: string; + transformOrigin: string; transformStyle: string | null; transition: string; transitionDelay: string; @@ -2816,8 +2933,8 @@ interface CSSStyleDeclaration { transitionProperty: string; transitionTimingFunction: string; translate: string | null; - unicodeBidi: string | null; - userSelect: string | null; + unicodeBidi: string; + userSelect: string; verticalAlign: string | null; visibility: string | null; /** @deprecated */ @@ -2973,14 +3090,14 @@ interface CSSStyleDeclaration { webkitUserModify: string | null; webkitUserSelect: string | null; webkitWritingMode: string | null; - whiteSpace: string | null; + whiteSpace: string; widows: string | null; width: string | null; willChange: string; - wordBreak: string | null; - wordSpacing: string | null; - wordWrap: string | null; - writingMode: string | null; + wordBreak: string; + wordSpacing: string; + wordWrap: string; + writingMode: string; zIndex: string | null; zoom: string | null; getPropertyPriority(propertyName: string): string; @@ -3124,11 +3241,9 @@ interface CanvasFilters { /** An opaque object describing a gradient. It is returned by the methods CanvasRenderingContext2D.createLinearGradient() or CanvasRenderingContext2D.createRadialGradient(). */ interface CanvasGradient { /** - * Adds a color stop with the given color to the gradient at the given offset. 0.0 is the offset - * at one end of the gradient, 1.0 is the offset at the other end. - * Throws an "IndexSizeError" DOMException if the offset - * is out of range. Throws a "SyntaxError" DOMException if - * the color cannot be parsed. + * Adds a color stop with the given color to the gradient at the given offset. 0.0 is the offset at one end of the gradient, 1.0 is the offset at the other end. + * + * Throws an "IndexSizeError" DOMException if the offset is out of range. Throws a "SyntaxError" DOMException if the color cannot be parsed. */ addColorStop(offset: number, color: string): void; } @@ -3176,8 +3291,7 @@ interface CanvasPathDrawingStyles { /** An opaque object describing a pattern, based on an image, a canvas, or a video, created by the CanvasRenderingContext2D.createPattern() method. */ interface CanvasPattern { /** - * Sets the transformation matrix that will be used when rendering the pattern during a fill or - * stroke painting operation. + * Sets the transformation matrix that will be used when rendering the pattern during a fill or stroke painting operation. */ setTransform(transform?: DOMMatrix2DInit): void; } @@ -3294,14 +3408,14 @@ declare var CharacterData: { interface ChildNode extends Node { /** * Inserts nodes just after node, while replacing strings in nodes with equivalent Text nodes. - * Throws a "HierarchyRequestError" DOMException if the constraints of - * the node tree are violated. + * + * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. */ after(...nodes: (Node | string)[]): void; /** * Inserts nodes just before node, while replacing strings in nodes with equivalent Text nodes. - * Throws a "HierarchyRequestError" DOMException if the constraints of - * the node tree are violated. + * + * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. */ before(...nodes: (Node | string)[]): void; /** @@ -3310,8 +3424,8 @@ interface ChildNode extends Node { remove(): void; /** * Replaces node with nodes, while replacing strings in nodes with equivalent Text nodes. - * Throws a "HierarchyRequestError" DOMException if the constraints of - * the node tree are violated. + * + * Throws a "HierarchyRequestError" DOMException if the constraints of the node tree are violated. */ replaceWith(...nodes: (Node | string)[]): void; } @@ -3387,13 +3501,11 @@ declare var Comment: { /** The DOM CompositionEvent represents events that occur due to the user indirectly entering text. */ interface CompositionEvent extends UIEvent { readonly data: string; - readonly locale: string; - initCompositionEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, viewArg: Window, dataArg: string, locale: string): void; } declare var CompositionEvent: { prototype: CompositionEvent; - new(typeArg: string, eventInitDict?: CompositionEventInit): CompositionEvent; + new(type: string, eventInitDict?: CompositionEventInit): CompositionEvent; }; interface ConcatParams extends Algorithm { @@ -3474,7 +3586,7 @@ interface Coordinates { readonly speed: number | null; } -/** An interface of the Streams API provides a built-in byte length queuing strategy that can be used when constructing streams. */ +/** This Streams API interface provides a built-in byte length queuing strategy that can be used when constructing streams. */ interface CountQueuingStrategy extends QueuingStrategy { highWaterMark: number; size(chunk: any): 1; @@ -3485,6 +3597,28 @@ declare var CountQueuingStrategy: { new(options: { highWaterMark: number }): CountQueuingStrategy; }; +interface Credential { + readonly id: string; + readonly type: string; +} + +declare var Credential: { + prototype: Credential; + new(): Credential; +}; + +interface CredentialsContainer { + create(options?: CredentialCreationOptions): Promise; + get(options?: CredentialRequestOptions): Promise; + preventSilentAccess(): Promise; + store(credential: Credential): Promise; +} + +declare var CredentialsContainer: { + prototype: CredentialsContainer; + new(): CredentialsContainer; +}; + /** Basic cryptography features available in the current context. It allows access to a cryptographically strong random number generator and to cryptographic primitives. */ interface Crypto { readonly subtle: SubtleCrypto; @@ -3534,8 +3668,7 @@ declare var CustomElementRegistry: { interface CustomEvent extends Event { /** - * Returns any custom data event was created with. - * Typically used for synthetic events. + * Returns any custom data event was created with. Typically used for synthetic events. */ readonly detail: T; initCustomEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, detailArg: T): void; @@ -3859,8 +3992,7 @@ interface DOMStringList { */ readonly length: number; /** - * Returns true if strings contains string, and false - * otherwise. + * Returns true if strings contains string, and false otherwise. */ contains(string: string): boolean; /** @@ -3893,15 +4025,16 @@ interface DOMTokenList { readonly length: number; /** * Returns the associated set as string. + * * Can be set, to change the associated attribute. */ value: string; /** * Adds all arguments passed, except those already present. - * Throws a "SyntaxError" DOMException if one of the arguments is the empty - * string. - * Throws an "InvalidCharacterError" DOMException if one of the arguments - * contains any ASCII whitespace. + * + * Throws a "SyntaxError" DOMException if one of the arguments is the empty string. + * + * Throws an "InvalidCharacterError" DOMException if one of the arguments contains any ASCII whitespace. */ add(...tokens: string[]): void; /** @@ -3909,32 +4042,42 @@ interface DOMTokenList { */ contains(token: string): boolean; /** - * tokenlist[index] + * Returns the token with index index. */ item(index: number): string | null; /** * Removes arguments passed, if they are present. - * Throws a "SyntaxError" DOMException if one of the arguments is the empty - * string. - * Throws an "InvalidCharacterError" DOMException if one of the arguments - * contains any ASCII whitespace. + * + * Throws a "SyntaxError" DOMException if one of the arguments is the empty string. + * + * Throws an "InvalidCharacterError" DOMException if one of the arguments contains any ASCII whitespace. */ remove(...tokens: string[]): void; /** * Replaces token with newToken. + * * Returns true if token was replaced with newToken, and false otherwise. - * Throws a "SyntaxError" DOMException if one of the arguments is the empty - * string. - * Throws an "InvalidCharacterError" DOMException if one of the arguments - * contains any ASCII whitespace. + * + * Throws a "SyntaxError" DOMException if one of the arguments is the empty string. + * + * Throws an "InvalidCharacterError" DOMException if one of the arguments contains any ASCII whitespace. */ replace(oldToken: string, newToken: string): void; /** - * Returns true if token is in the associated attribute's supported tokens. Returns - * false otherwise. + * Returns true if token is in the associated attribute's supported tokens. Returns false otherwise. + * * Throws a TypeError if the associated attribute has no supported tokens defined. */ supports(token: string): boolean; + /** + * If force is not given, "toggles" token, removing it if it's present and adding it if it's not present. If force is true, adds token (same as add()). If force is false, removes token (same as remove()). + * + * Returns true if token is now present, and false otherwise. + * + * Throws a "SyntaxError" DOMException if token is empty. + * + * Throws an "InvalidCharacterError" DOMException if token contains any spaces. + */ toggle(token: string, force?: boolean): boolean; forEach(callbackfn: (value: string, key: number, parent: DOMTokenList) => void, thisArg?: any): void; [index: number]: string; @@ -3960,7 +4103,21 @@ declare var DataCue: { /** Used to hold the data that is being dragged during a drag and drop operation. It may hold one or more data items, each of one or more data types. For more information about drag and drop, see HTML Drag and Drop API. */ interface DataTransfer { + /** + * Returns the kind of operation that is currently selected. If the kind of operation isn't one of those that is allowed by the effectAllowed attribute, then the operation will fail. + * + * Can be set, to change the selected operation. + * + * The possible values are "none", "copy", "link", and "move". + */ dropEffect: string; + /** + * Returns the kinds of operations that are to be allowed. + * + * Can be set (during the dragstart event), to change the allowed operations. + * + * The possible values are "none", "copy", "copyLink", "copyMove", "link", "linkMove", "move", "all", and "uninitialized", + */ effectAllowed: string; /** * Returns a FileList of the files being dragged, if any. @@ -3971,8 +4128,7 @@ interface DataTransfer { */ readonly items: DataTransferItemList; /** - * Returns a frozen array listing the formats that were set in the dragstart event. In addition, if any files are being - * dragged, then one of the types will be the string "Files". + * Returns a frozen array listing the formats that were set in the dragstart event. In addition, if any files are being dragged, then one of the types will be the string "Files". */ readonly types: ReadonlyArray; /** @@ -3988,8 +4144,7 @@ interface DataTransfer { */ setData(format: string, data: string): void; /** - * Uses the given element to update the drag feedback, replacing any previously specified - * feedback. + * Uses the given element to update the drag feedback, replacing any previously specified feedback. */ setDragImage(image: Element, x: number, y: number): void; } @@ -4002,8 +4157,7 @@ declare var DataTransfer: { /** One drag data item. During a drag operation, each drag event has a dataTransfer property which contains a list of drag data items. Each item in the list is a DataTransferItem object. */ interface DataTransferItem { /** - * Returns the drag data item kind, one of: "string", - * "file". + * Returns the drag data item kind, one of: "string", "file". */ readonly kind: string; /** @@ -4015,8 +4169,7 @@ interface DataTransferItem { */ getAsFile(): File | null; /** - * Invokes the callback with the string data as the argument, if the drag data item - * kind is Plain Unicode string. + * Invokes the callback with the string data as the argument, if the drag data item kind is Plain Unicode string. */ getAsString(callback: FunctionStringCallback | null): void; webkitGetAsEntry(): any; @@ -4034,9 +4187,7 @@ interface DataTransferItemList { */ readonly length: number; /** - * Adds a new entry for the given data to the drag data store. If the data is plain - * text then a type string has to be provided - * also. + * Adds a new entry for the given data to the drag data store. If the data is plain text then a type string has to be provided also. */ add(data: string, type: string): DataTransferItem | null; add(data: File): DataTransferItem | null; @@ -4182,53 +4333,53 @@ interface DocumentEventMap extends GlobalEventHandlersEventMap, DocumentAndEleme /** Any web page loaded in the browser and serves as an entry point into the web page's content, which is the DOM tree. */ interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, ParentNode, XPathEvaluatorBase, GlobalEventHandlers, DocumentAndElementEventHandlers { - /** - * Sets or gets the URL for the current document. + /** + * Sets or gets the URL for the current document. */ readonly URL: string; - /** - * Gets the object that has the focus when the parent document has focus. + /** + * Gets the object that has the focus when the parent document has focus. */ readonly activeElement: Element | null; - /** - * Sets or gets the color of all active links in the document. + /** + * Sets or gets the color of all active links in the document. */ /** @deprecated */ alinkColor: string; - /** - * Returns a reference to the collection of elements contained by the object. + /** + * Returns a reference to the collection of elements contained by the object. */ /** @deprecated */ readonly all: HTMLAllCollection; - /** - * Retrieves a collection of all a objects that have a name and/or id property. Objects in this collection are in HTML source order. + /** + * Retrieves a collection of all a objects that have a name and/or id property. Objects in this collection are in HTML source order. */ /** @deprecated */ readonly anchors: HTMLCollectionOf; - /** - * Retrieves a collection of all applet objects in the document. + /** + * Retrieves a collection of all applet objects in the document. */ /** @deprecated */ readonly applets: HTMLCollectionOf; - /** - * Deprecated. Sets or retrieves a value that indicates the background color behind the object. + /** + * Deprecated. Sets or retrieves a value that indicates the background color behind the object. */ /** @deprecated */ bgColor: string; - /** - * Specifies the beginning and end of the document body. + /** + * Specifies the beginning and end of the document body. */ body: HTMLElement; /** * Returns document's encoding. */ readonly characterSet: string; - /** - * Gets or sets the character set used to encode the object. + /** + * Gets or sets the character set used to encode the object. */ readonly charset: string; - /** - * Gets a value that indicates whether standards-compliant mode is switched on for the object. + /** + * Gets a value that indicates whether standards-compliant mode is switched on for the object. */ readonly compatMode: string; /** @@ -4236,69 +4387,61 @@ interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, Par */ readonly contentType: string; /** - * Returns the HTTP cookies that apply to the Document. If there are no cookies or - * cookies can't be applied to this resource, the empty string will be returned. + * Returns the HTTP cookies that apply to the Document. If there are no cookies or cookies can't be applied to this resource, the empty string will be returned. + * * Can be set, to add a new cookie to the element's set of HTTP cookies. - * If the contents are sandboxed into a - * unique origin (e.g. in an iframe with the sandbox attribute), a - * "SecurityError" DOMException will be thrown on getting - * and setting. + * + * If the contents are sandboxed into a unique origin (e.g. in an iframe with the sandbox attribute), a "SecurityError" DOMException will be thrown on getting and setting. */ cookie: string; /** - * Returns the script element, or the SVG script element, - * that is currently executing, as long as the element represents a classic script. - * In the case of reentrant script execution, returns the one that most recently started executing - * amongst those that have not yet finished executing. - * Returns null if the Document is not currently executing a script - * or SVG script element (e.g., because the running script is an event - * handler, or a timeout), or if the currently executing script or SVG - * script element represents a module script. + * Returns the script element, or the SVG script element, that is currently executing, as long as the element represents a classic script. In the case of reentrant script execution, returns the one that most recently started executing amongst those that have not yet finished executing. + * + * Returns null if the Document is not currently executing a script or SVG script element (e.g., because the running script is an event handler, or a timeout), or if the currently executing script or SVG script element represents a module script. */ readonly currentScript: HTMLOrSVGScriptElement | null; readonly defaultView: WindowProxy | null; - /** - * Sets or gets a value that indicates whether the document can be edited. + /** + * Sets or gets a value that indicates whether the document can be edited. */ designMode: string; - /** - * Sets or retrieves a value that indicates the reading order of the object. + /** + * Sets or retrieves a value that indicates the reading order of the object. */ dir: string; - /** - * Gets an object representing the document type declaration associated with the current document. + /** + * Gets an object representing the document type declaration associated with the current document. */ readonly doctype: DocumentType | null; - /** - * Gets a reference to the root node of the document. + /** + * Gets a reference to the root node of the document. */ readonly documentElement: HTMLElement; /** * Returns document's URL. */ readonly documentURI: string; - /** - * Sets or gets the security domain of the document. + /** + * Sets or gets the security domain of the document. */ domain: string; - /** - * Retrieves a collection of all embed objects in the document. + /** + * Retrieves a collection of all embed objects in the document. */ readonly embeds: HTMLCollectionOf; - /** - * Sets or gets the foreground (text) color of the document. + /** + * Sets or gets the foreground (text) color of the document. */ /** @deprecated */ fgColor: string; - /** - * Retrieves a collection, in source order, of all form objects in the document. + /** + * Retrieves a collection, in source order, of all form objects in the document. */ readonly forms: HTMLCollectionOf; /** @deprecated */ readonly fullscreen: boolean; /** - * Returns true if document has the ability to display elements fullscreen - * and fullscreen is supported, or false otherwise. + * Returns true if document has the ability to display elements fullscreen and fullscreen is supported, or false otherwise. */ readonly fullscreenEnabled: boolean; /** @@ -4306,42 +4449,42 @@ interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, Par */ readonly head: HTMLHeadElement; readonly hidden: boolean; - /** - * Retrieves a collection, in source order, of img objects in the document. + /** + * Retrieves a collection, in source order, of img objects in the document. */ readonly images: HTMLCollectionOf; - /** - * Gets the implementation object of the current document. + /** + * Gets the implementation object of the current document. */ readonly implementation: DOMImplementation; - /** - * Returns the character encoding used to create the webpage that is loaded into the document object. + /** + * Returns the character encoding used to create the webpage that is loaded into the document object. */ readonly inputEncoding: string; - /** - * Gets the date that the page was last modified, if the page supplies one. + /** + * Gets the date that the page was last modified, if the page supplies one. */ readonly lastModified: string; - /** - * Sets or gets the color of the document links. + /** + * Sets or gets the color of the document links. */ /** @deprecated */ linkColor: string; - /** - * Retrieves a collection of all a objects that specify the href property and all area objects in the document. + /** + * Retrieves a collection of all a objects that specify the href property and all area objects in the document. */ readonly links: HTMLCollectionOf; - /** - * Contains information about the current URL. + /** + * Contains information about the current URL. */ location: Location; onfullscreenchange: ((this: Document, ev: Event) => any) | null; onfullscreenerror: ((this: Document, ev: Event) => any) | null; onpointerlockchange: ((this: Document, ev: Event) => any) | null; onpointerlockerror: ((this: Document, ev: Event) => any) | null; - /** - * Fires when the state of the object has changed. - * @param ev The event + /** + * Fires when the state of the object has changed. + * @param ev The event */ onreadystatechange: ((this: Document, ev: ProgressEvent) => any) | null; onvisibilitychange: ((this: Document, ev: Event) => any) | null; @@ -4353,34 +4496,34 @@ interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, Par * Return an HTMLCollection of the embed elements in the Document. */ readonly plugins: HTMLCollectionOf; - /** - * Retrieves a value that indicates the current state of the object. + /** + * Retrieves a value that indicates the current state of the object. */ readonly readyState: DocumentReadyState; - /** - * Gets the URL of the location that referred the user to the current page. + /** + * Gets the URL of the location that referred the user to the current page. */ readonly referrer: string; - /** - * Retrieves a collection of all script objects in the document. + /** + * Retrieves a collection of all script objects in the document. */ readonly scripts: HTMLCollectionOf; readonly scrollingElement: Element | null; readonly timeline: DocumentTimeline; - /** - * Contains the title of the document. + /** + * Contains the title of the document. */ title: string; readonly visibilityState: VisibilityState; - /** - * Sets or gets the color of the links that the user has visited. + /** + * Sets or gets the color of the links that the user has visited. */ /** @deprecated */ vlinkColor: string; /** * Moves node from another document and returns it. - * If node is a document, throws a "NotSupportedError" DOMException or, if node is a shadow root, throws a - * "HierarchyRequestError" DOMException. + * + * If node is a document, throws a "NotSupportedError" DOMException or, if node is a shadow root, throws a "HierarchyRequestError" DOMException. */ adoptNode(source: T): T; /** @deprecated */ @@ -4390,13 +4533,13 @@ interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, Par caretRangeFromPoint(x: number, y: number): Range; /** @deprecated */ clear(): void; - /** - * Closes an output stream and forces the sent data to display. + /** + * Closes an output stream and forces the sent data to display. */ close(): void; - /** - * Creates an attribute object with a specified name. - * @param name String that sets the attribute object's name. + /** + * Creates an attribute object with a specified name. + * @param name String that sets the attribute object's name. */ createAttribute(localName: string): Attr; createAttributeNS(namespace: string | null, qualifiedName: string): Attr; @@ -4404,35 +4547,36 @@ interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, Par * Returns a CDATASection node whose data is data. */ createCDATASection(data: string): CDATASection; - /** - * Creates a comment object with the specified data. - * @param data Sets the comment object's data. + /** + * Creates a comment object with the specified data. + * @param data Sets the comment object's data. */ createComment(data: string): Comment; - /** - * Creates a new document. + /** + * Creates a new document. */ createDocumentFragment(): DocumentFragment; - /** - * Creates an instance of the element for the specified tag. - * @param tagName The name of an element. + /** + * Creates an instance of the element for the specified tag. + * @param tagName The name of an element. */ createElement(tagName: K, options?: ElementCreationOptions): HTMLElementTagNameMap[K]; /** @deprecated */ createElement(tagName: K, options?: ElementCreationOptions): HTMLElementDeprecatedTagNameMap[K]; createElement(tagName: string, options?: ElementCreationOptions): HTMLElement; /** - * Returns an element with namespace namespace. Its namespace prefix will be everything before ":" (U+003E) in qualifiedName or null. Its local name will be everything after - * ":" (U+003E) in qualifiedName or qualifiedName. - * If localName does not match the Name production an - * "InvalidCharacterError" DOMException will be thrown. + * Returns an element with namespace namespace. Its namespace prefix will be everything before ":" (U+003E) in qualifiedName or null. Its local name will be everything after ":" (U+003E) in qualifiedName or qualifiedName. + * + * If localName does not match the Name production an "InvalidCharacterError" DOMException will be thrown. + * * If one of the following conditions is true a "NamespaceError" DOMException will be thrown: + * * localName does not match the QName production. * Namespace prefix is not null and namespace is the empty string. * Namespace prefix is "xml" and namespace is not the XML namespace. * qualifiedName or namespace prefix is "xmlns" and namespace is not the XMLNS namespace. - * namespace is the XMLNS namespace and - * neither qualifiedName nor namespace prefix is "xmlns". + * namespace is the XMLNS namespace and neither qualifiedName nor namespace prefix is "xmlns". + * * When supplied, options's is can be used to create a customized built-in element. */ createElementNS(namespaceURI: "http://www.w3.org/1999/xhtml", qualifiedName: string): HTMLElement; @@ -4455,11 +4599,13 @@ interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, Par createEvent(eventInterface: "ErrorEvent"): ErrorEvent; createEvent(eventInterface: "Event"): Event; createEvent(eventInterface: "Events"): Event; + createEvent(eventInterface: "FileReaderProgressEvent"): FileReaderProgressEvent; createEvent(eventInterface: "FocusEvent"): FocusEvent; createEvent(eventInterface: "FocusNavigationEvent"): FocusNavigationEvent; createEvent(eventInterface: "GamepadEvent"): GamepadEvent; createEvent(eventInterface: "HashChangeEvent"): HashChangeEvent; createEvent(eventInterface: "IDBVersionChangeEvent"): IDBVersionChangeEvent; + createEvent(eventInterface: "InputEvent"): InputEvent; createEvent(eventInterface: "KeyboardEvent"): KeyboardEvent; createEvent(eventInterface: "ListeningStateChangedEvent"): ListeningStateChangedEvent; createEvent(eventInterface: "MSGestureEvent"): MSGestureEvent; @@ -4518,152 +4664,147 @@ interface Document extends Node, NonElementParentNode, DocumentOrShadowRoot, Par createEvent(eventInterface: "WebGLContextEvent"): WebGLContextEvent; createEvent(eventInterface: "WheelEvent"): WheelEvent; createEvent(eventInterface: string): Event; - /** - * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document. - * @param root The root element or node to start traversing on. - * @param whatToShow The type of nodes or elements to appear in the node list - * @param filter A custom NodeFilter function to use. For more information, see filter. Use null for no filter. - * @param entityReferenceExpansion A flag that specifies whether entity reference nodes are expanded. + /** + * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document. + * @param root The root element or node to start traversing on. + * @param whatToShow The type of nodes or elements to appear in the node list + * @param filter A custom NodeFilter function to use. For more information, see filter. Use null for no filter. + * @param entityReferenceExpansion A flag that specifies whether entity reference nodes are expanded. */ createNodeIterator(root: Node, whatToShow?: number, filter?: NodeFilter | null): NodeIterator; /** - * Returns a ProcessingInstruction node whose target is target and data is data. - * If target does not match the Name production an - * "InvalidCharacterError" DOMException will be thrown. - * If data contains "?>" an - * "InvalidCharacterError" DOMException will be thrown. + * Returns a ProcessingInstruction node whose target is target and data is data. If target does not match the Name production an "InvalidCharacterError" DOMException will be thrown. If data contains "?>" an "InvalidCharacterError" DOMException will be thrown. */ createProcessingInstruction(target: string, data: string): ProcessingInstruction; - /** - * Returns an empty range object that has both of its boundary points positioned at the beginning of the document. + /** + * Returns an empty range object that has both of its boundary points positioned at the beginning of the document. */ createRange(): Range; - /** - * Creates a text string from the specified value. - * @param data String that specifies the nodeValue property of the text node. + /** + * Creates a text string from the specified value. + * @param data String that specifies the nodeValue property of the text node. */ createTextNode(data: string): Text; - createTouch(view: WindowProxy, target: EventTarget, identifier: number, pageX: number, pageY: number, screenX: number, screenY: number): Touch; - createTouchList(...touches: Touch[]): TouchList; - /** - * Creates a TreeWalker object that you can use to traverse filtered lists of nodes or elements in a document. - * @param root The root element or node to start traversing on. - * @param whatToShow The type of nodes or elements to appear in the node list. For more information, see whatToShow. - * @param filter A custom NodeFilter function to use. - * @param entityReferenceExpansion A flag that specifies whether entity reference nodes are expanded. + /** + * Creates a TreeWalker object that you can use to traverse filtered lists of nodes or elements in a document. + * @param root The root element or node to start traversing on. + * @param whatToShow The type of nodes or elements to appear in the node list. For more information, see whatToShow. + * @param filter A custom NodeFilter function to use. + * @param entityReferenceExpansion A flag that specifies whether entity reference nodes are expanded. */ createTreeWalker(root: Node, whatToShow?: number, filter?: NodeFilter | null): TreeWalker; /** @deprecated */ createTreeWalker(root: Node, whatToShow: number, filter: NodeFilter | null, entityReferenceExpansion?: boolean): TreeWalker; - /** - * Returns the element for the specified x coordinate and the specified y coordinate. - * @param x The x-offset - * @param y The y-offset + /** + * Returns the element for the specified x coordinate and the specified y coordinate. + * @param x The x-offset + * @param y The y-offset */ elementFromPoint(x: number, y: number): Element | null; elementsFromPoint(x: number, y: number): Element[]; - /** - * Executes a command on the current document, current selection, or the given range. - * @param commandId String that specifies the command to execute. This command can be any of the command identifiers that can be executed in script. - * @param showUI Display the user interface, defaults to false. - * @param value Value to assign. + /** + * Executes a command on the current document, current selection, or the given range. + * @param commandId String that specifies the command to execute. This command can be any of the command identifiers that can be executed in script. + * @param showUI Display the user interface, defaults to false. + * @param value Value to assign. */ execCommand(commandId: string, showUI?: boolean, value?: string): boolean; /** - * Stops document's fullscreen element from being displayed fullscreen and - * resolves promise when done. + * Stops document's fullscreen element from being displayed fullscreen and resolves promise when done. */ exitFullscreen(): Promise; exitPointerLock(): void; getAnimations(): Animation[]; - /** - * Returns a reference to the first object with the specified value of the ID or NAME attribute. - * @param elementId String that specifies the ID value. Case-insensitive. + /** + * Returns a reference to the first object with the specified value of the ID or NAME attribute. + * @param elementId String that specifies the ID value. Case-insensitive. */ getElementById(elementId: string): HTMLElement | null; /** - * collection = element . getElementsByClassName(classNames) + * Returns a HTMLCollection of the elements in the object on which the method was invoked (a document or an element) that have all the classes given by classNames. The classNames argument is interpreted as a space-separated list of classes. */ getElementsByClassName(classNames: string): HTMLCollectionOf; - /** - * Gets a collection of objects based on the value of the NAME or ID attribute. - * @param elementName Gets a collection of objects based on the value of the NAME or ID attribute. + /** + * Gets a collection of objects based on the value of the NAME or ID attribute. + * @param elementName Gets a collection of objects based on the value of the NAME or ID attribute. */ getElementsByName(elementName: string): NodeListOf; - /** - * Retrieves a collection of objects based on the specified element name. - * @param name Specifies the name of an element. + /** + * Retrieves a collection of objects based on the specified element name. + * @param name Specifies the name of an element. */ getElementsByTagName(qualifiedName: K): HTMLCollectionOf; getElementsByTagName(qualifiedName: K): HTMLCollectionOf; getElementsByTagName(qualifiedName: string): HTMLCollectionOf; /** - * If namespace and localName are - * "*" returns a HTMLCollection of all descendant elements. + * If namespace and localName are "*" returns a HTMLCollection of all descendant elements. + * * If only namespace is "*" returns a HTMLCollection of all descendant elements whose local name is localName. + * * If only localName is "*" returns a HTMLCollection of all descendant elements whose namespace is namespace. + * * Otherwise, returns a HTMLCollection of all descendant elements whose namespace is namespace and local name is localName. */ getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollectionOf; getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollectionOf; getElementsByTagNameNS(namespaceURI: string, localName: string): HTMLCollectionOf; - /** - * Returns an object representing the current selection of the document that is loaded into the object displaying a webpage. + /** + * Returns an object representing the current selection of the document that is loaded into the object displaying a webpage. */ getSelection(): Selection | null; - /** - * Gets a value indicating whether the object currently has focus. + /** + * Gets a value indicating whether the object currently has focus. */ hasFocus(): boolean; /** * Returns a copy of node. If deep is true, the copy also includes the node's descendants. - * If node is a document or a shadow root, throws a - * "NotSupportedError" DOMException. + * + * If node is a document or a shadow root, throws a "NotSupportedError" DOMException. */ importNode(importedNode: T, deep: boolean): T; - /** - * Opens a new window and loads a document specified by a given URL. Also, opens a new window that uses the url parameter and the name parameter to collect the output of the write method and the writeln method. - * @param url Specifies a MIME type for the document. - * @param name Specifies the name of the window. This name is used as the value for the TARGET attribute on a form or an anchor element. - * @param features Contains a list of items separated by commas. Each item consists of an option and a value, separated by an equals sign (for example, "fullscreen=yes, toolbar=yes"). The following values are supported. - * @param replace Specifies whether the existing entry for the document is replaced in the history list. + /** + * Opens a new window and loads a document specified by a given URL. Also, opens a new window that uses the url parameter and the name parameter to collect the output of the write method and the writeln method. + * @param url Specifies a MIME type for the document. + * @param name Specifies the name of the window. This name is used as the value for the TARGET attribute on a form or an anchor element. + * @param features Contains a list of items separated by commas. Each item consists of an option and a value, separated by an equals sign (for example, "fullscreen=yes, toolbar=yes"). The following values are supported. + * @param replace Specifies whether the existing entry for the document is replaced in the history list. */ open(url?: string, name?: string, features?: string, replace?: boolean): Document; - /** - * Returns a Boolean value that indicates whether a specified command can be successfully executed using execCommand, given the current state of the document. - * @param commandId Specifies a command identifier. + /** + * Returns a Boolean value that indicates whether a specified command can be successfully executed using execCommand, given the current state of the document. + * @param commandId Specifies a command identifier. */ queryCommandEnabled(commandId: string): boolean; - /** - * Returns a Boolean value that indicates whether the specified command is in the indeterminate state. - * @param commandId String that specifies a command identifier. + /** + * Returns a Boolean value that indicates whether the specified command is in the indeterminate state. + * @param commandId String that specifies a command identifier. */ queryCommandIndeterm(commandId: string): boolean; - /** - * Returns a Boolean value that indicates the current state of the command. - * @param commandId String that specifies a command identifier. + /** + * Returns a Boolean value that indicates the current state of the command. + * @param commandId String that specifies a command identifier. */ queryCommandState(commandId: string): boolean; - /** - * Returns a Boolean value that indicates whether the current command is supported on the current range. - * @param commandId Specifies a command identifier. + /** + * Returns a Boolean value that indicates whether the current command is supported on the current range. + * @param commandId Specifies a command identifier. */ queryCommandSupported(commandId: string): boolean; - /** - * Returns the current value of the document, range, or current selection for the given command. - * @param commandId String that specifies a command identifier. + /** + * Returns the current value of the document, range, or current selection for the given command. + * @param commandId String that specifies a command identifier. */ queryCommandValue(commandId: string): string; /** @deprecated */ releaseEvents(): void; - /** - * Writes one or more HTML expressions to a document in the specified window. - * @param content Specifies the text and HTML tags to write. + /** + * Writes one or more HTML expressions to a document in the specified window. + * @param content Specifies the text and HTML tags to write. */ write(...text: string[]): void; - /** - * Writes one or more HTML expressions, followed by a carriage return, to a document in the specified window. - * @param content The text and HTML tags to write. + /** + * Writes one or more HTML expressions, followed by a carriage return, to a document in the specified window. + * @param content The text and HTML tags to write. */ writeln(...text: string[]): void; addEventListener(type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; @@ -4709,11 +4850,13 @@ interface DocumentEvent { createEvent(eventInterface: "ErrorEvent"): ErrorEvent; createEvent(eventInterface: "Event"): Event; createEvent(eventInterface: "Events"): Event; + createEvent(eventInterface: "FileReaderProgressEvent"): FileReaderProgressEvent; createEvent(eventInterface: "FocusEvent"): FocusEvent; createEvent(eventInterface: "FocusNavigationEvent"): FocusNavigationEvent; createEvent(eventInterface: "GamepadEvent"): GamepadEvent; createEvent(eventInterface: "HashChangeEvent"): HashChangeEvent; createEvent(eventInterface: "IDBVersionChangeEvent"): IDBVersionChangeEvent; + createEvent(eventInterface: "InputEvent"): InputEvent; createEvent(eventInterface: "KeyboardEvent"): KeyboardEvent; createEvent(eventInterface: "ListeningStateChangedEvent"): ListeningStateChangedEvent; createEvent(eventInterface: "MSGestureEvent"): MSGestureEvent; @@ -4786,10 +4929,13 @@ declare var DocumentFragment: { interface DocumentOrShadowRoot { readonly activeElement: Element | null; + /** + * Returns document's fullscreen element. + */ readonly fullscreenElement: Element | null; readonly pointerLockElement: Element | null; - /** - * Retrieves a collection of styleSheet objects representing the style sheets that correspond to each instance of a link or style object in the document. + /** + * Retrieves a collection of styleSheet objects representing the style sheets that correspond to each instance of a link or style object in the document. */ readonly styleSheets: StyleSheetList; caretPositionFromPoint(x: number, y: number): CaretPosition | null; @@ -4883,13 +5029,11 @@ interface Element extends Node, ParentNode, NonDocumentTypeChildNode, ChildNode, readonly assignedSlot: HTMLSlotElement | null; readonly attributes: NamedNodeMap; /** - * Allows for manipulation of element's class content attribute as a - * set of whitespace-separated tokens through a DOMTokenList object. + * Allows for manipulation of element's class content attribute as a set of whitespace-separated tokens through a DOMTokenList object. */ readonly classList: DOMTokenList; /** - * Returns the value of element's class content attribute. Can be set - * to change it. + * Returns the value of element's class content attribute. Can be set to change it. */ className: string; readonly clientHeight: number; @@ -4897,8 +5041,7 @@ interface Element extends Node, ParentNode, NonDocumentTypeChildNode, ChildNode, readonly clientTop: number; readonly clientWidth: number; /** - * Returns the value of element's id content attribute. Can be set to - * change it. + * Returns the value of element's id content attribute. Can be set to change it. */ id: string; /** @@ -4925,8 +5068,7 @@ interface Element extends Node, ParentNode, NonDocumentTypeChildNode, ChildNode, */ readonly shadowRoot: ShadowRoot | null; /** - * Returns the value of element's slot content attribute. Can be set to - * change it. + * Returns the value of element's slot content attribute. Can be set to change it. */ slot: string; /** @@ -4942,25 +5084,26 @@ interface Element extends Node, ParentNode, NonDocumentTypeChildNode, ChildNode, */ closest(selector: K): HTMLElementTagNameMap[K] | null; closest(selector: K): SVGElementTagNameMap[K] | null; - closest(selector: string): Element | null; + closest(selector: string): E | null; /** * Returns element's first attribute whose qualified name is qualifiedName, and null if there is no such attribute otherwise. */ getAttribute(qualifiedName: string): string | null; /** - * Returns element's attribute whose namespace is namespace and local name is localName, and null if there is - * no such attribute otherwise. + * Returns element's attribute whose namespace is namespace and local name is localName, and null if there is no such attribute otherwise. */ getAttributeNS(namespace: string | null, localName: string): string | null; /** - * Returns the qualified names of all element's attributes. - * Can contain duplicates. + * Returns the qualified names of all element's attributes. Can contain duplicates. */ getAttributeNames(): string[]; getAttributeNode(name: string): Attr | null; getAttributeNodeNS(namespaceURI: string, localName: string): Attr | null; getBoundingClientRect(): ClientRect | DOMRect; getClientRects(): ClientRectList | DOMRectList; + /** + * Returns a HTMLCollection of the elements in the object on which the method was invoked (a document or an element) that have all the classes given by classNames. The classNames argument is interpreted as a space-separated list of classes. + */ getElementsByClassName(classNames: string): HTMLCollectionOf; getElementsByTagName(qualifiedName: K): HTMLCollectionOf; getElementsByTagName(qualifiedName: K): HTMLCollectionOf; @@ -5001,11 +5144,8 @@ interface Element extends Node, ParentNode, NonDocumentTypeChildNode, ChildNode, removeAttributeNode(attr: Attr): Attr; /** * Displays element fullscreen and resolves promise when done. - * When supplied, options's navigationUI member indicates whether showing - * navigation UI while in fullscreen is preferred or not. If set to "show", navigation - * simplicity is preferred over screen space, and if set to "hide", more screen space - * is preferred. User agents are always free to honor user preference over the application's. The - * default value "auto" indicates no application preference. + * + * When supplied, options's navigationUI member indicates whether showing navigation UI while in fullscreen is preferred or not. If set to "show", navigation simplicity is preferred over screen space, and if set to "hide", more screen space is preferred. User agents are always free to honor user preference over the application's. The default value "auto" indicates no application preference. */ requestFullscreen(options?: FullscreenOptions): Promise; requestPointerLock(): void; @@ -5028,8 +5168,8 @@ interface Element extends Node, ParentNode, NonDocumentTypeChildNode, ChildNode, setAttributeNodeNS(attr: Attr): Attr | null; setPointerCapture(pointerId: number): void; /** - * If force is not given, "toggles" qualifiedName, removing it if it is - * present and adding it if it is not present. If force is true, adds qualifiedName. If force is false, removes qualifiedName. + * If force is not given, "toggles" qualifiedName, removing it if it is present and adding it if it is not present. If force is true, adds qualifiedName. If force is false, removes qualifiedName. + * * Returns true if qualifiedName is now present, and false otherwise. */ toggleAttribute(qualifiedName: string, force?: boolean): boolean; @@ -5076,21 +5216,28 @@ interface Event { */ readonly bubbles: boolean; cancelBubble: boolean; + /** + * Returns true or false depending on how event was initialized. Its return value does not always carry meaning, but true can indicate that part of the operation during which event was dispatched, can be canceled by invoking the preventDefault() method. + */ readonly cancelable: boolean; /** * Returns true or false depending on how event was initialized. True if event invokes listeners past a ShadowRoot node that is the root of its target, and false otherwise. */ readonly composed: boolean; /** - * Returns the object whose event listener's callback is currently being - * invoked. + * Returns the object whose event listener's callback is currently being invoked. */ readonly currentTarget: EventTarget | null; + /** + * Returns true if preventDefault() was invoked successfully to indicate cancelation, and false otherwise. + */ readonly defaultPrevented: boolean; + /** + * Returns the event's phase, which is one of NONE, CAPTURING_PHASE, AT_TARGET, and BUBBLING_PHASE. + */ readonly eventPhase: number; /** - * Returns true if event was dispatched by the user agent, and - * false otherwise. + * Returns true if event was dispatched by the user agent, and false otherwise. */ readonly isTrusted: boolean; returnValue: boolean; @@ -5101,23 +5248,24 @@ interface Event { */ readonly target: EventTarget | null; /** - * Returns the event's timestamp as the number of milliseconds measured relative to - * the time origin. + * Returns the event's timestamp as the number of milliseconds measured relative to the time origin. */ readonly timeStamp: number; /** - * Returns the type of event, e.g. - * "click", "hashchange", or - * "submit". + * Returns the type of event, e.g. "click", "hashchange", or "submit". */ readonly type: string; + /** + * Returns the item objects of event's path (objects on which listeners will be invoked), except for any nodes in shadow trees of which the shadow root's mode is "closed" that are not reachable from event's currentTarget. + */ composedPath(): EventTarget[]; initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void; + /** + * If invoked when the cancelable attribute value is true, and while executing a listener for the event with passive set to false, signals to the operation that caused event to be dispatched that it needs to be canceled. + */ preventDefault(): void; /** - * Invoking this method prevents event from reaching - * any registered event listeners after the current one finishes running and, when dispatched in a tree, also prevents event from reaching any - * other objects. + * Invoking this method prevents event from reaching any registered event listeners after the current one finishes running and, when dispatched in a tree, also prevents event from reaching any other objects. */ stopImmediatePropagation(): void; /** @@ -5154,8 +5302,7 @@ interface EventSource extends EventTarget { onmessage: ((this: EventSource, ev: MessageEvent) => any) | null; onopen: ((this: EventSource, ev: Event) => any) | null; /** - * Returns the state of this EventSource object's connection. It can have the - * values described below. + * Returns the state of this EventSource object's connection. It can have the values described below. */ readonly readyState: number; /** @@ -5163,11 +5310,12 @@ interface EventSource extends EventTarget { */ readonly url: string; /** - * Returns true if the credentials mode - * for connection requests to the URL providing the - * event stream is set to "include", and false otherwise. + * Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise. */ readonly withCredentials: boolean; + /** + * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED. + */ close(): void; readonly CLOSED: number; readonly CONNECTING: number; @@ -5190,18 +5338,20 @@ declare var EventSource: { interface EventTarget { /** * Appends an event listener for events whose type attribute value is type. The callback argument sets the callback that will be invoked when the event is dispatched. - * The options argument sets listener-specific options. For compatibility this can be a - * boolean, in which case the method behaves exactly as if the value was specified as options's capture. + * + * The options argument sets listener-specific options. For compatibility this can be a boolean, in which case the method behaves exactly as if the value was specified as options's capture. + * * When set to true, options's capture prevents callback from being invoked when the event's eventPhase attribute value is BUBBLING_PHASE. When false (or not present), callback will not be invoked when event's eventPhase attribute value is CAPTURING_PHASE. Either way, callback will be invoked if event's eventPhase attribute value is AT_TARGET. + * * When set to true, options's passive indicates that the callback will not cancel the event by invoking preventDefault(). This is used to enable performance optimizations described in §2.8 Observing event listeners. - * When set to true, options's once indicates that the callback will only be invoked once after which the event listener will - * be removed. + * + * When set to true, options's once indicates that the callback will only be invoked once after which the event listener will be removed. + * * The event listener is appended to target's event listener list and is not appended if it has the same type, callback, and capture. */ addEventListener(type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void; /** - * Dispatches a synthetic event event to target and returns true - * if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. + * Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. */ dispatchEvent(event: Event): boolean; /** @@ -5239,6 +5389,11 @@ interface External { IsSearchProviderInstalled(): void; } +declare var External: { + prototype: External; + new(): External; +}; + /** Provides information about files and allows JavaScript in a web page to access their content. */ interface File extends Blob { readonly lastModified: number; @@ -5263,23 +5418,23 @@ declare var FileList: { }; interface FileReaderEventMap { - "abort": ProgressEvent; - "error": ProgressEvent; - "load": ProgressEvent; - "loadend": ProgressEvent; - "loadstart": ProgressEvent; - "progress": ProgressEvent; + "abort": FileReaderProgressEvent; + "error": FileReaderProgressEvent; + "load": FileReaderProgressEvent; + "loadend": FileReaderProgressEvent; + "loadstart": FileReaderProgressEvent; + "progress": FileReaderProgressEvent; } /** Lets web applications asynchronously read the contents of files (or raw data buffers) stored on the user's computer, using File or Blob objects to specify the file or data to read. */ interface FileReader extends EventTarget { readonly error: DOMException | null; - onabort: ((this: FileReader, ev: ProgressEvent) => any) | null; - onerror: ((this: FileReader, ev: ProgressEvent) => any) | null; - onload: ((this: FileReader, ev: ProgressEvent) => any) | null; - onloadend: ((this: FileReader, ev: ProgressEvent) => any) | null; - onloadstart: ((this: FileReader, ev: ProgressEvent) => any) | null; - onprogress: ((this: FileReader, ev: ProgressEvent) => any) | null; + onabort: ((this: FileReader, ev: FileReaderProgressEvent) => any) | null; + onerror: ((this: FileReader, ev: FileReaderProgressEvent) => any) | null; + onload: ((this: FileReader, ev: FileReaderProgressEvent) => any) | null; + onloadend: ((this: FileReader, ev: FileReaderProgressEvent) => any) | null; + onloadstart: ((this: FileReader, ev: FileReaderProgressEvent) => any) | null; + onprogress: ((this: FileReader, ev: FileReaderProgressEvent) => any) | null; readonly readyState: number; readonly result: string | ArrayBuffer | null; abort(): void; @@ -5304,15 +5459,18 @@ declare var FileReader: { readonly LOADING: number; }; +interface FileReaderProgressEvent extends ProgressEvent { + readonly target: FileReader | null; +} + /** Focus-related events like focus, blur, focusin, or focusout. */ interface FocusEvent extends UIEvent { - readonly relatedTarget: EventTarget; - initFocusEvent(typeArg: string, canBubbleArg: boolean, cancelableArg: boolean, viewArg: Window, detailArg: number, relatedTargetArg: EventTarget): void; + readonly relatedTarget: EventTarget | null; } declare var FocusEvent: { prototype: FocusEvent; - new(typeArg: string, eventInitDict?: FocusEventInit): FocusEvent; + new(type: string, eventInitDict?: FocusEventInit): FocusEvent; }; interface FocusNavigationEvent extends Event { @@ -5355,7 +5513,7 @@ declare var GainNode: { new(context: BaseAudioContext, options?: GainOptions): GainNode; }; -/** An interface of the Gamepad API defines an individual gamepad or other controller, allowing access to information such as button presses, axis positions, and id. */ +/** This Gamepad API interface defines an individual gamepad or other controller, allowing access to information such as button presses, axis positions, and id. */ interface Gamepad { readonly axes: ReadonlyArray; readonly buttons: ReadonlyArray; @@ -5386,7 +5544,7 @@ declare var GamepadButton: { new(): GamepadButton; }; -/** An interface of the Gamepad API contains references to gamepads connected to the system, which is what the gamepad events Window.gamepadconnected and Window.gamepaddisconnected are fired in response to. */ +/** This Gamepad API interface contains references to gamepads connected to the system, which is what the gamepad events Window.gamepadconnected and Window.gamepaddisconnected are fired in response to. */ interface GamepadEvent extends Event { readonly gamepad: Gamepad; } @@ -5396,7 +5554,7 @@ declare var GamepadEvent: { new(type: string, eventInitDict: GamepadEventInit): GamepadEvent; }; -/** An interface of the Gamepad API represents hardware in the controller designed to provide haptic feedback to the user (if available), most commonly vibration hardware. */ +/** This Gamepad API interface represents hardware in the controller designed to provide haptic feedback to the user (if available), most commonly vibration hardware. */ interface GamepadHapticActuator { readonly type: GamepadHapticActuatorType; pulse(value: number, duration: number): Promise; @@ -5407,7 +5565,7 @@ declare var GamepadHapticActuator: { new(): GamepadHapticActuator; }; -/** An interface of the Gamepad API represents the pose of a WebVR controller at a given timestamp (which includes orientation, position, velocity, and acceleration information.) */ +/** This Gamepad API interface represents the pose of a WebVR controller at a given timestamp (which includes orientation, position, velocity, and acceleration information.) */ interface GamepadPose { readonly angularAcceleration: Float32Array | null; readonly angularVelocity: Float32Array | null; @@ -5425,13 +5583,23 @@ declare var GamepadPose: { }; interface GenericTransformStream { + /** + * Returns a readable stream whose chunks are strings resulting from running encoding's decoder on the chunks written to writable. + */ readonly readable: ReadableStream; /** - * Returns a writable stream which accepts string chunks and runs them through UTF-8's encoder before making them available to readable. + * Returns a writable stream which accepts BufferSource chunks and runs them through encoding's decoder before making them available to readable. + * * Typically this will be used via the pipeThrough() method on a ReadableStream source. - * textReadable - * .pipeThrough(new TextEncoderStream()) - * .pipeTo(byteWritable); + * + * ``` + * var decoder = new TextDecoderStream(encoding); + * byteReadable + * .pipeThrough(decoder) + * .pipeTo(textWritable); + * ``` + * + * If the error mode is "fatal" and encoding's decoder returns error, both readable and writable will be errored with a TypeError. */ readonly writable: WritableStream; } @@ -5473,6 +5641,8 @@ interface GlobalEventHandlersEventMap { "ended": Event; "error": ErrorEvent; "focus": FocusEvent; + "focusin": FocusEvent; + "focusout": FocusEvent; "gotpointercapture": PointerEvent; "input": Event; "invalid": Event; @@ -5533,9 +5703,9 @@ interface GlobalEventHandlersEventMap { } interface GlobalEventHandlers { - /** - * Fires when the user aborts the download. - * @param ev The event. + /** + * Fires when the user aborts the download. + * @param ev The event. */ onabort: ((this: GlobalEventHandlers, ev: UIEvent) => any) | null; onanimationcancel: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null; @@ -5543,177 +5713,177 @@ interface GlobalEventHandlers { onanimationiteration: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null; onanimationstart: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null; onauxclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; - /** - * Fires when the object loses the input focus. - * @param ev The focus event. + /** + * Fires when the object loses the input focus. + * @param ev The focus event. */ onblur: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null; oncancel: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Occurs when playback is possible, but would require further buffering. - * @param ev The event. + /** + * Occurs when playback is possible, but would require further buffering. + * @param ev The event. */ oncanplay: ((this: GlobalEventHandlers, ev: Event) => any) | null; oncanplaythrough: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Fires when the contents of the object or selection have changed. - * @param ev The event. + /** + * Fires when the contents of the object or selection have changed. + * @param ev The event. */ onchange: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Fires when the user clicks the left mouse button on the object - * @param ev The mouse event. + /** + * Fires when the user clicks the left mouse button on the object + * @param ev The mouse event. */ onclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; onclose: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Fires when the user clicks the right mouse button in the client area, opening the context menu. - * @param ev The mouse event. + /** + * Fires when the user clicks the right mouse button in the client area, opening the context menu. + * @param ev The mouse event. */ oncontextmenu: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; oncuechange: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Fires when the user double-clicks the object. - * @param ev The mouse event. + /** + * Fires when the user double-clicks the object. + * @param ev The mouse event. */ ondblclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; - /** - * Fires on the source object continuously during a drag operation. - * @param ev The event. + /** + * Fires on the source object continuously during a drag operation. + * @param ev The event. */ ondrag: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; - /** - * Fires on the source object when the user releases the mouse at the close of a drag operation. - * @param ev The event. + /** + * Fires on the source object when the user releases the mouse at the close of a drag operation. + * @param ev The event. */ ondragend: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; - /** - * Fires on the target element when the user drags the object to a valid drop target. - * @param ev The drag event. + /** + * Fires on the target element when the user drags the object to a valid drop target. + * @param ev The drag event. */ ondragenter: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; ondragexit: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Fires on the target object when the user moves the mouse out of a valid drop target during a drag operation. - * @param ev The drag event. + /** + * Fires on the target object when the user moves the mouse out of a valid drop target during a drag operation. + * @param ev The drag event. */ ondragleave: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; - /** - * Fires on the target element continuously while the user drags the object over a valid drop target. - * @param ev The event. + /** + * Fires on the target element continuously while the user drags the object over a valid drop target. + * @param ev The event. */ ondragover: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; - /** - * Fires on the source object when the user starts to drag a text selection or selected object. - * @param ev The event. + /** + * Fires on the source object when the user starts to drag a text selection or selected object. + * @param ev The event. */ ondragstart: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; ondrop: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null; - /** - * Occurs when the duration attribute is updated. - * @param ev The event. + /** + * Occurs when the duration attribute is updated. + * @param ev The event. */ ondurationchange: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Occurs when the media element is reset to its initial state. - * @param ev The event. + /** + * Occurs when the media element is reset to its initial state. + * @param ev The event. */ onemptied: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Occurs when the end of playback is reached. - * @param ev The event + /** + * Occurs when the end of playback is reached. + * @param ev The event */ onended: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Fires when an error occurs during object loading. - * @param ev The event. + /** + * Fires when an error occurs during object loading. + * @param ev The event. */ onerror: OnErrorEventHandler; - /** - * Fires when the object receives focus. - * @param ev The event. + /** + * Fires when the object receives focus. + * @param ev The event. */ onfocus: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null; ongotpointercapture: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; oninput: ((this: GlobalEventHandlers, ev: Event) => any) | null; oninvalid: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Fires when the user presses a key. - * @param ev The keyboard event + /** + * Fires when the user presses a key. + * @param ev The keyboard event */ onkeydown: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null; - /** - * Fires when the user presses an alphanumeric key. - * @param ev The event. + /** + * Fires when the user presses an alphanumeric key. + * @param ev The event. */ onkeypress: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null; - /** - * Fires when the user releases a key. - * @param ev The keyboard event + /** + * Fires when the user releases a key. + * @param ev The keyboard event */ onkeyup: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null; - /** - * Fires immediately after the browser loads the object. - * @param ev The event. + /** + * Fires immediately after the browser loads the object. + * @param ev The event. */ onload: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Occurs when media data is loaded at the current playback position. - * @param ev The event. + /** + * Occurs when media data is loaded at the current playback position. + * @param ev The event. */ onloadeddata: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Occurs when the duration and dimensions of the media have been determined. - * @param ev The event. + /** + * Occurs when the duration and dimensions of the media have been determined. + * @param ev The event. */ onloadedmetadata: ((this: GlobalEventHandlers, ev: Event) => any) | null; onloadend: ((this: GlobalEventHandlers, ev: ProgressEvent) => any) | null; - /** - * Occurs when Internet Explorer begins looking for media data. - * @param ev The event. + /** + * Occurs when Internet Explorer begins looking for media data. + * @param ev The event. */ onloadstart: ((this: GlobalEventHandlers, ev: Event) => any) | null; onlostpointercapture: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; - /** - * Fires when the user clicks the object with either mouse button. - * @param ev The mouse event. + /** + * Fires when the user clicks the object with either mouse button. + * @param ev The mouse event. */ onmousedown: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; onmouseenter: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; onmouseleave: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; - /** - * Fires when the user moves the mouse over the object. - * @param ev The mouse event. + /** + * Fires when the user moves the mouse over the object. + * @param ev The mouse event. */ onmousemove: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; - /** - * Fires when the user moves the mouse pointer outside the boundaries of the object. - * @param ev The mouse event. + /** + * Fires when the user moves the mouse pointer outside the boundaries of the object. + * @param ev The mouse event. */ onmouseout: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; - /** - * Fires when the user moves the mouse pointer into the object. - * @param ev The mouse event. + /** + * Fires when the user moves the mouse pointer into the object. + * @param ev The mouse event. */ onmouseover: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; - /** - * Fires when the user releases a mouse button while the mouse is over the object. - * @param ev The mouse event. + /** + * Fires when the user releases a mouse button while the mouse is over the object. + * @param ev The mouse event. */ onmouseup: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null; - /** - * Occurs when playback is paused. - * @param ev The event. + /** + * Occurs when playback is paused. + * @param ev The event. */ onpause: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Occurs when the play method is requested. - * @param ev The event. + /** + * Occurs when the play method is requested. + * @param ev The event. */ onplay: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Occurs when the audio or video has started playing. - * @param ev The event. + /** + * Occurs when the audio or video has started playing. + * @param ev The event. */ onplaying: ((this: GlobalEventHandlers, ev: Event) => any) | null; onpointercancel: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; @@ -5724,59 +5894,59 @@ interface GlobalEventHandlers { onpointerout: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; onpointerover: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; onpointerup: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null; - /** - * Occurs to indicate progress while downloading media data. - * @param ev The event. + /** + * Occurs to indicate progress while downloading media data. + * @param ev The event. */ onprogress: ((this: GlobalEventHandlers, ev: ProgressEvent) => any) | null; - /** - * Occurs when the playback rate is increased or decreased. - * @param ev The event. + /** + * Occurs when the playback rate is increased or decreased. + * @param ev The event. */ onratechange: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Fires when the user resets a form. - * @param ev The event. + /** + * Fires when the user resets a form. + * @param ev The event. */ onreset: ((this: GlobalEventHandlers, ev: Event) => any) | null; onresize: ((this: GlobalEventHandlers, ev: UIEvent) => any) | null; - /** - * Fires when the user repositions the scroll box in the scroll bar on the object. - * @param ev The event. + /** + * Fires when the user repositions the scroll box in the scroll bar on the object. + * @param ev The event. */ onscroll: ((this: GlobalEventHandlers, ev: Event) => any) | null; onsecuritypolicyviolation: ((this: GlobalEventHandlers, ev: SecurityPolicyViolationEvent) => any) | null; - /** - * Occurs when the seek operation ends. - * @param ev The event. + /** + * Occurs when the seek operation ends. + * @param ev The event. */ onseeked: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Occurs when the current playback position is moved. - * @param ev The event. + /** + * Occurs when the current playback position is moved. + * @param ev The event. */ onseeking: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Fires when the current selection changes. - * @param ev The event. + /** + * Fires when the current selection changes. + * @param ev The event. */ onselect: ((this: GlobalEventHandlers, ev: Event) => any) | null; onselectionchange: ((this: GlobalEventHandlers, ev: Event) => any) | null; onselectstart: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Occurs when the download has stopped. - * @param ev The event. + /** + * Occurs when the download has stopped. + * @param ev The event. */ onstalled: ((this: GlobalEventHandlers, ev: Event) => any) | null; onsubmit: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Occurs if the load operation has been intentionally halted. - * @param ev The event. + /** + * Occurs if the load operation has been intentionally halted. + * @param ev The event. */ onsuspend: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Occurs to indicate the current playback position. - * @param ev The event. + /** + * Occurs to indicate the current playback position. + * @param ev The event. */ ontimeupdate: ((this: GlobalEventHandlers, ev: Event) => any) | null; ontoggle: ((this: GlobalEventHandlers, ev: Event) => any) | null; @@ -5788,14 +5958,14 @@ interface GlobalEventHandlers { ontransitionend: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null; ontransitionrun: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null; ontransitionstart: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null; - /** - * Occurs when the volume is changed, or playback is muted or unmuted. - * @param ev The event. + /** + * Occurs when the volume is changed, or playback is muted or unmuted. + * @param ev The event. */ onvolumechange: ((this: GlobalEventHandlers, ev: Event) => any) | null; - /** - * Occurs when playback stops because the next frame of a video resource is not available. - * @param ev The event. + /** + * Occurs when playback stops because the next frame of a video resource is not available. + * @param ev The event. */ onwaiting: ((this: GlobalEventHandlers, ev: Event) => any) | null; onwheel: ((this: GlobalEventHandlers, ev: WheelEvent) => any) | null; @@ -5805,21 +5975,21 @@ interface GlobalEventHandlers { removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void; } -interface GlobalFetch { - fetch(input: RequestInfo, init?: RequestInit): Promise; -} - interface HTMLAllCollection { /** * Returns the number of elements in the collection. */ readonly length: number; /** - * element = collection(index) + * Returns the item with index index from the collection (determined by tree order). */ item(nameOrIndex?: string): HTMLCollection | Element | null; /** - * element = collection(name) + * Returns the item with ID or name name from the collection. + * + * If there are multiple matching items, then an HTMLCollection object containing all those elements is returned. + * + * Only button, form, iframe, input, map, meta, object, select, and textarea elements can have a name for the purpose of this method; their name is given by the value of their name attribute. */ namedItem(name: string): HTMLCollection | Element | null; [index: number]: Element; @@ -5832,49 +6002,49 @@ declare var HTMLAllCollection: { /** Hyperlink elements and provides special properties and methods (beyond those of the regular HTMLElement object interface that they inherit from) for manipulating the layout and presentation of such elements. */ interface HTMLAnchorElement extends HTMLElement, HTMLHyperlinkElementUtils { - /** - * Sets or retrieves the character set used to encode the object. + /** + * Sets or retrieves the character set used to encode the object. */ /** @deprecated */ charset: string; - /** - * Sets or retrieves the coordinates of the object. + /** + * Sets or retrieves the coordinates of the object. */ /** @deprecated */ coords: string; download: string; - /** - * Sets or retrieves the language code of the object. + /** + * Sets or retrieves the language code of the object. */ hreflang: string; - /** - * Sets or retrieves the shape of the object. + /** + * Sets or retrieves the shape of the object. */ /** @deprecated */ name: string; ping: string; referrerPolicy: string; - /** - * Sets or retrieves the relationship between the object and the destination of the link. + /** + * Sets or retrieves the relationship between the object and the destination of the link. */ rel: string; readonly relList: DOMTokenList; - /** - * Sets or retrieves the relationship between the object and the destination of the link. + /** + * Sets or retrieves the relationship between the object and the destination of the link. */ /** @deprecated */ rev: string; - /** - * Sets or retrieves the shape of the object. + /** + * Sets or retrieves the shape of the object. */ /** @deprecated */ shape: string; - /** - * Sets or retrieves the window or frame at which to target content. + /** + * Sets or retrieves the window or frame at which to target content. */ target: string; - /** - * Retrieves or sets the text of the object as a string. + /** + * Retrieves or sets the text of the object as a string. */ text: string; type: string; @@ -5892,33 +6062,33 @@ declare var HTMLAnchorElement: { interface HTMLAppletElement extends HTMLElement { /** @deprecated */ align: string; - /** - * Sets or retrieves a text alternative to the graphic. + /** + * Sets or retrieves a text alternative to the graphic. */ /** @deprecated */ alt: string; - /** - * Sets or retrieves a character string that can be used to implement your own archive functionality for the object. + /** + * Sets or retrieves a character string that can be used to implement your own archive functionality for the object. */ /** @deprecated */ archive: string; /** @deprecated */ code: string; - /** - * Sets or retrieves the URL of the component. + /** + * Sets or retrieves the URL of the component. */ /** @deprecated */ codeBase: string; readonly form: HTMLFormElement | null; - /** - * Sets or retrieves the height of the object. + /** + * Sets or retrieves the height of the object. */ /** @deprecated */ height: string; /** @deprecated */ hspace: number; - /** - * Sets or retrieves the shape of the object. + /** + * Sets or retrieves the shape of the object. */ /** @deprecated */ name: string; @@ -5941,17 +6111,17 @@ declare var HTMLAppletElement: { /** Provides special properties and methods (beyond those of the regular object HTMLElement interface it also has available to it by inheritance) for manipulating the layout and presentation of elements. */ interface HTMLAreaElement extends HTMLElement, HTMLHyperlinkElementUtils { - /** - * Sets or retrieves a text alternative to the graphic. + /** + * Sets or retrieves a text alternative to the graphic. */ alt: string; - /** - * Sets or retrieves the coordinates of the object. + /** + * Sets or retrieves the coordinates of the object. */ coords: string; download: string; - /** - * Sets or gets whether clicks in this region cause action. + /** + * Sets or gets whether clicks in this region cause action. */ /** @deprecated */ noHref: boolean; @@ -5959,12 +6129,12 @@ interface HTMLAreaElement extends HTMLElement, HTMLHyperlinkElementUtils { referrerPolicy: string; rel: string; readonly relList: DOMTokenList; - /** - * Sets or retrieves the shape of the object. + /** + * Sets or retrieves the shape of the object. */ shape: string; - /** - * Sets or retrieves the window or frame at which to target content. + /** + * Sets or retrieves the window or frame at which to target content. */ target: string; addEventListener(type: K, listener: (this: HTMLAreaElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; @@ -5993,8 +6163,8 @@ declare var HTMLAudioElement: { /** A HTML line break element (
). It inherits from HTMLElement. */ interface HTMLBRElement extends HTMLElement { - /** - * Sets or retrieves the side on which floating objects are not to be positioned when any IHTMLBlockElement is inserted into the document. + /** + * Sets or retrieves the side on which floating objects are not to be positioned when any IHTMLBlockElement is inserted into the document. */ /** @deprecated */ clear: string; @@ -6011,12 +6181,12 @@ declare var HTMLBRElement: { /** Contains the base URI for a document. This object inherits all of the properties and methods as described in the HTMLElement interface. */ interface HTMLBaseElement extends HTMLElement { - /** - * Gets or sets the baseline URL on which relative links are based. + /** + * Gets or sets the baseline URL on which relative links are based. */ href: string; - /** - * Sets or retrieves the window or frame at which to target content. + /** + * Sets or retrieves the window or frame at which to target content. */ target: string; addEventListener(type: K, listener: (this: HTMLBaseElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; @@ -6032,13 +6202,13 @@ declare var HTMLBaseElement: { /** Provides special properties (beyond the regular HTMLElement interface it also has available to it by inheritance) for manipulating elements. */ interface HTMLBaseFontElement extends HTMLElement, DOML2DeprecatedColorProperty { - /** - * Sets or retrieves the current typeface family. + /** + * Sets or retrieves the current typeface family. */ /** @deprecated */ face: string; - /** - * Sets or retrieves the font size of the object. + /** + * Sets or retrieves the font size of the object. */ /** @deprecated */ size: number; @@ -6089,68 +6259,68 @@ declare var HTMLBodyElement: { /** Provides properties and methods (beyond the regular HTMLElement interface it also has available to it by inheritance) for manipulating