Skip to content

Commit

Permalink
refactor(compiler): split compiler and core
Browse files Browse the repository at this point in the history
After this, neither @angular/compiler nor @angular/comnpiler-cli depend
on @angular/core.

This add a duplication of some interfaces and enums which is stored
in @angular/compiler/src/core.ts
  • Loading branch information
tbosch committed Aug 16, 2017
1 parent ef91f15 commit 0aefd15
Show file tree
Hide file tree
Showing 115 changed files with 1,779 additions and 1,700 deletions.
2 changes: 1 addition & 1 deletion packages/common/test/pipes/date_pipe_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

import {DatePipe} from '@angular/common';
import {JitReflector} from '@angular/compiler';
import {PipeResolver} from '@angular/compiler/src/pipe_resolver';
import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector';
import {browserDetection} from '@angular/platform-browser/testing/src/browser_util';

export function main() {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/pipes/i18n_plural_pipe_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/

import {I18nPluralPipe, NgLocalization} from '@angular/common';
import {JitReflector} from '@angular/compiler';
import {PipeResolver} from '@angular/compiler/src/pipe_resolver';
import {beforeEach, describe, expect, it} from '@angular/core/testing/src/testing_internal';
import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector';

export function main() {
describe('I18nPluralPipe', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/test/pipes/i18n_select_pipe_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*/

import {I18nSelectPipe} from '@angular/common';
import {JitReflector} from '@angular/compiler';
import {PipeResolver} from '@angular/compiler/src/pipe_resolver';
import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector';

export function main() {
describe('I18nSelectPipe', () => {
Expand Down
1 change: 0 additions & 1 deletion packages/compiler-cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ ts_library(
module_name = "@angular/compiler-cli",
deps = [
"//packages/compiler",
"//packages/core",
"//packages/tsc-wrapped",
],
tsconfig = ":tsconfig-build.json",
Expand Down
3 changes: 1 addition & 2 deletions packages/compiler-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
},
"peerDependencies": {
"typescript": "^2.0.2",
"@angular/compiler": "0.0.0-PLACEHOLDER",
"@angular/core": "0.0.0-PLACEHOLDER"
"@angular/compiler": "0.0.0-PLACEHOLDER"
},
"repository": {
"type": "git",
Expand Down
11 changes: 5 additions & 6 deletions packages/compiler-cli/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
* Intended to be used in a build step.
*/
import * as compiler from '@angular/compiler';
import {MissingTranslationStrategy} from '@angular/core';
import {AngularCompilerOptions, NgcCliOptions} from '@angular/tsc-wrapped';
import {readFileSync} from 'fs';
import * as ts from 'typescript';
Expand Down Expand Up @@ -78,25 +77,25 @@ export class CodeGenerator {
}
transContent = readFileSync(cliOptions.i18nFile, 'utf8');
}
let missingTranslation = MissingTranslationStrategy.Warning;
let missingTranslation = compiler.core.MissingTranslationStrategy.Warning;
if (cliOptions.missingTranslation) {
switch (cliOptions.missingTranslation) {
case 'error':
missingTranslation = MissingTranslationStrategy.Error;
missingTranslation = compiler.core.MissingTranslationStrategy.Error;
break;
case 'warning':
missingTranslation = MissingTranslationStrategy.Warning;
missingTranslation = compiler.core.MissingTranslationStrategy.Warning;
break;
case 'ignore':
missingTranslation = MissingTranslationStrategy.Ignore;
missingTranslation = compiler.core.MissingTranslationStrategy.Ignore;
break;
default:
throw new Error(
`Unknown option for missingTranslation (${cliOptions.missingTranslation}). Use either error, warning or ignore.`);
}
}
if (!transContent) {
missingTranslation = MissingTranslationStrategy.Ignore;
missingTranslation = compiler.core.MissingTranslationStrategy.Ignore;
}
const {compiler: aotCompiler} = compiler.createAotCompiler(ngCompilerHost, {
translations: transContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import {AotSummaryResolver, CompileMetadataResolver, CompilePipeSummary, CompilerConfig, DEFAULT_INTERPOLATION_CONFIG, DirectiveNormalizer, DirectiveResolver, DomElementSchemaRegistry, HtmlParser, InterpolationConfig, NgAnalyzedModules, NgModuleResolver, ParseTreeResult, PipeResolver, ResourceLoader, StaticReflector, StaticSymbol, StaticSymbolCache, StaticSymbolResolver, SummaryResolver, analyzeNgModules, extractProgramSymbols} from '@angular/compiler';
import {ViewEncapsulation, ɵConsole as Console} from '@angular/core';
import * as fs from 'fs';
import * as path from 'path';
import * as ts from 'typescript';
Expand Down
10 changes: 6 additions & 4 deletions packages/compiler-cli/src/ngtools_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* This API should be stable for NG 2. It can be removed in NG 4..., but should be replaced by
* something else.
*/
import {AotCompilerHost, StaticReflector, StaticSymbol} from '@angular/compiler';
import {NgModule} from '@angular/core';
import {AotCompilerHost, MetadataIdentifier, StaticReflector, StaticSymbol, core} from '@angular/compiler';


// We cannot depend directly to @angular/router.
type Route = any;
Expand Down Expand Up @@ -168,8 +168,10 @@ function _extractLazyRoutesFromStaticModule(
/**
* Get the NgModule Metadata of a symbol.
*/
function _getNgModuleMetadata(staticSymbol: StaticSymbol, reflector: StaticReflector): NgModule {
const ngModules = reflector.annotations(staticSymbol).filter((s: any) => s instanceof NgModule);
function _getNgModuleMetadata(
staticSymbol: StaticSymbol, reflector: StaticReflector): core.NgModule {
const ngModules = reflector.annotations(staticSymbol)
.filter((s: any) => MetadataIdentifier.NgModule.isTypeOfMetadata(s));
if (ngModules.length === 0) {
throw new Error(`${staticSymbol.name} is not an NgModule`);
}
Expand Down
11 changes: 5 additions & 6 deletions packages/compiler-cli/src/transformers/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {AotCompiler, AotCompilerHost, AotCompilerOptions, GeneratedFile, NgAnalyzedModules, createAotCompiler, getParseErrors, isSyntaxError, toTypeScript} from '@angular/compiler';
import {MissingTranslationStrategy} from '@angular/core';
import {AotCompiler, AotCompilerHost, AotCompilerOptions, GeneratedFile, NgAnalyzedModules, core, createAotCompiler, getParseErrors, isSyntaxError, toTypeScript} from '@angular/compiler';
import {createBundleIndexHost} from '@angular/tsc-wrapped';
import * as fs from 'fs';
import * as path from 'path';
Expand Down Expand Up @@ -337,14 +336,14 @@ export function createProgram(

// Compute the AotCompiler options
function getAotCompilerOptions(options: CompilerOptions): AotCompilerOptions {
let missingTranslation = MissingTranslationStrategy.Warning;
let missingTranslation = core.MissingTranslationStrategy.Warning;

switch (options.i18nInMissingTranslations) {
case 'ignore':
missingTranslation = MissingTranslationStrategy.Ignore;
missingTranslation = core.MissingTranslationStrategy.Ignore;
break;
case 'error':
missingTranslation = MissingTranslationStrategy.Error;
missingTranslation = core.MissingTranslationStrategy.Error;
break;
}

Expand All @@ -358,7 +357,7 @@ function getAotCompilerOptions(options: CompilerOptions): AotCompilerOptions {
} else {
// No translations are provided, ignore any errors
// We still go through i18n to remove i18n attributes
missingTranslation = MissingTranslationStrategy.Ignore;
missingTranslation = core.MissingTranslationStrategy.Ignore;
}

return {
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-cli/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Entry point for all public APIs of the common package.
*/

import {Version} from '@angular/core';
import {Version} from '@angular/compiler';
/**
* @stable
*/
Expand Down
5 changes: 0 additions & 5 deletions packages/compiler-cli/tsconfig-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
"module": "commonjs",
"outDir": "../../dist/packages/compiler-cli",
"paths": {
"@angular/core": ["../../dist/packages/core"],
"@angular/common": ["../../dist/packages/common"],
"@angular/compiler": ["../../dist/packages/compiler"],
"@angular/http": ["../../dist/packages/http"],
"@angular/platform-server": ["../../dist/packages/platform-server"],
"@angular/platform-browser": ["../../dist/packages/platform-browser"],
"@angular/tsc-wrapped": ["../../dist/packages-dist/tsc-wrapped"]
},
"rootDir": ".",
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ ts_library(
"testing/**",
]),
module_name = "@angular/compiler",
deps = ["//packages/core"],
deps = [],
tsconfig = ":tsconfig-build.json",
)
3 changes: 0 additions & 3 deletions packages/compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
"dependencies": {
"tslib": "^1.7.1"
},
"peerDependencies": {
"@angular/core": "0.0.0-PLACEHOLDER"
},
"repository": {
"type": "git",
"url": "https://github.com/angular/angular.git"
Expand Down
17 changes: 9 additions & 8 deletions packages/compiler/src/aot/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import {CompileDirectiveMetadata, CompileDirectiveSummary, CompileIdentifierMetadata, CompileNgModuleMetadata, CompileNgModuleSummary, CompilePipeMetadata, CompileProviderMetadata, CompileStylesheetMetadata, CompileSummaryKind, CompileTypeMetadata, CompileTypeSummary, componentFactoryName, createHostComponentMeta, flatten, identifierName, sourceUrl, templateSourceUrl} from '../compile_metadata';
import {CompilerConfig} from '../config';
import {Identifiers, createTokenForExternalReference} from '../identifiers';
import {OutputIdentifier, createTokenForExternalReference} from '../identifiers';
import {CompileMetadataResolver} from '../metadata_resolver';
import {NgModuleCompiler} from '../ng_module_compiler';
import {OutputEmitter} from '../output/abstract_emitter';
Expand Down Expand Up @@ -129,7 +129,7 @@ export class AotCompiler {
compMeta.template !.externalStylesheets.forEach((stylesheetMeta) => {
const styleContext = this._createOutputContext(_stylesModuleUrl(
stylesheetMeta.moduleUrl !, this._styleCompiler.needsStyleShim(compMeta), fileSuffix));
_createTypeReferenceStub(styleContext, Identifiers.ComponentFactory);
_createTypeReferenceStub(styleContext, OutputIdentifier.ComponentFactory);
generatedFiles.push(this._codegenSourceModule(stylesheetMeta.moduleUrl !, styleContext));
});

Expand All @@ -138,11 +138,11 @@ export class AotCompiler {

// If we need all the stubs to be generated then insert an arbitrary reference into the stub
if ((partialFactoryStubRequired || !partial) && ngFactoryOutputCtx.statements.length <= 0) {
_createTypeReferenceStub(ngFactoryOutputCtx, Identifiers.ComponentFactory);
_createTypeReferenceStub(ngFactoryOutputCtx, OutputIdentifier.ComponentFactory);
}
if ((partialJitStubRequired || !partial || (pipes && pipes.length > 0)) &&
jitSummaryOutputCtx.statements.length <= 0) {
_createTypeReferenceStub(jitSummaryOutputCtx, Identifiers.ComponentFactory);
_createTypeReferenceStub(jitSummaryOutputCtx, OutputIdentifier.ComponentFactory);
}

// Note: we are creating stub ngfactory/ngsummary for all source files,
Expand Down Expand Up @@ -259,14 +259,15 @@ export class AotCompiler {

if (this._localeId) {
providers.push({
token: createTokenForExternalReference(this._reflector, Identifiers.LOCALE_ID),
token: createTokenForExternalReference(this._reflector, OutputIdentifier.LOCALE_ID),
useValue: this._localeId,
});
}

if (this._translationFormat) {
providers.push({
token: createTokenForExternalReference(this._reflector, Identifiers.TRANSLATIONS_FORMAT),
token:
createTokenForExternalReference(this._reflector, OutputIdentifier.TRANSLATIONS_FORMAT),
useValue: this._translationFormat
});
}
Expand Down Expand Up @@ -299,7 +300,7 @@ export class AotCompiler {

outputCtx.statements.push(
o.variable(compFactoryVar)
.set(o.importExpr(Identifiers.createComponentFactory).callFn([
.set(o.importExpr(OutputIdentifier.createComponentFactory).callFn([
o.literal(compMeta.selector), outputCtx.importExpr(compMeta.type.reference),
o.variable(hostViewFactoryVar), new o.LiteralMapExpr(inputsExprs),
new o.LiteralMapExpr(outputsExprs),
Expand All @@ -308,7 +309,7 @@ export class AotCompiler {
]))
.toDeclStmt(
o.importType(
Identifiers.ComponentFactory,
OutputIdentifier.ComponentFactory,
[o.expressionType(outputCtx.importExpr(compMeta.type.reference)) !],
[o.TypeModifier.Const]),
[o.StmtModifier.Final, o.StmtModifier.Exported]));
Expand Down
4 changes: 1 addition & 3 deletions packages/compiler/src/aot/compiler_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/

import {MissingTranslationStrategy, ViewEncapsulation, ɵConsole as Console} from '@angular/core';

import {CompilerConfig} from '../config';
import {MissingTranslationStrategy, ViewEncapsulation} from '../core';
import {DirectiveNormalizer} from '../directive_normalizer';
import {DirectiveResolver} from '../directive_resolver';
import {Lexer} from '../expression_parser/lexer';
Expand Down Expand Up @@ -61,7 +60,6 @@ export function createAotCompiler(compilerHost: AotCompilerHost, options: AotCom
const summaryResolver = new AotSummaryResolver(compilerHost, symbolCache);
const symbolResolver = new StaticSymbolResolver(compilerHost, symbolCache, summaryResolver);
const staticReflector = new StaticReflector(summaryResolver, symbolResolver);
const console = new Console();
const htmlParser = new I18NHtmlParser(
new HtmlParser(), translations, options.i18nFormat, options.missingTranslation, console);
const config = new CompilerConfig({
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/aot/compiler_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {MissingTranslationStrategy} from '@angular/core';
import {MissingTranslationStrategy} from '../core';

export interface AotCompilerOptions {
locale?: string;
Expand Down
Loading

0 comments on commit 0aefd15

Please sign in to comment.