fix(ivy): ngcc generates setClassMetadata calls for ES5 bundles (#27438)

ngcc would feed ngtsc with the function declaration inside of an IIFE as
that is considered the class symbol's declaration node, according to
TypeScript's `ts.Symbol.valueDeclaration`. ngtsc however only considered
variable decls and actual class decls as potential class declarations,
so given the function declaration node it would fail to generate the
`setClassMetadata` call.

ngtsc no longer makes its own assumptions about what classes look like,
but always asks the reflection host to yield this kind of information.

PR Close #27438
This commit is contained in:
JoostK
2018-12-04 22:10:37 +01:00
committed by Miško Hevery
parent 84084b1bdb
commit 52544ffaa3
5 changed files with 8 additions and 13 deletions

View File

@ -20,10 +20,7 @@ import {CtorParameter, Decorator, ReflectionHost} from '../../host';
*/
export function generateSetClassMetadataCall(
clazz: ts.Declaration, reflection: ReflectionHost, isCore: boolean): Statement|null {
// Classes come in two flavors, class declarations (ES2015) and variable declarations (ES5).
// Both must have a declared name to have metadata set on them.
if ((!ts.isClassDeclaration(clazz) && !ts.isVariableDeclaration(clazz)) ||
clazz.name === undefined || !ts.isIdentifier(clazz.name)) {
if (!reflection.isClass(clazz) || clazz.name === undefined || !ts.isIdentifier(clazz.name)) {
return null;
}
const id = ts.updateIdentifier(clazz.name);