-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(ivy): first pass at extracting ReflectionHost for abstract reflection #24541
Conversation
You can preview fa66f9a at https://pr24541-fa66f9a.ngbuilds.io/. |
You can preview f9f98fa at https://pr24541-f9f98fa.ngbuilds.io/. |
You can preview 97f14a2 at https://pr24541-97f14a2.ngbuilds.io/. |
args: ts.Expression[]; | ||
} | ||
export class TypeScriptReflectionHost implements ReflectionHost { | ||
constructor(private checker: ts.TypeChecker) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make checker
"protected" so that we can inherit from TypeScriptReflectionHost
more easily.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I'm in general nervous about this - it's not in TypeScriptReflectionHost
's contract to support ES6 code.
if (analysis.analysis !== undefined) { | ||
this.analysis.set(node, { | ||
adapter, | ||
analysis: analysis.analysis, decorator, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this needs a little more analysis 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, it could use a little more... ;)
]), | ||
module_name = "@angular/compiler-cli/src/ngtsc/host", | ||
deps = [ | ||
"//packages/compiler", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just like slow builds.
Removed ;)
private _readSelectorFromCompiledClass(clazz: ts.Declaration): string|null { | ||
const def = this.reflector.getMembersOfClass(clazz).find( | ||
field => | ||
field.isStatic && (field.name === 'ngComponentDef' || field.name === 'ngDirectiveDef')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not possible for a class to have both decorators, right?
(Probably isn't; just checking 😃)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, it's not.
constructor(private checker: ts.TypeChecker, private scopeRegistry: SelectorScopeRegistry) {} | ||
constructor( | ||
private checker: ts.TypeChecker, private reflector: ReflectionHost, | ||
private scopeRegistry: SelectorScopeRegistry, ) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing comma (or missing newline) 😱
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0️⃣days since clang-format made code less readable
…eflection ngtsc needs to reflect over code to property compile it. It performs operations such as enumerating decorators on a type, reading metadata from constructor parameters, etc. Depending on the format (ES5, ES6, etc) of the underlying code, the AST structures over which this reflection takes place can be very different. For example, in TS/ES6 code `class` declarations are `ts.ClassDeclaration` nodes, but in ES5 code they've been downleveled to `ts.VariableDeclaration` nodes that are initialized to IIFEs that build up the classes being defined. The ReflectionHost abstraction allows ngtsc to perform these operations without directly querying the AST. Different implementations of ReflectionHost allow support for different code formats.
You can preview 4583e3c at https://pr24541-4583e3c.ngbuilds.io/. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
ngtsc needs to reflect over code to property compile it. It performs operations
such as enumerating decorators on a type, reading metadata from constructor
parameters, etc.
Depending on the format (ES5, ES6, etc) of the underlying code, the AST
structures over which this reflection takes place can be very different. For
example, in TS/ES6 code
class
declarations arets.ClassDeclaration
nodes,but in ES5 code they've been downleveled to
ts.VariableDeclaration
nodes thatare initialized to IIFEs that build up the classes being defined.
The ReflectionHost abstraction allows ngtsc to perform these operations without
directly querying the AST. Different implementations of ReflectionHost allow
support for different code formats.
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information