refactor(compiler): split compiler and core (#18683)
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 BREAKING CHANGE: - `@angular/platform-server` now additionally depends on `@angular/platform-browser-dynamic` as a peer dependency. PR Close #18683
This commit is contained in:

committed by
Miško Hevery

parent
a0ca01d580
commit
0cc77b4a69
@ -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';
|
||||
@ -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({
|
||||
|
@ -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;
|
||||
|
@ -6,10 +6,9 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Attribute, Component, ContentChild, ContentChildren, Directive, Host, HostBinding, HostListener, Inject, Injectable, Input, NgModule, Optional, Output, Pipe, Self, SkipSelf, ViewChild, ViewChildren, animate, group, keyframes, sequence, state, style, transition, trigger} from '@angular/core';
|
||||
|
||||
import {CompileSummaryKind} from '../compile_metadata';
|
||||
import {CompileReflector} from '../compile_reflector';
|
||||
import {MetadataFactory, createAttribute, createComponent, createContentChild, createContentChildren, createDirective, createHost, createHostBinding, createHostListener, createInject, createInjectable, createInput, createNgModule, createOptional, createOutput, createPipe, createSelf, createSkipSelf, createViewChild, createViewChildren} from '../core';
|
||||
import * as o from '../output/output_ast';
|
||||
import {SummaryResolver} from '../summary_resolver';
|
||||
import {syntaxError} from '../util';
|
||||
@ -48,8 +47,8 @@ export class StaticReflector implements CompileReflector {
|
||||
private opaqueToken: StaticSymbol;
|
||||
private ROUTES: StaticSymbol;
|
||||
private ANALYZE_FOR_ENTRY_COMPONENTS: StaticSymbol;
|
||||
private annotationForParentClassWithSummaryKind = new Map<CompileSummaryKind, any[]>();
|
||||
private annotationNames = new Map<any, string>();
|
||||
private annotationForParentClassWithSummaryKind =
|
||||
new Map<CompileSummaryKind, MetadataFactory<any>[]>();
|
||||
|
||||
constructor(
|
||||
private summaryResolver: SummaryResolver<StaticSymbol>,
|
||||
@ -64,16 +63,12 @@ export class StaticReflector implements CompileReflector {
|
||||
knownMetadataFunctions.forEach(
|
||||
(kf) => this._registerFunction(this.getStaticSymbol(kf.filePath, kf.name), kf.fn));
|
||||
this.annotationForParentClassWithSummaryKind.set(
|
||||
CompileSummaryKind.Directive, [Directive, Component]);
|
||||
this.annotationForParentClassWithSummaryKind.set(CompileSummaryKind.Pipe, [Pipe]);
|
||||
this.annotationForParentClassWithSummaryKind.set(CompileSummaryKind.NgModule, [NgModule]);
|
||||
CompileSummaryKind.Directive, [createDirective, createComponent]);
|
||||
this.annotationForParentClassWithSummaryKind.set(CompileSummaryKind.Pipe, [createPipe]);
|
||||
this.annotationForParentClassWithSummaryKind.set(CompileSummaryKind.NgModule, [createNgModule]);
|
||||
this.annotationForParentClassWithSummaryKind.set(
|
||||
CompileSummaryKind.Injectable, [Injectable, Pipe, Directive, Component, NgModule]);
|
||||
this.annotationNames.set(Directive, 'Directive');
|
||||
this.annotationNames.set(Component, 'Component');
|
||||
this.annotationNames.set(Pipe, 'Pipe');
|
||||
this.annotationNames.set(NgModule, 'NgModule');
|
||||
this.annotationNames.set(Injectable, 'Injectable');
|
||||
CompileSummaryKind.Injectable,
|
||||
[createInjectable, createPipe, createDirective, createComponent, createNgModule]);
|
||||
}
|
||||
|
||||
componentModuleUrl(typeOrFunc: StaticSymbol): string {
|
||||
@ -129,12 +124,12 @@ export class StaticReflector implements CompileReflector {
|
||||
const requiredAnnotationTypes =
|
||||
this.annotationForParentClassWithSummaryKind.get(summary.type.summaryKind !) !;
|
||||
const typeHasRequiredAnnotation = requiredAnnotationTypes.some(
|
||||
(requiredType: any) => ownAnnotations.some(ann => ann instanceof requiredType));
|
||||
(requiredType) => ownAnnotations.some(ann => requiredType.isTypeOf(ann)));
|
||||
if (!typeHasRequiredAnnotation) {
|
||||
this.reportError(
|
||||
syntaxError(
|
||||
`Class ${type.name} in ${type.filePath} extends from a ${CompileSummaryKind[summary.type.summaryKind!]} in another compilation unit without duplicating the decorator. ` +
|
||||
`Please add a ${requiredAnnotationTypes.map((type: any) => this.annotationNames.get(type)).join(' or ')} decorator to the class.`),
|
||||
`Please add a ${requiredAnnotationTypes.map((type) => type.ngMetadataName).join(' or ')} decorator to the class.`),
|
||||
type);
|
||||
}
|
||||
}
|
||||
@ -281,50 +276,48 @@ export class StaticReflector implements CompileReflector {
|
||||
this.ANALYZE_FOR_ENTRY_COMPONENTS =
|
||||
this.findDeclaration(ANGULAR_CORE, 'ANALYZE_FOR_ENTRY_COMPONENTS');
|
||||
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Host'), Host);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Host'), createHost);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'Injectable'), Injectable);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Self'), Self);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'SkipSelf'), SkipSelf);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Inject'), Inject);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Optional'), Optional);
|
||||
this.findDeclaration(ANGULAR_CORE, 'Injectable'), createInjectable);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Self'), createSelf);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'Attribute'), Attribute);
|
||||
this.findDeclaration(ANGULAR_CORE, 'SkipSelf'), createSkipSelf);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'ContentChild'), ContentChild);
|
||||
this.findDeclaration(ANGULAR_CORE, 'Inject'), createInject);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'ContentChildren'), ContentChildren);
|
||||
this.findDeclaration(ANGULAR_CORE, 'Optional'), createOptional);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'ViewChild'), ViewChild);
|
||||
this.findDeclaration(ANGULAR_CORE, 'Attribute'), createAttribute);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'ViewChildren'), ViewChildren);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Input'), Input);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Output'), Output);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Pipe'), Pipe);
|
||||
this.findDeclaration(ANGULAR_CORE, 'ContentChild'), createContentChild);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'HostBinding'), HostBinding);
|
||||
this.findDeclaration(ANGULAR_CORE, 'ContentChildren'), createContentChildren);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'HostListener'), HostListener);
|
||||
this.findDeclaration(ANGULAR_CORE, 'ViewChild'), createViewChild);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'Directive'), Directive);
|
||||
this.findDeclaration(ANGULAR_CORE, 'ViewChildren'), createViewChildren);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Input'), createInput);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'Component'), Component);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'NgModule'), NgModule);
|
||||
this.findDeclaration(ANGULAR_CORE, 'Output'), createOutput);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Pipe'), createPipe);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'HostBinding'), createHostBinding);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'HostListener'), createHostListener);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'Directive'), createDirective);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'Component'), createComponent);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'NgModule'), createNgModule);
|
||||
|
||||
// Note: Some metadata classes can be used directly with Provider.deps.
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Host'), Host);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Self'), Self);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'SkipSelf'), SkipSelf);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Optional'), Optional);
|
||||
|
||||
this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'trigger'), trigger);
|
||||
this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'state'), state);
|
||||
this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'transition'), transition);
|
||||
this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'style'), style);
|
||||
this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'animate'), animate);
|
||||
this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'keyframes'), keyframes);
|
||||
this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'sequence'), sequence);
|
||||
this._registerFunction(this.findDeclaration(ANGULAR_CORE, 'group'), group);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Host'), createHost);
|
||||
this._registerDecoratorOrConstructor(this.findDeclaration(ANGULAR_CORE, 'Self'), createSelf);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'SkipSelf'), createSkipSelf);
|
||||
this._registerDecoratorOrConstructor(
|
||||
this.findDeclaration(ANGULAR_CORE, 'Optional'), createOptional);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -755,4 +748,4 @@ function positionalError(message: string, fileName: string, line: number, column
|
||||
(result as any).line = line;
|
||||
(result as any).column = column;
|
||||
return result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user