@angular/compiler
Version:
Angular - the compiler library
1,818 lines (1,790 loc) • 974 kB
JavaScript
/**
* @license Angular v5.0.2
* (c) 2010-2017 Google, Inc. https://angular.io/
* License: MIT
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @record
*/
function Inject() { }
const createInject = makeMetadataFactory('Inject', (token) => ({ token }));
const createInjectionToken = makeMetadataFactory('InjectionToken', (desc) => ({ _desc: desc }));
/**
* @record
*/
function Attribute() { }
const createAttribute = makeMetadataFactory('Attribute', (attributeName) => ({ attributeName }));
/**
* @record
*/
function Query() { }
const createContentChildren = makeMetadataFactory('ContentChildren', (selector, data = {}) => (Object.assign({ selector, first: false, isViewQuery: false, descendants: false }, data)));
const createContentChild = makeMetadataFactory('ContentChild', (selector, data = {}) => (Object.assign({ selector, first: true, isViewQuery: false, descendants: true }, data)));
const createViewChildren = makeMetadataFactory('ViewChildren', (selector, data = {}) => (Object.assign({ selector, first: false, isViewQuery: true, descendants: true }, data)));
const createViewChild = makeMetadataFactory('ViewChild', (selector, data) => (Object.assign({ selector, first: true, isViewQuery: true, descendants: true }, data)));
/**
* @record
*/
function Directive() { }
const createDirective = makeMetadataFactory('Directive', (dir = {}) => dir);
/**
* @record
*/
function Component() { }
/** @enum {number} */
const ViewEncapsulation = {
Emulated: 0,
Native: 1,
None: 2,
};
ViewEncapsulation[ViewEncapsulation.Emulated] = "Emulated";
ViewEncapsulation[ViewEncapsulation.Native] = "Native";
ViewEncapsulation[ViewEncapsulation.None] = "None";
/** @enum {number} */
const ChangeDetectionStrategy = {
OnPush: 0,
Default: 1,
};
ChangeDetectionStrategy[ChangeDetectionStrategy.OnPush] = "OnPush";
ChangeDetectionStrategy[ChangeDetectionStrategy.Default] = "Default";
const createComponent = makeMetadataFactory('Component', (c = {}) => (Object.assign({ changeDetection: ChangeDetectionStrategy.Default }, c)));
/**
* @record
*/
function Pipe() { }
const createPipe = makeMetadataFactory('Pipe', (p) => (Object.assign({ pure: true }, p)));
/**
* @record
*/
function Input() { }
const createInput = makeMetadataFactory('Input', (bindingPropertyName) => ({ bindingPropertyName }));
/**
* @record
*/
function Output() { }
const createOutput = makeMetadataFactory('Output', (bindingPropertyName) => ({ bindingPropertyName }));
/**
* @record
*/
function HostBinding() { }
const createHostBinding = makeMetadataFactory('HostBinding', (hostPropertyName) => ({ hostPropertyName }));
/**
* @record
*/
function HostListener() { }
const createHostListener = makeMetadataFactory('HostListener', (eventName, args) => ({ eventName, args }));
/**
* @record
*/
function NgModule() { }
const createNgModule = makeMetadataFactory('NgModule', (ngModule) => ngModule);
/**
* @record
*/
function ModuleWithProviders() { }
/**
* @record
*/
function SchemaMetadata() { }
const CUSTOM_ELEMENTS_SCHEMA = {
name: 'custom-elements'
};
const NO_ERRORS_SCHEMA = {
name: 'no-errors-schema'
};
const createOptional = makeMetadataFactory('Optional');
const createInjectable = makeMetadataFactory('Injectable');
const createSelf = makeMetadataFactory('Self');
const createSkipSelf = makeMetadataFactory('SkipSelf');
const createHost = makeMetadataFactory('Host');
const Type = Function;
/** @enum {number} */
const SecurityContext = {
NONE: 0,
HTML: 1,
STYLE: 2,
SCRIPT: 3,
URL: 4,
RESOURCE_URL: 5,
};
SecurityContext[SecurityContext.NONE] = "NONE";
SecurityContext[SecurityContext.HTML] = "HTML";
SecurityContext[SecurityContext.STYLE] = "STYLE";
SecurityContext[SecurityContext.SCRIPT] = "SCRIPT";
SecurityContext[SecurityContext.URL] = "URL";
SecurityContext[SecurityContext.RESOURCE_URL] = "RESOURCE_URL";
/** @enum {number} */
const NodeFlags = {
None: 0,
TypeElement: 1,
TypeText: 2,
ProjectedTemplate: 4,
CatRenderNode: 3,
TypeNgContent: 8,
TypePipe: 16,
TypePureArray: 32,
TypePureObject: 64,
TypePurePipe: 128,
CatPureExpression: 224,
TypeValueProvider: 256,
TypeClassProvider: 512,
TypeFactoryProvider: 1024,
TypeUseExistingProvider: 2048,
LazyProvider: 4096,
PrivateProvider: 8192,
TypeDirective: 16384,
Component: 32768,
CatProviderNoDirective: 3840,
CatProvider: 20224,
OnInit: 65536,
OnDestroy: 131072,
DoCheck: 262144,
OnChanges: 524288,
AfterContentInit: 1048576,
AfterContentChecked: 2097152,
AfterViewInit: 4194304,
AfterViewChecked: 8388608,
EmbeddedViews: 16777216,
ComponentView: 33554432,
TypeContentQuery: 67108864,
TypeViewQuery: 134217728,
StaticQuery: 268435456,
DynamicQuery: 536870912,
CatQuery: 201326592,
// mutually exclusive values...
Types: 201347067,
};
/** @enum {number} */
const DepFlags = {
None: 0,
SkipSelf: 1,
Optional: 2,
Value: 8,
};
/** @enum {number} */
const ArgumentType = { Inline: 0, Dynamic: 1, };
/** @enum {number} */
const BindingFlags = {
TypeElementAttribute: 1,
TypeElementClass: 2,
TypeElementStyle: 4,
TypeProperty: 8,
SyntheticProperty: 16,
SyntheticHostProperty: 32,
CatSyntheticProperty: 48,
// mutually exclusive values...
Types: 15,
};
/** @enum {number} */
const QueryBindingType = { First: 0, All: 1, };
/** @enum {number} */
const QueryValueType = {
ElementRef: 0,
RenderElement: 1,
TemplateRef: 2,
ViewContainerRef: 3,
Provider: 4,
};
/** @enum {number} */
const ViewFlags = {
None: 0,
OnPush: 2,
};
/** @enum {number} */
const MissingTranslationStrategy = {
Error: 0,
Warning: 1,
Ignore: 2,
};
MissingTranslationStrategy[MissingTranslationStrategy.Error] = "Error";
MissingTranslationStrategy[MissingTranslationStrategy.Warning] = "Warning";
MissingTranslationStrategy[MissingTranslationStrategy.Ignore] = "Ignore";
/**
* @record
*/
function MetadataFactory() { }
/**
* @template T
* @param {?} name
* @param {?=} props
* @return {?}
*/
function makeMetadataFactory(name, props) {
const /** @type {?} */ factory = (...args) => {
const /** @type {?} */ values = props ? props(...args) : {};
return Object.assign({ ngMetadataName: name }, values);
};
factory.isTypeOf = (obj) => obj && obj.ngMetadataName === name;
factory.ngMetadataName = name;
return factory;
}
/**
* @record
*/
function Route() { }
var core = Object.freeze({
Inject: Inject,
createInject: createInject,
createInjectionToken: createInjectionToken,
Attribute: Attribute,
createAttribute: createAttribute,
Query: Query,
createContentChildren: createContentChildren,
createContentChild: createContentChild,
createViewChildren: createViewChildren,
createViewChild: createViewChild,
Directive: Directive,
createDirective: createDirective,
Component: Component,
ViewEncapsulation: ViewEncapsulation,
ChangeDetectionStrategy: ChangeDetectionStrategy,
createComponent: createComponent,
Pipe: Pipe,
createPipe: createPipe,
Input: Input,
createInput: createInput,
Output: Output,
createOutput: createOutput,
HostBinding: HostBinding,
createHostBinding: createHostBinding,
HostListener: HostListener,
createHostListener: createHostListener,
NgModule: NgModule,
createNgModule: createNgModule,
ModuleWithProviders: ModuleWithProviders,
SchemaMetadata: SchemaMetadata,
CUSTOM_ELEMENTS_SCHEMA: CUSTOM_ELEMENTS_SCHEMA,
NO_ERRORS_SCHEMA: NO_ERRORS_SCHEMA,
createOptional: createOptional,
createInjectable: createInjectable,
createSelf: createSelf,
createSkipSelf: createSkipSelf,
createHost: createHost,
Type: Type,
SecurityContext: SecurityContext,
NodeFlags: NodeFlags,
DepFlags: DepFlags,
ArgumentType: ArgumentType,
BindingFlags: BindingFlags,
QueryBindingType: QueryBindingType,
QueryValueType: QueryValueType,
ViewFlags: ViewFlags,
MissingTranslationStrategy: MissingTranslationStrategy,
MetadataFactory: MetadataFactory,
Route: Route
});
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
const DASH_CASE_REGEXP = /-+([a-z0-9])/g;
/**
* @param {?} input
* @return {?}
*/
function dashCaseToCamelCase(input) {
return input.replace(DASH_CASE_REGEXP, (...m) => m[1].toUpperCase());
}
/**
* @param {?} input
* @param {?} defaultValues
* @return {?}
*/
function splitAtColon(input, defaultValues) {
return _splitAt(input, ':', defaultValues);
}
/**
* @param {?} input
* @param {?} defaultValues
* @return {?}
*/
function splitAtPeriod(input, defaultValues) {
return _splitAt(input, '.', defaultValues);
}
/**
* @param {?} input
* @param {?} character
* @param {?} defaultValues
* @return {?}
*/
function _splitAt(input, character, defaultValues) {
const /** @type {?} */ characterIndex = input.indexOf(character);
if (characterIndex == -1)
return defaultValues;
return [input.slice(0, characterIndex).trim(), input.slice(characterIndex + 1).trim()];
}
/**
* @param {?} value
* @param {?} visitor
* @param {?} context
* @return {?}
*/
function visitValue(value, visitor, context) {
if (Array.isArray(value)) {
return visitor.visitArray(/** @type {?} */ (value), context);
}
if (isStrictStringMap(value)) {
return visitor.visitStringMap(/** @type {?} */ (value), context);
}
if (value == null || typeof value == 'string' || typeof value == 'number' ||
typeof value == 'boolean') {
return visitor.visitPrimitive(value, context);
}
return visitor.visitOther(value, context);
}
/**
* @param {?} val
* @return {?}
*/
function isDefined(val) {
return val !== null && val !== undefined;
}
/**
* @template T
* @param {?} val
* @return {?}
*/
function noUndefined(val) {
return val === undefined ? /** @type {?} */ ((null)) : val;
}
/**
* @record
*/
class ValueTransformer {
/**
* @param {?} arr
* @param {?} context
* @return {?}
*/
visitArray(arr, context) {
return arr.map(value => visitValue(value, this, context));
}
/**
* @param {?} map
* @param {?} context
* @return {?}
*/
visitStringMap(map, context) {
const /** @type {?} */ result = {};
Object.keys(map).forEach(key => { result[key] = visitValue(map[key], this, context); });
return result;
}
/**
* @param {?} value
* @param {?} context
* @return {?}
*/
visitPrimitive(value, context) { return value; }
/**
* @param {?} value
* @param {?} context
* @return {?}
*/
visitOther(value, context) { return value; }
}
const SyncAsync = {
assertSync: (value) => {
if (isPromise(value)) {
throw new Error(`Illegal state: value cannot be a promise`);
}
return value;
},
then: (value, cb) => { return isPromise(value) ? value.then(cb) : cb(value); },
all: (syncAsyncValues) => {
return syncAsyncValues.some(isPromise) ? Promise.all(syncAsyncValues) : /** @type {?} */ (syncAsyncValues);
}
};
/**
* @param {?} msg
* @param {?=} parseErrors
* @return {?}
*/
function syntaxError(msg, parseErrors) {
const /** @type {?} */ error = Error(msg);
(/** @type {?} */ (error))[ERROR_SYNTAX_ERROR] = true;
if (parseErrors)
(/** @type {?} */ (error))[ERROR_PARSE_ERRORS] = parseErrors;
return error;
}
const ERROR_SYNTAX_ERROR = 'ngSyntaxError';
const ERROR_PARSE_ERRORS = 'ngParseErrors';
/**
* @param {?} error
* @return {?}
*/
function isSyntaxError(error) {
return (/** @type {?} */ (error))[ERROR_SYNTAX_ERROR];
}
/**
* @param {?} error
* @return {?}
*/
function getParseErrors(error) {
return (/** @type {?} */ (error))[ERROR_PARSE_ERRORS] || [];
}
/**
* @param {?} s
* @return {?}
*/
function escapeRegExp(s) {
return s.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
}
const STRING_MAP_PROTO = Object.getPrototypeOf({});
/**
* @param {?} obj
* @return {?}
*/
function isStrictStringMap(obj) {
return typeof obj === 'object' && obj !== null && Object.getPrototypeOf(obj) === STRING_MAP_PROTO;
}
/**
* @param {?} str
* @return {?}
*/
function utf8Encode(str) {
let /** @type {?} */ encoded = '';
for (let /** @type {?} */ index = 0; index < str.length; index++) {
let /** @type {?} */ codePoint = str.charCodeAt(index);
// decode surrogate
// see https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
if (codePoint >= 0xd800 && codePoint <= 0xdbff && str.length > (index + 1)) {
const /** @type {?} */ low = str.charCodeAt(index + 1);
if (low >= 0xdc00 && low <= 0xdfff) {
index++;
codePoint = ((codePoint - 0xd800) << 10) + low - 0xdc00 + 0x10000;
}
}
if (codePoint <= 0x7f) {
encoded += String.fromCharCode(codePoint);
}
else if (codePoint <= 0x7ff) {
encoded += String.fromCharCode(((codePoint >> 6) & 0x1F) | 0xc0, (codePoint & 0x3f) | 0x80);
}
else if (codePoint <= 0xffff) {
encoded += String.fromCharCode((codePoint >> 12) | 0xe0, ((codePoint >> 6) & 0x3f) | 0x80, (codePoint & 0x3f) | 0x80);
}
else if (codePoint <= 0x1fffff) {
encoded += String.fromCharCode(((codePoint >> 18) & 0x07) | 0xf0, ((codePoint >> 12) & 0x3f) | 0x80, ((codePoint >> 6) & 0x3f) | 0x80, (codePoint & 0x3f) | 0x80);
}
}
return encoded;
}
/**
* @record
*/
/**
* @param {?} token
* @return {?}
*/
function stringify(token) {
if (typeof token === 'string') {
return token;
}
if (token instanceof Array) {
return '[' + token.map(stringify).join(', ') + ']';
}
if (token == null) {
return '' + token;
}
if (token.overriddenName) {
return `${token.overriddenName}`;
}
if (token.name) {
return `${token.name}`;
}
const /** @type {?} */ res = token.toString();
if (res == null) {
return '' + res;
}
const /** @type {?} */ newLineIndex = res.indexOf('\n');
return newLineIndex === -1 ? res : res.substring(0, newLineIndex);
}
/**
* Lazily retrieves the reference value from a forwardRef.
* @param {?} type
* @return {?}
*/
function resolveForwardRef(type) {
if (typeof type === 'function' && type.hasOwnProperty('__forward_ref__')) {
return type();
}
else {
return type;
}
}
/**
* Determine if the argument is shaped like a Promise
* @param {?} obj
* @return {?}
*/
function isPromise(obj) {
// allow any Promise/A+ compliant thenable.
// It's up to the caller to ensure that obj.then conforms to the spec
return !!obj && typeof obj.then === 'function';
}
class Version {
/**
* @param {?} full
*/
constructor(full) {
this.full = full;
const /** @type {?} */ splits = full.split('.');
this.major = splits[0];
this.minor = splits[1];
this.patch = splits.slice(2).join('.');
}
}
/**
* @record
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* 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
*/
/**
* @module
* @description
* Entry point for all public APIs of the common package.
*/
/**
* \@stable
*/
const VERSION = new Version('5.0.2');
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* An Abstract Syntax Tree node representing part of a parsed Angular template.
* @record
*/
/**
* A segment of text within the template.
*/
class TextAst {
/**
* @param {?} value
* @param {?} ngContentIndex
* @param {?} sourceSpan
*/
constructor(value, ngContentIndex, sourceSpan) {
this.value = value;
this.ngContentIndex = ngContentIndex;
this.sourceSpan = sourceSpan;
}
/**
* @param {?} visitor
* @param {?} context
* @return {?}
*/
visit(visitor, context) { return visitor.visitText(this, context); }
}
/**
* A bound expression within the text of a template.
*/
class BoundTextAst {
/**
* @param {?} value
* @param {?} ngContentIndex
* @param {?} sourceSpan
*/
constructor(value, ngContentIndex, sourceSpan) {
this.value = value;
this.ngContentIndex = ngContentIndex;
this.sourceSpan = sourceSpan;
}
/**
* @param {?} visitor
* @param {?} context
* @return {?}
*/
visit(visitor, context) {
return visitor.visitBoundText(this, context);
}
}
/**
* A plain attribute on an element.
*/
class AttrAst {
/**
* @param {?} name
* @param {?} value
* @param {?} sourceSpan
*/
constructor(name, value, sourceSpan) {
this.name = name;
this.value = value;
this.sourceSpan = sourceSpan;
}
/**
* @param {?} visitor
* @param {?} context
* @return {?}
*/
visit(visitor, context) { return visitor.visitAttr(this, context); }
}
/**
* A binding for an element property (e.g. `[property]="expression"`) or an animation trigger (e.g.
* `[\@trigger]="stateExp"`)
*/
class BoundElementPropertyAst {
/**
* @param {?} name
* @param {?} type
* @param {?} securityContext
* @param {?} value
* @param {?} unit
* @param {?} sourceSpan
*/
constructor(name, type, securityContext, value, unit, sourceSpan) {
this.name = name;
this.type = type;
this.securityContext = securityContext;
this.value = value;
this.unit = unit;
this.sourceSpan = sourceSpan;
this.isAnimation = this.type === PropertyBindingType.Animation;
}
/**
* @param {?} visitor
* @param {?} context
* @return {?}
*/
visit(visitor, context) {
return visitor.visitElementProperty(this, context);
}
}
/**
* A binding for an element event (e.g. `(event)="handler()"`) or an animation trigger event (e.g.
* `(\@trigger.phase)="callback($event)"`).
*/
class BoundEventAst {
/**
* @param {?} name
* @param {?} target
* @param {?} phase
* @param {?} handler
* @param {?} sourceSpan
*/
constructor(name, target, phase, handler, sourceSpan) {
this.name = name;
this.target = target;
this.phase = phase;
this.handler = handler;
this.sourceSpan = sourceSpan;
this.fullName = BoundEventAst.calcFullName(this.name, this.target, this.phase);
this.isAnimation = !!this.phase;
}
/**
* @param {?} name
* @param {?} target
* @param {?} phase
* @return {?}
*/
static calcFullName(name, target, phase) {
if (target) {
return `${target}:${name}`;
}
else if (phase) {
return `@${name}.${phase}`;
}
else {
return name;
}
}
/**
* @param {?} visitor
* @param {?} context
* @return {?}
*/
visit(visitor, context) {
return visitor.visitEvent(this, context);
}
}
/**
* A reference declaration on an element (e.g. `let someName="expression"`).
*/
class ReferenceAst {
/**
* @param {?} name
* @param {?} value
* @param {?} sourceSpan
*/
constructor(name, value, sourceSpan) {
this.name = name;
this.value = value;
this.sourceSpan = sourceSpan;
}
/**
* @param {?} visitor
* @param {?} context
* @return {?}
*/
visit(visitor, context) {
return visitor.visitReference(this, context);
}
}
/**
* A variable declaration on a <ng-template> (e.g. `var-someName="someLocalName"`).
*/
class VariableAst {
/**
* @param {?} name
* @param {?} value
* @param {?} sourceSpan
*/
constructor(name, value, sourceSpan) {
this.name = name;
this.value = value;
this.sourceSpan = sourceSpan;
}
/**
* @param {?} visitor
* @param {?} context
* @return {?}
*/
visit(visitor, context) {
return visitor.visitVariable(this, context);
}
}
/**
* An element declaration in a template.
*/
class ElementAst {
/**
* @param {?} name
* @param {?} attrs
* @param {?} inputs
* @param {?} outputs
* @param {?} references
* @param {?} directives
* @param {?} providers
* @param {?} hasViewContainer
* @param {?} queryMatches
* @param {?} children
* @param {?} ngContentIndex
* @param {?} sourceSpan
* @param {?} endSourceSpan
*/
constructor(name, attrs, inputs, outputs, references, directives, providers, hasViewContainer, queryMatches, children, ngContentIndex, sourceSpan, endSourceSpan) {
this.name = name;
this.attrs = attrs;
this.inputs = inputs;
this.outputs = outputs;
this.references = references;
this.directives = directives;
this.providers = providers;
this.hasViewContainer = hasViewContainer;
this.queryMatches = queryMatches;
this.children = children;
this.ngContentIndex = ngContentIndex;
this.sourceSpan = sourceSpan;
this.endSourceSpan = endSourceSpan;
}
/**
* @param {?} visitor
* @param {?} context
* @return {?}
*/
visit(visitor, context) {
return visitor.visitElement(this, context);
}
}
/**
* A `<ng-template>` element included in an Angular template.
*/
class EmbeddedTemplateAst {
/**
* @param {?} attrs
* @param {?} outputs
* @param {?} references
* @param {?} variables
* @param {?} directives
* @param {?} providers
* @param {?} hasViewContainer
* @param {?} queryMatches
* @param {?} children
* @param {?} ngContentIndex
* @param {?} sourceSpan
*/
constructor(attrs, outputs, references, variables, directives, providers, hasViewContainer, queryMatches, children, ngContentIndex, sourceSpan) {
this.attrs = attrs;
this.outputs = outputs;
this.references = references;
this.variables = variables;
this.directives = directives;
this.providers = providers;
this.hasViewContainer = hasViewContainer;
this.queryMatches = queryMatches;
this.children = children;
this.ngContentIndex = ngContentIndex;
this.sourceSpan = sourceSpan;
}
/**
* @param {?} visitor
* @param {?} context
* @return {?}
*/
visit(visitor, context) {
return visitor.visitEmbeddedTemplate(this, context);
}
}
/**
* A directive property with a bound value (e.g. `*ngIf="condition").
*/
class BoundDirectivePropertyAst {
/**
* @param {?} directiveName
* @param {?} templateName
* @param {?} value
* @param {?} sourceSpan
*/
constructor(directiveName, templateName, value, sourceSpan) {
this.directiveName = directiveName;
this.templateName = templateName;
this.value = value;
this.sourceSpan = sourceSpan;
}
/**
* @param {?} visitor
* @param {?} context
* @return {?}
*/
visit(visitor, context) {
return visitor.visitDirectiveProperty(this, context);
}
}
/**
* A directive declared on an element.
*/
class DirectiveAst {
/**
* @param {?} directive
* @param {?} inputs
* @param {?} hostProperties
* @param {?} hostEvents
* @param {?} contentQueryStartId
* @param {?} sourceSpan
*/
constructor(directive, inputs, hostProperties, hostEvents, contentQueryStartId, sourceSpan) {
this.directive = directive;
this.inputs = inputs;
this.hostProperties = hostProperties;
this.hostEvents = hostEvents;
this.contentQueryStartId = contentQueryStartId;
this.sourceSpan = sourceSpan;
}
/**
* @param {?} visitor
* @param {?} context
* @return {?}
*/
visit(visitor, context) {
return visitor.visitDirective(this, context);
}
}
/**
* A provider declared on an element
*/
class ProviderAst {
/**
* @param {?} token
* @param {?} multiProvider
* @param {?} eager
* @param {?} providers
* @param {?} providerType
* @param {?} lifecycleHooks
* @param {?} sourceSpan
*/
constructor(token, multiProvider, eager, providers, providerType, lifecycleHooks, sourceSpan) {
this.token = token;
this.multiProvider = multiProvider;
this.eager = eager;
this.providers = providers;
this.providerType = providerType;
this.lifecycleHooks = lifecycleHooks;
this.sourceSpan = sourceSpan;
}
/**
* @param {?} visitor
* @param {?} context
* @return {?}
*/
visit(visitor, context) {
// No visit method in the visitor for now...
return null;
}
}
/** @enum {number} */
const ProviderAstType = {
PublicService: 0,
PrivateService: 1,
Component: 2,
Directive: 3,
Builtin: 4,
};
ProviderAstType[ProviderAstType.PublicService] = "PublicService";
ProviderAstType[ProviderAstType.PrivateService] = "PrivateService";
ProviderAstType[ProviderAstType.Component] = "Component";
ProviderAstType[ProviderAstType.Directive] = "Directive";
ProviderAstType[ProviderAstType.Builtin] = "Builtin";
/**
* Position where content is to be projected (instance of `<ng-content>` in a template).
*/
class NgContentAst {
/**
* @param {?} index
* @param {?} ngContentIndex
* @param {?} sourceSpan
*/
constructor(index, ngContentIndex, sourceSpan) {
this.index = index;
this.ngContentIndex = ngContentIndex;
this.sourceSpan = sourceSpan;
}
/**
* @param {?} visitor
* @param {?} context
* @return {?}
*/
visit(visitor, context) {
return visitor.visitNgContent(this, context);
}
}
/** @enum {number} */
const PropertyBindingType = {
/**
* A normal binding to a property (e.g. `[property]="expression"`).
*/
Property: 0,
/**
* A binding to an element attribute (e.g. `[attr.name]="expression"`).
*/
Attribute: 1,
/**
* A binding to a CSS class (e.g. `[class.name]="condition"`).
*/
Class: 2,
/**
* A binding to a style rule (e.g. `[style.rule]="expression"`).
*/
Style: 3,
/**
* A binding to an animation reference (e.g. `[animate.key]="expression"`).
*/
Animation: 4,
};
PropertyBindingType[PropertyBindingType.Property] = "Property";
PropertyBindingType[PropertyBindingType.Attribute] = "Attribute";
PropertyBindingType[PropertyBindingType.Class] = "Class";
PropertyBindingType[PropertyBindingType.Style] = "Style";
PropertyBindingType[PropertyBindingType.Animation] = "Animation";
/**
* @record
*/
/**
* A visitor for {\@link TemplateAst} trees that will process each node.
* @record
*/
/**
* A visitor that accepts each node but doesn't do anything. It is intended to be used
* as the base class for a visitor that is only interested in a subset of the node types.
*/
class NullTemplateVisitor {
/**
* @param {?} ast
* @param {?} context
* @return {?}
*/
visitNgContent(ast, context) { }
/**
* @param {?} ast
* @param {?} context
* @return {?}
*/
visitEmbeddedTemplate(ast, context) { }
/**
* @param {?} ast
* @param {?} context
* @return {?}
*/
visitElement(ast, context) { }
/**
* @param {?} ast
* @param {?} context
* @return {?}
*/
visitReference(ast, context) { }
/**
* @param {?} ast
* @param {?} context
* @return {?}
*/
visitVariable(ast, context) { }
/**
* @param {?} ast
* @param {?} context
* @return {?}
*/
visitEvent(ast, context) { }
/**
* @param {?} ast
* @param {?} context
* @return {?}
*/
visitElementProperty(ast, context) { }
/**
* @param {?} ast
* @param {?} context
* @return {?}
*/
visitAttr(ast, context) { }
/**
* @param {?} ast
* @param {?} context
* @return {?}
*/
visitBoundText(ast, context) { }
/**
* @param {?} ast
* @param {?} context
* @return {?}
*/
visitText(ast, context) { }
/**
* @param {?} ast
* @param {?} context
* @return {?}
*/
visitDirective(ast, context) { }
/**
* @param {?} ast
* @param {?} context
* @return {?}
*/
visitDirectiveProperty(ast, context) { }
}
/**
* Base class that can be used to build a visitor that visits each node
* in an template ast recursively.
*/
class RecursiveTemplateAstVisitor extends NullTemplateVisitor {
constructor() { super(); }
/**
* @param {?} ast
* @param {?} context
* @return {?}
*/
visitEmbeddedTemplate(ast, context) {
return this.visitChildren(context, visit => {
visit(ast.attrs);
visit(ast.references);
visit(ast.variables);
visit(ast.directives);
visit(ast.providers);
visit(ast.children);
});
}
/**
* @param {?} ast
* @param {?} context
* @return {?}
*/
visitElement(ast, context) {
return this.visitChildren(context, visit => {
visit(ast.attrs);
visit(ast.inputs);
visit(ast.outputs);
visit(ast.references);
visit(ast.directives);
visit(ast.providers);
visit(ast.children);
});
}
/**
* @param {?} ast
* @param {?} context
* @return {?}
*/
visitDirective(ast, context) {
return this.visitChildren(context, visit => {
visit(ast.inputs);
visit(ast.hostProperties);
visit(ast.hostEvents);
});
}
/**
* @template T
* @param {?} context
* @param {?} cb
* @return {?}
*/
visitChildren(context, cb) {
let /** @type {?} */ results = [];
let /** @type {?} */ t = this;
/**
* @template T
* @param {?} children
* @return {?}
*/
function visit(children) {
if (children && children.length)
results.push(templateVisitAll(t, children, context));
}
cb(visit);
return [].concat.apply([], results);
}
}
/**
* Visit every node in a list of {\@link TemplateAst}s with the given {\@link TemplateAstVisitor}.
* @param {?} visitor
* @param {?} asts
* @param {?=} context
* @return {?}
*/
function templateVisitAll(visitor, asts, context = null) {
const /** @type {?} */ result = [];
const /** @type {?} */ visit = visitor.visit ?
(ast) => /** @type {?} */ ((visitor.visit))(ast, context) || ast.visit(visitor, context) :
(ast) => ast.visit(visitor, context);
asts.forEach(ast => {
const /** @type {?} */ astResult = visit(ast);
if (astResult) {
result.push(astResult);
}
});
return result;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
class CompilerConfig {
/**
* @param {?=} __0
*/
constructor({ defaultEncapsulation = ViewEncapsulation.Emulated, useJit = true, jitDevMode = false, missingTranslation = null, enableLegacyTemplate, preserveWhitespaces, strictInjectionParameters } = {}) {
this.defaultEncapsulation = defaultEncapsulation;
this.useJit = !!useJit;
this.jitDevMode = !!jitDevMode;
this.missingTranslation = missingTranslation;
this.enableLegacyTemplate = enableLegacyTemplate === true;
this.preserveWhitespaces = preserveWhitespacesDefault(noUndefined(preserveWhitespaces));
this.strictInjectionParameters = strictInjectionParameters === true;
}
}
/**
* @param {?} preserveWhitespacesOption
* @param {?=} defaultSetting
* @return {?}
*/
function preserveWhitespacesDefault(preserveWhitespacesOption, defaultSetting = true) {
return preserveWhitespacesOption === null ? defaultSetting : preserveWhitespacesOption;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* A token representing the a reference to a static type.
*
* This token is unique for a filePath and name and can be used as a hash table key.
*/
class StaticSymbol {
/**
* @param {?} filePath
* @param {?} name
* @param {?} members
*/
constructor(filePath, name, members) {
this.filePath = filePath;
this.name = name;
this.members = members;
}
/**
* @return {?}
*/
assertNoMembers() {
if (this.members.length) {
throw new Error(`Illegal state: symbol without members expected, but got ${JSON.stringify(this)}.`);
}
}
}
/**
* A cache of static symbol used by the StaticReflector to return the same symbol for the
* same symbol values.
*/
class StaticSymbolCache {
constructor() {
this.cache = new Map();
}
/**
* @param {?} declarationFile
* @param {?} name
* @param {?=} members
* @return {?}
*/
get(declarationFile, name, members) {
members = members || [];
const /** @type {?} */ memberSuffix = members.length ? `.${members.join('.')}` : '';
const /** @type {?} */ key = `"${declarationFile}".${name}${memberSuffix}`;
let /** @type {?} */ result = this.cache.get(key);
if (!result) {
result = new StaticSymbol(declarationFile, name, members);
this.cache.set(key, result);
}
return result;
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* 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
*/
// group 0: "[prop] or (event) or @trigger"
// group 1: "prop" from "[prop]"
// group 2: "event" from "(event)"
// group 3: "@trigger" from "@trigger"
const HOST_REG_EXP = /^(?:(?:\[([^\]]+)\])|(?:\(([^\)]+)\)))|(\@[-\w]+)$/;
/**
* @param {?} name
* @return {?}
*/
function _sanitizeIdentifier(name) {
return name.replace(/\W/g, '_');
}
let _anonymousTypeIndex = 0;
/**
* @param {?} compileIdentifier
* @return {?}
*/
function identifierName(compileIdentifier) {
if (!compileIdentifier || !compileIdentifier.reference) {
return null;
}
const /** @type {?} */ ref = compileIdentifier.reference;
if (ref instanceof StaticSymbol) {
return ref.name;
}
if (ref['__anonymousType']) {
return ref['__anonymousType'];
}
let /** @type {?} */ identifier = stringify(ref);
if (identifier.indexOf('(') >= 0) {
// case: anonymous functions!
identifier = `anonymous_${_anonymousTypeIndex++}`;
ref['__anonymousType'] = identifier;
}
else {
identifier = _sanitizeIdentifier(identifier);
}
return identifier;
}
/**
* @param {?} compileIdentifier
* @return {?}
*/
function identifierModuleUrl(compileIdentifier) {
const /** @type {?} */ ref = compileIdentifier.reference;
if (ref instanceof StaticSymbol) {
return ref.filePath;
}
// Runtime type
return `./${stringify(ref)}`;
}
/**
* @param {?} compType
* @param {?} embeddedTemplateIndex
* @return {?}
*/
function viewClassName(compType, embeddedTemplateIndex) {
return `View_${identifierName({ reference: compType })}_${embeddedTemplateIndex}`;
}
/**
* @param {?} compType
* @return {?}
*/
function rendererTypeName(compType) {
return `RenderType_${identifierName({ reference: compType })}`;
}
/**
* @param {?} compType
* @return {?}
*/
function hostViewClassName(compType) {
return `HostView_${identifierName({ reference: compType })}`;
}
/**
* @param {?} compType
* @return {?}
*/
function componentFactoryName(compType) {
return `${identifierName({ reference: compType })}NgFactory`;
}
/**
* @record
*/
/**
* @record
*/
/** @enum {number} */
const CompileSummaryKind = {
Pipe: 0,
Directive: 1,
NgModule: 2,
Injectable: 3,
};
CompileSummaryKind[CompileSummaryKind.Pipe] = "Pipe";
CompileSummaryKind[CompileSummaryKind.Directive] = "Directive";
CompileSummaryKind[CompileSummaryKind.NgModule] = "NgModule";
CompileSummaryKind[CompileSummaryKind.Injectable] = "Injectable";
/**
* A CompileSummary is the data needed to use a directive / pipe / module
* in other modules / components. However, this data is not enough to compile
* the directive / module itself.
* @record
*/
/**
* @record
*/
/**
* @record
*/
/**
* @record
*/
/**
* @param {?} token
* @return {?}
*/
function tokenName(token) {
return token.value != null ? _sanitizeIdentifier(token.value) : identifierName(token.identifier);
}
/**
* @param {?} token
* @return {?}
*/
function tokenReference(token) {
if (token.identifier != null) {
return token.identifier.reference;
}
else {
return token.value;
}
}
/**
* @record
*/
/**
* Metadata regarding compilation of a type.
* @record
*/
/**
* @record
*/
/**
* Metadata about a stylesheet
*/
class CompileStylesheetMetadata {
/**
* @param {?=} __0
*/
constructor({ moduleUrl, styles, styleUrls } = {}) {
this.moduleUrl = moduleUrl || null;
this.styles = _normalizeArray(styles);
this.styleUrls = _normalizeArray(styleUrls);
}
}
/**
* Summary Metadata regarding compilation of a template.
* @record
*/
/**
* Metadata regarding compilation of a template.
*/
class CompileTemplateMetadata {
/**
* @param {?} __0
*/
constructor({ encapsulation, template, templateUrl, htmlAst, styles, styleUrls, externalStylesheets, animations, ngContentSelectors, interpolation, isInline, preserveWhitespaces }) {
this.encapsulation = encapsulation;
this.template = template;
this.templateUrl = templateUrl;
this.htmlAst = htmlAst;
this.styles = _normalizeArray(styles);
this.styleUrls = _normalizeArray(styleUrls);
this.externalStylesheets = _normalizeArray(externalStylesheets);
this.animations = animations ? flatten(animations) : [];
this.ngContentSelectors = ngContentSelectors || [];
if (interpolation && interpolation.length != 2) {
throw new Error(`'interpolation' should have a start and an end symbol.`);
}
this.interpolation = interpolation;
this.isInline = isInline;
this.preserveWhitespaces = preserveWhitespaces;
}
/**
* @return {?}
*/
toSummary() {
return {
ngContentSelectors: this.ngContentSelectors,
encapsulation: this.encapsulation,
};
}
}
/**
* @record
*/
/**
* @record
*/
/**
* Metadata regarding compilation of a directive.
*/
class CompileDirectiveMetadata {
/**
* @param {?} __0
* @return {?}
*/
static create({ isHost, type, isComponent, selector, exportAs, changeDetection, inputs, outputs, host, providers, viewProviders, queries, viewQueries, entryComponents, template, componentViewType, rendererType, componentFactory }) {
const /** @type {?} */ hostListeners = {};
const /** @type {?} */ hostProperties = {};
const /** @type {?} */ hostAttributes = {};
if (host != null) {
Object.keys(host).forEach(key => {
const /** @type {?} */ value = host[key];
const /** @type {?} */ matches = key.match(HOST_REG_EXP);
if (matches === null) {
hostAttributes[key] = value;
}
else if (matches[1] != null) {
hostProperties[matches[1]] = value;
}
else if (matches[2] != null) {
hostListeners[matches[2]] = value;
}
});
}
const /** @type {?} */ inputsMap = {};
if (inputs != null) {
inputs.forEach((bindConfig) => {
// canonical syntax: `dirProp: elProp`
// if there is no `:`, use dirProp = elProp
const /** @type {?} */ parts = splitAtColon(bindConfig, [bindConfig, bindConfig]);
inputsMap[parts[0]] = parts[1];
});
}
const /** @type {?} */ outputsMap = {};
if (outputs != null) {
outputs.forEach((bindConfig) => {
// canonical syntax: `dirProp: elProp`
// if there is no `:`, use dirProp = elProp
const /** @type {?} */ parts = splitAtColon(bindConfig, [bindConfig, bindConfig]);
outputsMap[parts[0]] = parts[1];
});
}
return new CompileDirectiveMetadata({
isHost,
type,
isComponent: !!isComponent, selector, exportAs, changeDetection,
inputs: inputsMap,
outputs: outputsMap,
hostListeners,
hostProperties,
hostAttributes,
providers,
viewProviders,
queries,
viewQueries,
entryComponents,
template,
componentViewType,
rendererType,
componentFactory,
});
}
/**
* @param {?} __0
*/
constructor({ isHost, type, isComponent, selector, exportAs, changeDetection, inputs, outputs, hostListeners, hostProperties, hostAttributes, providers, viewProviders, queries, viewQueries, entryComponents, template, componentViewType, rendererType, componentFactory }) {
this.isHost = !!isHost;
this.type = type;
this.isComponent = isComponent;
this.selector = selector;
this.exportAs = exportAs;
this.changeDetection = changeDetection;
this.inputs = inputs;
this.outputs = outputs;
this.hostListeners = hostListeners;
this.hostProperties = hostProperties;
this.hostAttributes = hostAttributes;
this.providers = _normalizeArray(providers);
this.viewProviders = _normalizeArray(viewProviders);
this.queries = _normalizeArray(queries);
this.viewQueries = _normalizeArray(viewQueries);
this.entryComponents = _normalizeArray(entryComponents);
this.template = template;
this.componentViewType = componentViewType;
this.rendererType = rendererType;
this.componentFactory = componentFactory;
}
/**
* @return {?}
*/
toSummary() {
return {
summaryKind: CompileSummaryKind.Directive,
type: this.type,
isComponent: this.isComponent,
selector: this.selector,
exportAs: this.exportAs,
inputs: this.inputs,
outputs: this.outputs,
hostListeners: this.hostListeners,
hostProperties: this.hostProperties,
hostAttributes: this.hostAttributes,
providers: this.providers,
viewProviders: this.viewProviders,
queries: this.queries,
viewQueries: this.viewQueries,
entryComponents: this.entryComponents,
changeDetection: this.changeDetection,
template: this.template && this.template.toSummary(),
componentViewType: this.componentViewType,
rendererType: this.rendererType,
componentFactory: this.componentFactory
};
}
}
/**
* @record
*/
class CompilePipeMetadata {
/**
* @param {?} __0
*/
constructor({ type, name, pure }) {
this.type = type;
this.name = name;
this.pure = !!pure;
}
/**
* @return {?}
*/
toSummary() {
return {
summaryKind: CompileSummaryKind.Pipe,
type: this.type,
name: this.name,
pure: this.pure
};
}
}
/**
* @record
*/
/**
* Metadata regarding compilation of a module.
*/
class CompileNgModuleMetadata {
/**
* @param {?} __0
*/
constructor({ type, providers, declaredDirectives, exportedDirectives, declaredPipes, exportedPipes, entryComponents, bootstrapComponents, importedModules, exportedModules, schemas, transitiveModule, id }) {
this.type = type || null;
this.declaredDirectives = _normalizeArray(declaredDirectives);
this.exportedDirectives = _normalizeArray(exportedDirectives);
this.declaredPipes = _normalizeArray(declaredPipes);
this.exportedPipes = _normalizeArray(exportedPipes);
this.providers = _normalizeArray(providers);
this.entryComponents = _normalizeArray(entryComponents);
this.bootstrapComponents = _normalizeArray(bootstrapComponents);
this.importedModules = _normalizeArray(importedModules);
this.exportedModules = _normalizeArray(exportedModules);
this.schemas = _normalizeArray(schemas);
this.id = id || null;
this.transitiveModule = transitiveModule || null;
}
/**
* @return {?}
*/
toSummary() {
const /** @type {?} */ module = /** @type {?} */ ((this.transitiveModule));
return {
summaryKind: CompileSummaryKind.NgModule,
type: this.type,
entryComponents: module.entryComponents,
providers: module.providers,
modules: module.modules,
exportedDirectives: module.exportedDirectives,
exportedPipes: module.exportedPipes
};
}
}
class TransitiveCompileNgModuleMetadata {
constructor() {
this.directivesSet = new Set();
this.directives = [];
this.exportedDirectivesSet = new Set();
this.exportedDirectives = [];
this.pipesSet = new Set();
this.pipes = [];
this.exportedPipesSet = new Set();
this.exportedPipes = [];
this.modulesSet = new Set();
this.modules = [];
this.entryComponentsSet = new Set();
this.entryComponents = [];
this.providers = [];
}
/**
* @param {?} provider
* @param {?} module
* @return {?}
*/
addProvider(provider, module) {
this.providers.push({ provider: provider, module: module });
}
/**
* @param {?} id
* @return {?}
*/
addDirective(id) {
if (!this.directivesSet.has(id.reference)) {
this.directivesSet.add(id.reference);
this.directives.push(id);
}
}
/**
* @param {?} id
* @return {?}
*/
addExportedDirective(id) {
if (!this.exportedDirectivesSet.has(id.reference)) {
this.exportedDirectivesSet.add(id.reference);
this.exportedDirectives.push(id);
}
}
/**
* @param {?} id
* @return {?}
*/
addPipe(id) {
if (!this.pipesSet.has(id.reference)) {
this.pipesSet.add(id.reference);
this.pipes.push(id);
}
}
/**
* @param {?} id
* @return {?}
*/
addExportedPipe(id) {
if (!this.exportedPipesSet.has(id.reference)) {
this.exportedPipesSet.add(id.reference);
this.exportedPipes.push(id);
}
}
/**
* @param {?} id
* @return {?}
*/
addModule(id) {
if (!this.modulesSet.has(id.reference)) {
this.modulesSet.add(id.reference);
this.modules.push(id);
}
}
/**
* @param {?} ec
* @return {?}
*/
addEntryComponent(ec) {
if (!this.entryComponentsSet.has(ec.componentType)) {
this.entryComponentsSet.add(ec.componentType);
this.entryComponents.push(ec);
}
}
}
/**
* @param {?} obj
* @return {?}
*/
function _normalizeArray(obj) {
return obj || [];
}
class ProviderMeta {
/**
* @param {?} token
* @param {?} __1
*/
constructor(token, { useClass, useValue, useExisting, useFactory, deps, multi }) {
this.token = token;
this.useClass = useClass || null;
this.useValue = useValue;
this.useExisting = useExisting;
this.useFactory = useFactory || null;
this.dependencies = deps || null;
this.multi = !!multi;
}
}
/**
* @template T
* @param {?} list
* @return {?}
*/
function flatten(list) {
return list.reduce((flat, item) => {
const /** @type {?} */ flatItem = Array.isArray(item) ? flatten(item) : item;
return (/** @type {?} */ (flat)).concat(flatItem);
}, []);
}
/**
* @param {?} url
* @return {?}
*/
function jitSourceUrl(url) {
// Note: We need 3 "/" so that ng shows up as a separate domain
// in the chrome dev tools.
return url.replace(/(\w+:\/\/[\w:-]+)?(\/+)?/, 'ng:///');
}
/**
* @param {?} ngModuleType
* @param {?} compMeta
* @param {?} templateMeta
* @return {?}
*/
function templateSourceUrl(ngModuleType, compMeta, templateMeta) {
let /** @type {?} */ url;
if (templateMeta.isInline) {
if (compMeta.type.reference instanceof StaticSymbol) {
// Note: a .ts file might contain multiple components with inline templates,
// so we need to give them unique urls, as these will be used for sourcemaps.
url = `${compMeta.type.reference.filePath}.${compMeta.type.reference.name}.html`;
}
else {
url = `${identifierName(ngModuleType)}/${identifierName(compMeta.type)}.html`;
}
}
else {
url = /** @type {?} */ ((templateMeta.templateUrl));
}
r