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

Method replaceNode

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

* Replaces the text of an AST node with a new one. * @param oldNode Node to be replaced. * @param newNode New node to be inserted. * @param emitHint Hint when formatting the text of the new node. * @param sourceFileWhenPrinting File to use when printing out the new node. This is importan

(
    oldNode: ts.Node,
    newNode: ts.Node,
    emitHint = ts.EmitHint.Unspecified,
    sourceFileWhenPrinting?: ts.SourceFile,
  )

Source from the content-addressed store, hash-verified

80 * without it.
81 */
82 replaceNode(
83 oldNode: ts.Node,
84 newNode: ts.Node,
85 emitHint = ts.EmitHint.Unspecified,
86 sourceFileWhenPrinting?: ts.SourceFile,
87 ): void {
88 const sourceFile = oldNode.getSourceFile();
89 this.replaceText(
90 sourceFile,
91 oldNode.getStart(),
92 oldNode.getWidth(),
93 this._printer.printNode(emitHint, newNode, sourceFileWhenPrinting || sourceFile),
94 );
95 }
96
97 /**
98 * Removes the text of an AST node from a file.

Callers 11

_recordImportsMethod · 0.95
migrateRouteFunction · 0.80
visitFunction · 0.80
migrateTestDeclarationsFunction · 0.80
removeArrayReferencesFunction · 0.80
removeImportReferencesFunction · 0.80
removeExportReferencesFunction · 0.80

Calls 2

replaceTextMethod · 0.95
getSourceFileMethod · 0.45

Tested by

no test coverage detected