From 281b647f1550bee215db53862ae83cdda6703606 Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 16 Jul 2020 15:59:48 +0200 Subject: [PATCH] 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 --- packages/compiler-cli/src/ngtsc/annotations/src/metadata.ts | 2 +- packages/compiler-cli/src/ngtsc/imports/test/default_spec.ts | 2 +- .../compiler-cli/src/ngtsc/reflection/src/type_to_value.ts | 4 +--- packages/compiler-cli/src/ngtsc/switch/src/switch.ts | 4 ---- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/annotations/src/metadata.ts b/packages/compiler-cli/src/ngtsc/annotations/src/metadata.ts index af855d3b43..ce1a358c8a 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/metadata.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/metadata.ts @@ -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. diff --git a/packages/compiler-cli/src/ngtsc/imports/test/default_spec.ts b/packages/compiler-cli/src/ngtsc/imports/test/default_spec.ts index 0171459232..f07ea36462 100644 --- a/packages/compiler-cli/src/ngtsc/imports/test/default_spec.ts +++ b/packages/compiler-cli/src/ngtsc/imports/test/default_spec.ts @@ -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(); diff --git a/packages/compiler-cli/src/ngtsc/reflection/src/type_to_value.ts b/packages/compiler-cli/src/ngtsc/reflection/src/type_to_value.ts index cf17312b60..eea33c9bfe 100644 --- a/packages/compiler-cli/src/ngtsc/reflection/src/type_to_value.ts +++ b/packages/compiler-cli/src/ngtsc/reflection/src/type_to_value.ts @@ -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)) { diff --git a/packages/compiler-cli/src/ngtsc/switch/src/switch.ts b/packages/compiler-cli/src/ngtsc/switch/src/switch.ts index aa8897d74c..8d40c1e3db 100644 --- a/packages/compiler-cli/src/ngtsc/switch/src/switch.ts +++ b/packages/compiler-cli/src/ngtsc/switch/src/switch.ts @@ -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,