Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upfix(ngcc): properly detect origin of constructor param types #33901
Conversation
if (typeExpression !== null) { | ||
// `typeExpression` is an expression in a "type" context. Resolve it to a declared value. | ||
// Either it's a reference to an imported type, or a type declared locally. Distinguish the | ||
// to cases with `getDeclarationOfExpression`. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
// to cases with `getDeclarationOfExpression`. | ||
const decl = this.getDeclarationOfExpression(typeExpression); | ||
if (decl !== null && decl.node !== null && decl.viaModule !== null && | ||
isNamedDeclaration(decl.node)) { |
This comment has been minimized.
This comment has been minimized.
petebacondarwin
Nov 18, 2019
Member
Can it be possible that viaModule !== null && !isNamedDeclaration(decl.node)
?
If so, what does that mean? As this stands, we will return a "local" reference instead.
This comment has been minimized.
This comment has been minimized.
alxhub
Nov 18, 2019
Author
Contributor
I don't think it's generally possible, since a declaration has to have a name to be exported in the first place. You could probably contrive some example where it's true (export default 42
?) but in general I think a fallback option of "this could not be understood as a sane import, so just use the local identifier instead" is sane.
defaultImportStatement: null | ||
}; | ||
} | ||
} |
This comment has been minimized.
This comment has been minimized.
petebacondarwin
Nov 18, 2019
Member
NIT: this block of code is a candidate for a new private method, to keep the size of this method lean.
return {
name: getNameText(nameNode),
nameNode,
typeValueReference: this.getTypeValueReference(typeExpression),
typeNode: null,
decorators,
};
This comment has been minimized.
This comment has been minimized.
alxhub
Nov 18, 2019
Author
Contributor
Yeah, in general we should consider "constructor" methods for more complex types like this.
The ReflectionHost supports enumeration of constructor parameters, and one piece of information it returns describes the origin of the parameter's type. Parameter types come in two flavors: local (the type is not imported from anywhere) or non-local (the type comes via an import). ngcc incorrectly classified all type parameters as 'local', because in the source files that ngcc processes the type parameter is a real ts.Identifer. However, that identifier may still have come from an import and thus might be non-local. This commit changes ngcc's ReflectionHost(s) to properly recognize and report these non-local type references. Fixes #33677
The ReflectionHost supports enumeration of constructor parameters, and one piece of information it returns describes the origin of the parameter's type. Parameter types come in two flavors: local (the type is not imported from anywhere) or non-local (the type comes via an import). ngcc incorrectly classified all type parameters as 'local', because in the source files that ngcc processes the type parameter is a real ts.Identifer. However, that identifier may still have come from an import and thus might be non-local. This commit changes ngcc's ReflectionHost(s) to properly recognize and report these non-local type references. Fixes #33677 PR Close #33901
alxhub commentedNov 18, 2019
The ReflectionHost supports enumeration of constructor parameters, and one
piece of information it returns describes the origin of the parameter's
type. Parameter types come in two flavors: local (the type is not imported
from anywhere) or non-local (the type comes via an import).
ngcc incorrectly classified all type parameters as 'local', because in the
source files that ngcc processes the type parameter is a real ts.Identifer.
However, that identifier may still have come from an import and thus might
be non-local.
This commit changes ngcc's ReflectionHost(s) to properly recognize and
report these non-local type references.
Fixes #33677