Skip to content

Commit

Permalink
fix(compiler-cli): adapt for removal of tsickle
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Aug 24, 2018
1 parent 93085dd commit e36d92f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
44 changes: 28 additions & 16 deletions packages/compiler-cli/src/main.ts
Expand Up @@ -63,22 +63,34 @@ function createEmitCallback(options: api.CompilerOptions): api.TsEmitCallback|un
convertIndexImportShorthand: false, transformDecorators, transformTypesToClosure,
};

return ({
program,
targetSourceFile,
writeFile,
cancellationToken,
emitOnlyDtsFiles,
customTransformers = {},
host,
options
}) =>
tsickle.emitWithTsickle(
program, {...tsickleHost, options, host}, host, options, targetSourceFile,
writeFile, cancellationToken, emitOnlyDtsFiles, {
beforeTs: customTransformers.before,
afterTs: customTransformers.after,
});
if (options.annotateForClosureCompiler || options.annotationsAs === 'static fields') {
return ({
program,
targetSourceFile,
writeFile,
cancellationToken,
emitOnlyDtsFiles,
customTransformers = {},
host,
options
}) =>
// tslint:disable-next-line:no-require-imports only depend on tsickle if requested
require('tsickle').emitWithTsickle(
program, {...tsickleHost, options, host}, host, options, targetSourceFile,
writeFile, cancellationToken, emitOnlyDtsFiles, {
beforeTs: customTransformers.before,
afterTs: customTransformers.after,
});
} else {
return ({
program,
targetSourceFile,
writeFile,
cancellationToken,
emitOnlyDtsFiles,
customTransformers = {},
}) => program.emit(targetSourceFile, writeFile, cancellationToken, emitOnlyDtsFiles, {after: customTransformers.after, before: customTransformers.before});
}
}

export interface NgcParsedConfiguration extends ParsedConfiguration { watch?: boolean; }
Expand Down
19 changes: 10 additions & 9 deletions packages/compiler-cli/test/ngc_spec.ts
Expand Up @@ -554,10 +554,10 @@ describe('ngc transformer command-line', () => {
});

describe('closure', () => {
it('should not generate closure specific code by default', () => {
it('should not run tsickle by default', () => {
writeConfig(`{
"extends": "./tsconfig-base.json",
"files": ["mymodule.ts"]
"files": ["mymodule.ts"],
}`);
write('mymodule.ts', `
import {NgModule, Component} from '@angular/core';
Expand All @@ -575,7 +575,8 @@ describe('ngc transformer command-line', () => {
const mymodulejs = path.resolve(outDir, 'mymodule.js');
const mymoduleSource = fs.readFileSync(mymodulejs, 'utf8');
expect(mymoduleSource).not.toContain('@fileoverview added by tsickle');
expect(mymoduleSource).toContain('MyComp.decorators = [');
expect(mymoduleSource).toContain('MyComp = __decorate');
expect(mymoduleSource).not.toContain('MyComp.decorators = [');
});

it('should add closure annotations', () => {
Expand Down Expand Up @@ -873,7 +874,7 @@ describe('ngc transformer command-line', () => {
write('mymodule.ts', `
import {Component, NgModule} from '@angular/core';
import {RouterModule} from '@angular/router';
export function foo(): string {
console.log('side-effect');
return 'test';
Expand Down Expand Up @@ -2373,7 +2374,7 @@ describe('ngc transformer command-line', () => {
}
}`);
write('service.ts', `
import {Injectable, Self} from '@angular/core';
import {Injectable, Self} from '@angular/core';
@Injectable()
export class ServiceA {}
Expand All @@ -2388,10 +2389,10 @@ describe('ngc transformer command-line', () => {

const modulePath = path.resolve(outDir, 'service.js');
const moduleSource = fs.readFileSync(modulePath, 'utf8');
expect(moduleSource).not.toMatch(/ServiceA\.decorators =/);
expect(moduleSource).toMatch(/ServiceB\.decorators =/);
expect(moduleSource).toMatch(/type: Self/);
expect(moduleSource).not.toMatch(/type: Injectable/);
expect(moduleSource).toMatch(/ServiceA = __decorate/);
expect(moduleSource).not.toMatch(/ServiceB == __decorate/);
expect(moduleSource).not.toMatch(/Self\(\)/);
expect(moduleSource).toMatch(/Injectable\(\)/);
});

it('rewrites Injector to INJECTOR in Ivy factory functions ', () => {
Expand Down

0 comments on commit e36d92f

Please sign in to comment.