fix(ivy): include type parameter for ngBaseDef
declaration (#31210)
When a class uses Angular decorators such as `@Input`, `@Output` and friends without an Angular class decorator, they are compiled into a static `ngBaseDef` field on the class, with the TypeScript declaration of the class being altered to declare the `ngBaseDef` field to be of type `ɵɵBaseDef`. This type however requires a generic type parameter that corresponds with the type of the class, however the compiler did not provide this type parameter. As a result, compiling a program where such invalid `ngBaseDef` declarations are present will result in compilation errors. This commit fixes the problem by providing the generic type parameter. Fixes #31160 PR Close #31210
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {ConstantPool, R3BaseRefMetaData, compileBaseDefFromMetadata, makeBindingParser} from '@angular/compiler';
|
||||
import {ConstantPool, R3BaseRefMetaData, WrappedNodeExpr, compileBaseDefFromMetadata, makeBindingParser} from '@angular/compiler';
|
||||
|
||||
import {PartialEvaluator} from '../../partial_evaluator';
|
||||
import {ClassDeclaration, ClassMember, Decorator, ReflectionHost} from '../../reflection';
|
||||
@ -91,7 +91,11 @@ export class BaseDefDecoratorHandler implements
|
||||
|
||||
analyze(node: ClassDeclaration, metadata: R3BaseRefDecoratorDetection):
|
||||
AnalysisOutput<R3BaseRefMetaData> {
|
||||
const analysis: R3BaseRefMetaData = {name: node.name.text, typeSourceSpan: null !};
|
||||
const analysis: R3BaseRefMetaData = {
|
||||
name: node.name.text,
|
||||
type: new WrappedNodeExpr(node.name),
|
||||
typeSourceSpan: null !
|
||||
};
|
||||
|
||||
if (metadata.inputs) {
|
||||
const inputs = analysis.inputs = {} as{[key: string]: string | [string, string]};
|
||||
|
@ -423,6 +423,24 @@ runInEachFileSystem(os => {
|
||||
expect(jsContents).toContain('background-color: blue');
|
||||
});
|
||||
|
||||
it('should include generic type for ngBaseDef declarations', () => {
|
||||
env.write('test.ts', `
|
||||
import {Component, Input, NgModule} from '@angular/core';
|
||||
|
||||
export class TestBase {
|
||||
@Input() input: any;
|
||||
}
|
||||
`);
|
||||
|
||||
env.driveMain();
|
||||
|
||||
const jsContents = env.getContents('test.js');
|
||||
expect(jsContents).toContain('i0.ɵɵdefineBase({ inputs: { input: "input" } });');
|
||||
|
||||
const dtsContents = env.getContents('test.d.ts');
|
||||
expect(dtsContents).toContain('static ngBaseDef: i0.ɵɵBaseDef<TestBase>');
|
||||
});
|
||||
|
||||
it('should compile NgModules without errors', () => {
|
||||
env.write('test.ts', `
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
Reference in New Issue
Block a user