From c3a512a9e96c911ff3a2fc762e7e0d895ac8179e Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Wed, 21 Apr 2021 13:20:27 +0100 Subject: [PATCH] fix(compiler-cli): match string indexed partial declarations (#41747) Some partial libraries have been minified, which results in the declaration calls being being converted from property accesses to indexed accesses. This commit ensures that the linker can process these calls. Fixes #41655 PR Close #41747 --- .../linker/babel/src/es2015_linker_plugin.ts | 2 ++ .../linker/babel/test/es2015_linker_plugin_spec.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/compiler-cli/linker/babel/src/es2015_linker_plugin.ts b/packages/compiler-cli/linker/babel/src/es2015_linker_plugin.ts index 17abf1ad3380f..11a647f0df416 100644 --- a/packages/compiler-cli/linker/babel/src/es2015_linker_plugin.ts +++ b/packages/compiler-cli/linker/babel/src/es2015_linker_plugin.ts @@ -139,6 +139,8 @@ function getCalleeName(call: NodePath): string|null { return callee.name; } else if (t.isMemberExpression(callee) && t.isIdentifier(callee.property)) { return callee.property.name; + } else if (t.isMemberExpression(callee) && t.isStringLiteral(callee.property)) { + return callee.property.value; } else { return null; } diff --git a/packages/compiler-cli/linker/babel/test/es2015_linker_plugin_spec.ts b/packages/compiler-cli/linker/babel/test/es2015_linker_plugin_spec.ts index 31d17a7b8b553..92773e4a738e9 100644 --- a/packages/compiler-cli/linker/babel/test/es2015_linker_plugin_spec.ts +++ b/packages/compiler-cli/linker/babel/test/es2015_linker_plugin_spec.ts @@ -70,9 +70,10 @@ describe('createEs2015LinkerPlugin()', () => { [ 'var core;', `ɵɵngDeclareDirective({minVersion: '0.0.0-PLACEHOLDER', version: '0.0.0-PLACEHOLDER', ngImport: core, x: 1});`, - `ɵɵngDeclareComponent({minVersion: '0.0.0-PLACEHOLDER', version: '0.0.0-PLACEHOLDER', ngImport: core, foo: () => ɵɵngDeclareDirective({minVersion: '0.0.0-PLACEHOLDER', version: '0.0.0-PLACEHOLDER', ngImport: core, x: 2})});`, + `i0.ɵɵngDeclareComponent({minVersion: '0.0.0-PLACEHOLDER', version: '0.0.0-PLACEHOLDER', ngImport: core, foo: () => ɵɵngDeclareDirective({minVersion: '0.0.0-PLACEHOLDER', version: '0.0.0-PLACEHOLDER', ngImport: core, x: 2})});`, `x.qux(() => ɵɵngDeclareDirective({minVersion: '0.0.0-PLACEHOLDER', version: '0.0.0-PLACEHOLDER', ngImport: core, x: 3}));`, 'spread(...x);', + `i0['ɵɵngDeclareDirective']({minVersion: '0.0.0-PLACEHOLDER', version: '0.0.0-PLACEHOLDER', ngImport: core, x: 4});`, ].join('\n'), { plugins: [createEs2015LinkerPlugin({fileSystem, logger})], @@ -93,7 +94,11 @@ describe('createEs2015LinkerPlugin()', () => { [ 'ɵɵngDeclareDirective', '{minVersion:\'0.0.0-PLACEHOLDER\',version:\'0.0.0-PLACEHOLDER\',ngImport:core,x:3}' - ] + ], + [ + 'ɵɵngDeclareDirective', + '{minVersion:\'0.0.0-PLACEHOLDER\',version:\'0.0.0-PLACEHOLDER\',ngImport:core,x:4}' + ], ]); });