diff --git a/packages/compiler-cli/test/ngc_spec.ts b/packages/compiler-cli/test/ngc_spec.ts
index 0bd7a62314..834e87d6d3 100644
--- a/packages/compiler-cli/test/ngc_spec.ts
+++ b/packages/compiler-cli/test/ngc_spec.ts
@@ -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: '
Hello, {{name}}!
'
+ })
+ 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');
+ });
});
});
diff --git a/packages/compiler/src/constant_pool.ts b/packages/compiler/src/constant_pool.ts
index 06ff1004d1..0775bacf97 100644
--- a/packages/compiler/src/constant_pool.ts
+++ b/packages/compiler/src/constant_pool.ts
@@ -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 {
diff --git a/packages/compiler/src/render3/r3_view_compiler.ts b/packages/compiler/src/render3/r3_view_compiler.ts
index 9bdd343020..647a4784b5 100644
--- a/packages/compiler/src/render3/r3_view_compiler.ts
+++ b/packages/compiler/src/render3/r3_view_compiler.ts
@@ -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');