MCPcopy Create free account
hub / github.com/angular/angular / addImport

Method addImport

packages/core/schematics/utils/change_tracker.ts:119–144  ·  view source on GitHub ↗

* 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,
  )

Source from the content-addressed store, hash-verified

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.

Callers

nothing calls this directly

Calls 4

normalizePathFunction · 0.70
hasMethod · 0.65
setMethod · 0.65
addImportMethod · 0.65

Tested by

no test coverage detected