* Adds an import to a file. * @param sourceFile File to which to add the import. * @param symbolName Symbol being imported. * @param moduleName Module from which the symbol is imported. * @param alias Alias to use for the import.
(
sourceFile: ts.SourceFile,
symbolName: string,
moduleName: string,
alias?: string,
)
| 117 | * @param alias Alias to use for the import. |
| 118 | */ |
| 119 | addImport( |
| 120 | sourceFile: ts.SourceFile, |
| 121 | symbolName: string, |
| 122 | moduleName: string, |
| 123 | alias?: string, |
| 124 | ): ts.Expression { |
| 125 | if (this._importRemapper) { |
| 126 | moduleName = this._importRemapper(moduleName, sourceFile.fileName); |
| 127 | } |
| 128 | |
| 129 | // It's common for paths to be manipulated with Node's `path` utilties which |
| 130 | // can yield a path with back slashes. Normalize them since outputting such |
| 131 | // paths will also cause TS to escape the forward slashes. |
| 132 | moduleName = normalizePath(moduleName); |
| 133 | |
| 134 | if (!this._changes.has(sourceFile)) { |
| 135 | this._changes.set(sourceFile, []); |
| 136 | } |
| 137 | |
| 138 | return this._importManager.addImport({ |
| 139 | requestedFile: sourceFile, |
| 140 | exportSymbolName: symbolName, |
| 141 | exportModuleSpecifier: moduleName, |
| 142 | unsafeAliasOverride: alias, |
| 143 | }); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Removes an import from a file. |
nothing calls this directly
no test coverage detected