diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 573a45b9f3b1d..2f4ea640c3967 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -819,6 +819,18 @@ namespace ts { return deduplicateSorted(sort(array, comparer), equalityComparer || comparer || compareStringsCaseSensitive as any as Comparer); } + export function arrayIsSorted(array: readonly T[], comparer: Comparer) { + if (array.length < 2) return true; + let prevElement = array[0]; + for (const element of array.slice(1)) { + if (comparer(prevElement, element) === Comparison.GreaterThan) { + return false; + } + prevElement = element; + } + return true; + } + export function arrayIsEqualTo(array1: readonly T[] | undefined, array2: readonly T[] | undefined, equalityComparer: (a: T, b: T, index: number) => boolean = equateValues): boolean { if (!array1 || !array2) { return array1 === array2; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index ce1162933e4e5..661bc1cfd2d5a 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -4336,6 +4336,9 @@ namespace ts { /* @internal */ export type AnyImportOrRequire = AnyImportSyntax | RequireVariableDeclaration; + /* @internal */ + export type AnyImportOrRequireStatement = AnyImportSyntax | RequireVariableStatement; + /* @internal */ export type AnyImportOrReExport = AnyImportSyntax | ExportDeclaration; @@ -4357,8 +4360,17 @@ namespace ts { /* @internal */ export interface RequireVariableDeclaration extends VariableDeclaration { + readonly initializer: RequireOrImportCall; + } - initializer: RequireOrImportCall; + /* @internal */ + export interface RequireVariableStatement extends VariableStatement { + readonly declarationList: RequireVariableDeclarationList; + } + + /* @internal */ + export interface RequireVariableDeclarationList extends VariableDeclarationList { + readonly declarations: NodeArray; } /* @internal */ diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index a6978df31b5df..dbed7297524c5 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1934,8 +1934,10 @@ namespace ts { return isVariableDeclaration(node) && !!node.initializer && isRequireCall(node.initializer, requireStringLiteralLikeArgument); } - export function isRequireVariableDeclarationStatement(node: Node, requireStringLiteralLikeArgument = true): node is VariableStatement { - return isVariableStatement(node) && every(node.declarationList.declarations, decl => isRequireVariableDeclaration(decl, requireStringLiteralLikeArgument)); + export function isRequireVariableStatement(node: Node, requireStringLiteralLikeArgument = true): node is RequireVariableStatement { + return isVariableStatement(node) + && node.declarationList.declarations.length > 0 + && every(node.declarationList.declarations, decl => isRequireVariableDeclaration(decl, requireStringLiteralLikeArgument)); } export function isSingleOrDoubleQuote(charCode: number) { diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index f1d2996d7e662..e386d45538ae9 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -138,7 +138,7 @@ namespace ts.codefix { doAddExistingFix(changeTracker, sourceFile, importClauseOrBindingPattern, defaultImport, namedImports, canUseTypeOnlyImport); }); - let newDeclarations: Statement | readonly Statement[] | undefined; + let newDeclarations: AnyImportOrRequireStatement | readonly AnyImportOrRequireStatement[] | undefined; newImports.forEach(({ useRequire, ...imports }, moduleSpecifier) => { const getDeclarations = useRequire ? getNewRequires : getNewImports; newDeclarations = combine(newDeclarations, getDeclarations(moduleSpecifier, quotePreference, imports)); @@ -671,15 +671,35 @@ namespace ts.codefix { } if (namedImports.length) { - const specifiers = namedImports.map(name => factory.createImportSpecifier(/*propertyName*/ undefined, factory.createIdentifier(name))); - if (clause.namedBindings && cast(clause.namedBindings, isNamedImports).elements.length) { - for (const spec of specifiers) { - changes.insertNodeInListAfter(sourceFile, last(cast(clause.namedBindings, isNamedImports).elements), spec); + const existingSpecifiers = clause.namedBindings && cast(clause.namedBindings, isNamedImports).elements; + const newSpecifiers = stableSort( + namedImports.map(name => factory.createImportSpecifier(/*propertyName*/ undefined, factory.createIdentifier(name))), + OrganizeImports.compareImportOrExportSpecifiers); + + if (existingSpecifiers?.length && OrganizeImports.importSpecifiersAreSorted(existingSpecifiers)) { + for (const spec of newSpecifiers) { + const insertionIndex = OrganizeImports.getImportSpecifierInsertionIndex(existingSpecifiers, spec); + const prevSpecifier = (clause.namedBindings as NamedImports).elements[insertionIndex - 1]; + if (prevSpecifier) { + changes.insertNodeInListAfter(sourceFile, prevSpecifier, spec); + } + else { + changes.insertNodeBefore( + sourceFile, + existingSpecifiers[0], + spec, + !positionsAreOnSameLine(existingSpecifiers[0].getStart(), clause.parent.getStart(), sourceFile)); + } + } + } + else if (existingSpecifiers?.length) { + for (const spec of newSpecifiers) { + changes.insertNodeAtEndOfList(sourceFile, existingSpecifiers, spec); } } else { - if (specifiers.length) { - const namedImports = factory.createNamedImports(specifiers); + if (newSpecifiers.length) { + const namedImports = factory.createNamedImports(newSpecifiers); if (clause.namedBindings) { changes.replaceNode(sourceFile, clause.namedBindings, namedImports); } @@ -727,9 +747,9 @@ namespace ts.codefix { readonly name: string; }; } - function getNewImports(moduleSpecifier: string, quotePreference: QuotePreference, imports: ImportsCollection): Statement | readonly Statement[] { + function getNewImports(moduleSpecifier: string, quotePreference: QuotePreference, imports: ImportsCollection): AnyImportSyntax | readonly AnyImportSyntax[] { const quotedModuleSpecifier = makeStringLiteral(moduleSpecifier, quotePreference); - let statements: Statement | readonly Statement[] | undefined; + let statements: AnyImportSyntax | readonly AnyImportSyntax[] | undefined; if (imports.defaultImport !== undefined || imports.namedImports?.length) { statements = combine(statements, makeImport( imports.defaultImport === undefined ? undefined : factory.createIdentifier(imports.defaultImport), @@ -756,9 +776,9 @@ namespace ts.codefix { return Debug.checkDefined(statements); } - function getNewRequires(moduleSpecifier: string, quotePreference: QuotePreference, imports: ImportsCollection): Statement | readonly Statement[] { + function getNewRequires(moduleSpecifier: string, quotePreference: QuotePreference, imports: ImportsCollection): RequireVariableStatement | readonly RequireVariableStatement[] { const quotedModuleSpecifier = makeStringLiteral(moduleSpecifier, quotePreference); - let statements: Statement | readonly Statement[] | undefined; + let statements: RequireVariableStatement | readonly RequireVariableStatement[] | undefined; // const { default: foo, bar, etc } = require('./mod'); if (imports.defaultImport || imports.namedImports?.length) { const bindingElements = imports.namedImports?.map(name => factory.createBindingElement(/*dotDotDotToken*/ undefined, /*propertyName*/ undefined, name)) || []; @@ -776,7 +796,7 @@ namespace ts.codefix { return Debug.checkDefined(statements); } - function createConstEqualsRequireDeclaration(name: string | ObjectBindingPattern, quotedModuleSpecifier: StringLiteral): VariableStatement { + function createConstEqualsRequireDeclaration(name: string | ObjectBindingPattern, quotedModuleSpecifier: StringLiteral): RequireVariableStatement { return factory.createVariableStatement( /*modifiers*/ undefined, factory.createVariableDeclarationList([ @@ -785,7 +805,7 @@ namespace ts.codefix { /*exclamationToken*/ undefined, /*type*/ undefined, factory.createCallExpression(factory.createIdentifier("require"), /*typeArguments*/ undefined, [quotedModuleSpecifier]))], - NodeFlags.Const)); + NodeFlags.Const)) as RequireVariableStatement; } function symbolHasMeaning({ declarations }: Symbol, meaning: SemanticMeaning): boolean { diff --git a/src/services/organizeImports.ts b/src/services/organizeImports.ts index 566b0ebdd7b76..46eda4b00a916 100644 --- a/src/services/organizeImports.ts +++ b/src/services/organizeImports.ts @@ -17,7 +17,9 @@ namespace ts.OrganizeImports { const changeTracker = textChanges.ChangeTracker.fromContext({ host, formatContext, preferences }); - const coalesceAndOrganizeImports = (importGroup: readonly ImportDeclaration[]) => coalesceImports(removeUnusedImports(importGroup, sourceFile, program)); + const coalesceAndOrganizeImports = (importGroup: readonly ImportDeclaration[]) => stableSort( + coalesceImports(removeUnusedImports(importGroup, sourceFile, program)), + (s1, s2) => compareImportsOrRequireStatements(s1, s2)); // All of the old ImportDeclarations in the file, in syntactic order. const topLevelImportDecls = sourceFile.statements.filter(isImportDeclaration); @@ -55,7 +57,7 @@ namespace ts.OrganizeImports { suppressLeadingTrivia(oldImportDecls[0]); const oldImportGroups = group(oldImportDecls, importDecl => getExternalModuleName(importDecl.moduleSpecifier!)!); - const sortedImportGroups = stableSort(oldImportGroups, (group1, group2) => compareModuleSpecifiers(group1[0].moduleSpecifier!, group2[0].moduleSpecifier!)); + const sortedImportGroups = stableSort(oldImportGroups, (group1, group2) => compareModuleSpecifiers(group1[0].moduleSpecifier, group2[0].moduleSpecifier)); const newImportDecls = flatMap(sortedImportGroups, importGroup => getExternalModuleName(importGroup[0].moduleSpecifier!) ? coalesce(importGroup) @@ -395,15 +397,18 @@ namespace ts.OrganizeImports { } function sortSpecifiers(specifiers: readonly T[]) { - return stableSort(specifiers, (s1, s2) => - compareIdentifiers(s1.propertyName || s1.name, s2.propertyName || s2.name) || - compareIdentifiers(s1.name, s2.name)); + return stableSort(specifiers, compareImportOrExportSpecifiers); + } + + export function compareImportOrExportSpecifiers(s1: T, s2: T) { + return compareIdentifiers(s1.propertyName || s1.name, s2.propertyName || s2.name) + || compareIdentifiers(s1.name, s2.name); } /* internal */ // Exported for testing - export function compareModuleSpecifiers(m1: Expression, m2: Expression) { - const name1 = getExternalModuleName(m1); - const name2 = getExternalModuleName(m2); + export function compareModuleSpecifiers(m1: Expression | undefined, m2: Expression | undefined) { + const name1 = m1 === undefined ? undefined : getExternalModuleName(m1); + const name2 = m2 === undefined ? undefined : getExternalModuleName(m2); return compareBooleans(name1 === undefined, name2 === undefined) || compareBooleans(isExternalModuleNameRelative(name1!), isExternalModuleNameRelative(name2!)) || compareStringsCaseInsensitive(name1!, name2!); @@ -412,4 +417,63 @@ namespace ts.OrganizeImports { function compareIdentifiers(s1: Identifier, s2: Identifier) { return compareStringsCaseInsensitive(s1.text, s2.text); } + + function getModuleSpecifierExpression(declaration: AnyImportOrRequireStatement): Expression | undefined { + switch (declaration.kind) { + case SyntaxKind.ImportEqualsDeclaration: + return tryCast(declaration.moduleReference, isExternalModuleReference)?.expression; + case SyntaxKind.ImportDeclaration: + return declaration.moduleSpecifier; + case SyntaxKind.VariableStatement: + return declaration.declarationList.declarations[0].initializer.arguments[0]; + } + } + + export function importsAreSorted(imports: readonly AnyImportOrRequireStatement[]): imports is SortedReadonlyArray { + return arrayIsSorted(imports, compareImportsOrRequireStatements); + } + + export function importSpecifiersAreSorted(imports: readonly ImportSpecifier[]): imports is SortedReadonlyArray { + return arrayIsSorted(imports, compareImportOrExportSpecifiers); + } + + export function getImportDeclarationInsertionIndex(sortedImports: SortedReadonlyArray, newImport: AnyImportOrRequireStatement) { + const index = binarySearch(sortedImports, newImport, identity, compareImportsOrRequireStatements); + return index < 0 ? ~index : index; + } + + export function getImportSpecifierInsertionIndex(sortedImports: SortedReadonlyArray, newImport: ImportSpecifier) { + const index = binarySearch(sortedImports, newImport, identity, compareImportOrExportSpecifiers); + return index < 0 ? ~index : index; + } + + export function compareImportsOrRequireStatements(s1: AnyImportOrRequireStatement, s2: AnyImportOrRequireStatement) { + return compareModuleSpecifiers(getModuleSpecifierExpression(s1), getModuleSpecifierExpression(s2)) || compareImportKind(s1, s2); + } + + function compareImportKind(s1: AnyImportOrRequireStatement, s2: AnyImportOrRequireStatement) { + return compareValues(getImportKindOrder(s1), getImportKindOrder(s2)); + } + + // 1. Side-effect imports + // 2. Type-only imports + // 3. Namespace imports + // 4. Default imports + // 5. Named imports + // 6. ImportEqualsDeclarations + // 7. Require variable statements + function getImportKindOrder(s1: AnyImportOrRequireStatement) { + switch (s1.kind) { + case SyntaxKind.ImportDeclaration: + if (!s1.importClause) return 0; + if (s1.importClause.isTypeOnly) return 1; + if (s1.importClause.namedBindings?.kind === SyntaxKind.NamespaceImport) return 2; + if (s1.importClause.name) return 3; + return 4; + case SyntaxKind.ImportEqualsDeclaration: + return 5; + case SyntaxKind.VariableStatement: + return 6; + } + } } diff --git a/src/services/refactors/moveToNewFile.ts b/src/services/refactors/moveToNewFile.ts index f4984fe18bde9..24181c4cef0d0 100644 --- a/src/services/refactors/moveToNewFile.ts +++ b/src/services/refactors/moveToNewFile.ts @@ -269,7 +269,7 @@ namespace ts.refactor { | ImportEqualsDeclaration | VariableStatement; - function createOldFileImportsFromNewFile(newFileNeedExport: ReadonlySymbolSet, newFileNameWithExtension: string, useEs6Imports: boolean, quotePreference: QuotePreference): Statement | undefined { + function createOldFileImportsFromNewFile(newFileNeedExport: ReadonlySymbolSet, newFileNameWithExtension: string, useEs6Imports: boolean, quotePreference: QuotePreference): AnyImportOrRequireStatement | undefined { let defaultImport: Identifier | undefined; const imports: string[] = []; newFileNeedExport.forEach(symbol => { @@ -283,7 +283,7 @@ namespace ts.refactor { return makeImportOrRequire(defaultImport, imports, newFileNameWithExtension, useEs6Imports, quotePreference); } - function makeImportOrRequire(defaultImport: Identifier | undefined, imports: readonly string[], path: string, useEs6Imports: boolean, quotePreference: QuotePreference): Statement | undefined { + function makeImportOrRequire(defaultImport: Identifier | undefined, imports: readonly string[], path: string, useEs6Imports: boolean, quotePreference: QuotePreference): AnyImportOrRequireStatement | undefined { path = ensurePathIsNonModuleName(path); if (useEs6Imports) { const specifiers = imports.map(i => factory.createImportSpecifier(/*propertyName*/ undefined, factory.createIdentifier(i))); @@ -293,7 +293,7 @@ namespace ts.refactor { Debug.assert(!defaultImport, "No default import should exist"); // If there's a default export, it should have been an es6 module. const bindingElements = imports.map(i => factory.createBindingElement(/*dotDotDotToken*/ undefined, /*propertyName*/ undefined, i)); return bindingElements.length - ? makeVariableStatement(factory.createObjectBindingPattern(bindingElements), /*type*/ undefined, createRequireCall(factory.createStringLiteral(path))) + ? makeVariableStatement(factory.createObjectBindingPattern(bindingElements), /*type*/ undefined, createRequireCall(factory.createStringLiteral(path))) as RequireVariableStatement : undefined; } } diff --git a/src/services/textChanges.ts b/src/services/textChanges.ts index 1acce25574bfb..24349565296e9 100644 --- a/src/services/textChanges.ts +++ b/src/services/textChanges.ts @@ -472,9 +472,9 @@ namespace ts.textChanges { this.insertNodesAt(sourceFile, start, typeParameters, { prefix: "<", suffix: ">" }); } - private getOptionsForInsertNodeBefore(before: Node, inserted: Node, doubleNewlines: boolean): InsertNodeOptions { + private getOptionsForInsertNodeBefore(before: Node, inserted: Node, blankLineBetween: boolean): InsertNodeOptions { if (isStatement(before) || isClassElement(before)) { - return { suffix: doubleNewlines ? this.newLineCharacter + this.newLineCharacter : this.newLineCharacter }; + return { suffix: blankLineBetween ? this.newLineCharacter + this.newLineCharacter : this.newLineCharacter }; } else if (isVariableDeclaration(before)) { // insert `x = 1, ` into `const x = 1, y = 2; return { suffix: ", " }; @@ -485,6 +485,9 @@ namespace ts.textChanges { else if (isStringLiteral(before) && isImportDeclaration(before.parent) || isNamedImports(before)) { return { suffix: ", " }; } + else if (isImportSpecifier(before)) { + return { suffix: "," + (blankLineBetween ? this.newLineCharacter : " ") }; + } return Debug.failBadSyntaxKind(before); // We haven't handled this kind of node yet -- add it } diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 4e56757abee19..04bda47cd5611 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -1872,23 +1872,34 @@ namespace ts { return node.modifiers && find(node.modifiers, m => m.kind === kind); } - export function insertImports(changes: textChanges.ChangeTracker, sourceFile: SourceFile, imports: Statement | readonly Statement[], blankLineBetween: boolean): void { + export function insertImports(changes: textChanges.ChangeTracker, sourceFile: SourceFile, imports: AnyImportOrRequireStatement | readonly AnyImportOrRequireStatement[], blankLineBetween: boolean): void { const decl = isArray(imports) ? imports[0] : imports; - const importKindPredicate = decl.kind === SyntaxKind.VariableStatement ? isRequireVariableDeclarationStatement : isAnyImportSyntax; - const lastImportDeclaration = findLast(sourceFile.statements, statement => importKindPredicate(statement)); - if (lastImportDeclaration) { - if (isArray(imports)) { - changes.insertNodesAfter(sourceFile, lastImportDeclaration, imports); - } - else { - changes.insertNodeAfter(sourceFile, lastImportDeclaration, imports); + const importKindPredicate: (node: Node) => node is AnyImportOrRequireStatement = decl.kind === SyntaxKind.VariableStatement ? isRequireVariableStatement : isAnyImportSyntax; + const existingImportStatements = filter(sourceFile.statements, importKindPredicate); + const sortedNewImports = isArray(imports) ? stableSort(imports, OrganizeImports.compareImportsOrRequireStatements) : [imports]; + if (!existingImportStatements.length) { + changes.insertNodesAtTopOfFile(sourceFile, sortedNewImports, blankLineBetween); + } + else if (existingImportStatements && OrganizeImports.importsAreSorted(existingImportStatements)) { + for (const newImport of sortedNewImports) { + const insertionIndex = OrganizeImports.getImportDeclarationInsertionIndex(existingImportStatements, newImport); + if (insertionIndex === 0) { + changes.insertNodeBefore(sourceFile, existingImportStatements[0], newImport, /*blankLineBetween*/ false); + } + else { + const prevImport = existingImportStatements[insertionIndex - 1]; + changes.insertNodeAfter(sourceFile, prevImport, newImport); + } } } - else if (isArray(imports)) { - changes.insertNodesAtTopOfFile(sourceFile, imports, blankLineBetween); - } else { - changes.insertNodeAtTopOfFile(sourceFile, imports, blankLineBetween); + const lastExistingImport = lastOrUndefined(existingImportStatements); + if (lastExistingImport) { + changes.insertNodesAfter(sourceFile, lastExistingImport, sortedNewImports); + } + else { + changes.insertNodesAtTopOfFile(sourceFile, sortedNewImports, blankLineBetween); + } } } diff --git a/tests/baselines/reference/organizeImports/TypeOnly.ts b/tests/baselines/reference/organizeImports/TypeOnly.ts index dcd18e7ef86a4..96281b4ada53a 100644 --- a/tests/baselines/reference/organizeImports/TypeOnly.ts +++ b/tests/baselines/reference/organizeImports/TypeOnly.ts @@ -8,8 +8,8 @@ import type { A, B } from "lib"; export { A, B, X, Y, Z }; // ==ORGANIZED== -import { X, Z } from "lib"; import type Y from "lib"; import type { A, B } from "lib"; +import { X, Z } from "lib"; export { A, B, X, Y, Z }; diff --git a/tests/cases/fourslash/codeFixInferFromUsageContextualImport4.ts b/tests/cases/fourslash/codeFixInferFromUsageContextualImport4.ts index fbb6336a869b0..037bdc1121195 100644 --- a/tests/cases/fourslash/codeFixInferFromUsageContextualImport4.ts +++ b/tests/cases/fourslash/codeFixInferFromUsageContextualImport4.ts @@ -25,8 +25,8 @@ verify.codeFix({ index: 0, description: "Infer parameter types from usage", newFileContent: -`import { getEmail } from './getEmail'; -import { User, Settings } from './a'; +`import { User, Settings } from './a'; +import { getEmail } from './getEmail'; export function f(user: User, settings: Settings) { getEmail(user, settings); diff --git a/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs_importArgumentType.ts b/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs_importArgumentType.ts index b9410c035835b..50f376f9889cb 100644 --- a/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs_importArgumentType.ts +++ b/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs_importArgumentType.ts @@ -19,7 +19,7 @@ verify.codeFix({ description: [ts.Diagnostics.Declare_method_0.message, "foo"], index: 0, newFileContent: -`import { create, A } from "./a"; +`import { A, create } from "./a"; class B { bar() { create(args => this.foo(args)); diff --git a/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs_importArgumentType1.ts b/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs_importArgumentType1.ts index 4a7afe32b53df..a95ccbca1d109 100644 --- a/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs_importArgumentType1.ts +++ b/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs_importArgumentType1.ts @@ -25,8 +25,8 @@ verify.codeFix({ description: [ts.Diagnostics.Declare_method_0.message, "foo"], index: 0, newFileContent: -`import { create, B } from "./b"; -import { A } from "./a"; +`import { A } from "./a"; +import { B, create } from "./b"; class C { bar() { create(args => this.foo(args)); diff --git a/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs_importArgumentType2.ts b/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs_importArgumentType2.ts index 057558455348e..3a6da2fb9dd96 100644 --- a/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs_importArgumentType2.ts +++ b/tests/cases/fourslash/codeFixUndeclaredMethodFunctionArgs_importArgumentType2.ts @@ -31,9 +31,9 @@ verify.codeFix({ description: [ts.Diagnostics.Declare_method_0.message, "foo"], index: 0, newFileContent: -`import { create, C } from "./c"; +`import { A } from "./a"; import { B } from "./b"; -import { A } from "./a"; +import { C, create } from "./c"; class D { bar() { create(args => this.foo(args)); diff --git a/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts b/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts index 2e1fd6003ba14..610b4fc73cfa8 100644 --- a/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts +++ b/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts @@ -25,7 +25,7 @@ verify.applyCodeActionFromCompletion("", { name: "foo", source: "/a", description: `Import default 'foo' from module "./a"`, - newFileContent: `import f_o_o from "./a"; -import foo from "./a"; + newFileContent: `import foo from "./a"; +import f_o_o from "./a"; f;`, }); diff --git a/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts b/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts index 8e1ec13df79f3..55ba68abedded 100644 --- a/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts +++ b/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts @@ -26,6 +26,6 @@ verify.applyCodeActionFromCompletion("", { name: "foo", source: "/a", description: `Add 'foo' to existing import declaration from "./a"`, - newFileContent: `import { x, foo } from "./a"; + newFileContent: `import { foo, x } from "./a"; f;`, }); diff --git a/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts b/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts index cb55f859cca06..59766f81fcf50 100644 --- a/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts +++ b/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts @@ -14,21 +14,21 @@ verify.completions({ marker: "", exact: [ { - name: "Test2", - text: "(alias) function Test2(): void\nimport Test2", - kind: "alias" + name: "Test2", + text: "(alias) function Test2(): void\nimport Test2", + kind: "alias" }, completion.globalThisEntry, completion.undefinedVarEntry, { - name: "Test1", - source: "/a", - sourceDisplay: "./a", - text: "function Test1(): void", - kind: "function", - kindModifiers: "export", - hasAction: true, - sortText: completion.SortText.AutoImportSuggestions + name: "Test1", + source: "/a", + sourceDisplay: "./a", + text: "function Test1(): void", + kind: "function", + kindModifiers: "export", + hasAction: true, + sortText: completion.SortText.AutoImportSuggestions }, ...completion.statementKeywordsWithTypes, ], @@ -39,6 +39,6 @@ verify.applyCodeActionFromCompletion("", { name: "Test1", source: "/a", description: `Add 'Test1' to existing import declaration from "./a"`, - newFileContent: `import { Test2, Test1 } from "./a"; + newFileContent: `import { Test1, Test2 } from "./a"; t`, }); diff --git a/tests/cases/fourslash/completionsImport_reExport_wrongName.ts b/tests/cases/fourslash/completionsImport_reExport_wrongName.ts index 4080fe5cdb7dd..1b386e3728862 100644 --- a/tests/cases/fourslash/completionsImport_reExport_wrongName.ts +++ b/tests/cases/fourslash/completionsImport_reExport_wrongName.ts @@ -46,8 +46,8 @@ verify.applyCodeActionFromCompletion("", { name: "y", source: "/index", description: `Import 'y' from module "."`, - newFileContent: `import { x } from "./a"; -import { y } from "."; + newFileContent: `import { y } from "."; +import { x } from "./a"; `, }); diff --git a/tests/cases/fourslash/extract-method32.ts b/tests/cases/fourslash/extract-method32.ts index 229561e9795a1..d2d999fd290ad 100644 --- a/tests/cases/fourslash/extract-method32.ts +++ b/tests/cases/fourslash/extract-method32.ts @@ -21,7 +21,7 @@ edit.applyRefactor({ actionName: "function_scope_1", actionDescription: "Extract to function in module scope", newContent: -`import { a, A } from "./a"; +`import { A, a } from "./a"; function foo() { const arg = a; diff --git a/tests/cases/fourslash/extract-method33.ts b/tests/cases/fourslash/extract-method33.ts index 96d4216c844d0..6c3adbd6d1808 100644 --- a/tests/cases/fourslash/extract-method33.ts +++ b/tests/cases/fourslash/extract-method33.ts @@ -29,8 +29,8 @@ edit.applyRefactor({ actionName: "function_scope_1", actionDescription: "Extract to function in module scope", newContent: -`import { b, B } from "./b"; -import { A } from "./a"; +`import { A } from "./a"; +import { B, b } from "./b"; function foo() { const prop = b; diff --git a/tests/cases/fourslash/extract-method34.ts b/tests/cases/fourslash/extract-method34.ts index 7ffb72e7af54e..7499063268513 100644 --- a/tests/cases/fourslash/extract-method34.ts +++ b/tests/cases/fourslash/extract-method34.ts @@ -38,9 +38,9 @@ edit.applyRefactor({ actionName: "function_scope_1", actionDescription: "Extract to function in module scope", newContent: -`import { c, C } from "./c"; +`import { A } from "./a"; import { B } from "./b"; -import { A } from "./a"; +import { C, c } from "./c"; function foo() { const prop = c; diff --git a/tests/cases/fourslash/extract-method35.ts b/tests/cases/fourslash/extract-method35.ts index 67a3edd0b4ad3..5f6ea76c6dabe 100644 --- a/tests/cases/fourslash/extract-method35.ts +++ b/tests/cases/fourslash/extract-method35.ts @@ -23,7 +23,7 @@ edit.applyRefactor({ actionName: "function_scope_1", actionDescription: "Extract to method in class 'Foo'", newContent: -`import { a, A } from "./a"; +`import { A, a } from "./a"; class Foo { foo() { diff --git a/tests/cases/fourslash/extract-method36.ts b/tests/cases/fourslash/extract-method36.ts index 0b3e93e2b951a..47f9e75a24502 100644 --- a/tests/cases/fourslash/extract-method36.ts +++ b/tests/cases/fourslash/extract-method36.ts @@ -31,8 +31,8 @@ edit.applyRefactor({ actionName: "function_scope_1", actionDescription: "Extract to method in class 'Foo'", newContent: -`import { b, B } from "./b"; -import { A } from "./a"; +`import { A } from "./a"; +import { B, b } from "./b"; class Foo { foo() { diff --git a/tests/cases/fourslash/extract-method37.ts b/tests/cases/fourslash/extract-method37.ts index 1f71cd098187b..c6a1c485cb63a 100644 --- a/tests/cases/fourslash/extract-method37.ts +++ b/tests/cases/fourslash/extract-method37.ts @@ -40,9 +40,9 @@ edit.applyRefactor({ actionName: "function_scope_1", actionDescription: "Extract to method in class 'Foo'", newContent: -`import { c, C } from "./c"; +`import { A } from "./a"; import { B } from "./b"; -import { A } from "./a"; +import { C, c } from "./c"; class Foo { foo() { diff --git a/tests/cases/fourslash/importNameCodeFixExistingImport0.ts b/tests/cases/fourslash/importNameCodeFixExistingImport0.ts index e5b634998783c..922285e9afca3 100644 --- a/tests/cases/fourslash/importNameCodeFixExistingImport0.ts +++ b/tests/cases/fourslash/importNameCodeFixExistingImport0.ts @@ -7,4 +7,4 @@ //// export function f1() {} //// export var v1 = 5; -verify.importFixAtPosition([`{ v1, f1 }`]); +verify.importFixAtPosition([`{ f1, v1 }`]); diff --git a/tests/cases/fourslash/importNameCodeFixExistingImport1.ts b/tests/cases/fourslash/importNameCodeFixExistingImport1.ts index 49680692b6c58..f06ce49f0ea6b 100644 --- a/tests/cases/fourslash/importNameCodeFixExistingImport1.ts +++ b/tests/cases/fourslash/importNameCodeFixExistingImport1.ts @@ -8,4 +8,4 @@ //// export var v1 = 5; //// export default var d1 = 6; -verify.importFixAtPosition([`{ v1, f1 }`]); +verify.importFixAtPosition([`{ f1, v1 }`]); diff --git a/tests/cases/fourslash/importNameCodeFixExistingImport10.ts b/tests/cases/fourslash/importNameCodeFixExistingImport10.ts index a9525d272da00..3faa34deaa916 100644 --- a/tests/cases/fourslash/importNameCodeFixExistingImport10.ts +++ b/tests/cases/fourslash/importNameCodeFixExistingImport10.ts @@ -14,8 +14,8 @@ verify.importFixAtPosition([ `{ + f1, v1, - v2, - f1 + v2 }` ]); diff --git a/tests/cases/fourslash/importNameCodeFixExistingImport11.ts b/tests/cases/fourslash/importNameCodeFixExistingImport11.ts index 786e0e397756e..4a414ef9a36de 100644 --- a/tests/cases/fourslash/importNameCodeFixExistingImport11.ts +++ b/tests/cases/fourslash/importNameCodeFixExistingImport11.ts @@ -14,8 +14,8 @@ verify.importFixAtPosition([ `{ + f1, v1, v2, - v3, - f1 + v3 }` ]); diff --git a/tests/cases/fourslash/importNameCodeFixExistingImport6.ts b/tests/cases/fourslash/importNameCodeFixExistingImport6.ts index 0d3636e443955..7b2bd7d5383f5 100644 --- a/tests/cases/fourslash/importNameCodeFixExistingImport6.ts +++ b/tests/cases/fourslash/importNameCodeFixExistingImport6.ts @@ -10,4 +10,4 @@ //// export var v1 = 5; //// export function f1(); -verify.importFixAtPosition([`{ v1, f1 }`]); +verify.importFixAtPosition([`{ f1, v1 }`]); diff --git a/tests/cases/fourslash/importNameCodeFixExistingImport7.ts b/tests/cases/fourslash/importNameCodeFixExistingImport7.ts index f0b1a77f69012..8a8ceb926c230 100644 --- a/tests/cases/fourslash/importNameCodeFixExistingImport7.ts +++ b/tests/cases/fourslash/importNameCodeFixExistingImport7.ts @@ -7,4 +7,4 @@ //// export var v1 = 5; //// export function f1(); -verify.importFixAtPosition([`{ v1, f1 }`]); +verify.importFixAtPosition([`{ f1, v1 }`]); diff --git a/tests/cases/fourslash/importNameCodeFixExistingImport8.ts b/tests/cases/fourslash/importNameCodeFixExistingImport8.ts index a1b676a8b8309..a365136607d55 100644 --- a/tests/cases/fourslash/importNameCodeFixExistingImport8.ts +++ b/tests/cases/fourslash/importNameCodeFixExistingImport8.ts @@ -1,12 +1,12 @@ /// //// import [|{v1, v2, v3,}|] from "./module"; -//// f1/*0*/(); +//// v4/*0*/(); // @Filename: module.ts -//// export function f1() {} +//// export function v4() {} //// export var v1 = 5; //// export var v2 = 5; //// export var v3 = 5; -verify.importFixAtPosition([`{v1, v2, v3, f1,}`]); +verify.importFixAtPosition([`{v1, v2, v3, v4,}`]); diff --git a/tests/cases/fourslash/importNameCodeFixExistingImport9.ts b/tests/cases/fourslash/importNameCodeFixExistingImport9.ts index 67960de32d4c2..bc9701032bbeb 100644 --- a/tests/cases/fourslash/importNameCodeFixExistingImport9.ts +++ b/tests/cases/fourslash/importNameCodeFixExistingImport9.ts @@ -11,6 +11,7 @@ verify.importFixAtPosition([ `{ - v1, f1 + f1, + v1 }` ]); diff --git a/tests/cases/fourslash/importNameCodeFixExistingImportEquals0.ts b/tests/cases/fourslash/importNameCodeFixExistingImportEquals0.ts index de86ed13cd54b..4165cdae93bad 100644 --- a/tests/cases/fourslash/importNameCodeFixExistingImportEquals0.ts +++ b/tests/cases/fourslash/importNameCodeFixExistingImportEquals0.ts @@ -12,7 +12,7 @@ verify.importFixAtPosition([ `import ns = require("ambient-module"); var x = ns.v1 + 5;`, -`import ns = require("ambient-module"); -import { v1 } from "ambient-module"; +`import { v1 } from "ambient-module"; +import ns = require("ambient-module"); var x = v1 + 5;`, ]); diff --git a/tests/cases/fourslash/importNameCodeFixNewImportAmbient1.ts b/tests/cases/fourslash/importNameCodeFixNewImportAmbient1.ts index 835850306f68d..5966800667e7c 100644 --- a/tests/cases/fourslash/importNameCodeFixNewImportAmbient1.ts +++ b/tests/cases/fourslash/importNameCodeFixNewImportAmbient1.ts @@ -1,8 +1,8 @@ /// //// import d from "other-ambient-module"; -//// [|import * as ns from "yet-another-ambient-module"; -//// var x = v1/*0*/ + 5;|] +//// import * as ns from "yet-another-ambient-module"; +//// var x = v1/*0*/ + 5; // @Filename: ambientModule.ts //// declare module "ambient-module" { @@ -22,7 +22,8 @@ //// } verify.importFixAtPosition([ -`import * as ns from "yet-another-ambient-module"; -import { v1 } from "ambient-module"; +`import { v1 } from "ambient-module"; +import d from "other-ambient-module"; +import * as ns from "yet-another-ambient-module"; var x = v1 + 5;` ]); diff --git a/tests/cases/fourslash/importNameCodeFixNewImportAmbient3.ts b/tests/cases/fourslash/importNameCodeFixNewImportAmbient3.ts index dbd6c4ef26ab8..0b596e455331d 100644 --- a/tests/cases/fourslash/importNameCodeFixNewImportAmbient3.ts +++ b/tests/cases/fourslash/importNameCodeFixNewImportAmbient3.ts @@ -2,8 +2,8 @@ //// let a = "I am a non-trivial statement that appears before imports"; //// import d from "other-ambient-module" -//// [|import * as ns from "yet-another-ambient-module" -//// var x = v1/*0*/ + 5;|] +//// import * as ns from "yet-another-ambient-module" +//// var x = v1/*0*/ + 5; // @Filename: ambientModule.ts //// declare module "ambient-module" { @@ -24,7 +24,9 @@ // test cases when there are no semicolons at the line end verify.importFixAtPosition([ -`import * as ns from "yet-another-ambient-module" +`let a = "I am a non-trivial statement that appears before imports"; import { v1 } from "ambient-module"; +import d from "other-ambient-module" +import * as ns from "yet-another-ambient-module" var x = v1 + 5;` ]); diff --git a/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyle0.ts b/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyle0.ts index 6b5ef958e0546..4a7f109c7b15a 100644 --- a/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyle0.ts +++ b/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyle0.ts @@ -11,8 +11,8 @@ //// export var v2 = 6; verify.importFixAtPosition([ -`import { v2 } from './module2'; -import { f1 } from './module1'; +`import { f1 } from './module1'; +import { v2 } from './module2'; f1();` ]); diff --git a/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyle1.ts b/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyle1.ts index a9a12c419582e..ea131406ac25a 100644 --- a/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyle1.ts +++ b/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyle1.ts @@ -11,8 +11,8 @@ //// export var v2 = 6; verify.importFixAtPosition([ -`import { v2 } from "./module2"; -import { f1 } from "./module1"; +`import { f1 } from "./module1"; +import { v2 } from "./module2"; f1();` ]); diff --git a/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyle2.ts b/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyle2.ts index c356e239ee86a..663670d63074a 100644 --- a/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyle2.ts +++ b/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyle2.ts @@ -11,8 +11,8 @@ //// export var v2 = 6; verify.importFixAtPosition([ -`import m2 = require('./module2'); -import { f1 } from './module1'; +`import { f1 } from './module1'; +import m2 = require('./module2'); f1();` ]); diff --git a/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyleMixed0.ts b/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyleMixed0.ts index 2f17780df7ff6..95e437bbe71ca 100644 --- a/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyleMixed0.ts +++ b/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyleMixed0.ts @@ -15,9 +15,9 @@ //// export var v3 = 6; verify.importFixAtPosition([ -`import { v2 } from "./module2"; +`import { f1 } from "./module1"; +import { v2 } from "./module2"; import { v3 } from './module3'; -import { f1 } from "./module1"; f1();` ]); diff --git a/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyleMixed1.ts b/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyleMixed1.ts index ec68b3be0d844..310583671e38c 100644 --- a/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyleMixed1.ts +++ b/tests/cases/fourslash/importNameCodeFixNewImportFileQuoteStyleMixed1.ts @@ -15,9 +15,9 @@ //// export var v3 = 6; verify.importFixAtPosition([ -`import { v2 } from './module2'; +`import { f1 } from './module1'; +import { v2 } from './module2'; import { v3 } from "./module3"; -import { f1 } from './module1'; f1();` ]); diff --git a/tests/cases/fourslash/importNameCodeFixUMDGlobal1.ts b/tests/cases/fourslash/importNameCodeFixUMDGlobal1.ts index 1beebb0477cd0..f94ecf1c75a47 100644 --- a/tests/cases/fourslash/importNameCodeFixUMDGlobal1.ts +++ b/tests/cases/fourslash/importNameCodeFixUMDGlobal1.ts @@ -14,8 +14,8 @@ //// export as namespace bar1; verify.importFixAtPosition([ -`import { bar } from "./foo"; -import * as bar1 from "./foo"; +`import * as bar1 from "./foo"; +import { bar } from "./foo"; export function test() { }; bar1.bar();` diff --git a/tests/cases/fourslash/importNameCodeFixUMDGlobalReact0.ts b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact0.ts index 6fc3ce5498811..f630deb2a333e 100644 --- a/tests/cases/fourslash/importNameCodeFixUMDGlobalReact0.ts +++ b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact0.ts @@ -29,8 +29,8 @@ goTo.file("/a.tsx"); verify.importFixAtPosition([ - `import { Component } from "react"; -import * as React from "react"; + `import * as React from "react"; +import { Component } from "react"; export class MyMap extends Component { } ;`]); @@ -38,6 +38,6 @@ export class MyMap extends Component { } goTo.file("/b.tsx"); verify.importFixAtPosition([ -`import { Component } from "react"; -import * as React from "react"; +`import * as React from "react"; +import { Component } from "react"; <>;`]); diff --git a/tests/cases/fourslash/importNameCodeFixUMDGlobalReact1.ts b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact1.ts index 9dba0f3988256..247b48e99cca7 100644 --- a/tests/cases/fourslash/importNameCodeFixUMDGlobalReact1.ts +++ b/tests/cases/fourslash/importNameCodeFixUMDGlobalReact1.ts @@ -25,7 +25,7 @@ goTo.file("/a.tsx"); verify.importFixAtPosition([ -`import { Component } from "react"; -import * as React from "react"; +`import * as React from "react"; +import { Component } from "react"; export class MyMap extends Component { } ;`]); diff --git a/tests/cases/fourslash/importNameCodeFix_all.ts b/tests/cases/fourslash/importNameCodeFix_all.ts index d5bb525900a6b..f76a5d1aa6950 100644 --- a/tests/cases/fourslash/importNameCodeFix_all.ts +++ b/tests/cases/fourslash/importNameCodeFix_all.ts @@ -37,10 +37,10 @@ verify.codeFixAll({ fixId: "fixMissingImport", fixAllDescription: "Add all missing imports", newFileContent: -`import bd, * as b from "./b"; +`import ad, { a0 } from "./a"; +import bd, * as b from "./b"; import cd, { c0 } from "./c"; import dd, { d0, d1 } from "./d"; -import ad, { a0 } from "./a"; import e = require("./e"); ad; ad; a0; a0; diff --git a/tests/cases/fourslash/importNameCodeFix_all2.ts b/tests/cases/fourslash/importNameCodeFix_all2.ts index 6f7a9b3403cdc..68c1e5d5106e8 100644 --- a/tests/cases/fourslash/importNameCodeFix_all2.ts +++ b/tests/cases/fourslash/importNameCodeFix_all2.ts @@ -15,8 +15,8 @@ goTo.file("/index.ts"); verify.codeFixAll({ fixId: "fixMissingImport", fixAllDescription: "Add all missing imports", - newFileContent: `import { join } from "./path"; -import { homedir } from "./os"; + newFileContent: `import { homedir } from "./os"; +import { join } from "./path"; join(); homedir();` diff --git a/tests/cases/fourslash/importNameCodeFix_avoidRelativeNodeModules.ts b/tests/cases/fourslash/importNameCodeFix_avoidRelativeNodeModules.ts index bff7fec290873..71a406a3b91c8 100644 --- a/tests/cases/fourslash/importNameCodeFix_avoidRelativeNodeModules.ts +++ b/tests/cases/fourslash/importNameCodeFix_avoidRelativeNodeModules.ts @@ -21,7 +21,7 @@ goTo.file("/c/foo.ts"); verify.importFixAtPosition([ -`import { b } from "b"; -import { a } from "a"; +`import { a } from "a"; +import { b } from "b"; a;`, ]); diff --git a/tests/cases/fourslash/importNameCodeFix_fileWithNoTrailingNewline.ts b/tests/cases/fourslash/importNameCodeFix_fileWithNoTrailingNewline.ts index 89d6398a5538b..f596de2691af7 100644 --- a/tests/cases/fourslash/importNameCodeFix_fileWithNoTrailingNewline.ts +++ b/tests/cases/fourslash/importNameCodeFix_fileWithNoTrailingNewline.ts @@ -13,7 +13,6 @@ goTo.file("/c.ts"); verify.importFixAtPosition([ `foo; -import { bar } from "./b"; import { foo } from "./a"; -`, +import { bar } from "./b";`, ]); diff --git a/tests/cases/fourslash/importNameCodeFix_jsx.ts b/tests/cases/fourslash/importNameCodeFix_jsx.ts index 5e09074ba1c75..27373611338e4 100644 --- a/tests/cases/fourslash/importNameCodeFix_jsx.ts +++ b/tests/cases/fourslash/importNameCodeFix_jsx.ts @@ -33,6 +33,6 @@ import { Foo } from "./Foo"; // When JSX namespace is missing, provide fix for that goTo.file("/d.tsx"); verify.importFixAtPosition([ -`import { Foo } from "./Foo"; -import { React } from "react"; +`import { React } from "react"; +import { Foo } from "./Foo"; ;`]); diff --git a/tests/cases/fourslash/importNameCodeFix_order.ts b/tests/cases/fourslash/importNameCodeFix_order.ts index 888b440e928ed..e4363a42997af 100644 --- a/tests/cases/fourslash/importNameCodeFix_order.ts +++ b/tests/cases/fourslash/importNameCodeFix_order.ts @@ -15,7 +15,7 @@ goTo.file("/c.ts"); verify.importFixAtPosition([ `import { bar, foo } from "./b"; foo;`, -`import { bar } from "./b"; -import { foo } from "./a"; +`import { foo } from "./a"; +import { bar } from "./b"; foo;`, ]); diff --git a/tests/cases/fourslash/importNameCodeFix_require.ts b/tests/cases/fourslash/importNameCodeFix_require.ts index c682c469246d4..74687bf3e3685 100644 --- a/tests/cases/fourslash/importNameCodeFix_require.ts +++ b/tests/cases/fourslash/importNameCodeFix_require.ts @@ -25,9 +25,9 @@ verify.codeFixAll({ fixId: "fixMissingImport", fixAllDescription: "Add all missing imports", newFileContent: -`const foo = require("./foo"); +`const { default: Blah } = require("./blah"); +const foo = require("./foo"); const { util1, util2 } = require("./utils"); -const { default: Blah } = require("./blah"); foo(); util1(); diff --git a/tests/cases/fourslash/importNameCodeFix_withJson.ts b/tests/cases/fourslash/importNameCodeFix_withJson.ts index 49d449b7b0498..cc6432402652d 100644 --- a/tests/cases/fourslash/importNameCodeFix_withJson.ts +++ b/tests/cases/fourslash/importNameCodeFix_withJson.ts @@ -9,7 +9,7 @@ ////a/**/ goTo.file("/b.ts"); -verify.importFixAtPosition([`import "./anything.json"; -import { a } from "./a"; +verify.importFixAtPosition([`import { a } from "./a"; +import "./anything.json"; a`]); diff --git a/tests/cases/fourslash/quickfixImplementInterfaceUnreachableTypeUsesRelativeImport.ts b/tests/cases/fourslash/quickfixImplementInterfaceUnreachableTypeUsesRelativeImport.ts index 5db9047035513..d81500d489b33 100644 --- a/tests/cases/fourslash/quickfixImplementInterfaceUnreachableTypeUsesRelativeImport.ts +++ b/tests/cases/fourslash/quickfixImplementInterfaceUnreachableTypeUsesRelativeImport.ts @@ -18,8 +18,8 @@ verify.codeFix({ description: "Implement interface 'Foo'", newFileContent: { "/tests/cases/fourslash/index.ts": -`import { Foo } from './interface'; -import { Class } from './class'; +`import { Class } from './class'; +import { Foo } from './interface'; class X implements Foo { x: Class;