Home > vue-metamorph > astHelpers > createNamespaceImport
astHelpers.createNamespaceImport() function
Adds a namespace import to a script AST. If an import declaration for the module already exists, this function merges the namespace specifier into that declaration. It doesn't create duplicate imports.
Signature:
typescript
export declare function createNamespaceImport(ast: namedTypes.Program, moduleSpecifier: string, namespaceName: string): void;Parameters
Parameter | Type | Description |
|---|---|---|
ast | The script AST. | |
moduleSpecifier | string | The module name to import from, such as |
namespaceName | string | The local name for the namespace import. |
Returns:
void
Exceptions
An error if the declaration already has a namespace import under a different name.
Example
ts
// import * as _ from 'lodash-es';
createNamespaceImport(scriptAST, 'lodash-es', '_');