fix(compiler-cli): fix and re-enble expression lowering (#18570)

Fixes issue uncovered by #18388 and re-enables expression
lowering disabled by #18513.
This commit is contained in:
Chuck Jazdzewski
2017-08-08 12:40:08 -07:00
committed by Victor Berchet
parent f0a55016af
commit 6f2038cc85
4 changed files with 80 additions and 15 deletions

View File

@ -12,7 +12,7 @@ import * as path from 'path';
import * as ts from 'typescript';
import {main} from '../src/ngc';
import {performCompilation} from '../src/perform-compile';
import {performCompilation, readConfiguration} from '../src/perform-compile';
function getNgRootDir() {
const moduleFilename = module.filename.replace(/\\/g, '/');
@ -316,7 +316,7 @@ describe('ngc command-line', () => {
.toBe(true);
});
xdescribe('expression lowering', () => {
describe('expression lowering', () => {
beforeEach(() => {
writeConfig(`{
"extends": "./tsconfig-base.json",
@ -424,13 +424,35 @@ describe('ngc command-line', () => {
})
export class MyModule {}
`);
expect(compile()).toEqual(0);
expect(compile()).toEqual(0, 'Compile failed');
const mymodulejs = path.resolve(outDir, 'mymodule.js');
const mymoduleSource = fs.readFileSync(mymodulejs, 'utf8');
expect(mymoduleSource).toContain('var ɵ0 = function () { return new Foo(); }');
expect(mymoduleSource).toContain('export { ɵ0');
});
it('should not lower a lambda that is already exported', () => {
write('mymodule.ts', `
import {CommonModule} from '@angular/common';
import {NgModule} from '@angular/core';
class Foo {}
export const factory = () => new Foo();
@NgModule({
imports: [CommonModule],
providers: [{provide: 'someToken', useFactory: factory}]
})
export class MyModule {}
`);
expect(compile()).toEqual(0);
const mymodulejs = path.resolve(outDir, 'mymodule.js');
const mymoduleSource = fs.readFileSync(mymodulejs, 'utf8');
expect(mymoduleSource).not.toContain('ɵ0');
});
});
const shouldExist = (fileName: string) => {

View File

@ -51,11 +51,9 @@ function convert(annotatedSource: string) {
for (const annotation of annotations) {
const node = findNode(sourceFile, annotation.start, annotation.length);
expect(node).toBeDefined();
if (node) {
const location = node.pos;
requests.set(location, {name: annotation.name, kind: node.kind, location, end: node.end});
}
if (!node) throw new Error('Invalid test specification. Could not find the node to substitute');
const location = node.pos;
requests.set(location, {name: annotation.name, kind: node.kind, location, end: node.end});
}
const program = ts.createProgram(