Skip to content

Commit

Permalink
Fix factory update calls
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbranch committed Nov 20, 2019
1 parent ab31628 commit d5e3ebb
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/compiler/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2244,7 +2244,7 @@ namespace ts {
return node;
}

export function updateImportClause(node: ImportClause, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, isTypeOnly = false) {
export function updateImportClause(node: ImportClause, name: Identifier | undefined, namedBindings: NamedImportBindings | undefined, isTypeOnly: boolean) {
return node.name !== name
|| node.namedBindings !== namedBindings
|| node.isTypeOnly !== isTypeOnly
Expand Down Expand Up @@ -2323,7 +2323,7 @@ namespace ts {
modifiers: readonly Modifier[] | undefined,
exportClause: NamedExports | undefined,
moduleSpecifier: Expression | undefined,
isTypeOnly = false) {
isTypeOnly: boolean) {
return node.decorators !== decorators
|| node.modifiers !== modifiers
|| node.isTypeOnly !== isTypeOnly
Expand Down
17 changes: 13 additions & 4 deletions src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,8 @@ namespace ts {
return visibleDefaultBinding && updateImportDeclaration(decl, /*decorators*/ undefined, decl.modifiers, updateImportClause(
decl.importClause,
visibleDefaultBinding,
/*namedBindings*/ undefined
/*namedBindings*/ undefined,
decl.importClause.isTypeOnly,
), rewriteModuleSpecifier(decl, decl.moduleSpecifier));
}
if (decl.importClause.namedBindings.kind === SyntaxKind.NamespaceImport) {
Expand All @@ -695,7 +696,8 @@ namespace ts {
return visibleDefaultBinding || namedBindings ? updateImportDeclaration(decl, /*decorators*/ undefined, decl.modifiers, updateImportClause(
decl.importClause,
visibleDefaultBinding,
namedBindings
namedBindings,
decl.importClause.isTypeOnly,
), rewriteModuleSpecifier(decl, decl.moduleSpecifier)) : undefined;
}
// Named imports (optionally with visible default)
Expand All @@ -708,7 +710,8 @@ namespace ts {
updateImportClause(
decl.importClause,
visibleDefaultBinding,
bindingList && bindingList.length ? updateNamedImports(decl.importClause.namedBindings, bindingList) : undefined
bindingList && bindingList.length ? updateNamedImports(decl.importClause.namedBindings, bindingList) : undefined,
decl.importClause.isTypeOnly,
),
rewriteModuleSpecifier(decl, decl.moduleSpecifier)
);
Expand Down Expand Up @@ -1018,7 +1021,13 @@ namespace ts {
resultHasScopeMarker = true;
// Always visible if the parent node isn't dropped for being not visible
// Rewrite external module names if necessary
return updateExportDeclaration(input, /*decorators*/ undefined, input.modifiers, input.exportClause, rewriteModuleSpecifier(input, input.moduleSpecifier));
return updateExportDeclaration(
input,
/*decorators*/ undefined,
input.modifiers,
input.exportClause,
rewriteModuleSpecifier(input, input.moduleSpecifier),
input.isTypeOnly);
}
case SyntaxKind.ExportAssignment: {
// Always visible if the parent node isn't dropped for being not visible
Expand Down
8 changes: 6 additions & 2 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2781,10 +2781,13 @@ namespace ts {
* @param node The import clause node.
*/
function visitImportClause(node: ImportClause): VisitResult<ImportClause> {
if (node.isTypeOnly) {
return undefined;
}
// Elide the import clause if we elide both its name and its named bindings.
const name = resolver.isReferencedAliasDeclaration(node) ? node.name : undefined;
const namedBindings = visitNode(node.namedBindings, visitNamedImportBindings, isNamedImportBindings);
return (name || namedBindings) ? updateImportClause(node, name, namedBindings) : undefined;
return (name || namedBindings) ? updateImportClause(node, name, namedBindings, /*isTypeOnly*/ false) : undefined;
}

/**
Expand Down Expand Up @@ -2856,7 +2859,8 @@ namespace ts {
/*decorators*/ undefined,
/*modifiers*/ undefined,
exportClause,
node.moduleSpecifier)
node.moduleSpecifier,
node.isTypeOnly)
: undefined;
}

Expand Down
6 changes: 4 additions & 2 deletions src/compiler/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,8 @@ namespace ts {
case SyntaxKind.ImportClause:
return updateImportClause(<ImportClause>node,
visitNode((<ImportClause>node).name, visitor, isIdentifier),
visitNode((<ImportClause>node).namedBindings, visitor, isNamedImportBindings));
visitNode((<ImportClause>node).namedBindings, visitor, isNamedImportBindings),
(node as ImportClause).isTypeOnly);

case SyntaxKind.NamespaceImport:
return updateNamespaceImport(<NamespaceImport>node,
Expand All @@ -817,7 +818,8 @@ namespace ts {
nodesVisitor((<ExportDeclaration>node).decorators, visitor, isDecorator),
nodesVisitor((<ExportDeclaration>node).modifiers, visitor, isModifier),
visitNode((<ExportDeclaration>node).exportClause, visitor, isNamedExports),
visitNode((<ExportDeclaration>node).moduleSpecifier, visitor, isExpression));
visitNode((<ExportDeclaration>node).moduleSpecifier, visitor, isExpression),
(node as ExportDeclaration).isTypeOnly);

case SyntaxKind.NamedExports:
return updateNamedExports(<NamedExports>node,
Expand Down
5 changes: 3 additions & 2 deletions src/services/organizeImports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ namespace ts.OrganizeImports {
exportDecl.decorators,
exportDecl.modifiers,
updateNamedExports(exportDecl.exportClause!, sortedExportSpecifiers),
exportDecl.moduleSpecifier));
exportDecl.moduleSpecifier,
exportDecl.isTypeOnly));

return coalescedExports;

Expand Down Expand Up @@ -358,7 +359,7 @@ namespace ts.OrganizeImports {
importDeclaration,
importDeclaration.decorators,
importDeclaration.modifiers,
updateImportClause(importDeclaration.importClause!, name, namedBindings), // TODO: GH#18217
updateImportClause(importDeclaration.importClause!, name, namedBindings, importDeclaration.importClause!.isTypeOnly), // TODO: GH#18217
importDeclaration.moduleSpecifier);
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/refactors/moveToNewFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ namespace ts.refactor {
changes.replaceNode(
sourceFile,
importDecl.importClause,
updateImportClause(importDecl.importClause, name, /*namedBindings*/ undefined)
updateImportClause(importDecl.importClause, name, /*namedBindings*/ undefined, importDecl.importClause.isTypeOnly)
);
}
else if (namedBindings.kind === SyntaxKind.NamedImports) {
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ namespace ts {
const exports = [{ name: "x" }];
const exportSpecifiers = exports.map(e => createExportSpecifier(e.name, e.name));
const exportClause = createNamedExports(exportSpecifiers);
const newEd = updateExportDeclaration(ed, ed.decorators, ed.modifiers, exportClause, ed.moduleSpecifier);
const newEd = updateExportDeclaration(ed, ed.decorators, ed.modifiers, exportClause, ed.moduleSpecifier, ed.isTypeOnly);

return newEd as Node as T;
}
Expand Down

0 comments on commit d5e3ebb

Please sign in to comment.