( localName: string, exportedSpecifierName: string | null, rawModuleSpecifier: string, )
| 587 | * be omitted. |
| 588 | */ |
| 589 | export function generateImport( |
| 590 | localName: string, |
| 591 | exportedSpecifierName: string | null, |
| 592 | rawModuleSpecifier: string, |
| 593 | ): ts.ImportDeclaration { |
| 594 | let propName: ts.Identifier | undefined; |
| 595 | if (exportedSpecifierName !== null && exportedSpecifierName !== localName) { |
| 596 | propName = ts.factory.createIdentifier(exportedSpecifierName); |
| 597 | } |
| 598 | const name = ts.factory.createIdentifier(localName); |
| 599 | const moduleSpec = ts.factory.createStringLiteral(rawModuleSpecifier); |
| 600 | let importClauseName: ts.Identifier | undefined; |
| 601 | let importBindings: ts.NamedImportBindings | undefined; |
| 602 | |
| 603 | if (localName === 'default' && exportedSpecifierName !== null) { |
| 604 | importClauseName = ts.factory.createIdentifier(exportedSpecifierName); |
| 605 | } else { |
| 606 | importBindings = ts.factory.createNamedImports([ |
| 607 | ts.factory.createImportSpecifier(false, propName, name), |
| 608 | ]); |
| 609 | } |
| 610 | return ts.factory.createImportDeclaration( |
| 611 | undefined, |
| 612 | ts.factory.createImportClause(undefined, importClauseName, importBindings), |
| 613 | moduleSpec, |
| 614 | undefined, |
| 615 | ); |
| 616 | } |
| 617 | |
| 618 | /** |
| 619 | * Update an existing named import with a new member. |
no test coverage detected