@angular/compiler 17.1.0 → 17.2.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2022/src/compiler_facade_interface.mjs +1 -1
- package/esm2022/src/config.mjs +1 -1
- package/esm2022/src/jit_compiler_facade.mjs +3 -1
- package/esm2022/src/render3/partial/api.mjs +1 -1
- package/esm2022/src/render3/partial/class_metadata.mjs +1 -1
- package/esm2022/src/render3/partial/directive.mjs +10 -2
- package/esm2022/src/render3/partial/factory.mjs +1 -1
- package/esm2022/src/render3/partial/injectable.mjs +1 -1
- package/esm2022/src/render3/partial/injector.mjs +1 -1
- package/esm2022/src/render3/partial/ng_module.mjs +1 -1
- package/esm2022/src/render3/partial/pipe.mjs +1 -1
- package/esm2022/src/render3/r3_identifiers.mjs +5 -1
- package/esm2022/src/render3/view/api.mjs +1 -1
- package/esm2022/src/render3/view/compiler.mjs +3 -70
- package/esm2022/src/render3/view/query_generation.mjs +176 -0
- package/esm2022/src/render3/view/util.mjs +3 -26
- package/esm2022/src/shadow_css.mjs +6 -4
- package/esm2022/src/template/pipeline/src/phases/create_i18n_contexts.mjs +2 -2
- package/esm2022/src/version.mjs +1 -1
- package/fesm2022/compiler.mjs +1045 -955
- package/fesm2022/compiler.mjs.map +1 -1
- package/index.d.ts +16 -3
- package/package.json +2 -2
package/fesm2022/compiler.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Angular v17.
|
|
2
|
+
* @license Angular v17.2.0-next.0
|
|
3
3
|
* (c) 2010-2022 Google LLC. https://angular.io/
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
@@ -2628,6 +2628,10 @@ class Identifiers {
|
|
|
2628
2628
|
static { this.viewQuery = { name: 'ɵɵviewQuery', moduleName: CORE }; }
|
|
2629
2629
|
static { this.loadQuery = { name: 'ɵɵloadQuery', moduleName: CORE }; }
|
|
2630
2630
|
static { this.contentQuery = { name: 'ɵɵcontentQuery', moduleName: CORE }; }
|
|
2631
|
+
// Signal queries
|
|
2632
|
+
static { this.viewQuerySignal = { name: 'ɵɵviewQuerySignal', moduleName: CORE }; }
|
|
2633
|
+
static { this.contentQuerySignal = { name: 'ɵɵcontentQuerySignal', moduleName: CORE }; }
|
|
2634
|
+
static { this.queryAdvance = { name: 'ɵɵqueryAdvance', moduleName: CORE }; }
|
|
2631
2635
|
static { this.NgOnChangesFeature = { name: 'ɵɵNgOnChangesFeature', moduleName: CORE }; }
|
|
2632
2636
|
static { this.InheritDefinitionFeature = { name: 'ɵɵInheritDefinitionFeature', moduleName: CORE }; }
|
|
2633
2637
|
static { this.CopyDefinitionFeature = { name: 'ɵɵCopyDefinitionFeature', moduleName: CORE }; }
|
|
@@ -4967,11 +4971,11 @@ function invokeInstruction(span, reference, params) {
|
|
|
4967
4971
|
*
|
|
4968
4972
|
* A variable declaration is added to the statements the first time the allocator is invoked.
|
|
4969
4973
|
*/
|
|
4970
|
-
function temporaryAllocator(
|
|
4974
|
+
function temporaryAllocator(pushStatement, name) {
|
|
4971
4975
|
let temp = null;
|
|
4972
4976
|
return () => {
|
|
4973
4977
|
if (!temp) {
|
|
4974
|
-
|
|
4978
|
+
pushStatement(new DeclareVarStmt(TEMPORARY_NAME, undefined, DYNAMIC_TYPE));
|
|
4975
4979
|
temp = variable(name);
|
|
4976
4980
|
}
|
|
4977
4981
|
return temp;
|
|
@@ -5069,29 +5073,6 @@ function trimTrailingNulls(parameters) {
|
|
|
5069
5073
|
}
|
|
5070
5074
|
return parameters;
|
|
5071
5075
|
}
|
|
5072
|
-
function getQueryPredicate(query, constantPool) {
|
|
5073
|
-
if (Array.isArray(query.predicate)) {
|
|
5074
|
-
let predicate = [];
|
|
5075
|
-
query.predicate.forEach((selector) => {
|
|
5076
|
-
// Each item in predicates array may contain strings with comma-separated refs
|
|
5077
|
-
// (for ex. 'ref, ref1, ..., refN'), thus we extract individual refs and store them
|
|
5078
|
-
// as separate array entities
|
|
5079
|
-
const selectors = selector.split(',').map(token => literal(token.trim()));
|
|
5080
|
-
predicate.push(...selectors);
|
|
5081
|
-
});
|
|
5082
|
-
return constantPool.getConstLiteral(literalArr(predicate), true);
|
|
5083
|
-
}
|
|
5084
|
-
else {
|
|
5085
|
-
// The original predicate may have been wrapped in a `forwardRef()` call.
|
|
5086
|
-
switch (query.predicate.forwardRef) {
|
|
5087
|
-
case 0 /* ForwardRefHandling.None */:
|
|
5088
|
-
case 2 /* ForwardRefHandling.Unwrapped */:
|
|
5089
|
-
return query.predicate.expression;
|
|
5090
|
-
case 1 /* ForwardRefHandling.Wrapped */:
|
|
5091
|
-
return importExpr(Identifiers.resolveForwardRef).callFn([query.predicate.expression]);
|
|
5092
|
-
}
|
|
5093
|
-
}
|
|
5094
|
-
}
|
|
5095
5076
|
/**
|
|
5096
5077
|
* A representation for an object literal used during codegen of definition objects. The generic
|
|
5097
5078
|
* type `T` allows to reference a documented type of the generated structure, such that the
|
|
@@ -7861,6 +7842,10 @@ const animationKeywords = new Set([
|
|
|
7861
7842
|
// `steps()` function
|
|
7862
7843
|
'end', 'jump-both', 'jump-end', 'jump-none', 'jump-start', 'start'
|
|
7863
7844
|
]);
|
|
7845
|
+
/**
|
|
7846
|
+
* The following array contains all of the CSS at-rule identifiers which are scoped.
|
|
7847
|
+
*/
|
|
7848
|
+
const scopedAtRuleIdentifiers = ['@media', '@supports', '@document', '@layer', '@container', '@scope', '@starting-style'];
|
|
7864
7849
|
/**
|
|
7865
7850
|
* The following class has its origin from a port of shadowCSS from webcomponents.js to TypeScript.
|
|
7866
7851
|
* It has since diverge in many ways to tailor Angular's needs.
|
|
@@ -8348,9 +8333,7 @@ class ShadowCss {
|
|
|
8348
8333
|
if (rule.selector[0] !== '@') {
|
|
8349
8334
|
selector = this._scopeSelector(rule.selector, scopeSelector, hostSelector);
|
|
8350
8335
|
}
|
|
8351
|
-
else if (
|
|
8352
|
-
rule.selector.startsWith('@document') || rule.selector.startsWith('@layer') ||
|
|
8353
|
-
rule.selector.startsWith('@container') || rule.selector.startsWith('@scope')) {
|
|
8336
|
+
else if (scopedAtRuleIdentifiers.some(atRule => rule.selector.startsWith(atRule))) {
|
|
8354
8337
|
content = this._scopeSelectors(rule.content, scopeSelector, hostSelector);
|
|
8355
8338
|
}
|
|
8356
8339
|
else if (rule.selector.startsWith('@font-face') || rule.selector.startsWith('@page')) {
|
|
@@ -12282,7 +12265,7 @@ function createI18nContexts(job) {
|
|
|
12282
12265
|
if (op.message.id !== currentI18nOp.message.id) {
|
|
12283
12266
|
// This ICU is a sub-message inside its parent i18n block message. We need to give it
|
|
12284
12267
|
// its own context.
|
|
12285
|
-
const contextOp = createI18nContextOp(I18nContextKind.Icu, job.allocateXrefId(), currentI18nOp.
|
|
12268
|
+
const contextOp = createI18nContextOp(I18nContextKind.Icu, job.allocateXrefId(), currentI18nOp.root, op.message, null);
|
|
12286
12269
|
unit.create.push(contextOp);
|
|
12287
12270
|
op.context = contextOp.xref;
|
|
12288
12271
|
}
|
|
@@ -25042,810 +25025,281 @@ function ingestControlFlowInsertionPoint(unit, xref, node) {
|
|
|
25042
25025
|
|
|
25043
25026
|
const USE_TEMPLATE_PIPELINE = false;
|
|
25044
25027
|
|
|
25045
|
-
|
|
25028
|
+
class HtmlParser extends Parser {
|
|
25029
|
+
constructor() {
|
|
25030
|
+
super(getHtmlTagDefinition);
|
|
25031
|
+
}
|
|
25032
|
+
parse(source, url, options) {
|
|
25033
|
+
return super.parse(source, url, options);
|
|
25034
|
+
}
|
|
25035
|
+
}
|
|
25036
|
+
|
|
25037
|
+
const PRESERVE_WS_ATTR_NAME = 'ngPreserveWhitespaces';
|
|
25038
|
+
const SKIP_WS_TRIM_TAGS = new Set(['pre', 'template', 'textarea', 'script', 'style']);
|
|
25039
|
+
// Equivalent to \s with \u00a0 (non-breaking space) excluded.
|
|
25040
|
+
// Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
|
|
25041
|
+
const WS_CHARS = ' \f\n\r\t\v\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff';
|
|
25042
|
+
const NO_WS_REGEXP = new RegExp(`[^${WS_CHARS}]`);
|
|
25043
|
+
const WS_REPLACE_REGEXP = new RegExp(`[${WS_CHARS}]{2,}`, 'g');
|
|
25044
|
+
function hasPreserveWhitespacesAttr(attrs) {
|
|
25045
|
+
return attrs.some((attr) => attr.name === PRESERVE_WS_ATTR_NAME);
|
|
25046
|
+
}
|
|
25046
25047
|
/**
|
|
25047
|
-
*
|
|
25048
|
-
*
|
|
25049
|
-
*
|
|
25050
|
-
|
|
25051
|
-
|
|
25052
|
-
|
|
25053
|
-
|
|
25054
|
-
|
|
25055
|
-
* slot 2) cached value (all other values collected before it in string form)
|
|
25056
|
-
*
|
|
25057
|
-
* When a binding is registered it will place the following information in the `TData`:
|
|
25058
|
-
*
|
|
25059
|
-
* slot 1) prop name
|
|
25060
|
-
* slot 2) binding index that points to the previous style/class binding (and some extra config
|
|
25061
|
-
* values)
|
|
25062
|
-
*
|
|
25063
|
-
* Let's imagine we have a binding that looks like so:
|
|
25064
|
-
*
|
|
25065
|
-
* ```
|
|
25066
|
-
* <div [style.width]="x" [style.height]="y">
|
|
25067
|
-
* ```
|
|
25068
|
-
*
|
|
25069
|
-
* Our `LView` and `TData` data-structures look like so:
|
|
25070
|
-
*
|
|
25071
|
-
* ```typescript
|
|
25072
|
-
* LView = [
|
|
25073
|
-
* // ...
|
|
25074
|
-
* x, // value of x
|
|
25075
|
-
* "width: x",
|
|
25076
|
-
*
|
|
25077
|
-
* y, // value of y
|
|
25078
|
-
* "width: x; height: y",
|
|
25079
|
-
* // ...
|
|
25080
|
-
* ];
|
|
25081
|
-
*
|
|
25082
|
-
* TData = [
|
|
25083
|
-
* // ...
|
|
25084
|
-
* "width", // binding slot 20
|
|
25085
|
-
* 0,
|
|
25086
|
-
*
|
|
25087
|
-
* "height",
|
|
25088
|
-
* 20,
|
|
25089
|
-
* // ...
|
|
25090
|
-
* ];
|
|
25091
|
-
* ```
|
|
25092
|
-
*
|
|
25093
|
-
* */
|
|
25094
|
-
const MIN_STYLING_BINDING_SLOTS_REQUIRED = 2;
|
|
25048
|
+
* &ngsp; is a placeholder for non-removable space
|
|
25049
|
+
* &ngsp; is converted to the 0xE500 PUA (Private Use Areas) unicode character
|
|
25050
|
+
* and later on replaced by a space.
|
|
25051
|
+
*/
|
|
25052
|
+
function replaceNgsp(value) {
|
|
25053
|
+
// lexer is replacing the &ngsp; pseudo-entity with NGSP_UNICODE
|
|
25054
|
+
return value.replace(new RegExp(NGSP_UNICODE, 'g'), ' ');
|
|
25055
|
+
}
|
|
25095
25056
|
/**
|
|
25096
|
-
*
|
|
25097
|
-
*
|
|
25098
|
-
*
|
|
25099
|
-
*
|
|
25100
|
-
*
|
|
25101
|
-
*
|
|
25102
|
-
* The builder class below handles producing instructions for the following cases:
|
|
25103
|
-
*
|
|
25104
|
-
* - Static style/class attributes (style="..." and class="...")
|
|
25105
|
-
* - Dynamic style/class map bindings ([style]="map" and [class]="map|string")
|
|
25106
|
-
* - Dynamic style/class property bindings ([style.prop]="exp" and [class.name]="exp")
|
|
25107
|
-
*
|
|
25108
|
-
* Due to the complex relationship of all of these cases, the instructions generated
|
|
25109
|
-
* for these attributes/properties/bindings must be done so in the correct order. The
|
|
25110
|
-
* order which these must be generated is as follows:
|
|
25111
|
-
*
|
|
25112
|
-
* if (createMode) {
|
|
25113
|
-
* styling(...)
|
|
25114
|
-
* }
|
|
25115
|
-
* if (updateMode) {
|
|
25116
|
-
* styleMap(...)
|
|
25117
|
-
* classMap(...)
|
|
25118
|
-
* styleProp(...)
|
|
25119
|
-
* classProp(...)
|
|
25120
|
-
* }
|
|
25057
|
+
* This visitor can walk HTML parse tree and remove / trim text nodes using the following rules:
|
|
25058
|
+
* - consider spaces, tabs and new lines as whitespace characters;
|
|
25059
|
+
* - drop text nodes consisting of whitespace characters only;
|
|
25060
|
+
* - for all other text nodes replace consecutive whitespace characters with one space;
|
|
25061
|
+
* - convert &ngsp; pseudo-entity to a single space;
|
|
25121
25062
|
*
|
|
25122
|
-
*
|
|
25063
|
+
* Removal and trimming of whitespaces have positive performance impact (less code to generate
|
|
25064
|
+
* while compiling templates, faster view creation). At the same time it can be "destructive"
|
|
25065
|
+
* in some cases (whitespaces can influence layout). Because of the potential of breaking layout
|
|
25066
|
+
* this visitor is not activated by default in Angular 5 and people need to explicitly opt-in for
|
|
25067
|
+
* whitespace removal. The default option for whitespace removal will be revisited in Angular 6
|
|
25068
|
+
* and might be changed to "on" by default.
|
|
25123
25069
|
*/
|
|
25124
|
-
class
|
|
25125
|
-
|
|
25126
|
-
|
|
25127
|
-
|
|
25128
|
-
|
|
25129
|
-
|
|
25130
|
-
|
|
25131
|
-
|
|
25132
|
-
*/
|
|
25133
|
-
this.hasBindings = false;
|
|
25134
|
-
this.hasBindingsWithPipes = false;
|
|
25135
|
-
/** the input for [class] (if it exists) */
|
|
25136
|
-
this._classMapInput = null;
|
|
25137
|
-
/** the input for [style] (if it exists) */
|
|
25138
|
-
this._styleMapInput = null;
|
|
25139
|
-
/** an array of each [style.prop] input */
|
|
25140
|
-
this._singleStyleInputs = null;
|
|
25141
|
-
/** an array of each [class.name] input */
|
|
25142
|
-
this._singleClassInputs = null;
|
|
25143
|
-
this._lastStylingInput = null;
|
|
25144
|
-
this._firstStylingInput = null;
|
|
25145
|
-
// maps are used instead of hash maps because a Map will
|
|
25146
|
-
// retain the ordering of the keys
|
|
25147
|
-
/**
|
|
25148
|
-
* Represents the location of each style binding in the template
|
|
25149
|
-
* (e.g. `<div [style.width]="w" [style.height]="h">` implies
|
|
25150
|
-
* that `width=0` and `height=1`)
|
|
25151
|
-
*/
|
|
25152
|
-
this._stylesIndex = new Map();
|
|
25153
|
-
/**
|
|
25154
|
-
* Represents the location of each class binding in the template
|
|
25155
|
-
* (e.g. `<div [class.big]="b" [class.hidden]="h">` implies
|
|
25156
|
-
* that `big=0` and `hidden=1`)
|
|
25157
|
-
*/
|
|
25158
|
-
this._classesIndex = new Map();
|
|
25159
|
-
this._initialStyleValues = [];
|
|
25160
|
-
this._initialClassValues = [];
|
|
25070
|
+
class WhitespaceVisitor {
|
|
25071
|
+
visitElement(element, context) {
|
|
25072
|
+
if (SKIP_WS_TRIM_TAGS.has(element.name) || hasPreserveWhitespacesAttr(element.attrs)) {
|
|
25073
|
+
// don't descent into elements where we need to preserve whitespaces
|
|
25074
|
+
// but still visit all attributes to eliminate one used as a market to preserve WS
|
|
25075
|
+
return new Element(element.name, visitAll(this, element.attrs), element.children, element.sourceSpan, element.startSourceSpan, element.endSourceSpan, element.i18n);
|
|
25076
|
+
}
|
|
25077
|
+
return new Element(element.name, element.attrs, visitAllWithSiblings(this, element.children), element.sourceSpan, element.startSourceSpan, element.endSourceSpan, element.i18n);
|
|
25161
25078
|
}
|
|
25162
|
-
|
|
25163
|
-
|
|
25164
|
-
|
|
25165
|
-
|
|
25166
|
-
|
|
25167
|
-
|
|
25168
|
-
|
|
25169
|
-
|
|
25170
|
-
|
|
25171
|
-
|
|
25172
|
-
|
|
25173
|
-
|
|
25174
|
-
|
|
25175
|
-
let binding = null;
|
|
25176
|
-
let name = input.name;
|
|
25177
|
-
switch (input.type) {
|
|
25178
|
-
case 0 /* BindingType.Property */:
|
|
25179
|
-
binding = this.registerInputBasedOnName(name, input.value, input.sourceSpan);
|
|
25180
|
-
break;
|
|
25181
|
-
case 3 /* BindingType.Style */:
|
|
25182
|
-
binding = this.registerStyleInput(name, false, input.value, input.sourceSpan, input.unit);
|
|
25183
|
-
break;
|
|
25184
|
-
case 2 /* BindingType.Class */:
|
|
25185
|
-
binding = this.registerClassInput(name, false, input.value, input.sourceSpan);
|
|
25186
|
-
break;
|
|
25079
|
+
visitAttribute(attribute, context) {
|
|
25080
|
+
return attribute.name !== PRESERVE_WS_ATTR_NAME ? attribute : null;
|
|
25081
|
+
}
|
|
25082
|
+
visitText(text, context) {
|
|
25083
|
+
const isNotBlank = text.value.match(NO_WS_REGEXP);
|
|
25084
|
+
const hasExpansionSibling = context &&
|
|
25085
|
+
(context.prev instanceof Expansion || context.next instanceof Expansion);
|
|
25086
|
+
if (isNotBlank || hasExpansionSibling) {
|
|
25087
|
+
// Process the whitespace in the tokens of this Text node
|
|
25088
|
+
const tokens = text.tokens.map(token => token.type === 5 /* TokenType.TEXT */ ? createWhitespaceProcessedTextToken(token) : token);
|
|
25089
|
+
// Process the whitespace of the value of this Text node
|
|
25090
|
+
const value = processWhitespace(text.value);
|
|
25091
|
+
return new Text(value, text.sourceSpan, tokens, text.i18n);
|
|
25187
25092
|
}
|
|
25188
|
-
return
|
|
25093
|
+
return null;
|
|
25189
25094
|
}
|
|
25190
|
-
|
|
25191
|
-
|
|
25192
|
-
|
|
25193
|
-
|
|
25194
|
-
|
|
25195
|
-
|
|
25196
|
-
|
|
25197
|
-
|
|
25198
|
-
|
|
25199
|
-
|
|
25095
|
+
visitComment(comment, context) {
|
|
25096
|
+
return comment;
|
|
25097
|
+
}
|
|
25098
|
+
visitExpansion(expansion, context) {
|
|
25099
|
+
return expansion;
|
|
25100
|
+
}
|
|
25101
|
+
visitExpansionCase(expansionCase, context) {
|
|
25102
|
+
return expansionCase;
|
|
25103
|
+
}
|
|
25104
|
+
visitBlock(block, context) {
|
|
25105
|
+
return new Block(block.name, block.parameters, visitAllWithSiblings(this, block.children), block.sourceSpan, block.nameSpan, block.startSourceSpan, block.endSourceSpan);
|
|
25106
|
+
}
|
|
25107
|
+
visitBlockParameter(parameter, context) {
|
|
25108
|
+
return parameter;
|
|
25109
|
+
}
|
|
25110
|
+
}
|
|
25111
|
+
function createWhitespaceProcessedTextToken({ type, parts, sourceSpan }) {
|
|
25112
|
+
return { type, parts: [processWhitespace(parts[0])], sourceSpan };
|
|
25113
|
+
}
|
|
25114
|
+
function processWhitespace(text) {
|
|
25115
|
+
return replaceNgsp(text).replace(WS_REPLACE_REGEXP, ' ');
|
|
25116
|
+
}
|
|
25117
|
+
function removeWhitespaces(htmlAstWithErrors) {
|
|
25118
|
+
return new ParseTreeResult(visitAll(new WhitespaceVisitor(), htmlAstWithErrors.rootNodes), htmlAstWithErrors.errors);
|
|
25119
|
+
}
|
|
25120
|
+
function visitAllWithSiblings(visitor, nodes) {
|
|
25121
|
+
const result = [];
|
|
25122
|
+
nodes.forEach((ast, i) => {
|
|
25123
|
+
const context = { prev: nodes[i - 1], next: nodes[i + 1] };
|
|
25124
|
+
const astResult = ast.visit(visitor, context);
|
|
25125
|
+
if (astResult) {
|
|
25126
|
+
result.push(astResult);
|
|
25127
|
+
}
|
|
25128
|
+
});
|
|
25129
|
+
return result;
|
|
25130
|
+
}
|
|
25131
|
+
|
|
25132
|
+
const PROPERTY_PARTS_SEPARATOR = '.';
|
|
25133
|
+
const ATTRIBUTE_PREFIX = 'attr';
|
|
25134
|
+
const CLASS_PREFIX = 'class';
|
|
25135
|
+
const STYLE_PREFIX = 'style';
|
|
25136
|
+
const TEMPLATE_ATTR_PREFIX$1 = '*';
|
|
25137
|
+
const ANIMATE_PROP_PREFIX = 'animate-';
|
|
25138
|
+
/**
|
|
25139
|
+
* Parses bindings in templates and in the directive host area.
|
|
25140
|
+
*/
|
|
25141
|
+
class BindingParser {
|
|
25142
|
+
constructor(_exprParser, _interpolationConfig, _schemaRegistry, errors) {
|
|
25143
|
+
this._exprParser = _exprParser;
|
|
25144
|
+
this._interpolationConfig = _interpolationConfig;
|
|
25145
|
+
this._schemaRegistry = _schemaRegistry;
|
|
25146
|
+
this.errors = errors;
|
|
25147
|
+
}
|
|
25148
|
+
get interpolationConfig() {
|
|
25149
|
+
return this._interpolationConfig;
|
|
25150
|
+
}
|
|
25151
|
+
createBoundHostProperties(properties, sourceSpan) {
|
|
25152
|
+
const boundProps = [];
|
|
25153
|
+
for (const propName of Object.keys(properties)) {
|
|
25154
|
+
const expression = properties[propName];
|
|
25155
|
+
if (typeof expression === 'string') {
|
|
25156
|
+
this.parsePropertyBinding(propName, expression, true, sourceSpan, sourceSpan.start.offset, undefined, [],
|
|
25157
|
+
// Use the `sourceSpan` for `keySpan`. This isn't really accurate, but neither is the
|
|
25158
|
+
// sourceSpan, as it represents the sourceSpan of the host itself rather than the
|
|
25159
|
+
// source of the host binding (which doesn't exist in the template). Regardless,
|
|
25160
|
+
// neither of these values are used in Ivy but are only here to satisfy the function
|
|
25161
|
+
// signature. This should likely be refactored in the future so that `sourceSpan`
|
|
25162
|
+
// isn't being used inaccurately.
|
|
25163
|
+
boundProps, sourceSpan);
|
|
25200
25164
|
}
|
|
25201
25165
|
else {
|
|
25202
|
-
|
|
25166
|
+
this._reportError(`Value of the host property binding "${propName}" needs to be a string representing an expression but got "${expression}" (${typeof expression})`, sourceSpan);
|
|
25203
25167
|
}
|
|
25204
25168
|
}
|
|
25205
|
-
return
|
|
25169
|
+
return boundProps;
|
|
25206
25170
|
}
|
|
25207
|
-
|
|
25208
|
-
|
|
25209
|
-
|
|
25210
|
-
|
|
25211
|
-
|
|
25212
|
-
|
|
25213
|
-
|
|
25214
|
-
|
|
25215
|
-
|
|
25216
|
-
|
|
25217
|
-
|
|
25218
|
-
|
|
25219
|
-
|
|
25220
|
-
|
|
25221
|
-
|
|
25222
|
-
|
|
25223
|
-
(this._singleStyleInputs = this._singleStyleInputs || []).push(entry);
|
|
25224
|
-
registerIntoMap(this._stylesIndex, property);
|
|
25171
|
+
createDirectiveHostEventAsts(hostListeners, sourceSpan) {
|
|
25172
|
+
const targetEvents = [];
|
|
25173
|
+
for (const propName of Object.keys(hostListeners)) {
|
|
25174
|
+
const expression = hostListeners[propName];
|
|
25175
|
+
if (typeof expression === 'string') {
|
|
25176
|
+
// Use the `sourceSpan` for `keySpan` and `handlerSpan`. This isn't really accurate, but
|
|
25177
|
+
// neither is the `sourceSpan`, as it represents the `sourceSpan` of the host itself
|
|
25178
|
+
// rather than the source of the host binding (which doesn't exist in the template).
|
|
25179
|
+
// Regardless, neither of these values are used in Ivy but are only here to satisfy the
|
|
25180
|
+
// function signature. This should likely be refactored in the future so that `sourceSpan`
|
|
25181
|
+
// isn't being used inaccurately.
|
|
25182
|
+
this.parseEvent(propName, expression, /* isAssignmentEvent */ false, sourceSpan, sourceSpan, [], targetEvents, sourceSpan);
|
|
25183
|
+
}
|
|
25184
|
+
else {
|
|
25185
|
+
this._reportError(`Value of the host listener "${propName}" needs to be a string representing an expression but got "${expression}" (${typeof expression})`, sourceSpan);
|
|
25186
|
+
}
|
|
25225
25187
|
}
|
|
25226
|
-
|
|
25227
|
-
this._firstStylingInput = this._firstStylingInput || entry;
|
|
25228
|
-
this._checkForPipes(value);
|
|
25229
|
-
this.hasBindings = true;
|
|
25230
|
-
return entry;
|
|
25188
|
+
return targetEvents;
|
|
25231
25189
|
}
|
|
25232
|
-
|
|
25233
|
-
|
|
25234
|
-
|
|
25235
|
-
|
|
25236
|
-
|
|
25237
|
-
|
|
25238
|
-
|
|
25239
|
-
|
|
25240
|
-
}
|
|
25241
|
-
else {
|
|
25242
|
-
(this._singleClassInputs = this._singleClassInputs || []).push(entry);
|
|
25243
|
-
registerIntoMap(this._classesIndex, property);
|
|
25190
|
+
parseInterpolation(value, sourceSpan, interpolatedTokens) {
|
|
25191
|
+
const sourceInfo = sourceSpan.start.toString();
|
|
25192
|
+
const absoluteOffset = sourceSpan.fullStart.offset;
|
|
25193
|
+
try {
|
|
25194
|
+
const ast = this._exprParser.parseInterpolation(value, sourceInfo, absoluteOffset, interpolatedTokens, this._interpolationConfig);
|
|
25195
|
+
if (ast)
|
|
25196
|
+
this._reportExpressionParserErrors(ast.errors, sourceSpan);
|
|
25197
|
+
return ast;
|
|
25244
25198
|
}
|
|
25245
|
-
|
|
25246
|
-
|
|
25247
|
-
|
|
25248
|
-
this.hasBindings = true;
|
|
25249
|
-
return entry;
|
|
25250
|
-
}
|
|
25251
|
-
_checkForPipes(value) {
|
|
25252
|
-
if ((value instanceof ASTWithSource) && (value.ast instanceof BindingPipe)) {
|
|
25253
|
-
this.hasBindingsWithPipes = true;
|
|
25199
|
+
catch (e) {
|
|
25200
|
+
this._reportError(`${e}`, sourceSpan);
|
|
25201
|
+
return this._exprParser.wrapLiteralPrimitive('ERROR', sourceInfo, absoluteOffset);
|
|
25254
25202
|
}
|
|
25255
25203
|
}
|
|
25256
25204
|
/**
|
|
25257
|
-
*
|
|
25258
|
-
*
|
|
25259
|
-
*
|
|
25260
|
-
*/
|
|
25261
|
-
registerStyleAttr(value) {
|
|
25262
|
-
this._initialStyleValues = parse(value);
|
|
25263
|
-
this._hasInitialValues = true;
|
|
25264
|
-
}
|
|
25265
|
-
/**
|
|
25266
|
-
* Registers the element's static class string value to the builder.
|
|
25267
|
-
*
|
|
25268
|
-
* @param value the className string (e.g. `disabled gold zoom`)
|
|
25205
|
+
* Similar to `parseInterpolation`, but treats the provided string as a single expression
|
|
25206
|
+
* element that would normally appear within the interpolation prefix and suffix (`{{` and `}}`).
|
|
25207
|
+
* This is used for parsing the switch expression in ICUs.
|
|
25269
25208
|
*/
|
|
25270
|
-
|
|
25271
|
-
|
|
25272
|
-
|
|
25209
|
+
parseInterpolationExpression(expression, sourceSpan) {
|
|
25210
|
+
const sourceInfo = sourceSpan.start.toString();
|
|
25211
|
+
const absoluteOffset = sourceSpan.start.offset;
|
|
25212
|
+
try {
|
|
25213
|
+
const ast = this._exprParser.parseInterpolationExpression(expression, sourceInfo, absoluteOffset);
|
|
25214
|
+
if (ast)
|
|
25215
|
+
this._reportExpressionParserErrors(ast.errors, sourceSpan);
|
|
25216
|
+
return ast;
|
|
25217
|
+
}
|
|
25218
|
+
catch (e) {
|
|
25219
|
+
this._reportError(`${e}`, sourceSpan);
|
|
25220
|
+
return this._exprParser.wrapLiteralPrimitive('ERROR', sourceInfo, absoluteOffset);
|
|
25221
|
+
}
|
|
25273
25222
|
}
|
|
25274
25223
|
/**
|
|
25275
|
-
*
|
|
25224
|
+
* Parses the bindings in a microsyntax expression, and converts them to
|
|
25225
|
+
* `ParsedProperty` or `ParsedVariable`.
|
|
25276
25226
|
*
|
|
25277
|
-
* @param
|
|
25278
|
-
*
|
|
25227
|
+
* @param tplKey template binding name
|
|
25228
|
+
* @param tplValue template binding value
|
|
25229
|
+
* @param sourceSpan span of template binding relative to entire the template
|
|
25230
|
+
* @param absoluteValueOffset start of the tplValue relative to the entire template
|
|
25231
|
+
* @param targetMatchableAttrs potential attributes to match in the template
|
|
25232
|
+
* @param targetProps target property bindings in the template
|
|
25233
|
+
* @param targetVars target variables in the template
|
|
25279
25234
|
*/
|
|
25280
|
-
|
|
25281
|
-
|
|
25282
|
-
|
|
25283
|
-
|
|
25284
|
-
|
|
25285
|
-
|
|
25235
|
+
parseInlineTemplateBinding(tplKey, tplValue, sourceSpan, absoluteValueOffset, targetMatchableAttrs, targetProps, targetVars, isIvyAst) {
|
|
25236
|
+
const absoluteKeyOffset = sourceSpan.start.offset + TEMPLATE_ATTR_PREFIX$1.length;
|
|
25237
|
+
const bindings = this._parseTemplateBindings(tplKey, tplValue, sourceSpan, absoluteKeyOffset, absoluteValueOffset);
|
|
25238
|
+
for (const binding of bindings) {
|
|
25239
|
+
// sourceSpan is for the entire HTML attribute. bindingSpan is for a particular
|
|
25240
|
+
// binding within the microsyntax expression so it's more narrow than sourceSpan.
|
|
25241
|
+
const bindingSpan = moveParseSourceSpan(sourceSpan, binding.sourceSpan);
|
|
25242
|
+
const key = binding.key.source;
|
|
25243
|
+
const keySpan = moveParseSourceSpan(sourceSpan, binding.key.span);
|
|
25244
|
+
if (binding instanceof VariableBinding) {
|
|
25245
|
+
const value = binding.value ? binding.value.source : '$implicit';
|
|
25246
|
+
const valueSpan = binding.value ? moveParseSourceSpan(sourceSpan, binding.value.span) : undefined;
|
|
25247
|
+
targetVars.push(new ParsedVariable(key, value, bindingSpan, keySpan, valueSpan));
|
|
25286
25248
|
}
|
|
25287
|
-
|
|
25288
|
-
|
|
25289
|
-
|
|
25290
|
-
|
|
25291
|
-
|
|
25292
|
-
|
|
25249
|
+
else if (binding.value) {
|
|
25250
|
+
const srcSpan = isIvyAst ? bindingSpan : sourceSpan;
|
|
25251
|
+
const valueSpan = moveParseSourceSpan(sourceSpan, binding.value.ast.sourceSpan);
|
|
25252
|
+
this._parsePropertyAst(key, binding.value, srcSpan, keySpan, valueSpan, targetMatchableAttrs, targetProps);
|
|
25253
|
+
}
|
|
25254
|
+
else {
|
|
25255
|
+
targetMatchableAttrs.push([key, '' /* value */]);
|
|
25256
|
+
// Since this is a literal attribute with no RHS, source span should be
|
|
25257
|
+
// just the key span.
|
|
25258
|
+
this.parseLiteralAttr(key, null /* value */, keySpan, absoluteValueOffset, undefined /* valueSpan */, targetMatchableAttrs, targetProps, keySpan);
|
|
25293
25259
|
}
|
|
25294
25260
|
}
|
|
25295
25261
|
}
|
|
25296
25262
|
/**
|
|
25297
|
-
*
|
|
25263
|
+
* Parses the bindings in a microsyntax expression, e.g.
|
|
25264
|
+
* ```
|
|
25265
|
+
* <tag *tplKey="let value1 = prop; let value2 = localVar">
|
|
25266
|
+
* ```
|
|
25298
25267
|
*
|
|
25299
|
-
*
|
|
25300
|
-
*
|
|
25301
|
-
*
|
|
25268
|
+
* @param tplKey template binding name
|
|
25269
|
+
* @param tplValue template binding value
|
|
25270
|
+
* @param sourceSpan span of template binding relative to entire the template
|
|
25271
|
+
* @param absoluteKeyOffset start of the `tplKey`
|
|
25272
|
+
* @param absoluteValueOffset start of the `tplValue`
|
|
25302
25273
|
*/
|
|
25303
|
-
|
|
25304
|
-
|
|
25305
|
-
|
|
25306
|
-
|
|
25274
|
+
_parseTemplateBindings(tplKey, tplValue, sourceSpan, absoluteKeyOffset, absoluteValueOffset) {
|
|
25275
|
+
const sourceInfo = sourceSpan.start.toString();
|
|
25276
|
+
try {
|
|
25277
|
+
const bindingsResult = this._exprParser.parseTemplateBindings(tplKey, tplValue, sourceInfo, absoluteKeyOffset, absoluteValueOffset);
|
|
25278
|
+
this._reportExpressionParserErrors(bindingsResult.errors, sourceSpan);
|
|
25279
|
+
bindingsResult.warnings.forEach((warning) => {
|
|
25280
|
+
this._reportError(warning, sourceSpan, ParseErrorLevel.WARNING);
|
|
25281
|
+
});
|
|
25282
|
+
return bindingsResult.templateBindings;
|
|
25283
|
+
}
|
|
25284
|
+
catch (e) {
|
|
25285
|
+
this._reportError(`${e}`, sourceSpan);
|
|
25286
|
+
return [];
|
|
25307
25287
|
}
|
|
25308
25288
|
}
|
|
25309
|
-
|
|
25310
|
-
|
|
25311
|
-
|
|
25312
|
-
|
|
25313
|
-
|
|
25314
|
-
|
|
25315
|
-
|
|
25316
|
-
|
|
25317
|
-
|
|
25318
|
-
|
|
25319
|
-
|
|
25320
|
-
|
|
25321
|
-
|
|
25322
|
-
|
|
25323
|
-
*
|
|
25324
|
-
* The instruction data will contain all expressions for `styleMap` to function
|
|
25325
|
-
* which includes the `[style]` expression params.
|
|
25326
|
-
*/
|
|
25327
|
-
buildStyleMapInstruction(valueConverter) {
|
|
25328
|
-
if (this._styleMapInput) {
|
|
25329
|
-
return this._buildMapBasedInstruction(valueConverter, false, this._styleMapInput);
|
|
25330
|
-
}
|
|
25331
|
-
return null;
|
|
25332
|
-
}
|
|
25333
|
-
_buildMapBasedInstruction(valueConverter, isClassBased, stylingInput) {
|
|
25334
|
-
// each styling binding value is stored in the LView
|
|
25335
|
-
// map-based bindings allocate two slots: one for the
|
|
25336
|
-
// previous binding value and another for the previous
|
|
25337
|
-
// className or style attribute value.
|
|
25338
|
-
let totalBindingSlotsRequired = MIN_STYLING_BINDING_SLOTS_REQUIRED;
|
|
25339
|
-
// these values must be outside of the update block so that they can
|
|
25340
|
-
// be evaluated (the AST visit call) during creation time so that any
|
|
25341
|
-
// pipes can be picked up in time before the template is built
|
|
25342
|
-
const mapValue = stylingInput.value.visit(valueConverter);
|
|
25343
|
-
let reference;
|
|
25344
|
-
if (mapValue instanceof Interpolation$1) {
|
|
25345
|
-
totalBindingSlotsRequired += mapValue.expressions.length;
|
|
25346
|
-
reference = isClassBased ? getClassMapInterpolationExpression(mapValue) :
|
|
25347
|
-
getStyleMapInterpolationExpression(mapValue);
|
|
25348
|
-
}
|
|
25349
|
-
else {
|
|
25350
|
-
reference = isClassBased ? Identifiers.classMap : Identifiers.styleMap;
|
|
25351
|
-
}
|
|
25352
|
-
return {
|
|
25353
|
-
reference,
|
|
25354
|
-
calls: [{
|
|
25355
|
-
supportsInterpolation: true,
|
|
25356
|
-
sourceSpan: stylingInput.sourceSpan,
|
|
25357
|
-
allocateBindingSlots: totalBindingSlotsRequired,
|
|
25358
|
-
params: (convertFn) => {
|
|
25359
|
-
const convertResult = convertFn(mapValue);
|
|
25360
|
-
const params = Array.isArray(convertResult) ? convertResult : [convertResult];
|
|
25361
|
-
return params;
|
|
25362
|
-
}
|
|
25363
|
-
}]
|
|
25364
|
-
};
|
|
25365
|
-
}
|
|
25366
|
-
_buildSingleInputs(reference, inputs, valueConverter, getInterpolationExpressionFn, isClassBased) {
|
|
25367
|
-
const instructions = [];
|
|
25368
|
-
inputs.forEach(input => {
|
|
25369
|
-
const previousInstruction = instructions[instructions.length - 1];
|
|
25370
|
-
const value = input.value.visit(valueConverter);
|
|
25371
|
-
let referenceForCall = reference;
|
|
25372
|
-
// each styling binding value is stored in the LView
|
|
25373
|
-
// but there are two values stored for each binding:
|
|
25374
|
-
// 1) the value itself
|
|
25375
|
-
// 2) an intermediate value (concatenation of style up to this point).
|
|
25376
|
-
// We need to store the intermediate value so that we don't allocate
|
|
25377
|
-
// the strings on each CD.
|
|
25378
|
-
let totalBindingSlotsRequired = MIN_STYLING_BINDING_SLOTS_REQUIRED;
|
|
25379
|
-
if (value instanceof Interpolation$1) {
|
|
25380
|
-
totalBindingSlotsRequired += value.expressions.length;
|
|
25381
|
-
if (getInterpolationExpressionFn) {
|
|
25382
|
-
referenceForCall = getInterpolationExpressionFn(value);
|
|
25383
|
-
}
|
|
25384
|
-
}
|
|
25385
|
-
const call = {
|
|
25386
|
-
sourceSpan: input.sourceSpan,
|
|
25387
|
-
allocateBindingSlots: totalBindingSlotsRequired,
|
|
25388
|
-
supportsInterpolation: !!getInterpolationExpressionFn,
|
|
25389
|
-
params: (convertFn) => {
|
|
25390
|
-
// params => stylingProp(propName, value, suffix)
|
|
25391
|
-
const params = [];
|
|
25392
|
-
params.push(literal(input.name));
|
|
25393
|
-
const convertResult = convertFn(value);
|
|
25394
|
-
if (Array.isArray(convertResult)) {
|
|
25395
|
-
params.push(...convertResult);
|
|
25396
|
-
}
|
|
25397
|
-
else {
|
|
25398
|
-
params.push(convertResult);
|
|
25399
|
-
}
|
|
25400
|
-
// [style.prop] bindings may use suffix values (e.g. px, em, etc...), therefore,
|
|
25401
|
-
// if that is detected then we need to pass that in as an optional param.
|
|
25402
|
-
if (!isClassBased && input.suffix !== null) {
|
|
25403
|
-
params.push(literal(input.suffix));
|
|
25404
|
-
}
|
|
25405
|
-
return params;
|
|
25406
|
-
}
|
|
25407
|
-
};
|
|
25408
|
-
// If we ended up generating a call to the same instruction as the previous styling property
|
|
25409
|
-
// we can chain the calls together safely to save some bytes, otherwise we have to generate
|
|
25410
|
-
// a separate instruction call. This is primarily a concern with interpolation instructions
|
|
25411
|
-
// where we may start off with one `reference`, but end up using another based on the
|
|
25412
|
-
// number of interpolations.
|
|
25413
|
-
if (previousInstruction && previousInstruction.reference === referenceForCall) {
|
|
25414
|
-
previousInstruction.calls.push(call);
|
|
25415
|
-
}
|
|
25416
|
-
else {
|
|
25417
|
-
instructions.push({ reference: referenceForCall, calls: [call] });
|
|
25418
|
-
}
|
|
25419
|
-
});
|
|
25420
|
-
return instructions;
|
|
25421
|
-
}
|
|
25422
|
-
_buildClassInputs(valueConverter) {
|
|
25423
|
-
if (this._singleClassInputs) {
|
|
25424
|
-
return this._buildSingleInputs(Identifiers.classProp, this._singleClassInputs, valueConverter, null, true);
|
|
25425
|
-
}
|
|
25426
|
-
return [];
|
|
25427
|
-
}
|
|
25428
|
-
_buildStyleInputs(valueConverter) {
|
|
25429
|
-
if (this._singleStyleInputs) {
|
|
25430
|
-
return this._buildSingleInputs(Identifiers.styleProp, this._singleStyleInputs, valueConverter, getStylePropInterpolationExpression, false);
|
|
25431
|
-
}
|
|
25432
|
-
return [];
|
|
25433
|
-
}
|
|
25434
|
-
/**
|
|
25435
|
-
* Constructs all instructions which contain the expressions that will be placed
|
|
25436
|
-
* into the update block of a template function or a directive hostBindings function.
|
|
25437
|
-
*/
|
|
25438
|
-
buildUpdateLevelInstructions(valueConverter) {
|
|
25439
|
-
const instructions = [];
|
|
25440
|
-
if (this.hasBindings) {
|
|
25441
|
-
const styleMapInstruction = this.buildStyleMapInstruction(valueConverter);
|
|
25442
|
-
if (styleMapInstruction) {
|
|
25443
|
-
instructions.push(styleMapInstruction);
|
|
25444
|
-
}
|
|
25445
|
-
const classMapInstruction = this.buildClassMapInstruction(valueConverter);
|
|
25446
|
-
if (classMapInstruction) {
|
|
25447
|
-
instructions.push(classMapInstruction);
|
|
25448
|
-
}
|
|
25449
|
-
instructions.push(...this._buildStyleInputs(valueConverter));
|
|
25450
|
-
instructions.push(...this._buildClassInputs(valueConverter));
|
|
25451
|
-
}
|
|
25452
|
-
return instructions;
|
|
25453
|
-
}
|
|
25454
|
-
}
|
|
25455
|
-
function registerIntoMap(map, key) {
|
|
25456
|
-
if (!map.has(key)) {
|
|
25457
|
-
map.set(key, map.size);
|
|
25458
|
-
}
|
|
25459
|
-
}
|
|
25460
|
-
function parseProperty(name) {
|
|
25461
|
-
let hasOverrideFlag = false;
|
|
25462
|
-
const overrideIndex = name.indexOf(IMPORTANT_FLAG);
|
|
25463
|
-
if (overrideIndex !== -1) {
|
|
25464
|
-
name = overrideIndex > 0 ? name.substring(0, overrideIndex) : '';
|
|
25465
|
-
hasOverrideFlag = true;
|
|
25466
|
-
}
|
|
25467
|
-
let suffix = null;
|
|
25468
|
-
let property = name;
|
|
25469
|
-
const unitIndex = name.lastIndexOf('.');
|
|
25470
|
-
if (unitIndex > 0) {
|
|
25471
|
-
suffix = name.slice(unitIndex + 1);
|
|
25472
|
-
property = name.substring(0, unitIndex);
|
|
25473
|
-
}
|
|
25474
|
-
return { property, suffix, hasOverrideFlag };
|
|
25475
|
-
}
|
|
25476
|
-
/**
|
|
25477
|
-
* Gets the instruction to generate for an interpolated class map.
|
|
25478
|
-
* @param interpolation An Interpolation AST
|
|
25479
|
-
*/
|
|
25480
|
-
function getClassMapInterpolationExpression(interpolation) {
|
|
25481
|
-
switch (getInterpolationArgsLength(interpolation)) {
|
|
25482
|
-
case 1:
|
|
25483
|
-
return Identifiers.classMap;
|
|
25484
|
-
case 3:
|
|
25485
|
-
return Identifiers.classMapInterpolate1;
|
|
25486
|
-
case 5:
|
|
25487
|
-
return Identifiers.classMapInterpolate2;
|
|
25488
|
-
case 7:
|
|
25489
|
-
return Identifiers.classMapInterpolate3;
|
|
25490
|
-
case 9:
|
|
25491
|
-
return Identifiers.classMapInterpolate4;
|
|
25492
|
-
case 11:
|
|
25493
|
-
return Identifiers.classMapInterpolate5;
|
|
25494
|
-
case 13:
|
|
25495
|
-
return Identifiers.classMapInterpolate6;
|
|
25496
|
-
case 15:
|
|
25497
|
-
return Identifiers.classMapInterpolate7;
|
|
25498
|
-
case 17:
|
|
25499
|
-
return Identifiers.classMapInterpolate8;
|
|
25500
|
-
default:
|
|
25501
|
-
return Identifiers.classMapInterpolateV;
|
|
25502
|
-
}
|
|
25503
|
-
}
|
|
25504
|
-
/**
|
|
25505
|
-
* Gets the instruction to generate for an interpolated style map.
|
|
25506
|
-
* @param interpolation An Interpolation AST
|
|
25507
|
-
*/
|
|
25508
|
-
function getStyleMapInterpolationExpression(interpolation) {
|
|
25509
|
-
switch (getInterpolationArgsLength(interpolation)) {
|
|
25510
|
-
case 1:
|
|
25511
|
-
return Identifiers.styleMap;
|
|
25512
|
-
case 3:
|
|
25513
|
-
return Identifiers.styleMapInterpolate1;
|
|
25514
|
-
case 5:
|
|
25515
|
-
return Identifiers.styleMapInterpolate2;
|
|
25516
|
-
case 7:
|
|
25517
|
-
return Identifiers.styleMapInterpolate3;
|
|
25518
|
-
case 9:
|
|
25519
|
-
return Identifiers.styleMapInterpolate4;
|
|
25520
|
-
case 11:
|
|
25521
|
-
return Identifiers.styleMapInterpolate5;
|
|
25522
|
-
case 13:
|
|
25523
|
-
return Identifiers.styleMapInterpolate6;
|
|
25524
|
-
case 15:
|
|
25525
|
-
return Identifiers.styleMapInterpolate7;
|
|
25526
|
-
case 17:
|
|
25527
|
-
return Identifiers.styleMapInterpolate8;
|
|
25528
|
-
default:
|
|
25529
|
-
return Identifiers.styleMapInterpolateV;
|
|
25530
|
-
}
|
|
25531
|
-
}
|
|
25532
|
-
/**
|
|
25533
|
-
* Gets the instruction to generate for an interpolated style prop.
|
|
25534
|
-
* @param interpolation An Interpolation AST
|
|
25535
|
-
*/
|
|
25536
|
-
function getStylePropInterpolationExpression(interpolation) {
|
|
25537
|
-
switch (getInterpolationArgsLength(interpolation)) {
|
|
25538
|
-
case 1:
|
|
25539
|
-
return Identifiers.styleProp;
|
|
25540
|
-
case 3:
|
|
25541
|
-
return Identifiers.stylePropInterpolate1;
|
|
25542
|
-
case 5:
|
|
25543
|
-
return Identifiers.stylePropInterpolate2;
|
|
25544
|
-
case 7:
|
|
25545
|
-
return Identifiers.stylePropInterpolate3;
|
|
25546
|
-
case 9:
|
|
25547
|
-
return Identifiers.stylePropInterpolate4;
|
|
25548
|
-
case 11:
|
|
25549
|
-
return Identifiers.stylePropInterpolate5;
|
|
25550
|
-
case 13:
|
|
25551
|
-
return Identifiers.stylePropInterpolate6;
|
|
25552
|
-
case 15:
|
|
25553
|
-
return Identifiers.stylePropInterpolate7;
|
|
25554
|
-
case 17:
|
|
25555
|
-
return Identifiers.stylePropInterpolate8;
|
|
25556
|
-
default:
|
|
25557
|
-
return Identifiers.stylePropInterpolateV;
|
|
25558
|
-
}
|
|
25559
|
-
}
|
|
25560
|
-
/**
|
|
25561
|
-
* Checks whether property name is a custom CSS property.
|
|
25562
|
-
* See: https://www.w3.org/TR/css-variables-1
|
|
25563
|
-
*/
|
|
25564
|
-
function isCssCustomProperty(name) {
|
|
25565
|
-
return name.startsWith('--');
|
|
25566
|
-
}
|
|
25567
|
-
function isEmptyExpression(ast) {
|
|
25568
|
-
if (ast instanceof ASTWithSource) {
|
|
25569
|
-
ast = ast.ast;
|
|
25570
|
-
}
|
|
25571
|
-
return ast instanceof EmptyExpr$1;
|
|
25572
|
-
}
|
|
25573
|
-
|
|
25574
|
-
class HtmlParser extends Parser {
|
|
25575
|
-
constructor() {
|
|
25576
|
-
super(getHtmlTagDefinition);
|
|
25577
|
-
}
|
|
25578
|
-
parse(source, url, options) {
|
|
25579
|
-
return super.parse(source, url, options);
|
|
25580
|
-
}
|
|
25581
|
-
}
|
|
25582
|
-
|
|
25583
|
-
const PRESERVE_WS_ATTR_NAME = 'ngPreserveWhitespaces';
|
|
25584
|
-
const SKIP_WS_TRIM_TAGS = new Set(['pre', 'template', 'textarea', 'script', 'style']);
|
|
25585
|
-
// Equivalent to \s with \u00a0 (non-breaking space) excluded.
|
|
25586
|
-
// Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
|
|
25587
|
-
const WS_CHARS = ' \f\n\r\t\v\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff';
|
|
25588
|
-
const NO_WS_REGEXP = new RegExp(`[^${WS_CHARS}]`);
|
|
25589
|
-
const WS_REPLACE_REGEXP = new RegExp(`[${WS_CHARS}]{2,}`, 'g');
|
|
25590
|
-
function hasPreserveWhitespacesAttr(attrs) {
|
|
25591
|
-
return attrs.some((attr) => attr.name === PRESERVE_WS_ATTR_NAME);
|
|
25592
|
-
}
|
|
25593
|
-
/**
|
|
25594
|
-
* &ngsp; is a placeholder for non-removable space
|
|
25595
|
-
* &ngsp; is converted to the 0xE500 PUA (Private Use Areas) unicode character
|
|
25596
|
-
* and later on replaced by a space.
|
|
25597
|
-
*/
|
|
25598
|
-
function replaceNgsp(value) {
|
|
25599
|
-
// lexer is replacing the &ngsp; pseudo-entity with NGSP_UNICODE
|
|
25600
|
-
return value.replace(new RegExp(NGSP_UNICODE, 'g'), ' ');
|
|
25601
|
-
}
|
|
25602
|
-
/**
|
|
25603
|
-
* This visitor can walk HTML parse tree and remove / trim text nodes using the following rules:
|
|
25604
|
-
* - consider spaces, tabs and new lines as whitespace characters;
|
|
25605
|
-
* - drop text nodes consisting of whitespace characters only;
|
|
25606
|
-
* - for all other text nodes replace consecutive whitespace characters with one space;
|
|
25607
|
-
* - convert &ngsp; pseudo-entity to a single space;
|
|
25608
|
-
*
|
|
25609
|
-
* Removal and trimming of whitespaces have positive performance impact (less code to generate
|
|
25610
|
-
* while compiling templates, faster view creation). At the same time it can be "destructive"
|
|
25611
|
-
* in some cases (whitespaces can influence layout). Because of the potential of breaking layout
|
|
25612
|
-
* this visitor is not activated by default in Angular 5 and people need to explicitly opt-in for
|
|
25613
|
-
* whitespace removal. The default option for whitespace removal will be revisited in Angular 6
|
|
25614
|
-
* and might be changed to "on" by default.
|
|
25615
|
-
*/
|
|
25616
|
-
class WhitespaceVisitor {
|
|
25617
|
-
visitElement(element, context) {
|
|
25618
|
-
if (SKIP_WS_TRIM_TAGS.has(element.name) || hasPreserveWhitespacesAttr(element.attrs)) {
|
|
25619
|
-
// don't descent into elements where we need to preserve whitespaces
|
|
25620
|
-
// but still visit all attributes to eliminate one used as a market to preserve WS
|
|
25621
|
-
return new Element(element.name, visitAll(this, element.attrs), element.children, element.sourceSpan, element.startSourceSpan, element.endSourceSpan, element.i18n);
|
|
25622
|
-
}
|
|
25623
|
-
return new Element(element.name, element.attrs, visitAllWithSiblings(this, element.children), element.sourceSpan, element.startSourceSpan, element.endSourceSpan, element.i18n);
|
|
25624
|
-
}
|
|
25625
|
-
visitAttribute(attribute, context) {
|
|
25626
|
-
return attribute.name !== PRESERVE_WS_ATTR_NAME ? attribute : null;
|
|
25627
|
-
}
|
|
25628
|
-
visitText(text, context) {
|
|
25629
|
-
const isNotBlank = text.value.match(NO_WS_REGEXP);
|
|
25630
|
-
const hasExpansionSibling = context &&
|
|
25631
|
-
(context.prev instanceof Expansion || context.next instanceof Expansion);
|
|
25632
|
-
if (isNotBlank || hasExpansionSibling) {
|
|
25633
|
-
// Process the whitespace in the tokens of this Text node
|
|
25634
|
-
const tokens = text.tokens.map(token => token.type === 5 /* TokenType.TEXT */ ? createWhitespaceProcessedTextToken(token) : token);
|
|
25635
|
-
// Process the whitespace of the value of this Text node
|
|
25636
|
-
const value = processWhitespace(text.value);
|
|
25637
|
-
return new Text(value, text.sourceSpan, tokens, text.i18n);
|
|
25638
|
-
}
|
|
25639
|
-
return null;
|
|
25640
|
-
}
|
|
25641
|
-
visitComment(comment, context) {
|
|
25642
|
-
return comment;
|
|
25643
|
-
}
|
|
25644
|
-
visitExpansion(expansion, context) {
|
|
25645
|
-
return expansion;
|
|
25646
|
-
}
|
|
25647
|
-
visitExpansionCase(expansionCase, context) {
|
|
25648
|
-
return expansionCase;
|
|
25649
|
-
}
|
|
25650
|
-
visitBlock(block, context) {
|
|
25651
|
-
return new Block(block.name, block.parameters, visitAllWithSiblings(this, block.children), block.sourceSpan, block.nameSpan, block.startSourceSpan, block.endSourceSpan);
|
|
25652
|
-
}
|
|
25653
|
-
visitBlockParameter(parameter, context) {
|
|
25654
|
-
return parameter;
|
|
25655
|
-
}
|
|
25656
|
-
}
|
|
25657
|
-
function createWhitespaceProcessedTextToken({ type, parts, sourceSpan }) {
|
|
25658
|
-
return { type, parts: [processWhitespace(parts[0])], sourceSpan };
|
|
25659
|
-
}
|
|
25660
|
-
function processWhitespace(text) {
|
|
25661
|
-
return replaceNgsp(text).replace(WS_REPLACE_REGEXP, ' ');
|
|
25662
|
-
}
|
|
25663
|
-
function removeWhitespaces(htmlAstWithErrors) {
|
|
25664
|
-
return new ParseTreeResult(visitAll(new WhitespaceVisitor(), htmlAstWithErrors.rootNodes), htmlAstWithErrors.errors);
|
|
25665
|
-
}
|
|
25666
|
-
function visitAllWithSiblings(visitor, nodes) {
|
|
25667
|
-
const result = [];
|
|
25668
|
-
nodes.forEach((ast, i) => {
|
|
25669
|
-
const context = { prev: nodes[i - 1], next: nodes[i + 1] };
|
|
25670
|
-
const astResult = ast.visit(visitor, context);
|
|
25671
|
-
if (astResult) {
|
|
25672
|
-
result.push(astResult);
|
|
25673
|
-
}
|
|
25674
|
-
});
|
|
25675
|
-
return result;
|
|
25676
|
-
}
|
|
25677
|
-
|
|
25678
|
-
const PROPERTY_PARTS_SEPARATOR = '.';
|
|
25679
|
-
const ATTRIBUTE_PREFIX = 'attr';
|
|
25680
|
-
const CLASS_PREFIX = 'class';
|
|
25681
|
-
const STYLE_PREFIX = 'style';
|
|
25682
|
-
const TEMPLATE_ATTR_PREFIX$1 = '*';
|
|
25683
|
-
const ANIMATE_PROP_PREFIX = 'animate-';
|
|
25684
|
-
/**
|
|
25685
|
-
* Parses bindings in templates and in the directive host area.
|
|
25686
|
-
*/
|
|
25687
|
-
class BindingParser {
|
|
25688
|
-
constructor(_exprParser, _interpolationConfig, _schemaRegistry, errors) {
|
|
25689
|
-
this._exprParser = _exprParser;
|
|
25690
|
-
this._interpolationConfig = _interpolationConfig;
|
|
25691
|
-
this._schemaRegistry = _schemaRegistry;
|
|
25692
|
-
this.errors = errors;
|
|
25693
|
-
}
|
|
25694
|
-
get interpolationConfig() {
|
|
25695
|
-
return this._interpolationConfig;
|
|
25696
|
-
}
|
|
25697
|
-
createBoundHostProperties(properties, sourceSpan) {
|
|
25698
|
-
const boundProps = [];
|
|
25699
|
-
for (const propName of Object.keys(properties)) {
|
|
25700
|
-
const expression = properties[propName];
|
|
25701
|
-
if (typeof expression === 'string') {
|
|
25702
|
-
this.parsePropertyBinding(propName, expression, true, sourceSpan, sourceSpan.start.offset, undefined, [],
|
|
25703
|
-
// Use the `sourceSpan` for `keySpan`. This isn't really accurate, but neither is the
|
|
25704
|
-
// sourceSpan, as it represents the sourceSpan of the host itself rather than the
|
|
25705
|
-
// source of the host binding (which doesn't exist in the template). Regardless,
|
|
25706
|
-
// neither of these values are used in Ivy but are only here to satisfy the function
|
|
25707
|
-
// signature. This should likely be refactored in the future so that `sourceSpan`
|
|
25708
|
-
// isn't being used inaccurately.
|
|
25709
|
-
boundProps, sourceSpan);
|
|
25710
|
-
}
|
|
25711
|
-
else {
|
|
25712
|
-
this._reportError(`Value of the host property binding "${propName}" needs to be a string representing an expression but got "${expression}" (${typeof expression})`, sourceSpan);
|
|
25713
|
-
}
|
|
25714
|
-
}
|
|
25715
|
-
return boundProps;
|
|
25716
|
-
}
|
|
25717
|
-
createDirectiveHostEventAsts(hostListeners, sourceSpan) {
|
|
25718
|
-
const targetEvents = [];
|
|
25719
|
-
for (const propName of Object.keys(hostListeners)) {
|
|
25720
|
-
const expression = hostListeners[propName];
|
|
25721
|
-
if (typeof expression === 'string') {
|
|
25722
|
-
// Use the `sourceSpan` for `keySpan` and `handlerSpan`. This isn't really accurate, but
|
|
25723
|
-
// neither is the `sourceSpan`, as it represents the `sourceSpan` of the host itself
|
|
25724
|
-
// rather than the source of the host binding (which doesn't exist in the template).
|
|
25725
|
-
// Regardless, neither of these values are used in Ivy but are only here to satisfy the
|
|
25726
|
-
// function signature. This should likely be refactored in the future so that `sourceSpan`
|
|
25727
|
-
// isn't being used inaccurately.
|
|
25728
|
-
this.parseEvent(propName, expression, /* isAssignmentEvent */ false, sourceSpan, sourceSpan, [], targetEvents, sourceSpan);
|
|
25729
|
-
}
|
|
25730
|
-
else {
|
|
25731
|
-
this._reportError(`Value of the host listener "${propName}" needs to be a string representing an expression but got "${expression}" (${typeof expression})`, sourceSpan);
|
|
25732
|
-
}
|
|
25733
|
-
}
|
|
25734
|
-
return targetEvents;
|
|
25735
|
-
}
|
|
25736
|
-
parseInterpolation(value, sourceSpan, interpolatedTokens) {
|
|
25737
|
-
const sourceInfo = sourceSpan.start.toString();
|
|
25738
|
-
const absoluteOffset = sourceSpan.fullStart.offset;
|
|
25739
|
-
try {
|
|
25740
|
-
const ast = this._exprParser.parseInterpolation(value, sourceInfo, absoluteOffset, interpolatedTokens, this._interpolationConfig);
|
|
25741
|
-
if (ast)
|
|
25742
|
-
this._reportExpressionParserErrors(ast.errors, sourceSpan);
|
|
25743
|
-
return ast;
|
|
25744
|
-
}
|
|
25745
|
-
catch (e) {
|
|
25746
|
-
this._reportError(`${e}`, sourceSpan);
|
|
25747
|
-
return this._exprParser.wrapLiteralPrimitive('ERROR', sourceInfo, absoluteOffset);
|
|
25748
|
-
}
|
|
25749
|
-
}
|
|
25750
|
-
/**
|
|
25751
|
-
* Similar to `parseInterpolation`, but treats the provided string as a single expression
|
|
25752
|
-
* element that would normally appear within the interpolation prefix and suffix (`{{` and `}}`).
|
|
25753
|
-
* This is used for parsing the switch expression in ICUs.
|
|
25754
|
-
*/
|
|
25755
|
-
parseInterpolationExpression(expression, sourceSpan) {
|
|
25756
|
-
const sourceInfo = sourceSpan.start.toString();
|
|
25757
|
-
const absoluteOffset = sourceSpan.start.offset;
|
|
25758
|
-
try {
|
|
25759
|
-
const ast = this._exprParser.parseInterpolationExpression(expression, sourceInfo, absoluteOffset);
|
|
25760
|
-
if (ast)
|
|
25761
|
-
this._reportExpressionParserErrors(ast.errors, sourceSpan);
|
|
25762
|
-
return ast;
|
|
25763
|
-
}
|
|
25764
|
-
catch (e) {
|
|
25765
|
-
this._reportError(`${e}`, sourceSpan);
|
|
25766
|
-
return this._exprParser.wrapLiteralPrimitive('ERROR', sourceInfo, absoluteOffset);
|
|
25767
|
-
}
|
|
25768
|
-
}
|
|
25769
|
-
/**
|
|
25770
|
-
* Parses the bindings in a microsyntax expression, and converts them to
|
|
25771
|
-
* `ParsedProperty` or `ParsedVariable`.
|
|
25772
|
-
*
|
|
25773
|
-
* @param tplKey template binding name
|
|
25774
|
-
* @param tplValue template binding value
|
|
25775
|
-
* @param sourceSpan span of template binding relative to entire the template
|
|
25776
|
-
* @param absoluteValueOffset start of the tplValue relative to the entire template
|
|
25777
|
-
* @param targetMatchableAttrs potential attributes to match in the template
|
|
25778
|
-
* @param targetProps target property bindings in the template
|
|
25779
|
-
* @param targetVars target variables in the template
|
|
25780
|
-
*/
|
|
25781
|
-
parseInlineTemplateBinding(tplKey, tplValue, sourceSpan, absoluteValueOffset, targetMatchableAttrs, targetProps, targetVars, isIvyAst) {
|
|
25782
|
-
const absoluteKeyOffset = sourceSpan.start.offset + TEMPLATE_ATTR_PREFIX$1.length;
|
|
25783
|
-
const bindings = this._parseTemplateBindings(tplKey, tplValue, sourceSpan, absoluteKeyOffset, absoluteValueOffset);
|
|
25784
|
-
for (const binding of bindings) {
|
|
25785
|
-
// sourceSpan is for the entire HTML attribute. bindingSpan is for a particular
|
|
25786
|
-
// binding within the microsyntax expression so it's more narrow than sourceSpan.
|
|
25787
|
-
const bindingSpan = moveParseSourceSpan(sourceSpan, binding.sourceSpan);
|
|
25788
|
-
const key = binding.key.source;
|
|
25789
|
-
const keySpan = moveParseSourceSpan(sourceSpan, binding.key.span);
|
|
25790
|
-
if (binding instanceof VariableBinding) {
|
|
25791
|
-
const value = binding.value ? binding.value.source : '$implicit';
|
|
25792
|
-
const valueSpan = binding.value ? moveParseSourceSpan(sourceSpan, binding.value.span) : undefined;
|
|
25793
|
-
targetVars.push(new ParsedVariable(key, value, bindingSpan, keySpan, valueSpan));
|
|
25794
|
-
}
|
|
25795
|
-
else if (binding.value) {
|
|
25796
|
-
const srcSpan = isIvyAst ? bindingSpan : sourceSpan;
|
|
25797
|
-
const valueSpan = moveParseSourceSpan(sourceSpan, binding.value.ast.sourceSpan);
|
|
25798
|
-
this._parsePropertyAst(key, binding.value, srcSpan, keySpan, valueSpan, targetMatchableAttrs, targetProps);
|
|
25799
|
-
}
|
|
25800
|
-
else {
|
|
25801
|
-
targetMatchableAttrs.push([key, '' /* value */]);
|
|
25802
|
-
// Since this is a literal attribute with no RHS, source span should be
|
|
25803
|
-
// just the key span.
|
|
25804
|
-
this.parseLiteralAttr(key, null /* value */, keySpan, absoluteValueOffset, undefined /* valueSpan */, targetMatchableAttrs, targetProps, keySpan);
|
|
25805
|
-
}
|
|
25806
|
-
}
|
|
25807
|
-
}
|
|
25808
|
-
/**
|
|
25809
|
-
* Parses the bindings in a microsyntax expression, e.g.
|
|
25810
|
-
* ```
|
|
25811
|
-
* <tag *tplKey="let value1 = prop; let value2 = localVar">
|
|
25812
|
-
* ```
|
|
25813
|
-
*
|
|
25814
|
-
* @param tplKey template binding name
|
|
25815
|
-
* @param tplValue template binding value
|
|
25816
|
-
* @param sourceSpan span of template binding relative to entire the template
|
|
25817
|
-
* @param absoluteKeyOffset start of the `tplKey`
|
|
25818
|
-
* @param absoluteValueOffset start of the `tplValue`
|
|
25819
|
-
*/
|
|
25820
|
-
_parseTemplateBindings(tplKey, tplValue, sourceSpan, absoluteKeyOffset, absoluteValueOffset) {
|
|
25821
|
-
const sourceInfo = sourceSpan.start.toString();
|
|
25822
|
-
try {
|
|
25823
|
-
const bindingsResult = this._exprParser.parseTemplateBindings(tplKey, tplValue, sourceInfo, absoluteKeyOffset, absoluteValueOffset);
|
|
25824
|
-
this._reportExpressionParserErrors(bindingsResult.errors, sourceSpan);
|
|
25825
|
-
bindingsResult.warnings.forEach((warning) => {
|
|
25826
|
-
this._reportError(warning, sourceSpan, ParseErrorLevel.WARNING);
|
|
25827
|
-
});
|
|
25828
|
-
return bindingsResult.templateBindings;
|
|
25829
|
-
}
|
|
25830
|
-
catch (e) {
|
|
25831
|
-
this._reportError(`${e}`, sourceSpan);
|
|
25832
|
-
return [];
|
|
25833
|
-
}
|
|
25834
|
-
}
|
|
25835
|
-
parseLiteralAttr(name, value, sourceSpan, absoluteOffset, valueSpan, targetMatchableAttrs, targetProps, keySpan) {
|
|
25836
|
-
if (isAnimationLabel(name)) {
|
|
25837
|
-
name = name.substring(1);
|
|
25838
|
-
if (keySpan !== undefined) {
|
|
25839
|
-
keySpan = moveParseSourceSpan(keySpan, new AbsoluteSourceSpan(keySpan.start.offset + 1, keySpan.end.offset));
|
|
25840
|
-
}
|
|
25841
|
-
if (value) {
|
|
25842
|
-
this._reportError(`Assigning animation triggers via @prop="exp" attributes with an expression is invalid.` +
|
|
25843
|
-
` Use property bindings (e.g. [@prop]="exp") or use an attribute without a value (e.g. @prop) instead.`, sourceSpan, ParseErrorLevel.ERROR);
|
|
25844
|
-
}
|
|
25845
|
-
this._parseAnimation(name, value, sourceSpan, absoluteOffset, keySpan, valueSpan, targetMatchableAttrs, targetProps);
|
|
25846
|
-
}
|
|
25847
|
-
else {
|
|
25848
|
-
targetProps.push(new ParsedProperty(name, this._exprParser.wrapLiteralPrimitive(value, '', absoluteOffset), ParsedPropertyType.LITERAL_ATTR, sourceSpan, keySpan, valueSpan));
|
|
25289
|
+
parseLiteralAttr(name, value, sourceSpan, absoluteOffset, valueSpan, targetMatchableAttrs, targetProps, keySpan) {
|
|
25290
|
+
if (isAnimationLabel(name)) {
|
|
25291
|
+
name = name.substring(1);
|
|
25292
|
+
if (keySpan !== undefined) {
|
|
25293
|
+
keySpan = moveParseSourceSpan(keySpan, new AbsoluteSourceSpan(keySpan.start.offset + 1, keySpan.end.offset));
|
|
25294
|
+
}
|
|
25295
|
+
if (value) {
|
|
25296
|
+
this._reportError(`Assigning animation triggers via @prop="exp" attributes with an expression is invalid.` +
|
|
25297
|
+
` Use property bindings (e.g. [@prop]="exp") or use an attribute without a value (e.g. @prop) instead.`, sourceSpan, ParseErrorLevel.ERROR);
|
|
25298
|
+
}
|
|
25299
|
+
this._parseAnimation(name, value, sourceSpan, absoluteOffset, keySpan, valueSpan, targetMatchableAttrs, targetProps);
|
|
25300
|
+
}
|
|
25301
|
+
else {
|
|
25302
|
+
targetProps.push(new ParsedProperty(name, this._exprParser.wrapLiteralPrimitive(value, '', absoluteOffset), ParsedPropertyType.LITERAL_ATTR, sourceSpan, keySpan, valueSpan));
|
|
25849
25303
|
}
|
|
25850
25304
|
}
|
|
25851
25305
|
parsePropertyBinding(name, expression, isHost, sourceSpan, absoluteOffset, valueSpan, targetMatchableAttrs, targetProps, keySpan) {
|
|
@@ -27635,103 +27089,632 @@ class I18nContext {
|
|
|
27635
27089
|
this.appendTag(TagType.ELEMENT, node, index, true);
|
|
27636
27090
|
}
|
|
27637
27091
|
/**
|
|
27638
|
-
* Generates an instance of a child context based on the root one,
|
|
27639
|
-
* when we enter a nested template within I18n section.
|
|
27092
|
+
* Generates an instance of a child context based on the root one,
|
|
27093
|
+
* when we enter a nested template within I18n section.
|
|
27094
|
+
*
|
|
27095
|
+
* @param index Instruction index of corresponding i18nStart, which initiates this context
|
|
27096
|
+
* @param templateIndex Instruction index of a template which this context belongs to
|
|
27097
|
+
* @param meta Meta information (id, meaning, description, etc) associated with this context
|
|
27098
|
+
*
|
|
27099
|
+
* @returns I18nContext instance
|
|
27100
|
+
*/
|
|
27101
|
+
forkChildContext(index, templateIndex, meta) {
|
|
27102
|
+
return new I18nContext(index, this.ref, this.level + 1, templateIndex, meta, this._registry);
|
|
27103
|
+
}
|
|
27104
|
+
/**
|
|
27105
|
+
* Reconciles child context into parent one once the end of the i18n block is reached (i18nEnd).
|
|
27106
|
+
*
|
|
27107
|
+
* @param context Child I18nContext instance to be reconciled with parent context.
|
|
27108
|
+
*/
|
|
27109
|
+
reconcileChildContext(context) {
|
|
27110
|
+
// set the right context id for open and close
|
|
27111
|
+
// template tags, so we can use it as sub-block ids
|
|
27112
|
+
['start', 'close'].forEach((op) => {
|
|
27113
|
+
const key = context.meta[`${op}Name`];
|
|
27114
|
+
const phs = this.placeholders.get(key) || [];
|
|
27115
|
+
const tag = phs.find(findTemplateFn(this.id, context.templateIndex));
|
|
27116
|
+
if (tag) {
|
|
27117
|
+
tag.ctx = context.id;
|
|
27118
|
+
}
|
|
27119
|
+
});
|
|
27120
|
+
// reconcile placeholders
|
|
27121
|
+
const childPhs = context.placeholders;
|
|
27122
|
+
childPhs.forEach((values, key) => {
|
|
27123
|
+
const phs = this.placeholders.get(key);
|
|
27124
|
+
if (!phs) {
|
|
27125
|
+
this.placeholders.set(key, values);
|
|
27126
|
+
return;
|
|
27127
|
+
}
|
|
27128
|
+
// try to find matching template...
|
|
27129
|
+
const tmplIdx = phs.findIndex(findTemplateFn(context.id, context.templateIndex));
|
|
27130
|
+
if (tmplIdx >= 0) {
|
|
27131
|
+
// ... if found - replace it with nested template content
|
|
27132
|
+
const isCloseTag = key.startsWith('CLOSE');
|
|
27133
|
+
const isTemplateTag = key.endsWith('NG-TEMPLATE');
|
|
27134
|
+
if (isTemplateTag) {
|
|
27135
|
+
// current template's content is placed before or after
|
|
27136
|
+
// parent template tag, depending on the open/close attribute
|
|
27137
|
+
phs.splice(tmplIdx + (isCloseTag ? 0 : 1), 0, ...values);
|
|
27138
|
+
}
|
|
27139
|
+
else {
|
|
27140
|
+
const idx = isCloseTag ? values.length - 1 : 0;
|
|
27141
|
+
values[idx].tmpl = phs[tmplIdx];
|
|
27142
|
+
phs.splice(tmplIdx, 1, ...values);
|
|
27143
|
+
}
|
|
27144
|
+
}
|
|
27145
|
+
else {
|
|
27146
|
+
// ... otherwise just append content to placeholder value
|
|
27147
|
+
phs.push(...values);
|
|
27148
|
+
}
|
|
27149
|
+
this.placeholders.set(key, phs);
|
|
27150
|
+
});
|
|
27151
|
+
this._unresolvedCtxCount--;
|
|
27152
|
+
}
|
|
27153
|
+
}
|
|
27154
|
+
//
|
|
27155
|
+
// Helper methods
|
|
27156
|
+
//
|
|
27157
|
+
function wrap(symbol, index, contextId, closed) {
|
|
27158
|
+
const state = closed ? '/' : '';
|
|
27159
|
+
return wrapI18nPlaceholder(`${state}${symbol}${index}`, contextId);
|
|
27160
|
+
}
|
|
27161
|
+
function wrapTag(symbol, { index, ctx, isVoid }, closed) {
|
|
27162
|
+
return isVoid ? wrap(symbol, index, ctx) + wrap(symbol, index, ctx, true) :
|
|
27163
|
+
wrap(symbol, index, ctx, closed);
|
|
27164
|
+
}
|
|
27165
|
+
function findTemplateFn(ctx, templateIndex) {
|
|
27166
|
+
return (token) => typeof token === 'object' && token.type === TagType.TEMPLATE &&
|
|
27167
|
+
token.index === templateIndex && token.ctx === ctx;
|
|
27168
|
+
}
|
|
27169
|
+
function serializePlaceholderValue(value) {
|
|
27170
|
+
const element = (data, closed) => wrapTag('#', data, closed);
|
|
27171
|
+
const template = (data, closed) => wrapTag('*', data, closed);
|
|
27172
|
+
switch (value.type) {
|
|
27173
|
+
case TagType.ELEMENT:
|
|
27174
|
+
// close element tag
|
|
27175
|
+
if (value.closed) {
|
|
27176
|
+
return element(value, true) + (value.tmpl ? template(value.tmpl, true) : '');
|
|
27177
|
+
}
|
|
27178
|
+
// open element tag that also initiates a template
|
|
27179
|
+
if (value.tmpl) {
|
|
27180
|
+
return template(value.tmpl) + element(value) +
|
|
27181
|
+
(value.isVoid ? template(value.tmpl, true) : '');
|
|
27182
|
+
}
|
|
27183
|
+
return element(value);
|
|
27184
|
+
case TagType.TEMPLATE:
|
|
27185
|
+
return template(value, value.closed);
|
|
27186
|
+
default:
|
|
27187
|
+
return value;
|
|
27188
|
+
}
|
|
27189
|
+
}
|
|
27190
|
+
|
|
27191
|
+
const IMPORTANT_FLAG = '!important';
|
|
27192
|
+
/**
|
|
27193
|
+
* Minimum amount of binding slots required in the runtime for style/class bindings.
|
|
27194
|
+
*
|
|
27195
|
+
* Styling in Angular uses up two slots in the runtime LView/TData data structures to
|
|
27196
|
+
* record binding data, property information and metadata.
|
|
27197
|
+
*
|
|
27198
|
+
* When a binding is registered it will place the following information in the `LView`:
|
|
27199
|
+
*
|
|
27200
|
+
* slot 1) binding value
|
|
27201
|
+
* slot 2) cached value (all other values collected before it in string form)
|
|
27202
|
+
*
|
|
27203
|
+
* When a binding is registered it will place the following information in the `TData`:
|
|
27204
|
+
*
|
|
27205
|
+
* slot 1) prop name
|
|
27206
|
+
* slot 2) binding index that points to the previous style/class binding (and some extra config
|
|
27207
|
+
* values)
|
|
27208
|
+
*
|
|
27209
|
+
* Let's imagine we have a binding that looks like so:
|
|
27210
|
+
*
|
|
27211
|
+
* ```
|
|
27212
|
+
* <div [style.width]="x" [style.height]="y">
|
|
27213
|
+
* ```
|
|
27214
|
+
*
|
|
27215
|
+
* Our `LView` and `TData` data-structures look like so:
|
|
27216
|
+
*
|
|
27217
|
+
* ```typescript
|
|
27218
|
+
* LView = [
|
|
27219
|
+
* // ...
|
|
27220
|
+
* x, // value of x
|
|
27221
|
+
* "width: x",
|
|
27222
|
+
*
|
|
27223
|
+
* y, // value of y
|
|
27224
|
+
* "width: x; height: y",
|
|
27225
|
+
* // ...
|
|
27226
|
+
* ];
|
|
27227
|
+
*
|
|
27228
|
+
* TData = [
|
|
27229
|
+
* // ...
|
|
27230
|
+
* "width", // binding slot 20
|
|
27231
|
+
* 0,
|
|
27232
|
+
*
|
|
27233
|
+
* "height",
|
|
27234
|
+
* 20,
|
|
27235
|
+
* // ...
|
|
27236
|
+
* ];
|
|
27237
|
+
* ```
|
|
27238
|
+
*
|
|
27239
|
+
* */
|
|
27240
|
+
const MIN_STYLING_BINDING_SLOTS_REQUIRED = 2;
|
|
27241
|
+
/**
|
|
27242
|
+
* Produces creation/update instructions for all styling bindings (class and style)
|
|
27243
|
+
*
|
|
27244
|
+
* It also produces the creation instruction to register all initial styling values
|
|
27245
|
+
* (which are all the static class="..." and style="..." attribute values that exist
|
|
27246
|
+
* on an element within a template).
|
|
27247
|
+
*
|
|
27248
|
+
* The builder class below handles producing instructions for the following cases:
|
|
27249
|
+
*
|
|
27250
|
+
* - Static style/class attributes (style="..." and class="...")
|
|
27251
|
+
* - Dynamic style/class map bindings ([style]="map" and [class]="map|string")
|
|
27252
|
+
* - Dynamic style/class property bindings ([style.prop]="exp" and [class.name]="exp")
|
|
27253
|
+
*
|
|
27254
|
+
* Due to the complex relationship of all of these cases, the instructions generated
|
|
27255
|
+
* for these attributes/properties/bindings must be done so in the correct order. The
|
|
27256
|
+
* order which these must be generated is as follows:
|
|
27257
|
+
*
|
|
27258
|
+
* if (createMode) {
|
|
27259
|
+
* styling(...)
|
|
27260
|
+
* }
|
|
27261
|
+
* if (updateMode) {
|
|
27262
|
+
* styleMap(...)
|
|
27263
|
+
* classMap(...)
|
|
27264
|
+
* styleProp(...)
|
|
27265
|
+
* classProp(...)
|
|
27266
|
+
* }
|
|
27267
|
+
*
|
|
27268
|
+
* The creation/update methods within the builder class produce these instructions.
|
|
27269
|
+
*/
|
|
27270
|
+
class StylingBuilder {
|
|
27271
|
+
constructor(_directiveExpr) {
|
|
27272
|
+
this._directiveExpr = _directiveExpr;
|
|
27273
|
+
/** Whether or not there are any static styling values present */
|
|
27274
|
+
this._hasInitialValues = false;
|
|
27275
|
+
/**
|
|
27276
|
+
* Whether or not there are any styling bindings present
|
|
27277
|
+
* (i.e. `[style]`, `[class]`, `[style.prop]` or `[class.name]`)
|
|
27278
|
+
*/
|
|
27279
|
+
this.hasBindings = false;
|
|
27280
|
+
this.hasBindingsWithPipes = false;
|
|
27281
|
+
/** the input for [class] (if it exists) */
|
|
27282
|
+
this._classMapInput = null;
|
|
27283
|
+
/** the input for [style] (if it exists) */
|
|
27284
|
+
this._styleMapInput = null;
|
|
27285
|
+
/** an array of each [style.prop] input */
|
|
27286
|
+
this._singleStyleInputs = null;
|
|
27287
|
+
/** an array of each [class.name] input */
|
|
27288
|
+
this._singleClassInputs = null;
|
|
27289
|
+
this._lastStylingInput = null;
|
|
27290
|
+
this._firstStylingInput = null;
|
|
27291
|
+
// maps are used instead of hash maps because a Map will
|
|
27292
|
+
// retain the ordering of the keys
|
|
27293
|
+
/**
|
|
27294
|
+
* Represents the location of each style binding in the template
|
|
27295
|
+
* (e.g. `<div [style.width]="w" [style.height]="h">` implies
|
|
27296
|
+
* that `width=0` and `height=1`)
|
|
27297
|
+
*/
|
|
27298
|
+
this._stylesIndex = new Map();
|
|
27299
|
+
/**
|
|
27300
|
+
* Represents the location of each class binding in the template
|
|
27301
|
+
* (e.g. `<div [class.big]="b" [class.hidden]="h">` implies
|
|
27302
|
+
* that `big=0` and `hidden=1`)
|
|
27303
|
+
*/
|
|
27304
|
+
this._classesIndex = new Map();
|
|
27305
|
+
this._initialStyleValues = [];
|
|
27306
|
+
this._initialClassValues = [];
|
|
27307
|
+
}
|
|
27308
|
+
/**
|
|
27309
|
+
* Registers a given input to the styling builder to be later used when producing AOT code.
|
|
27310
|
+
*
|
|
27311
|
+
* The code below will only accept the input if it is somehow tied to styling (whether it be
|
|
27312
|
+
* style/class bindings or static style/class attributes).
|
|
27313
|
+
*/
|
|
27314
|
+
registerBoundInput(input) {
|
|
27315
|
+
// [attr.style] or [attr.class] are skipped in the code below,
|
|
27316
|
+
// they should not be treated as styling-based bindings since
|
|
27317
|
+
// they are intended to be written directly to the attr and
|
|
27318
|
+
// will therefore skip all style/class resolution that is present
|
|
27319
|
+
// with style="", [style]="" and [style.prop]="", class="",
|
|
27320
|
+
// [class.prop]="". [class]="" assignments
|
|
27321
|
+
let binding = null;
|
|
27322
|
+
let name = input.name;
|
|
27323
|
+
switch (input.type) {
|
|
27324
|
+
case 0 /* BindingType.Property */:
|
|
27325
|
+
binding = this.registerInputBasedOnName(name, input.value, input.sourceSpan);
|
|
27326
|
+
break;
|
|
27327
|
+
case 3 /* BindingType.Style */:
|
|
27328
|
+
binding = this.registerStyleInput(name, false, input.value, input.sourceSpan, input.unit);
|
|
27329
|
+
break;
|
|
27330
|
+
case 2 /* BindingType.Class */:
|
|
27331
|
+
binding = this.registerClassInput(name, false, input.value, input.sourceSpan);
|
|
27332
|
+
break;
|
|
27333
|
+
}
|
|
27334
|
+
return binding ? true : false;
|
|
27335
|
+
}
|
|
27336
|
+
registerInputBasedOnName(name, expression, sourceSpan) {
|
|
27337
|
+
let binding = null;
|
|
27338
|
+
const prefix = name.substring(0, 6);
|
|
27339
|
+
const isStyle = name === 'style' || prefix === 'style.' || prefix === 'style!';
|
|
27340
|
+
const isClass = !isStyle && (name === 'class' || prefix === 'class.' || prefix === 'class!');
|
|
27341
|
+
if (isStyle || isClass) {
|
|
27342
|
+
const isMapBased = name.charAt(5) !== '.'; // style.prop or class.prop makes this a no
|
|
27343
|
+
const property = name.slice(isMapBased ? 5 : 6); // the dot explains why there's a +1
|
|
27344
|
+
if (isStyle) {
|
|
27345
|
+
binding = this.registerStyleInput(property, isMapBased, expression, sourceSpan);
|
|
27346
|
+
}
|
|
27347
|
+
else {
|
|
27348
|
+
binding = this.registerClassInput(property, isMapBased, expression, sourceSpan);
|
|
27349
|
+
}
|
|
27350
|
+
}
|
|
27351
|
+
return binding;
|
|
27352
|
+
}
|
|
27353
|
+
registerStyleInput(name, isMapBased, value, sourceSpan, suffix) {
|
|
27354
|
+
if (isEmptyExpression(value)) {
|
|
27355
|
+
return null;
|
|
27356
|
+
}
|
|
27357
|
+
// CSS custom properties are case-sensitive so we shouldn't normalize them.
|
|
27358
|
+
// See: https://www.w3.org/TR/css-variables-1/#defining-variables
|
|
27359
|
+
if (!isCssCustomProperty(name)) {
|
|
27360
|
+
name = hyphenate(name);
|
|
27361
|
+
}
|
|
27362
|
+
const { property, hasOverrideFlag, suffix: bindingSuffix } = parseProperty(name);
|
|
27363
|
+
suffix = typeof suffix === 'string' && suffix.length !== 0 ? suffix : bindingSuffix;
|
|
27364
|
+
const entry = { name: property, suffix: suffix, value, sourceSpan, hasOverrideFlag };
|
|
27365
|
+
if (isMapBased) {
|
|
27366
|
+
this._styleMapInput = entry;
|
|
27367
|
+
}
|
|
27368
|
+
else {
|
|
27369
|
+
(this._singleStyleInputs = this._singleStyleInputs || []).push(entry);
|
|
27370
|
+
registerIntoMap(this._stylesIndex, property);
|
|
27371
|
+
}
|
|
27372
|
+
this._lastStylingInput = entry;
|
|
27373
|
+
this._firstStylingInput = this._firstStylingInput || entry;
|
|
27374
|
+
this._checkForPipes(value);
|
|
27375
|
+
this.hasBindings = true;
|
|
27376
|
+
return entry;
|
|
27377
|
+
}
|
|
27378
|
+
registerClassInput(name, isMapBased, value, sourceSpan) {
|
|
27379
|
+
if (isEmptyExpression(value)) {
|
|
27380
|
+
return null;
|
|
27381
|
+
}
|
|
27382
|
+
const { property, hasOverrideFlag } = parseProperty(name);
|
|
27383
|
+
const entry = { name: property, value, sourceSpan, hasOverrideFlag, suffix: null };
|
|
27384
|
+
if (isMapBased) {
|
|
27385
|
+
this._classMapInput = entry;
|
|
27386
|
+
}
|
|
27387
|
+
else {
|
|
27388
|
+
(this._singleClassInputs = this._singleClassInputs || []).push(entry);
|
|
27389
|
+
registerIntoMap(this._classesIndex, property);
|
|
27390
|
+
}
|
|
27391
|
+
this._lastStylingInput = entry;
|
|
27392
|
+
this._firstStylingInput = this._firstStylingInput || entry;
|
|
27393
|
+
this._checkForPipes(value);
|
|
27394
|
+
this.hasBindings = true;
|
|
27395
|
+
return entry;
|
|
27396
|
+
}
|
|
27397
|
+
_checkForPipes(value) {
|
|
27398
|
+
if ((value instanceof ASTWithSource) && (value.ast instanceof BindingPipe)) {
|
|
27399
|
+
this.hasBindingsWithPipes = true;
|
|
27400
|
+
}
|
|
27401
|
+
}
|
|
27402
|
+
/**
|
|
27403
|
+
* Registers the element's static style string value to the builder.
|
|
27404
|
+
*
|
|
27405
|
+
* @param value the style string (e.g. `width:100px; height:200px;`)
|
|
27406
|
+
*/
|
|
27407
|
+
registerStyleAttr(value) {
|
|
27408
|
+
this._initialStyleValues = parse(value);
|
|
27409
|
+
this._hasInitialValues = true;
|
|
27410
|
+
}
|
|
27411
|
+
/**
|
|
27412
|
+
* Registers the element's static class string value to the builder.
|
|
27413
|
+
*
|
|
27414
|
+
* @param value the className string (e.g. `disabled gold zoom`)
|
|
27415
|
+
*/
|
|
27416
|
+
registerClassAttr(value) {
|
|
27417
|
+
this._initialClassValues = value.trim().split(/\s+/g);
|
|
27418
|
+
this._hasInitialValues = true;
|
|
27419
|
+
}
|
|
27420
|
+
/**
|
|
27421
|
+
* Appends all styling-related expressions to the provided attrs array.
|
|
27640
27422
|
*
|
|
27641
|
-
* @param
|
|
27642
|
-
*
|
|
27643
|
-
|
|
27423
|
+
* @param attrs an existing array where each of the styling expressions
|
|
27424
|
+
* will be inserted into.
|
|
27425
|
+
*/
|
|
27426
|
+
populateInitialStylingAttrs(attrs) {
|
|
27427
|
+
// [CLASS_MARKER, 'foo', 'bar', 'baz' ...]
|
|
27428
|
+
if (this._initialClassValues.length) {
|
|
27429
|
+
attrs.push(literal(1 /* AttributeMarker.Classes */));
|
|
27430
|
+
for (let i = 0; i < this._initialClassValues.length; i++) {
|
|
27431
|
+
attrs.push(literal(this._initialClassValues[i]));
|
|
27432
|
+
}
|
|
27433
|
+
}
|
|
27434
|
+
// [STYLE_MARKER, 'width', '200px', 'height', '100px', ...]
|
|
27435
|
+
if (this._initialStyleValues.length) {
|
|
27436
|
+
attrs.push(literal(2 /* AttributeMarker.Styles */));
|
|
27437
|
+
for (let i = 0; i < this._initialStyleValues.length; i += 2) {
|
|
27438
|
+
attrs.push(literal(this._initialStyleValues[i]), literal(this._initialStyleValues[i + 1]));
|
|
27439
|
+
}
|
|
27440
|
+
}
|
|
27441
|
+
}
|
|
27442
|
+
/**
|
|
27443
|
+
* Builds an instruction with all the expressions and parameters for `elementHostAttrs`.
|
|
27644
27444
|
*
|
|
27645
|
-
*
|
|
27445
|
+
* The instruction generation code below is used for producing the AOT statement code which is
|
|
27446
|
+
* responsible for registering initial styles (within a directive hostBindings' creation block),
|
|
27447
|
+
* as well as any of the provided attribute values, to the directive host element.
|
|
27646
27448
|
*/
|
|
27647
|
-
|
|
27648
|
-
|
|
27449
|
+
assignHostAttrs(attrs, definitionMap) {
|
|
27450
|
+
if (this._directiveExpr && (attrs.length || this._hasInitialValues)) {
|
|
27451
|
+
this.populateInitialStylingAttrs(attrs);
|
|
27452
|
+
definitionMap.set('hostAttrs', literalArr(attrs));
|
|
27453
|
+
}
|
|
27649
27454
|
}
|
|
27650
27455
|
/**
|
|
27651
|
-
*
|
|
27456
|
+
* Builds an instruction with all the expressions and parameters for `classMap`.
|
|
27652
27457
|
*
|
|
27653
|
-
*
|
|
27458
|
+
* The instruction data will contain all expressions for `classMap` to function
|
|
27459
|
+
* which includes the `[class]` expression params.
|
|
27654
27460
|
*/
|
|
27655
|
-
|
|
27656
|
-
|
|
27657
|
-
|
|
27658
|
-
|
|
27659
|
-
|
|
27660
|
-
|
|
27661
|
-
|
|
27662
|
-
|
|
27663
|
-
|
|
27664
|
-
|
|
27665
|
-
|
|
27666
|
-
|
|
27667
|
-
|
|
27668
|
-
|
|
27669
|
-
|
|
27670
|
-
|
|
27671
|
-
|
|
27672
|
-
|
|
27673
|
-
|
|
27674
|
-
|
|
27675
|
-
|
|
27676
|
-
|
|
27677
|
-
|
|
27678
|
-
|
|
27679
|
-
|
|
27680
|
-
|
|
27681
|
-
|
|
27682
|
-
|
|
27683
|
-
|
|
27461
|
+
buildClassMapInstruction(valueConverter) {
|
|
27462
|
+
if (this._classMapInput) {
|
|
27463
|
+
return this._buildMapBasedInstruction(valueConverter, true, this._classMapInput);
|
|
27464
|
+
}
|
|
27465
|
+
return null;
|
|
27466
|
+
}
|
|
27467
|
+
/**
|
|
27468
|
+
* Builds an instruction with all the expressions and parameters for `styleMap`.
|
|
27469
|
+
*
|
|
27470
|
+
* The instruction data will contain all expressions for `styleMap` to function
|
|
27471
|
+
* which includes the `[style]` expression params.
|
|
27472
|
+
*/
|
|
27473
|
+
buildStyleMapInstruction(valueConverter) {
|
|
27474
|
+
if (this._styleMapInput) {
|
|
27475
|
+
return this._buildMapBasedInstruction(valueConverter, false, this._styleMapInput);
|
|
27476
|
+
}
|
|
27477
|
+
return null;
|
|
27478
|
+
}
|
|
27479
|
+
_buildMapBasedInstruction(valueConverter, isClassBased, stylingInput) {
|
|
27480
|
+
// each styling binding value is stored in the LView
|
|
27481
|
+
// map-based bindings allocate two slots: one for the
|
|
27482
|
+
// previous binding value and another for the previous
|
|
27483
|
+
// className or style attribute value.
|
|
27484
|
+
let totalBindingSlotsRequired = MIN_STYLING_BINDING_SLOTS_REQUIRED;
|
|
27485
|
+
// these values must be outside of the update block so that they can
|
|
27486
|
+
// be evaluated (the AST visit call) during creation time so that any
|
|
27487
|
+
// pipes can be picked up in time before the template is built
|
|
27488
|
+
const mapValue = stylingInput.value.visit(valueConverter);
|
|
27489
|
+
let reference;
|
|
27490
|
+
if (mapValue instanceof Interpolation$1) {
|
|
27491
|
+
totalBindingSlotsRequired += mapValue.expressions.length;
|
|
27492
|
+
reference = isClassBased ? getClassMapInterpolationExpression(mapValue) :
|
|
27493
|
+
getStyleMapInterpolationExpression(mapValue);
|
|
27494
|
+
}
|
|
27495
|
+
else {
|
|
27496
|
+
reference = isClassBased ? Identifiers.classMap : Identifiers.styleMap;
|
|
27497
|
+
}
|
|
27498
|
+
return {
|
|
27499
|
+
reference,
|
|
27500
|
+
calls: [{
|
|
27501
|
+
supportsInterpolation: true,
|
|
27502
|
+
sourceSpan: stylingInput.sourceSpan,
|
|
27503
|
+
allocateBindingSlots: totalBindingSlotsRequired,
|
|
27504
|
+
params: (convertFn) => {
|
|
27505
|
+
const convertResult = convertFn(mapValue);
|
|
27506
|
+
const params = Array.isArray(convertResult) ? convertResult : [convertResult];
|
|
27507
|
+
return params;
|
|
27508
|
+
}
|
|
27509
|
+
}]
|
|
27510
|
+
};
|
|
27511
|
+
}
|
|
27512
|
+
_buildSingleInputs(reference, inputs, valueConverter, getInterpolationExpressionFn, isClassBased) {
|
|
27513
|
+
const instructions = [];
|
|
27514
|
+
inputs.forEach(input => {
|
|
27515
|
+
const previousInstruction = instructions[instructions.length - 1];
|
|
27516
|
+
const value = input.value.visit(valueConverter);
|
|
27517
|
+
let referenceForCall = reference;
|
|
27518
|
+
// each styling binding value is stored in the LView
|
|
27519
|
+
// but there are two values stored for each binding:
|
|
27520
|
+
// 1) the value itself
|
|
27521
|
+
// 2) an intermediate value (concatenation of style up to this point).
|
|
27522
|
+
// We need to store the intermediate value so that we don't allocate
|
|
27523
|
+
// the strings on each CD.
|
|
27524
|
+
let totalBindingSlotsRequired = MIN_STYLING_BINDING_SLOTS_REQUIRED;
|
|
27525
|
+
if (value instanceof Interpolation$1) {
|
|
27526
|
+
totalBindingSlotsRequired += value.expressions.length;
|
|
27527
|
+
if (getInterpolationExpressionFn) {
|
|
27528
|
+
referenceForCall = getInterpolationExpressionFn(value);
|
|
27684
27529
|
}
|
|
27685
|
-
|
|
27686
|
-
|
|
27687
|
-
|
|
27688
|
-
|
|
27530
|
+
}
|
|
27531
|
+
const call = {
|
|
27532
|
+
sourceSpan: input.sourceSpan,
|
|
27533
|
+
allocateBindingSlots: totalBindingSlotsRequired,
|
|
27534
|
+
supportsInterpolation: !!getInterpolationExpressionFn,
|
|
27535
|
+
params: (convertFn) => {
|
|
27536
|
+
// params => stylingProp(propName, value, suffix)
|
|
27537
|
+
const params = [];
|
|
27538
|
+
params.push(literal(input.name));
|
|
27539
|
+
const convertResult = convertFn(value);
|
|
27540
|
+
if (Array.isArray(convertResult)) {
|
|
27541
|
+
params.push(...convertResult);
|
|
27542
|
+
}
|
|
27543
|
+
else {
|
|
27544
|
+
params.push(convertResult);
|
|
27545
|
+
}
|
|
27546
|
+
// [style.prop] bindings may use suffix values (e.g. px, em, etc...), therefore,
|
|
27547
|
+
// if that is detected then we need to pass that in as an optional param.
|
|
27548
|
+
if (!isClassBased && input.suffix !== null) {
|
|
27549
|
+
params.push(literal(input.suffix));
|
|
27550
|
+
}
|
|
27551
|
+
return params;
|
|
27689
27552
|
}
|
|
27553
|
+
};
|
|
27554
|
+
// If we ended up generating a call to the same instruction as the previous styling property
|
|
27555
|
+
// we can chain the calls together safely to save some bytes, otherwise we have to generate
|
|
27556
|
+
// a separate instruction call. This is primarily a concern with interpolation instructions
|
|
27557
|
+
// where we may start off with one `reference`, but end up using another based on the
|
|
27558
|
+
// number of interpolations.
|
|
27559
|
+
if (previousInstruction && previousInstruction.reference === referenceForCall) {
|
|
27560
|
+
previousInstruction.calls.push(call);
|
|
27690
27561
|
}
|
|
27691
27562
|
else {
|
|
27692
|
-
|
|
27693
|
-
phs.push(...values);
|
|
27563
|
+
instructions.push({ reference: referenceForCall, calls: [call] });
|
|
27694
27564
|
}
|
|
27695
|
-
this.placeholders.set(key, phs);
|
|
27696
27565
|
});
|
|
27697
|
-
|
|
27566
|
+
return instructions;
|
|
27567
|
+
}
|
|
27568
|
+
_buildClassInputs(valueConverter) {
|
|
27569
|
+
if (this._singleClassInputs) {
|
|
27570
|
+
return this._buildSingleInputs(Identifiers.classProp, this._singleClassInputs, valueConverter, null, true);
|
|
27571
|
+
}
|
|
27572
|
+
return [];
|
|
27573
|
+
}
|
|
27574
|
+
_buildStyleInputs(valueConverter) {
|
|
27575
|
+
if (this._singleStyleInputs) {
|
|
27576
|
+
return this._buildSingleInputs(Identifiers.styleProp, this._singleStyleInputs, valueConverter, getStylePropInterpolationExpression, false);
|
|
27577
|
+
}
|
|
27578
|
+
return [];
|
|
27579
|
+
}
|
|
27580
|
+
/**
|
|
27581
|
+
* Constructs all instructions which contain the expressions that will be placed
|
|
27582
|
+
* into the update block of a template function or a directive hostBindings function.
|
|
27583
|
+
*/
|
|
27584
|
+
buildUpdateLevelInstructions(valueConverter) {
|
|
27585
|
+
const instructions = [];
|
|
27586
|
+
if (this.hasBindings) {
|
|
27587
|
+
const styleMapInstruction = this.buildStyleMapInstruction(valueConverter);
|
|
27588
|
+
if (styleMapInstruction) {
|
|
27589
|
+
instructions.push(styleMapInstruction);
|
|
27590
|
+
}
|
|
27591
|
+
const classMapInstruction = this.buildClassMapInstruction(valueConverter);
|
|
27592
|
+
if (classMapInstruction) {
|
|
27593
|
+
instructions.push(classMapInstruction);
|
|
27594
|
+
}
|
|
27595
|
+
instructions.push(...this._buildStyleInputs(valueConverter));
|
|
27596
|
+
instructions.push(...this._buildClassInputs(valueConverter));
|
|
27597
|
+
}
|
|
27598
|
+
return instructions;
|
|
27698
27599
|
}
|
|
27699
27600
|
}
|
|
27700
|
-
|
|
27701
|
-
|
|
27702
|
-
|
|
27703
|
-
|
|
27704
|
-
const state = closed ? '/' : '';
|
|
27705
|
-
return wrapI18nPlaceholder(`${state}${symbol}${index}`, contextId);
|
|
27601
|
+
function registerIntoMap(map, key) {
|
|
27602
|
+
if (!map.has(key)) {
|
|
27603
|
+
map.set(key, map.size);
|
|
27604
|
+
}
|
|
27706
27605
|
}
|
|
27707
|
-
function
|
|
27708
|
-
|
|
27709
|
-
|
|
27606
|
+
function parseProperty(name) {
|
|
27607
|
+
let hasOverrideFlag = false;
|
|
27608
|
+
const overrideIndex = name.indexOf(IMPORTANT_FLAG);
|
|
27609
|
+
if (overrideIndex !== -1) {
|
|
27610
|
+
name = overrideIndex > 0 ? name.substring(0, overrideIndex) : '';
|
|
27611
|
+
hasOverrideFlag = true;
|
|
27612
|
+
}
|
|
27613
|
+
let suffix = null;
|
|
27614
|
+
let property = name;
|
|
27615
|
+
const unitIndex = name.lastIndexOf('.');
|
|
27616
|
+
if (unitIndex > 0) {
|
|
27617
|
+
suffix = name.slice(unitIndex + 1);
|
|
27618
|
+
property = name.substring(0, unitIndex);
|
|
27619
|
+
}
|
|
27620
|
+
return { property, suffix, hasOverrideFlag };
|
|
27710
27621
|
}
|
|
27711
|
-
|
|
27712
|
-
|
|
27713
|
-
|
|
27622
|
+
/**
|
|
27623
|
+
* Gets the instruction to generate for an interpolated class map.
|
|
27624
|
+
* @param interpolation An Interpolation AST
|
|
27625
|
+
*/
|
|
27626
|
+
function getClassMapInterpolationExpression(interpolation) {
|
|
27627
|
+
switch (getInterpolationArgsLength(interpolation)) {
|
|
27628
|
+
case 1:
|
|
27629
|
+
return Identifiers.classMap;
|
|
27630
|
+
case 3:
|
|
27631
|
+
return Identifiers.classMapInterpolate1;
|
|
27632
|
+
case 5:
|
|
27633
|
+
return Identifiers.classMapInterpolate2;
|
|
27634
|
+
case 7:
|
|
27635
|
+
return Identifiers.classMapInterpolate3;
|
|
27636
|
+
case 9:
|
|
27637
|
+
return Identifiers.classMapInterpolate4;
|
|
27638
|
+
case 11:
|
|
27639
|
+
return Identifiers.classMapInterpolate5;
|
|
27640
|
+
case 13:
|
|
27641
|
+
return Identifiers.classMapInterpolate6;
|
|
27642
|
+
case 15:
|
|
27643
|
+
return Identifiers.classMapInterpolate7;
|
|
27644
|
+
case 17:
|
|
27645
|
+
return Identifiers.classMapInterpolate8;
|
|
27646
|
+
default:
|
|
27647
|
+
return Identifiers.classMapInterpolateV;
|
|
27648
|
+
}
|
|
27714
27649
|
}
|
|
27715
|
-
|
|
27716
|
-
|
|
27717
|
-
|
|
27718
|
-
|
|
27719
|
-
|
|
27720
|
-
|
|
27721
|
-
|
|
27722
|
-
|
|
27723
|
-
|
|
27724
|
-
|
|
27725
|
-
|
|
27726
|
-
|
|
27727
|
-
|
|
27728
|
-
|
|
27729
|
-
|
|
27730
|
-
|
|
27731
|
-
|
|
27650
|
+
/**
|
|
27651
|
+
* Gets the instruction to generate for an interpolated style map.
|
|
27652
|
+
* @param interpolation An Interpolation AST
|
|
27653
|
+
*/
|
|
27654
|
+
function getStyleMapInterpolationExpression(interpolation) {
|
|
27655
|
+
switch (getInterpolationArgsLength(interpolation)) {
|
|
27656
|
+
case 1:
|
|
27657
|
+
return Identifiers.styleMap;
|
|
27658
|
+
case 3:
|
|
27659
|
+
return Identifiers.styleMapInterpolate1;
|
|
27660
|
+
case 5:
|
|
27661
|
+
return Identifiers.styleMapInterpolate2;
|
|
27662
|
+
case 7:
|
|
27663
|
+
return Identifiers.styleMapInterpolate3;
|
|
27664
|
+
case 9:
|
|
27665
|
+
return Identifiers.styleMapInterpolate4;
|
|
27666
|
+
case 11:
|
|
27667
|
+
return Identifiers.styleMapInterpolate5;
|
|
27668
|
+
case 13:
|
|
27669
|
+
return Identifiers.styleMapInterpolate6;
|
|
27670
|
+
case 15:
|
|
27671
|
+
return Identifiers.styleMapInterpolate7;
|
|
27672
|
+
case 17:
|
|
27673
|
+
return Identifiers.styleMapInterpolate8;
|
|
27732
27674
|
default:
|
|
27733
|
-
return
|
|
27675
|
+
return Identifiers.styleMapInterpolateV;
|
|
27676
|
+
}
|
|
27677
|
+
}
|
|
27678
|
+
/**
|
|
27679
|
+
* Gets the instruction to generate for an interpolated style prop.
|
|
27680
|
+
* @param interpolation An Interpolation AST
|
|
27681
|
+
*/
|
|
27682
|
+
function getStylePropInterpolationExpression(interpolation) {
|
|
27683
|
+
switch (getInterpolationArgsLength(interpolation)) {
|
|
27684
|
+
case 1:
|
|
27685
|
+
return Identifiers.styleProp;
|
|
27686
|
+
case 3:
|
|
27687
|
+
return Identifiers.stylePropInterpolate1;
|
|
27688
|
+
case 5:
|
|
27689
|
+
return Identifiers.stylePropInterpolate2;
|
|
27690
|
+
case 7:
|
|
27691
|
+
return Identifiers.stylePropInterpolate3;
|
|
27692
|
+
case 9:
|
|
27693
|
+
return Identifiers.stylePropInterpolate4;
|
|
27694
|
+
case 11:
|
|
27695
|
+
return Identifiers.stylePropInterpolate5;
|
|
27696
|
+
case 13:
|
|
27697
|
+
return Identifiers.stylePropInterpolate6;
|
|
27698
|
+
case 15:
|
|
27699
|
+
return Identifiers.stylePropInterpolate7;
|
|
27700
|
+
case 17:
|
|
27701
|
+
return Identifiers.stylePropInterpolate8;
|
|
27702
|
+
default:
|
|
27703
|
+
return Identifiers.stylePropInterpolateV;
|
|
27704
|
+
}
|
|
27705
|
+
}
|
|
27706
|
+
/**
|
|
27707
|
+
* Checks whether property name is a custom CSS property.
|
|
27708
|
+
* See: https://www.w3.org/TR/css-variables-1
|
|
27709
|
+
*/
|
|
27710
|
+
function isCssCustomProperty(name) {
|
|
27711
|
+
return name.startsWith('--');
|
|
27712
|
+
}
|
|
27713
|
+
function isEmptyExpression(ast) {
|
|
27714
|
+
if (ast instanceof ASTWithSource) {
|
|
27715
|
+
ast = ast.ast;
|
|
27734
27716
|
}
|
|
27717
|
+
return ast instanceof EmptyExpr$1;
|
|
27735
27718
|
}
|
|
27736
27719
|
|
|
27737
27720
|
// Selector attribute name of `<ng-content>`
|
|
@@ -30042,6 +30025,171 @@ function createClosureModeGuard() {
|
|
|
30042
30025
|
.and(variable(NG_I18N_CLOSURE_MODE));
|
|
30043
30026
|
}
|
|
30044
30027
|
|
|
30028
|
+
/**
|
|
30029
|
+
* Translates query flags into `TQueryFlags` type in
|
|
30030
|
+
* packages/core/src/render3/interfaces/query.ts
|
|
30031
|
+
* @param query
|
|
30032
|
+
*/
|
|
30033
|
+
function toQueryFlags(query) {
|
|
30034
|
+
return ((query.descendants ? 1 /* QueryFlags.descendants */ : 0 /* QueryFlags.none */) |
|
|
30035
|
+
(query.static ? 2 /* QueryFlags.isStatic */ : 0 /* QueryFlags.none */) |
|
|
30036
|
+
(query.emitDistinctChangesOnly ? 4 /* QueryFlags.emitDistinctChangesOnly */ : 0 /* QueryFlags.none */));
|
|
30037
|
+
}
|
|
30038
|
+
function getQueryPredicate(query, constantPool) {
|
|
30039
|
+
if (Array.isArray(query.predicate)) {
|
|
30040
|
+
let predicate = [];
|
|
30041
|
+
query.predicate.forEach((selector) => {
|
|
30042
|
+
// Each item in predicates array may contain strings with comma-separated refs
|
|
30043
|
+
// (for ex. 'ref, ref1, ..., refN'), thus we extract individual refs and store them
|
|
30044
|
+
// as separate array entities
|
|
30045
|
+
const selectors = selector.split(',').map((token) => literal(token.trim()));
|
|
30046
|
+
predicate.push(...selectors);
|
|
30047
|
+
});
|
|
30048
|
+
return constantPool.getConstLiteral(literalArr(predicate), true);
|
|
30049
|
+
}
|
|
30050
|
+
else {
|
|
30051
|
+
// The original predicate may have been wrapped in a `forwardRef()` call.
|
|
30052
|
+
switch (query.predicate.forwardRef) {
|
|
30053
|
+
case 0 /* ForwardRefHandling.None */:
|
|
30054
|
+
case 2 /* ForwardRefHandling.Unwrapped */:
|
|
30055
|
+
return query.predicate.expression;
|
|
30056
|
+
case 1 /* ForwardRefHandling.Wrapped */:
|
|
30057
|
+
return importExpr(Identifiers.resolveForwardRef).callFn([query.predicate.expression]);
|
|
30058
|
+
}
|
|
30059
|
+
}
|
|
30060
|
+
}
|
|
30061
|
+
function createQueryCreateCall(query, constantPool, queryTypeFns, prependParams) {
|
|
30062
|
+
const parameters = [];
|
|
30063
|
+
if (prependParams !== undefined) {
|
|
30064
|
+
parameters.push(...prependParams);
|
|
30065
|
+
}
|
|
30066
|
+
if (query.isSignal) {
|
|
30067
|
+
parameters.push(new ReadPropExpr(variable(CONTEXT_NAME), query.propertyName));
|
|
30068
|
+
}
|
|
30069
|
+
parameters.push(getQueryPredicate(query, constantPool), literal(toQueryFlags(query)));
|
|
30070
|
+
if (query.read) {
|
|
30071
|
+
parameters.push(query.read);
|
|
30072
|
+
}
|
|
30073
|
+
const queryCreateFn = query.isSignal ? queryTypeFns.signalBased : queryTypeFns.nonSignal;
|
|
30074
|
+
return importExpr(queryCreateFn).callFn(parameters);
|
|
30075
|
+
}
|
|
30076
|
+
const queryAdvancePlaceholder = Symbol('queryAdvancePlaceholder');
|
|
30077
|
+
/**
|
|
30078
|
+
* Collapses query advance placeholders in a list of statements.
|
|
30079
|
+
*
|
|
30080
|
+
* This allows for less generated code because multiple sibling query advance
|
|
30081
|
+
* statements can be collapsed into a single call with the count as argument.
|
|
30082
|
+
*
|
|
30083
|
+
* e.g.
|
|
30084
|
+
*
|
|
30085
|
+
* ```ts
|
|
30086
|
+
* bla();
|
|
30087
|
+
* queryAdvance();
|
|
30088
|
+
* queryAdvance();
|
|
30089
|
+
* bla();
|
|
30090
|
+
* ```
|
|
30091
|
+
*
|
|
30092
|
+
* --> will turn into
|
|
30093
|
+
*
|
|
30094
|
+
* ```
|
|
30095
|
+
* bla();
|
|
30096
|
+
* queryAdvance(2);
|
|
30097
|
+
* bla();
|
|
30098
|
+
* ```
|
|
30099
|
+
*/
|
|
30100
|
+
function collapseAdvanceStatements(statements) {
|
|
30101
|
+
const result = [];
|
|
30102
|
+
let advanceCollapseCount = 0;
|
|
30103
|
+
const flushAdvanceCount = () => {
|
|
30104
|
+
if (advanceCollapseCount > 0) {
|
|
30105
|
+
result.unshift(importExpr(Identifiers.queryAdvance)
|
|
30106
|
+
.callFn(advanceCollapseCount === 1 ? [] : [literal(advanceCollapseCount)])
|
|
30107
|
+
.toStmt());
|
|
30108
|
+
advanceCollapseCount = 0;
|
|
30109
|
+
}
|
|
30110
|
+
};
|
|
30111
|
+
// Iterate through statements in reverse and collapse advance placeholders.
|
|
30112
|
+
for (let i = statements.length - 1; i >= 0; i--) {
|
|
30113
|
+
const st = statements[i];
|
|
30114
|
+
if (st === queryAdvancePlaceholder) {
|
|
30115
|
+
advanceCollapseCount++;
|
|
30116
|
+
}
|
|
30117
|
+
else {
|
|
30118
|
+
flushAdvanceCount();
|
|
30119
|
+
result.unshift(st);
|
|
30120
|
+
}
|
|
30121
|
+
}
|
|
30122
|
+
flushAdvanceCount();
|
|
30123
|
+
return result;
|
|
30124
|
+
}
|
|
30125
|
+
// Define and update any view queries
|
|
30126
|
+
function createViewQueriesFunction(viewQueries, constantPool, name) {
|
|
30127
|
+
const createStatements = [];
|
|
30128
|
+
const updateStatements = [];
|
|
30129
|
+
const tempAllocator = temporaryAllocator(st => updateStatements.push(st), TEMPORARY_NAME);
|
|
30130
|
+
viewQueries.forEach((query) => {
|
|
30131
|
+
// creation call, e.g. r3.viewQuery(somePredicate, true) or
|
|
30132
|
+
// r3.viewQuerySignal(ctx.prop, somePredicate, true);
|
|
30133
|
+
const queryDefinitionCall = createQueryCreateCall(query, constantPool, {
|
|
30134
|
+
signalBased: Identifiers.viewQuerySignal,
|
|
30135
|
+
nonSignal: Identifiers.viewQuery,
|
|
30136
|
+
});
|
|
30137
|
+
createStatements.push(queryDefinitionCall.toStmt());
|
|
30138
|
+
// Signal queries update lazily and we just advance the index.
|
|
30139
|
+
if (query.isSignal) {
|
|
30140
|
+
updateStatements.push(queryAdvancePlaceholder);
|
|
30141
|
+
return;
|
|
30142
|
+
}
|
|
30143
|
+
// update, e.g. (r3.queryRefresh(tmp = r3.loadQuery()) && (ctx.someDir = tmp));
|
|
30144
|
+
const temporary = tempAllocator();
|
|
30145
|
+
const getQueryList = importExpr(Identifiers.loadQuery).callFn([]);
|
|
30146
|
+
const refresh = importExpr(Identifiers.queryRefresh).callFn([temporary.set(getQueryList)]);
|
|
30147
|
+
const updateDirective = variable(CONTEXT_NAME)
|
|
30148
|
+
.prop(query.propertyName)
|
|
30149
|
+
.set(query.first ? temporary.prop('first') : temporary);
|
|
30150
|
+
updateStatements.push(refresh.and(updateDirective).toStmt());
|
|
30151
|
+
});
|
|
30152
|
+
const viewQueryFnName = name ? `${name}_Query` : null;
|
|
30153
|
+
return fn([new FnParam(RENDER_FLAGS, NUMBER_TYPE), new FnParam(CONTEXT_NAME, null)], [
|
|
30154
|
+
renderFlagCheckIfStmt(1 /* core.RenderFlags.Create */, createStatements),
|
|
30155
|
+
renderFlagCheckIfStmt(2 /* core.RenderFlags.Update */, collapseAdvanceStatements(updateStatements))
|
|
30156
|
+
], INFERRED_TYPE, null, viewQueryFnName);
|
|
30157
|
+
}
|
|
30158
|
+
// Define and update any content queries
|
|
30159
|
+
function createContentQueriesFunction(queries, constantPool, name) {
|
|
30160
|
+
const createStatements = [];
|
|
30161
|
+
const updateStatements = [];
|
|
30162
|
+
const tempAllocator = temporaryAllocator(st => updateStatements.push(st), TEMPORARY_NAME);
|
|
30163
|
+
for (const query of queries) {
|
|
30164
|
+
// creation, e.g. r3.contentQuery(dirIndex, somePredicate, true, null) or
|
|
30165
|
+
// r3.contentQuerySignal(dirIndex, propName, somePredicate, <flags>, <read>).
|
|
30166
|
+
createStatements.push(createQueryCreateCall(query, constantPool, { nonSignal: Identifiers.contentQuery, signalBased: Identifiers.contentQuerySignal },
|
|
30167
|
+
/* prependParams */ [variable('dirIndex')])
|
|
30168
|
+
.toStmt());
|
|
30169
|
+
// Signal queries update lazily and we just advance the index.
|
|
30170
|
+
if (query.isSignal) {
|
|
30171
|
+
updateStatements.push(queryAdvancePlaceholder);
|
|
30172
|
+
continue;
|
|
30173
|
+
}
|
|
30174
|
+
// update, e.g. (r3.queryRefresh(tmp = r3.loadQuery()) && (ctx.someDir = tmp));
|
|
30175
|
+
const temporary = tempAllocator();
|
|
30176
|
+
const getQueryList = importExpr(Identifiers.loadQuery).callFn([]);
|
|
30177
|
+
const refresh = importExpr(Identifiers.queryRefresh).callFn([temporary.set(getQueryList)]);
|
|
30178
|
+
const updateDirective = variable(CONTEXT_NAME)
|
|
30179
|
+
.prop(query.propertyName)
|
|
30180
|
+
.set(query.first ? temporary.prop('first') : temporary);
|
|
30181
|
+
updateStatements.push(refresh.and(updateDirective).toStmt());
|
|
30182
|
+
}
|
|
30183
|
+
const contentQueriesFnName = name ? `${name}_ContentQueries` : null;
|
|
30184
|
+
return fn([
|
|
30185
|
+
new FnParam(RENDER_FLAGS, NUMBER_TYPE), new FnParam(CONTEXT_NAME, null),
|
|
30186
|
+
new FnParam('dirIndex', null)
|
|
30187
|
+
], [
|
|
30188
|
+
renderFlagCheckIfStmt(1 /* core.RenderFlags.Create */, createStatements),
|
|
30189
|
+
renderFlagCheckIfStmt(2 /* core.RenderFlags.Update */, collapseAdvanceStatements(updateStatements)),
|
|
30190
|
+
], INFERRED_TYPE, null, contentQueriesFnName);
|
|
30191
|
+
}
|
|
30192
|
+
|
|
30045
30193
|
// This regex matches any binding names that contain the "attr." prefix, e.g. "attr.required"
|
|
30046
30194
|
// If there is a match, the first matching group will contain the attribute name to bind.
|
|
30047
30195
|
const ATTR_REGEX = /attr\.([^\]]+)/;
|
|
@@ -30336,22 +30484,6 @@ function compileDeclarationList(list, mode) {
|
|
|
30336
30484
|
throw new Error(`Unsupported with an array of pre-resolved dependencies`);
|
|
30337
30485
|
}
|
|
30338
30486
|
}
|
|
30339
|
-
function prepareQueryParams(query, constantPool) {
|
|
30340
|
-
const parameters = [getQueryPredicate(query, constantPool), literal(toQueryFlags(query))];
|
|
30341
|
-
if (query.read) {
|
|
30342
|
-
parameters.push(query.read);
|
|
30343
|
-
}
|
|
30344
|
-
return parameters;
|
|
30345
|
-
}
|
|
30346
|
-
/**
|
|
30347
|
-
* Translates query flags into `TQueryFlags` type in packages/core/src/render3/interfaces/query.ts
|
|
30348
|
-
* @param query
|
|
30349
|
-
*/
|
|
30350
|
-
function toQueryFlags(query) {
|
|
30351
|
-
return (query.descendants ? 1 /* QueryFlags.descendants */ : 0 /* QueryFlags.none */) |
|
|
30352
|
-
(query.static ? 2 /* QueryFlags.isStatic */ : 0 /* QueryFlags.none */) |
|
|
30353
|
-
(query.emitDistinctChangesOnly ? 4 /* QueryFlags.emitDistinctChangesOnly */ : 0 /* QueryFlags.none */);
|
|
30354
|
-
}
|
|
30355
30487
|
function convertAttributesToExpressions(attributes) {
|
|
30356
30488
|
const values = [];
|
|
30357
30489
|
for (let key of Object.getOwnPropertyNames(attributes)) {
|
|
@@ -30360,34 +30492,6 @@ function convertAttributesToExpressions(attributes) {
|
|
|
30360
30492
|
}
|
|
30361
30493
|
return values;
|
|
30362
30494
|
}
|
|
30363
|
-
// Define and update any content queries
|
|
30364
|
-
function createContentQueriesFunction(queries, constantPool, name) {
|
|
30365
|
-
const createStatements = [];
|
|
30366
|
-
const updateStatements = [];
|
|
30367
|
-
const tempAllocator = temporaryAllocator(updateStatements, TEMPORARY_NAME);
|
|
30368
|
-
for (const query of queries) {
|
|
30369
|
-
// creation, e.g. r3.contentQuery(dirIndex, somePredicate, true, null);
|
|
30370
|
-
createStatements.push(importExpr(Identifiers.contentQuery)
|
|
30371
|
-
.callFn([variable('dirIndex'), ...prepareQueryParams(query, constantPool)])
|
|
30372
|
-
.toStmt());
|
|
30373
|
-
// update, e.g. (r3.queryRefresh(tmp = r3.loadQuery()) && (ctx.someDir = tmp));
|
|
30374
|
-
const temporary = tempAllocator();
|
|
30375
|
-
const getQueryList = importExpr(Identifiers.loadQuery).callFn([]);
|
|
30376
|
-
const refresh = importExpr(Identifiers.queryRefresh).callFn([temporary.set(getQueryList)]);
|
|
30377
|
-
const updateDirective = variable(CONTEXT_NAME)
|
|
30378
|
-
.prop(query.propertyName)
|
|
30379
|
-
.set(query.first ? temporary.prop('first') : temporary);
|
|
30380
|
-
updateStatements.push(refresh.and(updateDirective).toStmt());
|
|
30381
|
-
}
|
|
30382
|
-
const contentQueriesFnName = name ? `${name}_ContentQueries` : null;
|
|
30383
|
-
return fn([
|
|
30384
|
-
new FnParam(RENDER_FLAGS, NUMBER_TYPE), new FnParam(CONTEXT_NAME, null),
|
|
30385
|
-
new FnParam('dirIndex', null)
|
|
30386
|
-
], [
|
|
30387
|
-
renderFlagCheckIfStmt(1 /* core.RenderFlags.Create */, createStatements),
|
|
30388
|
-
renderFlagCheckIfStmt(2 /* core.RenderFlags.Update */, updateStatements)
|
|
30389
|
-
], INFERRED_TYPE, null, contentQueriesFnName);
|
|
30390
|
-
}
|
|
30391
30495
|
function stringAsType(str) {
|
|
30392
30496
|
return expressionType(literal(str));
|
|
30393
30497
|
}
|
|
@@ -30453,30 +30557,6 @@ function createDirectiveType(meta) {
|
|
|
30453
30557
|
}
|
|
30454
30558
|
return expressionType(importExpr(Identifiers.DirectiveDeclaration, typeParams));
|
|
30455
30559
|
}
|
|
30456
|
-
// Define and update any view queries
|
|
30457
|
-
function createViewQueriesFunction(viewQueries, constantPool, name) {
|
|
30458
|
-
const createStatements = [];
|
|
30459
|
-
const updateStatements = [];
|
|
30460
|
-
const tempAllocator = temporaryAllocator(updateStatements, TEMPORARY_NAME);
|
|
30461
|
-
viewQueries.forEach((query) => {
|
|
30462
|
-
// creation, e.g. r3.viewQuery(somePredicate, true);
|
|
30463
|
-
const queryDefinition = importExpr(Identifiers.viewQuery).callFn(prepareQueryParams(query, constantPool));
|
|
30464
|
-
createStatements.push(queryDefinition.toStmt());
|
|
30465
|
-
// update, e.g. (r3.queryRefresh(tmp = r3.loadQuery()) && (ctx.someDir = tmp));
|
|
30466
|
-
const temporary = tempAllocator();
|
|
30467
|
-
const getQueryList = importExpr(Identifiers.loadQuery).callFn([]);
|
|
30468
|
-
const refresh = importExpr(Identifiers.queryRefresh).callFn([temporary.set(getQueryList)]);
|
|
30469
|
-
const updateDirective = variable(CONTEXT_NAME)
|
|
30470
|
-
.prop(query.propertyName)
|
|
30471
|
-
.set(query.first ? temporary.prop('first') : temporary);
|
|
30472
|
-
updateStatements.push(refresh.and(updateDirective).toStmt());
|
|
30473
|
-
});
|
|
30474
|
-
const viewQueryFnName = name ? `${name}_Query` : null;
|
|
30475
|
-
return fn([new FnParam(RENDER_FLAGS, NUMBER_TYPE), new FnParam(CONTEXT_NAME, null)], [
|
|
30476
|
-
renderFlagCheckIfStmt(1 /* core.RenderFlags.Create */, createStatements),
|
|
30477
|
-
renderFlagCheckIfStmt(2 /* core.RenderFlags.Update */, updateStatements)
|
|
30478
|
-
], INFERRED_TYPE, null, viewQueryFnName);
|
|
30479
|
-
}
|
|
30480
30560
|
// Return a host binding function or null if one is not necessary.
|
|
30481
30561
|
function createHostBindingsFunction(hostBindingsMetadata, typeSourceSpan, bindingParser, constantPool, selector, name, definitionMap) {
|
|
30482
30562
|
const bindings = bindingParser.createBoundHostProperties(hostBindingsMetadata.properties, typeSourceSpan);
|
|
@@ -31862,6 +31942,7 @@ class CompilerFacadeImpl {
|
|
|
31862
31942
|
function convertToR3QueryMetadata(facade) {
|
|
31863
31943
|
return {
|
|
31864
31944
|
...facade,
|
|
31945
|
+
isSignal: facade.isSignal,
|
|
31865
31946
|
predicate: convertQueryPredicate(facade.predicate),
|
|
31866
31947
|
read: facade.read ? new WrappedNodeExpr(facade.read) : null,
|
|
31867
31948
|
static: facade.static,
|
|
@@ -31877,6 +31958,7 @@ function convertQueryDeclarationToMetadata(declaration) {
|
|
|
31877
31958
|
read: declaration.read ? new WrappedNodeExpr(declaration.read) : null,
|
|
31878
31959
|
static: declaration.static ?? false,
|
|
31879
31960
|
emitDistinctChangesOnly: declaration.emitDistinctChangesOnly ?? true,
|
|
31961
|
+
isSignal: !!declaration.isSignal,
|
|
31880
31962
|
};
|
|
31881
31963
|
}
|
|
31882
31964
|
function convertQueryPredicate(predicate) {
|
|
@@ -32315,7 +32397,7 @@ function publishFacade(global) {
|
|
|
32315
32397
|
* @description
|
|
32316
32398
|
* Entry point for all public APIs of the compiler package.
|
|
32317
32399
|
*/
|
|
32318
|
-
const VERSION = new Version('17.
|
|
32400
|
+
const VERSION = new Version('17.2.0-next.0');
|
|
32319
32401
|
|
|
32320
32402
|
class CompilerConfig {
|
|
32321
32403
|
constructor({ defaultEncapsulation = ViewEncapsulation.Emulated, preserveWhitespaces, strictInjectionParameters } = {}) {
|
|
@@ -33881,7 +33963,7 @@ const MINIMUM_PARTIAL_LINKER_VERSION$5 = '12.0.0';
|
|
|
33881
33963
|
function compileDeclareClassMetadata(metadata) {
|
|
33882
33964
|
const definitionMap = new DefinitionMap();
|
|
33883
33965
|
definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$5));
|
|
33884
|
-
definitionMap.set('version', literal('17.
|
|
33966
|
+
definitionMap.set('version', literal('17.2.0-next.0'));
|
|
33885
33967
|
definitionMap.set('ngImport', importExpr(Identifiers.core));
|
|
33886
33968
|
definitionMap.set('type', metadata.type);
|
|
33887
33969
|
definitionMap.set('decorators', metadata.decorators);
|
|
@@ -33977,7 +34059,7 @@ function createDirectiveDefinitionMap(meta) {
|
|
|
33977
34059
|
const definitionMap = new DefinitionMap();
|
|
33978
34060
|
const minVersion = getMinimumVersionForPartialOutput(meta);
|
|
33979
34061
|
definitionMap.set('minVersion', literal(minVersion));
|
|
33980
|
-
definitionMap.set('version', literal('17.
|
|
34062
|
+
definitionMap.set('version', literal('17.2.0-next.0'));
|
|
33981
34063
|
// e.g. `type: MyDirective`
|
|
33982
34064
|
definitionMap.set('type', meta.type.value);
|
|
33983
34065
|
if (meta.isStandalone) {
|
|
@@ -34045,6 +34127,11 @@ function getMinimumVersionForPartialOutput(meta) {
|
|
|
34045
34127
|
if (needsNewInputPartialOutput(meta)) {
|
|
34046
34128
|
minVersion = '17.1.0';
|
|
34047
34129
|
}
|
|
34130
|
+
// If there are signal-based queries, partial output generates an extra field
|
|
34131
|
+
// that should be parsed by linkers. Ensure a proper minimum linker version.
|
|
34132
|
+
if (meta.queries.some(q => q.isSignal) || meta.viewQueries.some(q => q.isSignal)) {
|
|
34133
|
+
minVersion = '17.2.0';
|
|
34134
|
+
}
|
|
34048
34135
|
return minVersion;
|
|
34049
34136
|
}
|
|
34050
34137
|
/**
|
|
@@ -34081,6 +34168,9 @@ function compileQuery(query) {
|
|
|
34081
34168
|
if (query.static) {
|
|
34082
34169
|
meta.set('static', literal(true));
|
|
34083
34170
|
}
|
|
34171
|
+
if (query.isSignal) {
|
|
34172
|
+
meta.set('isSignal', literal(true));
|
|
34173
|
+
}
|
|
34084
34174
|
return meta.toLiteralMap();
|
|
34085
34175
|
}
|
|
34086
34176
|
/**
|
|
@@ -34361,7 +34451,7 @@ const MINIMUM_PARTIAL_LINKER_VERSION$4 = '12.0.0';
|
|
|
34361
34451
|
function compileDeclareFactoryFunction(meta) {
|
|
34362
34452
|
const definitionMap = new DefinitionMap();
|
|
34363
34453
|
definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$4));
|
|
34364
|
-
definitionMap.set('version', literal('17.
|
|
34454
|
+
definitionMap.set('version', literal('17.2.0-next.0'));
|
|
34365
34455
|
definitionMap.set('ngImport', importExpr(Identifiers.core));
|
|
34366
34456
|
definitionMap.set('type', meta.type.value);
|
|
34367
34457
|
definitionMap.set('deps', compileDependencies(meta.deps));
|
|
@@ -34396,7 +34486,7 @@ function compileDeclareInjectableFromMetadata(meta) {
|
|
|
34396
34486
|
function createInjectableDefinitionMap(meta) {
|
|
34397
34487
|
const definitionMap = new DefinitionMap();
|
|
34398
34488
|
definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$3));
|
|
34399
|
-
definitionMap.set('version', literal('17.
|
|
34489
|
+
definitionMap.set('version', literal('17.2.0-next.0'));
|
|
34400
34490
|
definitionMap.set('ngImport', importExpr(Identifiers.core));
|
|
34401
34491
|
definitionMap.set('type', meta.type.value);
|
|
34402
34492
|
// Only generate providedIn property if it has a non-null value
|
|
@@ -34447,7 +34537,7 @@ function compileDeclareInjectorFromMetadata(meta) {
|
|
|
34447
34537
|
function createInjectorDefinitionMap(meta) {
|
|
34448
34538
|
const definitionMap = new DefinitionMap();
|
|
34449
34539
|
definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$2));
|
|
34450
|
-
definitionMap.set('version', literal('17.
|
|
34540
|
+
definitionMap.set('version', literal('17.2.0-next.0'));
|
|
34451
34541
|
definitionMap.set('ngImport', importExpr(Identifiers.core));
|
|
34452
34542
|
definitionMap.set('type', meta.type.value);
|
|
34453
34543
|
definitionMap.set('providers', meta.providers);
|
|
@@ -34480,7 +34570,7 @@ function createNgModuleDefinitionMap(meta) {
|
|
|
34480
34570
|
throw new Error('Invalid path! Local compilation mode should not get into the partial compilation path');
|
|
34481
34571
|
}
|
|
34482
34572
|
definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$1));
|
|
34483
|
-
definitionMap.set('version', literal('17.
|
|
34573
|
+
definitionMap.set('version', literal('17.2.0-next.0'));
|
|
34484
34574
|
definitionMap.set('ngImport', importExpr(Identifiers.core));
|
|
34485
34575
|
definitionMap.set('type', meta.type.value);
|
|
34486
34576
|
// We only generate the keys in the metadata if the arrays contain values.
|
|
@@ -34531,7 +34621,7 @@ function compileDeclarePipeFromMetadata(meta) {
|
|
|
34531
34621
|
function createPipeDefinitionMap(meta) {
|
|
34532
34622
|
const definitionMap = new DefinitionMap();
|
|
34533
34623
|
definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION));
|
|
34534
|
-
definitionMap.set('version', literal('17.
|
|
34624
|
+
definitionMap.set('version', literal('17.2.0-next.0'));
|
|
34535
34625
|
definitionMap.set('ngImport', importExpr(Identifiers.core));
|
|
34536
34626
|
// e.g. `type: MyPipe`
|
|
34537
34627
|
definitionMap.set('type', meta.type.value);
|