fix(compiler): fix two existing expression transformer issues (#28523)

Testing of Ivy revealed two bugs in the AstMemoryEfficientTransformer
class, a part of existing View Engine compiler infrastructure that's
reused in Ivy. These bugs cause AST expressions not to be transformed
under certain circumstances.

The fix is simple, and tests are added to ensure the specific expression
forms that trigger the issue compile properly under Ivy.

PR Close #28523
This commit is contained in:
Alex Rickabaugh 2019-01-31 14:19:29 -08:00 committed by Misko Hevery
parent dba2a406fd
commit 09af7ea4f5
2 changed files with 46 additions and 2 deletions

View File

@ -624,6 +624,49 @@ describe('ngtsc behavioral tests', () => {
'i0.ɵNgModuleDefWithMeta<TestModule, [typeof TestPipe, typeof TestCmp], never, never>'); 'i0.ɵNgModuleDefWithMeta<TestModule, [typeof TestPipe, typeof TestCmp], never, never>');
}); });
describe('former View Engine AST transform bugs', () => {
it('should compile array literals behind conditionals', () => {
env.tsconfig();
env.write('test.ts', `
import {Component} from '@angular/core';
@Component({
selector: 'test',
template: '{{value ? "yes" : [no]}}',
})
class TestCmp {
value = true;
no = 'no';
}
`);
env.driveMain();
expect(env.getContents('test.js')).toContain('i0.ɵpureFunction1');
});
it('should compile array literals inside function arguments', () => {
env.tsconfig();
env.write('test.ts', `
import {Component} from '@angular/core';
@Component({
selector: 'test',
template: '{{fn([test])}}',
})
class TestCmp {
fn(arg: any): string {
return 'test';
}
test = 'test';
}
`);
env.driveMain();
expect(env.getContents('test.js')).toContain('i0.ɵpureFunction1');
});
});
describe('unwrapping ModuleWithProviders functions', () => { describe('unwrapping ModuleWithProviders functions', () => {
it('should extract the generic type and include it in the module\'s declaration', () => { it('should extract the generic type and include it in the module\'s declaration', () => {
env.tsconfig(); env.tsconfig();

View File

@ -477,8 +477,9 @@ export class AstMemoryEfficientTransformer implements AstVisitor {
visitMethodCall(ast: MethodCall, context: any): AST { visitMethodCall(ast: MethodCall, context: any): AST {
const receiver = ast.receiver.visit(this); const receiver = ast.receiver.visit(this);
if (receiver !== ast.receiver) { const args = this.visitAll(ast.args);
return new MethodCall(ast.span, receiver, ast.name, this.visitAll(ast.args)); if (receiver !== ast.receiver || args !== ast.args) {
return new MethodCall(ast.span, receiver, ast.name, args);
} }
return ast; return ast;
} }