refactor(compiler-cli): remove usage of `ts.updateIdentifier` (#38076)

With Typescript 4, `ts.updateIdentifier` is no longer available.
Calling `ts.updateIdentifier` used to return the same node when
`typeArguments` was `undefined` because `node.typeArguments`
was also `undefined`.

Relevant TS code:
```js
function updateIdentifier(node, typeArguments) {
  return node.typeArguments !== typeArguments
      ? updateNode(createIdentifier(ts.idText(node), typeArguments), node)
      : node;
}
```

PR Close #38076
This commit is contained in:
Alan Agius 2020-07-16 15:59:48 +02:00 committed by Misko Hevery
parent 0fc44e0436
commit 281b647f15
4 changed files with 3 additions and 9 deletions

View File

@ -28,7 +28,7 @@ export function generateSetClassMetadataCall(
if (!reflection.isClass(clazz)) {
return null;
}
const id = ts.updateIdentifier(reflection.getAdjacentNameOfClass(clazz));
const id = reflection.getAdjacentNameOfClass(clazz);
// Reflect over the class decorators. If none are present, or those that are aren't from
// Angular, then return null. Otherwise, turn them into metadata.

View File

@ -69,7 +69,7 @@ runInEachFileSystem(() => {
module: ts.ModuleKind.CommonJS,
});
const fooClause = getDeclaration(program, _('/test.ts'), 'Foo', ts.isImportClause);
const fooId = ts.updateIdentifier(fooClause.name!);
const fooId = fooClause.name!;
const fooDecl = fooClause.parent;
const tracker = new DefaultImportTracker();

View File

@ -59,9 +59,7 @@ export function typeToValue(
return {
kind: TypeValueReferenceKind.LOCAL,
// Copying the name here ensures the generated references will be correctly transformed
// along with the import.
expression: ts.updateIdentifier(firstDecl.name),
expression: firstDecl.name,
defaultImportStatement: firstDecl.parent,
};
} else if (ts.isImportSpecifier(firstDecl)) {

View File

@ -110,10 +110,6 @@ function flipIvySwitchesInVariableStatement(
stmt.getSourceFile().fileName} for the Ivy switch.`);
}
// Copy the identifier with updateIdentifier(). This copies the internal information which
// allows TS to write a correct reference to the identifier.
newIdentifier = ts.updateIdentifier(newIdentifier);
newDeclarations[i] = ts.updateVariableDeclaration(
/* node */ decl,
/* name */ decl.name,