@angular/compiler 17.1.2 → 17.2.0-next.1

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v17.1.2
2
+ * @license Angular v17.2.0-next.1
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(statements, name) {
4974
+ function temporaryAllocator(pushStatement, name) {
4971
4975
  let temp = null;
4972
4976
  return () => {
4973
4977
  if (!temp) {
4974
- statements.push(new DeclareVarStmt(TEMPORARY_NAME, undefined, DYNAMIC_TYPE));
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
@@ -7862,6 +7843,10 @@ const animationKeywords = new Set([
7862
7843
  // `steps()` function
7863
7844
  'end', 'jump-both', 'jump-end', 'jump-none', 'jump-start', 'start'
7864
7845
  ]);
7846
+ /**
7847
+ * The following array contains all of the CSS at-rule identifiers which are scoped.
7848
+ */
7849
+ const scopedAtRuleIdentifiers = ['@media', '@supports', '@document', '@layer', '@container', '@scope', '@starting-style'];
7865
7850
  /**
7866
7851
  * The following class has its origin from a port of shadowCSS from webcomponents.js to TypeScript.
7867
7852
  * It has since diverge in many ways to tailor Angular's needs.
@@ -8349,9 +8334,7 @@ class ShadowCss {
8349
8334
  if (rule.selector[0] !== '@') {
8350
8335
  selector = this._scopeSelector(rule.selector, scopeSelector, hostSelector);
8351
8336
  }
8352
- else if (rule.selector.startsWith('@media') || rule.selector.startsWith('@supports') ||
8353
- rule.selector.startsWith('@document') || rule.selector.startsWith('@layer') ||
8354
- rule.selector.startsWith('@container') || rule.selector.startsWith('@scope')) {
8337
+ else if (scopedAtRuleIdentifiers.some(atRule => rule.selector.startsWith(atRule))) {
8355
8338
  content = this._scopeSelectors(rule.content, scopeSelector, hostSelector);
8356
8339
  }
8357
8340
  else if (rule.selector.startsWith('@font-face') || rule.selector.startsWith('@page')) {
@@ -25050,810 +25033,281 @@ function ingestControlFlowInsertionPoint(unit, xref, node) {
25050
25033
 
25051
25034
  const USE_TEMPLATE_PIPELINE = false;
25052
25035
 
25053
- const IMPORTANT_FLAG = '!important';
25036
+ class HtmlParser extends Parser {
25037
+ constructor() {
25038
+ super(getHtmlTagDefinition);
25039
+ }
25040
+ parse(source, url, options) {
25041
+ return super.parse(source, url, options);
25042
+ }
25043
+ }
25044
+
25045
+ const PRESERVE_WS_ATTR_NAME = 'ngPreserveWhitespaces';
25046
+ const SKIP_WS_TRIM_TAGS = new Set(['pre', 'template', 'textarea', 'script', 'style']);
25047
+ // Equivalent to \s with \u00a0 (non-breaking space) excluded.
25048
+ // Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
25049
+ const WS_CHARS = ' \f\n\r\t\v\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff';
25050
+ const NO_WS_REGEXP = new RegExp(`[^${WS_CHARS}]`);
25051
+ const WS_REPLACE_REGEXP = new RegExp(`[${WS_CHARS}]{2,}`, 'g');
25052
+ function hasPreserveWhitespacesAttr(attrs) {
25053
+ return attrs.some((attr) => attr.name === PRESERVE_WS_ATTR_NAME);
25054
+ }
25054
25055
  /**
25055
- * Minimum amount of binding slots required in the runtime for style/class bindings.
25056
- *
25057
- * Styling in Angular uses up two slots in the runtime LView/TData data structures to
25058
- * record binding data, property information and metadata.
25059
- *
25060
- * When a binding is registered it will place the following information in the `LView`:
25061
- *
25062
- * slot 1) binding value
25063
- * slot 2) cached value (all other values collected before it in string form)
25064
- *
25065
- * When a binding is registered it will place the following information in the `TData`:
25066
- *
25067
- * slot 1) prop name
25068
- * slot 2) binding index that points to the previous style/class binding (and some extra config
25069
- * values)
25070
- *
25071
- * Let's imagine we have a binding that looks like so:
25072
- *
25073
- * ```
25074
- * <div [style.width]="x" [style.height]="y">
25075
- * ```
25076
- *
25077
- * Our `LView` and `TData` data-structures look like so:
25078
- *
25079
- * ```typescript
25080
- * LView = [
25081
- * // ...
25082
- * x, // value of x
25083
- * "width: x",
25084
- *
25085
- * y, // value of y
25086
- * "width: x; height: y",
25087
- * // ...
25088
- * ];
25089
- *
25090
- * TData = [
25091
- * // ...
25092
- * "width", // binding slot 20
25093
- * 0,
25094
- *
25095
- * "height",
25096
- * 20,
25097
- * // ...
25098
- * ];
25099
- * ```
25100
- *
25101
- * */
25102
- const MIN_STYLING_BINDING_SLOTS_REQUIRED = 2;
25056
+ * &ngsp; is a placeholder for non-removable space
25057
+ * &ngsp; is converted to the 0xE500 PUA (Private Use Areas) unicode character
25058
+ * and later on replaced by a space.
25059
+ */
25060
+ function replaceNgsp(value) {
25061
+ // lexer is replacing the &ngsp; pseudo-entity with NGSP_UNICODE
25062
+ return value.replace(new RegExp(NGSP_UNICODE, 'g'), ' ');
25063
+ }
25103
25064
  /**
25104
- * Produces creation/update instructions for all styling bindings (class and style)
25105
- *
25106
- * It also produces the creation instruction to register all initial styling values
25107
- * (which are all the static class="..." and style="..." attribute values that exist
25108
- * on an element within a template).
25109
- *
25110
- * The builder class below handles producing instructions for the following cases:
25111
- *
25112
- * - Static style/class attributes (style="..." and class="...")
25113
- * - Dynamic style/class map bindings ([style]="map" and [class]="map|string")
25114
- * - Dynamic style/class property bindings ([style.prop]="exp" and [class.name]="exp")
25115
- *
25116
- * Due to the complex relationship of all of these cases, the instructions generated
25117
- * for these attributes/properties/bindings must be done so in the correct order. The
25118
- * order which these must be generated is as follows:
25119
- *
25120
- * if (createMode) {
25121
- * styling(...)
25122
- * }
25123
- * if (updateMode) {
25124
- * styleMap(...)
25125
- * classMap(...)
25126
- * styleProp(...)
25127
- * classProp(...)
25128
- * }
25065
+ * This visitor can walk HTML parse tree and remove / trim text nodes using the following rules:
25066
+ * - consider spaces, tabs and new lines as whitespace characters;
25067
+ * - drop text nodes consisting of whitespace characters only;
25068
+ * - for all other text nodes replace consecutive whitespace characters with one space;
25069
+ * - convert &ngsp; pseudo-entity to a single space;
25129
25070
  *
25130
- * The creation/update methods within the builder class produce these instructions.
25071
+ * Removal and trimming of whitespaces have positive performance impact (less code to generate
25072
+ * while compiling templates, faster view creation). At the same time it can be "destructive"
25073
+ * in some cases (whitespaces can influence layout). Because of the potential of breaking layout
25074
+ * this visitor is not activated by default in Angular 5 and people need to explicitly opt-in for
25075
+ * whitespace removal. The default option for whitespace removal will be revisited in Angular 6
25076
+ * and might be changed to "on" by default.
25131
25077
  */
25132
- class StylingBuilder {
25133
- constructor(_directiveExpr) {
25134
- this._directiveExpr = _directiveExpr;
25135
- /** Whether or not there are any static styling values present */
25136
- this._hasInitialValues = false;
25137
- /**
25138
- * Whether or not there are any styling bindings present
25139
- * (i.e. `[style]`, `[class]`, `[style.prop]` or `[class.name]`)
25140
- */
25141
- this.hasBindings = false;
25142
- this.hasBindingsWithPipes = false;
25143
- /** the input for [class] (if it exists) */
25144
- this._classMapInput = null;
25145
- /** the input for [style] (if it exists) */
25146
- this._styleMapInput = null;
25147
- /** an array of each [style.prop] input */
25148
- this._singleStyleInputs = null;
25149
- /** an array of each [class.name] input */
25150
- this._singleClassInputs = null;
25151
- this._lastStylingInput = null;
25152
- this._firstStylingInput = null;
25153
- // maps are used instead of hash maps because a Map will
25154
- // retain the ordering of the keys
25155
- /**
25156
- * Represents the location of each style binding in the template
25157
- * (e.g. `<div [style.width]="w" [style.height]="h">` implies
25158
- * that `width=0` and `height=1`)
25159
- */
25160
- this._stylesIndex = new Map();
25161
- /**
25162
- * Represents the location of each class binding in the template
25163
- * (e.g. `<div [class.big]="b" [class.hidden]="h">` implies
25164
- * that `big=0` and `hidden=1`)
25165
- */
25166
- this._classesIndex = new Map();
25167
- this._initialStyleValues = [];
25168
- this._initialClassValues = [];
25078
+ class WhitespaceVisitor {
25079
+ visitElement(element, context) {
25080
+ if (SKIP_WS_TRIM_TAGS.has(element.name) || hasPreserveWhitespacesAttr(element.attrs)) {
25081
+ // don't descent into elements where we need to preserve whitespaces
25082
+ // but still visit all attributes to eliminate one used as a market to preserve WS
25083
+ return new Element(element.name, visitAll(this, element.attrs), element.children, element.sourceSpan, element.startSourceSpan, element.endSourceSpan, element.i18n);
25084
+ }
25085
+ return new Element(element.name, element.attrs, visitAllWithSiblings(this, element.children), element.sourceSpan, element.startSourceSpan, element.endSourceSpan, element.i18n);
25169
25086
  }
25170
- /**
25171
- * Registers a given input to the styling builder to be later used when producing AOT code.
25172
- *
25173
- * The code below will only accept the input if it is somehow tied to styling (whether it be
25174
- * style/class bindings or static style/class attributes).
25175
- */
25176
- registerBoundInput(input) {
25177
- // [attr.style] or [attr.class] are skipped in the code below,
25178
- // they should not be treated as styling-based bindings since
25179
- // they are intended to be written directly to the attr and
25180
- // will therefore skip all style/class resolution that is present
25181
- // with style="", [style]="" and [style.prop]="", class="",
25182
- // [class.prop]="". [class]="" assignments
25183
- let binding = null;
25184
- let name = input.name;
25185
- switch (input.type) {
25186
- case 0 /* BindingType.Property */:
25187
- binding = this.registerInputBasedOnName(name, input.value, input.sourceSpan);
25188
- break;
25189
- case 3 /* BindingType.Style */:
25190
- binding = this.registerStyleInput(name, false, input.value, input.sourceSpan, input.unit);
25191
- break;
25192
- case 2 /* BindingType.Class */:
25193
- binding = this.registerClassInput(name, false, input.value, input.sourceSpan);
25194
- break;
25087
+ visitAttribute(attribute, context) {
25088
+ return attribute.name !== PRESERVE_WS_ATTR_NAME ? attribute : null;
25089
+ }
25090
+ visitText(text, context) {
25091
+ const isNotBlank = text.value.match(NO_WS_REGEXP);
25092
+ const hasExpansionSibling = context &&
25093
+ (context.prev instanceof Expansion || context.next instanceof Expansion);
25094
+ if (isNotBlank || hasExpansionSibling) {
25095
+ // Process the whitespace in the tokens of this Text node
25096
+ const tokens = text.tokens.map(token => token.type === 5 /* TokenType.TEXT */ ? createWhitespaceProcessedTextToken(token) : token);
25097
+ // Process the whitespace of the value of this Text node
25098
+ const value = processWhitespace(text.value);
25099
+ return new Text(value, text.sourceSpan, tokens, text.i18n);
25195
25100
  }
25196
- return binding ? true : false;
25101
+ return null;
25197
25102
  }
25198
- registerInputBasedOnName(name, expression, sourceSpan) {
25199
- let binding = null;
25200
- const prefix = name.substring(0, 6);
25201
- const isStyle = name === 'style' || prefix === 'style.' || prefix === 'style!';
25202
- const isClass = !isStyle && (name === 'class' || prefix === 'class.' || prefix === 'class!');
25203
- if (isStyle || isClass) {
25204
- const isMapBased = name.charAt(5) !== '.'; // style.prop or class.prop makes this a no
25205
- const property = name.slice(isMapBased ? 5 : 6); // the dot explains why there's a +1
25206
- if (isStyle) {
25207
- binding = this.registerStyleInput(property, isMapBased, expression, sourceSpan);
25103
+ visitComment(comment, context) {
25104
+ return comment;
25105
+ }
25106
+ visitExpansion(expansion, context) {
25107
+ return expansion;
25108
+ }
25109
+ visitExpansionCase(expansionCase, context) {
25110
+ return expansionCase;
25111
+ }
25112
+ visitBlock(block, context) {
25113
+ return new Block(block.name, block.parameters, visitAllWithSiblings(this, block.children), block.sourceSpan, block.nameSpan, block.startSourceSpan, block.endSourceSpan);
25114
+ }
25115
+ visitBlockParameter(parameter, context) {
25116
+ return parameter;
25117
+ }
25118
+ }
25119
+ function createWhitespaceProcessedTextToken({ type, parts, sourceSpan }) {
25120
+ return { type, parts: [processWhitespace(parts[0])], sourceSpan };
25121
+ }
25122
+ function processWhitespace(text) {
25123
+ return replaceNgsp(text).replace(WS_REPLACE_REGEXP, ' ');
25124
+ }
25125
+ function removeWhitespaces(htmlAstWithErrors) {
25126
+ return new ParseTreeResult(visitAll(new WhitespaceVisitor(), htmlAstWithErrors.rootNodes), htmlAstWithErrors.errors);
25127
+ }
25128
+ function visitAllWithSiblings(visitor, nodes) {
25129
+ const result = [];
25130
+ nodes.forEach((ast, i) => {
25131
+ const context = { prev: nodes[i - 1], next: nodes[i + 1] };
25132
+ const astResult = ast.visit(visitor, context);
25133
+ if (astResult) {
25134
+ result.push(astResult);
25135
+ }
25136
+ });
25137
+ return result;
25138
+ }
25139
+
25140
+ const PROPERTY_PARTS_SEPARATOR = '.';
25141
+ const ATTRIBUTE_PREFIX = 'attr';
25142
+ const CLASS_PREFIX = 'class';
25143
+ const STYLE_PREFIX = 'style';
25144
+ const TEMPLATE_ATTR_PREFIX$1 = '*';
25145
+ const ANIMATE_PROP_PREFIX = 'animate-';
25146
+ /**
25147
+ * Parses bindings in templates and in the directive host area.
25148
+ */
25149
+ class BindingParser {
25150
+ constructor(_exprParser, _interpolationConfig, _schemaRegistry, errors) {
25151
+ this._exprParser = _exprParser;
25152
+ this._interpolationConfig = _interpolationConfig;
25153
+ this._schemaRegistry = _schemaRegistry;
25154
+ this.errors = errors;
25155
+ }
25156
+ get interpolationConfig() {
25157
+ return this._interpolationConfig;
25158
+ }
25159
+ createBoundHostProperties(properties, sourceSpan) {
25160
+ const boundProps = [];
25161
+ for (const propName of Object.keys(properties)) {
25162
+ const expression = properties[propName];
25163
+ if (typeof expression === 'string') {
25164
+ this.parsePropertyBinding(propName, expression, true, false, sourceSpan, sourceSpan.start.offset, undefined, [],
25165
+ // Use the `sourceSpan` for `keySpan`. This isn't really accurate, but neither is the
25166
+ // sourceSpan, as it represents the sourceSpan of the host itself rather than the
25167
+ // source of the host binding (which doesn't exist in the template). Regardless,
25168
+ // neither of these values are used in Ivy but are only here to satisfy the function
25169
+ // signature. This should likely be refactored in the future so that `sourceSpan`
25170
+ // isn't being used inaccurately.
25171
+ boundProps, sourceSpan);
25208
25172
  }
25209
25173
  else {
25210
- binding = this.registerClassInput(property, isMapBased, expression, sourceSpan);
25174
+ this._reportError(`Value of the host property binding "${propName}" needs to be a string representing an expression but got "${expression}" (${typeof expression})`, sourceSpan);
25211
25175
  }
25212
25176
  }
25213
- return binding;
25177
+ return boundProps;
25214
25178
  }
25215
- registerStyleInput(name, isMapBased, value, sourceSpan, suffix) {
25216
- if (isEmptyExpression(value)) {
25217
- return null;
25218
- }
25219
- // CSS custom properties are case-sensitive so we shouldn't normalize them.
25220
- // See: https://www.w3.org/TR/css-variables-1/#defining-variables
25221
- if (!isCssCustomProperty(name)) {
25222
- name = hyphenate(name);
25223
- }
25224
- const { property, hasOverrideFlag, suffix: bindingSuffix } = parseProperty(name);
25225
- suffix = typeof suffix === 'string' && suffix.length !== 0 ? suffix : bindingSuffix;
25226
- const entry = { name: property, suffix: suffix, value, sourceSpan, hasOverrideFlag };
25227
- if (isMapBased) {
25228
- this._styleMapInput = entry;
25229
- }
25230
- else {
25231
- (this._singleStyleInputs = this._singleStyleInputs || []).push(entry);
25232
- registerIntoMap(this._stylesIndex, property);
25179
+ createDirectiveHostEventAsts(hostListeners, sourceSpan) {
25180
+ const targetEvents = [];
25181
+ for (const propName of Object.keys(hostListeners)) {
25182
+ const expression = hostListeners[propName];
25183
+ if (typeof expression === 'string') {
25184
+ // Use the `sourceSpan` for `keySpan` and `handlerSpan`. This isn't really accurate, but
25185
+ // neither is the `sourceSpan`, as it represents the `sourceSpan` of the host itself
25186
+ // rather than the source of the host binding (which doesn't exist in the template).
25187
+ // Regardless, neither of these values are used in Ivy but are only here to satisfy the
25188
+ // function signature. This should likely be refactored in the future so that `sourceSpan`
25189
+ // isn't being used inaccurately.
25190
+ this.parseEvent(propName, expression, /* isAssignmentEvent */ false, sourceSpan, sourceSpan, [], targetEvents, sourceSpan);
25191
+ }
25192
+ else {
25193
+ this._reportError(`Value of the host listener "${propName}" needs to be a string representing an expression but got "${expression}" (${typeof expression})`, sourceSpan);
25194
+ }
25233
25195
  }
25234
- this._lastStylingInput = entry;
25235
- this._firstStylingInput = this._firstStylingInput || entry;
25236
- this._checkForPipes(value);
25237
- this.hasBindings = true;
25238
- return entry;
25196
+ return targetEvents;
25239
25197
  }
25240
- registerClassInput(name, isMapBased, value, sourceSpan) {
25241
- if (isEmptyExpression(value)) {
25242
- return null;
25243
- }
25244
- const { property, hasOverrideFlag } = parseProperty(name);
25245
- const entry = { name: property, value, sourceSpan, hasOverrideFlag, suffix: null };
25246
- if (isMapBased) {
25247
- this._classMapInput = entry;
25248
- }
25249
- else {
25250
- (this._singleClassInputs = this._singleClassInputs || []).push(entry);
25251
- registerIntoMap(this._classesIndex, property);
25198
+ parseInterpolation(value, sourceSpan, interpolatedTokens) {
25199
+ const sourceInfo = sourceSpan.start.toString();
25200
+ const absoluteOffset = sourceSpan.fullStart.offset;
25201
+ try {
25202
+ const ast = this._exprParser.parseInterpolation(value, sourceInfo, absoluteOffset, interpolatedTokens, this._interpolationConfig);
25203
+ if (ast)
25204
+ this._reportExpressionParserErrors(ast.errors, sourceSpan);
25205
+ return ast;
25252
25206
  }
25253
- this._lastStylingInput = entry;
25254
- this._firstStylingInput = this._firstStylingInput || entry;
25255
- this._checkForPipes(value);
25256
- this.hasBindings = true;
25257
- return entry;
25258
- }
25259
- _checkForPipes(value) {
25260
- if ((value instanceof ASTWithSource) && (value.ast instanceof BindingPipe)) {
25261
- this.hasBindingsWithPipes = true;
25207
+ catch (e) {
25208
+ this._reportError(`${e}`, sourceSpan);
25209
+ return this._exprParser.wrapLiteralPrimitive('ERROR', sourceInfo, absoluteOffset);
25262
25210
  }
25263
25211
  }
25264
25212
  /**
25265
- * Registers the element's static style string value to the builder.
25266
- *
25267
- * @param value the style string (e.g. `width:100px; height:200px;`)
25268
- */
25269
- registerStyleAttr(value) {
25270
- this._initialStyleValues = parse(value);
25271
- this._hasInitialValues = true;
25272
- }
25273
- /**
25274
- * Registers the element's static class string value to the builder.
25275
- *
25276
- * @param value the className string (e.g. `disabled gold zoom`)
25213
+ * Similar to `parseInterpolation`, but treats the provided string as a single expression
25214
+ * element that would normally appear within the interpolation prefix and suffix (`{{` and `}}`).
25215
+ * This is used for parsing the switch expression in ICUs.
25277
25216
  */
25278
- registerClassAttr(value) {
25279
- this._initialClassValues = value.trim().split(/\s+/g);
25280
- this._hasInitialValues = true;
25217
+ parseInterpolationExpression(expression, sourceSpan) {
25218
+ const sourceInfo = sourceSpan.start.toString();
25219
+ const absoluteOffset = sourceSpan.start.offset;
25220
+ try {
25221
+ const ast = this._exprParser.parseInterpolationExpression(expression, sourceInfo, absoluteOffset);
25222
+ if (ast)
25223
+ this._reportExpressionParserErrors(ast.errors, sourceSpan);
25224
+ return ast;
25225
+ }
25226
+ catch (e) {
25227
+ this._reportError(`${e}`, sourceSpan);
25228
+ return this._exprParser.wrapLiteralPrimitive('ERROR', sourceInfo, absoluteOffset);
25229
+ }
25281
25230
  }
25282
25231
  /**
25283
- * Appends all styling-related expressions to the provided attrs array.
25232
+ * Parses the bindings in a microsyntax expression, and converts them to
25233
+ * `ParsedProperty` or `ParsedVariable`.
25284
25234
  *
25285
- * @param attrs an existing array where each of the styling expressions
25286
- * will be inserted into.
25235
+ * @param tplKey template binding name
25236
+ * @param tplValue template binding value
25237
+ * @param sourceSpan span of template binding relative to entire the template
25238
+ * @param absoluteValueOffset start of the tplValue relative to the entire template
25239
+ * @param targetMatchableAttrs potential attributes to match in the template
25240
+ * @param targetProps target property bindings in the template
25241
+ * @param targetVars target variables in the template
25287
25242
  */
25288
- populateInitialStylingAttrs(attrs) {
25289
- // [CLASS_MARKER, 'foo', 'bar', 'baz' ...]
25290
- if (this._initialClassValues.length) {
25291
- attrs.push(literal(1 /* AttributeMarker.Classes */));
25292
- for (let i = 0; i < this._initialClassValues.length; i++) {
25293
- attrs.push(literal(this._initialClassValues[i]));
25243
+ parseInlineTemplateBinding(tplKey, tplValue, sourceSpan, absoluteValueOffset, targetMatchableAttrs, targetProps, targetVars, isIvyAst) {
25244
+ const absoluteKeyOffset = sourceSpan.start.offset + TEMPLATE_ATTR_PREFIX$1.length;
25245
+ const bindings = this._parseTemplateBindings(tplKey, tplValue, sourceSpan, absoluteKeyOffset, absoluteValueOffset);
25246
+ for (const binding of bindings) {
25247
+ // sourceSpan is for the entire HTML attribute. bindingSpan is for a particular
25248
+ // binding within the microsyntax expression so it's more narrow than sourceSpan.
25249
+ const bindingSpan = moveParseSourceSpan(sourceSpan, binding.sourceSpan);
25250
+ const key = binding.key.source;
25251
+ const keySpan = moveParseSourceSpan(sourceSpan, binding.key.span);
25252
+ if (binding instanceof VariableBinding) {
25253
+ const value = binding.value ? binding.value.source : '$implicit';
25254
+ const valueSpan = binding.value ? moveParseSourceSpan(sourceSpan, binding.value.span) : undefined;
25255
+ targetVars.push(new ParsedVariable(key, value, bindingSpan, keySpan, valueSpan));
25294
25256
  }
25295
- }
25296
- // [STYLE_MARKER, 'width', '200px', 'height', '100px', ...]
25297
- if (this._initialStyleValues.length) {
25298
- attrs.push(literal(2 /* AttributeMarker.Styles */));
25299
- for (let i = 0; i < this._initialStyleValues.length; i += 2) {
25300
- attrs.push(literal(this._initialStyleValues[i]), literal(this._initialStyleValues[i + 1]));
25257
+ else if (binding.value) {
25258
+ const srcSpan = isIvyAst ? bindingSpan : sourceSpan;
25259
+ const valueSpan = moveParseSourceSpan(sourceSpan, binding.value.ast.sourceSpan);
25260
+ this._parsePropertyAst(key, binding.value, false, srcSpan, keySpan, valueSpan, targetMatchableAttrs, targetProps);
25261
+ }
25262
+ else {
25263
+ targetMatchableAttrs.push([key, '' /* value */]);
25264
+ // Since this is a literal attribute with no RHS, source span should be
25265
+ // just the key span.
25266
+ this.parseLiteralAttr(key, null /* value */, keySpan, absoluteValueOffset, undefined /* valueSpan */, targetMatchableAttrs, targetProps, keySpan);
25301
25267
  }
25302
25268
  }
25303
25269
  }
25304
25270
  /**
25305
- * Builds an instruction with all the expressions and parameters for `elementHostAttrs`.
25271
+ * Parses the bindings in a microsyntax expression, e.g.
25272
+ * ```
25273
+ * <tag *tplKey="let value1 = prop; let value2 = localVar">
25274
+ * ```
25306
25275
  *
25307
- * The instruction generation code below is used for producing the AOT statement code which is
25308
- * responsible for registering initial styles (within a directive hostBindings' creation block),
25309
- * as well as any of the provided attribute values, to the directive host element.
25276
+ * @param tplKey template binding name
25277
+ * @param tplValue template binding value
25278
+ * @param sourceSpan span of template binding relative to entire the template
25279
+ * @param absoluteKeyOffset start of the `tplKey`
25280
+ * @param absoluteValueOffset start of the `tplValue`
25310
25281
  */
25311
- assignHostAttrs(attrs, definitionMap) {
25312
- if (this._directiveExpr && (attrs.length || this._hasInitialValues)) {
25313
- this.populateInitialStylingAttrs(attrs);
25314
- definitionMap.set('hostAttrs', literalArr(attrs));
25282
+ _parseTemplateBindings(tplKey, tplValue, sourceSpan, absoluteKeyOffset, absoluteValueOffset) {
25283
+ const sourceInfo = sourceSpan.start.toString();
25284
+ try {
25285
+ const bindingsResult = this._exprParser.parseTemplateBindings(tplKey, tplValue, sourceInfo, absoluteKeyOffset, absoluteValueOffset);
25286
+ this._reportExpressionParserErrors(bindingsResult.errors, sourceSpan);
25287
+ bindingsResult.warnings.forEach((warning) => {
25288
+ this._reportError(warning, sourceSpan, ParseErrorLevel.WARNING);
25289
+ });
25290
+ return bindingsResult.templateBindings;
25291
+ }
25292
+ catch (e) {
25293
+ this._reportError(`${e}`, sourceSpan);
25294
+ return [];
25315
25295
  }
25316
25296
  }
25317
- /**
25318
- * Builds an instruction with all the expressions and parameters for `classMap`.
25319
- *
25320
- * The instruction data will contain all expressions for `classMap` to function
25321
- * which includes the `[class]` expression params.
25322
- */
25323
- buildClassMapInstruction(valueConverter) {
25324
- if (this._classMapInput) {
25325
- return this._buildMapBasedInstruction(valueConverter, true, this._classMapInput);
25326
- }
25327
- return null;
25328
- }
25329
- /**
25330
- * Builds an instruction with all the expressions and parameters for `styleMap`.
25331
- *
25332
- * The instruction data will contain all expressions for `styleMap` to function
25333
- * which includes the `[style]` expression params.
25334
- */
25335
- buildStyleMapInstruction(valueConverter) {
25336
- if (this._styleMapInput) {
25337
- return this._buildMapBasedInstruction(valueConverter, false, this._styleMapInput);
25338
- }
25339
- return null;
25340
- }
25341
- _buildMapBasedInstruction(valueConverter, isClassBased, stylingInput) {
25342
- // each styling binding value is stored in the LView
25343
- // map-based bindings allocate two slots: one for the
25344
- // previous binding value and another for the previous
25345
- // className or style attribute value.
25346
- let totalBindingSlotsRequired = MIN_STYLING_BINDING_SLOTS_REQUIRED;
25347
- // these values must be outside of the update block so that they can
25348
- // be evaluated (the AST visit call) during creation time so that any
25349
- // pipes can be picked up in time before the template is built
25350
- const mapValue = stylingInput.value.visit(valueConverter);
25351
- let reference;
25352
- if (mapValue instanceof Interpolation$1) {
25353
- totalBindingSlotsRequired += mapValue.expressions.length;
25354
- reference = isClassBased ? getClassMapInterpolationExpression(mapValue) :
25355
- getStyleMapInterpolationExpression(mapValue);
25356
- }
25357
- else {
25358
- reference = isClassBased ? Identifiers.classMap : Identifiers.styleMap;
25359
- }
25360
- return {
25361
- reference,
25362
- calls: [{
25363
- supportsInterpolation: true,
25364
- sourceSpan: stylingInput.sourceSpan,
25365
- allocateBindingSlots: totalBindingSlotsRequired,
25366
- params: (convertFn) => {
25367
- const convertResult = convertFn(mapValue);
25368
- const params = Array.isArray(convertResult) ? convertResult : [convertResult];
25369
- return params;
25370
- }
25371
- }]
25372
- };
25373
- }
25374
- _buildSingleInputs(reference, inputs, valueConverter, getInterpolationExpressionFn, isClassBased) {
25375
- const instructions = [];
25376
- inputs.forEach(input => {
25377
- const previousInstruction = instructions[instructions.length - 1];
25378
- const value = input.value.visit(valueConverter);
25379
- let referenceForCall = reference;
25380
- // each styling binding value is stored in the LView
25381
- // but there are two values stored for each binding:
25382
- // 1) the value itself
25383
- // 2) an intermediate value (concatenation of style up to this point).
25384
- // We need to store the intermediate value so that we don't allocate
25385
- // the strings on each CD.
25386
- let totalBindingSlotsRequired = MIN_STYLING_BINDING_SLOTS_REQUIRED;
25387
- if (value instanceof Interpolation$1) {
25388
- totalBindingSlotsRequired += value.expressions.length;
25389
- if (getInterpolationExpressionFn) {
25390
- referenceForCall = getInterpolationExpressionFn(value);
25391
- }
25392
- }
25393
- const call = {
25394
- sourceSpan: input.sourceSpan,
25395
- allocateBindingSlots: totalBindingSlotsRequired,
25396
- supportsInterpolation: !!getInterpolationExpressionFn,
25397
- params: (convertFn) => {
25398
- // params => stylingProp(propName, value, suffix)
25399
- const params = [];
25400
- params.push(literal(input.name));
25401
- const convertResult = convertFn(value);
25402
- if (Array.isArray(convertResult)) {
25403
- params.push(...convertResult);
25404
- }
25405
- else {
25406
- params.push(convertResult);
25407
- }
25408
- // [style.prop] bindings may use suffix values (e.g. px, em, etc...), therefore,
25409
- // if that is detected then we need to pass that in as an optional param.
25410
- if (!isClassBased && input.suffix !== null) {
25411
- params.push(literal(input.suffix));
25412
- }
25413
- return params;
25414
- }
25415
- };
25416
- // If we ended up generating a call to the same instruction as the previous styling property
25417
- // we can chain the calls together safely to save some bytes, otherwise we have to generate
25418
- // a separate instruction call. This is primarily a concern with interpolation instructions
25419
- // where we may start off with one `reference`, but end up using another based on the
25420
- // number of interpolations.
25421
- if (previousInstruction && previousInstruction.reference === referenceForCall) {
25422
- previousInstruction.calls.push(call);
25423
- }
25424
- else {
25425
- instructions.push({ reference: referenceForCall, calls: [call] });
25426
- }
25427
- });
25428
- return instructions;
25429
- }
25430
- _buildClassInputs(valueConverter) {
25431
- if (this._singleClassInputs) {
25432
- return this._buildSingleInputs(Identifiers.classProp, this._singleClassInputs, valueConverter, null, true);
25433
- }
25434
- return [];
25435
- }
25436
- _buildStyleInputs(valueConverter) {
25437
- if (this._singleStyleInputs) {
25438
- return this._buildSingleInputs(Identifiers.styleProp, this._singleStyleInputs, valueConverter, getStylePropInterpolationExpression, false);
25439
- }
25440
- return [];
25441
- }
25442
- /**
25443
- * Constructs all instructions which contain the expressions that will be placed
25444
- * into the update block of a template function or a directive hostBindings function.
25445
- */
25446
- buildUpdateLevelInstructions(valueConverter) {
25447
- const instructions = [];
25448
- if (this.hasBindings) {
25449
- const styleMapInstruction = this.buildStyleMapInstruction(valueConverter);
25450
- if (styleMapInstruction) {
25451
- instructions.push(styleMapInstruction);
25452
- }
25453
- const classMapInstruction = this.buildClassMapInstruction(valueConverter);
25454
- if (classMapInstruction) {
25455
- instructions.push(classMapInstruction);
25456
- }
25457
- instructions.push(...this._buildStyleInputs(valueConverter));
25458
- instructions.push(...this._buildClassInputs(valueConverter));
25459
- }
25460
- return instructions;
25461
- }
25462
- }
25463
- function registerIntoMap(map, key) {
25464
- if (!map.has(key)) {
25465
- map.set(key, map.size);
25466
- }
25467
- }
25468
- function parseProperty(name) {
25469
- let hasOverrideFlag = false;
25470
- const overrideIndex = name.indexOf(IMPORTANT_FLAG);
25471
- if (overrideIndex !== -1) {
25472
- name = overrideIndex > 0 ? name.substring(0, overrideIndex) : '';
25473
- hasOverrideFlag = true;
25474
- }
25475
- let suffix = null;
25476
- let property = name;
25477
- const unitIndex = name.lastIndexOf('.');
25478
- if (unitIndex > 0) {
25479
- suffix = name.slice(unitIndex + 1);
25480
- property = name.substring(0, unitIndex);
25481
- }
25482
- return { property, suffix, hasOverrideFlag };
25483
- }
25484
- /**
25485
- * Gets the instruction to generate for an interpolated class map.
25486
- * @param interpolation An Interpolation AST
25487
- */
25488
- function getClassMapInterpolationExpression(interpolation) {
25489
- switch (getInterpolationArgsLength(interpolation)) {
25490
- case 1:
25491
- return Identifiers.classMap;
25492
- case 3:
25493
- return Identifiers.classMapInterpolate1;
25494
- case 5:
25495
- return Identifiers.classMapInterpolate2;
25496
- case 7:
25497
- return Identifiers.classMapInterpolate3;
25498
- case 9:
25499
- return Identifiers.classMapInterpolate4;
25500
- case 11:
25501
- return Identifiers.classMapInterpolate5;
25502
- case 13:
25503
- return Identifiers.classMapInterpolate6;
25504
- case 15:
25505
- return Identifiers.classMapInterpolate7;
25506
- case 17:
25507
- return Identifiers.classMapInterpolate8;
25508
- default:
25509
- return Identifiers.classMapInterpolateV;
25510
- }
25511
- }
25512
- /**
25513
- * Gets the instruction to generate for an interpolated style map.
25514
- * @param interpolation An Interpolation AST
25515
- */
25516
- function getStyleMapInterpolationExpression(interpolation) {
25517
- switch (getInterpolationArgsLength(interpolation)) {
25518
- case 1:
25519
- return Identifiers.styleMap;
25520
- case 3:
25521
- return Identifiers.styleMapInterpolate1;
25522
- case 5:
25523
- return Identifiers.styleMapInterpolate2;
25524
- case 7:
25525
- return Identifiers.styleMapInterpolate3;
25526
- case 9:
25527
- return Identifiers.styleMapInterpolate4;
25528
- case 11:
25529
- return Identifiers.styleMapInterpolate5;
25530
- case 13:
25531
- return Identifiers.styleMapInterpolate6;
25532
- case 15:
25533
- return Identifiers.styleMapInterpolate7;
25534
- case 17:
25535
- return Identifiers.styleMapInterpolate8;
25536
- default:
25537
- return Identifiers.styleMapInterpolateV;
25538
- }
25539
- }
25540
- /**
25541
- * Gets the instruction to generate for an interpolated style prop.
25542
- * @param interpolation An Interpolation AST
25543
- */
25544
- function getStylePropInterpolationExpression(interpolation) {
25545
- switch (getInterpolationArgsLength(interpolation)) {
25546
- case 1:
25547
- return Identifiers.styleProp;
25548
- case 3:
25549
- return Identifiers.stylePropInterpolate1;
25550
- case 5:
25551
- return Identifiers.stylePropInterpolate2;
25552
- case 7:
25553
- return Identifiers.stylePropInterpolate3;
25554
- case 9:
25555
- return Identifiers.stylePropInterpolate4;
25556
- case 11:
25557
- return Identifiers.stylePropInterpolate5;
25558
- case 13:
25559
- return Identifiers.stylePropInterpolate6;
25560
- case 15:
25561
- return Identifiers.stylePropInterpolate7;
25562
- case 17:
25563
- return Identifiers.stylePropInterpolate8;
25564
- default:
25565
- return Identifiers.stylePropInterpolateV;
25566
- }
25567
- }
25568
- /**
25569
- * Checks whether property name is a custom CSS property.
25570
- * See: https://www.w3.org/TR/css-variables-1
25571
- */
25572
- function isCssCustomProperty(name) {
25573
- return name.startsWith('--');
25574
- }
25575
- function isEmptyExpression(ast) {
25576
- if (ast instanceof ASTWithSource) {
25577
- ast = ast.ast;
25578
- }
25579
- return ast instanceof EmptyExpr$1;
25580
- }
25581
-
25582
- class HtmlParser extends Parser {
25583
- constructor() {
25584
- super(getHtmlTagDefinition);
25585
- }
25586
- parse(source, url, options) {
25587
- return super.parse(source, url, options);
25588
- }
25589
- }
25590
-
25591
- const PRESERVE_WS_ATTR_NAME = 'ngPreserveWhitespaces';
25592
- const SKIP_WS_TRIM_TAGS = new Set(['pre', 'template', 'textarea', 'script', 'style']);
25593
- // Equivalent to \s with \u00a0 (non-breaking space) excluded.
25594
- // Based on https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
25595
- const WS_CHARS = ' \f\n\r\t\v\u1680\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff';
25596
- const NO_WS_REGEXP = new RegExp(`[^${WS_CHARS}]`);
25597
- const WS_REPLACE_REGEXP = new RegExp(`[${WS_CHARS}]{2,}`, 'g');
25598
- function hasPreserveWhitespacesAttr(attrs) {
25599
- return attrs.some((attr) => attr.name === PRESERVE_WS_ATTR_NAME);
25600
- }
25601
- /**
25602
- * &ngsp; is a placeholder for non-removable space
25603
- * &ngsp; is converted to the 0xE500 PUA (Private Use Areas) unicode character
25604
- * and later on replaced by a space.
25605
- */
25606
- function replaceNgsp(value) {
25607
- // lexer is replacing the &ngsp; pseudo-entity with NGSP_UNICODE
25608
- return value.replace(new RegExp(NGSP_UNICODE, 'g'), ' ');
25609
- }
25610
- /**
25611
- * This visitor can walk HTML parse tree and remove / trim text nodes using the following rules:
25612
- * - consider spaces, tabs and new lines as whitespace characters;
25613
- * - drop text nodes consisting of whitespace characters only;
25614
- * - for all other text nodes replace consecutive whitespace characters with one space;
25615
- * - convert &ngsp; pseudo-entity to a single space;
25616
- *
25617
- * Removal and trimming of whitespaces have positive performance impact (less code to generate
25618
- * while compiling templates, faster view creation). At the same time it can be "destructive"
25619
- * in some cases (whitespaces can influence layout). Because of the potential of breaking layout
25620
- * this visitor is not activated by default in Angular 5 and people need to explicitly opt-in for
25621
- * whitespace removal. The default option for whitespace removal will be revisited in Angular 6
25622
- * and might be changed to "on" by default.
25623
- */
25624
- class WhitespaceVisitor {
25625
- visitElement(element, context) {
25626
- if (SKIP_WS_TRIM_TAGS.has(element.name) || hasPreserveWhitespacesAttr(element.attrs)) {
25627
- // don't descent into elements where we need to preserve whitespaces
25628
- // but still visit all attributes to eliminate one used as a market to preserve WS
25629
- return new Element(element.name, visitAll(this, element.attrs), element.children, element.sourceSpan, element.startSourceSpan, element.endSourceSpan, element.i18n);
25630
- }
25631
- return new Element(element.name, element.attrs, visitAllWithSiblings(this, element.children), element.sourceSpan, element.startSourceSpan, element.endSourceSpan, element.i18n);
25632
- }
25633
- visitAttribute(attribute, context) {
25634
- return attribute.name !== PRESERVE_WS_ATTR_NAME ? attribute : null;
25635
- }
25636
- visitText(text, context) {
25637
- const isNotBlank = text.value.match(NO_WS_REGEXP);
25638
- const hasExpansionSibling = context &&
25639
- (context.prev instanceof Expansion || context.next instanceof Expansion);
25640
- if (isNotBlank || hasExpansionSibling) {
25641
- // Process the whitespace in the tokens of this Text node
25642
- const tokens = text.tokens.map(token => token.type === 5 /* TokenType.TEXT */ ? createWhitespaceProcessedTextToken(token) : token);
25643
- // Process the whitespace of the value of this Text node
25644
- const value = processWhitespace(text.value);
25645
- return new Text(value, text.sourceSpan, tokens, text.i18n);
25646
- }
25647
- return null;
25648
- }
25649
- visitComment(comment, context) {
25650
- return comment;
25651
- }
25652
- visitExpansion(expansion, context) {
25653
- return expansion;
25654
- }
25655
- visitExpansionCase(expansionCase, context) {
25656
- return expansionCase;
25657
- }
25658
- visitBlock(block, context) {
25659
- return new Block(block.name, block.parameters, visitAllWithSiblings(this, block.children), block.sourceSpan, block.nameSpan, block.startSourceSpan, block.endSourceSpan);
25660
- }
25661
- visitBlockParameter(parameter, context) {
25662
- return parameter;
25663
- }
25664
- }
25665
- function createWhitespaceProcessedTextToken({ type, parts, sourceSpan }) {
25666
- return { type, parts: [processWhitespace(parts[0])], sourceSpan };
25667
- }
25668
- function processWhitespace(text) {
25669
- return replaceNgsp(text).replace(WS_REPLACE_REGEXP, ' ');
25670
- }
25671
- function removeWhitespaces(htmlAstWithErrors) {
25672
- return new ParseTreeResult(visitAll(new WhitespaceVisitor(), htmlAstWithErrors.rootNodes), htmlAstWithErrors.errors);
25673
- }
25674
- function visitAllWithSiblings(visitor, nodes) {
25675
- const result = [];
25676
- nodes.forEach((ast, i) => {
25677
- const context = { prev: nodes[i - 1], next: nodes[i + 1] };
25678
- const astResult = ast.visit(visitor, context);
25679
- if (astResult) {
25680
- result.push(astResult);
25681
- }
25682
- });
25683
- return result;
25684
- }
25685
-
25686
- const PROPERTY_PARTS_SEPARATOR = '.';
25687
- const ATTRIBUTE_PREFIX = 'attr';
25688
- const CLASS_PREFIX = 'class';
25689
- const STYLE_PREFIX = 'style';
25690
- const TEMPLATE_ATTR_PREFIX$1 = '*';
25691
- const ANIMATE_PROP_PREFIX = 'animate-';
25692
- /**
25693
- * Parses bindings in templates and in the directive host area.
25694
- */
25695
- class BindingParser {
25696
- constructor(_exprParser, _interpolationConfig, _schemaRegistry, errors) {
25697
- this._exprParser = _exprParser;
25698
- this._interpolationConfig = _interpolationConfig;
25699
- this._schemaRegistry = _schemaRegistry;
25700
- this.errors = errors;
25701
- }
25702
- get interpolationConfig() {
25703
- return this._interpolationConfig;
25704
- }
25705
- createBoundHostProperties(properties, sourceSpan) {
25706
- const boundProps = [];
25707
- for (const propName of Object.keys(properties)) {
25708
- const expression = properties[propName];
25709
- if (typeof expression === 'string') {
25710
- this.parsePropertyBinding(propName, expression, true, false, sourceSpan, sourceSpan.start.offset, undefined, [],
25711
- // Use the `sourceSpan` for `keySpan`. This isn't really accurate, but neither is the
25712
- // sourceSpan, as it represents the sourceSpan of the host itself rather than the
25713
- // source of the host binding (which doesn't exist in the template). Regardless,
25714
- // neither of these values are used in Ivy but are only here to satisfy the function
25715
- // signature. This should likely be refactored in the future so that `sourceSpan`
25716
- // isn't being used inaccurately.
25717
- boundProps, sourceSpan);
25718
- }
25719
- else {
25720
- this._reportError(`Value of the host property binding "${propName}" needs to be a string representing an expression but got "${expression}" (${typeof expression})`, sourceSpan);
25721
- }
25722
- }
25723
- return boundProps;
25724
- }
25725
- createDirectiveHostEventAsts(hostListeners, sourceSpan) {
25726
- const targetEvents = [];
25727
- for (const propName of Object.keys(hostListeners)) {
25728
- const expression = hostListeners[propName];
25729
- if (typeof expression === 'string') {
25730
- // Use the `sourceSpan` for `keySpan` and `handlerSpan`. This isn't really accurate, but
25731
- // neither is the `sourceSpan`, as it represents the `sourceSpan` of the host itself
25732
- // rather than the source of the host binding (which doesn't exist in the template).
25733
- // Regardless, neither of these values are used in Ivy but are only here to satisfy the
25734
- // function signature. This should likely be refactored in the future so that `sourceSpan`
25735
- // isn't being used inaccurately.
25736
- this.parseEvent(propName, expression, /* isAssignmentEvent */ false, sourceSpan, sourceSpan, [], targetEvents, sourceSpan);
25737
- }
25738
- else {
25739
- this._reportError(`Value of the host listener "${propName}" needs to be a string representing an expression but got "${expression}" (${typeof expression})`, sourceSpan);
25740
- }
25741
- }
25742
- return targetEvents;
25743
- }
25744
- parseInterpolation(value, sourceSpan, interpolatedTokens) {
25745
- const sourceInfo = sourceSpan.start.toString();
25746
- const absoluteOffset = sourceSpan.fullStart.offset;
25747
- try {
25748
- const ast = this._exprParser.parseInterpolation(value, sourceInfo, absoluteOffset, interpolatedTokens, this._interpolationConfig);
25749
- if (ast)
25750
- this._reportExpressionParserErrors(ast.errors, sourceSpan);
25751
- return ast;
25752
- }
25753
- catch (e) {
25754
- this._reportError(`${e}`, sourceSpan);
25755
- return this._exprParser.wrapLiteralPrimitive('ERROR', sourceInfo, absoluteOffset);
25756
- }
25757
- }
25758
- /**
25759
- * Similar to `parseInterpolation`, but treats the provided string as a single expression
25760
- * element that would normally appear within the interpolation prefix and suffix (`{{` and `}}`).
25761
- * This is used for parsing the switch expression in ICUs.
25762
- */
25763
- parseInterpolationExpression(expression, sourceSpan) {
25764
- const sourceInfo = sourceSpan.start.toString();
25765
- const absoluteOffset = sourceSpan.start.offset;
25766
- try {
25767
- const ast = this._exprParser.parseInterpolationExpression(expression, sourceInfo, absoluteOffset);
25768
- if (ast)
25769
- this._reportExpressionParserErrors(ast.errors, sourceSpan);
25770
- return ast;
25771
- }
25772
- catch (e) {
25773
- this._reportError(`${e}`, sourceSpan);
25774
- return this._exprParser.wrapLiteralPrimitive('ERROR', sourceInfo, absoluteOffset);
25775
- }
25776
- }
25777
- /**
25778
- * Parses the bindings in a microsyntax expression, and converts them to
25779
- * `ParsedProperty` or `ParsedVariable`.
25780
- *
25781
- * @param tplKey template binding name
25782
- * @param tplValue template binding value
25783
- * @param sourceSpan span of template binding relative to entire the template
25784
- * @param absoluteValueOffset start of the tplValue relative to the entire template
25785
- * @param targetMatchableAttrs potential attributes to match in the template
25786
- * @param targetProps target property bindings in the template
25787
- * @param targetVars target variables in the template
25788
- */
25789
- parseInlineTemplateBinding(tplKey, tplValue, sourceSpan, absoluteValueOffset, targetMatchableAttrs, targetProps, targetVars, isIvyAst) {
25790
- const absoluteKeyOffset = sourceSpan.start.offset + TEMPLATE_ATTR_PREFIX$1.length;
25791
- const bindings = this._parseTemplateBindings(tplKey, tplValue, sourceSpan, absoluteKeyOffset, absoluteValueOffset);
25792
- for (const binding of bindings) {
25793
- // sourceSpan is for the entire HTML attribute. bindingSpan is for a particular
25794
- // binding within the microsyntax expression so it's more narrow than sourceSpan.
25795
- const bindingSpan = moveParseSourceSpan(sourceSpan, binding.sourceSpan);
25796
- const key = binding.key.source;
25797
- const keySpan = moveParseSourceSpan(sourceSpan, binding.key.span);
25798
- if (binding instanceof VariableBinding) {
25799
- const value = binding.value ? binding.value.source : '$implicit';
25800
- const valueSpan = binding.value ? moveParseSourceSpan(sourceSpan, binding.value.span) : undefined;
25801
- targetVars.push(new ParsedVariable(key, value, bindingSpan, keySpan, valueSpan));
25802
- }
25803
- else if (binding.value) {
25804
- const srcSpan = isIvyAst ? bindingSpan : sourceSpan;
25805
- const valueSpan = moveParseSourceSpan(sourceSpan, binding.value.ast.sourceSpan);
25806
- this._parsePropertyAst(key, binding.value, false, srcSpan, keySpan, valueSpan, targetMatchableAttrs, targetProps);
25807
- }
25808
- else {
25809
- targetMatchableAttrs.push([key, '' /* value */]);
25810
- // Since this is a literal attribute with no RHS, source span should be
25811
- // just the key span.
25812
- this.parseLiteralAttr(key, null /* value */, keySpan, absoluteValueOffset, undefined /* valueSpan */, targetMatchableAttrs, targetProps, keySpan);
25813
- }
25814
- }
25815
- }
25816
- /**
25817
- * Parses the bindings in a microsyntax expression, e.g.
25818
- * ```
25819
- * <tag *tplKey="let value1 = prop; let value2 = localVar">
25820
- * ```
25821
- *
25822
- * @param tplKey template binding name
25823
- * @param tplValue template binding value
25824
- * @param sourceSpan span of template binding relative to entire the template
25825
- * @param absoluteKeyOffset start of the `tplKey`
25826
- * @param absoluteValueOffset start of the `tplValue`
25827
- */
25828
- _parseTemplateBindings(tplKey, tplValue, sourceSpan, absoluteKeyOffset, absoluteValueOffset) {
25829
- const sourceInfo = sourceSpan.start.toString();
25830
- try {
25831
- const bindingsResult = this._exprParser.parseTemplateBindings(tplKey, tplValue, sourceInfo, absoluteKeyOffset, absoluteValueOffset);
25832
- this._reportExpressionParserErrors(bindingsResult.errors, sourceSpan);
25833
- bindingsResult.warnings.forEach((warning) => {
25834
- this._reportError(warning, sourceSpan, ParseErrorLevel.WARNING);
25835
- });
25836
- return bindingsResult.templateBindings;
25837
- }
25838
- catch (e) {
25839
- this._reportError(`${e}`, sourceSpan);
25840
- return [];
25841
- }
25842
- }
25843
- parseLiteralAttr(name, value, sourceSpan, absoluteOffset, valueSpan, targetMatchableAttrs, targetProps, keySpan) {
25844
- if (isAnimationLabel(name)) {
25845
- name = name.substring(1);
25846
- if (keySpan !== undefined) {
25847
- keySpan = moveParseSourceSpan(keySpan, new AbsoluteSourceSpan(keySpan.start.offset + 1, keySpan.end.offset));
25848
- }
25849
- if (value) {
25850
- this._reportError(`Assigning animation triggers via @prop="exp" attributes with an expression is invalid.` +
25851
- ` Use property bindings (e.g. [@prop]="exp") or use an attribute without a value (e.g. @prop) instead.`, sourceSpan, ParseErrorLevel.ERROR);
25852
- }
25853
- this._parseAnimation(name, value, sourceSpan, absoluteOffset, keySpan, valueSpan, targetMatchableAttrs, targetProps);
25854
- }
25855
- else {
25856
- targetProps.push(new ParsedProperty(name, this._exprParser.wrapLiteralPrimitive(value, '', absoluteOffset), ParsedPropertyType.LITERAL_ATTR, sourceSpan, keySpan, valueSpan));
25297
+ parseLiteralAttr(name, value, sourceSpan, absoluteOffset, valueSpan, targetMatchableAttrs, targetProps, keySpan) {
25298
+ if (isAnimationLabel(name)) {
25299
+ name = name.substring(1);
25300
+ if (keySpan !== undefined) {
25301
+ keySpan = moveParseSourceSpan(keySpan, new AbsoluteSourceSpan(keySpan.start.offset + 1, keySpan.end.offset));
25302
+ }
25303
+ if (value) {
25304
+ this._reportError(`Assigning animation triggers via @prop="exp" attributes with an expression is invalid.` +
25305
+ ` Use property bindings (e.g. [@prop]="exp") or use an attribute without a value (e.g. @prop) instead.`, sourceSpan, ParseErrorLevel.ERROR);
25306
+ }
25307
+ this._parseAnimation(name, value, sourceSpan, absoluteOffset, keySpan, valueSpan, targetMatchableAttrs, targetProps);
25308
+ }
25309
+ else {
25310
+ targetProps.push(new ParsedProperty(name, this._exprParser.wrapLiteralPrimitive(value, '', absoluteOffset), ParsedPropertyType.LITERAL_ATTR, sourceSpan, keySpan, valueSpan));
25857
25311
  }
25858
25312
  }
25859
25313
  parsePropertyBinding(name, expression, isHost, isPartOfAssignmentBinding, sourceSpan, absoluteOffset, valueSpan, targetMatchableAttrs, targetProps, keySpan) {
@@ -27676,103 +27130,632 @@ class I18nContext {
27676
27130
  this.appendTag(TagType.ELEMENT, node, index, true);
27677
27131
  }
27678
27132
  /**
27679
- * Generates an instance of a child context based on the root one,
27680
- * when we enter a nested template within I18n section.
27133
+ * Generates an instance of a child context based on the root one,
27134
+ * when we enter a nested template within I18n section.
27135
+ *
27136
+ * @param index Instruction index of corresponding i18nStart, which initiates this context
27137
+ * @param templateIndex Instruction index of a template which this context belongs to
27138
+ * @param meta Meta information (id, meaning, description, etc) associated with this context
27139
+ *
27140
+ * @returns I18nContext instance
27141
+ */
27142
+ forkChildContext(index, templateIndex, meta) {
27143
+ return new I18nContext(index, this.ref, this.level + 1, templateIndex, meta, this._registry);
27144
+ }
27145
+ /**
27146
+ * Reconciles child context into parent one once the end of the i18n block is reached (i18nEnd).
27147
+ *
27148
+ * @param context Child I18nContext instance to be reconciled with parent context.
27149
+ */
27150
+ reconcileChildContext(context) {
27151
+ // set the right context id for open and close
27152
+ // template tags, so we can use it as sub-block ids
27153
+ ['start', 'close'].forEach((op) => {
27154
+ const key = context.meta[`${op}Name`];
27155
+ const phs = this.placeholders.get(key) || [];
27156
+ const tag = phs.find(findTemplateFn(this.id, context.templateIndex));
27157
+ if (tag) {
27158
+ tag.ctx = context.id;
27159
+ }
27160
+ });
27161
+ // reconcile placeholders
27162
+ const childPhs = context.placeholders;
27163
+ childPhs.forEach((values, key) => {
27164
+ const phs = this.placeholders.get(key);
27165
+ if (!phs) {
27166
+ this.placeholders.set(key, values);
27167
+ return;
27168
+ }
27169
+ // try to find matching template...
27170
+ const tmplIdx = phs.findIndex(findTemplateFn(context.id, context.templateIndex));
27171
+ if (tmplIdx >= 0) {
27172
+ // ... if found - replace it with nested template content
27173
+ const isCloseTag = key.startsWith('CLOSE');
27174
+ const isTemplateTag = key.endsWith('NG-TEMPLATE');
27175
+ if (isTemplateTag) {
27176
+ // current template's content is placed before or after
27177
+ // parent template tag, depending on the open/close attribute
27178
+ phs.splice(tmplIdx + (isCloseTag ? 0 : 1), 0, ...values);
27179
+ }
27180
+ else {
27181
+ const idx = isCloseTag ? values.length - 1 : 0;
27182
+ values[idx].tmpl = phs[tmplIdx];
27183
+ phs.splice(tmplIdx, 1, ...values);
27184
+ }
27185
+ }
27186
+ else {
27187
+ // ... otherwise just append content to placeholder value
27188
+ phs.push(...values);
27189
+ }
27190
+ this.placeholders.set(key, phs);
27191
+ });
27192
+ this._unresolvedCtxCount--;
27193
+ }
27194
+ }
27195
+ //
27196
+ // Helper methods
27197
+ //
27198
+ function wrap(symbol, index, contextId, closed) {
27199
+ const state = closed ? '/' : '';
27200
+ return wrapI18nPlaceholder(`${state}${symbol}${index}`, contextId);
27201
+ }
27202
+ function wrapTag(symbol, { index, ctx, isVoid }, closed) {
27203
+ return isVoid ? wrap(symbol, index, ctx) + wrap(symbol, index, ctx, true) :
27204
+ wrap(symbol, index, ctx, closed);
27205
+ }
27206
+ function findTemplateFn(ctx, templateIndex) {
27207
+ return (token) => typeof token === 'object' && token.type === TagType.TEMPLATE &&
27208
+ token.index === templateIndex && token.ctx === ctx;
27209
+ }
27210
+ function serializePlaceholderValue(value) {
27211
+ const element = (data, closed) => wrapTag('#', data, closed);
27212
+ const template = (data, closed) => wrapTag('*', data, closed);
27213
+ switch (value.type) {
27214
+ case TagType.ELEMENT:
27215
+ // close element tag
27216
+ if (value.closed) {
27217
+ return element(value, true) + (value.tmpl ? template(value.tmpl, true) : '');
27218
+ }
27219
+ // open element tag that also initiates a template
27220
+ if (value.tmpl) {
27221
+ return template(value.tmpl) + element(value) +
27222
+ (value.isVoid ? template(value.tmpl, true) : '');
27223
+ }
27224
+ return element(value);
27225
+ case TagType.TEMPLATE:
27226
+ return template(value, value.closed);
27227
+ default:
27228
+ return value;
27229
+ }
27230
+ }
27231
+
27232
+ const IMPORTANT_FLAG = '!important';
27233
+ /**
27234
+ * Minimum amount of binding slots required in the runtime for style/class bindings.
27235
+ *
27236
+ * Styling in Angular uses up two slots in the runtime LView/TData data structures to
27237
+ * record binding data, property information and metadata.
27238
+ *
27239
+ * When a binding is registered it will place the following information in the `LView`:
27240
+ *
27241
+ * slot 1) binding value
27242
+ * slot 2) cached value (all other values collected before it in string form)
27243
+ *
27244
+ * When a binding is registered it will place the following information in the `TData`:
27245
+ *
27246
+ * slot 1) prop name
27247
+ * slot 2) binding index that points to the previous style/class binding (and some extra config
27248
+ * values)
27249
+ *
27250
+ * Let's imagine we have a binding that looks like so:
27251
+ *
27252
+ * ```
27253
+ * <div [style.width]="x" [style.height]="y">
27254
+ * ```
27255
+ *
27256
+ * Our `LView` and `TData` data-structures look like so:
27257
+ *
27258
+ * ```typescript
27259
+ * LView = [
27260
+ * // ...
27261
+ * x, // value of x
27262
+ * "width: x",
27263
+ *
27264
+ * y, // value of y
27265
+ * "width: x; height: y",
27266
+ * // ...
27267
+ * ];
27268
+ *
27269
+ * TData = [
27270
+ * // ...
27271
+ * "width", // binding slot 20
27272
+ * 0,
27273
+ *
27274
+ * "height",
27275
+ * 20,
27276
+ * // ...
27277
+ * ];
27278
+ * ```
27279
+ *
27280
+ * */
27281
+ const MIN_STYLING_BINDING_SLOTS_REQUIRED = 2;
27282
+ /**
27283
+ * Produces creation/update instructions for all styling bindings (class and style)
27284
+ *
27285
+ * It also produces the creation instruction to register all initial styling values
27286
+ * (which are all the static class="..." and style="..." attribute values that exist
27287
+ * on an element within a template).
27288
+ *
27289
+ * The builder class below handles producing instructions for the following cases:
27290
+ *
27291
+ * - Static style/class attributes (style="..." and class="...")
27292
+ * - Dynamic style/class map bindings ([style]="map" and [class]="map|string")
27293
+ * - Dynamic style/class property bindings ([style.prop]="exp" and [class.name]="exp")
27294
+ *
27295
+ * Due to the complex relationship of all of these cases, the instructions generated
27296
+ * for these attributes/properties/bindings must be done so in the correct order. The
27297
+ * order which these must be generated is as follows:
27298
+ *
27299
+ * if (createMode) {
27300
+ * styling(...)
27301
+ * }
27302
+ * if (updateMode) {
27303
+ * styleMap(...)
27304
+ * classMap(...)
27305
+ * styleProp(...)
27306
+ * classProp(...)
27307
+ * }
27308
+ *
27309
+ * The creation/update methods within the builder class produce these instructions.
27310
+ */
27311
+ class StylingBuilder {
27312
+ constructor(_directiveExpr) {
27313
+ this._directiveExpr = _directiveExpr;
27314
+ /** Whether or not there are any static styling values present */
27315
+ this._hasInitialValues = false;
27316
+ /**
27317
+ * Whether or not there are any styling bindings present
27318
+ * (i.e. `[style]`, `[class]`, `[style.prop]` or `[class.name]`)
27319
+ */
27320
+ this.hasBindings = false;
27321
+ this.hasBindingsWithPipes = false;
27322
+ /** the input for [class] (if it exists) */
27323
+ this._classMapInput = null;
27324
+ /** the input for [style] (if it exists) */
27325
+ this._styleMapInput = null;
27326
+ /** an array of each [style.prop] input */
27327
+ this._singleStyleInputs = null;
27328
+ /** an array of each [class.name] input */
27329
+ this._singleClassInputs = null;
27330
+ this._lastStylingInput = null;
27331
+ this._firstStylingInput = null;
27332
+ // maps are used instead of hash maps because a Map will
27333
+ // retain the ordering of the keys
27334
+ /**
27335
+ * Represents the location of each style binding in the template
27336
+ * (e.g. `<div [style.width]="w" [style.height]="h">` implies
27337
+ * that `width=0` and `height=1`)
27338
+ */
27339
+ this._stylesIndex = new Map();
27340
+ /**
27341
+ * Represents the location of each class binding in the template
27342
+ * (e.g. `<div [class.big]="b" [class.hidden]="h">` implies
27343
+ * that `big=0` and `hidden=1`)
27344
+ */
27345
+ this._classesIndex = new Map();
27346
+ this._initialStyleValues = [];
27347
+ this._initialClassValues = [];
27348
+ }
27349
+ /**
27350
+ * Registers a given input to the styling builder to be later used when producing AOT code.
27351
+ *
27352
+ * The code below will only accept the input if it is somehow tied to styling (whether it be
27353
+ * style/class bindings or static style/class attributes).
27354
+ */
27355
+ registerBoundInput(input) {
27356
+ // [attr.style] or [attr.class] are skipped in the code below,
27357
+ // they should not be treated as styling-based bindings since
27358
+ // they are intended to be written directly to the attr and
27359
+ // will therefore skip all style/class resolution that is present
27360
+ // with style="", [style]="" and [style.prop]="", class="",
27361
+ // [class.prop]="". [class]="" assignments
27362
+ let binding = null;
27363
+ let name = input.name;
27364
+ switch (input.type) {
27365
+ case 0 /* BindingType.Property */:
27366
+ binding = this.registerInputBasedOnName(name, input.value, input.sourceSpan);
27367
+ break;
27368
+ case 3 /* BindingType.Style */:
27369
+ binding = this.registerStyleInput(name, false, input.value, input.sourceSpan, input.unit);
27370
+ break;
27371
+ case 2 /* BindingType.Class */:
27372
+ binding = this.registerClassInput(name, false, input.value, input.sourceSpan);
27373
+ break;
27374
+ }
27375
+ return binding ? true : false;
27376
+ }
27377
+ registerInputBasedOnName(name, expression, sourceSpan) {
27378
+ let binding = null;
27379
+ const prefix = name.substring(0, 6);
27380
+ const isStyle = name === 'style' || prefix === 'style.' || prefix === 'style!';
27381
+ const isClass = !isStyle && (name === 'class' || prefix === 'class.' || prefix === 'class!');
27382
+ if (isStyle || isClass) {
27383
+ const isMapBased = name.charAt(5) !== '.'; // style.prop or class.prop makes this a no
27384
+ const property = name.slice(isMapBased ? 5 : 6); // the dot explains why there's a +1
27385
+ if (isStyle) {
27386
+ binding = this.registerStyleInput(property, isMapBased, expression, sourceSpan);
27387
+ }
27388
+ else {
27389
+ binding = this.registerClassInput(property, isMapBased, expression, sourceSpan);
27390
+ }
27391
+ }
27392
+ return binding;
27393
+ }
27394
+ registerStyleInput(name, isMapBased, value, sourceSpan, suffix) {
27395
+ if (isEmptyExpression(value)) {
27396
+ return null;
27397
+ }
27398
+ // CSS custom properties are case-sensitive so we shouldn't normalize them.
27399
+ // See: https://www.w3.org/TR/css-variables-1/#defining-variables
27400
+ if (!isCssCustomProperty(name)) {
27401
+ name = hyphenate(name);
27402
+ }
27403
+ const { property, hasOverrideFlag, suffix: bindingSuffix } = parseProperty(name);
27404
+ suffix = typeof suffix === 'string' && suffix.length !== 0 ? suffix : bindingSuffix;
27405
+ const entry = { name: property, suffix: suffix, value, sourceSpan, hasOverrideFlag };
27406
+ if (isMapBased) {
27407
+ this._styleMapInput = entry;
27408
+ }
27409
+ else {
27410
+ (this._singleStyleInputs = this._singleStyleInputs || []).push(entry);
27411
+ registerIntoMap(this._stylesIndex, property);
27412
+ }
27413
+ this._lastStylingInput = entry;
27414
+ this._firstStylingInput = this._firstStylingInput || entry;
27415
+ this._checkForPipes(value);
27416
+ this.hasBindings = true;
27417
+ return entry;
27418
+ }
27419
+ registerClassInput(name, isMapBased, value, sourceSpan) {
27420
+ if (isEmptyExpression(value)) {
27421
+ return null;
27422
+ }
27423
+ const { property, hasOverrideFlag } = parseProperty(name);
27424
+ const entry = { name: property, value, sourceSpan, hasOverrideFlag, suffix: null };
27425
+ if (isMapBased) {
27426
+ this._classMapInput = entry;
27427
+ }
27428
+ else {
27429
+ (this._singleClassInputs = this._singleClassInputs || []).push(entry);
27430
+ registerIntoMap(this._classesIndex, property);
27431
+ }
27432
+ this._lastStylingInput = entry;
27433
+ this._firstStylingInput = this._firstStylingInput || entry;
27434
+ this._checkForPipes(value);
27435
+ this.hasBindings = true;
27436
+ return entry;
27437
+ }
27438
+ _checkForPipes(value) {
27439
+ if ((value instanceof ASTWithSource) && (value.ast instanceof BindingPipe)) {
27440
+ this.hasBindingsWithPipes = true;
27441
+ }
27442
+ }
27443
+ /**
27444
+ * Registers the element's static style string value to the builder.
27445
+ *
27446
+ * @param value the style string (e.g. `width:100px; height:200px;`)
27447
+ */
27448
+ registerStyleAttr(value) {
27449
+ this._initialStyleValues = parse(value);
27450
+ this._hasInitialValues = true;
27451
+ }
27452
+ /**
27453
+ * Registers the element's static class string value to the builder.
27454
+ *
27455
+ * @param value the className string (e.g. `disabled gold zoom`)
27456
+ */
27457
+ registerClassAttr(value) {
27458
+ this._initialClassValues = value.trim().split(/\s+/g);
27459
+ this._hasInitialValues = true;
27460
+ }
27461
+ /**
27462
+ * Appends all styling-related expressions to the provided attrs array.
27681
27463
  *
27682
- * @param index Instruction index of corresponding i18nStart, which initiates this context
27683
- * @param templateIndex Instruction index of a template which this context belongs to
27684
- * @param meta Meta information (id, meaning, description, etc) associated with this context
27464
+ * @param attrs an existing array where each of the styling expressions
27465
+ * will be inserted into.
27466
+ */
27467
+ populateInitialStylingAttrs(attrs) {
27468
+ // [CLASS_MARKER, 'foo', 'bar', 'baz' ...]
27469
+ if (this._initialClassValues.length) {
27470
+ attrs.push(literal(1 /* AttributeMarker.Classes */));
27471
+ for (let i = 0; i < this._initialClassValues.length; i++) {
27472
+ attrs.push(literal(this._initialClassValues[i]));
27473
+ }
27474
+ }
27475
+ // [STYLE_MARKER, 'width', '200px', 'height', '100px', ...]
27476
+ if (this._initialStyleValues.length) {
27477
+ attrs.push(literal(2 /* AttributeMarker.Styles */));
27478
+ for (let i = 0; i < this._initialStyleValues.length; i += 2) {
27479
+ attrs.push(literal(this._initialStyleValues[i]), literal(this._initialStyleValues[i + 1]));
27480
+ }
27481
+ }
27482
+ }
27483
+ /**
27484
+ * Builds an instruction with all the expressions and parameters for `elementHostAttrs`.
27685
27485
  *
27686
- * @returns I18nContext instance
27486
+ * The instruction generation code below is used for producing the AOT statement code which is
27487
+ * responsible for registering initial styles (within a directive hostBindings' creation block),
27488
+ * as well as any of the provided attribute values, to the directive host element.
27687
27489
  */
27688
- forkChildContext(index, templateIndex, meta) {
27689
- return new I18nContext(index, this.ref, this.level + 1, templateIndex, meta, this._registry);
27490
+ assignHostAttrs(attrs, definitionMap) {
27491
+ if (this._directiveExpr && (attrs.length || this._hasInitialValues)) {
27492
+ this.populateInitialStylingAttrs(attrs);
27493
+ definitionMap.set('hostAttrs', literalArr(attrs));
27494
+ }
27690
27495
  }
27691
27496
  /**
27692
- * Reconciles child context into parent one once the end of the i18n block is reached (i18nEnd).
27497
+ * Builds an instruction with all the expressions and parameters for `classMap`.
27693
27498
  *
27694
- * @param context Child I18nContext instance to be reconciled with parent context.
27499
+ * The instruction data will contain all expressions for `classMap` to function
27500
+ * which includes the `[class]` expression params.
27695
27501
  */
27696
- reconcileChildContext(context) {
27697
- // set the right context id for open and close
27698
- // template tags, so we can use it as sub-block ids
27699
- ['start', 'close'].forEach((op) => {
27700
- const key = context.meta[`${op}Name`];
27701
- const phs = this.placeholders.get(key) || [];
27702
- const tag = phs.find(findTemplateFn(this.id, context.templateIndex));
27703
- if (tag) {
27704
- tag.ctx = context.id;
27705
- }
27706
- });
27707
- // reconcile placeholders
27708
- const childPhs = context.placeholders;
27709
- childPhs.forEach((values, key) => {
27710
- const phs = this.placeholders.get(key);
27711
- if (!phs) {
27712
- this.placeholders.set(key, values);
27713
- return;
27714
- }
27715
- // try to find matching template...
27716
- const tmplIdx = phs.findIndex(findTemplateFn(context.id, context.templateIndex));
27717
- if (tmplIdx >= 0) {
27718
- // ... if found - replace it with nested template content
27719
- const isCloseTag = key.startsWith('CLOSE');
27720
- const isTemplateTag = key.endsWith('NG-TEMPLATE');
27721
- if (isTemplateTag) {
27722
- // current template's content is placed before or after
27723
- // parent template tag, depending on the open/close attribute
27724
- phs.splice(tmplIdx + (isCloseTag ? 0 : 1), 0, ...values);
27502
+ buildClassMapInstruction(valueConverter) {
27503
+ if (this._classMapInput) {
27504
+ return this._buildMapBasedInstruction(valueConverter, true, this._classMapInput);
27505
+ }
27506
+ return null;
27507
+ }
27508
+ /**
27509
+ * Builds an instruction with all the expressions and parameters for `styleMap`.
27510
+ *
27511
+ * The instruction data will contain all expressions for `styleMap` to function
27512
+ * which includes the `[style]` expression params.
27513
+ */
27514
+ buildStyleMapInstruction(valueConverter) {
27515
+ if (this._styleMapInput) {
27516
+ return this._buildMapBasedInstruction(valueConverter, false, this._styleMapInput);
27517
+ }
27518
+ return null;
27519
+ }
27520
+ _buildMapBasedInstruction(valueConverter, isClassBased, stylingInput) {
27521
+ // each styling binding value is stored in the LView
27522
+ // map-based bindings allocate two slots: one for the
27523
+ // previous binding value and another for the previous
27524
+ // className or style attribute value.
27525
+ let totalBindingSlotsRequired = MIN_STYLING_BINDING_SLOTS_REQUIRED;
27526
+ // these values must be outside of the update block so that they can
27527
+ // be evaluated (the AST visit call) during creation time so that any
27528
+ // pipes can be picked up in time before the template is built
27529
+ const mapValue = stylingInput.value.visit(valueConverter);
27530
+ let reference;
27531
+ if (mapValue instanceof Interpolation$1) {
27532
+ totalBindingSlotsRequired += mapValue.expressions.length;
27533
+ reference = isClassBased ? getClassMapInterpolationExpression(mapValue) :
27534
+ getStyleMapInterpolationExpression(mapValue);
27535
+ }
27536
+ else {
27537
+ reference = isClassBased ? Identifiers.classMap : Identifiers.styleMap;
27538
+ }
27539
+ return {
27540
+ reference,
27541
+ calls: [{
27542
+ supportsInterpolation: true,
27543
+ sourceSpan: stylingInput.sourceSpan,
27544
+ allocateBindingSlots: totalBindingSlotsRequired,
27545
+ params: (convertFn) => {
27546
+ const convertResult = convertFn(mapValue);
27547
+ const params = Array.isArray(convertResult) ? convertResult : [convertResult];
27548
+ return params;
27549
+ }
27550
+ }]
27551
+ };
27552
+ }
27553
+ _buildSingleInputs(reference, inputs, valueConverter, getInterpolationExpressionFn, isClassBased) {
27554
+ const instructions = [];
27555
+ inputs.forEach(input => {
27556
+ const previousInstruction = instructions[instructions.length - 1];
27557
+ const value = input.value.visit(valueConverter);
27558
+ let referenceForCall = reference;
27559
+ // each styling binding value is stored in the LView
27560
+ // but there are two values stored for each binding:
27561
+ // 1) the value itself
27562
+ // 2) an intermediate value (concatenation of style up to this point).
27563
+ // We need to store the intermediate value so that we don't allocate
27564
+ // the strings on each CD.
27565
+ let totalBindingSlotsRequired = MIN_STYLING_BINDING_SLOTS_REQUIRED;
27566
+ if (value instanceof Interpolation$1) {
27567
+ totalBindingSlotsRequired += value.expressions.length;
27568
+ if (getInterpolationExpressionFn) {
27569
+ referenceForCall = getInterpolationExpressionFn(value);
27725
27570
  }
27726
- else {
27727
- const idx = isCloseTag ? values.length - 1 : 0;
27728
- values[idx].tmpl = phs[tmplIdx];
27729
- phs.splice(tmplIdx, 1, ...values);
27571
+ }
27572
+ const call = {
27573
+ sourceSpan: input.sourceSpan,
27574
+ allocateBindingSlots: totalBindingSlotsRequired,
27575
+ supportsInterpolation: !!getInterpolationExpressionFn,
27576
+ params: (convertFn) => {
27577
+ // params => stylingProp(propName, value, suffix)
27578
+ const params = [];
27579
+ params.push(literal(input.name));
27580
+ const convertResult = convertFn(value);
27581
+ if (Array.isArray(convertResult)) {
27582
+ params.push(...convertResult);
27583
+ }
27584
+ else {
27585
+ params.push(convertResult);
27586
+ }
27587
+ // [style.prop] bindings may use suffix values (e.g. px, em, etc...), therefore,
27588
+ // if that is detected then we need to pass that in as an optional param.
27589
+ if (!isClassBased && input.suffix !== null) {
27590
+ params.push(literal(input.suffix));
27591
+ }
27592
+ return params;
27730
27593
  }
27594
+ };
27595
+ // If we ended up generating a call to the same instruction as the previous styling property
27596
+ // we can chain the calls together safely to save some bytes, otherwise we have to generate
27597
+ // a separate instruction call. This is primarily a concern with interpolation instructions
27598
+ // where we may start off with one `reference`, but end up using another based on the
27599
+ // number of interpolations.
27600
+ if (previousInstruction && previousInstruction.reference === referenceForCall) {
27601
+ previousInstruction.calls.push(call);
27731
27602
  }
27732
27603
  else {
27733
- // ... otherwise just append content to placeholder value
27734
- phs.push(...values);
27604
+ instructions.push({ reference: referenceForCall, calls: [call] });
27735
27605
  }
27736
- this.placeholders.set(key, phs);
27737
27606
  });
27738
- this._unresolvedCtxCount--;
27607
+ return instructions;
27608
+ }
27609
+ _buildClassInputs(valueConverter) {
27610
+ if (this._singleClassInputs) {
27611
+ return this._buildSingleInputs(Identifiers.classProp, this._singleClassInputs, valueConverter, null, true);
27612
+ }
27613
+ return [];
27614
+ }
27615
+ _buildStyleInputs(valueConverter) {
27616
+ if (this._singleStyleInputs) {
27617
+ return this._buildSingleInputs(Identifiers.styleProp, this._singleStyleInputs, valueConverter, getStylePropInterpolationExpression, false);
27618
+ }
27619
+ return [];
27620
+ }
27621
+ /**
27622
+ * Constructs all instructions which contain the expressions that will be placed
27623
+ * into the update block of a template function or a directive hostBindings function.
27624
+ */
27625
+ buildUpdateLevelInstructions(valueConverter) {
27626
+ const instructions = [];
27627
+ if (this.hasBindings) {
27628
+ const styleMapInstruction = this.buildStyleMapInstruction(valueConverter);
27629
+ if (styleMapInstruction) {
27630
+ instructions.push(styleMapInstruction);
27631
+ }
27632
+ const classMapInstruction = this.buildClassMapInstruction(valueConverter);
27633
+ if (classMapInstruction) {
27634
+ instructions.push(classMapInstruction);
27635
+ }
27636
+ instructions.push(...this._buildStyleInputs(valueConverter));
27637
+ instructions.push(...this._buildClassInputs(valueConverter));
27638
+ }
27639
+ return instructions;
27739
27640
  }
27740
27641
  }
27741
- //
27742
- // Helper methods
27743
- //
27744
- function wrap(symbol, index, contextId, closed) {
27745
- const state = closed ? '/' : '';
27746
- return wrapI18nPlaceholder(`${state}${symbol}${index}`, contextId);
27642
+ function registerIntoMap(map, key) {
27643
+ if (!map.has(key)) {
27644
+ map.set(key, map.size);
27645
+ }
27747
27646
  }
27748
- function wrapTag(symbol, { index, ctx, isVoid }, closed) {
27749
- return isVoid ? wrap(symbol, index, ctx) + wrap(symbol, index, ctx, true) :
27750
- wrap(symbol, index, ctx, closed);
27647
+ function parseProperty(name) {
27648
+ let hasOverrideFlag = false;
27649
+ const overrideIndex = name.indexOf(IMPORTANT_FLAG);
27650
+ if (overrideIndex !== -1) {
27651
+ name = overrideIndex > 0 ? name.substring(0, overrideIndex) : '';
27652
+ hasOverrideFlag = true;
27653
+ }
27654
+ let suffix = null;
27655
+ let property = name;
27656
+ const unitIndex = name.lastIndexOf('.');
27657
+ if (unitIndex > 0) {
27658
+ suffix = name.slice(unitIndex + 1);
27659
+ property = name.substring(0, unitIndex);
27660
+ }
27661
+ return { property, suffix, hasOverrideFlag };
27751
27662
  }
27752
- function findTemplateFn(ctx, templateIndex) {
27753
- return (token) => typeof token === 'object' && token.type === TagType.TEMPLATE &&
27754
- token.index === templateIndex && token.ctx === ctx;
27663
+ /**
27664
+ * Gets the instruction to generate for an interpolated class map.
27665
+ * @param interpolation An Interpolation AST
27666
+ */
27667
+ function getClassMapInterpolationExpression(interpolation) {
27668
+ switch (getInterpolationArgsLength(interpolation)) {
27669
+ case 1:
27670
+ return Identifiers.classMap;
27671
+ case 3:
27672
+ return Identifiers.classMapInterpolate1;
27673
+ case 5:
27674
+ return Identifiers.classMapInterpolate2;
27675
+ case 7:
27676
+ return Identifiers.classMapInterpolate3;
27677
+ case 9:
27678
+ return Identifiers.classMapInterpolate4;
27679
+ case 11:
27680
+ return Identifiers.classMapInterpolate5;
27681
+ case 13:
27682
+ return Identifiers.classMapInterpolate6;
27683
+ case 15:
27684
+ return Identifiers.classMapInterpolate7;
27685
+ case 17:
27686
+ return Identifiers.classMapInterpolate8;
27687
+ default:
27688
+ return Identifiers.classMapInterpolateV;
27689
+ }
27755
27690
  }
27756
- function serializePlaceholderValue(value) {
27757
- const element = (data, closed) => wrapTag('#', data, closed);
27758
- const template = (data, closed) => wrapTag('*', data, closed);
27759
- switch (value.type) {
27760
- case TagType.ELEMENT:
27761
- // close element tag
27762
- if (value.closed) {
27763
- return element(value, true) + (value.tmpl ? template(value.tmpl, true) : '');
27764
- }
27765
- // open element tag that also initiates a template
27766
- if (value.tmpl) {
27767
- return template(value.tmpl) + element(value) +
27768
- (value.isVoid ? template(value.tmpl, true) : '');
27769
- }
27770
- return element(value);
27771
- case TagType.TEMPLATE:
27772
- return template(value, value.closed);
27691
+ /**
27692
+ * Gets the instruction to generate for an interpolated style map.
27693
+ * @param interpolation An Interpolation AST
27694
+ */
27695
+ function getStyleMapInterpolationExpression(interpolation) {
27696
+ switch (getInterpolationArgsLength(interpolation)) {
27697
+ case 1:
27698
+ return Identifiers.styleMap;
27699
+ case 3:
27700
+ return Identifiers.styleMapInterpolate1;
27701
+ case 5:
27702
+ return Identifiers.styleMapInterpolate2;
27703
+ case 7:
27704
+ return Identifiers.styleMapInterpolate3;
27705
+ case 9:
27706
+ return Identifiers.styleMapInterpolate4;
27707
+ case 11:
27708
+ return Identifiers.styleMapInterpolate5;
27709
+ case 13:
27710
+ return Identifiers.styleMapInterpolate6;
27711
+ case 15:
27712
+ return Identifiers.styleMapInterpolate7;
27713
+ case 17:
27714
+ return Identifiers.styleMapInterpolate8;
27773
27715
  default:
27774
- return value;
27716
+ return Identifiers.styleMapInterpolateV;
27717
+ }
27718
+ }
27719
+ /**
27720
+ * Gets the instruction to generate for an interpolated style prop.
27721
+ * @param interpolation An Interpolation AST
27722
+ */
27723
+ function getStylePropInterpolationExpression(interpolation) {
27724
+ switch (getInterpolationArgsLength(interpolation)) {
27725
+ case 1:
27726
+ return Identifiers.styleProp;
27727
+ case 3:
27728
+ return Identifiers.stylePropInterpolate1;
27729
+ case 5:
27730
+ return Identifiers.stylePropInterpolate2;
27731
+ case 7:
27732
+ return Identifiers.stylePropInterpolate3;
27733
+ case 9:
27734
+ return Identifiers.stylePropInterpolate4;
27735
+ case 11:
27736
+ return Identifiers.stylePropInterpolate5;
27737
+ case 13:
27738
+ return Identifiers.stylePropInterpolate6;
27739
+ case 15:
27740
+ return Identifiers.stylePropInterpolate7;
27741
+ case 17:
27742
+ return Identifiers.stylePropInterpolate8;
27743
+ default:
27744
+ return Identifiers.stylePropInterpolateV;
27745
+ }
27746
+ }
27747
+ /**
27748
+ * Checks whether property name is a custom CSS property.
27749
+ * See: https://www.w3.org/TR/css-variables-1
27750
+ */
27751
+ function isCssCustomProperty(name) {
27752
+ return name.startsWith('--');
27753
+ }
27754
+ function isEmptyExpression(ast) {
27755
+ if (ast instanceof ASTWithSource) {
27756
+ ast = ast.ast;
27775
27757
  }
27758
+ return ast instanceof EmptyExpr$1;
27776
27759
  }
27777
27760
 
27778
27761
  // Selector attribute name of `<ng-content>`
@@ -30084,6 +30067,171 @@ function createClosureModeGuard() {
30084
30067
  .and(variable(NG_I18N_CLOSURE_MODE));
30085
30068
  }
30086
30069
 
30070
+ /**
30071
+ * Translates query flags into `TQueryFlags` type in
30072
+ * packages/core/src/render3/interfaces/query.ts
30073
+ * @param query
30074
+ */
30075
+ function toQueryFlags(query) {
30076
+ return ((query.descendants ? 1 /* QueryFlags.descendants */ : 0 /* QueryFlags.none */) |
30077
+ (query.static ? 2 /* QueryFlags.isStatic */ : 0 /* QueryFlags.none */) |
30078
+ (query.emitDistinctChangesOnly ? 4 /* QueryFlags.emitDistinctChangesOnly */ : 0 /* QueryFlags.none */));
30079
+ }
30080
+ function getQueryPredicate(query, constantPool) {
30081
+ if (Array.isArray(query.predicate)) {
30082
+ let predicate = [];
30083
+ query.predicate.forEach((selector) => {
30084
+ // Each item in predicates array may contain strings with comma-separated refs
30085
+ // (for ex. 'ref, ref1, ..., refN'), thus we extract individual refs and store them
30086
+ // as separate array entities
30087
+ const selectors = selector.split(',').map((token) => literal(token.trim()));
30088
+ predicate.push(...selectors);
30089
+ });
30090
+ return constantPool.getConstLiteral(literalArr(predicate), true);
30091
+ }
30092
+ else {
30093
+ // The original predicate may have been wrapped in a `forwardRef()` call.
30094
+ switch (query.predicate.forwardRef) {
30095
+ case 0 /* ForwardRefHandling.None */:
30096
+ case 2 /* ForwardRefHandling.Unwrapped */:
30097
+ return query.predicate.expression;
30098
+ case 1 /* ForwardRefHandling.Wrapped */:
30099
+ return importExpr(Identifiers.resolveForwardRef).callFn([query.predicate.expression]);
30100
+ }
30101
+ }
30102
+ }
30103
+ function createQueryCreateCall(query, constantPool, queryTypeFns, prependParams) {
30104
+ const parameters = [];
30105
+ if (prependParams !== undefined) {
30106
+ parameters.push(...prependParams);
30107
+ }
30108
+ if (query.isSignal) {
30109
+ parameters.push(new ReadPropExpr(variable(CONTEXT_NAME), query.propertyName));
30110
+ }
30111
+ parameters.push(getQueryPredicate(query, constantPool), literal(toQueryFlags(query)));
30112
+ if (query.read) {
30113
+ parameters.push(query.read);
30114
+ }
30115
+ const queryCreateFn = query.isSignal ? queryTypeFns.signalBased : queryTypeFns.nonSignal;
30116
+ return importExpr(queryCreateFn).callFn(parameters);
30117
+ }
30118
+ const queryAdvancePlaceholder = Symbol('queryAdvancePlaceholder');
30119
+ /**
30120
+ * Collapses query advance placeholders in a list of statements.
30121
+ *
30122
+ * This allows for less generated code because multiple sibling query advance
30123
+ * statements can be collapsed into a single call with the count as argument.
30124
+ *
30125
+ * e.g.
30126
+ *
30127
+ * ```ts
30128
+ * bla();
30129
+ * queryAdvance();
30130
+ * queryAdvance();
30131
+ * bla();
30132
+ * ```
30133
+ *
30134
+ * --> will turn into
30135
+ *
30136
+ * ```
30137
+ * bla();
30138
+ * queryAdvance(2);
30139
+ * bla();
30140
+ * ```
30141
+ */
30142
+ function collapseAdvanceStatements(statements) {
30143
+ const result = [];
30144
+ let advanceCollapseCount = 0;
30145
+ const flushAdvanceCount = () => {
30146
+ if (advanceCollapseCount > 0) {
30147
+ result.unshift(importExpr(Identifiers.queryAdvance)
30148
+ .callFn(advanceCollapseCount === 1 ? [] : [literal(advanceCollapseCount)])
30149
+ .toStmt());
30150
+ advanceCollapseCount = 0;
30151
+ }
30152
+ };
30153
+ // Iterate through statements in reverse and collapse advance placeholders.
30154
+ for (let i = statements.length - 1; i >= 0; i--) {
30155
+ const st = statements[i];
30156
+ if (st === queryAdvancePlaceholder) {
30157
+ advanceCollapseCount++;
30158
+ }
30159
+ else {
30160
+ flushAdvanceCount();
30161
+ result.unshift(st);
30162
+ }
30163
+ }
30164
+ flushAdvanceCount();
30165
+ return result;
30166
+ }
30167
+ // Define and update any view queries
30168
+ function createViewQueriesFunction(viewQueries, constantPool, name) {
30169
+ const createStatements = [];
30170
+ const updateStatements = [];
30171
+ const tempAllocator = temporaryAllocator(st => updateStatements.push(st), TEMPORARY_NAME);
30172
+ viewQueries.forEach((query) => {
30173
+ // creation call, e.g. r3.viewQuery(somePredicate, true) or
30174
+ // r3.viewQuerySignal(ctx.prop, somePredicate, true);
30175
+ const queryDefinitionCall = createQueryCreateCall(query, constantPool, {
30176
+ signalBased: Identifiers.viewQuerySignal,
30177
+ nonSignal: Identifiers.viewQuery,
30178
+ });
30179
+ createStatements.push(queryDefinitionCall.toStmt());
30180
+ // Signal queries update lazily and we just advance the index.
30181
+ if (query.isSignal) {
30182
+ updateStatements.push(queryAdvancePlaceholder);
30183
+ return;
30184
+ }
30185
+ // update, e.g. (r3.queryRefresh(tmp = r3.loadQuery()) && (ctx.someDir = tmp));
30186
+ const temporary = tempAllocator();
30187
+ const getQueryList = importExpr(Identifiers.loadQuery).callFn([]);
30188
+ const refresh = importExpr(Identifiers.queryRefresh).callFn([temporary.set(getQueryList)]);
30189
+ const updateDirective = variable(CONTEXT_NAME)
30190
+ .prop(query.propertyName)
30191
+ .set(query.first ? temporary.prop('first') : temporary);
30192
+ updateStatements.push(refresh.and(updateDirective).toStmt());
30193
+ });
30194
+ const viewQueryFnName = name ? `${name}_Query` : null;
30195
+ return fn([new FnParam(RENDER_FLAGS, NUMBER_TYPE), new FnParam(CONTEXT_NAME, null)], [
30196
+ renderFlagCheckIfStmt(1 /* core.RenderFlags.Create */, createStatements),
30197
+ renderFlagCheckIfStmt(2 /* core.RenderFlags.Update */, collapseAdvanceStatements(updateStatements))
30198
+ ], INFERRED_TYPE, null, viewQueryFnName);
30199
+ }
30200
+ // Define and update any content queries
30201
+ function createContentQueriesFunction(queries, constantPool, name) {
30202
+ const createStatements = [];
30203
+ const updateStatements = [];
30204
+ const tempAllocator = temporaryAllocator(st => updateStatements.push(st), TEMPORARY_NAME);
30205
+ for (const query of queries) {
30206
+ // creation, e.g. r3.contentQuery(dirIndex, somePredicate, true, null) or
30207
+ // r3.contentQuerySignal(dirIndex, propName, somePredicate, <flags>, <read>).
30208
+ createStatements.push(createQueryCreateCall(query, constantPool, { nonSignal: Identifiers.contentQuery, signalBased: Identifiers.contentQuerySignal },
30209
+ /* prependParams */ [variable('dirIndex')])
30210
+ .toStmt());
30211
+ // Signal queries update lazily and we just advance the index.
30212
+ if (query.isSignal) {
30213
+ updateStatements.push(queryAdvancePlaceholder);
30214
+ continue;
30215
+ }
30216
+ // update, e.g. (r3.queryRefresh(tmp = r3.loadQuery()) && (ctx.someDir = tmp));
30217
+ const temporary = tempAllocator();
30218
+ const getQueryList = importExpr(Identifiers.loadQuery).callFn([]);
30219
+ const refresh = importExpr(Identifiers.queryRefresh).callFn([temporary.set(getQueryList)]);
30220
+ const updateDirective = variable(CONTEXT_NAME)
30221
+ .prop(query.propertyName)
30222
+ .set(query.first ? temporary.prop('first') : temporary);
30223
+ updateStatements.push(refresh.and(updateDirective).toStmt());
30224
+ }
30225
+ const contentQueriesFnName = name ? `${name}_ContentQueries` : null;
30226
+ return fn([
30227
+ new FnParam(RENDER_FLAGS, NUMBER_TYPE), new FnParam(CONTEXT_NAME, null),
30228
+ new FnParam('dirIndex', null)
30229
+ ], [
30230
+ renderFlagCheckIfStmt(1 /* core.RenderFlags.Create */, createStatements),
30231
+ renderFlagCheckIfStmt(2 /* core.RenderFlags.Update */, collapseAdvanceStatements(updateStatements)),
30232
+ ], INFERRED_TYPE, null, contentQueriesFnName);
30233
+ }
30234
+
30087
30235
  // This regex matches any binding names that contain the "attr." prefix, e.g. "attr.required"
30088
30236
  // If there is a match, the first matching group will contain the attribute name to bind.
30089
30237
  const ATTR_REGEX = /attr\.([^\]]+)/;
@@ -30222,7 +30370,7 @@ function compileComponentFromMetadata(meta, constantPool, bindingParser) {
30222
30370
  allDeferrableDepsFn = createDeferredDepsFunction(constantPool, fnName, meta.deferrableTypes);
30223
30371
  }
30224
30372
  // Template compilation is currently conditional as we're in the process of rewriting it.
30225
- if (!USE_TEMPLATE_PIPELINE) {
30373
+ if (!USE_TEMPLATE_PIPELINE && !meta.useTemplatePipeline) {
30226
30374
  // This is the main path currently used in compilation, which compiles the template with the
30227
30375
  // legacy `TemplateDefinitionBuilder`.
30228
30376
  const template = meta.template;
@@ -30378,22 +30526,6 @@ function compileDeclarationList(list, mode) {
30378
30526
  throw new Error(`Unsupported with an array of pre-resolved dependencies`);
30379
30527
  }
30380
30528
  }
30381
- function prepareQueryParams(query, constantPool) {
30382
- const parameters = [getQueryPredicate(query, constantPool), literal(toQueryFlags(query))];
30383
- if (query.read) {
30384
- parameters.push(query.read);
30385
- }
30386
- return parameters;
30387
- }
30388
- /**
30389
- * Translates query flags into `TQueryFlags` type in packages/core/src/render3/interfaces/query.ts
30390
- * @param query
30391
- */
30392
- function toQueryFlags(query) {
30393
- return (query.descendants ? 1 /* QueryFlags.descendants */ : 0 /* QueryFlags.none */) |
30394
- (query.static ? 2 /* QueryFlags.isStatic */ : 0 /* QueryFlags.none */) |
30395
- (query.emitDistinctChangesOnly ? 4 /* QueryFlags.emitDistinctChangesOnly */ : 0 /* QueryFlags.none */);
30396
- }
30397
30529
  function convertAttributesToExpressions(attributes) {
30398
30530
  const values = [];
30399
30531
  for (let key of Object.getOwnPropertyNames(attributes)) {
@@ -30402,34 +30534,6 @@ function convertAttributesToExpressions(attributes) {
30402
30534
  }
30403
30535
  return values;
30404
30536
  }
30405
- // Define and update any content queries
30406
- function createContentQueriesFunction(queries, constantPool, name) {
30407
- const createStatements = [];
30408
- const updateStatements = [];
30409
- const tempAllocator = temporaryAllocator(updateStatements, TEMPORARY_NAME);
30410
- for (const query of queries) {
30411
- // creation, e.g. r3.contentQuery(dirIndex, somePredicate, true, null);
30412
- createStatements.push(importExpr(Identifiers.contentQuery)
30413
- .callFn([variable('dirIndex'), ...prepareQueryParams(query, constantPool)])
30414
- .toStmt());
30415
- // update, e.g. (r3.queryRefresh(tmp = r3.loadQuery()) && (ctx.someDir = tmp));
30416
- const temporary = tempAllocator();
30417
- const getQueryList = importExpr(Identifiers.loadQuery).callFn([]);
30418
- const refresh = importExpr(Identifiers.queryRefresh).callFn([temporary.set(getQueryList)]);
30419
- const updateDirective = variable(CONTEXT_NAME)
30420
- .prop(query.propertyName)
30421
- .set(query.first ? temporary.prop('first') : temporary);
30422
- updateStatements.push(refresh.and(updateDirective).toStmt());
30423
- }
30424
- const contentQueriesFnName = name ? `${name}_ContentQueries` : null;
30425
- return fn([
30426
- new FnParam(RENDER_FLAGS, NUMBER_TYPE), new FnParam(CONTEXT_NAME, null),
30427
- new FnParam('dirIndex', null)
30428
- ], [
30429
- renderFlagCheckIfStmt(1 /* core.RenderFlags.Create */, createStatements),
30430
- renderFlagCheckIfStmt(2 /* core.RenderFlags.Update */, updateStatements)
30431
- ], INFERRED_TYPE, null, contentQueriesFnName);
30432
- }
30433
30537
  function stringAsType(str) {
30434
30538
  return expressionType(literal(str));
30435
30539
  }
@@ -30495,36 +30599,12 @@ function createDirectiveType(meta) {
30495
30599
  }
30496
30600
  return expressionType(importExpr(Identifiers.DirectiveDeclaration, typeParams));
30497
30601
  }
30498
- // Define and update any view queries
30499
- function createViewQueriesFunction(viewQueries, constantPool, name) {
30500
- const createStatements = [];
30501
- const updateStatements = [];
30502
- const tempAllocator = temporaryAllocator(updateStatements, TEMPORARY_NAME);
30503
- viewQueries.forEach((query) => {
30504
- // creation, e.g. r3.viewQuery(somePredicate, true);
30505
- const queryDefinition = importExpr(Identifiers.viewQuery).callFn(prepareQueryParams(query, constantPool));
30506
- createStatements.push(queryDefinition.toStmt());
30507
- // update, e.g. (r3.queryRefresh(tmp = r3.loadQuery()) && (ctx.someDir = tmp));
30508
- const temporary = tempAllocator();
30509
- const getQueryList = importExpr(Identifiers.loadQuery).callFn([]);
30510
- const refresh = importExpr(Identifiers.queryRefresh).callFn([temporary.set(getQueryList)]);
30511
- const updateDirective = variable(CONTEXT_NAME)
30512
- .prop(query.propertyName)
30513
- .set(query.first ? temporary.prop('first') : temporary);
30514
- updateStatements.push(refresh.and(updateDirective).toStmt());
30515
- });
30516
- const viewQueryFnName = name ? `${name}_Query` : null;
30517
- return fn([new FnParam(RENDER_FLAGS, NUMBER_TYPE), new FnParam(CONTEXT_NAME, null)], [
30518
- renderFlagCheckIfStmt(1 /* core.RenderFlags.Create */, createStatements),
30519
- renderFlagCheckIfStmt(2 /* core.RenderFlags.Update */, updateStatements)
30520
- ], INFERRED_TYPE, null, viewQueryFnName);
30521
- }
30522
30602
  // Return a host binding function or null if one is not necessary.
30523
30603
  function createHostBindingsFunction(hostBindingsMetadata, typeSourceSpan, bindingParser, constantPool, selector, name, definitionMap) {
30524
30604
  const bindings = bindingParser.createBoundHostProperties(hostBindingsMetadata.properties, typeSourceSpan);
30525
30605
  // Calculate host event bindings
30526
30606
  const eventBindings = bindingParser.createDirectiveHostEventAsts(hostBindingsMetadata.listeners, typeSourceSpan);
30527
- if (USE_TEMPLATE_PIPELINE) {
30607
+ if (USE_TEMPLATE_PIPELINE || hostBindingsMetadata.useTemplatePipeline) {
30528
30608
  // The parser for host bindings treats class and style attributes specially -- they are
30529
30609
  // extracted into these separate fields. This is not the case for templates, so the compiler can
30530
30610
  // actually already handle these special attributes internally. Therefore, we just drop them
@@ -31708,6 +31788,7 @@ function extractScopedNodeEntities(rootScope) {
31708
31788
  class ResourceLoader {
31709
31789
  }
31710
31790
 
31791
+ const SHOULD_USE_TEMPLATE_PIPELINE_FOR_JIT = false;
31711
31792
  class CompilerFacadeImpl {
31712
31793
  constructor(jitEvaluator = new JitEvaluator()) {
31713
31794
  this.jitEvaluator = jitEvaluator;
@@ -31841,6 +31922,7 @@ class CompilerFacadeImpl {
31841
31922
  null,
31842
31923
  relativeContextFilePath: '',
31843
31924
  i18nUseExternalIds: true,
31925
+ useTemplatePipeline: SHOULD_USE_TEMPLATE_PIPELINE_FOR_JIT,
31844
31926
  };
31845
31927
  const jitExpressionSourceMap = `ng:///${facade.name}.js`;
31846
31928
  return this.compileComponentFromMeta(angularCoreEnv, jitExpressionSourceMap, meta);
@@ -31904,6 +31986,7 @@ class CompilerFacadeImpl {
31904
31986
  function convertToR3QueryMetadata(facade) {
31905
31987
  return {
31906
31988
  ...facade,
31989
+ isSignal: facade.isSignal,
31907
31990
  predicate: convertQueryPredicate(facade.predicate),
31908
31991
  read: facade.read ? new WrappedNodeExpr(facade.read) : null,
31909
31992
  static: facade.static,
@@ -31919,6 +32002,7 @@ function convertQueryDeclarationToMetadata(declaration) {
31919
32002
  read: declaration.read ? new WrappedNodeExpr(declaration.read) : null,
31920
32003
  static: declaration.static ?? false,
31921
32004
  emitDistinctChangesOnly: declaration.emitDistinctChangesOnly ?? true,
32005
+ isSignal: !!declaration.isSignal,
31922
32006
  };
31923
32007
  }
31924
32008
  function convertQueryPredicate(predicate) {
@@ -31961,7 +32045,10 @@ function convertDirectiveFacadeToMetadata(facade) {
31961
32045
  typeSourceSpan: facade.typeSourceSpan,
31962
32046
  type: wrapReference(facade.type),
31963
32047
  deps: null,
31964
- host: extractHostBindings(facade.propMetadata, facade.typeSourceSpan, facade.host),
32048
+ host: {
32049
+ ...extractHostBindings(facade.propMetadata, facade.typeSourceSpan, facade.host),
32050
+ useTemplatePipeline: SHOULD_USE_TEMPLATE_PIPELINE_FOR_JIT,
32051
+ },
31965
32052
  inputs: { ...inputsFromMetadata, ...inputsFromType },
31966
32053
  outputs: { ...outputsFromMetadata, ...outputsFromType },
31967
32054
  queries: facade.queries.map(convertToR3QueryMetadata),
@@ -32004,6 +32091,7 @@ function convertHostDeclarationToMetadata(host = {}) {
32004
32091
  classAttr: host.classAttribute,
32005
32092
  styleAttr: host.styleAttribute,
32006
32093
  },
32094
+ useTemplatePipeline: SHOULD_USE_TEMPLATE_PIPELINE_FOR_JIT,
32007
32095
  };
32008
32096
  }
32009
32097
  function convertHostDirectivesToMetadata(metadata) {
@@ -32076,6 +32164,7 @@ function convertDeclareComponentFacadeToMetadata(decl, typeSourceSpan, sourceMap
32076
32164
  declarationListEmitMode: 2 /* DeclarationListEmitMode.ClosureResolved */,
32077
32165
  relativeContextFilePath: '',
32078
32166
  i18nUseExternalIds: true,
32167
+ useTemplatePipeline: SHOULD_USE_TEMPLATE_PIPELINE_FOR_JIT,
32079
32168
  };
32080
32169
  }
32081
32170
  function convertDeclarationFacadeToMetadata(declaration) {
@@ -32357,7 +32446,7 @@ function publishFacade(global) {
32357
32446
  * @description
32358
32447
  * Entry point for all public APIs of the compiler package.
32359
32448
  */
32360
- const VERSION = new Version('17.1.2');
32449
+ const VERSION = new Version('17.2.0-next.1');
32361
32450
 
32362
32451
  class CompilerConfig {
32363
32452
  constructor({ defaultEncapsulation = ViewEncapsulation.Emulated, preserveWhitespaces, strictInjectionParameters } = {}) {
@@ -33923,7 +34012,7 @@ const MINIMUM_PARTIAL_LINKER_VERSION$5 = '12.0.0';
33923
34012
  function compileDeclareClassMetadata(metadata) {
33924
34013
  const definitionMap = new DefinitionMap();
33925
34014
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$5));
33926
- definitionMap.set('version', literal('17.1.2'));
34015
+ definitionMap.set('version', literal('17.2.0-next.1'));
33927
34016
  definitionMap.set('ngImport', importExpr(Identifiers.core));
33928
34017
  definitionMap.set('type', metadata.type);
33929
34018
  definitionMap.set('decorators', metadata.decorators);
@@ -34019,7 +34108,7 @@ function createDirectiveDefinitionMap(meta) {
34019
34108
  const definitionMap = new DefinitionMap();
34020
34109
  const minVersion = getMinimumVersionForPartialOutput(meta);
34021
34110
  definitionMap.set('minVersion', literal(minVersion));
34022
- definitionMap.set('version', literal('17.1.2'));
34111
+ definitionMap.set('version', literal('17.2.0-next.1'));
34023
34112
  // e.g. `type: MyDirective`
34024
34113
  definitionMap.set('type', meta.type.value);
34025
34114
  if (meta.isStandalone) {
@@ -34087,6 +34176,11 @@ function getMinimumVersionForPartialOutput(meta) {
34087
34176
  if (needsNewInputPartialOutput(meta)) {
34088
34177
  minVersion = '17.1.0';
34089
34178
  }
34179
+ // If there are signal-based queries, partial output generates an extra field
34180
+ // that should be parsed by linkers. Ensure a proper minimum linker version.
34181
+ if (meta.queries.some(q => q.isSignal) || meta.viewQueries.some(q => q.isSignal)) {
34182
+ minVersion = '17.2.0';
34183
+ }
34090
34184
  return minVersion;
34091
34185
  }
34092
34186
  /**
@@ -34123,6 +34217,9 @@ function compileQuery(query) {
34123
34217
  if (query.static) {
34124
34218
  meta.set('static', literal(true));
34125
34219
  }
34220
+ if (query.isSignal) {
34221
+ meta.set('isSignal', literal(true));
34222
+ }
34126
34223
  return meta.toLiteralMap();
34127
34224
  }
34128
34225
  /**
@@ -34403,7 +34500,7 @@ const MINIMUM_PARTIAL_LINKER_VERSION$4 = '12.0.0';
34403
34500
  function compileDeclareFactoryFunction(meta) {
34404
34501
  const definitionMap = new DefinitionMap();
34405
34502
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$4));
34406
- definitionMap.set('version', literal('17.1.2'));
34503
+ definitionMap.set('version', literal('17.2.0-next.1'));
34407
34504
  definitionMap.set('ngImport', importExpr(Identifiers.core));
34408
34505
  definitionMap.set('type', meta.type.value);
34409
34506
  definitionMap.set('deps', compileDependencies(meta.deps));
@@ -34438,7 +34535,7 @@ function compileDeclareInjectableFromMetadata(meta) {
34438
34535
  function createInjectableDefinitionMap(meta) {
34439
34536
  const definitionMap = new DefinitionMap();
34440
34537
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$3));
34441
- definitionMap.set('version', literal('17.1.2'));
34538
+ definitionMap.set('version', literal('17.2.0-next.1'));
34442
34539
  definitionMap.set('ngImport', importExpr(Identifiers.core));
34443
34540
  definitionMap.set('type', meta.type.value);
34444
34541
  // Only generate providedIn property if it has a non-null value
@@ -34489,7 +34586,7 @@ function compileDeclareInjectorFromMetadata(meta) {
34489
34586
  function createInjectorDefinitionMap(meta) {
34490
34587
  const definitionMap = new DefinitionMap();
34491
34588
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$2));
34492
- definitionMap.set('version', literal('17.1.2'));
34589
+ definitionMap.set('version', literal('17.2.0-next.1'));
34493
34590
  definitionMap.set('ngImport', importExpr(Identifiers.core));
34494
34591
  definitionMap.set('type', meta.type.value);
34495
34592
  definitionMap.set('providers', meta.providers);
@@ -34522,7 +34619,7 @@ function createNgModuleDefinitionMap(meta) {
34522
34619
  throw new Error('Invalid path! Local compilation mode should not get into the partial compilation path');
34523
34620
  }
34524
34621
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$1));
34525
- definitionMap.set('version', literal('17.1.2'));
34622
+ definitionMap.set('version', literal('17.2.0-next.1'));
34526
34623
  definitionMap.set('ngImport', importExpr(Identifiers.core));
34527
34624
  definitionMap.set('type', meta.type.value);
34528
34625
  // We only generate the keys in the metadata if the arrays contain values.
@@ -34573,7 +34670,7 @@ function compileDeclarePipeFromMetadata(meta) {
34573
34670
  function createPipeDefinitionMap(meta) {
34574
34671
  const definitionMap = new DefinitionMap();
34575
34672
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION));
34576
- definitionMap.set('version', literal('17.1.2'));
34673
+ definitionMap.set('version', literal('17.2.0-next.1'));
34577
34674
  definitionMap.set('ngImport', importExpr(Identifiers.core));
34578
34675
  // e.g. `type: MyPipe`
34579
34676
  definitionMap.set('type', meta.type.value);