( localName: string, exportedSpecifierName: string | null, rawModuleSpecifier: string, useSingleQuotes = false, )
| 617 | * be omitted. |
| 618 | */ |
| 619 | export function generateImport( |
| 620 | localName: string, |
| 621 | exportedSpecifierName: string | null, |
| 622 | rawModuleSpecifier: string, |
| 623 | useSingleQuotes = false, |
| 624 | ): ts.ImportDeclaration { |
| 625 | let propName: ts.Identifier | undefined; |
| 626 | if (exportedSpecifierName !== null && exportedSpecifierName !== localName) { |
| 627 | propName = ts.factory.createIdentifier(exportedSpecifierName); |
| 628 | } |
| 629 | const name = ts.factory.createIdentifier(localName); |
| 630 | const moduleSpec = ts.factory.createStringLiteral(rawModuleSpecifier, useSingleQuotes); |
| 631 | let importClauseName: ts.Identifier | undefined; |
| 632 | let importBindings: ts.NamedImportBindings | undefined; |
| 633 | |
| 634 | if (localName === 'default' && exportedSpecifierName !== null) { |
| 635 | importClauseName = ts.factory.createIdentifier(exportedSpecifierName); |
| 636 | } else { |
| 637 | importBindings = ts.factory.createNamedImports([ |
| 638 | ts.factory.createImportSpecifier(false, propName, name), |
| 639 | ]); |
| 640 | } |
| 641 | return ts.factory.createImportDeclaration( |
| 642 | undefined, |
| 643 | ts.factory.createImportClause(undefined, importClauseName, importBindings), |
| 644 | moduleSpec, |
| 645 | undefined, |
| 646 | ); |
| 647 | } |
| 648 | |
| 649 | /** |
| 650 | * Update an existing named import with a new member. |
no test coverage detected