@ -28,7 +28,7 @@ export class Rule extends Rules.TypedRule {
|
||||
const typeChecker = program.getTypeChecker();
|
||||
const queryVisitor = new NgQueryResolveVisitor(program.getTypeChecker());
|
||||
const templateVisitor = new NgComponentTemplateVisitor(typeChecker);
|
||||
const rootSourceFiles = program.getRootFileNames().map(f => program.getSourceFile(f) !);
|
||||
const rootSourceFiles = program.getRootFileNames().map(f => program.getSourceFile(f)!);
|
||||
const printer = ts.createPrinter();
|
||||
const failures: RuleFailure[] = [];
|
||||
|
||||
@ -44,7 +44,7 @@ export class Rule extends Rules.TypedRule {
|
||||
// check component templates for static query usage.
|
||||
templateVisitor.resolvedTemplates.forEach(template => {
|
||||
if (classMetadata.has(template.container)) {
|
||||
classMetadata.get(template.container) !.template = template;
|
||||
classMetadata.get(template.container)!.template = template;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -50,7 +50,7 @@ export class Rule extends Rules.TypedRule {
|
||||
transformer.recordChanges();
|
||||
|
||||
if (updateRecorders.has(sourceFile)) {
|
||||
failures.push(...updateRecorders.get(sourceFile) !.failures);
|
||||
failures.push(...updateRecorders.get(sourceFile)!.failures);
|
||||
}
|
||||
|
||||
return failures;
|
||||
@ -58,7 +58,7 @@ export class Rule extends Rules.TypedRule {
|
||||
/** Gets the update recorder for the specified source file. */
|
||||
function getUpdateRecorder(sourceFile: ts.SourceFile): TslintUpdateRecorder {
|
||||
if (updateRecorders.has(sourceFile)) {
|
||||
return updateRecorders.get(sourceFile) !;
|
||||
return updateRecorders.get(sourceFile)!;
|
||||
}
|
||||
const recorder = new TslintUpdateRecorder(ruleName, sourceFile);
|
||||
updateRecorders.set(sourceFile, recorder);
|
||||
|
@ -9,7 +9,7 @@
|
||||
import {Replacement, RuleFailure, Rules} from 'tslint';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {HelperFunction, getHelper} from '../renderer-to-renderer2/helpers';
|
||||
import {getHelper, HelperFunction} from '../renderer-to-renderer2/helpers';
|
||||
import {migrateExpression, replaceImport} from '../renderer-to-renderer2/migration';
|
||||
import {findCoreImport, findRendererReferences} from '../renderer-to-renderer2/util';
|
||||
|
||||
@ -75,7 +75,7 @@ export class Rule extends Rules.TypedRule {
|
||||
private _getTypedNodeFailure(
|
||||
node: ts.ParameterDeclaration|ts.PropertyDeclaration|ts.AsExpression,
|
||||
sourceFile: ts.SourceFile): RuleFailure {
|
||||
const type = node.type !;
|
||||
const type = node.type!;
|
||||
|
||||
return new RuleFailure(
|
||||
sourceFile, type.getStart(), type.getEnd(),
|
||||
|
@ -32,14 +32,14 @@ export class Rule extends Rules.TypedRule {
|
||||
transform.recordChanges();
|
||||
|
||||
if (updateRecorders.has(sourceFile)) {
|
||||
return updateRecorders.get(sourceFile) !.failures;
|
||||
return updateRecorders.get(sourceFile)!.failures;
|
||||
}
|
||||
return [];
|
||||
|
||||
/** Gets the update recorder for the specified source file. */
|
||||
function getUpdateRecorder(sourceFile: ts.SourceFile): TslintUpdateRecorder {
|
||||
if (updateRecorders.has(sourceFile)) {
|
||||
return updateRecorders.get(sourceFile) !;
|
||||
return updateRecorders.get(sourceFile)!;
|
||||
}
|
||||
const recorder = new TslintUpdateRecorder(ruleName, sourceFile);
|
||||
updateRecorders.set(sourceFile, recorder);
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {NgDecorator, getAngularDecorators} from '../../utils/ng_decorators';
|
||||
import {getAngularDecorators, NgDecorator} from '../../utils/ng_decorators';
|
||||
import {getPropertyNameText} from '../../utils/typescript/property_name';
|
||||
|
||||
export interface ResolvedNgModule {
|
||||
|
@ -21,7 +21,8 @@ export class TslintUpdateRecorder implements UpdateRecorder {
|
||||
// are handled in reverse and in case a decorator and import are inserted at
|
||||
// the start of the file, the class decorator should come after the import.
|
||||
this.failures.unshift(new RuleFailure(
|
||||
this.sourceFile, node.getStart(), 0, `Class needs to be decorated with ` +
|
||||
this.sourceFile, node.getStart(), 0,
|
||||
`Class needs to be decorated with ` +
|
||||
`"${decoratorText}" because it has been provided by "${className}".`,
|
||||
this.ruleName, Replacement.appendText(node.getStart(), `${decoratorText}\n`)));
|
||||
}
|
||||
|
@ -46,7 +46,9 @@ export class MissingInjectableTransform {
|
||||
new TypeScriptReflectionHost(typeChecker), typeChecker, /* dependencyTracker */ null);
|
||||
}
|
||||
|
||||
recordChanges() { this.importManager.recordChanges(); }
|
||||
recordChanges() {
|
||||
this.importManager.recordChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* Migrates all specified NgModule's by walking through referenced providers
|
||||
@ -76,10 +78,9 @@ export class MissingInjectableTransform {
|
||||
this._migrateLiteralProviders(literals);
|
||||
|
||||
if (!Array.isArray(resolvedValue)) {
|
||||
return [{
|
||||
node: module.providersExpr,
|
||||
message: 'Providers of module are not statically analyzable.'
|
||||
}];
|
||||
return [
|
||||
{node: module.providersExpr, message: 'Providers of module are not statically analyzable.'}
|
||||
];
|
||||
}
|
||||
|
||||
return this._visitProviderResolvedValue(resolvedValue, module);
|
||||
@ -194,8 +195,9 @@ export class MissingInjectableTransform {
|
||||
|
||||
const sourceFile = node.getSourceFile();
|
||||
const newObjectLiteral = ts.updateObjectLiteral(
|
||||
node, node.properties.concat(
|
||||
ts.createPropertyAssignment('useValue', ts.createIdentifier('undefined'))));
|
||||
node,
|
||||
node.properties.concat(
|
||||
ts.createPropertyAssignment('useValue', ts.createIdentifier('undefined'))));
|
||||
|
||||
this.getUpdateRecorder(sourceFile)
|
||||
.updateObjectLiteral(
|
||||
@ -217,11 +219,12 @@ export class MissingInjectableTransform {
|
||||
// decorate the class. This is because the class is instantiated through the
|
||||
// specified "deps" and the class does not need a factory definition.
|
||||
if (value.has('provide') && value.has('useClass') && value.get('deps') == null) {
|
||||
return this._visitProviderResolvedValue(value.get('useClass') !, module);
|
||||
return this._visitProviderResolvedValue(value.get('useClass')!, module);
|
||||
}
|
||||
} else if (Array.isArray(value)) {
|
||||
return value.reduce((res, v) => res.concat(this._visitProviderResolvedValue(v, module)), [
|
||||
] as AnalysisFailure[]);
|
||||
return value.reduce(
|
||||
(res, v) => res.concat(this._visitProviderResolvedValue(v, module)),
|
||||
[] as AnalysisFailure[]);
|
||||
} else if (value instanceof DynamicValue) {
|
||||
return [{node: value.node, message: `Provider is not statically analyzable.`}];
|
||||
}
|
||||
|
@ -8,7 +8,8 @@
|
||||
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {NgDecorator, getAngularDecorators} from '../../utils/ng_decorators';
|
||||
import {getAngularDecorators, NgDecorator} from '../../utils/ng_decorators';
|
||||
|
||||
import {isModuleWithProvidersNotGeneric} from './util';
|
||||
|
||||
export interface ResolvedNgModule {
|
||||
|
@ -35,7 +35,7 @@ export class ModuleWithProvidersTransform {
|
||||
/** Migrates a given NgModule by walking through the referenced providers and static methods. */
|
||||
migrateModule(module: ResolvedNgModule): AnalysisFailure[] {
|
||||
return module.staticMethodsWithoutType.map(this._migrateStaticNgModuleMethod.bind(this))
|
||||
.filter(v => v) as AnalysisFailure[];
|
||||
.filter(v => v) as AnalysisFailure[];
|
||||
}
|
||||
|
||||
/** Migrates a ModuleWithProviders type definition that has no explicit generic type */
|
||||
@ -98,8 +98,10 @@ export class ModuleWithProvidersTransform {
|
||||
return ngModule && (value.size === 1 || (providers && value.size === 2));
|
||||
}
|
||||
|
||||
/** Determine the generic type of a suspected ModuleWithProviders return type and add it
|
||||
* explicitly */
|
||||
/**
|
||||
* Determine the generic type of a suspected ModuleWithProviders return type and add it
|
||||
* explicitly
|
||||
*/
|
||||
private _migrateStaticNgModuleMethod(node: ts.MethodDeclaration): AnalysisFailure|null {
|
||||
const returnStatement = node.body &&
|
||||
node.body.statements.find(n => ts.isReturnStatement(n)) as ts.ReturnStatement | undefined;
|
||||
@ -131,7 +133,7 @@ export class ModuleWithProvidersTransform {
|
||||
*/
|
||||
private _getTypeOfResolvedValue(value: ResolvedValue): string|undefined {
|
||||
if (value instanceof Map && this.isModuleWithProvidersType(value)) {
|
||||
const mapValue = value.get('ngModule') !;
|
||||
const mapValue = value.get('ngModule')!;
|
||||
if (mapValue instanceof Reference && ts.isClassDeclaration(mapValue.node) &&
|
||||
mapValue.node.name) {
|
||||
return mapValue.node.name.text;
|
||||
|
@ -69,7 +69,7 @@ function createAnyTypeHelper(): ts.TypeAliasDeclaration {
|
||||
|
||||
/** Creates a function parameter that is typed as `any`. */
|
||||
function getAnyTypedParameter(
|
||||
parameterName: string | ts.Identifier, isRequired = true): ts.ParameterDeclaration {
|
||||
parameterName: string|ts.Identifier, isRequired = true): ts.ParameterDeclaration {
|
||||
// Declare the parameter as `any` so we don't have to add extra logic to ensure that the
|
||||
// generated code will pass type checking. Use our custom `any` type so people have an incentive
|
||||
// to clean it up afterwards and to avoid potentially introducing lint warnings in G3.
|
||||
@ -153,10 +153,11 @@ function getCreationHelper(
|
||||
|
||||
// `if (parent) { renderer.appendChild(parent, node) }`.
|
||||
const guardedAppendChildCall = ts.createIf(
|
||||
parent, ts.createBlock(
|
||||
[ts.createExpressionStatement(ts.createCall(
|
||||
ts.createPropertyAccess(renderer, 'appendChild'), [], [parent, node]))],
|
||||
true));
|
||||
parent,
|
||||
ts.createBlock(
|
||||
[ts.createExpressionStatement(
|
||||
ts.createCall(ts.createPropertyAccess(renderer, 'appendChild'), [], [parent, node]))],
|
||||
true));
|
||||
|
||||
return ts.createFunctionDeclaration(
|
||||
[], [], undefined, functionName, [],
|
||||
@ -258,10 +259,11 @@ function getDetachViewHelper(): ts.FunctionDeclaration {
|
||||
|
||||
// const node = rootNodes[i];
|
||||
const nodeVariableStatement = ts.createVariableStatement(
|
||||
undefined, ts.createVariableDeclarationList(
|
||||
[ts.createVariableDeclaration(
|
||||
node, undefined, ts.createElementAccess(rootNodes, incrementor))],
|
||||
ts.NodeFlags.Const));
|
||||
undefined,
|
||||
ts.createVariableDeclarationList(
|
||||
[ts.createVariableDeclaration(
|
||||
node, undefined, ts.createElementAccess(rootNodes, incrementor))],
|
||||
ts.NodeFlags.Const));
|
||||
// renderer.removeChild(renderer.parentNode(node), node);
|
||||
const removeCall = ts.createCall(
|
||||
ts.createPropertyAccess(renderer, 'removeChild'), [],
|
||||
|
@ -12,7 +12,7 @@ import {HelperFunction} from './helpers';
|
||||
import {findImportSpecifier} from './util';
|
||||
|
||||
/** A call expression that is based on a property access. */
|
||||
type PropertyAccessCallExpression = ts.CallExpression & {expression: ts.PropertyAccessExpression};
|
||||
type PropertyAccessCallExpression = ts.CallExpression&{expression: ts.PropertyAccessExpression};
|
||||
|
||||
/** Replaces an import inside an import statement with a different one. */
|
||||
export function replaceImport(node: ts.NamedImports, oldImport: string, newImport: string) {
|
||||
@ -42,7 +42,7 @@ export function replaceImport(node: ts.NamedImports, oldImport: string, newImpor
|
||||
* Returns null if the expression should be dropped.
|
||||
*/
|
||||
export function migrateExpression(node: ts.CallExpression, typeChecker: ts.TypeChecker):
|
||||
{node: ts.Node | null, requiredHelpers?: HelperFunction[]} {
|
||||
{node: ts.Node|null, requiredHelpers?: HelperFunction[]} {
|
||||
if (isPropertyAccessCallExpression(node)) {
|
||||
switch (node.expression.name.getText()) {
|
||||
case 'setElementProperty':
|
||||
@ -152,7 +152,7 @@ function migrateSetElementClass(node: PropertyAccessCallExpression): ts.Node {
|
||||
// Clone so we don't mutate by accident. Note that we assume that
|
||||
// the user's code is providing all three required arguments.
|
||||
const outputMethodArgs = node.arguments.slice();
|
||||
const isAddArgument = outputMethodArgs.pop() !;
|
||||
const isAddArgument = outputMethodArgs.pop()!;
|
||||
const createRendererCall = (isAdd: boolean) => {
|
||||
const innerExpression = node.expression.expression;
|
||||
const topExpression =
|
||||
@ -263,6 +263,6 @@ function migrateAnimateCall() {
|
||||
*/
|
||||
function switchToHelperCall(
|
||||
node: PropertyAccessCallExpression, helper: HelperFunction,
|
||||
args: ts.Expression[] | ts.NodeArray<ts.Expression>): ts.Node {
|
||||
args: ts.Expression[]|ts.NodeArray<ts.Expression>): ts.Node {
|
||||
return ts.createCall(ts.createIdentifier(helper), [], [node.expression.expression, ...args]);
|
||||
}
|
||||
|
@ -88,8 +88,7 @@ export function findImportSpecifier(
|
||||
|
||||
/** Checks whether a node is referring to an import spcifier. */
|
||||
function isReferenceToImport(
|
||||
typeChecker: ts.TypeChecker, node: ts.Node,
|
||||
importSpecifier: ts.ImportSpecifier | null): boolean {
|
||||
typeChecker: ts.TypeChecker, node: ts.Node, importSpecifier: ts.ImportSpecifier|null): boolean {
|
||||
if (importSpecifier) {
|
||||
const nodeSymbol = typeChecker.getTypeAtLocation(node).getSymbol();
|
||||
const importSymbol = typeChecker.getTypeAtLocation(importSpecifier).getSymbol();
|
||||
@ -102,7 +101,7 @@ function isReferenceToImport(
|
||||
/** Finds the identifier referring to the `Renderer` inside a `forwardRef` call expression. */
|
||||
function findRendererIdentifierInForwardRef(
|
||||
typeChecker: ts.TypeChecker, node: ts.CallExpression,
|
||||
rendererImport: ts.ImportSpecifier | null): ts.Identifier|null {
|
||||
rendererImport: ts.ImportSpecifier|null): ts.Identifier|null {
|
||||
const firstArg = node.arguments[0];
|
||||
|
||||
if (ts.isArrowFunction(firstArg)) {
|
||||
|
@ -24,7 +24,7 @@ export function getInputNamesOfClass(
|
||||
}
|
||||
|
||||
const inputDecorator =
|
||||
getAngularDecorators(typeChecker, m.decorators !).find(d => d.name === 'Input');
|
||||
getAngularDecorators(typeChecker, m.decorators!).find(d => d.name === 'Input');
|
||||
|
||||
if (inputDecorator && hasPropertyNameText(m.name)) {
|
||||
resolvedInputSetters.push(m.name.text);
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {AotCompiler, CompileDirectiveMetadata, CompileMetadataResolver, CompileNgModuleMetadata, CompileStylesheetMetadata, ElementAst, EmbeddedTemplateAst, NgAnalyzedModules, QueryMatch, StaticSymbol, TemplateAst} from '@angular/compiler';
|
||||
import {Diagnostic, createProgram, readConfiguration} from '@angular/compiler-cli';
|
||||
import {createProgram, Diagnostic, readConfiguration} from '@angular/compiler-cli';
|
||||
import {resolve} from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
@ -46,17 +46,17 @@ export class QueryTemplateStrategy implements TimingStrategy {
|
||||
// expose the logic that is necessary to analyze the determined modules. We work around
|
||||
// this by just accessing the necessary private properties using the bracket notation.
|
||||
this.compiler = (aotProgram as any)['compiler'];
|
||||
this.metadataResolver = this.compiler !['_metadataResolver'];
|
||||
this.metadataResolver = this.compiler!['_metadataResolver'];
|
||||
|
||||
// Modify the "DirectiveNormalizer" to not normalize any referenced external stylesheets.
|
||||
// This is necessary because in CLI projects preprocessor files are commonly referenced
|
||||
// and we don't want to parse them in order to extract relative style references. This
|
||||
// breaks the analysis of the project because we instantiate a standalone AOT compiler
|
||||
// program which does not contain the custom logic by the Angular CLI Webpack compiler plugin.
|
||||
const directiveNormalizer = this.metadataResolver !['_directiveNormalizer'];
|
||||
const directiveNormalizer = this.metadataResolver!['_directiveNormalizer'];
|
||||
directiveNormalizer['_normalizeStylesheet'] = function(metadata: CompileStylesheetMetadata) {
|
||||
return new CompileStylesheetMetadata(
|
||||
{styles: metadata.styles, styleUrls: [], moduleUrl: metadata.moduleUrl !});
|
||||
{styles: metadata.styles, styleUrls: [], moduleUrl: metadata.moduleUrl!});
|
||||
};
|
||||
|
||||
// Retrieves the analyzed modules of the current program. This data can be
|
||||
@ -75,7 +75,7 @@ export class QueryTemplateStrategy implements TimingStrategy {
|
||||
|
||||
/** Analyzes a given directive by determining the timing of all matched view queries. */
|
||||
private _analyzeDirective(symbol: StaticSymbol, analyzedModules: NgAnalyzedModules) {
|
||||
const metadata = this.metadataResolver !.getDirectiveMetadata(symbol);
|
||||
const metadata = this.metadataResolver!.getDirectiveMetadata(symbol);
|
||||
const ngModule = analyzedModules.ngModuleByPipeOrDirective.get(symbol);
|
||||
|
||||
if (!metadata.isComponent || !ngModule) {
|
||||
@ -168,7 +168,7 @@ export class QueryTemplateStrategy implements TimingStrategy {
|
||||
const queryKey = this._getViewQueryUniqueKey(filePath, classDecl.name.text, queryName);
|
||||
|
||||
if (this.analyzedQueries.has(queryKey)) {
|
||||
return this.analyzedQueries.get(queryKey) !;
|
||||
return this.analyzedQueries.get(queryKey)!;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -176,7 +176,7 @@ export class QueryTemplateStrategy implements TimingStrategy {
|
||||
private _parseTemplate(component: CompileDirectiveMetadata, ngModule: CompileNgModuleMetadata):
|
||||
TemplateAst[] {
|
||||
return this
|
||||
.compiler 
|
||||
.compiler
|
||||
.template;
|
||||
}
|
||||
|
||||
@ -201,11 +201,11 @@ function findStaticQueryIds(
|
||||
nodes.forEach((node) => {
|
||||
const staticQueryIds = new Set<number>();
|
||||
const dynamicQueryIds = new Set<number>();
|
||||
let queryMatches: QueryMatch[] = undefined !;
|
||||
let queryMatches: QueryMatch[] = undefined!;
|
||||
if (node instanceof ElementAst) {
|
||||
findStaticQueryIds(node.children, result);
|
||||
node.children.forEach((child) => {
|
||||
const childData = result.get(child) !;
|
||||
const childData = result.get(child)!;
|
||||
childData.staticQueryIds.forEach(queryId => staticQueryIds.add(queryId));
|
||||
childData.dynamicQueryIds.forEach(queryId => dynamicQueryIds.add(queryId));
|
||||
});
|
||||
@ -213,7 +213,7 @@ function findStaticQueryIds(
|
||||
} else if (node instanceof EmbeddedTemplateAst) {
|
||||
findStaticQueryIds(node.children, result);
|
||||
node.children.forEach((child) => {
|
||||
const childData = result.get(child) !;
|
||||
const childData = result.get(child)!;
|
||||
childData.staticQueryIds.forEach(queryId => dynamicQueryIds.add(queryId));
|
||||
childData.dynamicQueryIds.forEach(queryId => dynamicQueryIds.add(queryId));
|
||||
});
|
||||
|
@ -16,5 +16,6 @@ export interface TimingStrategy {
|
||||
}
|
||||
|
||||
export type TimingResult = {
|
||||
timing: QueryTiming | null; message?: string;
|
||||
timing: QueryTiming|null;
|
||||
message?: string;
|
||||
};
|
||||
|
@ -167,7 +167,7 @@ export class DeclarationUsageVisitor {
|
||||
d.body && !this.visitedJumpExprNodes.has(d))
|
||||
.forEach(d => {
|
||||
this.visitedJumpExprNodes.add(d);
|
||||
this.nodeQueue.push(d.body !);
|
||||
this.nodeQueue.push(d.body!);
|
||||
});
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ export class DeclarationUsageVisitor {
|
||||
this.ambiguousNodeQueue = [];
|
||||
|
||||
while (this.nodeQueue.length) {
|
||||
const node = this.nodeQueue.shift() !;
|
||||
const node = this.nodeQueue.shift()!;
|
||||
|
||||
if (ts.isIdentifier(node) && this.isReferringToSymbol(node)) {
|
||||
return ResolvedUsage.SYNCHRONOUS;
|
||||
@ -306,7 +306,7 @@ export class DeclarationUsageVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
jumpExp.arguments !.forEach((node: ts.Node) => {
|
||||
jumpExp.arguments!.forEach((node: ts.Node) => {
|
||||
node = this._resolveDeclarationOfNode(node);
|
||||
|
||||
if (ts.isVariableDeclaration(node) && node.initializer) {
|
||||
@ -325,7 +325,7 @@ export class DeclarationUsageVisitor {
|
||||
*/
|
||||
private _resolveNodeFromContext(node: ts.Node): ts.Node {
|
||||
if (this.context.has(node)) {
|
||||
return this.context.get(node) !;
|
||||
return this.context.get(node)!;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ export function updateSuperClassAbstractMembersContext(
|
||||
const baseClassImpl = baseClass.members.find(
|
||||
baseClassMethod => !!baseClassMethod.name &&
|
||||
getPropertyNameText(baseClassMethod.name) ===
|
||||
getPropertyNameText(superClassMember.name !));
|
||||
getPropertyNameText(superClassMember.name!));
|
||||
|
||||
if (!baseClassImpl || !isFunctionLikeDeclaration(baseClassImpl) || !baseClassImpl.body) {
|
||||
return;
|
||||
|
@ -17,7 +17,9 @@ export class TemplateUsageVisitor extends NullVisitor {
|
||||
private hasQueryTemplateReference = false;
|
||||
private expressionAstVisitor = new ExpressionAstVisitor(this.queryPropertyName);
|
||||
|
||||
constructor(public queryPropertyName: string) { super(); }
|
||||
constructor(public queryPropertyName: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
/** Checks whether the given query is statically accessed within the specified HTML nodes. */
|
||||
isQueryUsedStatically(htmlNodes: Node[]): boolean {
|
||||
@ -59,7 +61,9 @@ export class TemplateUsageVisitor extends NullVisitor {
|
||||
attribute.value.visit(this.expressionAstVisitor, attribute.sourceSpan);
|
||||
}
|
||||
|
||||
visitBoundText(text: BoundText) { text.value.visit(this.expressionAstVisitor, text.sourceSpan); }
|
||||
visitBoundText(text: BoundText) {
|
||||
text.value.visit(this.expressionAstVisitor, text.sourceSpan);
|
||||
}
|
||||
|
||||
visitBoundEvent(node: BoundEvent) {
|
||||
node.handler.visit(this.expressionAstVisitor, node.handlerSpan);
|
||||
@ -73,7 +77,9 @@ export class TemplateUsageVisitor extends NullVisitor {
|
||||
class ExpressionAstVisitor extends RecursiveAstVisitor {
|
||||
hasQueryPropertyRead = false;
|
||||
|
||||
constructor(private queryPropertyName: string) { super(); }
|
||||
constructor(private queryPropertyName: string) {
|
||||
super();
|
||||
}
|
||||
|
||||
visitPropertyRead(node: PropertyRead, span: ParseSourceSpan): any {
|
||||
// The receiver of the property read needs to be "implicit" as queries are accessed
|
||||
|
@ -70,7 +70,7 @@ export class QueryUsageStrategy implements TimingStrategy {
|
||||
classDecl: ts.ClassDeclaration, query: NgQueryDefinition, knownInputNames: string[],
|
||||
functionCtx: FunctionContext = new Map(), visitInheritedClasses = true): ResolvedUsage {
|
||||
const usageVisitor =
|
||||
new DeclarationUsageVisitor(query.property !, this.typeChecker, functionCtx);
|
||||
new DeclarationUsageVisitor(query.property!, this.typeChecker, functionCtx);
|
||||
const classMetadata = this.classMetadata.get(classDecl);
|
||||
let usage: ResolvedUsage = ResolvedUsage.ASYNCHRONOUS;
|
||||
|
||||
@ -99,10 +99,10 @@ export class QueryUsageStrategy implements TimingStrategy {
|
||||
// In case there is a component template for the current class, we check if the
|
||||
// template statically accesses the current query. In case that's true, the query
|
||||
// can be marked as static.
|
||||
if (classMetadata.template && hasPropertyNameText(query.property !.name)) {
|
||||
if (classMetadata.template && hasPropertyNameText(query.property!.name)) {
|
||||
const template = classMetadata.template;
|
||||
const parsedHtml = parseHtmlGracefully(template.content, template.filePath);
|
||||
const htmlVisitor = new TemplateUsageVisitor(query.property !.name.text);
|
||||
const htmlVisitor = new TemplateUsageVisitor(query.property!.name.text);
|
||||
|
||||
if (parsedHtml && htmlVisitor.isQueryUsedStatically(parsedHtml)) {
|
||||
return ResolvedUsage.SYNCHRONOUS;
|
||||
@ -179,5 +179,5 @@ function filterQueryClassMemberNodes(
|
||||
}
|
||||
return false;
|
||||
})
|
||||
.map(member => member.body !);
|
||||
.map(member => member.body!);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import * as ts from 'typescript';
|
||||
import {getPropertyNameText} from '../../utils/typescript/property_name';
|
||||
import {NgQueryDefinition, QueryTiming} from './angular/query-definition';
|
||||
|
||||
export type TransformedQueryResult = null | {
|
||||
export type TransformedQueryResult = null|{
|
||||
/** Transformed call expression. */
|
||||
node: ts.CallExpression;
|
||||
/** Failure message which is set when the query could not be transformed successfully. */
|
||||
@ -25,7 +25,7 @@ const TODO_CHECK_COMMENT = 'TODO: check static flag';
|
||||
* determined timing. The updated decorator call expression node will be returned.
|
||||
*/
|
||||
export function getTransformedQueryCallExpr(
|
||||
query: NgQueryDefinition, timing: QueryTiming | null,
|
||||
query: NgQueryDefinition, timing: QueryTiming|null,
|
||||
createTodo: boolean): TransformedQueryResult {
|
||||
const queryExpr = query.decorator.node.expression;
|
||||
const queryArguments = queryExpr.arguments;
|
||||
@ -81,7 +81,7 @@ export function getTransformedQueryCallExpr(
|
||||
failureMessage,
|
||||
node: ts.updateCall(
|
||||
queryExpr, queryExpr.expression, queryExpr.typeArguments,
|
||||
[queryArguments[0], newOptionsNode !])
|
||||
[queryArguments[0], newOptionsNode!])
|
||||
};
|
||||
}
|
||||
|
||||
@ -94,8 +94,7 @@ export function getTransformedQueryCallExpr(
|
||||
return {
|
||||
failureMessage: null,
|
||||
node: ts.updateCall(
|
||||
queryExpr, queryExpr.expression, queryExpr.typeArguments,
|
||||
[queryArguments[0], optionsNode])
|
||||
queryExpr, queryExpr.expression, queryExpr.typeArguments, [queryArguments[0], optionsNode])
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,8 @@ export class TslintUpdateRecorder implements UpdateRecorder {
|
||||
// are handled in reverse and in case a decorator and import are inserted at
|
||||
// the start of the file, the class decorator should come after the import.
|
||||
this.failures.unshift(new RuleFailure(
|
||||
this.sourceFile, node.getStart(), 0, `Class needs to be decorated with ` +
|
||||
this.sourceFile, node.getStart(), 0,
|
||||
`Class needs to be decorated with ` +
|
||||
`"${decoratorText}" because it uses Angular features.`,
|
||||
this.ruleName, Replacement.appendText(node.getStart(), `${decoratorText}\n`)));
|
||||
}
|
||||
|
@ -7,11 +7,11 @@
|
||||
*/
|
||||
|
||||
import {PartialEvaluator} from '@angular/compiler-cli/src/ngtsc/partial_evaluator';
|
||||
import {TypeScriptReflectionHost, reflectObjectLiteral} from '@angular/compiler-cli/src/ngtsc/reflection';
|
||||
import {reflectObjectLiteral, TypeScriptReflectionHost} from '@angular/compiler-cli/src/ngtsc/reflection';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {ImportManager} from '../../utils/import_manager';
|
||||
import {NgDecorator, getAngularDecorators} from '../../utils/ng_decorators';
|
||||
import {getAngularDecorators, NgDecorator} from '../../utils/ng_decorators';
|
||||
import {findBaseClassDeclarations} from '../../utils/typescript/find_base_classes';
|
||||
import {unwrapExpression} from '../../utils/typescript/functions';
|
||||
|
||||
@ -56,7 +56,9 @@ export class UndecoratedClassesWithDecoratedFieldsTransform {
|
||||
}
|
||||
|
||||
/** Records all changes that were made in the import manager. */
|
||||
recordChanges() { this.importManager.recordChanges(); }
|
||||
recordChanges() {
|
||||
this.importManager.recordChanges();
|
||||
}
|
||||
|
||||
/** Finds undecorated abstract directives in the specified source files. */
|
||||
private _findUndecoratedAbstractDirectives(sourceFiles: ts.SourceFile[]) {
|
||||
@ -130,9 +132,9 @@ export class UndecoratedClassesWithDecoratedFieldsTransform {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the given decorator resolves to an abstract directive. An directive is
|
||||
* considered "abstract" if there is no selector specified.
|
||||
*/
|
||||
* Checks whether the given decorator resolves to an abstract directive. An directive is
|
||||
* considered "abstract" if there is no selector specified.
|
||||
*/
|
||||
private _isAbstractDirective({node}: NgDecorator): boolean {
|
||||
const metadataArgs = node.expression.arguments;
|
||||
if (metadataArgs.length === 0) {
|
||||
@ -146,7 +148,7 @@ export class UndecoratedClassesWithDecoratedFieldsTransform {
|
||||
if (!metadata.has('selector')) {
|
||||
return false;
|
||||
}
|
||||
const selector = this.partialEvaluator.evaluate(metadata.get('selector') !);
|
||||
const selector = this.partialEvaluator.evaluate(metadata.get('selector')!);
|
||||
return selector == null;
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ export function convertDirectiveMetadataToExpression(
|
||||
/**
|
||||
* Gets a valid property name from the given text. If the text cannot be used
|
||||
* as unquoted identifier, the name will be wrapped in a string literal.
|
||||
*/
|
||||
*/
|
||||
function getPropertyName(name: string): string|ts.StringLiteral {
|
||||
// Matches the most common identifiers that do not need quotes. Constructing a
|
||||
// regular expression that matches the ECMAScript specification in order to determine
|
||||
|
@ -122,7 +122,7 @@ export class DecoratorRewriter {
|
||||
|null {
|
||||
try {
|
||||
return ts
|
||||
.transform(prop, [ctx => this.importRewriterFactory.create(ctx, this.newSourceFile !)])
|
||||
.transform(prop, [ctx => this.importRewriterFactory.create(ctx, this.newSourceFile!)])
|
||||
.transformed[0];
|
||||
} catch (e) {
|
||||
// If the error is for an unresolved identifier, we want to return "null" because
|
||||
|
@ -11,11 +11,11 @@ import {dirname, resolve} from 'path';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {ImportManager} from '../../../utils/import_manager';
|
||||
import {Import, getImportOfIdentifier} from '../../../utils/typescript/imports';
|
||||
import {getImportOfIdentifier, Import} from '../../../utils/typescript/imports';
|
||||
import {getValueSymbolOfDeclaration} from '../../../utils/typescript/symbol';
|
||||
|
||||
import {getPosixPath} from './path_format';
|
||||
import {ResolvedExport, getExportSymbolsOfFile} from './source_file_exports';
|
||||
import {getExportSymbolsOfFile, ResolvedExport} from './source_file_exports';
|
||||
|
||||
|
||||
/**
|
||||
@ -116,7 +116,7 @@ export class ImportRewriteTransformerFactory {
|
||||
*/
|
||||
private _getSourceFileExports(sourceFile: ts.SourceFile): ResolvedExport[] {
|
||||
if (this.sourceFileExports.has(sourceFile)) {
|
||||
return this.sourceFileExports.get(sourceFile) !;
|
||||
return this.sourceFileExports.get(sourceFile)!;
|
||||
}
|
||||
|
||||
const sourceFileExports = getExportSymbolsOfFile(sourceFile, this.typeChecker);
|
||||
|
@ -123,7 +123,7 @@ function runUndecoratedClassesMigration(
|
||||
/** Gets the update recorder for the specified source file. */
|
||||
function getUpdateRecorder(sourceFile: ts.SourceFile): UpdateRecorder {
|
||||
if (updateRecorders.has(sourceFile)) {
|
||||
return updateRecorders.get(sourceFile) !;
|
||||
return updateRecorders.get(sourceFile)!;
|
||||
}
|
||||
const treeRecorder = tree.beginUpdate(relative(basePath, sourceFile.fileName));
|
||||
const recorder: UpdateRecorder = {
|
||||
@ -146,7 +146,9 @@ function runUndecoratedClassesMigration(
|
||||
treeRecorder.remove(namedBindings.getStart(), namedBindings.getWidth());
|
||||
treeRecorder.insertRight(namedBindings.getStart(), newNamedBindings);
|
||||
},
|
||||
commitUpdate() { tree.commitUpdate(treeRecorder); }
|
||||
commitUpdate() {
|
||||
tree.commitUpdate(treeRecorder);
|
||||
}
|
||||
};
|
||||
updateRecorders.set(sourceFile, recorder);
|
||||
return recorder;
|
||||
|
@ -10,7 +10,7 @@ import {Reference} from '@angular/compiler-cli/src/ngtsc/imports';
|
||||
import {PartialEvaluator, ResolvedValue} from '@angular/compiler-cli/src/ngtsc/partial_evaluator';
|
||||
import * as ts from 'typescript';
|
||||
|
||||
import {NgDecorator, getAngularDecorators} from '../../utils/ng_decorators';
|
||||
import {getAngularDecorators, NgDecorator} from '../../utils/ng_decorators';
|
||||
import {getPropertyNameText} from '../../utils/typescript/property_name';
|
||||
|
||||
|
||||
|
@ -17,7 +17,7 @@ import {hasExplicitConstructor} from '../../utils/typescript/class_declaration';
|
||||
import {findBaseClassDeclarations} from '../../utils/typescript/find_base_classes';
|
||||
import {getImportOfIdentifier} from '../../utils/typescript/imports';
|
||||
|
||||
import {UnexpectedMetadataValueError, convertDirectiveMetadataToExpression} from './decorator_rewrite/convert_directive_metadata';
|
||||
import {convertDirectiveMetadataToExpression, UnexpectedMetadataValueError} from './decorator_rewrite/convert_directive_metadata';
|
||||
import {DecoratorRewriter} from './decorator_rewrite/decorator_rewriter';
|
||||
import {hasDirectiveDecorator, hasInjectableDecorator} from './ng_declaration_collector';
|
||||
import {UpdateRecorder} from './update_recorder';
|
||||
@ -316,7 +316,9 @@ export class UndecoratedClassesTransform {
|
||||
}
|
||||
|
||||
/** Records all changes that were made in the import manager. */
|
||||
recordChanges() { this.importManager.recordChanges(); }
|
||||
recordChanges() {
|
||||
this.importManager.recordChanges();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a TypeScript decorator node from the specified declaration metadata. Returns
|
||||
|
@ -47,7 +47,7 @@ describe('dynamic queries migration', () => {
|
||||
});
|
||||
|
||||
it('should remove the options object from a dynamic ViewChild query that only has one property',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Directive, ViewChild } from '@angular/core';
|
||||
|
||||
@ -62,7 +62,7 @@ describe('dynamic queries migration', () => {
|
||||
});
|
||||
|
||||
it('should remove the options object from a dynamic ContentChild query that only has one property',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Directive, ContentChild } from '@angular/core';
|
||||
|
||||
@ -77,7 +77,7 @@ describe('dynamic queries migration', () => {
|
||||
});
|
||||
|
||||
it('should only remove the `static` flag from a ViewChild query if it has more than one property',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Directive, ViewChild, ElementRef } from '@angular/core';
|
||||
|
||||
@ -93,7 +93,7 @@ describe('dynamic queries migration', () => {
|
||||
});
|
||||
|
||||
it('should only remove the `static` flag from a ContentChild query if it has more than one property',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Directive, ContentChild, ElementRef } from '@angular/core';
|
||||
|
||||
@ -108,7 +108,7 @@ describe('dynamic queries migration', () => {
|
||||
.toContain(`@ContentChild('child', { read: ElementRef }) child: ElementRef;`);
|
||||
});
|
||||
|
||||
it('should not change static ViewChild queries', async() => {
|
||||
it('should not change static ViewChild queries', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Directive, ViewChild, ElementRef } from '@angular/core';
|
||||
|
||||
@ -123,7 +123,7 @@ describe('dynamic queries migration', () => {
|
||||
.toContain(`@ViewChild('child', { read: ElementRef, static: true }) child: ElementRef;`);
|
||||
});
|
||||
|
||||
it('should not change static ContentChild queries', async() => {
|
||||
it('should not change static ContentChild queries', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Directive, ContentChild, ElementRef } from '@angular/core';
|
||||
|
||||
@ -138,7 +138,7 @@ describe('dynamic queries migration', () => {
|
||||
.toContain(`@ContentChild('child', { static: true, read: ElementRef }) child: ElementRef;`);
|
||||
});
|
||||
|
||||
it('should migrate dynamic queries on a setter', async() => {
|
||||
it('should migrate dynamic queries on a setter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Directive, ContentChild, ViewChild } from '@angular/core';
|
||||
|
||||
|
@ -17,7 +17,7 @@ describe('Google3 dynamic queries TSLint rule', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
@ -31,7 +31,7 @@ describe('Google3 dynamic queries TSLint rule', () => {
|
||||
const config = Configuration.parseConfigFile({rules: {'dynamic-queries': true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
@ -41,7 +41,9 @@ describe('Google3 dynamic queries TSLint rule', () => {
|
||||
writeFileSync(join(tmpDir, fileName), content);
|
||||
}
|
||||
|
||||
function getFile(fileName: string) { return readFileSync(join(tmpDir, fileName), 'utf8'); }
|
||||
function getFile(fileName: string) {
|
||||
return readFileSync(join(tmpDir, fileName), 'utf8');
|
||||
}
|
||||
|
||||
it('should flag dynamic queries', () => {
|
||||
writeFile('/index.ts', `
|
||||
@ -172,5 +174,4 @@ describe('Google3 dynamic queries TSLint rule', () => {
|
||||
expect(content).toContain(`@ContentChild('child') set child(c: any) {}`);
|
||||
expect(content).toContain(`@ViewChild('otherChild') set otherChild(c: any) {}`);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -12,7 +12,6 @@ import * as shx from 'shelljs';
|
||||
import {Configuration, Linter} from 'tslint';
|
||||
|
||||
describe('Google3 explicitQueryTiming TSLint rule', () => {
|
||||
|
||||
/**
|
||||
* Path to the static-query schematic rules directory. The path needs to be resolved through
|
||||
* the Bazel runfiles, because on Windows runfiles are not symlinked into the working directory.
|
||||
@ -23,7 +22,7 @@ describe('Google3 explicitQueryTiming TSLint rule', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
@ -41,7 +40,7 @@ describe('Google3 explicitQueryTiming TSLint rule', () => {
|
||||
const config = Configuration.parseConfigFile({rules: {'explicit-query-timing': true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
|
@ -18,7 +18,7 @@ describe('Google3 missing injectable tslint rule', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
@ -32,7 +32,7 @@ describe('Google3 missing injectable tslint rule', () => {
|
||||
const config = Configuration.parseConfigFile({rules: {'no-missing-injectable': true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
@ -42,7 +42,9 @@ describe('Google3 missing injectable tslint rule', () => {
|
||||
writeFileSync(join(tmpDir, fileName), content);
|
||||
}
|
||||
|
||||
function getFile(fileName: string) { return readFileSync(join(tmpDir, fileName), 'utf8'); }
|
||||
function getFile(fileName: string) {
|
||||
return readFileSync(join(tmpDir, fileName), 'utf8');
|
||||
}
|
||||
|
||||
describe('NgModule', () => createTests('NgModule', 'providers'));
|
||||
describe('Directive', () => createTests('Directive', 'providers'));
|
||||
@ -77,7 +79,7 @@ describe('Google3 missing injectable tslint rule', () => {
|
||||
});
|
||||
|
||||
function createTests(
|
||||
type: 'NgModule' | 'Directive' | 'Component', propName: 'providers' | 'viewProviders') {
|
||||
type: 'NgModule'|'Directive'|'Component', propName: 'providers'|'viewProviders') {
|
||||
it('should create proper failures for missing injectable providers', () => {
|
||||
writeFile('index.ts', `
|
||||
import { ${type} } from '@angular/core';
|
||||
@ -266,6 +268,4 @@ describe('Google3 missing injectable tslint rule', () => {
|
||||
.toMatch(/import { Inject, Injectable } from '@angular\/core';/);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ describe('Google3 noTemplateVariableAssignment TSLint rule', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
@ -34,7 +34,7 @@ describe('Google3 noTemplateVariableAssignment TSLint rule', () => {
|
||||
Configuration.parseConfigFile({rules: {'no-template-variable-assignment': true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
|
@ -18,7 +18,7 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
|
||||
// We need to declare the Angular symbols we're testing for, otherwise type checking won't work.
|
||||
@ -46,7 +46,7 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
|
||||
const config = Configuration.parseConfigFile({rules: {'renderer-to-renderer2': true}});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
@ -56,7 +56,9 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
|
||||
writeFileSync(join(tmpDir, fileName), content);
|
||||
}
|
||||
|
||||
function getFile(fileName: string) { return readFileSync(join(tmpDir, fileName), 'utf8'); }
|
||||
function getFile(fileName: string) {
|
||||
return readFileSync(join(tmpDir, fileName), 'utf8');
|
||||
}
|
||||
|
||||
it('should flag Renderer imports and typed nodes', () => {
|
||||
writeFile('/index.ts', `
|
||||
@ -223,8 +225,8 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
|
||||
runTSLint(true);
|
||||
const content = getFile('index.ts');
|
||||
|
||||
expect(content.match(/function __ngRendererCreateElementHelper\(/g) !.length).toBe(1);
|
||||
expect(content.match(/function __ngRendererSetElementAttributeHelper\(/g) !.length).toBe(1);
|
||||
expect(content.match(/function __ngRendererCreateElementHelper\(/g)!.length).toBe(1);
|
||||
expect(content.match(/function __ngRendererSetElementAttributeHelper\(/g)!.length).toBe(1);
|
||||
});
|
||||
|
||||
it('should insert helpers after the user\'s code', () => {
|
||||
@ -410,5 +412,4 @@ describe('Google3 Renderer to Renderer2 TSLint rule', () => {
|
||||
// Expect the `setInfo` method to only contain whitespace.
|
||||
expect(content).toMatch(/setInfo\(\) \{\s+\}/);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -18,7 +18,7 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
let tmpDir: string;
|
||||
|
||||
beforeEach(() => {
|
||||
tmpDir = join(process.env['TEST_TMPDIR'] !, 'google3-test');
|
||||
tmpDir = join(process.env['TEST_TMPDIR']!, 'google3-test');
|
||||
shx.mkdir('-p', tmpDir);
|
||||
writeFile('tsconfig.json', JSON.stringify({compilerOptions: {module: 'es2015'}}));
|
||||
});
|
||||
@ -33,7 +33,7 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
});
|
||||
|
||||
program.getRootFileNames().forEach(fileName => {
|
||||
linter.lint(fileName, program.getSourceFile(fileName) !.getFullText(), config);
|
||||
linter.lint(fileName, program.getSourceFile(fileName)!.getFullText(), config);
|
||||
});
|
||||
|
||||
return linter;
|
||||
@ -43,7 +43,9 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
writeFileSync(join(tmpDir, fileName), content);
|
||||
}
|
||||
|
||||
function getFile(fileName: string) { return readFileSync(join(tmpDir, fileName), 'utf8'); }
|
||||
function getFile(fileName: string) {
|
||||
return readFileSync(join(tmpDir, fileName), 'utf8');
|
||||
}
|
||||
|
||||
it('should flag undecorated classes with decorated fields', () => {
|
||||
writeFile('/index.ts', `
|
||||
@ -97,8 +99,9 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
expect(getFile('/index.ts')).toContain(`import { Directive, Input } from '@angular/core';`);
|
||||
});
|
||||
|
||||
it('should not generate conflicting imports there is a different `Directive` symbol', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should not generate conflicting imports there is a different `Directive` symbol',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { HostBinding } from '@angular/core';
|
||||
|
||||
export class Directive {
|
||||
@ -111,12 +114,12 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
}
|
||||
`);
|
||||
|
||||
runTSLint(true);
|
||||
const fileContent = getFile('/index.ts');
|
||||
expect(fileContent)
|
||||
.toContain(`import { HostBinding, Directive as Directive_1 } from '@angular/core';`);
|
||||
expect(fileContent).toMatch(/@Directive_1\(\)\s+export class MyLibrarySharedBaseClass/);
|
||||
});
|
||||
runTSLint(true);
|
||||
const fileContent = getFile('/index.ts');
|
||||
expect(fileContent)
|
||||
.toContain(`import { HostBinding, Directive as Directive_1 } from '@angular/core';`);
|
||||
expect(fileContent).toMatch(/@Directive_1\(\)\s+export class MyLibrarySharedBaseClass/);
|
||||
});
|
||||
|
||||
it('should add @Directive to undecorated classes that have @Input', () => {
|
||||
writeFile('/index.ts', `
|
||||
@ -250,7 +253,7 @@ describe('Google3 undecorated classes with decorated fields TSLint rule', () =>
|
||||
expect(getFile('/index.ts')).toContain(`@Directive()\nexport class Base {`);
|
||||
});
|
||||
|
||||
it('should add @Directive to undecorated derived classes of a migrated class', async() => {
|
||||
it('should add @Directive to undecorated derived classes of a migrated class', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Input, Directive, NgModule } from '@angular/core';
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
import {computeLineStartsMap, getLineAndCharacterFromPosition} from '../utils/line_mappings';
|
||||
|
||||
describe('line mappings', () => {
|
||||
|
||||
it('should properly compute line starts',
|
||||
() => {
|
||||
expect(computeLineStartsMap(`
|
||||
|
@ -76,7 +76,7 @@ describe('Missing injectable migration', () => {
|
||||
|
||||
it('should migrate all providers defined in "viewProviders" and "providers" in the ' +
|
||||
'same component',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -102,8 +102,8 @@ describe('Missing injectable migration', () => {
|
||||
});
|
||||
|
||||
function createTests(
|
||||
type: 'NgModule' | 'Directive' | 'Component', propName: 'providers' | 'viewProviders') {
|
||||
it(`should migrate type provider in ${type}`, async() => {
|
||||
type: 'NgModule'|'Directive'|'Component', propName: 'providers'|'viewProviders') {
|
||||
it(`should migrate type provider in ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -121,7 +121,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`{ ${type}, Injectable } from '@angular/core`);
|
||||
});
|
||||
|
||||
it(`should migrate object literal provider in ${type} to explicit value provider`, async() => {
|
||||
it(`should migrate object literal provider in ${type} to explicit value provider`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -140,7 +140,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain(`{${type}} from '@angular/core`);
|
||||
});
|
||||
|
||||
it(`should migrate object literal provider with forwardRef in ${type}`, async() => {
|
||||
it(`should migrate object literal provider with forwardRef in ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}, forwardRef} from '@angular/core';
|
||||
|
||||
@ -158,7 +158,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`{ ${type}, forwardRef, Injectable } from '@angular/core`);
|
||||
});
|
||||
|
||||
it(`should not migrate object literal provider with "useValue" in ${type}`, async() => {
|
||||
it(`should not migrate object literal provider with "useValue" in ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -174,7 +174,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain('@Injectable');
|
||||
});
|
||||
|
||||
it(`should not migrate provider with "useClass" and "deps" in ${type}`, async() => {
|
||||
it(`should not migrate provider with "useClass" and "deps" in ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -190,7 +190,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain('@Injectable');
|
||||
});
|
||||
|
||||
it(`should not migrate object literal provider with "useFactory" in ${type}`, async() => {
|
||||
it(`should not migrate object literal provider with "useFactory" in ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -206,7 +206,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain('@Injectable');
|
||||
});
|
||||
|
||||
it(`should not migrate object literal provider with "useExisting" in ${type}`, async() => {
|
||||
it(`should not migrate object literal provider with "useExisting" in ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -226,7 +226,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain('@Injectable');
|
||||
});
|
||||
|
||||
it(`should migrate object literal provider with "useClass" in ${type}`, async() => {
|
||||
it(`should migrate object literal provider with "useClass" in ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -248,7 +248,7 @@ describe('Missing injectable migration', () => {
|
||||
|
||||
it(`should not migrate references for providers with "useExisting" in ${type}, but migrate ` +
|
||||
`existing token if declared in other ${type}`,
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -281,7 +281,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toMatch(/MyService {}\s+export class MyToken/);
|
||||
});
|
||||
|
||||
it('should not migrate provider which is already decorated with @Injectable', async() => {
|
||||
it('should not migrate provider which is already decorated with @Injectable', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Injectable, ${type}} from '@angular/core';
|
||||
|
||||
@ -299,7 +299,7 @@ describe('Missing injectable migration', () => {
|
||||
.toMatch(/@angular\/core';\s+@Injectable\(\)\s+export class MyService/);
|
||||
});
|
||||
|
||||
it('should not migrate provider which is already decorated with @Directive', async() => {
|
||||
it('should not migrate provider which is already decorated with @Directive', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Directive, ${type}} from '@angular/core';
|
||||
|
||||
@ -316,7 +316,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain('@Injectable');
|
||||
});
|
||||
|
||||
it('should not migrate provider which is already decorated with @Component', async() => {
|
||||
it('should not migrate provider which is already decorated with @Component', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${type}} from '@angular/core';
|
||||
|
||||
@ -333,7 +333,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain('@Injectable');
|
||||
});
|
||||
|
||||
it('should not migrate provider which is already decorated with @Pipe', async() => {
|
||||
it('should not migrate provider which is already decorated with @Pipe', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Pipe, ${type}} from '@angular/core';
|
||||
|
||||
@ -350,7 +350,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain('@Injectable');
|
||||
});
|
||||
|
||||
it(`should migrate multiple providers in same ${type}`, async() => {
|
||||
it(`should migrate multiple providers in same ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -370,7 +370,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`{ ${type}, Injectable } from '@angular/core`);
|
||||
});
|
||||
|
||||
it(`should migrate multiple mixed providers in same ${type}`, async() => {
|
||||
it(`should migrate multiple mixed providers in same ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -399,7 +399,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`{ provide: ServiceB, useValue: undefined },`);
|
||||
});
|
||||
|
||||
it(`should migrate multiple nested providers in same ${type}`, async() => {
|
||||
it(`should migrate multiple nested providers in same ${type}`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -433,7 +433,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`{ provide: ServiceD, useValue: undefined },`);
|
||||
});
|
||||
|
||||
it('should migrate providers referenced through identifier', async() => {
|
||||
it('should migrate providers referenced through identifier', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -467,7 +467,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`{ provide: ServiceC, useValue: undefined },`);
|
||||
});
|
||||
|
||||
it('should migrate providers created through static analyzable function call', async() => {
|
||||
it('should migrate providers created through static analyzable function call', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -497,7 +497,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`ServiceB, { provide: ServiceC, useValue: undefined }),`);
|
||||
});
|
||||
|
||||
it('should migrate providers which are computed through spread operator', async() => {
|
||||
it('should migrate providers which are computed through spread operator', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -525,7 +525,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`ServiceB, { provide: ServiceC, useValue: undefined }];`);
|
||||
});
|
||||
|
||||
it(`should migrate provider once if referenced in multiple ${type} definitions`, async() => {
|
||||
it(`should migrate provider once if referenced in multiple ${type} definitions`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -559,7 +559,7 @@ describe('Missing injectable migration', () => {
|
||||
|
||||
it(`should only migrate empty object provider literal once if referenced multiple times ` +
|
||||
`in ${type} definitions`,
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/provider.ts', `
|
||||
export class MyService {}
|
||||
|
||||
@ -592,7 +592,7 @@ describe('Missing injectable migration', () => {
|
||||
.toContain(`const PROVIDER = { provide: MyService, useValue: undefined };`);
|
||||
});
|
||||
|
||||
it('should create new import for @Injectable when migrating provider', async() => {
|
||||
it('should create new import for @Injectable when migrating provider', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
import {MyService, MySecondService} from './service';
|
||||
@ -617,7 +617,7 @@ describe('Missing injectable migration', () => {
|
||||
});
|
||||
|
||||
it('should re-use existing namespace import for importing @Injectable when migrating provider',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import * as core from '@angular/core';
|
||||
|
||||
@ -643,7 +643,7 @@ describe('Missing injectable migration', () => {
|
||||
.toMatch(/@core.Injectable\(\)\s+export class MyService/);
|
||||
});
|
||||
|
||||
it('should warn if a referenced individual provider could not be resolved', async() => {
|
||||
it('should warn if a referenced individual provider could not be resolved', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -659,7 +659,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(warnOutput[0]).toContain(`4:${providerSourceTextColumn}:`);
|
||||
});
|
||||
|
||||
it(`should warn if ${propName} value could not be resolved`, async() => {
|
||||
it(`should warn if ${propName} value could not be resolved`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -675,7 +675,7 @@ describe('Missing injectable migration', () => {
|
||||
expect(warnOutput[0]).toContain(`4:${propValueSourceTextColumn}:`);
|
||||
});
|
||||
|
||||
it(`should not throw if an empty @${type} is analyzed`, async() => {
|
||||
it(`should not throw if an empty @${type} is analyzed`, async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
|
||||
@ -693,7 +693,7 @@ describe('Missing injectable migration', () => {
|
||||
});
|
||||
|
||||
it('should create new import for injectable after full end of last import statement',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
import {MyService} from './service';
|
||||
@ -718,7 +718,7 @@ describe('Missing injectable migration', () => {
|
||||
.toMatch(/'b'; \/\/ some comment\s+import { Injectable } from "@angular\/core";/);
|
||||
});
|
||||
|
||||
it('should create new import at source file start with trailing new-line', async() => {
|
||||
it('should create new import at source file start with trailing new-line', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
import {MyService} from './service';
|
||||
@ -739,7 +739,7 @@ describe('Missing injectable migration', () => {
|
||||
/^import { Injectable } from "@angular\/core";\s+\/\* @license \*\/\s+@Injectable\(\)\s+export class MyService/);
|
||||
});
|
||||
|
||||
it('should remove @Inject decorator for providers which are migrated', async() => {
|
||||
it('should remove @Inject decorator for providers which are migrated', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {${type}} from '@angular/core';
|
||||
import {MyService} from './service';
|
||||
@ -766,7 +766,7 @@ describe('Missing injectable migration', () => {
|
||||
.toMatch(/import { Inject, Injectable } from '@angular\/core';/);
|
||||
});
|
||||
|
||||
it('should not migrate provider classes in library type definitions', async() => {
|
||||
it('should not migrate provider classes in library type definitions', async () => {
|
||||
writeFile('/node_modules/my-lib/index.d.ts', `
|
||||
export declare class MyService {}
|
||||
`);
|
||||
|
@ -46,7 +46,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
shx.rm('-r', tmpDirPath);
|
||||
});
|
||||
|
||||
it('should add generic type for function return', async() => {
|
||||
it('should add generic type for function return', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {NgModule, ModuleWithProviders} from '@angular/core';
|
||||
|
||||
@ -69,7 +69,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain(`ModuleWithProviders<BaseModule>`);
|
||||
});
|
||||
|
||||
it('should add generic type for function return; external file', async() => {
|
||||
it('should add generic type for function return; external file', async () => {
|
||||
writeFile('/module.ts', `
|
||||
import {NgModule} from '@angular/core';
|
||||
|
||||
@ -96,7 +96,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain(`ModuleWithProviders<BaseModule>`);
|
||||
});
|
||||
|
||||
it('should add generic type for function return without explicit type', async() => {
|
||||
it('should add generic type for function return without explicit type', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {NgModule} from '@angular/core';
|
||||
|
||||
@ -119,7 +119,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain(`ModuleWithProviders<BaseModule>`);
|
||||
});
|
||||
|
||||
it('should add generic type for const variable', async() => {
|
||||
it('should add generic type for const variable', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {ModuleWithProviders, NgModule} from '@angular/core';
|
||||
|
||||
@ -140,7 +140,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain(`ModuleWithProviders<BaseModule>`);
|
||||
});
|
||||
|
||||
it('should add generic type for const variable without explicit type', async() => {
|
||||
it('should add generic type for const variable without explicit type', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {NgModule} from '@angular/core';
|
||||
|
||||
@ -161,7 +161,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain(`ModuleWithProviders<BaseModule>`);
|
||||
});
|
||||
|
||||
it('should not add generic type for const variable with invalid base object', async() => {
|
||||
it('should not add generic type for const variable with invalid base object', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {NgModule} from '@angular/core';
|
||||
|
||||
@ -182,7 +182,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain(`ModuleWithProviders<BaseModule>`);
|
||||
});
|
||||
|
||||
it('should add generic type for const variables and functions with incomplete type', async() => {
|
||||
it('should add generic type for const variables and functions with incomplete type', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {ModuleWithProviders, NgModule} from '@angular/core';
|
||||
|
||||
@ -214,7 +214,7 @@ describe('ModuleWithProviders migration', () => {
|
||||
expect(tree.readContent('/index.ts')).not.toContain(`ModuleWithProviders `);
|
||||
});
|
||||
|
||||
it('should not add generic type for const variables without initialization', async() => {
|
||||
it('should not add generic type for const variables without initialization', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {ModuleWithProviders} from '@angular/core';
|
||||
|
||||
|
@ -47,7 +47,7 @@ describe('move-document migration', () => {
|
||||
});
|
||||
|
||||
describe('move-document', () => {
|
||||
it('should properly apply import replacement', async() => {
|
||||
it('should properly apply import replacement', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {DOCUMENT} from '@angular/platform-browser';
|
||||
`);
|
||||
@ -73,7 +73,7 @@ describe('move-document migration', () => {
|
||||
expect(content).not.toContain(`import {DOCUMENT} from '@angular/platform-browser';`);
|
||||
});
|
||||
|
||||
it('should properly apply import replacement with existing import', async() => {
|
||||
it('should properly apply import replacement with existing import', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {DOCUMENT} from '@angular/platform-browser';
|
||||
import {someImport} from '@angular/common';
|
||||
@ -96,7 +96,7 @@ describe('move-document migration', () => {
|
||||
expect(contentReverse).not.toContain(`import {DOCUMENT} from '@angular/platform-browser';`);
|
||||
});
|
||||
|
||||
it('should properly apply import replacement with existing import w/ comments', async() => {
|
||||
it('should properly apply import replacement with existing import w/ comments', async () => {
|
||||
writeFile('/index.ts', `
|
||||
/**
|
||||
* this is a comment
|
||||
@ -115,7 +115,7 @@ describe('move-document migration', () => {
|
||||
expect(content).toMatch(/.*this is a comment.*/);
|
||||
});
|
||||
|
||||
it('should properly apply import replacement with existing and redundant imports', async() => {
|
||||
it('should properly apply import replacement with existing and redundant imports', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {DOCUMENT} from '@angular/platform-browser';
|
||||
import {anotherImport} from '@angular/platform-browser-dynamic';
|
||||
@ -131,7 +131,7 @@ describe('move-document migration', () => {
|
||||
});
|
||||
|
||||
it('should properly apply import replacement with existing import and leave original import',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {DOCUMENT, anotherImport} from '@angular/platform-browser';
|
||||
import {someImport} from '@angular/common';
|
||||
@ -145,7 +145,7 @@ describe('move-document migration', () => {
|
||||
expect(content).toContain(`import { anotherImport } from '@angular/platform-browser';`);
|
||||
});
|
||||
|
||||
it('should properly apply import replacement with existing import and alias', async() => {
|
||||
it('should properly apply import replacement with existing import and alias', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {DOCUMENT as doc, anotherImport} from '@angular/platform-browser';
|
||||
import {someImport} from '@angular/common';
|
||||
|
@ -13,13 +13,14 @@ import {getProjectTsConfigPaths} from '../utils/project_tsconfig_paths';
|
||||
describe('project tsconfig paths', () => {
|
||||
let testTree: UnitTestTree;
|
||||
|
||||
beforeEach(() => { testTree = new UnitTestTree(new HostTree()); });
|
||||
beforeEach(() => {
|
||||
testTree = new UnitTestTree(new HostTree());
|
||||
});
|
||||
|
||||
it('should detect build tsconfig path inside of angular.json file', () => {
|
||||
testTree.create('/my-custom-config.json', '');
|
||||
testTree.create('/angular.json', JSON.stringify({
|
||||
projects:
|
||||
{my_name: {architect: {build: {options: {tsConfig: './my-custom-config.json'}}}}}
|
||||
projects: {my_name: {architect: {build: {options: {tsConfig: './my-custom-config.json'}}}}}
|
||||
}));
|
||||
|
||||
expect(getProjectTsConfigPaths(testTree).buildPaths).toEqual(['my-custom-config.json']);
|
||||
@ -57,8 +58,7 @@ describe('project tsconfig paths', () => {
|
||||
it('should detect test tsconfig path inside of .angular.json file', () => {
|
||||
testTree.create('/my-test-config.json', '');
|
||||
testTree.create('/.angular.json', JSON.stringify({
|
||||
projects:
|
||||
{with_tests: {architect: {test: {options: {tsConfig: './my-test-config.json'}}}}}
|
||||
projects: {with_tests: {architect: {test: {options: {tsConfig: './my-test-config.json'}}}}}
|
||||
}));
|
||||
|
||||
expect(getProjectTsConfigPaths(testTree).testPaths).toEqual(['my-test-config.json']);
|
||||
|
@ -52,7 +52,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('import renaming', () => {
|
||||
it('should change Renderer imports to Renderer2', async() => {
|
||||
it('should change Renderer imports to Renderer2', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component } from '@angular/core';
|
||||
|
||||
@ -67,7 +67,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain(`import { Component, Renderer2 } from '@angular/core';`);
|
||||
});
|
||||
|
||||
it('should change aliased Renderer imports to Renderer2', async() => {
|
||||
it('should change aliased Renderer imports to Renderer2', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer as RenamedRenderer, Component } from '@angular/core';
|
||||
|
||||
@ -82,7 +82,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain(`import { Component, Renderer2 as RenamedRenderer } from '@angular/core';`);
|
||||
});
|
||||
|
||||
it('should not change Renderer imports if they are not from @angular/core', async() => {
|
||||
it('should not change Renderer imports if they are not from @angular/core', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Component } from '@angular/core';
|
||||
import { Renderer } from './my-renderer';
|
||||
@ -102,7 +102,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('type renaming', () => {
|
||||
it('should change type of constructor parameter from Renderer to Renderer2', async() => {
|
||||
it('should change type of constructor parameter from Renderer to Renderer2', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -117,7 +117,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain('constructor(element: ElementRef, renderer: Renderer2)');
|
||||
});
|
||||
|
||||
it('should change type of method parameter from Renderer to Renderer2', async() => {
|
||||
it('should change type of method parameter from Renderer to Renderer2', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -134,7 +134,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain('disable(renderer: Renderer2, element: HTMLElement, isDisabled: boolean)');
|
||||
});
|
||||
|
||||
it('should change type of property declarations', async() => {
|
||||
it('should change type of property declarations', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component } from '@angular/core';
|
||||
|
||||
@ -148,7 +148,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain('public renderer: Renderer2;');
|
||||
});
|
||||
|
||||
it('should change type of properties initialized via the constructor', async() => {
|
||||
it('should change type of properties initialized via the constructor', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -163,7 +163,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain('constructor(element: ElementRef, private _renderer: Renderer2)');
|
||||
});
|
||||
|
||||
it('should change the type of something that was cast to Renderer', async() => {
|
||||
it('should change the type of something that was cast to Renderer', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -184,7 +184,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
expect(content).toContain(`renderer.setStyle(element.nativeElement, 'color', 'red');`);
|
||||
});
|
||||
|
||||
it('should not rename types called Renderer that do not come from Angular', async() => {
|
||||
it('should not rename types called Renderer that do not come from Angular', async () => {
|
||||
// Write a dummy renderer file so type checking picks it up.
|
||||
writeFile('/my-renderer.ts', `export abstract class Renderer {}`);
|
||||
|
||||
@ -203,7 +203,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain('constructor(element: ElementRef, renderer: Renderer)');
|
||||
});
|
||||
|
||||
it('should rename inside single-line forwardRef', async() => {
|
||||
it('should rename inside single-line forwardRef', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef, forwardRef, Inject } from '@angular/core';
|
||||
|
||||
@ -221,7 +221,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
`constructor(@Inject(forwardRef(() => Renderer2)) private _renderer: Renderer2)`);
|
||||
});
|
||||
|
||||
it('should rename inside multi-line forwardRef', async() => {
|
||||
it('should rename inside multi-line forwardRef', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef, forwardRef, Inject } from '@angular/core';
|
||||
|
||||
@ -238,11 +238,10 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
expect(content).toContain(
|
||||
`constructor(@Inject(forwardRef(() => { return Renderer2; })) private _renderer: Renderer2) {}`);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('helper insertion', () => {
|
||||
it('should only declare each helper once per file', async() => {
|
||||
it('should only declare each helper once per file', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -260,11 +259,11 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
|
||||
const content = tree.readContent('/index.ts');
|
||||
|
||||
expect(content.match(/function __ngRendererCreateElementHelper\(/g) !.length)
|
||||
expect(content.match(/function __ngRendererCreateElementHelper\(/g)!.length)
|
||||
.toBe(1, 'Expected exactly one helper for createElement.');
|
||||
});
|
||||
|
||||
it('should insert helpers after the user\'s code', async() => {
|
||||
it('should insert helpers after the user\'s code', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -287,7 +286,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
expect(contentAfterSeparator).toContain('function __ngRendererCreateElementHelper(');
|
||||
});
|
||||
|
||||
it('should be able to handle multiple helpers per file', async() => {
|
||||
it('should be able to handle multiple helpers per file', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -314,15 +313,15 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
|
||||
const content = tree.readContent('/index.ts');
|
||||
|
||||
expect(content.match(/function __ngRendererCreateTextHelper\(/g) !.length)
|
||||
expect(content.match(/function __ngRendererCreateTextHelper\(/g)!.length)
|
||||
.toBe(1, 'Expected exactly one helper for createElement.');
|
||||
expect(content.match(/function __ngRendererCreateElementHelper\(/g) !.length)
|
||||
expect(content.match(/function __ngRendererCreateElementHelper\(/g)!.length)
|
||||
.toBe(1, 'Expected exactly one helper for createText.');
|
||||
expect(content.match(/function __ngRendererCreateTemplateAnchorHelper\(/g) !.length)
|
||||
expect(content.match(/function __ngRendererCreateTemplateAnchorHelper\(/g)!.length)
|
||||
.toBe(1, 'Expected exactly one helper for createTemplateAnchor.');
|
||||
});
|
||||
|
||||
it('should create the __ngRendererSplitNamespaceHelper', async() => {
|
||||
it('should create the __ngRendererSplitNamespaceHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -347,7 +346,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
`));
|
||||
});
|
||||
|
||||
it('should declare our custom any type', async() => {
|
||||
it('should declare our custom any type', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -365,11 +364,10 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
type AnyDuringRendererMigration = any;
|
||||
`));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('setElementProperty migration', () => {
|
||||
it('should migrate setElementProperty calls', async() => {
|
||||
it('should migrate setElementProperty calls', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -390,7 +388,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('setText migration', () => {
|
||||
it('should migrate setText calls', async() => {
|
||||
it('should migrate setText calls', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -412,7 +410,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('listenGlobal migration', () => {
|
||||
it('should migrate listenGlobal calls', async() => {
|
||||
it('should migrate listenGlobal calls', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component } from '@angular/core';
|
||||
|
||||
@ -433,7 +431,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('selectRootElement migration', () => {
|
||||
it('should migrate selectRootElement calls', async() => {
|
||||
it('should migrate selectRootElement calls', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -454,7 +452,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('setElementClass migration', () => {
|
||||
it('should migrate calls with inline isAdd value', async() => {
|
||||
it('should migrate calls with inline isAdd value', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -479,7 +477,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain(`this._renderer.removeClass(this._element.nativeElement, className);`);
|
||||
});
|
||||
|
||||
it('should migrate calls with variable isAdd value', async() => {
|
||||
it('should migrate calls with variable isAdd value', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -503,7 +501,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('setElementStyle migration', () => {
|
||||
it('should migrate calls with two arguments to a removeStyle call', async() => {
|
||||
it('should migrate calls with two arguments to a removeStyle call', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -522,7 +520,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain(`this._renderer.removeStyle(this._element.nativeElement, 'color');`);
|
||||
});
|
||||
|
||||
it('should migrate calls with static third arguments to a setStyle call', async() => {
|
||||
it('should migrate calls with static third arguments to a setStyle call', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -552,7 +550,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
it('should migrate calls with null or undefined value for last argument to a removeStyle call',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -575,7 +573,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
`this._renderer.removeStyle(this._element.nativeElement, 'background-color');`);
|
||||
});
|
||||
|
||||
it('should migrate calls with a variable third argument', async() => {
|
||||
it('should migrate calls with a variable third argument', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -597,7 +595,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
it('should migrate calls with a variable third argument whose value can be inferred',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -625,7 +623,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('setElementAttribute migration', () => {
|
||||
it('should migrate to calls to the __ngRendererSetElementAttributeHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererSetElementAttributeHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -651,7 +649,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
'__ngRendererSetElementAttributeHelper(this._renderer, this._element.nativeElement, name);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererSetElementAttributeHelper', async() => {
|
||||
it('should declare the __ngRendererSetElementAttributeHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -680,12 +678,11 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
|
||||
expect(content).toContain(stripWhitespace('function __ngRendererSplitNamespaceHelper('));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('invokeElementMethod migration', () => {
|
||||
it('should migrate calls to a direct method call if the method name and arguments are static',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -710,7 +707,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
it('should migrate calls to a property access if the method name or arguments are dynamic',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -738,7 +735,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
`(this._element.nativeElement as any)['otherMethod'].apply(this._element.nativeElement, args);`);
|
||||
});
|
||||
|
||||
it('should handle calls without an `args` array', async() => {
|
||||
it('should handle calls without an `args` array', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -761,7 +758,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('setBindingDebugInfo migration', () => {
|
||||
it('should drop calls to setBindingDebugInfo', async() => {
|
||||
it('should drop calls to setBindingDebugInfo', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -783,7 +780,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('createViewRoot migration', () => {
|
||||
it('should replace createViewRoot calls with a reference to the first argument', async() => {
|
||||
it('should replace createViewRoot calls with a reference to the first argument', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -806,7 +803,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('createElement migration', () => {
|
||||
it('should migrate to calls to the __ngRendererCreateElementHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererCreateElementHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -833,7 +830,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
'return __ngRendererCreateElementHelper(this._renderer, this._element.nativeElement, nodeName);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererCreateElementHelper', async() => {
|
||||
it('should declare the __ngRendererCreateElementHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -862,11 +859,10 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
|
||||
expect(content).toContain(stripWhitespace('function __ngRendererSplitNamespaceHelper('));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('createText migration', () => {
|
||||
it('should migrate to calls to the __ngRendererCreateTextHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererCreateTextHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -893,7 +889,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
'return __ngRendererCreateTextHelper(this._renderer, this._element.nativeElement, value);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererCreateTextHelper', async() => {
|
||||
it('should declare the __ngRendererCreateTextHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -917,11 +913,10 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
}
|
||||
`));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('createTemplateAnchor migration', () => {
|
||||
it('should migrate to calls to the __ngRendererCreateTemplateAnchorHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererCreateTemplateAnchorHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -947,7 +942,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
'return __ngRendererCreateTemplateAnchorHelper(this._renderer, this._element.nativeElement);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererCreateTemplateAnchorHelper', async() => {
|
||||
it('should declare the __ngRendererCreateTemplateAnchorHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -971,11 +966,10 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
}
|
||||
`));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('projectNodes migration', () => {
|
||||
it('should migrate to calls to the __ngRendererProjectNodesHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererProjectNodesHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -997,7 +991,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
'__ngRendererProjectNodesHelper(this._renderer, this._element.nativeElement, nodesToProject);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererProjectNodesHelper', async() => {
|
||||
it('should declare the __ngRendererProjectNodesHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -1019,11 +1013,10 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
}
|
||||
`));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('animate migration', () => {
|
||||
it('should migrate to calls to the __ngRendererAnimateHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererAnimateHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -1043,7 +1036,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toContain('__ngRendererAnimateHelper();');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererAnimateHelper', async() => {
|
||||
it('should declare the __ngRendererAnimateHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -1063,11 +1056,10 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
}
|
||||
`));
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('destroyView migration', () => {
|
||||
it('should migrate to calls to the __ngRendererDestroyViewHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererDestroyViewHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -1088,7 +1080,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain('__ngRendererDestroyViewHelper(this._renderer, allNodes);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererDestroyViewHelper', async() => {
|
||||
it('should declare the __ngRendererDestroyViewHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -1116,7 +1108,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('detachView migration', () => {
|
||||
it('should migrate to calls to the __ngRendererDetachViewHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererDetachViewHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component } from '@angular/core';
|
||||
|
||||
@ -1137,7 +1129,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
.toContain('__ngRendererDetachViewHelper(this._renderer, rootNodes);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererDetachViewHelper', async() => {
|
||||
it('should declare the __ngRendererDetachViewHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component } from '@angular/core';
|
||||
|
||||
@ -1166,7 +1158,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
});
|
||||
|
||||
describe('attachViewAfter migration', () => {
|
||||
it('should migrate to calls to the __ngRendererAttachViewAfterHelper', async() => {
|
||||
it('should migrate to calls to the __ngRendererAttachViewAfterHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component, ElementRef } from '@angular/core';
|
||||
|
||||
@ -1188,7 +1180,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
'__ngRendererAttachViewAfterHelper(this._renderer, this._element.nativeElement, rootNodes);');
|
||||
});
|
||||
|
||||
it('should declare the __ngRendererAttachViewAfterHelper', async() => {
|
||||
it('should declare the __ngRendererAttachViewAfterHelper', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import { Renderer, Component } from '@angular/core';
|
||||
|
||||
@ -1225,5 +1217,7 @@ describe('Renderer to Renderer2 migration', () => {
|
||||
return runner.runSchematicAsync('migration-v9-renderer-to-renderer2', {}, tree).toPromise();
|
||||
}
|
||||
|
||||
function stripWhitespace(contents: string) { return contents.replace(/\s/g, ''); }
|
||||
function stripWhitespace(contents: string) {
|
||||
return contents.replace(/\s/g, '');
|
||||
}
|
||||
});
|
||||
|
@ -61,7 +61,9 @@ describe('static-queries migration with template strategy', () => {
|
||||
shx.rm('-r', tmpDirPath);
|
||||
});
|
||||
|
||||
function writeFakeAngular() { writeFile('/node_modules/@angular/core/index.d.ts', ``); }
|
||||
function writeFakeAngular() {
|
||||
writeFile('/node_modules/@angular/core/index.d.ts', ``);
|
||||
}
|
||||
|
||||
function writeFakeLibrary(selectorName = 'my-lib-selector') {
|
||||
writeFile('/node_modules/my-lib/index.d.ts', `export * from './public-api';`);
|
||||
@ -105,8 +107,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
}
|
||||
|
||||
describe('ViewChild', () => {
|
||||
|
||||
it('should detect queries selecting elements through template reference', async() => {
|
||||
it('should detect queries selecting elements through template reference', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -135,7 +136,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('myStaticButton', { static: true }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries selecting ng-template as static', async() => {
|
||||
it('should detect queries selecting ng-template as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -158,7 +159,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('myTmpl', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries selecting ng-template as static (BOM)', async() => {
|
||||
it('should detect queries selecting ng-template as static (BOM)', async () => {
|
||||
writeFile('/index.ts', `\uFEFF
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -181,8 +182,9 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('myTmpl', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries selecting component view providers through string token', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should detect queries selecting component view providers through string token',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, Directive, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
@ -211,22 +213,22 @@ describe('static-queries migration with template strategy', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile(`/my-tmpl.html`, `
|
||||
writeFile(`/my-tmpl.html`, `
|
||||
<span myDirective></span>
|
||||
<ng-template>
|
||||
<span myDirective2></span>
|
||||
</ng-template>
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@ViewChild('my-token', { static: true }) query: any;`);
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@ViewChild('my-token-2', { static: false }) query2: any;`);
|
||||
});
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@ViewChild('my-token', { static: true }) query: any;`);
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@ViewChild('my-token-2', { static: false }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries selecting component view providers using class token', async() => {
|
||||
it('should detect queries selecting component view providers using class token', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, Directive, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -270,7 +272,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild(MyService2, { static: false }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries selecting component', async() => {
|
||||
it('should detect queries selecting component', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
import {HomeComponent, HomeComponent2} from './home-comp';
|
||||
@ -316,7 +318,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild(HomeComponent2, { static: false }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries selecting third-party component', async() => {
|
||||
it('should detect queries selecting third-party component', async () => {
|
||||
writeFakeLibrary();
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
@ -341,9 +343,10 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild(MyLibComponent, { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries selecting third-party component with multiple selectors', async() => {
|
||||
writeFakeLibrary('a-selector, test-selector');
|
||||
writeFile('/index.ts', `
|
||||
it('should detect queries selecting third-party component with multiple selectors',
|
||||
async () => {
|
||||
writeFakeLibrary('a-selector, test-selector');
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
import {MyLibComponent} from 'my-lib';
|
||||
|
||||
@ -356,20 +359,20 @@ describe('static-queries migration with template strategy', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/my-tmpl.html', `
|
||||
writeFile('/my-tmpl.html', `
|
||||
<a-selector>Match 1</a-selector>
|
||||
<ng-template>
|
||||
<test-selector>Match 2</test-selector>
|
||||
</ng-template>
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@ViewChild(MyLibComponent, { static: false }) query: any;`);
|
||||
});
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@ViewChild(MyLibComponent, { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries within structural directive', async() => {
|
||||
it('should detect queries within structural directive', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, Directive, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -399,7 +402,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('myRef2', { static: false }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should detect inherited queries', async() => {
|
||||
it('should detect inherited queries', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -424,7 +427,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('myRef', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries declared on setter', async() => {
|
||||
it('should detect queries declared on setter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -448,7 +451,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toMatch(/@ViewChild\('myRef', { static: true }\)\s+set query/);
|
||||
});
|
||||
|
||||
it('should detect queries declared on getter', async() => {
|
||||
it('should detect queries declared on getter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -473,7 +476,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toMatch(/@ViewChild\('myRef', { static: true }\)\s+get query/);
|
||||
});
|
||||
|
||||
it('should add a todo if a query is not declared in any component', async() => {
|
||||
it('should add a todo if a query is not declared in any component', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild, SomeToken} from '@angular/core';
|
||||
|
||||
@ -493,7 +496,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
/^⮑ {3}index.ts@5:11:.+could not be determined.+not declared in any component/);
|
||||
});
|
||||
|
||||
it('should add a todo if a query is used multiple times with different timing', async() => {
|
||||
it('should add a todo if a query is used multiple times with different timing', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -523,7 +526,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
|
||||
it('should be able to migrate an application with type checking failure which ' +
|
||||
'does not affect analysis',
|
||||
async() => {
|
||||
async () => {
|
||||
// Fakes the `@angular/package` by creating a `ViewChild` decorator
|
||||
// function that requires developers to specify the "static" flag.
|
||||
writeFile('/node_modules/@angular/core/index.d.ts', `
|
||||
@ -565,7 +568,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
|
||||
it('should be able to migrate applications with template type checking failure ' +
|
||||
'which does not affect analysis',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {NgModule, Component, ViewChild} from '@angular/core';
|
||||
|
||||
@ -596,7 +599,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('myRef', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should notify user if project has syntax errors which can affect analysis', async() => {
|
||||
it('should notify user if project has syntax errors which can affect analysis', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ViewChild} from '@angular/core';
|
||||
|
||||
@ -630,7 +633,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('myRef', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should gracefully exit migration if queries could not be analyzed', async() => {
|
||||
it('should gracefully exit migration if queries could not be analyzed', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ViewChild} from '@angular/core';
|
||||
|
||||
@ -650,7 +653,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
expect(errorOutput[0]).toMatch(/Cannot determine the module for class MyComp/);
|
||||
});
|
||||
|
||||
it('should gracefully exit migration if AOT compiler throws exception', async() => {
|
||||
it('should gracefully exit migration if AOT compiler throws exception', async () => {
|
||||
writeFile('/my-component.ts', `
|
||||
import {Component, ViewChild} from '@angular/core';
|
||||
|
||||
@ -691,7 +694,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
expect(errorOutput[0]).toMatch(/^TypeError: Cannot read property 'module' of undefined/);
|
||||
});
|
||||
|
||||
it('should add a todo for content queries which are not detectable', async() => {
|
||||
it('should add a todo for content queries which are not detectable', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ContentChild} from '@angular/core';
|
||||
|
||||
@ -713,7 +716,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toMatch(/^⮑ {3}index.ts@6:11: Content queries cannot be migrated automatically\./);
|
||||
});
|
||||
|
||||
it('should add a todo if query options cannot be migrated inline', async() => {
|
||||
it('should add a todo if query options cannot be migrated inline', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, ViewChild} from '@angular/core';
|
||||
|
||||
@ -738,7 +741,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
expect(warnOutput[0]).toMatch(/Please manually set the query timing to.*static: true/);
|
||||
});
|
||||
|
||||
it('should not normalize stylesheets which are referenced in component', async() => {
|
||||
it('should not normalize stylesheets which are referenced in component', async () => {
|
||||
writeFile('sub_dir/index.ts', `
|
||||
import {Component, NgModule, ContentChild} from '@angular/core';
|
||||
|
||||
@ -765,7 +768,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
expect(console.error).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('should always use the test migration strategy for test tsconfig files', async() => {
|
||||
it('should always use the test migration strategy for test tsconfig files', async () => {
|
||||
writeFile('/src/tsconfig.spec.json', JSON.stringify({
|
||||
compilerOptions: {
|
||||
experimentalDecorators: true,
|
||||
@ -812,7 +815,7 @@ describe('static-queries migration with template strategy', () => {
|
||||
.toContain(`@ViewChild('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not fall back to test strategy if selected strategy fails', async() => {
|
||||
it('should not fall back to test strategy if selected strategy fails', async () => {
|
||||
writeFile('/src/tsconfig.spec.json', JSON.stringify({
|
||||
compilerOptions: {
|
||||
experimentalDecorators: true,
|
||||
|
@ -63,7 +63,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
describe('ViewChild', () => {
|
||||
createQueryTests('ViewChild');
|
||||
|
||||
it('should mark view queries used in "ngAfterContentInit" as static', async() => {
|
||||
it('should mark view queries used in "ngAfterContentInit" as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ViewChild} from '@angular/core';
|
||||
|
||||
@ -83,7 +83,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@ViewChild('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should mark view queries used in "ngAfterContentChecked" as static', async() => {
|
||||
it('should mark view queries used in "ngAfterContentChecked" as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ViewChild} from '@angular/core';
|
||||
|
||||
@ -107,7 +107,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
describe('ContentChild', () => {
|
||||
createQueryTests('ContentChild');
|
||||
|
||||
it('should not mark content queries used in "ngAfterContentInit" as static', async() => {
|
||||
it('should not mark content queries used in "ngAfterContentInit" as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ContentChild} from '@angular/core';
|
||||
|
||||
@ -127,7 +127,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@ContentChild('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark content queries used in "ngAfterContentInit" as static (BOM)', async() => {
|
||||
it('should not mark content queries used in "ngAfterContentInit" as static (BOM)', async () => {
|
||||
writeFile('/index.ts', `\uFEFF
|
||||
import {Component, ContentChild} from '@angular/core';
|
||||
|
||||
@ -147,7 +147,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@ContentChild('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark content queries used in "ngAfterContentChecked" as static', async() => {
|
||||
it('should not mark content queries used in "ngAfterContentChecked" as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ContentChild} from '@angular/core';
|
||||
|
||||
@ -176,8 +176,8 @@ describe('static-queries migration with usage strategy', () => {
|
||||
return runner.runSchematicAsync('migration-v8-static-queries', {}, tree).toPromise();
|
||||
}
|
||||
|
||||
function createQueryTests(queryType: 'ViewChild' | 'ContentChild') {
|
||||
it('should mark queries as dynamic', async() => {
|
||||
function createQueryTests(queryType: 'ViewChild'|'ContentChild') {
|
||||
it('should mark queries as dynamic', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -200,7 +200,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('dynamic', { static: false }) dynamic: any`);
|
||||
});
|
||||
|
||||
it('should mark queries used in "ngOnChanges" as static', async() => {
|
||||
it('should mark queries used in "ngOnChanges" as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -220,7 +220,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should mark queries used in "ngOnInit" as static', async() => {
|
||||
it('should mark queries used in "ngOnInit" as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -240,7 +240,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should mark queries used in "ngDoCheck" as static', async() => {
|
||||
it('should mark queries used in "ngDoCheck" as static', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -260,7 +260,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should keep existing query options when updating timing', async() => {
|
||||
it('should keep existing query options when updating timing', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -280,7 +280,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { /* test */ read: null, static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should add a todo for queries declared on setter', async() => {
|
||||
it('should add a todo for queries declared on setter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -300,7 +300,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toMatch(/index.ts@6:11: Queries defined on accessors cannot be analyzed.$/);
|
||||
});
|
||||
|
||||
it('should add a todo for queries declared on getter', async() => {
|
||||
it('should add a todo for queries declared on getter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -321,7 +321,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toMatch(/index.ts@6:11: Queries defined on accessors cannot be analyzed.$/);
|
||||
});
|
||||
|
||||
it('should not overwrite existing explicit query timing', async() => {
|
||||
it('should not overwrite existing explicit query timing', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -337,7 +337,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', {static: /* untouched */ someVal}) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries used in deep method chain', async() => {
|
||||
it('should detect queries used in deep method chain', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -372,7 +372,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should properly exit if recursive function is analyzed', async() => {
|
||||
it('should properly exit if recursive function is analyzed', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -396,7 +396,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries used in newly instantiated classes', async() => {
|
||||
it('should detect queries used in newly instantiated classes', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -435,7 +435,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries used in parenthesized new expressions', async() => {
|
||||
it('should detect queries used in parenthesized new expressions', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -461,7 +461,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries in lifecycle hook with string literal name', async() => {
|
||||
it('should detect queries in lifecycle hook with string literal name', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -481,7 +481,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect static queries within nested inheritance', async() => {
|
||||
it('should detect static queries within nested inheritance', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -506,7 +506,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect static queries used within input setters', async() => {
|
||||
it('should detect static queries used within input setters', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, Input, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -528,7 +528,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect inputs defined in metadata', async() => {
|
||||
it('should detect inputs defined in metadata', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -554,7 +554,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect aliased inputs declared in metadata', async() => {
|
||||
it('should detect aliased inputs declared in metadata', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -577,7 +577,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark query as static if query is used in non-input setter', async() => {
|
||||
it('should not mark query as static if query is used in non-input setter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -597,7 +597,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect input decorator on setter', async() => {
|
||||
it('should detect input decorator on setter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Input, Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -622,7 +622,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect setter inputs in derived classes', async() => {
|
||||
it('should detect setter inputs in derived classes', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -647,7 +647,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should properly detect static query in external derived class', async() => {
|
||||
it('should properly detect static query in external derived class', async () => {
|
||||
writeFile('/src/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -680,7 +680,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark queries used in promises as static', async() => {
|
||||
it('should not mark queries used in promises as static', async () => {
|
||||
writeFile('/es2015.dom.d.ts', `
|
||||
interface PromiseConstructor {
|
||||
resolve(): Promise;
|
||||
@ -735,7 +735,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should handle function callbacks which statically access queries', async() => {
|
||||
it('should handle function callbacks which statically access queries', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -764,7 +764,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
});
|
||||
|
||||
it('should handle class instantiations with specified callbacks that access queries',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
import {External} from './external';
|
||||
@ -794,7 +794,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should handle nested functions with arguments from parent closure', async() => {
|
||||
it('should handle nested functions with arguments from parent closure', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -823,7 +823,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark queries used in setTimeout as static', async() => {
|
||||
it('should not mark queries used in setTimeout as static', async () => {
|
||||
writeFile('/lib.dom.d.ts', `declare function setTimeout(cb: Function);`);
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
@ -859,7 +859,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) query3: any;`);
|
||||
});
|
||||
|
||||
it('should not mark queries used in "addEventListener" as static', async() => {
|
||||
it('should not mark queries used in "addEventListener" as static', async () => {
|
||||
writeFile('/lib.dom.d.ts', `
|
||||
interface HTMLElement {
|
||||
addEventListener(cb: Function);
|
||||
@ -888,7 +888,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark queries used in "requestAnimationFrame" as static', async() => {
|
||||
it('should not mark queries used in "requestAnimationFrame" as static', async () => {
|
||||
writeFile('/lib.dom.d.ts', `declare function requestAnimationFrame(cb: Function);`);
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ElementRef, ${queryType}} from '@angular/core';
|
||||
@ -913,8 +913,9 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should mark queries used in immediately-invoked function expression as static', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should mark queries used in immediately-invoked function expression as static',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@Component({template: '<span #test></span>'})
|
||||
@ -934,15 +935,15 @@ describe('static-queries migration with usage strategy', () => {
|
||||
}
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query2: any;`);
|
||||
});
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should detect static queries used in external function-like declaration', async() => {
|
||||
it('should detect static queries used in external function-like declaration', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
import {externalFn} from './external';
|
||||
@ -971,7 +972,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect static queries used through getter property access', async() => {
|
||||
it('should detect static queries used through getter property access', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -995,7 +996,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect static queries used through external getter access', async() => {
|
||||
it('should detect static queries used through external getter access', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
import {External} from './external';
|
||||
@ -1033,8 +1034,9 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark queries as static if a value is assigned to accessor property', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should not mark queries as static if a value is assigned to accessor property',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@Component({template: '<span #test></span>'})
|
||||
@ -1052,13 +1054,13 @@ describe('static-queries migration with usage strategy', () => {
|
||||
}
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should mark queries as static if non-input setter uses query', async() => {
|
||||
it('should mark queries as static if non-input setter uses query', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1083,7 +1085,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should check setter and getter when using compound assignment', async() => {
|
||||
it('should check setter and getter when using compound assignment', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1111,7 +1113,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query2: any;`);
|
||||
});
|
||||
|
||||
it('should check getters when using comparison operator in binary expression', async() => {
|
||||
it('should check getters when using comparison operator in binary expression', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1136,7 +1138,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should check derived abstract class methods', async() => {
|
||||
it('should check derived abstract class methods', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1172,7 +1174,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries accessed through deep abstract class method', async() => {
|
||||
it('should detect queries accessed through deep abstract class method', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1204,7 +1206,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries accessed through abstract property getter', async() => {
|
||||
it('should detect queries accessed through abstract property getter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1230,7 +1232,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect queries accessed through abstract property setter', async() => {
|
||||
it('should detect queries accessed through abstract property setter', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1257,8 +1259,9 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect query usage in abstract class methods accessing inherited query', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should detect query usage in abstract class methods accessing inherited query',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
export abstract class RootBaseClass {
|
||||
@ -1287,13 +1290,13 @@ describe('static-queries migration with usage strategy', () => {
|
||||
}
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect query usage within component template', async() => {
|
||||
it('should detect query usage within component template', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1314,8 +1317,9 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect query usage with nested property read within component template', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should detect query usage with nested property read within component template',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@Component({templateUrl: 'my-template.html'})
|
||||
@ -1324,19 +1328,19 @@ describe('static-queries migration with usage strategy', () => {
|
||||
}
|
||||
`);
|
||||
|
||||
writeFile(`/my-template.html`, `
|
||||
writeFile(`/my-template.html`, `
|
||||
<foo #test></foo>
|
||||
<comp [dir]="query.someProperty"></comp>
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`@${queryType}('test', { static: true }) query: any;`);
|
||||
});
|
||||
|
||||
it('should not mark query as static if template has template reference with same name',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1360,7 +1364,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
});
|
||||
|
||||
it('should not mark query as static if template has property read with query name but different receiver',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1385,7 +1389,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) someProp: any;`);
|
||||
});
|
||||
|
||||
it('should ignore queries accessed within <ng-template> element', async() => {
|
||||
it('should ignore queries accessed within <ng-template> element', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1409,7 +1413,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should detect inherited queries used in templates', async() => {
|
||||
it('should detect inherited queries used in templates', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1433,7 +1437,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
});
|
||||
|
||||
it('should mark queries which could be accessed statically within third-party calls as ambiguous',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
import {thirdPartySync} from 'my-lib';
|
||||
@ -1458,18 +1462,18 @@ describe('static-queries migration with usage strategy', () => {
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(
|
||||
`@${queryType}('test', /* TODO: check static flag */ { static: true }) query: any;`);
|
||||
.toContain(`@${
|
||||
queryType}('test', /* TODO: check static flag */ { static: true }) query: any;`);
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(
|
||||
`@${queryType}('test', /* TODO: check static flag */ { static: true }) query2: any;`);
|
||||
.toContain(`@${
|
||||
queryType}('test', /* TODO: check static flag */ { static: true }) query2: any;`);
|
||||
expect(warnOutput.length).toBe(2);
|
||||
expect(warnOutput[0]).toContain('Query timing is ambiguous.');
|
||||
expect(warnOutput[1]).toContain('Query timing is ambiguous.');
|
||||
});
|
||||
|
||||
it('should mark queries which could be accessed statically within third-party new expressions as ambiguous',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
import {ThirdParty} from 'my-lib';
|
||||
@ -1493,15 +1497,15 @@ describe('static-queries migration with usage strategy', () => {
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(
|
||||
`@${queryType}('test', /* TODO: check static flag */ { static: true }) query: any;`);
|
||||
.toContain(`@${
|
||||
queryType}('test', /* TODO: check static flag */ { static: true }) query: any;`);
|
||||
expect(warnOutput.length).toBe(1);
|
||||
expect(warnOutput[0])
|
||||
.toContain(
|
||||
'Query timing is ambiguous. Please check if the query can be marked as dynamic');
|
||||
});
|
||||
|
||||
it('should properly handle multiple tsconfig files', async() => {
|
||||
it('should properly handle multiple tsconfig files', async () => {
|
||||
writeFile('/src/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
@ -1526,7 +1530,7 @@ describe('static-queries migration with usage strategy', () => {
|
||||
.toContain(`@${queryType}('test', { static: false }) query: any;`);
|
||||
});
|
||||
|
||||
it('should support function call with default parameter value', async() => {
|
||||
it('should support function call with default parameter value', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, ${queryType}} from '@angular/core';
|
||||
|
||||
|
@ -62,7 +62,7 @@ describe('template variable assignment migration', () => {
|
||||
return runner.runSchematicAsync('migration-v8-template-local-variables', {}, tree).toPromise();
|
||||
}
|
||||
|
||||
it('should warn for two-way data binding variable assignment', async() => {
|
||||
it('should warn for two-way data binding variable assignment', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -78,7 +78,7 @@ describe('template variable assignment migration', () => {
|
||||
expect(warnOutput[0]).toMatch(/^⮑ {3}index.ts@5:69: Found assignment/);
|
||||
});
|
||||
|
||||
it('should warn for two-way data binding assigning to "as" variable', async() => {
|
||||
it('should warn for two-way data binding assigning to "as" variable', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -100,7 +100,7 @@ describe('template variable assignment migration', () => {
|
||||
expect(warnOutput).toMatch(/^⮑ {3}tmpl.html@3:31: Found assignment/);
|
||||
});
|
||||
|
||||
it('should warn for bound event assignments to "as" variable', async() => {
|
||||
it('should warn for bound event assignments to "as" variable', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -124,7 +124,7 @@ describe('template variable assignment migration', () => {
|
||||
expect(warnOutput[1]).toMatch(/^⮑ {3}sub_dir\/tmpl.html@4:25: Found assignment/);
|
||||
});
|
||||
|
||||
it('should warn for bound event assignments to template "let" variables', async() => {
|
||||
it('should warn for bound event assignments to template "let" variables', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -148,7 +148,7 @@ describe('template variable assignment migration', () => {
|
||||
expect(warnOutput[1]).toMatch(/^⮑ {3}sub_dir\/tmpl.html@4:25: Found assignment/);
|
||||
});
|
||||
|
||||
it('should not warn for bound event assignments to component property', async() => {
|
||||
it('should not warn for bound event assignments to component property', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -166,7 +166,7 @@ describe('template variable assignment migration', () => {
|
||||
});
|
||||
|
||||
it('should not warn for bound event assignments to template variable object property',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -186,7 +186,7 @@ describe('template variable assignment migration', () => {
|
||||
});
|
||||
|
||||
it('should not warn for property writes with template variable name but different receiver',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -211,7 +211,7 @@ describe('template variable assignment migration', () => {
|
||||
expect(warnOutput.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should warn for template variable assignments in expression conditional', async() => {
|
||||
it('should warn for template variable assignments in expression conditional', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -236,7 +236,7 @@ describe('template variable assignment migration', () => {
|
||||
});
|
||||
|
||||
it('should not warn for property writes with template variable name but different scope',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -259,7 +259,7 @@ describe('template variable assignment migration', () => {
|
||||
});
|
||||
|
||||
|
||||
it('should not throw an error if a detected template fails parsing', async() => {
|
||||
it('should not throw an error if a detected template fails parsing', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@ -276,7 +276,7 @@ describe('template variable assignment migration', () => {
|
||||
expect(warnOutput.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should be able to report multiple templates within the same source file', async() => {
|
||||
it('should be able to report multiple templates within the same source file', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
|
@ -83,7 +83,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
`);
|
||||
}
|
||||
|
||||
it('should print a failure message base class is declared through type definition', async() => {
|
||||
it('should print a failure message base class is declared through type definition', async () => {
|
||||
writeFile('/node_modules/my-lib/package.json', JSON.stringify({
|
||||
version: '0.0.0',
|
||||
main: './index.js',
|
||||
@ -121,7 +121,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
'dependency injection. Please manually fix the following failures');
|
||||
});
|
||||
|
||||
it('should add @Directive() decorator to extended base class', async() => {
|
||||
it('should add @Directive() decorator to extended base class', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, NgZone} from '@angular/core';
|
||||
|
||||
@ -149,8 +149,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toMatch(/@Directive\(\)\nexport class BaseClass2 {/);
|
||||
});
|
||||
|
||||
it('not decorated base class multiple times if extended multiple times', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('not decorated base class multiple times if extended multiple times', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, NgModule, NgZone} from '@angular/core';
|
||||
|
||||
export class BaseClass {
|
||||
@ -169,7 +169,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
|
||||
@Directive()
|
||||
export class BaseClass {
|
||||
@ -177,7 +177,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
}`);
|
||||
});
|
||||
|
||||
it('should add @Injectable() decorator to extended base class', async() => {
|
||||
it('should add @Injectable() decorator to extended base class', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Injectable, NgModule, NgZone} from '@angular/core';
|
||||
|
||||
@ -197,8 +197,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(tree.readContent('/index.ts')).toMatch(/@Injectable\(\)\nexport class BaseClass {/);
|
||||
});
|
||||
|
||||
it('should not decorate base class for decorated pipe', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should not decorate base class for decorated pipe', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, NgModule, Pipe, PipeTransform} from '@angular/core';
|
||||
|
||||
@Pipe({name: 'test'})
|
||||
@ -213,13 +213,13 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(errorOutput.length).toBe(0);
|
||||
expect(warnOutput.length).toBe(0);
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Pipe({name: 'test'})
|
||||
export class MyPipe extends PipeTransform {}`);
|
||||
});
|
||||
|
||||
it('should not decorate base class if no constructor is inherited', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should not decorate base class if no constructor is inherited', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, NgModule, Directive} from '@angular/core';
|
||||
|
||||
export class BaseClassWithoutCtor {
|
||||
@ -238,7 +238,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
|
||||
export class BaseClassWithoutCtor {
|
||||
someUnrelatedProp = true;
|
||||
@ -252,8 +252,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
});
|
||||
|
||||
it('should not decorate base class if directive/component/provider defines a constructor',
|
||||
async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, Injectable, NgModule, NgZone} from '@angular/core';
|
||||
|
||||
export class BaseClass {
|
||||
@ -284,15 +284,15 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
|
||||
export class BaseClass {
|
||||
constructor(zone: NgZone) {}
|
||||
}`);
|
||||
});
|
||||
|
||||
it('should not decorate base class if it already has decorator', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should not decorate base class if it already has decorator', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, Directive, NgModule, NgZone} from '@angular/core';
|
||||
|
||||
@Directive({selector: 'base-class'})
|
||||
@ -312,13 +312,13 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
|
||||
@Directive({selector: 'base-class'})
|
||||
export class BaseClass {`);
|
||||
});
|
||||
|
||||
it('should add a comment if the base class is declared through type definition', async() => {
|
||||
it('should add a comment if the base class is declared through type definition', async () => {
|
||||
writeFile('/node_modules/my-lib/package.json', JSON.stringify({
|
||||
version: '0.0.0',
|
||||
main: './index.js',
|
||||
@ -332,7 +332,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
}
|
||||
`);
|
||||
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, Injectable, NgModule} from '@angular/core';
|
||||
import {SuperBaseClass} from 'my-lib';
|
||||
|
||||
@ -365,42 +365,42 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Directive()
|
||||
export class BaseClass extends SuperBaseClass {
|
||||
// TODO: add explicit constructor
|
||||
}`);
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Injectable()
|
||||
export class BaseClass2 extends SuperBaseClass {
|
||||
// TODO: add explicit constructor
|
||||
}`);
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Directive()
|
||||
export class PassThroughClass extends BaseClass {}`);
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({template: ''})
|
||||
export class MyComponent extends PassThroughClass {}`);
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({template: ''})
|
||||
export class MyComponent3 extends SuperBaseClass {
|
||||
// TODO: add explicit constructor
|
||||
}`);
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Injectable()
|
||||
export class MyService extends BaseClass2 {}`);
|
||||
});
|
||||
|
||||
it('should not add a comment if the base class is declared through type definition but is' +
|
||||
'decorated',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFakeLibrary();
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BaseComponent} from 'my-lib';
|
||||
|
||||
@ -413,14 +413,14 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({template: ''})
|
||||
export class MyComponent extends BaseComponent {}`);
|
||||
});
|
||||
|
||||
it('should not decorate base class in typings if it misses an explicit constructor', async() => {
|
||||
it('should not decorate base class in typings if it misses an explicit constructor', async () => {
|
||||
writeFakeLibrary();
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BaseDirective} from 'my-lib';
|
||||
|
||||
@ -433,16 +433,16 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({template: ''})
|
||||
export class MyComponent extends BaseDirective {}`);
|
||||
expect(tree.readContent('/node_modules/my-lib/public-api.d.ts')).not.toContain('@Directive');
|
||||
});
|
||||
|
||||
it('should detect decorated classes by respecting summary files', async() => {
|
||||
it('should detect decorated classes by respecting summary files', async () => {
|
||||
writeSummaryOnlyThirdPartyLibrary();
|
||||
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BaseComponent} from 'my-lib';
|
||||
|
||||
@ -457,12 +457,12 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
expect(warnOutput.length).toBe(0);
|
||||
expect(errorOutput.length).toBe(0);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({template: ''})
|
||||
export class MyComponent extends BaseComponent {}`);
|
||||
});
|
||||
|
||||
it('should decorate all undecorated directives of inheritance chain', async() => {
|
||||
it('should decorate all undecorated directives of inheritance chain', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, NgZone} from '@angular/core';
|
||||
|
||||
@ -486,7 +486,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
.toMatch(/}\s+@Directive\(\)\nexport class BaseClass extends SuperBaseClass {/);
|
||||
});
|
||||
|
||||
it('should decorate all undecorated providers of inheritance chain', async() => {
|
||||
it('should decorate all undecorated providers of inheritance chain', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Injectable, NgModule, NgZone} from '@angular/core';
|
||||
|
||||
@ -511,7 +511,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
});
|
||||
|
||||
it('should properly update import if @Directive can be accessed through existing namespace import',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, NgZone} from '@angular/core';
|
||||
import {BaseClass} from './base';
|
||||
@ -537,7 +537,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
});
|
||||
|
||||
it('should properly update existing import with aliased specifier if identifier is already used',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, NgZone} from '@angular/core';
|
||||
import {Directive} from './third_party_directive';
|
||||
@ -561,7 +561,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
});
|
||||
|
||||
it('should properly create new import with aliased specifier if identifier is already used',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule, NgZone} from '@angular/core';
|
||||
import {BaseClass} from './base';
|
||||
@ -590,8 +590,9 @@ describe('Undecorated classes with DI migration', () => {
|
||||
.toContain(`{ Directive as Directive_1 } from "@angular/core";`);
|
||||
});
|
||||
|
||||
it('should use existing aliased import of @Directive instead of creating new import', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should use existing aliased import of @Directive instead of creating new import',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {BaseClass} from './base';
|
||||
|
||||
@ -602,7 +603,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/base.ts', `
|
||||
writeFile('/base.ts', `
|
||||
import {Directive as AliasedDir, NgZone} from '@angular/core';
|
||||
|
||||
export class BaseClass {
|
||||
@ -610,15 +611,14 @@ describe('Undecorated classes with DI migration', () => {
|
||||
}
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/base.ts')).toMatch(/@AliasedDir\(\)\nexport class BaseClass {/);
|
||||
});
|
||||
expect(tree.readContent('/base.ts')).toMatch(/@AliasedDir\(\)\nexport class BaseClass {/);
|
||||
});
|
||||
|
||||
describe('decorator copying', async() => {
|
||||
|
||||
it('should be able to copy the "templateUrl" field', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
describe('decorator copying', async () => {
|
||||
it('should be able to copy the "templateUrl" field', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -628,7 +628,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Directive, NgModule} from '@angular/core';
|
||||
|
||||
@Directive({
|
||||
@ -645,7 +645,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`import { NgModule, Directive } from '@angular/core';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Directive({
|
||||
selector: 'my-dir',
|
||||
templateUrl: './my-dir.html'
|
||||
@ -653,8 +653,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyDir extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should be able to copy the "styleUrls" field', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should be able to copy the "styleUrls" field', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -664,7 +664,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Directive, NgModule} from '@angular/core';
|
||||
|
||||
/** my comment */
|
||||
@ -680,7 +680,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@Directive({
|
||||
@ -690,8 +690,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyDir extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should be able to copy @Pipe decorator', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should be able to copy @Pipe decorator', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BasePipe} from './lib/base';
|
||||
|
||||
@ -701,7 +701,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Pipe, NgModule} from '@angular/core';
|
||||
|
||||
@Pipe({name: 'my-pipe-name'})
|
||||
@ -715,16 +715,16 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`import { NgModule, Pipe } from '@angular/core';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Pipe({ name: 'my-pipe-name' })
|
||||
export class MyPipe extends BasePipe {}`);
|
||||
});
|
||||
|
||||
it('should be able to copy decorator in same source file', async() => {
|
||||
it('should be able to copy decorator in same source file', async () => {
|
||||
writeFile(
|
||||
'/node_modules/@angular/cdk/table/index.d.ts',
|
||||
`export declare const CDK_TABLE_TEMPLATE = '';`);
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule, Component} from '@angular/core';
|
||||
import {CDK_TABLE_TEMPLATE} from '@angular/cdk/table';
|
||||
|
||||
@ -748,7 +748,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
selector: 'my-dir',
|
||||
template: CDK_TABLE_TEMPLATE,
|
||||
@ -757,8 +757,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyDir extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should be able to create new imports for copied identifier references', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should be able to create new imports for copied identifier references', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -772,7 +772,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
'/node_modules/@angular/cdk/table/index.d.ts',
|
||||
`export declare const CDK_TABLE_TEMPLATE = '';`);
|
||||
writeFile('/styles.ts', `export const STYLE_THROUGH_VAR = 'external';`);
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
import {CDK_TABLE_TEMPLATE as tableTmpl} from '@angular/cdk/table';
|
||||
import {STYLE_THROUGH_VAR} from '../styles';
|
||||
@ -798,7 +798,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
.toContain(`import { STYLE_THROUGH_VAR } from "./styles";`);
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`import { BaseClass, LOCAL_STYLE } from './lib/base';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
selector: 'my-dir',
|
||||
template: CDK_TABLE_TEMPLATE,
|
||||
@ -807,8 +807,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyDir extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should copy decorator once if directive is referenced multiple times', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should copy decorator once if directive is referenced multiple times', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -818,7 +818,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/second-module.ts', dedent `
|
||||
writeFile('/second-module.ts', dedent`
|
||||
import {NgModule, Directive} from '@angular/core';
|
||||
import {MyComp} from './index';
|
||||
|
||||
@ -829,7 +829,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MySecondModule {}
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
@ -844,7 +844,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@Component({
|
||||
@ -854,8 +854,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyComp extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should create aliased imports to avoid collisions for referenced identifiers', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should create aliased imports to avoid collisions for referenced identifiers', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -869,7 +869,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
||||
export const MY_TEMPLATE = '';
|
||||
@ -888,7 +888,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`import { BaseClass, MY_TEMPLATE as MY_TEMPLATE_1 } from './lib/base';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
selector: 'my-dir',
|
||||
template: MY_TEMPLATE_1
|
||||
@ -896,8 +896,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyComp extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should add comment for metadata fields which cannot be copied', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should add comment for metadata fields which cannot be copied', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -907,7 +907,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Component, NgModule, Document} from '@angular/core';
|
||||
|
||||
// this variable cannot be imported automatically.
|
||||
@ -926,7 +926,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
selector: 'my-dir',
|
||||
template: '',
|
||||
@ -940,8 +940,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
});
|
||||
|
||||
it('should add comment for metadata fields which are added through spread operator',
|
||||
async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -951,7 +951,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyModule {}
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
||||
export const metadataThroughVar = {
|
||||
@ -971,7 +971,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
await runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
selector: 'my-dir',
|
||||
template: '',
|
||||
@ -984,10 +984,10 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyComp extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should be able to copy fields specified through shorthand assignment', async() => {
|
||||
it('should be able to copy fields specified through shorthand assignment', async () => {
|
||||
writeFile('/hello.css', '');
|
||||
writeFile('/my-tmpl.html', '');
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -999,7 +999,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
writeFile('/lib/hello.css', '');
|
||||
writeFile('/lib/my-tmpl.html', '');
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
||||
export const host = {};
|
||||
@ -1022,7 +1022,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`import { BaseClass, templateUrl, host } from './lib/base';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
selector: 'my-dir',
|
||||
templateUrl,
|
||||
@ -1036,10 +1036,10 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyComp extends BaseClass {}`);
|
||||
});
|
||||
|
||||
it('should serialize metadata from base class without source code', async() => {
|
||||
it('should serialize metadata from base class without source code', async () => {
|
||||
writeFakeLibrary();
|
||||
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseComponent, BasePipe} from 'my-lib';
|
||||
|
||||
@ -1061,7 +1061,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(
|
||||
`import { NgModule, ChangeDetectionStrategy, ViewEncapsulation, NG_VALIDATORS, Component, Pipe } from '@angular/core';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
changeDetection: ChangeDetectionStrategy.Default,
|
||||
selector: "comp-selector",
|
||||
@ -1077,7 +1077,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
}
|
||||
})
|
||||
export class PassThrough extends BaseComponent {}`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
changeDetection: ChangeDetectionStrategy.Default,
|
||||
selector: "comp-selector",
|
||||
@ -1093,7 +1093,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
}
|
||||
})
|
||||
export class MyComp extends PassThrough {}`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Pipe({
|
||||
pure: true,
|
||||
name: "external-pipe-name"
|
||||
@ -1101,12 +1101,12 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyPipe extends BasePipe {}`);
|
||||
});
|
||||
|
||||
it('should serialize metadata with external references from class without source code', async() => {
|
||||
it('should serialize metadata with external references from class without source code', async () => {
|
||||
writeFakeLibrary({useImportedTemplate: true});
|
||||
writeFile(
|
||||
'/node_modules/@angular/cdk/table/index.d.ts',
|
||||
`export declare const CDK_TABLE_TEMPLATE = 'Template of CDK Table.';`);
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseComponent} from 'my-lib';
|
||||
|
||||
@ -1121,7 +1121,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(
|
||||
`import { NgModule, ChangeDetectionStrategy, ViewEncapsulation, NG_VALIDATORS, Component } from '@angular/core';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Component({
|
||||
changeDetection: ChangeDetectionStrategy.Default,
|
||||
selector: "comp-selector",
|
||||
@ -1140,10 +1140,10 @@ describe('Undecorated classes with DI migration', () => {
|
||||
});
|
||||
|
||||
it('should not throw if metadata from base class without source code is not serializable',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFakeLibrary({insertInvalidReference: true});
|
||||
|
||||
writeFile('/index.ts', dedent `
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseComponent} from 'my-lib';
|
||||
|
||||
@ -1159,8 +1159,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(errorOutput[0]).toMatch(/Could not resolve non-existent/);
|
||||
});
|
||||
|
||||
it('should not create imports for identifiers resolving to target source file', async() => {
|
||||
writeFile('/index.ts', dedent `
|
||||
it('should not create imports for identifiers resolving to target source file', async () => {
|
||||
writeFile('/index.ts', dedent`
|
||||
import {NgModule} from '@angular/core';
|
||||
import {BaseClass} from './lib/base';
|
||||
|
||||
@ -1175,7 +1175,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export {LOCAL_NAME as PUBLIC_NAME};
|
||||
`);
|
||||
|
||||
writeFile('/lib/base.ts', dedent `
|
||||
writeFile('/lib/base.ts', dedent`
|
||||
import {Directive, NgModule} from '@angular/core';
|
||||
import {SHARED_TEMPLATE_URL, PUBLIC_NAME} from '..';
|
||||
|
||||
@ -1194,7 +1194,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
|
||||
expect(tree.readContent('/index.ts'))
|
||||
.toContain(`import { NgModule, Directive } from '@angular/core';`);
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent`
|
||||
@Directive({
|
||||
selector: 'my-dir',
|
||||
template: SHARED_TEMPLATE_URL,
|
||||
@ -1388,7 +1388,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
}));
|
||||
}
|
||||
|
||||
it('should not run for test tsconfig files', async() => {
|
||||
it('should not run for test tsconfig files', async () => {
|
||||
writeFile('/src/tsconfig.spec.json', JSON.stringify({
|
||||
compilerOptions: {
|
||||
lib: ['es2015'],
|
||||
@ -1429,8 +1429,8 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(errorOutput.length).toBe(0);
|
||||
});
|
||||
|
||||
describe('diagnostics', async() => {
|
||||
it('should gracefully exit migration if project fails with structural diagnostic', async() => {
|
||||
describe('diagnostics', async () => {
|
||||
it('should gracefully exit migration if project fails with structural diagnostic', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
||||
@ -1455,28 +1455,29 @@ describe('Undecorated classes with DI migration', () => {
|
||||
'TypeScript program failures');
|
||||
});
|
||||
|
||||
it('should gracefully exit migration if project fails with syntactical diagnostic', async() => {
|
||||
writeFile('/index.ts', `
|
||||
it('should gracefully exit migration if project fails with syntactical diagnostic',
|
||||
async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule} /* missing "from" */ '@angular/core';
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
await runMigration();
|
||||
|
||||
expect(warnOutput.length).toBe(1);
|
||||
expect(warnOutput[0])
|
||||
.toMatch(/project "tsconfig.json" has syntactical errors which could cause/);
|
||||
expect(errorOutput.length).toBe(1);
|
||||
expect(errorOutput[0]).toMatch(/error TS1005: 'from' expected/);
|
||||
expect(infoOutput.join(' '))
|
||||
.toContain(
|
||||
'Some project targets could not be analyzed due to ' +
|
||||
'TypeScript program failures');
|
||||
});
|
||||
expect(warnOutput.length).toBe(1);
|
||||
expect(warnOutput[0])
|
||||
.toMatch(/project "tsconfig.json" has syntactical errors which could cause/);
|
||||
expect(errorOutput.length).toBe(1);
|
||||
expect(errorOutput[0]).toMatch(/error TS1005: 'from' expected/);
|
||||
expect(infoOutput.join(' '))
|
||||
.toContain(
|
||||
'Some project targets could not be analyzed due to ' +
|
||||
'TypeScript program failures');
|
||||
});
|
||||
|
||||
// Regression test for: https://github.com/angular/angular/issues/34985.
|
||||
it('should be able to migrate libraries with multiple source files and flat-module ' +
|
||||
'options set',
|
||||
async() => {
|
||||
async () => {
|
||||
writeFile('/tsconfig.json', JSON.stringify({
|
||||
compilerOptions: {
|
||||
lib: ['es2015'],
|
||||
@ -1507,7 +1508,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(tree.readContent('/test.ts')).toMatch(/@Injectable\(\)\nexport class BaseClass {/);
|
||||
});
|
||||
|
||||
it('should not throw if resources could not be read', async() => {
|
||||
it('should not throw if resources could not be read', async () => {
|
||||
writeFile('/index.ts', `
|
||||
import {Component, NgModule} from '@angular/core';
|
||||
|
||||
@ -1529,7 +1530,7 @@ describe('Undecorated classes with DI migration', () => {
|
||||
expect(errorOutput.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should not throw if tsconfig references non-existent source file', async() => {
|
||||
it('should not throw if tsconfig references non-existent source file', async () => {
|
||||
writeFile('/tsconfig.json', JSON.stringify({
|
||||
compilerOptions: {
|
||||
lib: ['es2015'],
|
||||
|
@ -114,8 +114,8 @@ export class ImportManager {
|
||||
}
|
||||
|
||||
if (existingImport) {
|
||||
const propertyIdentifier = ts.createIdentifier(symbolName !);
|
||||
const generatedUniqueIdentifier = this._getUniqueIdentifier(sourceFile, symbolName !);
|
||||
const propertyIdentifier = ts.createIdentifier(symbolName!);
|
||||
const generatedUniqueIdentifier = this._getUniqueIdentifier(sourceFile, symbolName!);
|
||||
const needsGeneratedUniqueName = generatedUniqueIdentifier.text !== symbolName;
|
||||
const importName = needsGeneratedUniqueName ? generatedUniqueIdentifier : propertyIdentifier;
|
||||
|
||||
@ -186,7 +186,7 @@ export class ImportManager {
|
||||
this.updatedImports.forEach((expressions, importDecl) => {
|
||||
const sourceFile = importDecl.getSourceFile();
|
||||
const recorder = this.getUpdateRecorder(sourceFile);
|
||||
const namedBindings = importDecl.importClause !.namedBindings as ts.NamedImports;
|
||||
const namedBindings = importDecl.importClause!.namedBindings as ts.NamedImports;
|
||||
const newNamedBindings = ts.updateNamedImports(
|
||||
namedBindings,
|
||||
namedBindings.elements.concat(expressions.map(
|
||||
@ -211,8 +211,8 @@ export class ImportManager {
|
||||
name = `${baseName}_${counter++}`;
|
||||
} while (!this.isUniqueIdentifierName(sourceFile, name));
|
||||
|
||||
this._recordUsedIdentifier(sourceFile, name !);
|
||||
return ts.createIdentifier(name !);
|
||||
this._recordUsedIdentifier(sourceFile, name!);
|
||||
return ts.createIdentifier(name!);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -221,7 +221,7 @@ export class ImportManager {
|
||||
*/
|
||||
private isUniqueIdentifierName(sourceFile: ts.SourceFile, name: string) {
|
||||
if (this.usedIdentifierNames.has(sourceFile) &&
|
||||
this.usedIdentifierNames.get(sourceFile) !.indexOf(name) !== -1) {
|
||||
this.usedIdentifierNames.get(sourceFile)!.indexOf(name) !== -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -230,7 +230,7 @@ export class ImportManager {
|
||||
// is unique in the given declaration scope and we just return false.
|
||||
const nodeQueue: ts.Node[] = [sourceFile];
|
||||
while (nodeQueue.length) {
|
||||
const node = nodeQueue.shift() !;
|
||||
const node = nodeQueue.shift()!;
|
||||
if (ts.isIdentifier(node) && node.text === name) {
|
||||
return false;
|
||||
}
|
||||
@ -254,6 +254,6 @@ export class ImportManager {
|
||||
if (!commentRanges || !commentRanges.length) {
|
||||
return nodeEndPos;
|
||||
}
|
||||
return commentRanges[commentRanges.length - 1] !.end;
|
||||
return commentRanges[commentRanges.length - 1]!.end;
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,9 @@ export interface ResolvedTemplate {
|
||||
* If the template is declared inline within a TypeScript source file, the line and
|
||||
* character are based on the full source file content.
|
||||
*/
|
||||
getCharacterAndLineOfPosition: (pos: number) => { character: number, line: number };
|
||||
getCharacterAndLineOfPosition: (pos: number) => {
|
||||
character: number, line: number
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,8 +105,8 @@ export class NgComponentTemplateVisitor {
|
||||
content: property.initializer.text,
|
||||
inline: true,
|
||||
start: templateStartIdx,
|
||||
getCharacterAndLineOfPosition:
|
||||
pos => ts.getLineAndCharacterOfPosition(sourceFile, pos + templateStartIdx)
|
||||
getCharacterAndLineOfPosition: pos =>
|
||||
ts.getLineAndCharacterOfPosition(sourceFile, pos + templateStartIdx)
|
||||
});
|
||||
}
|
||||
if (propertyName === 'templateUrl' && ts.isStringLiteralLike(property.initializer)) {
|
||||
|
@ -9,7 +9,7 @@
|
||||
import * as ts from 'typescript';
|
||||
import {getCallDecoratorImport} from './typescript/decorators';
|
||||
|
||||
export type CallExpressionDecorator = ts.Decorator & {
|
||||
export type CallExpressionDecorator = ts.Decorator&{
|
||||
expression: ts.CallExpression;
|
||||
};
|
||||
|
||||
@ -30,8 +30,8 @@ export function getAngularDecorators(
|
||||
.filter(({importData}) => importData && importData.importModule.startsWith('@angular/'))
|
||||
.map(({node, importData}) => ({
|
||||
node: node as CallExpressionDecorator,
|
||||
name: importData !.name,
|
||||
moduleName: importData !.importModule,
|
||||
importNode: importData !.node
|
||||
name: importData!.name,
|
||||
moduleName: importData!.importModule,
|
||||
importNode: importData!.node
|
||||
}));
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ function getTargetTsconfigPath(project: WorkspaceProject, targetName: string): s
|
||||
*/
|
||||
function getWorkspaceConfigGracefully(tree: Tree): any {
|
||||
const path = defaultWorkspaceConfigPaths.find(filePath => tree.exists(filePath));
|
||||
const configBuffer = tree.read(path !);
|
||||
const configBuffer = tree.read(path!);
|
||||
|
||||
if (!path || !configBuffer) {
|
||||
return null;
|
||||
|
@ -30,5 +30,5 @@ export function supportsPrompt(): boolean {
|
||||
* create prompts.
|
||||
*/
|
||||
export function getInquirer(): Inquirer {
|
||||
return resolvedInquirerModule !;
|
||||
return resolvedInquirerModule!;
|
||||
}
|
||||
|
@ -7,7 +7,8 @@
|
||||
*/
|
||||
|
||||
import * as ts from 'typescript';
|
||||
import {Import, getImportOfIdentifier} from './imports';
|
||||
|
||||
import {getImportOfIdentifier, Import} from './imports';
|
||||
|
||||
export function getCallDecoratorImport(
|
||||
typeChecker: ts.TypeChecker, decorator: ts.Decorator): Import|null {
|
||||
|
@ -20,7 +20,7 @@ export function isFunctionLikeDeclaration(node: ts.Node): node is ts.FunctionLik
|
||||
* parentheses or as expression. e.g. "(((({exp}))))()". The function should return the
|
||||
* TypeScript node referring to the inner expression. e.g "exp".
|
||||
*/
|
||||
export function unwrapExpression(node: ts.Expression | ts.ParenthesizedExpression): ts.Expression {
|
||||
export function unwrapExpression(node: ts.Expression|ts.ParenthesizedExpression): ts.Expression {
|
||||
if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node)) {
|
||||
return unwrapExpression(node.expression);
|
||||
} else {
|
||||
|
@ -34,9 +34,9 @@ export const APP_INITIALIZER = new InjectionToken<Array<() => void>>('Applicatio
|
||||
@Injectable()
|
||||
export class ApplicationInitStatus {
|
||||
// TODO(issue/24571): remove '!'.
|
||||
private resolve !: Function;
|
||||
private resolve!: Function;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
private reject !: Function;
|
||||
private reject!: Function;
|
||||
private initialized = false;
|
||||
public readonly donePromise: Promise<any>;
|
||||
public readonly done = false;
|
||||
@ -57,7 +57,7 @@ export class ApplicationInitStatus {
|
||||
const asyncInitPromises: Promise<any>[] = [];
|
||||
|
||||
const complete = () => {
|
||||
(this as{done: boolean}).done = true;
|
||||
(this as {done: boolean}).done = true;
|
||||
this.resolve();
|
||||
};
|
||||
|
||||
@ -70,7 +70,13 @@ export class ApplicationInitStatus {
|
||||
}
|
||||
}
|
||||
|
||||
Promise.all(asyncInitPromises).then(() => { complete(); }).catch(e => { this.reject(e); });
|
||||
Promise.all(asyncInitPromises)
|
||||
.then(() => {
|
||||
complete();
|
||||
})
|
||||
.catch(e => {
|
||||
this.reject(e);
|
||||
});
|
||||
|
||||
if (asyncInitPromises.length === 0) {
|
||||
complete();
|
||||
|
@ -9,7 +9,7 @@
|
||||
import {APP_INITIALIZER, ApplicationInitStatus} from './application_init';
|
||||
import {ApplicationRef} from './application_ref';
|
||||
import {APP_ID_RANDOM_PROVIDER} from './application_tokens';
|
||||
import {IterableDiffers, KeyValueDiffers, defaultIterableDiffers, defaultKeyValueDiffers} from './change_detection/change_detection';
|
||||
import {defaultIterableDiffers, defaultKeyValueDiffers, IterableDiffers, KeyValueDiffers} from './change_detection/change_detection';
|
||||
import {Console} from './console';
|
||||
import {Injector, StaticProvider} from './di';
|
||||
import {Inject, Optional, SkipSelf} from './di/metadata';
|
||||
@ -78,8 +78,7 @@ export const APPLICATION_MODULE_PROVIDERS: StaticProvider[] = [
|
||||
{
|
||||
provide: ApplicationRef,
|
||||
useClass: ApplicationRef,
|
||||
deps:
|
||||
[NgZone, Console, Injector, ErrorHandler, ComponentFactoryResolver, ApplicationInitStatus]
|
||||
deps: [NgZone, Console, Injector, ErrorHandler, ComponentFactoryResolver, ApplicationInitStatus]
|
||||
},
|
||||
{provide: SCHEDULER, deps: [NgZone], useFactory: zoneSchedulerFactory},
|
||||
{
|
||||
@ -112,10 +111,12 @@ export function zoneSchedulerFactory(ngZone: NgZone): (fn: () => void) => void {
|
||||
let queue: (() => void)[] = [];
|
||||
ngZone.onStable.subscribe(() => {
|
||||
while (queue.length) {
|
||||
queue.pop() !();
|
||||
queue.pop()!();
|
||||
}
|
||||
});
|
||||
return function(fn: () => void) { queue.push(fn); };
|
||||
return function(fn: () => void) {
|
||||
queue.push(fn);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
import './util/ng_jit_mode';
|
||||
|
||||
import {Observable, Observer, Subscription, merge} from 'rxjs';
|
||||
import {merge, Observable, Observer, Subscription} from 'rxjs';
|
||||
import {share} from 'rxjs/operators';
|
||||
|
||||
import {ApplicationInitStatus} from './application_init';
|
||||
@ -80,7 +80,7 @@ export function compileNgModuleFactory__POST_R3__<M>(
|
||||
return Promise.resolve(moduleFactory);
|
||||
}
|
||||
|
||||
const compilerProviders = _mergeArrays(compilerOptions.map(o => o.providers !));
|
||||
const compilerProviders = _mergeArrays(compilerOptions.map(o => o.providers!));
|
||||
|
||||
// In case there are no compiler providers, we just return the module factory as
|
||||
// there won't be any resource loader. This can happen with Ivy, because AOT compiled
|
||||
@ -157,9 +157,8 @@ export function createPlatform(injector: Injector): PlatformRef {
|
||||
* @publicApi
|
||||
*/
|
||||
export function createPlatformFactory(
|
||||
parentPlatformFactory: ((extraProviders?: StaticProvider[]) => PlatformRef) | null,
|
||||
name: string, providers: StaticProvider[] = []): (extraProviders?: StaticProvider[]) =>
|
||||
PlatformRef {
|
||||
parentPlatformFactory: ((extraProviders?: StaticProvider[]) => PlatformRef)|null, name: string,
|
||||
providers: StaticProvider[] = []): (extraProviders?: StaticProvider[]) => PlatformRef {
|
||||
const desc = `Platform: ${name}`;
|
||||
const marker = new InjectionToken(desc);
|
||||
return (extraProviders: StaticProvider[] = []) => {
|
||||
@ -320,10 +319,12 @@ export class PlatformRef {
|
||||
throw new Error('No ErrorHandler. Is platform module (BrowserModule) included?');
|
||||
}
|
||||
moduleRef.onDestroy(() => remove(this._modules, moduleRef));
|
||||
ngZone !.runOutsideAngular(
|
||||
() => ngZone !.onError.subscribe(
|
||||
{next: (error: any) => { exceptionHandler.handleError(error); }}));
|
||||
return _callAndReportToErrorHandler(exceptionHandler, ngZone !, () => {
|
||||
ngZone!.runOutsideAngular(() => ngZone!.onError.subscribe({
|
||||
next: (error: any) => {
|
||||
exceptionHandler.handleError(error);
|
||||
}
|
||||
}));
|
||||
return _callAndReportToErrorHandler(exceptionHandler, ngZone!, () => {
|
||||
const initStatus: ApplicationInitStatus = moduleRef.injector.get(ApplicationInitStatus);
|
||||
initStatus.runInitializers();
|
||||
return initStatus.donePromise.then(() => {
|
||||
@ -356,7 +357,8 @@ export class PlatformRef {
|
||||
*
|
||||
*/
|
||||
bootstrapModule<M>(
|
||||
moduleType: Type<M>, compilerOptions: (CompilerOptions&BootstrapOptions)|
|
||||
moduleType: Type<M>,
|
||||
compilerOptions: (CompilerOptions&BootstrapOptions)|
|
||||
Array<CompilerOptions&BootstrapOptions> = []): Promise<NgModuleRef<M>> {
|
||||
const options = optionsReducer({}, compilerOptions);
|
||||
return compileNgModuleFactory(this.injector, options, moduleType)
|
||||
@ -371,7 +373,10 @@ export class PlatformRef {
|
||||
moduleRef.instance.ngDoBootstrap(appRef);
|
||||
} else {
|
||||
throw new Error(
|
||||
`The module ${stringify(moduleRef.instance.constructor)} was bootstrapped, but it does not declare "@NgModule.bootstrap" components nor a "ngDoBootstrap" method. ` +
|
||||
`The module ${
|
||||
stringify(
|
||||
moduleRef.instance
|
||||
.constructor)} was bootstrapped, but it does not declare "@NgModule.bootstrap" components nor a "ngDoBootstrap" method. ` +
|
||||
`Please define one of these.`);
|
||||
}
|
||||
this._modules.push(moduleRef);
|
||||
@ -380,13 +385,17 @@ export class PlatformRef {
|
||||
/**
|
||||
* Register a listener to be called when the platform is disposed.
|
||||
*/
|
||||
onDestroy(callback: () => void): void { this._destroyListeners.push(callback); }
|
||||
onDestroy(callback: () => void): void {
|
||||
this._destroyListeners.push(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the platform {@link Injector}, which is the parent injector for
|
||||
* every Angular application on the page and provides singleton providers.
|
||||
*/
|
||||
get injector(): Injector { return this._injector; }
|
||||
get injector(): Injector {
|
||||
return this._injector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy the Angular platform and all Angular applications on the page.
|
||||
@ -400,11 +409,13 @@ export class PlatformRef {
|
||||
this._destroyed = true;
|
||||
}
|
||||
|
||||
get destroyed() { return this._destroyed; }
|
||||
get destroyed() {
|
||||
return this._destroyed;
|
||||
}
|
||||
}
|
||||
|
||||
function getNgZone(
|
||||
ngZoneOption: NgZone | 'zone.js' | 'noop' | undefined, ngZoneEventCoalescing: boolean): NgZone {
|
||||
ngZoneOption: NgZone|'zone.js'|'noop'|undefined, ngZoneEventCoalescing: boolean): NgZone {
|
||||
let ngZone: NgZone;
|
||||
|
||||
if (ngZoneOption === 'noop') {
|
||||
@ -438,7 +449,7 @@ function _callAndReportToErrorHandler(
|
||||
}
|
||||
}
|
||||
|
||||
function optionsReducer<T extends Object>(dst: any, objs: T | T[]): T {
|
||||
function optionsReducer<T extends Object>(dst: any, objs: T|T[]): T {
|
||||
if (Array.isArray(objs)) {
|
||||
dst = objs.reduce(optionsReducer, dst);
|
||||
} else {
|
||||
@ -566,7 +577,7 @@ export class ApplicationRef {
|
||||
* @see [Usage notes](#is-stable-examples) for examples and caveats when using this API.
|
||||
*/
|
||||
// TODO(issue/24571): remove '!'.
|
||||
public readonly isStable !: Observable<boolean>;
|
||||
public readonly isStable!: Observable<boolean>;
|
||||
|
||||
/** @internal */
|
||||
constructor(
|
||||
@ -576,8 +587,13 @@ export class ApplicationRef {
|
||||
private _initStatus: ApplicationInitStatus) {
|
||||
this._enforceNoNewChanges = isDevMode();
|
||||
|
||||
this._zone.onMicrotaskEmpty.subscribe(
|
||||
{next: () => { this._zone.run(() => { this.tick(); }); }});
|
||||
this._zone.onMicrotaskEmpty.subscribe({
|
||||
next: () => {
|
||||
this._zone.run(() => {
|
||||
this.tick();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
const isCurrentlyStable = new Observable<boolean>((observer: Observer<boolean>) => {
|
||||
this._stable = this._zone.isStable && !this._zone.hasPendingMacrotasks &&
|
||||
@ -612,7 +628,9 @@ export class ApplicationRef {
|
||||
NgZone.assertInAngularZone();
|
||||
if (this._stable) {
|
||||
this._stable = false;
|
||||
this._zone.runOutsideAngular(() => { observer.next(false); });
|
||||
this._zone.runOutsideAngular(() => {
|
||||
observer.next(false);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -622,7 +640,7 @@ export class ApplicationRef {
|
||||
};
|
||||
});
|
||||
|
||||
(this as{isStable: Observable<boolean>}).isStable =
|
||||
(this as {isStable: Observable<boolean>}).isStable =
|
||||
merge(isCurrentlyStable, isStable.pipe(share()));
|
||||
}
|
||||
|
||||
@ -653,7 +671,7 @@ export class ApplicationRef {
|
||||
componentFactory = componentOrFactory;
|
||||
} else {
|
||||
componentFactory =
|
||||
this._componentFactoryResolver.resolveComponentFactory(componentOrFactory) !;
|
||||
this._componentFactoryResolver.resolveComponentFactory(componentOrFactory)!;
|
||||
}
|
||||
this.componentTypes.push(componentFactory.componentType);
|
||||
|
||||
@ -663,7 +681,9 @@ export class ApplicationRef {
|
||||
const selectorOrNode = rootSelectorOrNode || componentFactory.selector;
|
||||
const compRef = componentFactory.create(Injector.NULL, [], selectorOrNode, ngModule);
|
||||
|
||||
compRef.onDestroy(() => { this._unloadComponent(compRef); });
|
||||
compRef.onDestroy(() => {
|
||||
this._unloadComponent(compRef);
|
||||
});
|
||||
const testability = compRef.injector.get(Testability, null);
|
||||
if (testability) {
|
||||
compRef.injector.get(TestabilityRegistry)
|
||||
@ -755,7 +775,9 @@ export class ApplicationRef {
|
||||
/**
|
||||
* Returns the number of attached views.
|
||||
*/
|
||||
get viewCount() { return this._views.length; }
|
||||
get viewCount() {
|
||||
return this._views.length;
|
||||
}
|
||||
}
|
||||
|
||||
function remove<T>(list: T[], el: T): void {
|
||||
|
@ -11,26 +11,16 @@ import {DefaultKeyValueDifferFactory} from './differs/default_keyvalue_differ';
|
||||
import {IterableDifferFactory, IterableDiffers} from './differs/iterable_differs';
|
||||
import {KeyValueDifferFactory, KeyValueDiffers} from './differs/keyvalue_differs';
|
||||
|
||||
export {WrappedValue, devModeEqual} from './change_detection_util';
|
||||
export {SimpleChange, SimpleChanges} from '../interface/simple_change';
|
||||
export {devModeEqual, WrappedValue} from './change_detection_util';
|
||||
export {ChangeDetectorRef} from './change_detector_ref';
|
||||
export {ChangeDetectionStrategy, ChangeDetectorStatus, isDefaultChangeDetectionStrategy} from './constants';
|
||||
export {DefaultIterableDifferFactory} from './differs/default_iterable_differ';
|
||||
export {DefaultIterableDiffer} from './differs/default_iterable_differ';
|
||||
export {DefaultKeyValueDifferFactory} from './differs/default_keyvalue_differ';
|
||||
export {
|
||||
CollectionChangeRecord,
|
||||
IterableChangeRecord,
|
||||
IterableChanges,
|
||||
IterableDiffer,
|
||||
IterableDifferFactory,
|
||||
IterableDiffers,
|
||||
NgIterable,
|
||||
TrackByFunction
|
||||
} from
|
||||
'./differs/iterable_differs';
|
||||
export {CollectionChangeRecord, IterableChangeRecord, IterableChanges, IterableDiffer, IterableDifferFactory, IterableDiffers, NgIterable, TrackByFunction} from './differs/iterable_differs';
|
||||
export {KeyValueChangeRecord, KeyValueChanges, KeyValueDiffer, KeyValueDifferFactory, KeyValueDiffers} from './differs/keyvalue_differs';
|
||||
export {PipeTransform} from './pipe_transform';
|
||||
export {SimpleChange, SimpleChanges} from '../interface/simple_change';
|
||||
|
||||
|
||||
|
||||
|
@ -49,19 +49,27 @@ export class WrappedValue {
|
||||
/** @deprecated from 5.3, use `unwrap()` instead - will switch to protected */
|
||||
wrapped: any;
|
||||
|
||||
constructor(value: any) { this.wrapped = value; }
|
||||
constructor(value: any) {
|
||||
this.wrapped = value;
|
||||
}
|
||||
|
||||
/** Creates a wrapped value. */
|
||||
static wrap(value: any): WrappedValue { return new WrappedValue(value); }
|
||||
static wrap(value: any): WrappedValue {
|
||||
return new WrappedValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the underlying value of a wrapped value.
|
||||
* Returns the given `value` when it is not wrapped.
|
||||
**/
|
||||
static unwrap(value: any): any { return WrappedValue.isWrapped(value) ? value.wrapped : value; }
|
||||
static unwrap(value: any): any {
|
||||
return WrappedValue.isWrapped(value) ? value.wrapped : value;
|
||||
}
|
||||
|
||||
/** Returns true if `value` is a wrapped value. */
|
||||
static isWrapped(value: any): value is WrappedValue { return value instanceof WrappedValue; }
|
||||
static isWrapped(value: any): value is WrappedValue {
|
||||
return value instanceof WrappedValue;
|
||||
}
|
||||
}
|
||||
|
||||
export function isListLikeIterable(obj: any): boolean {
|
||||
|
@ -15,7 +15,9 @@ import {IterableChangeRecord, IterableChanges, IterableDiffer, IterableDifferFac
|
||||
|
||||
export class DefaultIterableDifferFactory implements IterableDifferFactory {
|
||||
constructor() {}
|
||||
supports(obj: Object|null|undefined): boolean { return isListLikeIterable(obj); }
|
||||
supports(obj: Object|null|undefined): boolean {
|
||||
return isListLikeIterable(obj);
|
||||
}
|
||||
|
||||
create<V>(trackByFn?: TrackByFunction<V>): DefaultIterableDiffer<V> {
|
||||
return new DefaultIterableDiffer<V>(trackByFn);
|
||||
@ -31,7 +33,7 @@ const trackByIdentity = (index: number, item: any) => item;
|
||||
export class DefaultIterableDiffer<V> implements IterableDiffer<V>, IterableChanges<V> {
|
||||
public readonly length: number = 0;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
public readonly collection !: V[] | Iterable<V>| null;
|
||||
public readonly collection!: V[]|Iterable<V>|null;
|
||||
// Keeps track of the used records at any point in time (during & across `_check()` calls)
|
||||
private _linkedRecords: _DuplicateMap<V>|null = null;
|
||||
// Keeps track of the removed records at any point in time during `_check()` calls.
|
||||
@ -50,7 +52,9 @@ export class DefaultIterableDiffer<V> implements IterableDiffer<V>, IterableChan
|
||||
private _identityChangesTail: IterableChangeRecord_<V>|null = null;
|
||||
private _trackByFn: TrackByFunction<V>;
|
||||
|
||||
constructor(trackByFn?: TrackByFunction<V>) { this._trackByFn = trackByFn || trackByIdentity; }
|
||||
constructor(trackByFn?: TrackByFunction<V>) {
|
||||
this._trackByFn = trackByFn || trackByIdentity;
|
||||
}
|
||||
|
||||
forEachItem(fn: (record: IterableChangeRecord_<V>) => void) {
|
||||
let record: IterableChangeRecord_<V>|null;
|
||||
@ -71,9 +75,9 @@ export class DefaultIterableDiffer<V> implements IterableDiffer<V>, IterableChan
|
||||
// Order: remove, add, move
|
||||
const record: IterableChangeRecord<V> = !nextRemove ||
|
||||
nextIt &&
|
||||
nextIt.currentIndex ! <
|
||||
nextIt.currentIndex! <
|
||||
getPreviousIndex(nextRemove, addRemoveOffset, moveOffsets) ?
|
||||
nextIt ! :
|
||||
nextIt! :
|
||||
nextRemove;
|
||||
const adjPreviousIndex = getPreviousIndex(record, addRemoveOffset, moveOffsets);
|
||||
const currentIndex = record.currentIndex;
|
||||
@ -83,14 +87,14 @@ export class DefaultIterableDiffer<V> implements IterableDiffer<V>, IterableChan
|
||||
addRemoveOffset--;
|
||||
nextRemove = nextRemove._nextRemoved;
|
||||
} else {
|
||||
nextIt = nextIt !._next;
|
||||
nextIt = nextIt!._next;
|
||||
if (record.previousIndex == null) {
|
||||
addRemoveOffset++;
|
||||
} else {
|
||||
// INVARIANT: currentIndex < previousIndex
|
||||
if (!moveOffsets) moveOffsets = [];
|
||||
const localMovePreviousIndex = adjPreviousIndex - addRemoveOffset;
|
||||
const localCurrentIndex = currentIndex ! - addRemoveOffset;
|
||||
const localCurrentIndex = currentIndex! - addRemoveOffset;
|
||||
if (localMovePreviousIndex != localCurrentIndex) {
|
||||
for (let i = 0; i < localMovePreviousIndex; i++) {
|
||||
const offset = i < moveOffsets.length ? moveOffsets[i] : (moveOffsets[i] = 0);
|
||||
@ -171,7 +175,7 @@ export class DefaultIterableDiffer<V> implements IterableDiffer<V>, IterableChan
|
||||
let item: V;
|
||||
let itemTrackBy: any;
|
||||
if (Array.isArray(collection)) {
|
||||
(this as{length: number}).length = collection.length;
|
||||
(this as {length: number}).length = collection.length;
|
||||
|
||||
for (let index = 0; index < this.length; index++) {
|
||||
item = collection[index];
|
||||
@ -206,11 +210,11 @@ export class DefaultIterableDiffer<V> implements IterableDiffer<V>, IterableChan
|
||||
record = record._next;
|
||||
index++;
|
||||
});
|
||||
(this as{length: number}).length = index;
|
||||
(this as {length: number}).length = index;
|
||||
}
|
||||
|
||||
this._truncate(record);
|
||||
(this as{collection: V[] | Iterable<V>}).collection = collection;
|
||||
(this as {collection: V[] | Iterable<V>}).collection = collection;
|
||||
return this.isDirty;
|
||||
}
|
||||
|
||||
@ -338,7 +342,7 @@ export class DefaultIterableDiffer<V> implements IterableDiffer<V>, IterableChan
|
||||
let reinsertRecord: IterableChangeRecord_<V>|null =
|
||||
this._unlinkedRecords === null ? null : this._unlinkedRecords.get(itemTrackBy, null);
|
||||
if (reinsertRecord !== null) {
|
||||
record = this._reinsertAfter(reinsertRecord, record._prev !, index);
|
||||
record = this._reinsertAfter(reinsertRecord, record._prev!, index);
|
||||
} else if (record.currentIndex != index) {
|
||||
record.currentIndex = index;
|
||||
this._addToMoves(record, index);
|
||||
@ -611,7 +615,7 @@ class _DuplicateItemRecordList<V> {
|
||||
// TODO(vicb):
|
||||
// assert(record.item == _head.item ||
|
||||
// record.item is num && record.item.isNaN && _head.item is num && _head.item.isNaN);
|
||||
this._tail !._nextDup = record;
|
||||
this._tail!._nextDup = record;
|
||||
record._prevDup = this._tail;
|
||||
record._nextDup = null;
|
||||
this._tail = record;
|
||||
@ -623,7 +627,7 @@ class _DuplicateItemRecordList<V> {
|
||||
get(trackById: any, atOrAfterIndex: number|null): IterableChangeRecord_<V>|null {
|
||||
let record: IterableChangeRecord_<V>|null;
|
||||
for (record = this._head; record !== null; record = record._nextDup) {
|
||||
if ((atOrAfterIndex === null || atOrAfterIndex <= record.currentIndex !) &&
|
||||
if ((atOrAfterIndex === null || atOrAfterIndex <= record.currentIndex!) &&
|
||||
looseIdentical(record.trackById, trackById)) {
|
||||
return record;
|
||||
}
|
||||
@ -696,7 +700,7 @@ class _DuplicateMap<V> {
|
||||
*/
|
||||
remove(record: IterableChangeRecord_<V>): IterableChangeRecord_<V> {
|
||||
const key = record.trackById;
|
||||
const recordList: _DuplicateItemRecordList<V> = this.map.get(key) !;
|
||||
const recordList: _DuplicateItemRecordList<V> = this.map.get(key)!;
|
||||
// Remove the list of duplicates when it gets empty
|
||||
if (recordList.remove(record)) {
|
||||
this.map.delete(key);
|
||||
@ -704,13 +708,16 @@ class _DuplicateMap<V> {
|
||||
return record;
|
||||
}
|
||||
|
||||
get isEmpty(): boolean { return this.map.size === 0; }
|
||||
get isEmpty(): boolean {
|
||||
return this.map.size === 0;
|
||||
}
|
||||
|
||||
clear() { this.map.clear(); }
|
||||
clear() {
|
||||
this.map.clear();
|
||||
}
|
||||
}
|
||||
|
||||
function getPreviousIndex(
|
||||
item: any, addRemoveOffset: number, moveOffsets: number[] | null): number {
|
||||
function getPreviousIndex(item: any, addRemoveOffset: number, moveOffsets: number[]|null): number {
|
||||
const previousIndex = item.previousIndex;
|
||||
if (previousIndex === null) return previousIndex;
|
||||
let moveOffset = 0;
|
||||
|
@ -14,9 +14,13 @@ import {KeyValueChangeRecord, KeyValueChanges, KeyValueDiffer, KeyValueDifferFac
|
||||
|
||||
export class DefaultKeyValueDifferFactory<K, V> implements KeyValueDifferFactory {
|
||||
constructor() {}
|
||||
supports(obj: any): boolean { return obj instanceof Map || isJsObject(obj); }
|
||||
supports(obj: any): boolean {
|
||||
return obj instanceof Map || isJsObject(obj);
|
||||
}
|
||||
|
||||
create<K, V>(): KeyValueDiffer<K, V> { return new DefaultKeyValueDiffer<K, V>(); }
|
||||
create<K, V>(): KeyValueDiffer<K, V> {
|
||||
return new DefaultKeyValueDiffer<K, V>();
|
||||
}
|
||||
}
|
||||
|
||||
export class DefaultKeyValueDiffer<K, V> implements KeyValueDiffer<K, V>, KeyValueChanges<K, V> {
|
||||
@ -175,7 +179,7 @@ export class DefaultKeyValueDiffer<K, V> implements KeyValueDiffer<K, V>, KeyVal
|
||||
|
||||
private _getOrCreateRecordForKey(key: K, value: V): KeyValueChangeRecord_<K, V> {
|
||||
if (this._records.has(key)) {
|
||||
const record = this._records.get(key) !;
|
||||
const record = this._records.get(key)!;
|
||||
this._maybeAddToChanges(record, value);
|
||||
const prev = record._prev;
|
||||
const next = record._next;
|
||||
@ -236,7 +240,7 @@ export class DefaultKeyValueDiffer<K, V> implements KeyValueDiffer<K, V>, KeyVal
|
||||
if (this._additionsHead === null) {
|
||||
this._additionsHead = this._additionsTail = record;
|
||||
} else {
|
||||
this._additionsTail !._nextAdded = record;
|
||||
this._additionsTail!._nextAdded = record;
|
||||
this._additionsTail = record;
|
||||
}
|
||||
}
|
||||
@ -245,7 +249,7 @@ export class DefaultKeyValueDiffer<K, V> implements KeyValueDiffer<K, V>, KeyVal
|
||||
if (this._changesHead === null) {
|
||||
this._changesHead = this._changesTail = record;
|
||||
} else {
|
||||
this._changesTail !._nextChanged = record;
|
||||
this._changesTail!._nextChanged = record;
|
||||
this._changesTail = record;
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import {DefaultIterableDifferFactory} from '../differs/default_iterable_differ';
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export type NgIterable<T> = Array<T>| Iterable<T>;
|
||||
export type NgIterable<T> = Array<T>|Iterable<T>;
|
||||
|
||||
/**
|
||||
* A strategy for tracking changes over time to an iterable. Used by {@link NgForOf} to
|
||||
@ -86,8 +86,10 @@ export interface IterableChanges<V> {
|
||||
/** Iterate over all removed items. */
|
||||
forEachRemovedItem(fn: (record: IterableChangeRecord<V>) => void): void;
|
||||
|
||||
/** Iterate over all items which had their identity (as computed by the `TrackByFunction`)
|
||||
* changed. */
|
||||
/**
|
||||
* Iterate over all items which had their identity (as computed by the `TrackByFunction`)
|
||||
* changed.
|
||||
*/
|
||||
forEachIdentityChange(fn: (record: IterableChangeRecord<V>) => void): void;
|
||||
}
|
||||
|
||||
@ -124,7 +126,9 @@ export interface CollectionChangeRecord<V> extends IterableChangeRecord<V> {}
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export interface TrackByFunction<T> { (index: number, item: T): any; }
|
||||
export interface TrackByFunction<T> {
|
||||
(index: number, item: T): any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a factory for {@link IterableDiffer}.
|
||||
@ -153,7 +157,9 @@ export class IterableDiffers {
|
||||
* @deprecated v4.0.0 - Should be private
|
||||
*/
|
||||
factories: IterableDifferFactory[];
|
||||
constructor(factories: IterableDifferFactory[]) { this.factories = factories; }
|
||||
constructor(factories: IterableDifferFactory[]) {
|
||||
this.factories = factories;
|
||||
}
|
||||
|
||||
static create(factories: IterableDifferFactory[], parent?: IterableDiffers): IterableDiffers {
|
||||
if (parent != null) {
|
||||
@ -206,8 +212,8 @@ export class IterableDiffers {
|
||||
if (factory != null) {
|
||||
return factory;
|
||||
} else {
|
||||
throw new Error(
|
||||
`Cannot find a differ supporting object '${iterable}' of type '${getTypeNameForDebugging(iterable)}'`);
|
||||
throw new Error(`Cannot find a differ supporting object '${iterable}' of type '${
|
||||
getTypeNameForDebugging(iterable)}'`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,9 @@ export class KeyValueDiffers {
|
||||
*/
|
||||
factories: KeyValueDifferFactory[];
|
||||
|
||||
constructor(factories: KeyValueDifferFactory[]) { this.factories = factories; }
|
||||
constructor(factories: KeyValueDifferFactory[]) {
|
||||
this.factories = factories;
|
||||
}
|
||||
|
||||
static create<S>(factories: KeyValueDifferFactory[], parent?: KeyValueDiffers): KeyValueDiffers {
|
||||
if (parent) {
|
||||
|
@ -30,4 +30,6 @@
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export interface PipeTransform { transform(value: any, ...args: any[]): any; }
|
||||
export interface PipeTransform {
|
||||
transform(value: any, ...args: any[]): any;
|
||||
}
|
||||
|
@ -8,4 +8,4 @@
|
||||
|
||||
export {CodegenComponentFactoryResolver as ɵCodegenComponentFactoryResolver} from './linker/component_factory_resolver';
|
||||
export {registerModuleFactory as ɵregisterModuleFactory} from './linker/ng_module_factory_registration';
|
||||
export {ArgumentType as ɵArgumentType, BindingFlags as ɵBindingFlags, DepFlags as ɵDepFlags, EMPTY_ARRAY as ɵEMPTY_ARRAY, EMPTY_MAP as ɵEMPTY_MAP, NodeFlags as ɵNodeFlags, QueryBindingType as ɵQueryBindingType, QueryValueType as ɵQueryValueType, ViewDefinition as ɵViewDefinition, ViewFlags as ɵViewFlags, anchorDef as ɵand, createComponentFactory as ɵccf, createNgModuleFactory as ɵcmf, createRendererType2 as ɵcrt, directiveDef as ɵdid, elementDef as ɵeld, getComponentViewDefinitionFactory as ɵgetComponentViewDefinitionFactory, inlineInterpolate as ɵinlineInterpolate, interpolate as ɵinterpolate, moduleDef as ɵmod, moduleProvideDef as ɵmpd, ngContentDef as ɵncd, nodeValue as ɵnov, pipeDef as ɵpid, providerDef as ɵprd, pureArrayDef as ɵpad, pureObjectDef as ɵpod, purePipeDef as ɵppd, queryDef as ɵqud, textDef as ɵted, unwrapValue as ɵunv, viewDef as ɵvid} from './view/index';
|
||||
export {anchorDef as ɵand, ArgumentType as ɵArgumentType, BindingFlags as ɵBindingFlags, createComponentFactory as ɵccf, createNgModuleFactory as ɵcmf, createRendererType2 as ɵcrt, DepFlags as ɵDepFlags, directiveDef as ɵdid, elementDef as ɵeld, EMPTY_ARRAY as ɵEMPTY_ARRAY, EMPTY_MAP as ɵEMPTY_MAP, getComponentViewDefinitionFactory as ɵgetComponentViewDefinitionFactory, inlineInterpolate as ɵinlineInterpolate, interpolate as ɵinterpolate, moduleDef as ɵmod, moduleProvideDef as ɵmpd, ngContentDef as ɵncd, NodeFlags as ɵNodeFlags, nodeValue as ɵnov, pipeDef as ɵpid, providerDef as ɵprd, pureArrayDef as ɵpad, pureObjectDef as ɵpod, purePipeDef as ɵppd, QueryBindingType as ɵQueryBindingType, queryDef as ɵqud, QueryValueType as ɵQueryValueType, textDef as ɵted, unwrapValue as ɵunv, viewDef as ɵvid, ViewDefinition as ɵViewDefinition, ViewFlags as ɵViewFlags} from './view/index';
|
||||
|
@ -22,7 +22,9 @@
|
||||
* ```
|
||||
*/
|
||||
|
||||
export interface ExportedCompilerFacade { ɵcompilerFacade: CompilerFacade; }
|
||||
export interface ExportedCompilerFacade {
|
||||
ɵcompilerFacade: CompilerFacade;
|
||||
}
|
||||
|
||||
export interface CompilerFacade {
|
||||
compilePipe(angularCoreEnv: CoreEnvironment, sourceMapUrl: string, meta: R3PipeMetadataFacade):
|
||||
@ -44,13 +46,15 @@ export interface CompilerFacade {
|
||||
|
||||
R3ResolvedDependencyType: typeof R3ResolvedDependencyType;
|
||||
R3FactoryTarget: typeof R3FactoryTarget;
|
||||
ResourceLoader: {new (): ResourceLoader};
|
||||
ResourceLoader: {new(): ResourceLoader};
|
||||
}
|
||||
|
||||
export interface CoreEnvironment { [name: string]: Function; }
|
||||
export interface CoreEnvironment {
|
||||
[name: string]: Function;
|
||||
}
|
||||
|
||||
export type ResourceLoader = {
|
||||
get(url: string): Promise<string>| string;
|
||||
get(url: string): Promise<string>|string;
|
||||
};
|
||||
|
||||
export type StringMap = {
|
||||
@ -58,7 +62,7 @@ export type StringMap = {
|
||||
};
|
||||
|
||||
export type StringMapWithRename = {
|
||||
[key: string]: string | [string, string];
|
||||
[key: string]: string|[string, string];
|
||||
};
|
||||
|
||||
export type Provider = any;
|
||||
|
@ -16,7 +16,7 @@ export {getDebugNodeR2 as ɵgetDebugNodeR2} from './debug/debug_node';
|
||||
export {inject, setCurrentInjector as ɵsetCurrentInjector, ɵɵinject} from './di/injector_compatibility';
|
||||
export {getInjectableDef as ɵgetInjectableDef, ɵɵInjectableDef, ɵɵInjectorDef} from './di/interface/defs';
|
||||
export {INJECTOR_SCOPE as ɵINJECTOR_SCOPE} from './di/scope';
|
||||
export {CurrencyIndex as ɵCurrencyIndex, ExtraLocaleDataIndex as ɵExtraLocaleDataIndex, LocaleDataIndex as ɵLocaleDataIndex, findLocaleData as ɵfindLocaleData, getLocaleCurrencyCode as ɵgetLocaleCurrencyCode, getLocalePluralCase as ɵgetLocalePluralCase, registerLocaleData as ɵregisterLocaleData, unregisterAllLocaleData as ɵunregisterLocaleData} from './i18n/locale_data_api';
|
||||
export {CurrencyIndex as ɵCurrencyIndex, ExtraLocaleDataIndex as ɵExtraLocaleDataIndex, findLocaleData as ɵfindLocaleData, getLocaleCurrencyCode as ɵgetLocaleCurrencyCode, getLocalePluralCase as ɵgetLocalePluralCase, LocaleDataIndex as ɵLocaleDataIndex, registerLocaleData as ɵregisterLocaleData, unregisterAllLocaleData as ɵunregisterLocaleData} from './i18n/locale_data_api';
|
||||
export {DEFAULT_LOCALE_ID as ɵDEFAULT_LOCALE_ID} from './i18n/localization';
|
||||
export {ivyEnabled as ɵivyEnabled} from './ivy_switch';
|
||||
export {ComponentFactory as ɵComponentFactory} from './linker/component_factory';
|
||||
@ -24,7 +24,7 @@ export {CodegenComponentFactoryResolver as ɵCodegenComponentFactoryResolver} fr
|
||||
export {clearResolutionOfComponentResourcesQueue as ɵclearResolutionOfComponentResourcesQueue, resolveComponentResources as ɵresolveComponentResources} from './metadata/resource_loading';
|
||||
export {ReflectionCapabilities as ɵReflectionCapabilities} from './reflection/reflection_capabilities';
|
||||
export {GetterFn as ɵGetterFn, MethodFn as ɵMethodFn, SetterFn as ɵSetterFn} from './reflection/types';
|
||||
export {BypassType as ɵBypassType, SafeHtml as ɵSafeHtml, SafeResourceUrl as ɵSafeResourceUrl, SafeScript as ɵSafeScript, SafeStyle as ɵSafeStyle, SafeUrl as ɵSafeUrl, SafeValue as ɵSafeValue, allowSanitizationBypassAndThrow as ɵallowSanitizationBypassAndThrow, getSanitizationBypassType as ɵgetSanitizationBypassType, unwrapSafeValue as ɵunwrapSafeValue} from './sanitization/bypass';
|
||||
export {allowSanitizationBypassAndThrow as ɵallowSanitizationBypassAndThrow, BypassType as ɵBypassType, getSanitizationBypassType as ɵgetSanitizationBypassType, SafeHtml as ɵSafeHtml, SafeResourceUrl as ɵSafeResourceUrl, SafeScript as ɵSafeScript, SafeStyle as ɵSafeStyle, SafeUrl as ɵSafeUrl, SafeValue as ɵSafeValue, unwrapSafeValue as ɵunwrapSafeValue} from './sanitization/bypass';
|
||||
export {_sanitizeHtml as ɵ_sanitizeHtml} from './sanitization/html_sanitizer';
|
||||
export {_sanitizeStyle as ɵ_sanitizeStyle} from './sanitization/style_sanitizer';
|
||||
export {_sanitizeUrl as ɵ_sanitizeUrl} from './sanitization/url_sanitizer';
|
||||
|
@ -7,7 +7,101 @@
|
||||
*/
|
||||
|
||||
// clang-format off
|
||||
// we reexport these symbols just so that they are retained during the dead code elimination
|
||||
// performed by rollup while it's creating fesm files.
|
||||
//
|
||||
// no code actually imports these symbols from the @angular/core entry point
|
||||
export {
|
||||
compileNgModuleFactory__POST_R3__ as ɵcompileNgModuleFactory__POST_R3__,
|
||||
isBoundToModule__POST_R3__ as ɵisBoundToModule__POST_R3__
|
||||
} from './application_ref';
|
||||
export {
|
||||
SWITCH_CHANGE_DETECTOR_REF_FACTORY__POST_R3__ as ɵSWITCH_CHANGE_DETECTOR_REF_FACTORY__POST_R3__,
|
||||
} from './change_detection/change_detector_ref';
|
||||
export {
|
||||
getDebugNode__POST_R3__ as ɵgetDebugNode__POST_R3__,
|
||||
} from './debug/debug_node';
|
||||
export {
|
||||
SWITCH_COMPILE_INJECTABLE__POST_R3__ as ɵSWITCH_COMPILE_INJECTABLE__POST_R3__,
|
||||
} from './di/injectable';
|
||||
export {INJECTOR_IMPL__POST_R3__ as ɵINJECTOR_IMPL__POST_R3__} from './di/injector';
|
||||
export {
|
||||
NG_INJ_DEF as ɵNG_INJ_DEF,
|
||||
NG_PROV_DEF as ɵNG_PROV_DEF,
|
||||
} from './di/interface/defs';
|
||||
export {createInjector as ɵcreateInjector} from './di/r3_injector';
|
||||
export {
|
||||
SWITCH_IVY_ENABLED__POST_R3__ as ɵSWITCH_IVY_ENABLED__POST_R3__,
|
||||
} from './ivy_switch';
|
||||
export {
|
||||
Compiler_compileModuleAndAllComponentsAsync__POST_R3__ as ɵCompiler_compileModuleAndAllComponentsAsync__POST_R3__,
|
||||
Compiler_compileModuleAndAllComponentsSync__POST_R3__ as ɵCompiler_compileModuleAndAllComponentsSync__POST_R3__,
|
||||
Compiler_compileModuleAsync__POST_R3__ as ɵCompiler_compileModuleAsync__POST_R3__,
|
||||
Compiler_compileModuleSync__POST_R3__ as ɵCompiler_compileModuleSync__POST_R3__,
|
||||
} from './linker/compiler';
|
||||
export {
|
||||
SWITCH_ELEMENT_REF_FACTORY__POST_R3__ as ɵSWITCH_ELEMENT_REF_FACTORY__POST_R3__,
|
||||
} from './linker/element_ref';
|
||||
export { getModuleFactory__POST_R3__ as ɵgetModuleFactory__POST_R3__ } from './linker/ng_module_factory_loader';
|
||||
export { registerNgModuleType as ɵregisterNgModuleType } from './linker/ng_module_factory_registration';
|
||||
export {
|
||||
SWITCH_TEMPLATE_REF_FACTORY__POST_R3__ as ɵSWITCH_TEMPLATE_REF_FACTORY__POST_R3__,
|
||||
} from './linker/template_ref';
|
||||
export {
|
||||
SWITCH_VIEW_CONTAINER_REF_FACTORY__POST_R3__ as ɵSWITCH_VIEW_CONTAINER_REF_FACTORY__POST_R3__,
|
||||
} from './linker/view_container_ref';
|
||||
export {
|
||||
SWITCH_COMPILE_COMPONENT__POST_R3__ as ɵSWITCH_COMPILE_COMPONENT__POST_R3__,
|
||||
SWITCH_COMPILE_DIRECTIVE__POST_R3__ as ɵSWITCH_COMPILE_DIRECTIVE__POST_R3__,
|
||||
SWITCH_COMPILE_PIPE__POST_R3__ as ɵSWITCH_COMPILE_PIPE__POST_R3__,
|
||||
} from './metadata/directives';
|
||||
export {
|
||||
NgModuleDef as ɵNgModuleDef,
|
||||
NgModuleTransitiveScopes as ɵNgModuleTransitiveScopes,
|
||||
ɵɵNgModuleDefWithMeta,
|
||||
} from './metadata/ng_module';
|
||||
export {
|
||||
SWITCH_COMPILE_NGMODULE__POST_R3__ as ɵSWITCH_COMPILE_NGMODULE__POST_R3__,
|
||||
} from './metadata/ng_module';
|
||||
export {
|
||||
SWITCH_RENDERER2_FACTORY__POST_R3__ as ɵSWITCH_RENDERER2_FACTORY__POST_R3__,
|
||||
} from './render/api';
|
||||
export {
|
||||
getLContext as ɵgetLContext
|
||||
} from './render3/context_discovery';
|
||||
export {
|
||||
NG_COMP_DEF as ɵNG_COMP_DEF,
|
||||
NG_DIR_DEF as ɵNG_DIR_DEF,
|
||||
NG_ELEMENT_ID as ɵNG_ELEMENT_ID,
|
||||
NG_MOD_DEF as ɵNG_MOD_DEF,
|
||||
NG_PIPE_DEF as ɵNG_PIPE_DEF,
|
||||
} from './render3/fields';
|
||||
export {
|
||||
AttributeMarker as ɵAttributeMarker,
|
||||
ComponentDef as ɵComponentDef,
|
||||
ComponentFactory as ɵRender3ComponentFactory,
|
||||
ComponentRef as ɵRender3ComponentRef,
|
||||
ComponentType as ɵComponentType,
|
||||
CssSelectorList as ɵCssSelectorList,
|
||||
detectChanges as ɵdetectChanges,
|
||||
DirectiveDef as ɵDirectiveDef,
|
||||
DirectiveType as ɵDirectiveType,
|
||||
getDirectives as ɵgetDirectives,
|
||||
getHostElement as ɵgetHostElement,
|
||||
LifecycleHooksFeature as ɵLifecycleHooksFeature,
|
||||
markDirty as ɵmarkDirty,
|
||||
NgModuleFactory as ɵNgModuleFactory,
|
||||
NgModuleRef as ɵRender3NgModuleRef,
|
||||
NgModuleType as ɵNgModuleType,
|
||||
NO_CHANGE as ɵNO_CHANGE,
|
||||
PipeDef as ɵPipeDef,
|
||||
renderComponent as ɵrenderComponent,
|
||||
RenderFlags as ɵRenderFlags,
|
||||
setClassMetadata as ɵsetClassMetadata,
|
||||
setLocaleId as ɵsetLocaleId,
|
||||
store as ɵstore,
|
||||
whenRendered as ɵwhenRendered,
|
||||
ɵɵadvance,
|
||||
ɵɵattribute,
|
||||
ɵɵattributeInterpolate1,
|
||||
ɵɵattributeInterpolate2,
|
||||
@ -18,88 +112,72 @@ export {
|
||||
ɵɵattributeInterpolate7,
|
||||
ɵɵattributeInterpolate8,
|
||||
ɵɵattributeInterpolateV,
|
||||
ɵɵclassMap,
|
||||
ɵɵclassMapInterpolate1,
|
||||
ɵɵclassMapInterpolate2,
|
||||
ɵɵclassMapInterpolate3,
|
||||
ɵɵclassMapInterpolate4,
|
||||
ɵɵclassMapInterpolate5,
|
||||
ɵɵclassMapInterpolate6,
|
||||
ɵɵclassMapInterpolate7,
|
||||
ɵɵclassMapInterpolate8,
|
||||
ɵɵclassMapInterpolateV,
|
||||
ɵɵclassProp,
|
||||
ɵɵComponentDefWithMeta,
|
||||
ɵɵcomponentHostSyntheticListener,
|
||||
ɵɵcontainer,
|
||||
ɵɵcontainerRefreshEnd,
|
||||
ɵɵcontainerRefreshStart,
|
||||
ɵɵcontentQuery,
|
||||
ɵɵCopyDefinitionFeature,
|
||||
ɵɵdefineComponent,
|
||||
ɵɵdefineDirective,
|
||||
ɵɵdefinePipe,
|
||||
ɵɵdefineNgModule,
|
||||
detectChanges as ɵdetectChanges,
|
||||
renderComponent as ɵrenderComponent,
|
||||
AttributeMarker as ɵAttributeMarker,
|
||||
ComponentType as ɵComponentType,
|
||||
ComponentFactory as ɵRender3ComponentFactory,
|
||||
ComponentRef as ɵRender3ComponentRef,
|
||||
DirectiveType as ɵDirectiveType,
|
||||
RenderFlags as ɵRenderFlags,
|
||||
ɵɵdefinePipe,
|
||||
ɵɵDirectiveDefWithMeta,
|
||||
ɵɵdirectiveInject,
|
||||
ɵɵdisableBindings,
|
||||
ɵɵelement,
|
||||
ɵɵelementContainer,
|
||||
ɵɵelementContainerEnd,
|
||||
ɵɵelementContainerStart,
|
||||
ɵɵelementEnd,
|
||||
ɵɵelementStart,
|
||||
ɵɵembeddedViewEnd,
|
||||
ɵɵembeddedViewStart,
|
||||
ɵɵenableBindings,
|
||||
ɵɵFactoryDef,
|
||||
ɵɵgetCurrentView,
|
||||
ɵɵgetFactoryOf,
|
||||
ɵɵgetInheritedFactory,
|
||||
ɵɵhostProperty,
|
||||
ɵɵi18n,
|
||||
ɵɵi18nApply,
|
||||
ɵɵi18nAttributes,
|
||||
ɵɵi18nEnd,
|
||||
ɵɵi18nExp,
|
||||
ɵɵi18nPostprocess,
|
||||
ɵɵi18nStart,
|
||||
ɵɵInheritDefinitionFeature,
|
||||
ɵɵinjectAttribute,
|
||||
ɵɵinjectPipeChangeDetectorRef,
|
||||
ɵɵinvalidFactory,
|
||||
ɵɵgetFactoryOf,
|
||||
ɵɵgetInheritedFactory,
|
||||
ɵɵsetComponentScope,
|
||||
ɵɵsetNgModuleScope,
|
||||
ɵɵtemplateRefExtractor,
|
||||
ɵɵProvidersFeature,
|
||||
ɵɵCopyDefinitionFeature,
|
||||
ɵɵInheritDefinitionFeature,
|
||||
ɵɵNgOnChangesFeature,
|
||||
LifecycleHooksFeature as ɵLifecycleHooksFeature,
|
||||
NgModuleType as ɵNgModuleType,
|
||||
NgModuleRef as ɵRender3NgModuleRef,
|
||||
CssSelectorList as ɵCssSelectorList,
|
||||
markDirty as ɵmarkDirty,
|
||||
NgModuleFactory as ɵNgModuleFactory,
|
||||
NO_CHANGE as ɵNO_CHANGE,
|
||||
ɵɵcontainer,
|
||||
ɵɵnextContext,
|
||||
ɵɵelementStart,
|
||||
ɵɵlistener,
|
||||
ɵɵloadQuery,
|
||||
ɵɵnamespaceHTML,
|
||||
ɵɵnamespaceMathML,
|
||||
ɵɵnamespaceSVG,
|
||||
ɵɵelement,
|
||||
ɵɵlistener,
|
||||
ɵɵtext,
|
||||
ɵɵtextInterpolate,
|
||||
ɵɵtextInterpolate1,
|
||||
ɵɵtextInterpolate2,
|
||||
ɵɵtextInterpolate3,
|
||||
ɵɵtextInterpolate4,
|
||||
ɵɵtextInterpolate5,
|
||||
ɵɵtextInterpolate6,
|
||||
ɵɵtextInterpolate7,
|
||||
ɵɵtextInterpolate8,
|
||||
ɵɵtextInterpolateV,
|
||||
ɵɵembeddedViewStart,
|
||||
ɵɵprojection,
|
||||
ɵɵnextContext,
|
||||
ɵɵNgOnChangesFeature,
|
||||
ɵɵpipe,
|
||||
ɵɵpipeBind1,
|
||||
ɵɵpipeBind2,
|
||||
ɵɵpipeBind3,
|
||||
ɵɵpipeBind4,
|
||||
ɵɵpipeBindV,
|
||||
ɵɵpureFunction0,
|
||||
ɵɵpureFunction1,
|
||||
ɵɵpureFunction2,
|
||||
ɵɵpureFunction3,
|
||||
ɵɵpureFunction4,
|
||||
ɵɵpureFunction5,
|
||||
ɵɵpureFunction6,
|
||||
ɵɵpureFunction7,
|
||||
ɵɵpureFunction8,
|
||||
ɵɵpureFunctionV,
|
||||
ɵɵgetCurrentView,
|
||||
getDirectives as ɵgetDirectives,
|
||||
getHostElement as ɵgetHostElement,
|
||||
ɵɵrestoreView,
|
||||
ɵɵcontainerRefreshStart,
|
||||
ɵɵcontainerRefreshEnd,
|
||||
ɵɵqueryRefresh,
|
||||
ɵɵviewQuery,
|
||||
ɵɵstaticViewQuery,
|
||||
ɵɵstaticContentQuery,
|
||||
ɵɵcontentQuery,
|
||||
ɵɵloadQuery,
|
||||
ɵɵelementEnd,
|
||||
ɵɵhostProperty,
|
||||
ɵɵPipeDefWithMeta,
|
||||
ɵɵprojection,
|
||||
ɵɵprojectionDef,
|
||||
ɵɵproperty,
|
||||
ɵɵpropertyInterpolate,
|
||||
ɵɵpropertyInterpolate1,
|
||||
@ -111,15 +189,29 @@ export {
|
||||
ɵɵpropertyInterpolate7,
|
||||
ɵɵpropertyInterpolate8,
|
||||
ɵɵpropertyInterpolateV,
|
||||
ɵɵupdateSyntheticHostBinding,
|
||||
ɵɵcomponentHostSyntheticListener,
|
||||
ɵɵprojectionDef,
|
||||
ɵɵProvidersFeature,
|
||||
ɵɵpureFunction0,
|
||||
ɵɵpureFunction1,
|
||||
ɵɵpureFunction2,
|
||||
ɵɵpureFunction3,
|
||||
ɵɵpureFunction4,
|
||||
ɵɵpureFunction5,
|
||||
ɵɵpureFunction6,
|
||||
ɵɵpureFunction7,
|
||||
ɵɵpureFunction8,
|
||||
ɵɵpureFunctionV,
|
||||
ɵɵqueryRefresh,
|
||||
ɵɵreference,
|
||||
ɵɵenableBindings,
|
||||
ɵɵdisableBindings,
|
||||
ɵɵelementContainerStart,
|
||||
ɵɵelementContainerEnd,
|
||||
ɵɵelementContainer,
|
||||
ɵɵresolveBody,
|
||||
ɵɵresolveDocument,
|
||||
ɵɵresolveWindow,
|
||||
ɵɵrestoreView,
|
||||
|
||||
ɵɵselect,
|
||||
ɵɵsetComponentScope,
|
||||
ɵɵsetNgModuleScope,
|
||||
ɵɵstaticContentQuery,
|
||||
ɵɵstaticViewQuery,
|
||||
ɵɵstyleMap,
|
||||
ɵɵstyleMapInterpolate1,
|
||||
ɵɵstyleMapInterpolate2,
|
||||
@ -130,17 +222,6 @@ export {
|
||||
ɵɵstyleMapInterpolate7,
|
||||
ɵɵstyleMapInterpolate8,
|
||||
ɵɵstyleMapInterpolateV,
|
||||
ɵɵstyleSanitizer,
|
||||
ɵɵclassMap,
|
||||
ɵɵclassMapInterpolate1,
|
||||
ɵɵclassMapInterpolate2,
|
||||
ɵɵclassMapInterpolate3,
|
||||
ɵɵclassMapInterpolate4,
|
||||
ɵɵclassMapInterpolate5,
|
||||
ɵɵclassMapInterpolate6,
|
||||
ɵɵclassMapInterpolate7,
|
||||
ɵɵclassMapInterpolate8,
|
||||
ɵɵclassMapInterpolateV,
|
||||
ɵɵstyleProp,
|
||||
ɵɵstylePropInterpolate1,
|
||||
ɵɵstylePropInterpolate2,
|
||||
@ -151,170 +232,72 @@ export {
|
||||
ɵɵstylePropInterpolate7,
|
||||
ɵɵstylePropInterpolate8,
|
||||
ɵɵstylePropInterpolateV,
|
||||
ɵɵclassProp,
|
||||
|
||||
ɵɵselect,
|
||||
ɵɵadvance,
|
||||
ɵɵstyleSanitizer,
|
||||
ɵɵtemplate,
|
||||
ɵɵembeddedViewEnd,
|
||||
store as ɵstore,
|
||||
ɵɵpipe,
|
||||
ComponentDef as ɵComponentDef,
|
||||
ɵɵComponentDefWithMeta,
|
||||
ɵɵFactoryDef,
|
||||
DirectiveDef as ɵDirectiveDef,
|
||||
ɵɵDirectiveDefWithMeta,
|
||||
PipeDef as ɵPipeDef,
|
||||
ɵɵPipeDefWithMeta,
|
||||
whenRendered as ɵwhenRendered,
|
||||
ɵɵi18n,
|
||||
ɵɵi18nAttributes,
|
||||
ɵɵi18nExp,
|
||||
ɵɵi18nStart,
|
||||
ɵɵi18nEnd,
|
||||
ɵɵi18nApply,
|
||||
ɵɵi18nPostprocess,
|
||||
setLocaleId as ɵsetLocaleId,
|
||||
setClassMetadata as ɵsetClassMetadata,
|
||||
ɵɵresolveWindow,
|
||||
ɵɵresolveDocument,
|
||||
ɵɵresolveBody,
|
||||
ɵɵtemplateRefExtractor,
|
||||
ɵɵtext,
|
||||
ɵɵtextInterpolate,
|
||||
ɵɵtextInterpolate1,
|
||||
ɵɵtextInterpolate2,
|
||||
ɵɵtextInterpolate3,
|
||||
ɵɵtextInterpolate4,
|
||||
ɵɵtextInterpolate5,
|
||||
ɵɵtextInterpolate6,
|
||||
ɵɵtextInterpolate7,
|
||||
ɵɵtextInterpolate8,
|
||||
ɵɵtextInterpolateV,
|
||||
ɵɵupdateSyntheticHostBinding,
|
||||
ɵɵviewQuery,
|
||||
} from './render3/index';
|
||||
|
||||
|
||||
export {
|
||||
LContext as ɵLContext,
|
||||
} from './render3/interfaces/context';
|
||||
export {
|
||||
setDocument as ɵsetDocument
|
||||
} from './render3/interfaces/document';
|
||||
export {
|
||||
Player as ɵPlayer,
|
||||
PlayerFactory as ɵPlayerFactory,
|
||||
PlayerHandler as ɵPlayerHandler,
|
||||
PlayState as ɵPlayState,
|
||||
} from './render3/interfaces/player';
|
||||
export {
|
||||
compileComponent as ɵcompileComponent,
|
||||
compileDirective as ɵcompileDirective,
|
||||
} from './render3/jit/directive';
|
||||
export {
|
||||
resetJitOptions as ɵresetJitOptions,
|
||||
} from './render3/jit/jit_options';
|
||||
export {
|
||||
compileNgModule as ɵcompileNgModule,
|
||||
compileNgModuleDefs as ɵcompileNgModuleDefs,
|
||||
flushModuleScopingQueueAsMuchAsPossible as ɵflushModuleScopingQueueAsMuchAsPossible,
|
||||
patchComponentDefWithScope as ɵpatchComponentDefWithScope,
|
||||
resetCompiledComponents as ɵresetCompiledComponents,
|
||||
flushModuleScopingQueueAsMuchAsPossible as ɵflushModuleScopingQueueAsMuchAsPossible,
|
||||
transitiveScopesFor as ɵtransitiveScopesFor,
|
||||
} from './render3/jit/module';
|
||||
export {
|
||||
compilePipe as ɵcompilePipe,
|
||||
} from './render3/jit/pipe';
|
||||
export {
|
||||
resetJitOptions as ɵresetJitOptions,
|
||||
} from './render3/jit/jit_options';
|
||||
|
||||
publishDefaultGlobalUtils as ɵpublishDefaultGlobalUtils
|
||||
,
|
||||
publishGlobalUtil as ɵpublishGlobalUtil} from './render3/util/global_utils';
|
||||
export {
|
||||
NgModuleDef as ɵNgModuleDef,
|
||||
ɵɵNgModuleDefWithMeta,
|
||||
NgModuleTransitiveScopes as ɵNgModuleTransitiveScopes,
|
||||
} from './metadata/ng_module';
|
||||
|
||||
bypassSanitizationTrustHtml as ɵbypassSanitizationTrustHtml,
|
||||
bypassSanitizationTrustResourceUrl as ɵbypassSanitizationTrustResourceUrl,
|
||||
bypassSanitizationTrustScript as ɵbypassSanitizationTrustScript,
|
||||
bypassSanitizationTrustStyle as ɵbypassSanitizationTrustStyle,
|
||||
bypassSanitizationTrustUrl as ɵbypassSanitizationTrustUrl,
|
||||
} from './sanitization/bypass';
|
||||
export {
|
||||
ɵɵsanitizeHtml,
|
||||
ɵɵsanitizeStyle,
|
||||
ɵɵdefaultStyleSanitizer,
|
||||
ɵɵsanitizeScript,
|
||||
ɵɵsanitizeUrl,
|
||||
ɵɵsanitizeHtml,
|
||||
ɵɵsanitizeResourceUrl,
|
||||
ɵɵsanitizeScript,
|
||||
ɵɵsanitizeStyle,
|
||||
ɵɵsanitizeUrl,
|
||||
ɵɵsanitizeUrlOrResourceUrl,
|
||||
} from './sanitization/sanitization';
|
||||
|
||||
export {
|
||||
bypassSanitizationTrustHtml as ɵbypassSanitizationTrustHtml,
|
||||
bypassSanitizationTrustStyle as ɵbypassSanitizationTrustStyle,
|
||||
bypassSanitizationTrustScript as ɵbypassSanitizationTrustScript,
|
||||
bypassSanitizationTrustUrl as ɵbypassSanitizationTrustUrl,
|
||||
bypassSanitizationTrustResourceUrl as ɵbypassSanitizationTrustResourceUrl,
|
||||
} from './sanitization/bypass';
|
||||
|
||||
export {
|
||||
getLContext as ɵgetLContext
|
||||
} from './render3/context_discovery';
|
||||
|
||||
export {
|
||||
NG_ELEMENT_ID as ɵNG_ELEMENT_ID,
|
||||
NG_COMP_DEF as ɵNG_COMP_DEF,
|
||||
NG_DIR_DEF as ɵNG_DIR_DEF,
|
||||
NG_PIPE_DEF as ɵNG_PIPE_DEF,
|
||||
NG_MOD_DEF as ɵNG_MOD_DEF,
|
||||
} from './render3/fields';
|
||||
|
||||
export {
|
||||
NG_PROV_DEF as ɵNG_PROV_DEF,
|
||||
NG_INJ_DEF as ɵNG_INJ_DEF,
|
||||
} from './di/interface/defs';
|
||||
|
||||
export {
|
||||
Player as ɵPlayer,
|
||||
PlayerFactory as ɵPlayerFactory,
|
||||
PlayState as ɵPlayState,
|
||||
PlayerHandler as ɵPlayerHandler,
|
||||
} from './render3/interfaces/player';
|
||||
|
||||
export {
|
||||
LContext as ɵLContext,
|
||||
} from './render3/interfaces/context';
|
||||
|
||||
export {
|
||||
setDocument as ɵsetDocument
|
||||
} from './render3/interfaces/document';
|
||||
|
||||
// we reexport these symbols just so that they are retained during the dead code elimination
|
||||
// performed by rollup while it's creating fesm files.
|
||||
//
|
||||
// no code actually imports these symbols from the @angular/core entry point
|
||||
export {
|
||||
compileNgModuleFactory__POST_R3__ as ɵcompileNgModuleFactory__POST_R3__,
|
||||
isBoundToModule__POST_R3__ as ɵisBoundToModule__POST_R3__
|
||||
} from './application_ref';
|
||||
export {
|
||||
SWITCH_COMPILE_COMPONENT__POST_R3__ as ɵSWITCH_COMPILE_COMPONENT__POST_R3__,
|
||||
SWITCH_COMPILE_DIRECTIVE__POST_R3__ as ɵSWITCH_COMPILE_DIRECTIVE__POST_R3__,
|
||||
SWITCH_COMPILE_PIPE__POST_R3__ as ɵSWITCH_COMPILE_PIPE__POST_R3__,
|
||||
} from './metadata/directives';
|
||||
export {
|
||||
SWITCH_COMPILE_NGMODULE__POST_R3__ as ɵSWITCH_COMPILE_NGMODULE__POST_R3__,
|
||||
} from './metadata/ng_module';
|
||||
export {
|
||||
getDebugNode__POST_R3__ as ɵgetDebugNode__POST_R3__,
|
||||
} from './debug/debug_node';
|
||||
export {
|
||||
SWITCH_COMPILE_INJECTABLE__POST_R3__ as ɵSWITCH_COMPILE_INJECTABLE__POST_R3__,
|
||||
} from './di/injectable';
|
||||
export {
|
||||
SWITCH_IVY_ENABLED__POST_R3__ as ɵSWITCH_IVY_ENABLED__POST_R3__,
|
||||
} from './ivy_switch';
|
||||
export {
|
||||
SWITCH_CHANGE_DETECTOR_REF_FACTORY__POST_R3__ as ɵSWITCH_CHANGE_DETECTOR_REF_FACTORY__POST_R3__,
|
||||
} from './change_detection/change_detector_ref';
|
||||
export {
|
||||
Compiler_compileModuleSync__POST_R3__ as ɵCompiler_compileModuleSync__POST_R3__,
|
||||
Compiler_compileModuleAsync__POST_R3__ as ɵCompiler_compileModuleAsync__POST_R3__,
|
||||
Compiler_compileModuleAndAllComponentsSync__POST_R3__ as ɵCompiler_compileModuleAndAllComponentsSync__POST_R3__,
|
||||
Compiler_compileModuleAndAllComponentsAsync__POST_R3__ as ɵCompiler_compileModuleAndAllComponentsAsync__POST_R3__,
|
||||
} from './linker/compiler';
|
||||
export {
|
||||
SWITCH_ELEMENT_REF_FACTORY__POST_R3__ as ɵSWITCH_ELEMENT_REF_FACTORY__POST_R3__,
|
||||
} from './linker/element_ref';
|
||||
export {
|
||||
SWITCH_TEMPLATE_REF_FACTORY__POST_R3__ as ɵSWITCH_TEMPLATE_REF_FACTORY__POST_R3__,
|
||||
} from './linker/template_ref';
|
||||
export {
|
||||
SWITCH_VIEW_CONTAINER_REF_FACTORY__POST_R3__ as ɵSWITCH_VIEW_CONTAINER_REF_FACTORY__POST_R3__,
|
||||
} from './linker/view_container_ref';
|
||||
export {
|
||||
SWITCH_RENDERER2_FACTORY__POST_R3__ as ɵSWITCH_RENDERER2_FACTORY__POST_R3__,
|
||||
} from './render/api';
|
||||
|
||||
export { getModuleFactory__POST_R3__ as ɵgetModuleFactory__POST_R3__ } from './linker/ng_module_factory_loader';
|
||||
|
||||
export { registerNgModuleType as ɵregisterNgModuleType } from './linker/ng_module_factory_registration';
|
||||
|
||||
export {
|
||||
publishGlobalUtil as ɵpublishGlobalUtil,
|
||||
publishDefaultGlobalUtils as ɵpublishDefaultGlobalUtils
|
||||
} from './render3/util/global_utils';
|
||||
|
||||
export {createInjector as ɵcreateInjector} from './di/r3_injector';
|
||||
|
||||
export {INJECTOR_IMPL__POST_R3__ as ɵINJECTOR_IMPL__POST_R3__} from './di/injector';
|
||||
|
||||
// clang-format on
|
||||
|
@ -10,7 +10,7 @@ import {Injector} from '../di';
|
||||
import {CONTAINER_HEADER_OFFSET, LContainer, NATIVE} from '../render3/interfaces/container';
|
||||
import {TElementNode, TNode, TNodeFlags, TNodeType} from '../render3/interfaces/node';
|
||||
import {isComponentHost, isLContainer} from '../render3/interfaces/type_checks';
|
||||
import {DECLARATION_COMPONENT_VIEW, LView, PARENT, TData, TVIEW, T_HOST} from '../render3/interfaces/view';
|
||||
import {DECLARATION_COMPONENT_VIEW, LView, PARENT, T_HOST, TData, TVIEW} from '../render3/interfaces/view';
|
||||
import {getComponent, getContext, getInjectionTokens, getInjector, getListeners, getLocalRefs, getOwningComponent, loadLContext} from '../render3/util/discovery_utils';
|
||||
import {INTERPOLATION_DELIMITER, renderStringify} from '../render3/util/misc_utils';
|
||||
import {getComponentLViewByIndex, getNativeByTNodeOrNull} from '../render3/util/view_utils';
|
||||
@ -53,15 +53,25 @@ export class DebugNode__PRE_R3__ {
|
||||
}
|
||||
}
|
||||
|
||||
get injector(): Injector { return this._debugContext.injector; }
|
||||
get injector(): Injector {
|
||||
return this._debugContext.injector;
|
||||
}
|
||||
|
||||
get componentInstance(): any { return this._debugContext.component; }
|
||||
get componentInstance(): any {
|
||||
return this._debugContext.component;
|
||||
}
|
||||
|
||||
get context(): any { return this._debugContext.context; }
|
||||
get context(): any {
|
||||
return this._debugContext.context;
|
||||
}
|
||||
|
||||
get references(): {[key: string]: any} { return this._debugContext.references; }
|
||||
get references(): {[key: string]: any} {
|
||||
return this._debugContext.references;
|
||||
}
|
||||
|
||||
get providerTokens(): any[] { return this._debugContext.providerTokens; }
|
||||
get providerTokens(): any[] {
|
||||
return this._debugContext.providerTokens;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,9 +80,9 @@ export class DebugNode__PRE_R3__ {
|
||||
export interface DebugElement extends DebugNode {
|
||||
readonly name: string;
|
||||
readonly properties: {[key: string]: any};
|
||||
readonly attributes: {[key: string]: string | null};
|
||||
readonly attributes: {[key: string]: string|null};
|
||||
readonly classes: {[key: string]: boolean};
|
||||
readonly styles: {[key: string]: string | null};
|
||||
readonly styles: {[key: string]: string|null};
|
||||
readonly childNodes: DebugNode[];
|
||||
readonly nativeElement: any;
|
||||
readonly children: DebugElement[];
|
||||
@ -83,11 +93,11 @@ export interface DebugElement extends DebugNode {
|
||||
triggerEventHandler(eventName: string, eventObj: any): void;
|
||||
}
|
||||
export class DebugElement__PRE_R3__ extends DebugNode__PRE_R3__ implements DebugElement {
|
||||
readonly name !: string;
|
||||
readonly name!: string;
|
||||
readonly properties: {[key: string]: any} = {};
|
||||
readonly attributes: {[key: string]: string | null} = {};
|
||||
readonly attributes: {[key: string]: string|null} = {};
|
||||
readonly classes: {[key: string]: boolean} = {};
|
||||
readonly styles: {[key: string]: string | null} = {};
|
||||
readonly styles: {[key: string]: string|null} = {};
|
||||
readonly childNodes: DebugNode[] = [];
|
||||
readonly nativeElement: any;
|
||||
|
||||
@ -99,14 +109,14 @@ export class DebugElement__PRE_R3__ extends DebugNode__PRE_R3__ implements Debug
|
||||
addChild(child: DebugNode) {
|
||||
if (child) {
|
||||
this.childNodes.push(child);
|
||||
(child as{parent: DebugNode}).parent = this;
|
||||
(child as {parent: DebugNode}).parent = this;
|
||||
}
|
||||
}
|
||||
|
||||
removeChild(child: DebugNode) {
|
||||
const childIndex = this.childNodes.indexOf(child);
|
||||
if (childIndex !== -1) {
|
||||
(child as{parent: DebugNode | null}).parent = null;
|
||||
(child as {parent: DebugNode | null}).parent = null;
|
||||
this.childNodes.splice(childIndex, 1);
|
||||
}
|
||||
}
|
||||
@ -119,7 +129,7 @@ export class DebugElement__PRE_R3__ extends DebugNode__PRE_R3__ implements Debug
|
||||
if (c.parent) {
|
||||
(c.parent as DebugElement__PRE_R3__).removeChild(c);
|
||||
}
|
||||
(child as{parent: DebugNode}).parent = this;
|
||||
(child as {parent: DebugNode}).parent = this;
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -132,7 +142,7 @@ export class DebugElement__PRE_R3__ extends DebugNode__PRE_R3__ implements Debug
|
||||
if (newChild.parent) {
|
||||
(newChild.parent as DebugElement__PRE_R3__).removeChild(newChild);
|
||||
}
|
||||
(newChild as{parent: DebugNode}).parent = this;
|
||||
(newChild as {parent: DebugNode}).parent = this;
|
||||
this.childNodes.splice(refIndex, 0, newChild);
|
||||
}
|
||||
}
|
||||
@ -155,9 +165,8 @@ export class DebugElement__PRE_R3__ extends DebugNode__PRE_R3__ implements Debug
|
||||
}
|
||||
|
||||
get children(): DebugElement[] {
|
||||
return this
|
||||
.childNodes //
|
||||
.filter((node) => node instanceof DebugElement__PRE_R3__) as DebugElement[];
|
||||
return this.childNodes //
|
||||
.filter((node) => node instanceof DebugElement__PRE_R3__) as DebugElement[];
|
||||
}
|
||||
|
||||
triggerEventHandler(eventName: string, eventObj: any) {
|
||||
@ -205,14 +214,18 @@ function _queryNodeChildren(
|
||||
class DebugNode__POST_R3__ implements DebugNode {
|
||||
readonly nativeNode: Node;
|
||||
|
||||
constructor(nativeNode: Node) { this.nativeNode = nativeNode; }
|
||||
constructor(nativeNode: Node) {
|
||||
this.nativeNode = nativeNode;
|
||||
}
|
||||
|
||||
get parent(): DebugElement|null {
|
||||
const parent = this.nativeNode.parentNode as Element;
|
||||
return parent ? new DebugElement__POST_R3__(parent) : null;
|
||||
}
|
||||
|
||||
get injector(): Injector { return getInjector(this.nativeNode); }
|
||||
get injector(): Injector {
|
||||
return getInjector(this.nativeNode);
|
||||
}
|
||||
|
||||
get componentInstance(): any {
|
||||
const nativeElement = this.nativeNode;
|
||||
@ -227,9 +240,13 @@ class DebugNode__POST_R3__ implements DebugNode {
|
||||
return getListeners(this.nativeNode as Element).filter(listener => listener.type === 'dom');
|
||||
}
|
||||
|
||||
get references(): {[key: string]: any;} { return getLocalRefs(this.nativeNode); }
|
||||
get references(): {[key: string]: any;} {
|
||||
return getLocalRefs(this.nativeNode);
|
||||
}
|
||||
|
||||
get providerTokens(): any[] { return getInjectionTokens(this.nativeNode as Element); }
|
||||
get providerTokens(): any[] {
|
||||
return getInjectionTokens(this.nativeNode as Element);
|
||||
}
|
||||
}
|
||||
|
||||
class DebugElement__POST_R3__ extends DebugNode__POST_R3__ implements DebugElement {
|
||||
@ -244,11 +261,11 @@ class DebugElement__POST_R3__ extends DebugNode__POST_R3__ implements DebugEleme
|
||||
|
||||
get name(): string {
|
||||
try {
|
||||
const context = loadLContext(this.nativeNode) !;
|
||||
const context = loadLContext(this.nativeNode)!;
|
||||
const lView = context.lView;
|
||||
const tData = lView[TVIEW].data;
|
||||
const tNode = tData[context.nodeIndex] as TNode;
|
||||
return tNode.tagName !;
|
||||
return tNode.tagName!;
|
||||
} catch (e) {
|
||||
return this.nativeNode.nodeName;
|
||||
}
|
||||
@ -285,8 +302,8 @@ class DebugElement__POST_R3__ extends DebugNode__POST_R3__ implements DebugEleme
|
||||
return properties;
|
||||
}
|
||||
|
||||
get attributes(): {[key: string]: string | null;} {
|
||||
const attributes: {[key: string]: string | null;} = {};
|
||||
get attributes(): {[key: string]: string|null;} {
|
||||
const attributes: {[key: string]: string|null;} = {};
|
||||
const element = this.nativeElement;
|
||||
|
||||
if (!element) {
|
||||
@ -343,9 +360,9 @@ class DebugElement__POST_R3__ extends DebugNode__POST_R3__ implements DebugEleme
|
||||
return attributes;
|
||||
}
|
||||
|
||||
get styles(): {[key: string]: string | null} {
|
||||
get styles(): {[key: string]: string|null} {
|
||||
if (this.nativeElement && (this.nativeElement as HTMLElement).style) {
|
||||
return (this.nativeElement as HTMLElement).style as{[key: string]: any};
|
||||
return (this.nativeElement as HTMLElement).style as {[key: string]: any};
|
||||
}
|
||||
return {};
|
||||
}
|
||||
@ -438,7 +455,7 @@ class DebugElement__POST_R3__ extends DebugNode__POST_R3__ implements DebugEleme
|
||||
}
|
||||
}
|
||||
|
||||
function copyDomProperties(element: Element | null, properties: {[name: string]: string}): void {
|
||||
function copyDomProperties(element: Element|null, properties: {[name: string]: string}): void {
|
||||
if (element) {
|
||||
// Skip own properties (as those are patched)
|
||||
let obj = Object.getPrototypeOf(element);
|
||||
@ -481,8 +498,8 @@ function _queryAllR3(
|
||||
parentElement: DebugElement, predicate: Predicate<DebugNode>, matches: DebugNode[],
|
||||
elementsOnly: false): void;
|
||||
function _queryAllR3(
|
||||
parentElement: DebugElement, predicate: Predicate<DebugElement>| Predicate<DebugNode>,
|
||||
matches: DebugElement[] | DebugNode[], elementsOnly: boolean) {
|
||||
parentElement: DebugElement, predicate: Predicate<DebugElement>|Predicate<DebugNode>,
|
||||
matches: DebugElement[]|DebugNode[], elementsOnly: boolean) {
|
||||
const context = loadLContext(parentElement.nativeNode, false);
|
||||
if (context !== null) {
|
||||
const parentTNode = context.lView[TVIEW].data[context.nodeIndex] as TNode;
|
||||
@ -506,8 +523,8 @@ function _queryAllR3(
|
||||
* @param rootNativeNode the root native node on which predicate should not be matched
|
||||
*/
|
||||
function _queryNodeChildrenR3(
|
||||
tNode: TNode, lView: LView, predicate: Predicate<DebugElement>| Predicate<DebugNode>,
|
||||
matches: DebugElement[] | DebugNode[], elementsOnly: boolean, rootNativeNode: any) {
|
||||
tNode: TNode, lView: LView, predicate: Predicate<DebugElement>|Predicate<DebugNode>,
|
||||
matches: DebugElement[]|DebugNode[], elementsOnly: boolean, rootNativeNode: any) {
|
||||
const nativeNode = getNativeByTNodeOrNull(tNode, lView);
|
||||
// For each type of TNode, specific logic is executed.
|
||||
if (tNode.type === TNodeType.Element || tNode.type === TNodeType.ElementContainer) {
|
||||
@ -520,7 +537,7 @@ function _queryNodeChildrenR3(
|
||||
const componentView = getComponentLViewByIndex(tNode.index, lView);
|
||||
if (componentView && componentView[TVIEW].firstChild) {
|
||||
_queryNodeChildrenR3(
|
||||
componentView[TVIEW].firstChild !, componentView, predicate, matches, elementsOnly,
|
||||
componentView[TVIEW].firstChild!, componentView, predicate, matches, elementsOnly,
|
||||
rootNativeNode);
|
||||
}
|
||||
} else {
|
||||
@ -556,17 +573,17 @@ function _queryNodeChildrenR3(
|
||||
} else if (tNode.type === TNodeType.Projection) {
|
||||
// Case 3: the TNode is a projection insertion point (i.e. a <ng-content>).
|
||||
// The nodes projected at this location all need to be processed.
|
||||
const componentView = lView ![DECLARATION_COMPONENT_VIEW];
|
||||
const componentView = lView![DECLARATION_COMPONENT_VIEW];
|
||||
const componentHost = componentView[T_HOST] as TElementNode;
|
||||
const head: TNode|null =
|
||||
(componentHost.projection as(TNode | null)[])[tNode.projection as number];
|
||||
(componentHost.projection as (TNode | null)[])[tNode.projection as number];
|
||||
|
||||
if (Array.isArray(head)) {
|
||||
for (let nativeNode of head) {
|
||||
_addQueryMatchR3(nativeNode, predicate, matches, elementsOnly, rootNativeNode);
|
||||
}
|
||||
} else if (head) {
|
||||
const nextLView = componentView[PARENT] !as LView;
|
||||
const nextLView = componentView[PARENT]! as LView;
|
||||
const nextTNode = nextLView[TVIEW].data[head.index] as TNode;
|
||||
_queryNodeChildrenR3(nextTNode, nextLView, predicate, matches, elementsOnly, rootNativeNode);
|
||||
}
|
||||
@ -596,12 +613,12 @@ function _queryNodeChildrenR3(
|
||||
* @param rootNativeNode the root native node on which predicate should not be matched
|
||||
*/
|
||||
function _queryNodeChildrenInContainerR3(
|
||||
lContainer: LContainer, predicate: Predicate<DebugElement>| Predicate<DebugNode>,
|
||||
matches: DebugElement[] | DebugNode[], elementsOnly: boolean, rootNativeNode: any) {
|
||||
lContainer: LContainer, predicate: Predicate<DebugElement>|Predicate<DebugNode>,
|
||||
matches: DebugElement[]|DebugNode[], elementsOnly: boolean, rootNativeNode: any) {
|
||||
for (let i = CONTAINER_HEADER_OFFSET; i < lContainer.length; i++) {
|
||||
const childView = lContainer[i];
|
||||
_queryNodeChildrenR3(
|
||||
childView[TVIEW].node !, childView, predicate, matches, elementsOnly, rootNativeNode);
|
||||
childView[TVIEW].node!, childView, predicate, matches, elementsOnly, rootNativeNode);
|
||||
}
|
||||
}
|
||||
|
||||
@ -615,8 +632,8 @@ function _queryNodeChildrenInContainerR3(
|
||||
* @param rootNativeNode the root native node on which predicate should not be matched
|
||||
*/
|
||||
function _addQueryMatchR3(
|
||||
nativeNode: any, predicate: Predicate<DebugElement>| Predicate<DebugNode>,
|
||||
matches: DebugElement[] | DebugNode[], elementsOnly: boolean, rootNativeNode: any) {
|
||||
nativeNode: any, predicate: Predicate<DebugElement>|Predicate<DebugNode>,
|
||||
matches: DebugElement[]|DebugNode[], elementsOnly: boolean, rootNativeNode: any) {
|
||||
if (rootNativeNode !== nativeNode) {
|
||||
const debugNode = getDebugNode(nativeNode);
|
||||
if (!debugNode) {
|
||||
@ -645,8 +662,8 @@ function _addQueryMatchR3(
|
||||
* @param elementsOnly whether only elements should be searched
|
||||
*/
|
||||
function _queryNativeNodeDescendants(
|
||||
parentNode: any, predicate: Predicate<DebugElement>| Predicate<DebugNode>,
|
||||
matches: DebugElement[] | DebugNode[], elementsOnly: boolean) {
|
||||
parentNode: any, predicate: Predicate<DebugElement>|Predicate<DebugNode>,
|
||||
matches: DebugElement[]|DebugNode[], elementsOnly: boolean) {
|
||||
const nodes = parentNode.childNodes;
|
||||
const length = nodes.length;
|
||||
|
||||
@ -757,7 +774,9 @@ export function removeDebugNodeFromIndex(node: DebugNode) {
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export interface Predicate<T> { (value: T): boolean; }
|
||||
export interface Predicate<T> {
|
||||
(value: T): boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* @publicApi
|
||||
|
@ -21,7 +21,9 @@ import {stringify} from '../util/stringify';
|
||||
* {@example core/di/ts/forward_ref/forward_ref_spec.ts region='forward_ref_fn'}
|
||||
* @publicApi
|
||||
*/
|
||||
export interface ForwardRefFn { (): any; }
|
||||
export interface ForwardRefFn {
|
||||
(): any;
|
||||
}
|
||||
|
||||
const __forward_ref__ = getClosureSafeProperty({__forward_ref__: getClosureSafeProperty});
|
||||
|
||||
@ -39,7 +41,9 @@ const __forward_ref__ = getClosureSafeProperty({__forward_ref__: getClosureSafeP
|
||||
*/
|
||||
export function forwardRef(forwardRefFn: ForwardRefFn): Type<any> {
|
||||
(<any>forwardRefFn).__forward_ref__ = forwardRef;
|
||||
(<any>forwardRefFn).toString = function() { return stringify(this()); };
|
||||
(<any>forwardRefFn).toString = function() {
|
||||
return stringify(this());
|
||||
};
|
||||
return (<Type<any>><any>forwardRefFn);
|
||||
}
|
||||
|
||||
|
@ -7,9 +7,9 @@
|
||||
*/
|
||||
|
||||
import {Type} from '../interface/type';
|
||||
import {TypeDecorator, makeDecorator} from '../util/decorators';
|
||||
import {makeDecorator, TypeDecorator} from '../util/decorators';
|
||||
|
||||
import {InjectableType, getInjectableDef, ɵɵdefineInjectable} from './interface/defs';
|
||||
import {getInjectableDef, InjectableType, ɵɵdefineInjectable} from './interface/defs';
|
||||
import {ClassSansProvider, ConstructorSansProvider, ExistingSansProvider, FactorySansProvider, StaticClassSansProvider, ValueSansProvider} from './interface/provider';
|
||||
import {compileInjectable as render3CompileInjectable} from './jit/injectable';
|
||||
import {convertInjectableProviderToFactory} from './util';
|
||||
@ -21,8 +21,8 @@ import {convertInjectableProviderToFactory} from './util';
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export type InjectableProvider = ValueSansProvider | ExistingSansProvider |
|
||||
StaticClassSansProvider | ConstructorSansProvider | FactorySansProvider | ClassSansProvider;
|
||||
export type InjectableProvider = ValueSansProvider|ExistingSansProvider|StaticClassSansProvider|
|
||||
ConstructorSansProvider|FactorySansProvider|ClassSansProvider;
|
||||
|
||||
/**
|
||||
* Type of the Injectable decorator / constructor function.
|
||||
@ -50,11 +50,11 @@ export interface InjectableDecorator {
|
||||
*
|
||||
*/
|
||||
(): TypeDecorator;
|
||||
(options?: {providedIn: Type<any>| 'root' | 'platform' | 'any' | null}&
|
||||
(options?: {providedIn: Type<any>|'root'|'platform'|'any'|null}&
|
||||
InjectableProvider): TypeDecorator;
|
||||
new (): Injectable;
|
||||
new (options?: {providedIn: Type<any>| 'root' | 'platform' | 'any' | null}&
|
||||
InjectableProvider): Injectable;
|
||||
new(): Injectable;
|
||||
new(options?: {providedIn: Type<any>|'root'|'platform'|'any'|null}&
|
||||
InjectableProvider): Injectable;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,9 +91,9 @@ export const Injectable: InjectableDecorator = makeDecorator(
|
||||
/**
|
||||
* Supports @Injectable() in JIT mode for Render2.
|
||||
*/
|
||||
function render2CompileInjectable(injectableType: Type<any>, options?: {
|
||||
providedIn?: Type<any>| 'root' | 'platform' | 'any' | null
|
||||
} & InjectableProvider): void {
|
||||
function render2CompileInjectable(
|
||||
injectableType: Type<any>,
|
||||
options?: {providedIn?: Type<any>|'root'|'platform'|'any'|null}&InjectableProvider): void {
|
||||
if (options && options.providedIn !== undefined && !getInjectableDef(injectableType)) {
|
||||
(injectableType as InjectableType<any>).ɵprov = ɵɵdefineInjectable({
|
||||
token: injectableType,
|
||||
|
@ -57,8 +57,7 @@ export class InjectionToken<T> {
|
||||
readonly ɵprov: never|undefined;
|
||||
|
||||
constructor(protected _desc: string, options?: {
|
||||
providedIn?: Type<any>| 'root' | 'platform' | 'any' | null,
|
||||
factory: () => T
|
||||
providedIn?: Type<any>|'root'|'platform'|'any'|null, factory: () => T
|
||||
}) {
|
||||
this.ɵprov = undefined;
|
||||
if (typeof options == 'number') {
|
||||
@ -75,7 +74,11 @@ export class InjectionToken<T> {
|
||||
}
|
||||
}
|
||||
|
||||
toString(): string { return `InjectionToken ${this._desc}`; }
|
||||
toString(): string {
|
||||
return `InjectionToken ${this._desc}`;
|
||||
}
|
||||
}
|
||||
|
||||
export interface InjectableDefToken<T> extends InjectionToken<T> { ɵprov: never; }
|
||||
export interface InjectableDefToken<T> extends InjectionToken<T> {
|
||||
ɵprov: never;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import {stringify} from '../util/stringify';
|
||||
|
||||
import {resolveForwardRef} from './forward_ref';
|
||||
import {InjectionToken} from './injection_token';
|
||||
import {INJECTOR, NG_TEMP_TOKEN_PATH, NullInjector, THROW_IF_NOT_FOUND, USE_VALUE, catchInjectorError, formatError, setCurrentInjector, ɵɵinject} from './injector_compatibility';
|
||||
import {catchInjectorError, formatError, INJECTOR, NG_TEMP_TOKEN_PATH, NullInjector, setCurrentInjector, THROW_IF_NOT_FOUND, USE_VALUE, ɵɵinject} from './injector_compatibility';
|
||||
import {getInjectableDef, ɵɵdefineInjectable} from './interface/defs';
|
||||
import {InjectFlags} from './interface/injector';
|
||||
import {ConstructorProvider, ExistingProvider, FactoryProvider, StaticClassProvider, StaticProvider, ValueProvider} from './interface/provider';
|
||||
@ -20,12 +20,12 @@ import {createInjector} from './r3_injector';
|
||||
import {INJECTOR_SCOPE} from './scope';
|
||||
|
||||
export function INJECTOR_IMPL__PRE_R3__(
|
||||
providers: StaticProvider[], parent: Injector | undefined, name: string) {
|
||||
providers: StaticProvider[], parent: Injector|undefined, name: string) {
|
||||
return new StaticInjector(providers, parent, name);
|
||||
}
|
||||
|
||||
export function INJECTOR_IMPL__POST_R3__(
|
||||
providers: StaticProvider[], parent: Injector | undefined, name: string) {
|
||||
providers: StaticProvider[], parent: Injector|undefined, name: string) {
|
||||
return createInjector({name: name}, parent, providers, name);
|
||||
}
|
||||
|
||||
@ -166,8 +166,9 @@ export class StaticInjector implements Injector {
|
||||
const providedIn = injectableDef && injectableDef.providedIn;
|
||||
if (providedIn === 'any' || providedIn != null && providedIn === this.scope) {
|
||||
records.set(
|
||||
token, record = resolveProvider(
|
||||
{provide: token, useFactory: injectableDef.factory, deps: EMPTY}));
|
||||
token,
|
||||
record = resolveProvider(
|
||||
{provide: token, useFactory: injectableDef.factory, deps: EMPTY}));
|
||||
}
|
||||
}
|
||||
if (record === undefined) {
|
||||
@ -193,7 +194,7 @@ export class StaticInjector implements Injector {
|
||||
}
|
||||
|
||||
type SupportedProvider =
|
||||
ValueProvider | ExistingProvider | StaticClassProvider | ConstructorProvider | FactoryProvider;
|
||||
ValueProvider|ExistingProvider|StaticClassProvider|ConstructorProvider|FactoryProvider;
|
||||
|
||||
interface Record {
|
||||
fn: Function;
|
||||
@ -293,7 +294,7 @@ function recursivelyProcessProviders(records: Map<any, Record>, provider: Static
|
||||
}
|
||||
|
||||
function tryResolveToken(
|
||||
token: any, record: Record | undefined | null, records: Map<any, Record|null>, parent: Injector,
|
||||
token: any, record: Record|undefined|null, records: Map<any, Record|null>, parent: Injector,
|
||||
notFoundValue: any, flags: InjectFlags): any {
|
||||
try {
|
||||
return resolveToken(token, record, records, parent, notFoundValue, flags);
|
||||
@ -313,7 +314,7 @@ function tryResolveToken(
|
||||
}
|
||||
|
||||
function resolveToken(
|
||||
token: any, record: Record | undefined | null, records: Map<any, Record|null>, parent: Injector,
|
||||
token: any, record: Record|undefined|null, records: Map<any, Record|null>, parent: Injector,
|
||||
notFoundValue: any, flags: InjectFlags): any {
|
||||
let value;
|
||||
if (record && !(flags & InjectFlags.SkipSelf)) {
|
||||
|
@ -33,7 +33,7 @@ import {Inject, Optional, Self, SkipSelf} from './metadata';
|
||||
export const INJECTOR = new InjectionToken<Injector>(
|
||||
'INJECTOR',
|
||||
-1 as any // `-1` is used by Ivy DI system as special value to recognize it as `Injector`.
|
||||
);
|
||||
);
|
||||
|
||||
const _THROW_IF_NOT_FOUND = {};
|
||||
export const THROW_IF_NOT_FOUND = _THROW_IF_NOT_FOUND;
|
||||
@ -55,7 +55,7 @@ export const USE_VALUE =
|
||||
*/
|
||||
let _currentInjector: Injector|undefined|null = undefined;
|
||||
|
||||
export function setCurrentInjector(injector: Injector | null | undefined): Injector|undefined|null {
|
||||
export function setCurrentInjector(injector: Injector|null|undefined): Injector|undefined|null {
|
||||
const former = _currentInjector;
|
||||
_currentInjector = injector;
|
||||
return former;
|
||||
@ -70,25 +70,25 @@ export function setCurrentInjector(injector: Injector | null | undefined): Injec
|
||||
* 1. `Injector` should not depend on ivy logic.
|
||||
* 2. To maintain tree shake-ability we don't want to bring in unnecessary code.
|
||||
*/
|
||||
let _injectImplementation:
|
||||
(<T>(token: Type<T>| InjectionToken<T>, flags?: InjectFlags) => T | null)|undefined;
|
||||
let _injectImplementation: (<T>(token: Type<T>|InjectionToken<T>, flags?: InjectFlags) => T | null)|
|
||||
undefined;
|
||||
|
||||
/**
|
||||
* Sets the current inject implementation.
|
||||
*/
|
||||
export function setInjectImplementation(
|
||||
impl: (<T>(token: Type<T>| InjectionToken<T>, flags?: InjectFlags) => T | null) | undefined):
|
||||
(<T>(token: Type<T>| InjectionToken<T>, flags?: InjectFlags) => T | null)|undefined {
|
||||
impl: (<T>(token: Type<T>|InjectionToken<T>, flags?: InjectFlags) => T | null)|
|
||||
undefined): (<T>(token: Type<T>|InjectionToken<T>, flags?: InjectFlags) => T | null)|undefined {
|
||||
const previous = _injectImplementation;
|
||||
_injectImplementation = impl;
|
||||
return previous;
|
||||
}
|
||||
|
||||
export function injectInjectorOnly<T>(token: Type<T>| InjectionToken<T>): T;
|
||||
export function injectInjectorOnly<T>(token: Type<T>| InjectionToken<T>, flags?: InjectFlags): T|
|
||||
export function injectInjectorOnly<T>(token: Type<T>|InjectionToken<T>): T;
|
||||
export function injectInjectorOnly<T>(token: Type<T>|InjectionToken<T>, flags?: InjectFlags): T|
|
||||
null;
|
||||
export function injectInjectorOnly<T>(
|
||||
token: Type<T>| InjectionToken<T>, flags = InjectFlags.Default): T|null {
|
||||
token: Type<T>|InjectionToken<T>, flags = InjectFlags.Default): T|null {
|
||||
if (_currentInjector === undefined) {
|
||||
throw new Error(`inject() must be called from an injection context`);
|
||||
} else if (_currentInjector === null) {
|
||||
@ -104,15 +104,15 @@ export function injectInjectorOnly<T>(
|
||||
* Must be used in the context of a factory function such as one defined for an
|
||||
* `InjectionToken`. Throws an error if not called from such a context.
|
||||
*
|
||||
* (Additional documentation moved to `inject`, as it is the public API, and an alias for this instruction)
|
||||
* (Additional documentation moved to `inject`, as it is the public API, and an alias for this
|
||||
* instruction)
|
||||
*
|
||||
* @see inject
|
||||
* @codeGenApi
|
||||
*/
|
||||
export function ɵɵinject<T>(token: Type<T>| InjectionToken<T>): T;
|
||||
export function ɵɵinject<T>(token: Type<T>| InjectionToken<T>, flags?: InjectFlags): T|null;
|
||||
export function ɵɵinject<T>(token: Type<T>| InjectionToken<T>, flags = InjectFlags.Default): T|
|
||||
null {
|
||||
export function ɵɵinject<T>(token: Type<T>|InjectionToken<T>): T;
|
||||
export function ɵɵinject<T>(token: Type<T>|InjectionToken<T>, flags?: InjectFlags): T|null;
|
||||
export function ɵɵinject<T>(token: Type<T>|InjectionToken<T>, flags = InjectFlags.Default): T|null {
|
||||
return (_injectImplementation || injectInjectorOnly)(resolveForwardRef(token), flags);
|
||||
}
|
||||
|
||||
@ -130,10 +130,12 @@ export function ɵɵinject<T>(token: Type<T>| InjectionToken<T>, flags = InjectF
|
||||
*/
|
||||
export function ɵɵinvalidFactoryDep(index: number): never {
|
||||
const msg = ngDevMode ?
|
||||
`This constructor is not compatible with Angular Dependency Injection because its dependency at index ${index} of the parameter list is invalid.
|
||||
`This constructor is not compatible with Angular Dependency Injection because its dependency at index ${
|
||||
index} of the parameter list is invalid.
|
||||
This can happen if the dependency type is a primitive like a string or if an ancestor of this class is missing an Angular decorator.
|
||||
|
||||
Please check that 1) the type for the parameter at index ${index} is correct and 2) the correct Angular decorators are defined for this class and its ancestors.` :
|
||||
Please check that 1) the type for the parameter at index ${
|
||||
index} is correct and 2) the correct Angular decorators are defined for this class and its ancestors.` :
|
||||
'invalid';
|
||||
throw new Error(msg);
|
||||
}
|
||||
@ -172,7 +174,7 @@ export const inject = ɵɵinject;
|
||||
* `InjectableDef`.
|
||||
*/
|
||||
export function injectRootLimpMode<T>(
|
||||
token: Type<T>| InjectionToken<T>, notFoundValue: T | undefined, flags: InjectFlags): T|null {
|
||||
token: Type<T>|InjectionToken<T>, notFoundValue: T|undefined, flags: InjectFlags): T|null {
|
||||
const injectableDef: ɵɵInjectableDef<T>|null = getInjectableDef(token);
|
||||
if (injectableDef && injectableDef.providedIn == 'root') {
|
||||
return injectableDef.value === undefined ? injectableDef.value = injectableDef.factory() :
|
||||
@ -183,7 +185,7 @@ export function injectRootLimpMode<T>(
|
||||
throw new Error(`Injector: NOT_FOUND [${stringify(token)}]`);
|
||||
}
|
||||
|
||||
export function injectArgs(types: (Type<any>| InjectionToken<any>| any[])[]): any[] {
|
||||
export function injectArgs(types: (Type<any>|InjectionToken<any>|any[])[]): any[] {
|
||||
const args: any[] = [];
|
||||
for (let i = 0; i < types.length; i++) {
|
||||
const arg = resolveForwardRef(types[i]);
|
||||
@ -210,7 +212,7 @@ export function injectArgs(types: (Type<any>| InjectionToken<any>| any[])[]): an
|
||||
}
|
||||
}
|
||||
|
||||
args.push(ɵɵinject(type !, flags));
|
||||
args.push(ɵɵinject(type!, flags));
|
||||
} else {
|
||||
args.push(ɵɵinject(arg));
|
||||
}
|
||||
@ -236,7 +238,7 @@ export class NullInjector implements Injector {
|
||||
|
||||
|
||||
export function catchInjectorError(
|
||||
e: any, token: any, injectorErrorName: string, source: string | null): never {
|
||||
e: any, token: any, injectorErrorName: string, source: string|null): never {
|
||||
const tokenPath: any[] = e[NG_TEMP_TOKEN_PATH];
|
||||
if (token[SOURCE]) {
|
||||
tokenPath.unshift(token[SOURCE]);
|
||||
@ -248,7 +250,7 @@ export function catchInjectorError(
|
||||
}
|
||||
|
||||
export function formatError(
|
||||
text: string, obj: any, injectorErrorName: string, source: string | null = null): string {
|
||||
text: string, obj: any, injectorErrorName: string, source: string|null = null): string {
|
||||
text = text && text.charAt(0) === '\n' && text.charAt(1) == NO_NEW_LINE ? text.substr(2) : text;
|
||||
let context = stringify(obj);
|
||||
if (Array.isArray(obj)) {
|
||||
@ -264,5 +266,6 @@ export function formatError(
|
||||
}
|
||||
context = `{${parts.join(', ')}}`;
|
||||
}
|
||||
return `${injectorErrorName}${source ? '(' + source + ')' : ''}[${context}]: ${text.replace(NEW_LINE, '\n ')}`;
|
||||
return `${injectorErrorName}${source ? '(' + source + ')' : ''}[${context}]: ${
|
||||
text.replace(NEW_LINE, '\n ')}`;
|
||||
}
|
||||
|
@ -140,13 +140,14 @@ export interface InjectorTypeWithProviders<T> {
|
||||
*/
|
||||
export function ɵɵdefineInjectable<T>(opts: {
|
||||
token: unknown,
|
||||
providedIn?: Type<any>| 'root' | 'platform' | 'any' | null,
|
||||
factory: () => T,
|
||||
providedIn?: Type<any>|'root'|'platform'|'any'|null, factory: () => T,
|
||||
}): never {
|
||||
return ({
|
||||
token: opts.token, providedIn: opts.providedIn as any || null, factory: opts.factory,
|
||||
value: undefined,
|
||||
} as ɵɵInjectableDef<T>) as never;
|
||||
token: opts.token,
|
||||
providedIn: opts.providedIn as any || null,
|
||||
factory: opts.factory,
|
||||
value: undefined,
|
||||
} as ɵɵInjectableDef<T>) as never;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -179,8 +180,10 @@ export const defineInjectable = ɵɵdefineInjectable;
|
||||
export function ɵɵdefineInjector(options: {factory: () => any, providers?: any[], imports?: any[]}):
|
||||
never {
|
||||
return ({
|
||||
factory: options.factory, providers: options.providers || [], imports: options.imports || [],
|
||||
} as ɵɵInjectorDef<any>) as never;
|
||||
factory: options.factory,
|
||||
providers: options.providers || [],
|
||||
imports: options.imports || [],
|
||||
} as ɵɵInjectorDef<any>) as never;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -219,15 +222,17 @@ function getOwnDefinition<T>(type: any, def: ɵɵInjectableDef<T>): ɵɵInjectab
|
||||
*/
|
||||
export function getInheritedInjectableDef<T>(type: any): ɵɵInjectableDef<T>|null {
|
||||
// See `jit/injectable.ts#compileInjectable` for context on NG_PROV_DEF_FALLBACK.
|
||||
const def = type && (type[NG_PROV_DEF] || type[NG_INJECTABLE_DEF] ||
|
||||
(type[NG_PROV_DEF_FALLBACK] && type[NG_PROV_DEF_FALLBACK]()));
|
||||
const def = type &&
|
||||
(type[NG_PROV_DEF] || type[NG_INJECTABLE_DEF] ||
|
||||
(type[NG_PROV_DEF_FALLBACK] && type[NG_PROV_DEF_FALLBACK]()));
|
||||
|
||||
if (def) {
|
||||
const typeName = getTypeName(type);
|
||||
// TODO(FW-1307): Re-add ngDevMode when closure can handle it
|
||||
// ngDevMode &&
|
||||
console.warn(
|
||||
`DEPRECATED: DI is instantiating a token "${typeName}" that inherits its @Injectable decorator but does not provide one itself.\n` +
|
||||
`DEPRECATED: DI is instantiating a token "${
|
||||
typeName}" that inherits its @Injectable decorator but does not provide one itself.\n` +
|
||||
`This will become an error in v10. Please add @Injectable() to the "${typeName}" class.`);
|
||||
return def;
|
||||
} else {
|
||||
|
@ -255,8 +255,8 @@ export interface FactoryProvider extends FactorySansProvider {
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export type StaticProvider = ValueProvider | ExistingProvider | StaticClassProvider |
|
||||
ConstructorProvider | FactoryProvider | any[];
|
||||
export type StaticProvider =
|
||||
ValueProvider|ExistingProvider|StaticClassProvider|ConstructorProvider|FactoryProvider|any[];
|
||||
|
||||
|
||||
/**
|
||||
@ -329,8 +329,8 @@ export interface ClassProvider extends ClassSansProvider {
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export type Provider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider |
|
||||
ExistingProvider | FactoryProvider | any[];
|
||||
export type Provider = TypeProvider|ValueProvider|ClassProvider|ConstructorProvider|
|
||||
ExistingProvider|FactoryProvider|any[];
|
||||
|
||||
/**
|
||||
* Describes a function that is used to process provider lists (such as provider
|
||||
|
@ -31,9 +31,9 @@ function getFactoryOf<T>(type: Type<any>): ((type?: Type<T>) => T)|null {
|
||||
|
||||
if (isForwardRef(type)) {
|
||||
return (() => {
|
||||
const factory = getFactoryOf<T>(resolveForwardRef(typeAny));
|
||||
return factory ? factory() : null;
|
||||
}) as any;
|
||||
const factory = getFactoryOf<T>(resolveForwardRef(typeAny));
|
||||
return factory ? factory() : null;
|
||||
}) as any;
|
||||
}
|
||||
|
||||
const def = getInjectableDef<T>(typeAny) || getInjectorDef<T>(typeAny);
|
||||
|
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {R3InjectableMetadataFacade, getCompilerFacade} from '../../compiler/compiler_facade';
|
||||
import {getCompilerFacade, R3InjectableMetadataFacade} from '../../compiler/compiler_facade';
|
||||
import {Type} from '../../interface/type';
|
||||
import {NG_FACTORY_DEF} from '../../render3/fields';
|
||||
import {getClosureSafeProperty} from '../../util/property';
|
||||
@ -76,7 +76,7 @@ export function compileInjectable(type: Type<any>, srcMeta?: Injectable): void {
|
||||
}
|
||||
}
|
||||
|
||||
type UseClassProvider = Injectable & ClassSansProvider & {deps?: any[]};
|
||||
type UseClassProvider = Injectable&ClassSansProvider&{deps?: any[]};
|
||||
|
||||
const USE_VALUE =
|
||||
getClosureSafeProperty<ValueProvider>({provide: String, useValue: getClosureSafeProperty});
|
||||
|
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {ChangeDetectorRef} from '../../change_detection/change_detector_ref';
|
||||
import {CompilerFacade, R3DependencyMetadataFacade, R3ResolvedDependencyType, getCompilerFacade} from '../../compiler/compiler_facade';
|
||||
import {CompilerFacade, getCompilerFacade, R3DependencyMetadataFacade, R3ResolvedDependencyType} from '../../compiler/compiler_facade';
|
||||
import {Type} from '../../interface/type';
|
||||
import {ReflectionCapabilities} from '../../reflection/reflection_capabilities';
|
||||
import {Attribute, Host, Inject, Optional, Self, SkipSelf} from '../metadata';
|
||||
@ -27,7 +27,7 @@ export function convertDependencies(deps: any[]): R3DependencyMetadataFacade[] {
|
||||
return deps.map(dep => reflectDependency(compiler, dep));
|
||||
}
|
||||
|
||||
function reflectDependency(compiler: CompilerFacade, dep: any | any[]): R3DependencyMetadataFacade {
|
||||
function reflectDependency(compiler: CompilerFacade, dep: any|any[]): R3DependencyMetadataFacade {
|
||||
const meta: R3DependencyMetadataFacade = {
|
||||
token: null,
|
||||
host: false,
|
||||
|
@ -33,7 +33,7 @@ export interface InjectDecorator {
|
||||
* </code-example>
|
||||
*/
|
||||
(token: any): any;
|
||||
new (token: any): Inject;
|
||||
new(token: any): Inject;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,7 +82,7 @@ export interface OptionalDecorator {
|
||||
*
|
||||
*/
|
||||
(): any;
|
||||
new (): Optional;
|
||||
new(): Optional;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,7 +128,7 @@ export interface SelfDecorator {
|
||||
*
|
||||
*/
|
||||
(): any;
|
||||
new (): Self;
|
||||
new(): Self;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -175,7 +175,7 @@ export interface SkipSelfDecorator {
|
||||
*
|
||||
*/
|
||||
(): any;
|
||||
new (): SkipSelf;
|
||||
new(): SkipSelf;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -215,7 +215,7 @@ export interface HostDecorator {
|
||||
* </code-example>
|
||||
*/
|
||||
(): any;
|
||||
new (): Host;
|
||||
new(): Host;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -262,7 +262,7 @@ export interface AttributeDecorator {
|
||||
*
|
||||
*/
|
||||
(name: string): any;
|
||||
new (name: string): Attribute;
|
||||
new(name: string): Attribute;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -15,11 +15,12 @@ import {throwCyclicDependencyError, throwInvalidProviderError, throwMixedMultiPr
|
||||
import {FactoryFn} from '../render3/interfaces/definition';
|
||||
import {deepForEach, newArray} from '../util/array_utils';
|
||||
import {stringify} from '../util/stringify';
|
||||
|
||||
import {resolveForwardRef} from './forward_ref';
|
||||
import {InjectionToken} from './injection_token';
|
||||
import {Injector} from './injector';
|
||||
import {INJECTOR, NG_TEMP_TOKEN_PATH, NullInjector, THROW_IF_NOT_FOUND, USE_VALUE, catchInjectorError, injectArgs, setCurrentInjector, ɵɵinject} from './injector_compatibility';
|
||||
import {InjectorType, InjectorTypeWithProviders, getInheritedInjectableDef, getInjectableDef, getInjectorDef, ɵɵInjectableDef} from './interface/defs';
|
||||
import {catchInjectorError, injectArgs, INJECTOR, NG_TEMP_TOKEN_PATH, NullInjector, setCurrentInjector, THROW_IF_NOT_FOUND, USE_VALUE, ɵɵinject} from './injector_compatibility';
|
||||
import {getInheritedInjectableDef, getInjectableDef, getInjectorDef, InjectorType, InjectorTypeWithProviders, ɵɵInjectableDef} from './interface/defs';
|
||||
import {InjectFlags} from './interface/injector';
|
||||
import {ClassProvider, ConstructorProvider, ExistingProvider, FactoryProvider, StaticClassProvider, StaticProvider, TypeProvider, ValueProvider} from './interface/provider';
|
||||
import {INJECTOR_SCOPE} from './scope';
|
||||
@ -29,8 +30,8 @@ import {INJECTOR_SCOPE} from './scope';
|
||||
/**
|
||||
* Internal type for a single provider in a deep provider array.
|
||||
*/
|
||||
type SingleProvider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider |
|
||||
ExistingProvider | FactoryProvider | StaticClassProvider;
|
||||
type SingleProvider = TypeProvider|ValueProvider|ClassProvider|ConstructorProvider|ExistingProvider|
|
||||
FactoryProvider|StaticClassProvider;
|
||||
|
||||
/**
|
||||
* Marker which indicates that a value has not yet been created from the factory function.
|
||||
@ -76,8 +77,8 @@ interface Record<T> {
|
||||
* @publicApi
|
||||
*/
|
||||
export function createInjector(
|
||||
defType: /* InjectorType<any> */ any, parent: Injector | null = null,
|
||||
additionalProviders: StaticProvider[] | null = null, name?: string): Injector {
|
||||
defType: /* InjectorType<any> */ any, parent: Injector|null = null,
|
||||
additionalProviders: StaticProvider[]|null = null, name?: string): Injector {
|
||||
const injector =
|
||||
createInjectorWithoutInjectorInstances(defType, parent, additionalProviders, name);
|
||||
injector._resolveInjectorDefTypes();
|
||||
@ -90,8 +91,8 @@ export function createInjector(
|
||||
* should be resolved at a later point by calling `_resolveInjectorDefTypes`.
|
||||
*/
|
||||
export function createInjectorWithoutInjectorInstances(
|
||||
defType: /* InjectorType<any> */ any, parent: Injector | null = null,
|
||||
additionalProviders: StaticProvider[] | null = null, name?: string): R3Injector {
|
||||
defType: /* InjectorType<any> */ any, parent: Injector|null = null,
|
||||
additionalProviders: StaticProvider[]|null = null, name?: string): R3Injector {
|
||||
return new R3Injector(defType, additionalProviders, parent || getNullInjector(), name);
|
||||
}
|
||||
|
||||
@ -124,7 +125,9 @@ export class R3Injector {
|
||||
/**
|
||||
* Flag indicating that this injector was previously destroyed.
|
||||
*/
|
||||
get destroyed(): boolean { return this._destroyed; }
|
||||
get destroyed(): boolean {
|
||||
return this._destroyed;
|
||||
}
|
||||
private _destroyed = false;
|
||||
|
||||
constructor(
|
||||
@ -135,9 +138,10 @@ export class R3Injector {
|
||||
// Start off by creating Records for every provider declared in every InjectorType
|
||||
// included transitively in additional providers then do the same for `def`. This order is
|
||||
// important because `def` may include providers that override ones in additionalProviders.
|
||||
additionalProviders && deepForEach(
|
||||
additionalProviders, provider => this.processProvider(
|
||||
provider, def, additionalProviders));
|
||||
additionalProviders &&
|
||||
deepForEach(
|
||||
additionalProviders,
|
||||
provider => this.processProvider(provider, def, additionalProviders));
|
||||
|
||||
deepForEach([def], injectorDef => this.processInjectorType(injectorDef, [], dedupStack));
|
||||
|
||||
@ -235,7 +239,9 @@ export class R3Injector {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
_resolveInjectorDefTypes() { this.injectorDefTypes.forEach(defType => this.get(defType)); }
|
||||
_resolveInjectorDefTypes() {
|
||||
this.injectorDefTypes.forEach(defType => this.get(defType));
|
||||
}
|
||||
|
||||
toString() {
|
||||
const tokens = <string[]>[], records = this.records;
|
||||
@ -285,8 +291,8 @@ export class R3Injector {
|
||||
// Check for circular dependencies.
|
||||
if (ngDevMode && parents.indexOf(defType) !== -1) {
|
||||
const defName = stringify(defType);
|
||||
throw new Error(
|
||||
`Circular dependency in DI detected for type ${defName}. Dependency path: ${parents.map(defType => stringify(defType)).join(' > ')} > ${defName}.`);
|
||||
throw new Error(`Circular dependency in DI detected for type ${defName}. Dependency path: ${
|
||||
parents.map(defType => stringify(defType)).join(' > ')} > ${defName}.`);
|
||||
}
|
||||
|
||||
// Check for multiple imports of the same module
|
||||
@ -335,7 +341,7 @@ export class R3Injector {
|
||||
for (let i = 0; i < importTypesWithProviders.length; i++) {
|
||||
const {ngModule, providers} = importTypesWithProviders[i];
|
||||
deepForEach(
|
||||
providers !,
|
||||
providers!,
|
||||
provider => this.processProvider(provider, ngModule, providers || EMPTY_ARRAY));
|
||||
}
|
||||
}
|
||||
@ -383,11 +389,11 @@ export class R3Injector {
|
||||
}
|
||||
} else {
|
||||
multiRecord = makeRecord(undefined, NOT_YET, true);
|
||||
multiRecord.factory = () => injectArgs(multiRecord !.multi !);
|
||||
multiRecord.factory = () => injectArgs(multiRecord!.multi!);
|
||||
this.records.set(token, multiRecord);
|
||||
}
|
||||
token = provider;
|
||||
multiRecord.multi !.push(provider);
|
||||
multiRecord.multi!.push(provider);
|
||||
} else {
|
||||
const existing = this.records.get(token);
|
||||
if (existing && existing.multi !== undefined) {
|
||||
@ -402,7 +408,7 @@ export class R3Injector {
|
||||
throwCyclicDependencyError(stringify(token));
|
||||
} else if (record.value === NOT_YET) {
|
||||
record.value = CIRCULAR;
|
||||
record.value = record.factory !();
|
||||
record.value = record.factory!();
|
||||
}
|
||||
if (typeof record.value === 'object' && record.value && hasOnDestroy(record.value)) {
|
||||
this.onDestroy.add(record.value);
|
||||
@ -421,7 +427,7 @@ export class R3Injector {
|
||||
}
|
||||
}
|
||||
|
||||
function injectableDefOrInjectorDefFactory(token: Type<any>| InjectionToken<any>): FactoryFn<any> {
|
||||
function injectableDefOrInjectorDefFactory(token: Type<any>|InjectionToken<any>): FactoryFn<any> {
|
||||
// Most tokens will have an injectable def directly on them, which specifies a factory directly.
|
||||
const injectableDef = getInjectableDef(token);
|
||||
const factory = injectableDef !== null ? injectableDef.factory : getFactoryDef(token);
|
||||
@ -519,7 +525,7 @@ export function providerToFactory(
|
||||
}
|
||||
|
||||
function makeRecord<T>(
|
||||
factory: (() => T) | undefined, value: T | {}, multi: boolean = false): Record<T> {
|
||||
factory: (() => T)|undefined, value: T|{}, multi: boolean = false): Record<T> {
|
||||
return {
|
||||
factory: factory,
|
||||
value: value,
|
||||
@ -547,14 +553,14 @@ export function isClassProvider(value: SingleProvider): value is ClassProvider {
|
||||
return !!(value as StaticClassProvider | ClassProvider).useClass;
|
||||
}
|
||||
|
||||
function hasDeps(value: ClassProvider | ConstructorProvider | StaticClassProvider):
|
||||
value is ClassProvider&{deps: any[]} {
|
||||
function hasDeps(value: ClassProvider|ConstructorProvider|
|
||||
StaticClassProvider): value is ClassProvider&{deps: any[]} {
|
||||
return !!(value as any).deps;
|
||||
}
|
||||
|
||||
function hasOnDestroy(value: any): value is OnDestroy {
|
||||
return value !== null && typeof value === 'object' &&
|
||||
typeof(value as OnDestroy).ngOnDestroy === 'function';
|
||||
typeof (value as OnDestroy).ngOnDestroy === 'function';
|
||||
}
|
||||
|
||||
function couldBeInjectableType(value: any): value is Type<any>|InjectionToken<any> {
|
||||
|
@ -143,7 +143,8 @@ export function instantiationError(
|
||||
key: ReflectiveKey): InjectionError {
|
||||
return injectionError(injector, key, function(keys: ReflectiveKey[]) {
|
||||
const first = stringify(keys[0].token);
|
||||
return `${originalException.message}: Error during instantiation of ${first}!${constructResolvingPath(keys)}.`;
|
||||
return `${originalException.message}: Error during instantiation of ${first}!${
|
||||
constructResolvingPath(keys)}.`;
|
||||
}, originalException);
|
||||
}
|
||||
|
||||
@ -193,7 +194,7 @@ export function invalidProviderError(provider: any) {
|
||||
* ```
|
||||
*
|
||||
*/
|
||||
export function noAnnotationError(typeOrFunc: Type<any>| Function, params: any[][]): Error {
|
||||
export function noAnnotationError(typeOrFunc: Type<any>|Function, params: any[][]): Error {
|
||||
const signature: string[] = [];
|
||||
for (let i = 0, ii = params.length; i < ii; i++) {
|
||||
const parameter = params[i];
|
||||
|
@ -308,7 +308,7 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
|
||||
|
||||
createChildFromResolved(providers: ResolvedReflectiveProvider[]): ReflectiveInjector {
|
||||
const inj = new ReflectiveInjector_(providers);
|
||||
(inj as{parent: Injector | null}).parent = this;
|
||||
(inj as {parent: Injector | null}).parent = this;
|
||||
return inj;
|
||||
}
|
||||
|
||||
@ -335,7 +335,9 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
|
||||
return this._instantiateProvider(provider);
|
||||
}
|
||||
|
||||
private _getMaxNumberOfObjects(): number { return this.objs.length; }
|
||||
private _getMaxNumberOfObjects(): number {
|
||||
return this.objs.length;
|
||||
}
|
||||
|
||||
private _instantiateProvider(provider: ResolvedReflectiveProvider): any {
|
||||
if (provider.multiProvider) {
|
||||
@ -451,7 +453,9 @@ export class ReflectiveInjector_ implements ReflectiveInjector {
|
||||
return `ReflectiveInjector(providers: [${providers}])`;
|
||||
}
|
||||
|
||||
toString(): string { return this.displayName; }
|
||||
toString(): string {
|
||||
return this.displayName;
|
||||
}
|
||||
}
|
||||
|
||||
function _mapProviders(injector: ReflectiveInjector_, fn: Function): any[] {
|
||||
|
@ -50,7 +50,9 @@ export class ReflectiveKey {
|
||||
/**
|
||||
* @returns the number of keys registered in the system.
|
||||
*/
|
||||
static get numberOfKeys(): number { return _globalKeyRegistry.numberOfKeys; }
|
||||
static get numberOfKeys(): number {
|
||||
return _globalKeyRegistry.numberOfKeys;
|
||||
}
|
||||
}
|
||||
|
||||
export class KeyRegistry {
|
||||
@ -60,7 +62,7 @@ export class KeyRegistry {
|
||||
if (token instanceof ReflectiveKey) return token;
|
||||
|
||||
if (this._allKeys.has(token)) {
|
||||
return this._allKeys.get(token) !;
|
||||
return this._allKeys.get(token)!;
|
||||
}
|
||||
|
||||
const newKey = new ReflectiveKey(token, ReflectiveKey.numberOfKeys);
|
||||
@ -68,7 +70,9 @@ export class KeyRegistry {
|
||||
return newKey;
|
||||
}
|
||||
|
||||
get numberOfKeys(): number { return this._allKeys.size; }
|
||||
get numberOfKeys(): number {
|
||||
return this._allKeys.size;
|
||||
}
|
||||
}
|
||||
|
||||
const _globalKeyRegistry = new KeyRegistry();
|
||||
|
@ -18,7 +18,7 @@ import {ReflectiveKey} from './reflective_key';
|
||||
|
||||
|
||||
interface NormalizedProvider extends TypeProvider, ValueProvider, ClassProvider, ExistingProvider,
|
||||
FactoryProvider {}
|
||||
FactoryProvider {}
|
||||
|
||||
/**
|
||||
* `Dependency` is used by the framework to extend DI.
|
||||
@ -184,7 +184,7 @@ function _normalizeProviders(
|
||||
providers: Provider[], res: NormalizedProvider[]): NormalizedProvider[] {
|
||||
providers.forEach(b => {
|
||||
if (b instanceof Type) {
|
||||
res.push({ provide: b, useClass: b } as NormalizedProvider);
|
||||
res.push({provide: b, useClass: b} as NormalizedProvider);
|
||||
|
||||
} else if (b && typeof b == 'object' && (b as any).provide !== undefined) {
|
||||
res.push(b as NormalizedProvider);
|
||||
@ -221,7 +221,7 @@ function _dependenciesFor(typeOrFunc: any): ReflectiveDependency[] {
|
||||
}
|
||||
|
||||
function _extractToken(
|
||||
typeOrFunc: any, metadata: any[] | any, params: any[][]): ReflectiveDependency {
|
||||
typeOrFunc: any, metadata: any[]|any, params: any[][]): ReflectiveDependency {
|
||||
let token: any = null;
|
||||
let optional = false;
|
||||
|
||||
@ -264,6 +264,6 @@ function _extractToken(
|
||||
}
|
||||
|
||||
function _createDependency(
|
||||
token: any, optional: boolean, visibility: Self | SkipSelf | null): ReflectiveDependency {
|
||||
token: any, optional: boolean, visibility: Self|SkipSelf|null): ReflectiveDependency {
|
||||
return new ReflectiveDependency(ReflectiveKey.get(token), optional, visibility);
|
||||
}
|
||||
|
@ -19,8 +19,9 @@ const USE_VALUE =
|
||||
const EMPTY_ARRAY: any[] = [];
|
||||
|
||||
export function convertInjectableProviderToFactory(
|
||||
type: Type<any>, provider?: ValueSansProvider | ExistingSansProvider | StaticClassSansProvider |
|
||||
ConstructorSansProvider | FactorySansProvider | ClassSansProvider): () => any {
|
||||
type: Type<any>,
|
||||
provider?: ValueSansProvider|ExistingSansProvider|StaticClassSansProvider|
|
||||
ConstructorSansProvider|FactorySansProvider|ClassSansProvider): () => any {
|
||||
if (!provider) {
|
||||
const reflectionCapabilities = new ReflectionCapabilities();
|
||||
const deps = reflectionCapabilities.parameters(type);
|
||||
@ -51,6 +52,6 @@ export function convertInjectableProviderToFactory(
|
||||
const reflectionCapabilities = new ReflectionCapabilities();
|
||||
deps = reflectionCapabilities.parameters(type);
|
||||
}
|
||||
return () => new type(...injectArgs(deps !));
|
||||
return () => new type(...injectArgs(deps!));
|
||||
}
|
||||
}
|
||||
|
@ -83,7 +83,9 @@ export class EventEmitter<T extends any> extends Subject<T> {
|
||||
* Emits an event containing a given value.
|
||||
* @param value The value to emit.
|
||||
*/
|
||||
emit(value?: T) { super.next(value); }
|
||||
emit(value?: T) {
|
||||
super.next(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers handlers for events emitted by this instance.
|
||||
@ -101,29 +103,46 @@ export class EventEmitter<T extends any> extends Subject<T> {
|
||||
if (generatorOrNext && typeof generatorOrNext === 'object') {
|
||||
schedulerFn = this.__isAsync ? (value: any) => {
|
||||
setTimeout(() => generatorOrNext.next(value));
|
||||
} : (value: any) => { generatorOrNext.next(value); };
|
||||
} : (value: any) => {
|
||||
generatorOrNext.next(value);
|
||||
};
|
||||
|
||||
if (generatorOrNext.error) {
|
||||
errorFn = this.__isAsync ? (err) => { setTimeout(() => generatorOrNext.error(err)); } :
|
||||
(err) => { generatorOrNext.error(err); };
|
||||
errorFn = this.__isAsync ? (err) => {
|
||||
setTimeout(() => generatorOrNext.error(err));
|
||||
} : (err) => {
|
||||
generatorOrNext.error(err);
|
||||
};
|
||||
}
|
||||
|
||||
if (generatorOrNext.complete) {
|
||||
completeFn = this.__isAsync ? () => { setTimeout(() => generatorOrNext.complete()); } :
|
||||
() => { generatorOrNext.complete(); };
|
||||
completeFn = this.__isAsync ? () => {
|
||||
setTimeout(() => generatorOrNext.complete());
|
||||
} : () => {
|
||||
generatorOrNext.complete();
|
||||
};
|
||||
}
|
||||
} else {
|
||||
schedulerFn = this.__isAsync ? (value: any) => { setTimeout(() => generatorOrNext(value)); } :
|
||||
(value: any) => { generatorOrNext(value); };
|
||||
schedulerFn = this.__isAsync ? (value: any) => {
|
||||
setTimeout(() => generatorOrNext(value));
|
||||
} : (value: any) => {
|
||||
generatorOrNext(value);
|
||||
};
|
||||
|
||||
if (error) {
|
||||
errorFn =
|
||||
this.__isAsync ? (err) => { setTimeout(() => error(err)); } : (err) => { error(err); };
|
||||
errorFn = this.__isAsync ? (err) => {
|
||||
setTimeout(() => error(err));
|
||||
} : (err) => {
|
||||
error(err);
|
||||
};
|
||||
}
|
||||
|
||||
if (complete) {
|
||||
completeFn =
|
||||
this.__isAsync ? () => { setTimeout(() => complete()); } : () => { complete(); };
|
||||
completeFn = this.__isAsync ? () => {
|
||||
setTimeout(() => complete());
|
||||
} : () => {
|
||||
complete();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,9 +5,10 @@
|
||||
* 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 localeEn from './locale_en';
|
||||
import {global} from '../util/global';
|
||||
|
||||
import localeEn from './locale_en';
|
||||
|
||||
/**
|
||||
* This const is used to store the locale data registered with `registerLocaleData`
|
||||
*/
|
||||
@ -19,7 +20,7 @@ let LOCALE_DATA: {[localeId: string]: any} = {};
|
||||
*
|
||||
* The signature `registerLocaleData(data: any, extraData?: any)` is deprecated since v5.1
|
||||
*/
|
||||
export function registerLocaleData(data: any, localeId?: string | any, extraData?: any): void {
|
||||
export function registerLocaleData(data: any, localeId?: string|any, extraData?: any): void {
|
||||
if (typeof localeId !== 'string') {
|
||||
extraData = localeId;
|
||||
localeId = data[LocaleDataIndex.LocaleId];
|
||||
@ -151,7 +152,11 @@ export const enum ExtraLocaleDataIndex {
|
||||
/**
|
||||
* Index of each value in currency data (used to describe CURRENCIES_EN in currencies.ts)
|
||||
*/
|
||||
export const enum CurrencyIndex {Symbol = 0, SymbolNarrow, NbOfDigits}
|
||||
export const enum CurrencyIndex {
|
||||
Symbol = 0,
|
||||
SymbolNarrow,
|
||||
NbOfDigits
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the canonical form of a locale name - lowercase with `_` replaced with `-`.
|
||||
|
@ -90,12 +90,12 @@ export interface OnInit {
|
||||
*/
|
||||
export interface DoCheck {
|
||||
/**
|
||||
* A callback method that performs change-detection, invoked
|
||||
* after the default change-detector runs.
|
||||
* See `KeyValueDiffers` and `IterableDiffers` for implementing
|
||||
* custom change checking for collections.
|
||||
*
|
||||
*/
|
||||
* A callback method that performs change-detection, invoked
|
||||
* after the default change-detector runs.
|
||||
* See `KeyValueDiffers` and `IterableDiffers` for implementing
|
||||
* custom change checking for collections.
|
||||
*
|
||||
*/
|
||||
ngDoCheck(): void;
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,9 @@ export class SimpleChange {
|
||||
/**
|
||||
* Check whether the new value is the first value assigned.
|
||||
*/
|
||||
isFirstChange(): boolean { return this.firstChange; }
|
||||
isFirstChange(): boolean {
|
||||
return this.firstChange;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -32,4 +34,6 @@ export class SimpleChange {
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export interface SimpleChanges { [propName: string]: SimpleChange; }
|
||||
export interface SimpleChanges {
|
||||
[propName: string]: SimpleChange;
|
||||
}
|
||||
|
@ -30,11 +30,15 @@ export function isType(v: any): v is Type<any> {
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export interface AbstractType<T> extends Function { prototype: T; }
|
||||
export interface AbstractType<T> extends Function {
|
||||
prototype: T;
|
||||
}
|
||||
|
||||
export interface Type<T> extends Function { new (...args: any[]): T; }
|
||||
export interface Type<T> extends Function {
|
||||
new(...args: any[]): T;
|
||||
}
|
||||
|
||||
export type Mutable<T extends{[x: string]: any}, K extends string> = {
|
||||
export type Mutable<T extends {[x: string]: any}, K extends string> = {
|
||||
[P in K]: T[P];
|
||||
};
|
||||
|
||||
|
@ -7,12 +7,12 @@
|
||||
*/
|
||||
|
||||
// Public API for compiler
|
||||
export {COMPILER_OPTIONS, Compiler, CompilerFactory, CompilerOptions, ModuleWithComponentFactories} from './linker/compiler';
|
||||
export {Compiler, COMPILER_OPTIONS, CompilerFactory, CompilerOptions, ModuleWithComponentFactories} from './linker/compiler';
|
||||
export {ComponentFactory, ComponentRef} from './linker/component_factory';
|
||||
export {ComponentFactoryResolver} from './linker/component_factory_resolver';
|
||||
export {ElementRef} from './linker/element_ref';
|
||||
export {NgModuleFactory, NgModuleRef} from './linker/ng_module_factory';
|
||||
export {NgModuleFactoryLoader, getModuleFactory} from './linker/ng_module_factory_loader';
|
||||
export {getModuleFactory, NgModuleFactoryLoader} from './linker/ng_module_factory_loader';
|
||||
export {QueryList} from './linker/query_list';
|
||||
export {SystemJsNgModuleLoader, SystemJsNgModuleLoaderConfig} from './linker/system_js_ng_module_factory_loader';
|
||||
export {TemplateRef} from './linker/template_ref';
|
||||
|
@ -60,7 +60,7 @@ export const Compiler_compileModuleAndAllComponentsSync__POST_R3__: <T>(moduleTy
|
||||
ModuleWithComponentFactories<T> = function<T>(moduleType: Type<T>):
|
||||
ModuleWithComponentFactories<T> {
|
||||
const ngModuleFactory = Compiler_compileModuleSync__POST_R3__(moduleType);
|
||||
const moduleDef = getNgModuleDef(moduleType) !;
|
||||
const moduleDef = getNgModuleDef(moduleType)!;
|
||||
const componentFactories =
|
||||
maybeUnwrapFn(moduleDef.declarations)
|
||||
.reduce((factories: ComponentFactory<any>[], declaration: Type<any>) => {
|
||||
@ -133,7 +133,9 @@ export class Compiler {
|
||||
/**
|
||||
* Returns the id for a given NgModule, if one is defined and known to the compiler.
|
||||
*/
|
||||
getModuleId(moduleType: Type<any>): string|undefined { return undefined; }
|
||||
getModuleId(moduleType: Type<any>): string|undefined {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -14,8 +14,8 @@ import {ComponentFactory, ComponentRef} from './component_factory';
|
||||
import {NgModuleRef} from './ng_module_factory';
|
||||
|
||||
export function noComponentFactoryError(component: Function) {
|
||||
const error = Error(
|
||||
`No component factory found for ${stringify(component)}. Did you add it to @NgModule.entryComponents?`);
|
||||
const error = Error(`No component factory found for ${
|
||||
stringify(component)}. Did you add it to @NgModule.entryComponents?`);
|
||||
(error as any)[ERROR_COMPONENT] = component;
|
||||
return error;
|
||||
}
|
||||
@ -28,7 +28,7 @@ export function getComponent(error: Error): Type<any> {
|
||||
|
||||
|
||||
class _NullComponentFactoryResolver implements ComponentFactoryResolver {
|
||||
resolveComponentFactory<T>(component: {new (...args: any[]): T}): ComponentFactory<T> {
|
||||
resolveComponentFactory<T>(component: {new(...args: any[]): T}): ComponentFactory<T> {
|
||||
throw noComponentFactoryError(component);
|
||||
}
|
||||
}
|
||||
@ -63,7 +63,7 @@ export class CodegenComponentFactoryResolver implements ComponentFactoryResolver
|
||||
}
|
||||
}
|
||||
|
||||
resolveComponentFactory<T>(component: {new (...args: any[]): T}): ComponentFactory<T> {
|
||||
resolveComponentFactory<T>(component: {new(...args: any[]): T}): ComponentFactory<T> {
|
||||
let factory = this._factories.get(component);
|
||||
if (!factory && this._parent) {
|
||||
factory = this._parent.resolveComponentFactory(component);
|
||||
|
@ -48,7 +48,9 @@ export class ElementRef<T extends any = any> {
|
||||
*/
|
||||
public nativeElement: T;
|
||||
|
||||
constructor(nativeElement: T) { this.nativeElement = nativeElement; }
|
||||
constructor(nativeElement: T) {
|
||||
this.nativeElement = nativeElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
@ -43,6 +43,8 @@ export function getModuleFactory__POST_R3__(id: string): NgModuleFactory<any> {
|
||||
*/
|
||||
export const getModuleFactory: (id: string) => NgModuleFactory<any> = getModuleFactory__PRE_R3__;
|
||||
|
||||
function noModuleError(id: string, ): Error {
|
||||
function noModuleError(
|
||||
id: string,
|
||||
): Error {
|
||||
return new Error(`No module with ID ${id} loaded`);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ export function registerModuleFactory(id: string, factory: NgModuleFactory<any>)
|
||||
modules.set(id, factory);
|
||||
}
|
||||
|
||||
function assertSameOrNotExisting(id: string, type: Type<any>| null, incoming: Type<any>): void {
|
||||
function assertSameOrNotExisting(id: string, type: Type<any>|null, incoming: Type<any>): void {
|
||||
if (type && type !== incoming) {
|
||||
throw new Error(
|
||||
`Duplicate module registered for ${id} - ${stringify(type)} vs ${stringify(type.name)}`);
|
||||
|
@ -13,7 +13,7 @@ import {flatten} from '../util/array_utils';
|
||||
import {getSymbolIterator} from '../util/symbol';
|
||||
|
||||
function symbolIterator<T>(this: QueryList<T>): Iterator<T> {
|
||||
return ((this as any as{_results: Array<T>})._results as any)[getSymbolIterator()]();
|
||||
return ((this as any as {_results: Array<T>})._results as any)[getSymbolIterator()]();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -49,9 +49,9 @@ export class QueryList<T> implements Iterable<T> {
|
||||
|
||||
readonly length: number = 0;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
readonly first !: T;
|
||||
readonly first!: T;
|
||||
// TODO(issue/24571): remove '!'.
|
||||
readonly last !: T;
|
||||
readonly last!: T;
|
||||
|
||||
constructor() {
|
||||
// This function should be declared on the prototype, but doing so there will cause the class
|
||||
@ -67,7 +67,9 @@ export class QueryList<T> implements Iterable<T> {
|
||||
* See
|
||||
* [Array.map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)
|
||||
*/
|
||||
map<U>(fn: (item: T, index: number, array: T[]) => U): U[] { return this._results.map(fn); }
|
||||
map<U>(fn: (item: T, index: number, array: T[]) => U): U[] {
|
||||
return this._results.map(fn);
|
||||
}
|
||||
|
||||
/**
|
||||
* See
|
||||
@ -97,7 +99,9 @@ export class QueryList<T> implements Iterable<T> {
|
||||
* See
|
||||
* [Array.forEach](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)
|
||||
*/
|
||||
forEach(fn: (item: T, index: number, array: T[]) => void): void { this._results.forEach(fn); }
|
||||
forEach(fn: (item: T, index: number, array: T[]) => void): void {
|
||||
this._results.forEach(fn);
|
||||
}
|
||||
|
||||
/**
|
||||
* See
|
||||
@ -110,9 +114,13 @@ export class QueryList<T> implements Iterable<T> {
|
||||
/**
|
||||
* Returns a copy of the internal results list as an Array.
|
||||
*/
|
||||
toArray(): T[] { return this._results.slice(); }
|
||||
toArray(): T[] {
|
||||
return this._results.slice();
|
||||
}
|
||||
|
||||
toString(): string { return this._results.toString(); }
|
||||
toString(): string {
|
||||
return this._results.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the stored data of the query list, and resets the `dirty` flag to `false`, so that
|
||||
@ -123,19 +131,23 @@ export class QueryList<T> implements Iterable<T> {
|
||||
*/
|
||||
reset(resultsTree: Array<T|any[]>): void {
|
||||
this._results = flatten(resultsTree);
|
||||
(this as{dirty: boolean}).dirty = false;
|
||||
(this as{length: number}).length = this._results.length;
|
||||
(this as{last: T}).last = this._results[this.length - 1];
|
||||
(this as{first: T}).first = this._results[0];
|
||||
(this as {dirty: boolean}).dirty = false;
|
||||
(this as {length: number}).length = this._results.length;
|
||||
(this as {last: T}).last = this._results[this.length - 1];
|
||||
(this as {first: T}).first = this._results[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a change event by emitting on the `changes` {@link EventEmitter}.
|
||||
*/
|
||||
notifyOnChanges(): void { (this.changes as EventEmitter<any>).emit(this); }
|
||||
notifyOnChanges(): void {
|
||||
(this.changes as EventEmitter<any>).emit(this);
|
||||
}
|
||||
|
||||
/** internal */
|
||||
setDirty() { (this as{dirty: boolean}).dirty = true; }
|
||||
setDirty() {
|
||||
(this as {dirty: boolean}).dirty = true;
|
||||
}
|
||||
|
||||
/** internal */
|
||||
destroy(): void {
|
||||
@ -148,5 +160,5 @@ export class QueryList<T> implements Iterable<T> {
|
||||
// there) and this declaration is left here to ensure that TypeScript considers QueryList to
|
||||
// implement the Iterable interface. This is required for template type-checking of NgFor loops
|
||||
// over QueryLists to work correctly, since QueryList must be assignable to NgIterable.
|
||||
[Symbol.iterator] !: () => Iterator<T>;
|
||||
[Symbol.iterator]!: () => Iterator<T>;
|
||||
}
|
||||
|
@ -32,13 +32,13 @@ export abstract class SystemJsNgModuleLoaderConfig {
|
||||
* Prefix to add when computing the name of the factory module for a given module name.
|
||||
*/
|
||||
// TODO(issue/24571): remove '!'.
|
||||
factoryPathPrefix !: string;
|
||||
factoryPathPrefix!: string;
|
||||
|
||||
/**
|
||||
* Suffix to add when computing the name of the factory module for a given module name.
|
||||
*/
|
||||
// TODO(issue/24571): remove '!'.
|
||||
factoryPathSuffix !: string;
|
||||
factoryPathSuffix!: string;
|
||||
}
|
||||
|
||||
const DEFAULT_CONFIG: SystemJsNgModuleLoaderConfig = {
|
||||
|
@ -75,7 +75,7 @@ export interface AttributeDecorator {
|
||||
* @publicApi
|
||||
*/
|
||||
(name: string): any;
|
||||
new (name: string): Attribute;
|
||||
new(name: string): Attribute;
|
||||
}
|
||||
|
||||
|
||||
@ -158,7 +158,7 @@ export interface ContentChildrenDecorator {
|
||||
* @Annotation
|
||||
*/
|
||||
(selector: Type<any>|Function|string, opts?: {descendants?: boolean, read?: any}): any;
|
||||
new (selector: Type<any>|Function|string, opts?: {descendants?: boolean, read?: any}): Query;
|
||||
new(selector: Type<any>|Function|string, opts?: {descendants?: boolean, read?: any}): Query;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -219,7 +219,7 @@ export interface ContentChildDecorator {
|
||||
* @Annotation
|
||||
*/
|
||||
(selector: Type<any>|Function|string, opts?: {read?: any, static?: boolean}): any;
|
||||
new (selector: Type<any>|Function|string, opts?: {read?: any, static?: boolean}): ContentChild;
|
||||
new(selector: Type<any>|Function|string, opts?: {read?: any, static?: boolean}): ContentChild;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -238,8 +238,9 @@ export type ContentChild = Query;
|
||||
* @publicApi
|
||||
*/
|
||||
export const ContentChild: ContentChildDecorator = makePropDecorator(
|
||||
'ContentChild', (selector?: any, data: any = {}) =>
|
||||
({selector, first: true, isViewQuery: false, descendants: true, ...data}),
|
||||
'ContentChild',
|
||||
(selector?: any, data: any = {}) =>
|
||||
({selector, first: true, isViewQuery: false, descendants: true, ...data}),
|
||||
Query);
|
||||
|
||||
/**
|
||||
@ -275,7 +276,7 @@ export interface ViewChildrenDecorator {
|
||||
* @Annotation
|
||||
*/
|
||||
(selector: Type<any>|Function|string, opts?: {read?: any}): any;
|
||||
new (selector: Type<any>|Function|string, opts?: {read?: any}): ViewChildren;
|
||||
new(selector: Type<any>|Function|string, opts?: {read?: any}): ViewChildren;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -292,8 +293,9 @@ export type ViewChildren = Query;
|
||||
* @publicApi
|
||||
*/
|
||||
export const ViewChildren: ViewChildrenDecorator = makePropDecorator(
|
||||
'ViewChildren', (selector?: any, data: any = {}) =>
|
||||
({selector, first: false, isViewQuery: true, descendants: true, ...data}),
|
||||
'ViewChildren',
|
||||
(selector?: any, data: any = {}) =>
|
||||
({selector, first: false, isViewQuery: true, descendants: true, ...data}),
|
||||
Query);
|
||||
|
||||
/**
|
||||
@ -342,7 +344,7 @@ export interface ViewChildDecorator {
|
||||
* @Annotation
|
||||
*/
|
||||
(selector: Type<any>|Function|string, opts?: {read?: any, static?: boolean}): any;
|
||||
new (selector: Type<any>|Function|string, opts?: {read?: any, static?: boolean}): ViewChild;
|
||||
new(selector: Type<any>|Function|string, opts?: {read?: any, static?: boolean}): ViewChild;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -359,6 +361,7 @@ export type ViewChild = Query;
|
||||
* @publicApi
|
||||
*/
|
||||
export const ViewChild: ViewChildDecorator = makePropDecorator(
|
||||
'ViewChild', (selector: any, data: any) =>
|
||||
({selector, first: true, isViewQuery: true, descendants: true, ...data}),
|
||||
'ViewChild',
|
||||
(selector: any, data: any) =>
|
||||
({selector, first: true, isViewQuery: true, descendants: true, ...data}),
|
||||
Query);
|
||||
|
@ -11,7 +11,7 @@ import {Provider} from '../di';
|
||||
import {Type} from '../interface/type';
|
||||
import {compileComponent as render3CompileComponent, compileDirective as render3CompileDirective} from '../render3/jit/directive';
|
||||
import {compilePipe as render3CompilePipe} from '../render3/jit/pipe';
|
||||
import {TypeDecorator, makeDecorator, makePropDecorator} from '../util/decorators';
|
||||
import {makeDecorator, makePropDecorator, TypeDecorator} from '../util/decorators';
|
||||
import {noop} from '../util/noop';
|
||||
|
||||
import {ViewEncapsulation} from './view';
|
||||
@ -73,7 +73,7 @@ export interface DirectiveDecorator {
|
||||
/**
|
||||
* See the `Directive` decorator.
|
||||
*/
|
||||
new (obj?: Directive): Directive;
|
||||
new(obj?: Directive): Directive;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -445,7 +445,7 @@ export interface ComponentDecorator {
|
||||
/**
|
||||
* See the `Component` decorator.
|
||||
*/
|
||||
new (obj: Component): Component;
|
||||
new(obj: Component): Component;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -598,7 +598,7 @@ export interface PipeDecorator {
|
||||
/**
|
||||
* See the `Pipe` decorator.
|
||||
*/
|
||||
new (obj: Pipe): Pipe;
|
||||
new(obj: Pipe): Pipe;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -641,52 +641,52 @@ export const Pipe: PipeDecorator = makeDecorator(
|
||||
*/
|
||||
export interface InputDecorator {
|
||||
/**
|
||||
* Decorator that marks a class field as an input property and supplies configuration metadata.
|
||||
* The input property is bound to a DOM property in the template. During change detection,
|
||||
* Angular automatically updates the data property with the DOM property's value.
|
||||
*
|
||||
* @usageNotes
|
||||
*
|
||||
* You can supply an optional name to use in templates when the
|
||||
* component is instantiated, that maps to the
|
||||
* name of the bound property. By default, the original
|
||||
* name of the bound property is used for input binding.
|
||||
*
|
||||
* The following example creates a component with two input properties,
|
||||
* one of which is given a special binding name.
|
||||
*
|
||||
* ```typescript
|
||||
* @Component({
|
||||
* selector: 'bank-account',
|
||||
* template: `
|
||||
* Bank Name: {{bankName}}
|
||||
* Account Id: {{id}}
|
||||
* `
|
||||
* })
|
||||
* class BankAccount {
|
||||
* // This property is bound using its original name.
|
||||
* @Input() bankName: string;
|
||||
* // this property value is bound to a different property name
|
||||
* // when this component is instantiated in a template.
|
||||
* @Input('account-id') id: string;
|
||||
*
|
||||
* // this property is not bound, and is not automatically updated by Angular
|
||||
* normalizedBankName: string;
|
||||
* }
|
||||
*
|
||||
* @Component({
|
||||
* selector: 'app',
|
||||
* template: `
|
||||
* <bank-account bankName="RBC" account-id="4747"></bank-account>
|
||||
* `
|
||||
* })
|
||||
* class App {}
|
||||
* ```
|
||||
*
|
||||
* @see [Input and Output properties](guide/template-syntax#input-and-output-properties)
|
||||
*/
|
||||
* Decorator that marks a class field as an input property and supplies configuration metadata.
|
||||
* The input property is bound to a DOM property in the template. During change detection,
|
||||
* Angular automatically updates the data property with the DOM property's value.
|
||||
*
|
||||
* @usageNotes
|
||||
*
|
||||
* You can supply an optional name to use in templates when the
|
||||
* component is instantiated, that maps to the
|
||||
* name of the bound property. By default, the original
|
||||
* name of the bound property is used for input binding.
|
||||
*
|
||||
* The following example creates a component with two input properties,
|
||||
* one of which is given a special binding name.
|
||||
*
|
||||
* ```typescript
|
||||
* @Component({
|
||||
* selector: 'bank-account',
|
||||
* template: `
|
||||
* Bank Name: {{bankName}}
|
||||
* Account Id: {{id}}
|
||||
* `
|
||||
* })
|
||||
* class BankAccount {
|
||||
* // This property is bound using its original name.
|
||||
* @Input() bankName: string;
|
||||
* // this property value is bound to a different property name
|
||||
* // when this component is instantiated in a template.
|
||||
* @Input('account-id') id: string;
|
||||
*
|
||||
* // this property is not bound, and is not automatically updated by Angular
|
||||
* normalizedBankName: string;
|
||||
* }
|
||||
*
|
||||
* @Component({
|
||||
* selector: 'app',
|
||||
* template: `
|
||||
* <bank-account bankName="RBC" account-id="4747"></bank-account>
|
||||
* `
|
||||
* })
|
||||
* class App {}
|
||||
* ```
|
||||
*
|
||||
* @see [Input and Output properties](guide/template-syntax#input-and-output-properties)
|
||||
*/
|
||||
(bindingPropertyName?: string): any;
|
||||
new (bindingPropertyName?: string): any;
|
||||
new(bindingPropertyName?: string): any;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -715,23 +715,23 @@ export const Input: InputDecorator =
|
||||
*/
|
||||
export interface OutputDecorator {
|
||||
/**
|
||||
* Decorator that marks a class field as an output property and supplies configuration metadata.
|
||||
* The DOM property bound to the output property is automatically updated during change detection.
|
||||
*
|
||||
* @usageNotes
|
||||
*
|
||||
* You can supply an optional name to use in templates when the
|
||||
* component is instantiated, that maps to the
|
||||
* name of the bound property. By default, the original
|
||||
* name of the bound property is used for output binding.
|
||||
*
|
||||
* See `Input` decorator for an example of providing a binding name.
|
||||
*
|
||||
* @see [Input and Output properties](guide/template-syntax#input-and-output-properties)
|
||||
*
|
||||
*/
|
||||
* Decorator that marks a class field as an output property and supplies configuration metadata.
|
||||
* The DOM property bound to the output property is automatically updated during change detection.
|
||||
*
|
||||
* @usageNotes
|
||||
*
|
||||
* You can supply an optional name to use in templates when the
|
||||
* component is instantiated, that maps to the
|
||||
* name of the bound property. By default, the original
|
||||
* name of the bound property is used for output binding.
|
||||
*
|
||||
* See `Input` decorator for an example of providing a binding name.
|
||||
*
|
||||
* @see [Input and Output properties](guide/template-syntax#input-and-output-properties)
|
||||
*
|
||||
*/
|
||||
(bindingPropertyName?: string): any;
|
||||
new (bindingPropertyName?: string): any;
|
||||
new(bindingPropertyName?: string): any;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -741,8 +741,8 @@ export interface OutputDecorator {
|
||||
*/
|
||||
export interface Output {
|
||||
/**
|
||||
* The name of the DOM property to which the output property is bound.
|
||||
*/
|
||||
* The name of the DOM property to which the output property is bound.
|
||||
*/
|
||||
bindingPropertyName?: string;
|
||||
}
|
||||
|
||||
@ -791,7 +791,7 @@ export interface HostBindingDecorator {
|
||||
*
|
||||
*/
|
||||
(hostPropertyName?: string): any;
|
||||
new (hostPropertyName?: string): any;
|
||||
new(hostPropertyName?: string): any;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -825,7 +825,7 @@ export interface HostListenerDecorator {
|
||||
* and provides a handler method to run when that event occurs.
|
||||
*/
|
||||
(eventName: string, args?: string[]): any;
|
||||
new (eventName: string, args?: string[]): any;
|
||||
new(eventName: string, args?: string[]): any;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -13,7 +13,7 @@ import {convertInjectableProviderToFactory} from '../di/util';
|
||||
import {Type} from '../interface/type';
|
||||
import {SchemaMetadata} from '../metadata/schema';
|
||||
import {compileNgModule as render3CompileNgModule} from '../render3/jit/module';
|
||||
import {TypeDecorator, makeDecorator} from '../util/decorators';
|
||||
import {makeDecorator, TypeDecorator} from '../util/decorators';
|
||||
|
||||
|
||||
/**
|
||||
@ -107,7 +107,7 @@ export interface NgModuleDecorator {
|
||||
* Decorator that marks a class as an NgModule and supplies configuration metadata.
|
||||
*/
|
||||
(obj?: NgModule): TypeDecorator;
|
||||
new (obj?: NgModule): NgModule;
|
||||
new(obj?: NgModule): NgModule;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -345,7 +345,9 @@ export const NgModule: NgModuleDecorator = makeDecorator(
|
||||
*
|
||||
* @publicApi
|
||||
*/
|
||||
export interface DoBootstrap { ngDoBootstrap(appRef: ApplicationRef): void; }
|
||||
export interface DoBootstrap {
|
||||
ngDoBootstrap(appRef: ApplicationRef): void;
|
||||
}
|
||||
|
||||
function preR3NgModuleCompile(moduleType: Type<any>, metadata?: NgModule): void {
|
||||
let imports = (metadata && metadata.imports) || [];
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user