Skip to content

Commit d5e3ebb

Browse files
committed
Fix factory update calls
1 parent ab31628 commit d5e3ebb

File tree

7 files changed

+30
-14
lines changed

7 files changed

+30
-14
lines changed

Diff for: src/compiler/factory.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2244,7 +2244,7 @@ namespace ts {
22442244
return node;
22452245
}
22462246

2247-
export function updateImportClause(node: ImportClause, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, isTypeOnly = false) {
2247+
export function updateImportClause(node: ImportClause, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, isTypeOnly: boolean) {
22482248
return node.name !== name
22492249
|| node.namedBindings !== namedBindings
22502250
|| node.isTypeOnly !== isTypeOnly
@@ -2323,7 +2323,7 @@ namespace ts {
23232323
modifiers: readonly Modifier[] | undefined,
23242324
exportClause: NamedExports | undefined,
23252325
moduleSpecifier: Expression | undefined,
2326-
isTypeOnly = false) {
2326+
isTypeOnly: boolean) {
23272327
return node.decorators !== decorators
23282328
|| node.modifiers !== modifiers
23292329
|| node.isTypeOnly !== isTypeOnly

Diff for: src/compiler/transformers/declarations.ts

+13-4
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,8 @@ namespace ts {
686686
return visibleDefaultBinding && updateImportDeclaration(decl, /*decorators*/ undefined, decl.modifiers, updateImportClause(
687687
decl.importClause,
688688
visibleDefaultBinding,
689-
/*namedBindings*/ undefined
689+
/*namedBindings*/ undefined,
690+
decl.importClause.isTypeOnly,
690691
), rewriteModuleSpecifier(decl, decl.moduleSpecifier));
691692
}
692693
if (decl.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) {
@@ -695,7 +696,8 @@ namespace ts {
695696
return visibleDefaultBinding || namedBindings ? updateImportDeclaration(decl, /*decorators*/ undefined, decl.modifiers, updateImportClause(
696697
decl.importClause,
697698
visibleDefaultBinding,
698-
namedBindings
699+
namedBindings,
700+
decl.importClause.isTypeOnly,
699701
), rewriteModuleSpecifier(decl, decl.moduleSpecifier)) : undefined;
700702
}
701703
// Named imports (optionally with visible default)
@@ -708,7 +710,8 @@ namespace ts {
708710
updateImportClause(
709711
decl.importClause,
710712
visibleDefaultBinding,
711-
bindingList && bindingList.length ? updateNamedImports(decl.importClause.namedBindings, bindingList) : undefined
713+
bindingList && bindingList.length ? updateNamedImports(decl.importClause.namedBindings, bindingList) : undefined,
714+
decl.importClause.isTypeOnly,
712715
),
713716
rewriteModuleSpecifier(decl, decl.moduleSpecifier)
714717
);
@@ -1018,7 +1021,13 @@ namespace ts {
10181021
resultHasScopeMarker = true;
10191022
// Always visible if the parent node isn't dropped for being not visible
10201023
// Rewrite external module names if necessary
1021-
return updateExportDeclaration(input, /*decorators*/ undefined, input.modifiers, input.exportClause, rewriteModuleSpecifier(input, input.moduleSpecifier));
1024+
return updateExportDeclaration(
1025+
input,
1026+
/*decorators*/ undefined,
1027+
input.modifiers,
1028+
input.exportClause,
1029+
rewriteModuleSpecifier(input, input.moduleSpecifier),
1030+
input.isTypeOnly);
10221031
}
10231032
case SyntaxKind.ExportAssignment: {
10241033
// Always visible if the parent node isn't dropped for being not visible

Diff for: src/compiler/transformers/ts.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -2781,10 +2781,13 @@ namespace ts {
27812781
* @param node The import clause node.
27822782
*/
27832783
function visitImportClause(node: ImportClause): VisitResult<ImportClause> {
2784+
if (node.isTypeOnly) {
2785+
return undefined;
2786+
}
27842787
// Elide the import clause if we elide both its name and its named bindings.
27852788
const name = resolver.isReferencedAliasDeclaration(node) ? node.name : undefined;
27862789
const namedBindings = visitNode(node.namedBindings, visitNamedImportBindings, isNamedImportBindings);
2787-
return (name || namedBindings) ? updateImportClause(node, name, namedBindings) : undefined;
2790+
return (name || namedBindings) ? updateImportClause(node, name, namedBindings, /*isTypeOnly*/ false) : undefined;
27882791
}
27892792

27902793
/**
@@ -2856,7 +2859,8 @@ namespace ts {
28562859
/*decorators*/ undefined,
28572860
/*modifiers*/ undefined,
28582861
exportClause,
2859-
node.moduleSpecifier)
2862+
node.moduleSpecifier,
2863+
node.isTypeOnly)
28602864
: undefined;
28612865
}
28622866

Diff for: src/compiler/visitor.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,8 @@ namespace ts {
791791
case SyntaxKind.ImportClause:
792792
return updateImportClause(<ImportClause>node,
793793
visitNode((<ImportClause>node).name, visitor, isIdentifier),
794-
visitNode((<ImportClause>node).namedBindings, visitor, isNamedImportBindings));
794+
visitNode((<ImportClause>node).namedBindings, visitor, isNamedImportBindings),
795+
(node as ImportClause).isTypeOnly);
795796

796797
case SyntaxKind.NamespaceImport:
797798
return updateNamespaceImport(<NamespaceImport>node,
@@ -817,7 +818,8 @@ namespace ts {
817818
nodesVisitor((<ExportDeclaration>node).decorators, visitor, isDecorator),
818819
nodesVisitor((<ExportDeclaration>node).modifiers, visitor, isModifier),
819820
visitNode((<ExportDeclaration>node).exportClause, visitor, isNamedExports),
820-
visitNode((<ExportDeclaration>node).moduleSpecifier, visitor, isExpression));
821+
visitNode((<ExportDeclaration>node).moduleSpecifier, visitor, isExpression),
822+
(node as ExportDeclaration).isTypeOnly);
821823

822824
case SyntaxKind.NamedExports:
823825
return updateNamedExports(<NamedExports>node,

Diff for: src/services/organizeImports.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@ namespace ts.OrganizeImports {
318318
exportDecl.decorators,
319319
exportDecl.modifiers,
320320
updateNamedExports(exportDecl.exportClause!, sortedExportSpecifiers),
321-
exportDecl.moduleSpecifier));
321+
exportDecl.moduleSpecifier,
322+
exportDecl.isTypeOnly));
322323

323324
return coalescedExports;
324325

@@ -358,7 +359,7 @@ namespace ts.OrganizeImports {
358359
importDeclaration,
359360
importDeclaration.decorators,
360361
importDeclaration.modifiers,
361-
updateImportClause(importDeclaration.importClause!, name, namedBindings), // TODO: GH#18217
362+
updateImportClause(importDeclaration.importClause!, name, namedBindings, importDeclaration.importClause!.isTypeOnly), // TODO: GH#18217
362363
importDeclaration.moduleSpecifier);
363364
}
364365

Diff for: src/services/refactors/moveToNewFile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ namespace ts.refactor {
353353
changes.replaceNode(
354354
sourceFile,
355355
importDecl.importClause,
356-
updateImportClause(importDecl.importClause, name, /*namedBindings*/ undefined)
356+
updateImportClause(importDecl.importClause, name, /*namedBindings*/ undefined, importDecl.importClause.isTypeOnly)
357357
);
358358
}
359359
else if (namedBindings.kind === SyntaxKind.NamedImports) {

Diff for: src/testRunner/unittests/transform.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ namespace ts {
220220
const exports = [{ name: "x" }];
221221
const exportSpecifiers = exports.map(e => createExportSpecifier(e.name, e.name));
222222
const exportClause = createNamedExports(exportSpecifiers);
223-
const newEd = updateExportDeclaration(ed, ed.decorators, ed.modifiers, exportClause, ed.moduleSpecifier);
223+
const newEd = updateExportDeclaration(ed, ed.decorators, ed.modifiers, exportClause, ed.moduleSpecifier, ed.isTypeOnly);
224224

225225
return newEd as Node as T;
226226
}

0 commit comments

Comments
 (0)