fix(ivy): fix issues found producing "Hello, World" example (#21790)
PR Close #21790
This commit is contained in:
parent
87754ad5ec
commit
5778bb820a
|
@ -1878,5 +1878,68 @@ describe('ngc transformer command-line', () => {
|
|||
expect(exitCode).toBe(0, 'Compile failed');
|
||||
expect(emittedFile('hello-world.js')).toContain('ngComponentDef');
|
||||
});
|
||||
|
||||
it('should emit an injection of a string token', () => {
|
||||
write('tsconfig.json', `{
|
||||
"extends": "./tsconfig-base.json",
|
||||
"files": ["hello-world.ts"],
|
||||
"angularCompilerOptions": {
|
||||
"enableIvy": true
|
||||
}
|
||||
}`);
|
||||
|
||||
write('hello-world.ts', `
|
||||
import {Component, Inject, NgModule} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'hello-world',
|
||||
template: 'Hello, world!'
|
||||
})
|
||||
export class HelloWorldComponent {
|
||||
constructor (@Inject('test') private test: string) {}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [HelloWorldComponent],
|
||||
providers: [
|
||||
{provide: 'test', useValue: 'test'}
|
||||
]
|
||||
})
|
||||
export class HelloWorldModule {}
|
||||
`);
|
||||
const errors: string[] = [];
|
||||
const exitCode = main(['-p', path.join(basePath, 'tsconfig.json')], msg => errors.push(msg));
|
||||
expect(exitCode).toBe(0, `Compile failed:\n${errors.join('\n ')}`);
|
||||
expect(emittedFile('hello-world.js')).toContain('ngComponentDef');
|
||||
});
|
||||
|
||||
it('should emit an example that uses the E() instruction', () => {
|
||||
write('tsconfig.json', `{
|
||||
"extends": "./tsconfig-base.json",
|
||||
"files": ["hello-world.ts"],
|
||||
"angularCompilerOptions": {
|
||||
"enableIvy": true
|
||||
}
|
||||
}`);
|
||||
|
||||
write('hello-world.ts', `
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'hello-world',
|
||||
template: '<h1><div style="text-align:center"> Hello, {{name}}! </div></h1> '
|
||||
})
|
||||
export class HelloWorldComponent {
|
||||
name = 'World';
|
||||
}
|
||||
|
||||
@NgModule({declarations: [HelloWorldComponent]})
|
||||
export class HelloWorldModule {}
|
||||
`);
|
||||
const errors: string[] = [];
|
||||
const exitCode = main(['-p', path.join(basePath, 'tsconfig.json')], msg => errors.push(msg));
|
||||
expect(exitCode).toBe(0, `Compile failed:\n${errors.join('\n ')}`);
|
||||
expect(emittedFile('hello-world.js')).toContain('ngComponentDef');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -27,7 +27,7 @@ class FixupExpression extends o.Expression {
|
|||
shared: boolean;
|
||||
|
||||
visitExpression(visitor: o.ExpressionVisitor, context: any): any {
|
||||
this.resolved.visitExpression(visitor, context);
|
||||
return this.resolved.visitExpression(visitor, context);
|
||||
}
|
||||
|
||||
isEquivalent(e: o.Expression): boolean {
|
||||
|
|
|
@ -140,7 +140,7 @@ function unsupported(feature: string): never {
|
|||
if (this) {
|
||||
throw new Error(`Builder ${this.constructor.name} doesn't support ${feature} yet`);
|
||||
}
|
||||
throw new Error(`Feature ${feature} is supported yet`);
|
||||
throw new Error(`Feature ${feature} is not supported yet`);
|
||||
}
|
||||
|
||||
const BINDING_INSTRUCTION_MAP: {[index: number]: o.ExternalReference | undefined} = {
|
||||
|
@ -571,7 +571,9 @@ function createFactory(
|
|||
} else if (tokenRef === viewContainerRef) {
|
||||
args.push(o.importExpr(R3.injectViewContainerRef).callFn([]));
|
||||
} else {
|
||||
args.push(o.importExpr(R3.inject).callFn([outputCtx.importExpr(token)]));
|
||||
const value =
|
||||
token.identifier != null ? outputCtx.importExpr(tokenRef) : o.literal(tokenRef);
|
||||
args.push(o.importExpr(R3.inject).callFn([value]));
|
||||
}
|
||||
} else {
|
||||
unsupported('dependency without a token');
|
||||
|
|
Loading…
Reference in New Issue