refactor(compiler): don’t write summaries for jit by default

The default is false externally but true internally at Google.
This commit is contained in:
Tobias Bosch 2017-06-09 14:00:03 -07:00 committed by Alex Rickabaugh
parent d56b7ed96d
commit 90b0713e32
11 changed files with 79 additions and 12 deletions

View File

@ -3,7 +3,8 @@
// For TypeScript 1.8, we have to lay out generated files
// in the same source directory with your code.
"genDir": ".",
"debug": true
"debug": true,
"enableSummariesForJit": true
},
"compilerOptions": {

View File

@ -100,6 +100,7 @@ export class CodeGenerator {
i18nFormat: cliOptions.i18nFormat,
locale: cliOptions.locale, missingTranslation,
enableLegacyTemplate: options.enableLegacyTemplate !== false,
enableSummariesForJit: options.enableSummariesForJit !== false,
});
return new CodeGenerator(options, program, tsCompilerHost, aotCompiler, ngCompilerHost);
}

View File

@ -20,6 +20,10 @@ import {CodeGenerator} from './codegen';
function codegen(
ngOptions: tsc.AngularCompilerOptions, cliOptions: tsc.NgcCliOptions, program: ts.Program,
host: ts.CompilerHost) {
if (ngOptions.enableSummariesForJit === undefined) {
// default to false
ngOptions.enableSummariesForJit = false;
}
return CodeGenerator.create(ngOptions, cliOptions, program, host).codegen();
}

View File

@ -99,10 +99,15 @@ export class NgTools_InternalApi_NG_2 {
missingTranslation: options.missingTranslation !,
basePath: options.basePath
};
const ngOptions = options.angularCompilerOptions;
if (ngOptions.enableSummariesForJit === undefined) {
// default to false
ngOptions.enableSummariesForJit = false;
}
// Create the Code Generator.
const codeGenerator = CodeGenerator.create(
options.angularCompilerOptions, cliOptions, options.program, options.host, hostContext);
const codeGenerator =
CodeGenerator.create(ngOptions, cliOptions, options.program, options.host, hostContext);
return codeGenerator.codegen();
}

View File

@ -25,7 +25,7 @@ function compile(
return ngChecker.getDiagnostics();
}
fdescribe('ng type checker', () => {
describe('ng type checker', () => {
let angularFiles = setup();
function accept(...files: MockDirectory[]) {

View File

@ -261,5 +261,52 @@ describe('compiler-cli', () => {
})
.catch(e => done.fail(e));
});
it('should not produce ngsummary files by default', (done) => {
writeConfig(`{
"extends": "./tsconfig-base.json",
"files": ["mymodule.ts"]
}`);
write('mymodule.ts', `
import {NgModule} from '@angular/core';
@NgModule()
export class MyModule {}
`);
main({p: basePath})
.then((exitCode) => {
expect(exitCode).toEqual(0);
expect(fs.existsSync(path.resolve(outDir, 'mymodule.ngsummary.js'))).toBe(false);
done();
})
.catch(e => done.fail(e));
});
it('should produce ngsummary files if configured', (done) => {
writeConfig(`{
"extends": "./tsconfig-base.json",
"files": ["mymodule.ts"],
"angularCompilerOptions": {
"enableSummariesForJit": true
}
}`);
write('mymodule.ts', `
import {NgModule} from '@angular/core';
@NgModule()
export class MyModule {}
`);
main({p: basePath})
.then((exitCode) => {
expect(exitCode).toEqual(0);
expect(fs.existsSync(path.resolve(outDir, 'mymodule.ngsummary.js'))).toBe(true);
done();
})
.catch(e => done.fail(e));
});
});
});

View File

@ -35,7 +35,8 @@ export class AotCompiler {
private _viewCompiler: ViewCompiler, private _ngModuleCompiler: NgModuleCompiler,
private _outputEmitter: OutputEmitter,
private _summaryResolver: SummaryResolver<StaticSymbol>, private _localeId: string|null,
private _translationFormat: string|null, private _symbolResolver: StaticSymbolResolver) {}
private _translationFormat: string|null, private _enableSummariesForJit: boolean|null,
private _symbolResolver: StaticSymbolResolver) {}
clearCache() { this._metadataResolver.clearCache(); }
@ -204,10 +205,12 @@ export class AotCompiler {
o.StmtModifier.Exported
]));
});
return [
new GeneratedFile(srcFileUrl, summaryFileName(srcFileUrl), json),
this._codegenSourceModule(srcFileUrl, forJitOutputCtx)
];
const summaryJson = new GeneratedFile(srcFileUrl, summaryFileName(srcFileUrl), json);
if (this._enableSummariesForJit) {
return [summaryJson, this._codegenSourceModule(srcFileUrl, forJitOutputCtx)];
};
return [summaryJson];
}
private _compileModule(outputCtx: OutputContext, ngModuleType: StaticSymbol): void {

View File

@ -70,6 +70,7 @@ export function createAotCompiler(compilerHost: AotCompilerHost, options: AotCom
const compiler = new AotCompiler(
config, compilerHost, staticReflector, resolver, tmplParser, new StyleCompiler(urlResolver),
viewCompiler, new NgModuleCompiler(staticReflector), new TypeScriptEmitter(), summaryResolver,
options.locale || null, options.i18nFormat || null, symbolResolver);
options.locale || null, options.i18nFormat || null, options.enableSummariesForJit || null,
symbolResolver);
return {compiler, reflector: staticReflector};
}

View File

@ -14,4 +14,5 @@ export interface AotCompilerOptions {
translations?: string;
missingTranslation?: MissingTranslationStrategy;
enableLegacyTemplate?: boolean;
enableSummariesForJit?: boolean
}

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AotCompiler, AotCompilerHost, AotCompilerOptions, CompileSummaryKind, GeneratedFile, createAotCompiler, toTypeScript} from '@angular/compiler';
import {AotCompiler, AotCompilerHost, AotCompilerOptions, CompileSummaryKind, GeneratedFile, toTypeScript} from '@angular/compiler';
import {MockDirectory, compile, setup} from './test_util';
@ -15,7 +15,7 @@ describe('aot summaries for jit', () => {
function compileApp(rootDir: MockDirectory, options: {useSummaries?: boolean} = {}):
{genFiles: GeneratedFile[], outDir: MockDirectory} {
return compile([rootDir, angularFiles], options);
return compile([rootDir, angularFiles], {...options, enableSummariesForJit: true});
}
it('should create @Injectable summaries', () => {

View File

@ -81,6 +81,10 @@ interface Options extends ts.CompilerOptions {
// Whether to enable support for <template> and the template attribute (true by default)
enableLegacyTemplate?: boolean;
// Whether to generate .ngsummary.ts files that allow to use AOTed artifacts
// in JIT mode.
enableSummariesForJit?: boolean;
}
export default Options;