refactor(ivy): remove deep imports into the compiler (#31376)

The compiler-cli should only reference code that can
be imported from the main entry-point of compiler.

PR Close #31376
This commit is contained in:
Pete Bacon Darwin 2019-07-01 20:58:28 +01:00 committed by Miško Hevery
parent 4aecf9253b
commit 376ad9c3cd
5 changed files with 16 additions and 19 deletions

View File

@ -6,8 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {Expression, ExternalExpr, InvokeFunctionExpr, LiteralArrayExpr, LiteralExpr, R3Identifiers, R3InjectorMetadata, R3NgModuleMetadata, R3Reference, Statement, WrappedNodeExpr, compileInjector, compileNgModule} from '@angular/compiler';
import {STRING_TYPE} from '@angular/compiler/src/output/output_ast';
import {Expression, ExternalExpr, InvokeFunctionExpr, LiteralArrayExpr, LiteralExpr, R3Identifiers, R3InjectorMetadata, R3NgModuleMetadata, R3Reference, STRING_TYPE, Statement, WrappedNodeExpr, compileInjector, compileNgModule} from '@angular/compiler';
import * as ts from 'typescript';
import {ErrorCode, FatalDiagnosticError} from '../../diagnostics';
@ -19,6 +18,7 @@ import {NgModuleRouteAnalyzer} from '../../routing';
import {LocalModuleScopeRegistry, ScopeData} from '../../scope';
import {AnalysisOutput, CompileResult, DecoratorHandler, DetectResult, HandlerPrecedence, ResolveResult} from '../../transform';
import {getSourceFile} from '../../util/src/typescript';
import {generateSetClassMetadataCall} from './metadata';
import {ReferencesRegistry} from './references_registry';
import {combineResolvers, findAngularDecorator, forwardRefResolver, getValidConstructorDependencies, isExpressionForwardReference, toR3Reference, unwrapExpression} from './util';

View File

@ -5,8 +5,7 @@
* 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 {Expression, ExternalExpr, WrappedNodeExpr} from '@angular/compiler';
import {ExternalReference} from '@angular/compiler/src/compiler';
import {Expression, ExternalExpr, ExternalReference, WrappedNodeExpr} from '@angular/compiler';
import * as ts from 'typescript';
import {LogicalFileSystem, LogicalProjectPath, absoluteFrom} from '../../file_system';
import {ReflectionHost} from '../../reflection';

View File

@ -5,9 +5,7 @@
* 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 {AST, BoundTarget, ImplicitReceiver, MethodCall, PropertyRead, RecursiveAstVisitor} from '@angular/compiler';
import {BoundText, Element, Node, RecursiveVisitor as RecursiveTemplateVisitor, Template} from '@angular/compiler/src/render3/r3_ast';
import {AST, BoundTarget, ImplicitReceiver, MethodCall, PropertyRead, RecursiveAstVisitor, TmplAstBoundText, TmplAstElement, TmplAstNode, TmplAstRecursiveVisitor, TmplAstTemplate} from '@angular/compiler';
import {AbsoluteSourceSpan, AttributeIdentifier, ElementIdentifier, IdentifierKind, MethodIdentifier, PropertyIdentifier, TemplateIdentifier, TopLevelIdentifier} from './api';
import {ComponentMeta} from './context';
@ -15,7 +13,7 @@ import {ComponentMeta} from './context';
* A parsed node in a template, which may have a name (if it is a selector) or
* be anonymous (like a text span).
*/
interface HTMLNode extends Node {
interface HTMLNode extends TmplAstNode {
tagName?: string;
name?: string;
}
@ -35,7 +33,7 @@ class ExpressionVisitor extends RecursiveAstVisitor {
readonly identifiers: ExpressionIdentifier[] = [];
private constructor(
context: Node, private readonly boundTemplate: BoundTarget<ComponentMeta>,
context: TmplAstNode, private readonly boundTemplate: BoundTarget<ComponentMeta>,
private readonly expressionStr = context.sourceSpan.toString(),
private readonly absoluteOffset = context.sourceSpan.start.offset) {
super();
@ -49,7 +47,7 @@ class ExpressionVisitor extends RecursiveAstVisitor {
* @param boundTemplate bound target of the entire template, which can be used to query for the
* entities expressions target.
*/
static getIdentifiers(ast: AST, context: Node, boundTemplate: BoundTarget<ComponentMeta>):
static getIdentifiers(ast: AST, context: TmplAstNode, boundTemplate: BoundTarget<ComponentMeta>):
TopLevelIdentifier[] {
const visitor = new ExpressionVisitor(context, boundTemplate);
visitor.visit(ast);
@ -108,7 +106,7 @@ class ExpressionVisitor extends RecursiveAstVisitor {
* Visits the AST of a parsed Angular template. Discovers and stores
* identifiers of interest, deferring to an `ExpressionVisitor` as needed.
*/
class TemplateVisitor extends RecursiveTemplateVisitor {
class TemplateVisitor extends TmplAstRecursiveVisitor {
// identifiers of interest found in the template
readonly identifiers = new Set<TopLevelIdentifier>();
@ -127,14 +125,14 @@ class TemplateVisitor extends RecursiveTemplateVisitor {
*/
visit(node: HTMLNode) { node.visit(this); }
visitAll(nodes: Node[]) { nodes.forEach(node => this.visit(node)); }
visitAll(nodes: TmplAstNode[]) { nodes.forEach(node => this.visit(node)); }
/**
* Add an identifier for an HTML element and visit its children recursively.
*
* @param element
*/
visitElement(element: Element) {
visitElement(element: TmplAstElement) {
// Record the element's attributes, which an indexer can later traverse to see if any of them
// specify a used directive on the element.
const attributes = element.attributes.map(({name, value, sourceSpan}): AttributeIdentifier => {
@ -166,20 +164,20 @@ class TemplateVisitor extends RecursiveTemplateVisitor {
this.visitAll(element.children);
this.visitAll(element.references);
}
visitTemplate(template: Template) {
visitTemplate(template: TmplAstTemplate) {
this.visitAll(template.attributes);
this.visitAll(template.children);
this.visitAll(template.references);
this.visitAll(template.variables);
}
visitBoundText(text: BoundText) { this.visitExpression(text); }
visitBoundText(text: TmplAstBoundText) { this.visitExpression(text); }
/**
* Visits a node's expression and adds its identifiers, if any, to the visitor's state.
*
* @param node node whose expression to visit
*/
private visitExpression(node: Node&{value: AST}) {
private visitExpression(node: TmplAstNode&{value: AST}) {
const identifiers = ExpressionVisitor.getIdentifiers(node.value, node, this.boundTemplate);
identifiers.forEach(id => this.identifiers.add(id));
}

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {ParseSourceFile} from '@angular/compiler/src/compiler';
import {ParseSourceFile} from '@angular/compiler';
import * as ts from 'typescript';
import {IndexedComponent} from './api';
import {IndexingContext} from './context';

View File

@ -76,7 +76,7 @@ export * from './ml_parser/interpolation_config';
export * from './ml_parser/tags';
export {LexerRange} from './ml_parser/lexer';
export {NgModuleCompiler} from './ng_module_compiler';
export {ArrayType, AssertNotNull, DYNAMIC_TYPE, BinaryOperator, BinaryOperatorExpr, BuiltinMethod, BuiltinType, BuiltinTypeName, BuiltinVar, CastExpr, ClassField, ClassMethod, ClassStmt, CommaExpr, CommentStmt, ConditionalExpr, DeclareFunctionStmt, DeclareVarStmt, Expression, ExpressionStatement, ExpressionType, ExpressionVisitor, ExternalExpr, ExternalReference, literalMap, FunctionExpr, IfStmt, InstantiateExpr, InvokeFunctionExpr, InvokeMethodExpr, JSDocCommentStmt, LiteralArrayExpr, LiteralExpr, LiteralMapExpr, MapType, NotExpr, ReadKeyExpr, ReadPropExpr, ReadVarExpr, ReturnStatement, StatementVisitor, ThrowStmt, TryCatchStmt, Type, TypeVisitor, WrappedNodeExpr, WriteKeyExpr, WritePropExpr, WriteVarExpr, StmtModifier, Statement, TypeofExpr, collectExternalReferences} from './output/output_ast';
export {ArrayType, AssertNotNull, DYNAMIC_TYPE, BinaryOperator, BinaryOperatorExpr, BuiltinMethod, BuiltinType, BuiltinTypeName, BuiltinVar, CastExpr, ClassField, ClassMethod, ClassStmt, CommaExpr, CommentStmt, ConditionalExpr, DeclareFunctionStmt, DeclareVarStmt, Expression, ExpressionStatement, ExpressionType, ExpressionVisitor, ExternalExpr, ExternalReference, literalMap, FunctionExpr, IfStmt, InstantiateExpr, InvokeFunctionExpr, InvokeMethodExpr, JSDocCommentStmt, LiteralArrayExpr, LiteralExpr, LiteralMapExpr, MapType, NotExpr, ReadKeyExpr, ReadPropExpr, ReadVarExpr, ReturnStatement, StatementVisitor, ThrowStmt, TryCatchStmt, Type, TypeVisitor, WrappedNodeExpr, WriteKeyExpr, WritePropExpr, WriteVarExpr, StmtModifier, Statement, STRING_TYPE, TypeofExpr, collectExternalReferences} from './output/output_ast';
export {EmitterVisitorContext} from './output/abstract_emitter';
export {JitEvaluator} from './output/output_jit';
export * from './output/ts_emitter';
@ -90,7 +90,7 @@ export {getParseErrors, isSyntaxError, syntaxError, Version} from './util';
export {SourceMap} from './output/source_map';
export * from './injectable_compiler_2';
export * from './render3/view/api';
export {BoundAttribute as TmplAstBoundAttribute, BoundEvent as TmplAstBoundEvent, BoundText as TmplAstBoundText, Content as TmplAstContent, Element as TmplAstElement, Node as TmplAstNode, Reference as TmplAstReference, Template as TmplAstTemplate, Text as TmplAstText, TextAttribute as TmplAstTextAttribute, Variable as TmplAstVariable,} from './render3/r3_ast';
export {BoundAttribute as TmplAstBoundAttribute, BoundEvent as TmplAstBoundEvent, BoundText as TmplAstBoundText, Content as TmplAstContent, Element as TmplAstElement, Node as TmplAstNode, RecursiveVisitor as TmplAstRecursiveVisitor, Reference as TmplAstReference, Template as TmplAstTemplate, Text as TmplAstText, TextAttribute as TmplAstTextAttribute, Variable as TmplAstVariable,} from './render3/r3_ast';
export * from './render3/view/t2_api';
export * from './render3/view/t2_binder';
export {Identifiers as R3Identifiers} from './render3/r3_identifiers';