Revert "refactor(compiler): remove cyclic dependencies (#42062)" (#43033)

This reverts commit 75855196e3.

PR Close #43033
This commit is contained in:
atscott 2021-08-03 14:49:21 -07:00
parent dda75ca1d0
commit 9436f4bf77
32 changed files with 199 additions and 132 deletions

View File

@ -41,6 +41,55 @@
"packages/compiler-cli/src/ngtsc/scope/src/component_scope.ts",
"packages/compiler-cli/src/ngtsc/scope/src/local.ts"
],
[
"packages/compiler/src/compile_metadata.ts",
"packages/compiler/src/lifecycle_reflector.ts",
"packages/compiler/src/compile_reflector.ts",
"packages/compiler/src/output/output_ast.ts",
"packages/compiler/src/parse_util.ts"
],
[
"packages/compiler/src/compile_metadata.ts",
"packages/compiler/src/ml_parser/parser.ts",
"packages/compiler/src/ml_parser/ast.ts",
"packages/compiler/src/i18n/i18n_ast.ts",
"packages/compiler/src/parse_util.ts"
],
[
"packages/compiler/src/compile_metadata.ts",
"packages/compiler/src/ml_parser/parser.ts",
"packages/compiler/src/ml_parser/ast.ts",
"packages/compiler/src/parse_util.ts"
],
[
"packages/compiler/src/compile_metadata.ts",
"packages/compiler/src/ml_parser/parser.ts",
"packages/compiler/src/ml_parser/lexer.ts",
"packages/compiler/src/parse_util.ts"
],
[
"packages/compiler/src/compile_metadata.ts",
"packages/compiler/src/ml_parser/parser.ts",
"packages/compiler/src/parse_util.ts"
],
[
"packages/compiler/src/compile_metadata.ts",
"packages/compiler/src/util.ts",
"packages/compiler/src/constant_pool.ts",
"packages/compiler/src/output/output_ast.ts",
"packages/compiler/src/parse_util.ts"
],
[
"packages/compiler/src/compile_metadata.ts",
"packages/compiler/src/util.ts",
"packages/compiler/src/output/output_ast.ts",
"packages/compiler/src/parse_util.ts"
],
[
"packages/compiler/src/compile_metadata.ts",
"packages/compiler/src/util.ts",
"packages/compiler/src/parse_util.ts"
],
[
"packages/compiler/src/output/output_ast.ts",
"packages/compiler/src/render3/view/i18n/meta.ts"
@ -50,6 +99,11 @@
"packages/compiler/src/render3/view/i18n/meta.ts",
"packages/compiler/src/render3/view/i18n/util.ts"
],
[
"packages/compiler/src/render3/r3_factory.ts",
"packages/compiler/src/render3/view/util.ts",
"packages/compiler/src/render3/view/api.ts"
],
[
"packages/compiler/src/render3/view/styling_builder.ts",
"packages/compiler/src/render3/view/template.ts"

View File

@ -6,9 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {CompileDirectiveMetadata, CompileInjectableMetadata, CompileNgModuleMetadata, CompilePipeMetadata, CompilePipeSummary, CompileProviderMetadata, CompileShallowModuleMetadata, CompileStylesheetMetadata, CompileTypeMetadata, CompileTypeSummary, componentFactoryName, flatten, templateSourceUrl} from '../compile_metadata';
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileInjectableMetadata, CompileNgModuleMetadata, CompilePipeMetadata, CompilePipeSummary, CompileProviderMetadata, CompileShallowModuleMetadata, CompileStylesheetMetadata, CompileTypeMetadata, CompileTypeSummary, componentFactoryName, flatten, identifierName, templateSourceUrl} from '../compile_metadata';
import {CompilerConfig} from '../config';
import {ConstantPool, OutputContext} from '../constant_pool';
import {ConstantPool} from '../constant_pool';
import {ViewEncapsulation} from '../core';
import {MessageBundle} from '../i18n/message_bundle';
import {createTokenForExternalReference, Identifiers} from '../identifiers';
@ -19,12 +19,12 @@ import {InterpolationConfig} from '../ml_parser/interpolation_config';
import {NgModuleCompiler} from '../ng_module_compiler';
import {OutputEmitter} from '../output/abstract_emitter';
import * as o from '../output/output_ast';
import {CompileIdentifierMetadata, identifierName, ParseError, syntaxError} from '../parse_util';
import {ParseError} from '../parse_util';
import {CompiledStylesheet, StyleCompiler} from '../style_compiler';
import {SummaryResolver} from '../summary_resolver';
import {TemplateAst} from '../template_parser/template_ast';
import {TemplateParser} from '../template_parser/template_parser';
import {newArray, ValueVisitor, visitValue} from '../util';
import {newArray, OutputContext, syntaxError, ValueVisitor, visitValue} from '../util';
import {TypeCheckCompiler} from '../view_compiler/type_check_compiler';
import {ViewCompiler, ViewCompileResult} from '../view_compiler/view_compiler';

View File

@ -19,12 +19,12 @@ import {HtmlParser} from '../ml_parser/html_parser';
import {NgModuleCompiler} from '../ng_module_compiler';
import {NgModuleResolver} from '../ng_module_resolver';
import {TypeScriptEmitter} from '../output/ts_emitter';
import {syntaxError} from '../parse_util';
import {PipeResolver} from '../pipe_resolver';
import {DomElementSchemaRegistry} from '../schema/dom_element_schema_registry';
import {StyleCompiler} from '../style_compiler';
import {TemplateParser} from '../template_parser/template_parser';
import {UrlResolver} from '../url_resolver';
import {syntaxError} from '../util';
import {TypeCheckCompiler} from '../view_compiler/type_check_compiler';
import {ViewCompiler} from '../view_compiler/view_compiler';

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {syntaxError} from '../parse_util';
import {syntaxError} from '../util';
export interface Position {
fileName: string;

View File

@ -10,8 +10,8 @@ import {CompileSummaryKind} from '../compile_metadata';
import {CompileReflector} from '../compile_reflector';
import {createAttribute, createComponent, createContentChild, createContentChildren, createDirective, createHost, createHostBinding, createHostListener, createInject, createInjectable, createInput, createNgModule, createOptional, createOutput, createPipe, createSelf, createSkipSelf, createViewChild, createViewChildren, MetadataFactory} from '../core';
import * as o from '../output/output_ast';
import {syntaxError} from '../parse_util';
import {SummaryResolver} from '../summary_resolver';
import {syntaxError} from '../util';
import {formattedError, FormattedMessageChain} from './formatted_error';
import {StaticSymbol} from './static_symbol';

View File

@ -6,10 +6,9 @@
* found in the LICENSE file at https://angular.io/license
*/
import {CompileDirectiveMetadata, CompileDirectiveSummary, CompileNgModuleMetadata, CompileNgModuleSummary, CompilePipeMetadata, CompileProviderMetadata, CompileSummaryKind, CompileTypeMetadata, CompileTypeSummary} from '../compile_metadata';
import {OutputContext} from '../constant_pool';
import * as o from '../output/output_ast';
import {Summary, SummaryResolver} from '../summary_resolver';
import {ValueTransformer, ValueVisitor, visitValue} from '../util';
import {OutputContext, ValueTransformer, ValueVisitor, visitValue} from '../util';
import {StaticSymbol, StaticSymbolCache} from './static_symbol';
import {ResolvedStaticSymbol, StaticSymbolResolver, unwrapResolvedMetadata} from './static_symbol_resolver';

View File

@ -10,8 +10,7 @@ import {StaticSymbol} from './aot/static_symbol';
import {ChangeDetectionStrategy, SchemaMetadata, Type, ViewEncapsulation} from './core';
import {LifecycleHooks} from './lifecycle_reflector';
import {ParseTreeResult as HtmlParseTreeResult} from './ml_parser/parser';
import {CompileIdentifierMetadata, identifierName, sanitizeIdentifier} from './parse_util';
import {splitAtColon} from './util';
import {splitAtColon, stringify} from './util';
// group 0: "[prop] or (event) or @trigger"
// group 1: "prop" from "[prop]"
@ -19,6 +18,49 @@ import {splitAtColon} from './util';
// group 3: "@trigger" from "@trigger"
const HOST_REG_EXP = /^(?:(?:\[([^\]]+)\])|(?:\(([^\)]+)\)))|(\@[-\w]+)$/;
export function sanitizeIdentifier(name: string): string {
return name.replace(/\W/g, '_');
}
let _anonymousTypeIndex = 0;
export function identifierName(compileIdentifier: CompileIdentifierMetadata|null|undefined): string|
null {
if (!compileIdentifier || !compileIdentifier.reference) {
return null;
}
const ref = compileIdentifier.reference;
if (ref instanceof StaticSymbol) {
return ref.name;
}
if (ref['__anonymousType']) {
return ref['__anonymousType'];
}
if (ref['__forward_ref__']) {
// We do not want to try to stringify a `forwardRef()` function because that would cause the
// inner function to be evaluated too early, defeating the whole point of the `forwardRef`.
return '__forward_ref__';
}
let identifier = stringify(ref);
if (identifier.indexOf('(') >= 0) {
// case: anonymous functions!
identifier = `anonymous_${_anonymousTypeIndex++}`;
ref['__anonymousType'] = identifier;
} else {
identifier = sanitizeIdentifier(identifier);
}
return identifier;
}
export function identifierModuleUrl(compileIdentifier: CompileIdentifierMetadata): string {
const ref = compileIdentifier.reference;
if (ref instanceof StaticSymbol) {
return ref.filePath;
}
// Runtime type
return `./${stringify(ref)}`;
}
export function viewClassName(compType: any, embeddedTemplateIndex: number): string {
return `View_${identifierName({reference: compType})}_${embeddedTemplateIndex}`;
}
@ -39,6 +81,10 @@ export interface ProxyClass {
setDelegate(delegate: any): void;
}
export interface CompileIdentifierMetadata {
reference: any;
}
export enum CompileSummaryKind {
Pipe,
Directive,

View File

@ -88,7 +88,7 @@ export * from './selector';
export * from './style_compiler';
export * from './template_parser/template_parser';
export {ViewCompiler} from './view_compiler/view_compiler';
export {Version} from './util';
export {getParseErrors, isSyntaxError, syntaxError, Version} from './util';
export {SourceMap} from './output/source_map';
export * from './injectable_compiler_2';
export * from './render3/partial/api';

View File

@ -7,6 +7,7 @@
*/
import * as o from './output/output_ast';
import {error, OutputContext} from './util';
const CONSTANT_PREFIX = '_c';
@ -275,13 +276,6 @@ export class ConstantPool {
}
}
export interface OutputContext {
genFilePath: string;
statements: o.Statement[];
constantPool: ConstantPool;
importExpr(reference: any, typeParams?: o.Type[]|null, useSummaries?: boolean): o.Expression;
}
/**
* Visitor used to determine if 2 expressions are equivalent and can be shared in the
* `ConstantPool`.

View File

@ -13,12 +13,11 @@ import * as html from './ml_parser/ast';
import {HtmlParser} from './ml_parser/html_parser';
import {InterpolationConfig} from './ml_parser/interpolation_config';
import {ParseTreeResult as HtmlParseTreeResult} from './ml_parser/parser';
import {syntaxError} from './parse_util';
import {ResourceLoader} from './resource_loader';
import {extractStyleUrls, isStyleUrlResolvable} from './style_url_resolver';
import {PreparsedElementType, preparseElement} from './template_parser/template_preparser';
import {UrlResolver} from './url_resolver';
import {isDefined, stringify, SyncAsync} from './util';
import {isDefined, stringify, SyncAsync, syntaxError} from './util';
export interface PrenormalizedTemplateMetadata {
ngModuleType: any;

View File

@ -28,6 +28,7 @@ import {NgModuleResolver} from '../ng_module_resolver';
import {ParseError} from '../parse_util';
import {PipeResolver} from '../pipe_resolver';
import {DomElementSchemaRegistry} from '../schema/dom_element_schema_registry';
import {syntaxError} from '../util';
import {MessageBundle} from './message_bundle';

View File

@ -7,15 +7,14 @@
*/
import {StaticSymbol} from './aot/static_symbol';
import {CompileInjectableMetadata} from './compile_metadata';
import {CompileInjectableMetadata, identifierName} from './compile_metadata';
import {CompileReflector} from './compile_reflector';
import {OutputContext} from './constant_pool';
import {InjectFlags} from './core';
import {Identifiers} from './identifiers';
import * as o from './output/output_ast';
import {convertValueToOutputAst} from './output/value_util';
import {identifierName} from './parse_util';
import {Identifiers as R3} from './render3/r3_identifiers';
import {OutputContext} from './util';
type MapEntry = {
key: string,

View File

@ -6,22 +6,21 @@
* found in the LICENSE file at https://angular.io/license
*/
import {CompileDirectiveMetadata, CompileNgModuleMetadata, CompilePipeSummary, CompileProviderMetadata, CompileTypeSummary, ngModuleJitUrl, ProxyClass, sharedStylesheetJitUrl, templateJitUrl, templateSourceUrl} from '../compile_metadata';
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileNgModuleMetadata, CompilePipeSummary, CompileProviderMetadata, CompileStylesheetMetadata, CompileTypeSummary, identifierName, ngModuleJitUrl, ProviderMeta, ProxyClass, sharedStylesheetJitUrl, templateJitUrl, templateSourceUrl} from '../compile_metadata';
import {CompileReflector} from '../compile_reflector';
import {CompilerConfig} from '../config';
import {ConstantPool, OutputContext} from '../constant_pool';
import {ConstantPool} from '../constant_pool';
import {Type} from '../core';
import {CompileMetadataResolver} from '../metadata_resolver';
import {NgModuleCompiler} from '../ng_module_compiler';
import * as ir from '../output/output_ast';
import {interpretStatements} from '../output/output_interpreter';
import {JitEvaluator} from '../output/output_jit';
import {CompileIdentifierMetadata, identifierName} from '../parse_util';
import {CompiledStylesheet, StyleCompiler} from '../style_compiler';
import {SummaryResolver} from '../summary_resolver';
import {TemplateAst} from '../template_parser/template_ast';
import {TemplateParser} from '../template_parser/template_parser';
import {Console, stringify, SyncAsync} from '../util';
import {Console, OutputContext, stringify, SyncAsync} from '../util';
import {ViewCompiler} from '../view_compiler/view_compiler';
export interface ModuleWithComponentFactories {

View File

@ -19,12 +19,11 @@ import {Identifiers} from './identifiers';
import {getAllLifecycleHooks} from './lifecycle_reflector';
import {HtmlParser} from './ml_parser/html_parser';
import {NgModuleResolver} from './ng_module_resolver';
import {CompileIdentifierMetadata, identifierName, syntaxError} from './parse_util';
import {PipeResolver} from './pipe_resolver';
import {ElementSchemaRegistry} from './schema/element_schema_registry';
import {CssSelector} from './selector';
import {SummaryResolver} from './summary_resolver';
import {Console, isPromise, noUndefined, resolveForwardRef, stringify, SyncAsync, ValueTransformer, visitValue} from './util';
import {Console, isPromise, noUndefined, resolveForwardRef, stringify, SyncAsync, syntaxError, ValueTransformer, visitValue} from './util';
export type ErrorCollector = (error: any, type?: any) => void;
@ -131,7 +130,7 @@ export class CompileMetadataResolver {
}
getHostComponentType(dirType: any): StaticSymbol|cpl.ProxyClass {
const name = `${identifierName({reference: dirType})}_Host`;
const name = `${cpl.identifierName({reference: dirType})}_Host`;
if (dirType instanceof StaticSymbol) {
return this._staticSymbolCache.get(dirType.filePath, name);
}
@ -534,14 +533,14 @@ export class CompileMetadataResolver {
if (!meta) {
return null;
}
const declaredDirectives: CompileIdentifierMetadata[] = [];
const exportedNonModuleIdentifiers: CompileIdentifierMetadata[] = [];
const declaredPipes: CompileIdentifierMetadata[] = [];
const declaredDirectives: cpl.CompileIdentifierMetadata[] = [];
const exportedNonModuleIdentifiers: cpl.CompileIdentifierMetadata[] = [];
const declaredPipes: cpl.CompileIdentifierMetadata[] = [];
const importedModules: cpl.CompileNgModuleSummary[] = [];
const exportedModules: cpl.CompileNgModuleSummary[] = [];
const providers: cpl.CompileProviderMetadata[] = [];
const entryComponents: cpl.CompileEntryComponentMetadata[] = [];
const bootstrapComponents: CompileIdentifierMetadata[] = [];
const bootstrapComponents: cpl.CompileIdentifierMetadata[] = [];
const schemas: SchemaMetadata[] = [];
if (meta.imports) {
@ -673,8 +672,8 @@ export class CompileMetadataResolver {
});
}
const exportedDirectives: CompileIdentifierMetadata[] = [];
const exportedPipes: CompileIdentifierMetadata[] = [];
const exportedDirectives: cpl.CompileIdentifierMetadata[] = [];
const exportedPipes: cpl.CompileIdentifierMetadata[] = [];
exportedNonModuleIdentifiers.forEach((exportedId) => {
if (transitiveModule.directivesSet.has(exportedId.reference)) {
exportedDirectives.push(exportedId);
@ -837,7 +836,7 @@ export class CompileMetadataResolver {
return result;
}
private _getIdentifierMetadata(type: Type): CompileIdentifierMetadata {
private _getIdentifierMetadata(type: Type): cpl.CompileIdentifierMetadata {
type = resolveForwardRef(type);
return {reference: type};
}
@ -1094,7 +1093,7 @@ export class CompileMetadataResolver {
private _getEntryComponentsFromProvider(provider: cpl.ProviderMeta, type?: any):
cpl.CompileEntryComponentMetadata[] {
const components: cpl.CompileEntryComponentMetadata[] = [];
const collectedIdentifiers: CompileIdentifierMetadata[] = [];
const collectedIdentifiers: cpl.CompileIdentifierMetadata[] = [];
if (provider.useFactory || provider.useExisting || provider.useClass) {
this._reportError(
@ -1264,12 +1263,12 @@ function isValidType(value: any): boolean {
return (value instanceof StaticSymbol) || (value instanceof Type);
}
function extractIdentifiers(value: any, targetIdentifiers: CompileIdentifierMetadata[]) {
function extractIdentifiers(value: any, targetIdentifiers: cpl.CompileIdentifierMetadata[]) {
visitValue(value, new _CompileValueConverter(), targetIdentifiers);
}
class _CompileValueConverter extends ValueTransformer {
override visitOther(value: any, targetIdentifiers: CompileIdentifierMetadata[]): any {
override visitOther(value: any, targetIdentifiers: cpl.CompileIdentifierMetadata[]): any {
targetIdentifiers.push({reference: value});
}
}

View File

@ -6,14 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/
import {CompileNgModuleMetadata, CompileProviderMetadata} from './compile_metadata';
import {CompileNgModuleMetadata, CompileProviderMetadata, identifierName} from './compile_metadata';
import {CompileReflector} from './compile_reflector';
import {OutputContext} from './constant_pool';
import {NodeFlags} from './core';
import {Identifiers} from './identifiers';
import * as o from './output/output_ast';
import {identifierName, typeSourceSpan} from './parse_util';
import {typeSourceSpan} from './parse_util';
import {NgModuleProviderAnalyzer} from './provider_analyzer';
import {OutputContext} from './util';
import {componentFactoryResolverProviderDef, depDef, providerDef} from './view_compiler/provider_compiler';
export class NgModuleCompileResult {

View File

@ -5,6 +5,11 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {StaticSymbol} from '../aot/static_symbol';
import {CompileIdentifierMetadata} from '../compile_metadata';
import {EmitterVisitorContext, OutputEmitter} from './abstract_emitter';
import {AbstractJsEmitterVisitor} from './abstract_js_emitter';
import * as o from './output_ast';

View File

@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ParseSourceSpan} from '../parse_util';
import {I18nMeta} from '../render3/view/i18n/meta';

View File

@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {identifierName} from '../compile_metadata';
import {CompileReflector} from '../compile_reflector';
import {identifierName} from '../parse_util';
import {EmitterVisitorContext} from './abstract_emitter';
import {AbstractJsEmitterVisitor} from './abstract_js_emitter';

View File

@ -7,8 +7,7 @@
*/
import {OutputContext} from '../constant_pool';
import {ValueTransformer, visitValue} from '../util';
import {OutputContext, ValueTransformer, visitValue} from '../util';
import * as o from './output_ast';

View File

@ -5,9 +5,8 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {StaticSymbol} from './aot/static_symbol';
import * as chars from './chars';
import {stringify} from './util';
import {CompileIdentifierMetadata, identifierModuleUrl, identifierName} from './compile_metadata';
export class ParseLocation {
constructor(
@ -179,68 +178,3 @@ export function r3JitTypeSourceSpan(
return new ParseSourceSpan(
new ParseLocation(sourceFile, -1, -1, -1), new ParseLocation(sourceFile, -1, -1, -1));
}
export function syntaxError(msg: string, parseErrors?: ParseError[]): Error {
const error = Error(msg);
(error as any)[ERROR_SYNTAX_ERROR] = true;
if (parseErrors) (error as any)[ERROR_PARSE_ERRORS] = parseErrors;
return error;
}
const ERROR_SYNTAX_ERROR = 'ngSyntaxError';
const ERROR_PARSE_ERRORS = 'ngParseErrors';
export function isSyntaxError(error: Error): boolean {
return (error as any)[ERROR_SYNTAX_ERROR];
}
export function getParseErrors(error: Error): ParseError[] {
return (error as any)[ERROR_PARSE_ERRORS] || [];
}
let _anonymousTypeIndex = 0;
export function identifierName(compileIdentifier: CompileIdentifierMetadata|null|undefined): string|
null {
if (!compileIdentifier || !compileIdentifier.reference) {
return null;
}
const ref = compileIdentifier.reference;
if (ref instanceof StaticSymbol) {
return ref.name;
}
if (ref['__anonymousType']) {
return ref['__anonymousType'];
}
if (ref['__forward_ref__']) {
// We do not want to try to stringify a `forwardRef()` function because that would cause the
// inner function to be evaluated too early, defeating the whole point of the `forwardRef`.
return '__forward_ref__';
}
let identifier = stringify(ref);
if (identifier.indexOf('(') >= 0) {
// case: anonymous functions!
identifier = `anonymous_${_anonymousTypeIndex++}`;
ref['__anonymousType'] = identifier;
} else {
identifier = sanitizeIdentifier(identifier);
}
return identifier;
}
export function identifierModuleUrl(compileIdentifier: CompileIdentifierMetadata): string {
const ref = compileIdentifier.reference;
if (ref instanceof StaticSymbol) {
return ref.filePath;
}
// Runtime type
return `./${stringify(ref)}`;
}
export interface CompileIdentifierMetadata {
reference: any;
}
export function sanitizeIdentifier(name: string): string {
return name.replace(/\W/g, '_');
}

View File

@ -5,10 +5,17 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {StaticSymbol} from '../aot/static_symbol';
import {CompileTypeMetadata, tokenReference} from '../compile_metadata';
import {InjectFlags} from '../core';
import * as o from '../output/output_ast';
import {Identifiers as R3} from '../render3/r3_identifiers';
import {OutputContext} from '../util';
import {R3CompiledExpression, R3Reference, typeWithParameters} from './util';
import {unsupported} from './view/util';
/**

View File

@ -6,13 +6,13 @@
* found in the LICENSE file at https://angular.io/license
*/
import {CompileDirectiveSummary} from '../../compile_metadata';
import {CompileDirectiveSummary, sanitizeIdentifier} from '../../compile_metadata';
import {BindingForm, convertPropertyBinding} from '../../compiler_util/expression_converter';
import {ConstantPool} from '../../constant_pool';
import * as core from '../../core';
import {AST, ParsedEvent, ParsedEventType, ParsedProperty} from '../../expression_parser/ast';
import * as o from '../../output/output_ast';
import {ParseError, ParseSourceSpan, sanitizeIdentifier} from '../../parse_util';
import {ParseError, ParseSourceSpan} from '../../parse_util';
import {CssSelector, SelectorMatcher} from '../../selector';
import {ShadowCss} from '../../shadow_css';
import {CONTENT_ATTR, HOST_ATTR} from '../../style_compiler';

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {flatten} from '../../compile_metadata';
import {flatten, sanitizeIdentifier} from '../../compile_metadata';
import {BindingForm, BuiltinFunctionCall, convertActionBinding, convertPropertyBinding, convertUpdateArguments, LocalResolver} from '../../compiler_util/expression_converter';
import {ConstantPool} from '../../constant_pool';
import * as core from '../../core';
@ -22,7 +22,7 @@ import {LexerRange} from '../../ml_parser/lexer';
import {isNgContainer as checkIsNgContainer, splitNsName} from '../../ml_parser/tags';
import {mapLiteral} from '../../output/map_util';
import * as o from '../../output/output_ast';
import {ParseError, ParseSourceSpan, sanitizeIdentifier} from '../../parse_util';
import {ParseError, ParseSourceFile, ParseSourceSpan} from '../../parse_util';
import {DomElementSchemaRegistry} from '../../schema/dom_element_schema_registry';
import {isTrustedTypesSink} from '../../schema/trusted_types_sinks';
import {CssSelector, SelectorMatcher} from '../../selector';

View File

@ -6,13 +6,12 @@
* found in the LICENSE file at https://angular.io/license
*/
import {CompileDirectiveMetadata, CompileStylesheetMetadata} from './compile_metadata';
import {OutputContext} from './constant_pool';
import {CompileDirectiveMetadata, CompileIdentifierMetadata, CompileStylesheetMetadata, identifierModuleUrl, identifierName} from './compile_metadata';
import {ViewEncapsulation} from './core';
import * as o from './output/output_ast';
import {identifierModuleUrl, identifierName} from './parse_util';
import {ShadowCss} from './shadow_css';
import {UrlResolver} from './url_resolver';
import {OutputContext} from './util';
const COMPONENT_VARIABLE = '%COMP%';
export const HOST_ATTR = `_nghost-${COMPONENT_VARIABLE}`;

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {CompileDirectiveMetadata, CompileDirectiveSummary, CompilePipeSummary, CompileTokenMetadata, CompileTypeMetadata} from '../compile_metadata';
import {CompileDirectiveMetadata, CompileDirectiveSummary, CompilePipeSummary, CompileTokenMetadata, CompileTypeMetadata, identifierName} from '../compile_metadata';
import {CompileReflector} from '../compile_reflector';
import {CompilerConfig} from '../config';
import {SchemaMetadata} from '../core';
@ -19,12 +19,12 @@ import {removeWhitespaces, replaceNgsp} from '../ml_parser/html_whitespaces';
import {expandNodes} from '../ml_parser/icu_ast_expander';
import {InterpolationConfig} from '../ml_parser/interpolation_config';
import {isNgTemplate, splitNsName} from '../ml_parser/tags';
import {identifierName, ParseError, ParseErrorLevel, ParseSourceSpan, syntaxError} from '../parse_util';
import {ParseError, ParseErrorLevel, ParseSourceSpan} from '../parse_util';
import {ProviderElementContext, ProviderViewContext} from '../provider_analyzer';
import {ElementSchemaRegistry} from '../schema/element_schema_registry';
import {CssSelector, SelectorMatcher} from '../selector';
import {isStyleUrlResolvable} from '../style_url_resolver';
import {Console, newArray} from '../util';
import {Console, newArray, syntaxError} from '../util';
import {BindingParser} from './binding_parser';
import * as t from './template_ast';

View File

@ -6,6 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ConstantPool} from './constant_pool';
import * as o from './output/output_ast';
import {ParseError} from './parse_util';
const DASH_CASE_REGEXP = /-+([a-z0-9])/g;
export function dashCaseToCamelCase(input: string): string {
@ -99,6 +104,24 @@ export function error(msg: string): never {
throw new Error(`Internal Error: ${msg}`);
}
export function syntaxError(msg: string, parseErrors?: ParseError[]): Error {
const error = Error(msg);
(error as any)[ERROR_SYNTAX_ERROR] = true;
if (parseErrors) (error as any)[ERROR_PARSE_ERRORS] = parseErrors;
return error;
}
const ERROR_SYNTAX_ERROR = 'ngSyntaxError';
const ERROR_PARSE_ERRORS = 'ngParseErrors';
export function isSyntaxError(error: Error): boolean {
return (error as any)[ERROR_SYNTAX_ERROR];
}
export function getParseErrors(error: Error): ParseError[] {
return (error as any)[ERROR_PARSE_ERRORS] || [];
}
// Escape characters that have a special meaning in Regular Expressions
export function escapeRegExp(s: string): string {
return s.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
@ -143,6 +166,13 @@ export function utf8Encode(str: string): Byte[] {
return encoded;
}
export interface OutputContext {
genFilePath: string;
statements: o.Statement[];
constantPool: ConstantPool;
importExpr(reference: any, typeParams?: o.Type[]|null, useSummaries?: boolean): o.Expression;
}
export function stringify(token: any): string {
if (typeof token === 'string') {
return token;

View File

@ -8,13 +8,13 @@
import {CompileDiDependencyMetadata, CompileEntryComponentMetadata, CompileProviderMetadata, CompileTokenMetadata} from '../compile_metadata';
import {CompileReflector} from '../compile_reflector';
import {OutputContext} from '../constant_pool';
import {DepFlags, NodeFlags} from '../core';
import {createTokenForExternalReference, Identifiers} from '../identifiers';
import {LifecycleHooks} from '../lifecycle_reflector';
import * as o from '../output/output_ast';
import {convertValueToOutputAst} from '../output/value_util';
import {ProviderAst, ProviderAstType} from '../template_parser/template_ast';
import {OutputContext} from '../util';
export function providerDef(ctx: OutputContext, providerAst: ProviderAst): {
providerExpr: o.Expression,

View File

@ -11,11 +11,11 @@ import {StaticReflector} from '../aot/static_reflector';
import {StaticSymbol} from '../aot/static_symbol';
import {CompileDirectiveMetadata, CompilePipeSummary} from '../compile_metadata';
import {BindingForm, convertActionBinding, convertPropertyBinding, convertPropertyBindingBuiltins, EventHandlerVars, LocalResolver} from '../compiler_util/expression_converter';
import {OutputContext} from '../constant_pool';
import {AST, ASTWithSource, Interpolation} from '../expression_parser/ast';
import * as o from '../output/output_ast';
import {ParseSourceSpan} from '../parse_util';
import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, DirectiveAst, ElementAst, EmbeddedTemplateAst, NgContentAst, ReferenceAst, TemplateAst, TemplateAstVisitor, templateVisitAll, TextAst, VariableAst} from '../template_parser/template_ast';
import {OutputContext} from '../util';
/**

View File

@ -9,7 +9,6 @@
import {CompileDirectiveMetadata, CompilePipeSummary, CompileQueryMetadata, rendererTypeName, tokenReference, viewClassName} from '../compile_metadata';
import {CompileReflector} from '../compile_reflector';
import {BindingForm, BuiltinConverter, convertActionBinding, convertPropertyBinding, convertPropertyBindingBuiltins, EventHandlerVars, LocalResolver} from '../compiler_util/expression_converter';
import {OutputContext} from '../constant_pool';
import {ArgumentType, BindingFlags, ChangeDetectionStrategy, NodeFlags, QueryBindingType, QueryValueType, ViewFlags} from '../core';
import {AST, ASTWithSource, Interpolation} from '../expression_parser/ast';
import {Identifiers} from '../identifiers';
@ -19,6 +18,7 @@ import * as o from '../output/output_ast';
import {convertValueToOutputAst} from '../output/value_util';
import {ParseSourceSpan} from '../parse_util';
import {AttrAst, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, DirectiveAst, ElementAst, EmbeddedTemplateAst, NgContentAst, PropertyBindingType, ProviderAst, QueryMatch, ReferenceAst, TemplateAst, TemplateAstVisitor, templateVisitAll, TextAst, VariableAst} from '../template_parser/template_ast';
import {OutputContext} from '../util';
import {componentFactoryResolverProviderDef, depDef, lifecycleHookToNodeFlag, providerDef} from './provider_compiler';

View File

@ -6,10 +6,11 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AotSummaryResolver, AotSummaryResolverHost, ResolvedStaticSymbol, StaticSymbolCache, StaticSymbolResolver} from '@angular/compiler';
import {serializeSummaries} from '@angular/compiler/src/aot/summary_serializer';
import {ConstantPool, OutputContext} from '@angular/compiler/src/constant_pool';
import {AotSummaryResolver, AotSummaryResolverHost, CompileSummaryKind, CompileTypeSummary, ResolvedStaticSymbol, StaticSymbol, StaticSymbolCache, StaticSymbolResolver} from '@angular/compiler';
import {deserializeSummaries, serializeSummaries} from '@angular/compiler/src/aot/summary_serializer';
import {ConstantPool} from '@angular/compiler/src/constant_pool';
import * as o from '@angular/compiler/src/output/output_ast';
import {OutputContext} from '@angular/compiler/src/util';
import * as path from 'path';
import {MockStaticSymbolResolverHost, MockSummaryResolver} from './static_symbol_resolver_spec';

View File

@ -10,9 +10,8 @@ import {LIFECYCLE_HOOKS_VALUES, LifecycleHooks} from '@angular/compiler/src/life
import {AfterContentChecked, AfterContentInit, AfterViewChecked, AfterViewInit, ChangeDetectionStrategy, Component, Directive, DoCheck, Injectable, NgModule, OnChanges, OnDestroy, OnInit, Pipe, SimpleChanges, ViewEncapsulation, ɵstringify as stringify} from '@angular/core';
import {inject, TestBed, waitForAsync} from '@angular/core/testing';
import {CompileDiDependencyMetadata} from '../src/compile_metadata';
import {CompileDiDependencyMetadata, identifierName} from '../src/compile_metadata';
import {CompileMetadataResolver} from '../src/metadata_resolver';
import {identifierName} from '../src/parse_util';
import {ResourceLoader} from '../src/resource_loader';
import {MockResourceLoader} from '../testing/src/resource_loader_mock';

View File

@ -6,6 +6,8 @@
* found in the LICENSE file at https://angular.io/license
*/
import {StaticSymbol} from '@angular/compiler/src/aot/static_symbol';
import {CompileIdentifierMetadata} from '@angular/compiler/src/compile_metadata';
import {JavaScriptEmitter} from '@angular/compiler/src/output/js_emitter';
import * as o from '@angular/compiler/src/output/output_ast';
import {SourceMap} from '@angular/compiler/src/output/source_map';