feat(53656): Add support for the updated import attributes proposal (#54242)

This commit is contained in:
Oleksandr T
2023-09-26 13:20:15 -07:00
committed by GitHub
parent b12af0fa2b
commit 2e9e9a292c
169 changed files with 32223 additions and 374 deletions
@@ -68,14 +68,14 @@ function fixSingleExportDeclaration(changes: textChanges.ChangeTracker, exportSp
/*isTypeOnly*/ false,
factory.updateNamedExports(exportClause, filter(exportClause.elements, e => !contains(typeExportSpecifiers, e))),
exportDeclaration.moduleSpecifier,
/*assertClause*/ undefined,
/*attributes*/ undefined,
);
const typeExportDeclaration = factory.createExportDeclaration(
/*modifiers*/ undefined,
/*isTypeOnly*/ true,
factory.createNamedExports(typeExportSpecifiers),
exportDeclaration.moduleSpecifier,
/*assertClause*/ undefined,
/*attributes*/ undefined,
);
changes.replaceNode(context.sourceFile, exportDeclaration, valueExportDeclaration, {
@@ -125,13 +125,13 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, de
getSynthesizedDeepClones(declaration.modifiers, /*includeTrivia*/ true),
factory.createImportClause(/*isTypeOnly*/ true, getSynthesizedDeepClone(importClause.name, /*includeTrivia*/ true), /*namedBindings*/ undefined),
getSynthesizedDeepClone(declaration.moduleSpecifier, /*includeTrivia*/ true),
getSynthesizedDeepClone(declaration.assertClause, /*includeTrivia*/ true),
getSynthesizedDeepClone(declaration.attributes, /*includeTrivia*/ true),
),
factory.createImportDeclaration(
getSynthesizedDeepClones(declaration.modifiers, /*includeTrivia*/ true),
factory.createImportClause(/*isTypeOnly*/ true, /*name*/ undefined, getSynthesizedDeepClone(importClause.namedBindings, /*includeTrivia*/ true)),
getSynthesizedDeepClone(declaration.moduleSpecifier, /*includeTrivia*/ true),
getSynthesizedDeepClone(declaration.assertClause, /*includeTrivia*/ true),
getSynthesizedDeepClone(declaration.attributes, /*includeTrivia*/ true),
),
]);
}
@@ -142,7 +142,7 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, de
sameMap(importClause.namedBindings.elements, e => factory.updateImportSpecifier(e, /*isTypeOnly*/ false, e.propertyName, e.name)),
)
: importClause.namedBindings;
const importDeclaration = factory.updateImportDeclaration(declaration, declaration.modifiers, factory.updateImportClause(importClause, /*isTypeOnly*/ true, importClause.name, newNamedBindings), declaration.moduleSpecifier, declaration.assertClause);
const importDeclaration = factory.updateImportDeclaration(declaration, declaration.modifiers, factory.updateImportClause(importClause, /*isTypeOnly*/ true, importClause.name, newNamedBindings), declaration.moduleSpecifier, declaration.attributes);
changes.replaceNode(sourceFile, declaration, importDeclaration);
}
}
@@ -38,6 +38,6 @@ function getImportTypeNode(sourceFile: SourceFile, pos: number): ImportTypeNode
}
function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, importType: ImportTypeNode) {
const newTypeNode = factory.updateImportTypeNode(importType, importType.argument, importType.assertions, importType.qualifier, importType.typeArguments, /*isTypeOf*/ true);
const newTypeNode = factory.updateImportTypeNode(importType, importType.argument, importType.attributes, importType.qualifier, importType.typeArguments, /*isTypeOf*/ true);
changes.replaceNode(sourceFile, importType, newTypeNode);
}
@@ -184,13 +184,13 @@ function updateExport(changes: textChanges.ChangeTracker, program: Program, sour
factory.createNodeArray([...namedExports, ...createExportSpecifiers(names, allowTypeModifier)], /*hasTrailingComma*/ namedExports.hasTrailingComma),
),
node.moduleSpecifier,
node.assertClause,
node.attributes,
),
);
}
function createExport(changes: textChanges.ChangeTracker, program: Program, sourceFile: SourceFile, names: ExportName[]) {
changes.insertNodeAtEndOfScope(sourceFile, sourceFile, factory.createExportDeclaration(/*modifiers*/ undefined, /*isTypeOnly*/ false, factory.createNamedExports(createExportSpecifiers(names, /*allowTypeModifier*/ getIsolatedModules(program.getCompilerOptions()))), /*moduleSpecifier*/ undefined, /*assertClause*/ undefined));
changes.insertNodeAtEndOfScope(sourceFile, sourceFile, factory.createExportDeclaration(/*modifiers*/ undefined, /*isTypeOnly*/ false, factory.createNamedExports(createExportSpecifiers(names, /*allowTypeModifier*/ getIsolatedModules(program.getCompilerOptions()))), /*moduleSpecifier*/ undefined, /*attributes*/ undefined));
}
function createExportSpecifiers(names: ExportName[], allowTypeModifier: boolean) {
+1 -1
View File
@@ -1655,7 +1655,7 @@ function getNewImports(
factory.createNamespaceImport(factory.createIdentifier(namespaceLikeImport.name)),
),
quotedModuleSpecifier,
/*assertClause*/ undefined,
/*attributes*/ undefined,
);
statements = combine(statements, declaration);
}
+1 -1
View File
@@ -57,7 +57,7 @@ function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, in
statement,
defaultImportName && !allowSyntheticDefaults
? factory.createImportEqualsDeclaration(/*modifiers*/ undefined, /*isTypeOnly*/ false, defaultImportName, factory.createExternalModuleReference(required))
: factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, namedImports), required, /*assertClause*/ undefined),
: factory.createImportDeclaration(/*modifiers*/ undefined, factory.createImportClause(/*isTypeOnly*/ false, defaultImportName, namedImports), required, /*attributes*/ undefined),
);
}
@@ -53,7 +53,7 @@ function splitTypeOnlyImport(changes: textChanges.ChangeTracker, importDeclarati
importDeclaration.modifiers,
factory.updateImportClause(importClause, importClause.isTypeOnly, importClause.name, /*namedBindings*/ undefined),
importDeclaration.moduleSpecifier,
importDeclaration.assertClause,
importDeclaration.attributes,
),
);
@@ -64,7 +64,7 @@ function splitTypeOnlyImport(changes: textChanges.ChangeTracker, importDeclarati
/*modifiers*/ undefined,
factory.updateImportClause(importClause, importClause.isTypeOnly, /*name*/ undefined, importClause.namedBindings),
importDeclaration.moduleSpecifier,
importDeclaration.assertClause,
importDeclaration.attributes,
),
);
}