@angular/compiler 13.2.4 → 13.3.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v13.2.4
2
+ * @license Angular v13.3.0-rc.0
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v13.2.4
2
+ * @license Angular v13.3.0-rc.0
3
3
  * (c) 2010-2022 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
@@ -9562,8 +9562,8 @@ class Parser$1 {
9562
9562
  span: new AbsoluteSourceSpan(absoluteKeyOffset, absoluteKeyOffset + templateKey.length),
9563
9563
  });
9564
9564
  }
9565
- parseInterpolation(input, location, absoluteOffset, interpolationConfig = DEFAULT_INTERPOLATION_CONFIG) {
9566
- const { strings, expressions, offsets } = this.splitInterpolation(input, location, interpolationConfig);
9565
+ parseInterpolation(input, location, absoluteOffset, interpolatedTokens, interpolationConfig = DEFAULT_INTERPOLATION_CONFIG) {
9566
+ const { strings, expressions, offsets } = this.splitInterpolation(input, location, interpolatedTokens, interpolationConfig);
9567
9567
  if (expressions.length === 0)
9568
9568
  return null;
9569
9569
  const expressionNodes = [];
@@ -9602,10 +9602,11 @@ class Parser$1 {
9602
9602
  * `SplitInterpolation` with splits that look like
9603
9603
  * <raw text> <expression> <raw text> ... <raw text> <expression> <raw text>
9604
9604
  */
9605
- splitInterpolation(input, location, interpolationConfig = DEFAULT_INTERPOLATION_CONFIG) {
9605
+ splitInterpolation(input, location, interpolatedTokens, interpolationConfig = DEFAULT_INTERPOLATION_CONFIG) {
9606
9606
  const strings = [];
9607
9607
  const expressions = [];
9608
9608
  const offsets = [];
9609
+ const inputToTemplateIndexMap = interpolatedTokens ? getIndexMapForOriginalTemplate(interpolatedTokens) : null;
9609
9610
  let i = 0;
9610
9611
  let atInterpolation = false;
9611
9612
  let extendLastString = false;
@@ -9640,7 +9641,9 @@ class Parser$1 {
9640
9641
  this._reportError('Blank expressions are not allowed in interpolated strings', input, `at column ${i} in`, location);
9641
9642
  }
9642
9643
  expressions.push({ text, start: fullStart, end: fullEnd });
9643
- offsets.push(exprStart);
9644
+ const startInOriginalTemplate = inputToTemplateIndexMap?.get(fullStart) ?? fullStart;
9645
+ const offset = startInOriginalTemplate + interpStart.length;
9646
+ offsets.push(offset);
9644
9647
  i = fullEnd;
9645
9648
  atInterpolation = false;
9646
9649
  }
@@ -10648,6 +10651,41 @@ class SimpleExpressionChecker extends RecursiveAstVisitor {
10648
10651
  this.errors.push('pipes');
10649
10652
  }
10650
10653
  }
10654
+ /**
10655
+ * Computes the real offset in the original template for indexes in an interpolation.
10656
+ *
10657
+ * Because templates can have encoded HTML entities and the input passed to the parser at this stage
10658
+ * of the compiler is the _decoded_ value, we need to compute the real offset using the original
10659
+ * encoded values in the interpolated tokens. Note that this is only a special case handling for
10660
+ * `MlParserTokenType.ENCODED_ENTITY` token types. All other interpolated tokens are expected to
10661
+ * have parts which exactly match the input string for parsing the interpolation.
10662
+ *
10663
+ * @param interpolatedTokens The tokens for the interpolated value.
10664
+ *
10665
+ * @returns A map of index locations in the decoded template to indexes in the original template
10666
+ */
10667
+ function getIndexMapForOriginalTemplate(interpolatedTokens) {
10668
+ let offsetMap = new Map();
10669
+ let consumedInOriginalTemplate = 0;
10670
+ let consumedInInput = 0;
10671
+ let tokenIndex = 0;
10672
+ while (tokenIndex < interpolatedTokens.length) {
10673
+ const currentToken = interpolatedTokens[tokenIndex];
10674
+ if (currentToken.type === 9 /* ENCODED_ENTITY */) {
10675
+ const [decoded, encoded] = currentToken.parts;
10676
+ consumedInOriginalTemplate += encoded.length;
10677
+ consumedInInput += decoded.length;
10678
+ }
10679
+ else {
10680
+ const lengthOfParts = currentToken.parts.reduce((sum, current) => sum + current.length, 0);
10681
+ consumedInInput += lengthOfParts;
10682
+ consumedInOriginalTemplate += lengthOfParts;
10683
+ }
10684
+ offsetMap.set(consumedInInput, consumedInOriginalTemplate);
10685
+ tokenIndex++;
10686
+ }
10687
+ return offsetMap;
10688
+ }
10651
10689
 
10652
10690
  /**
10653
10691
  * @license
@@ -15053,11 +15091,11 @@ class BindingParser {
15053
15091
  }
15054
15092
  return targetEvents;
15055
15093
  }
15056
- parseInterpolation(value, sourceSpan) {
15094
+ parseInterpolation(value, sourceSpan, interpolatedTokens) {
15057
15095
  const sourceInfo = sourceSpan.start.toString();
15058
15096
  const absoluteOffset = sourceSpan.fullStart.offset;
15059
15097
  try {
15060
- const ast = this._exprParser.parseInterpolation(value, sourceInfo, absoluteOffset, this._interpolationConfig);
15098
+ const ast = this._exprParser.parseInterpolation(value, sourceInfo, absoluteOffset, interpolatedTokens, this._interpolationConfig);
15061
15099
  if (ast)
15062
15100
  this._reportExpressionParserErrors(ast.errors, sourceSpan);
15063
15101
  return ast;
@@ -15194,8 +15232,8 @@ class BindingParser {
15194
15232
  this._parsePropertyAst(name, this._parseBinding(expression, isHost, valueSpan || sourceSpan, absoluteOffset), sourceSpan, keySpan, valueSpan, targetMatchableAttrs, targetProps);
15195
15233
  }
15196
15234
  }
15197
- parsePropertyInterpolation(name, value, sourceSpan, valueSpan, targetMatchableAttrs, targetProps, keySpan) {
15198
- const expr = this.parseInterpolation(value, valueSpan || sourceSpan);
15235
+ parsePropertyInterpolation(name, value, sourceSpan, valueSpan, targetMatchableAttrs, targetProps, keySpan, interpolatedTokens) {
15236
+ const expr = this.parseInterpolation(value, valueSpan || sourceSpan, interpolatedTokens);
15199
15237
  if (expr) {
15200
15238
  this._parsePropertyAst(name, expr, sourceSpan, keySpan, valueSpan, targetMatchableAttrs, targetProps);
15201
15239
  return true;
@@ -15692,7 +15730,7 @@ class HtmlAstToIvyAst {
15692
15730
  return new TextAttribute(attribute.name, attribute.value, attribute.sourceSpan, attribute.keySpan, attribute.valueSpan, attribute.i18n);
15693
15731
  }
15694
15732
  visitText(text) {
15695
- return this._visitTextWithInterpolation(text.value, text.sourceSpan, text.i18n);
15733
+ return this._visitTextWithInterpolation(text.value, text.sourceSpan, text.tokens, text.i18n);
15696
15734
  }
15697
15735
  visitExpansion(expansion) {
15698
15736
  if (!expansion.i18n) {
@@ -15722,7 +15760,7 @@ class HtmlAstToIvyAst {
15722
15760
  vars[formattedKey] = new BoundText(ast, value.sourceSpan);
15723
15761
  }
15724
15762
  else {
15725
- placeholders[key] = this._visitTextWithInterpolation(value.text, value.sourceSpan);
15763
+ placeholders[key] = this._visitTextWithInterpolation(value.text, value.sourceSpan, null);
15726
15764
  }
15727
15765
  });
15728
15766
  return new Icu$1(vars, placeholders, expansion.sourceSpan, message);
@@ -15845,12 +15883,12 @@ class HtmlAstToIvyAst {
15845
15883
  }
15846
15884
  // No explicit binding found.
15847
15885
  const keySpan = createKeySpan(srcSpan, '' /* prefix */, name);
15848
- const hasBinding = this.bindingParser.parsePropertyInterpolation(name, value, srcSpan, attribute.valueSpan, matchableAttributes, parsedProperties, keySpan);
15886
+ const hasBinding = this.bindingParser.parsePropertyInterpolation(name, value, srcSpan, attribute.valueSpan, matchableAttributes, parsedProperties, keySpan, attribute.valueTokens ?? null);
15849
15887
  return hasBinding;
15850
15888
  }
15851
- _visitTextWithInterpolation(value, sourceSpan, i18n) {
15889
+ _visitTextWithInterpolation(value, sourceSpan, interpolatedTokens, i18n) {
15852
15890
  const valueNoNgsp = replaceNgsp(value);
15853
- const expr = this.bindingParser.parseInterpolation(valueNoNgsp, sourceSpan);
15891
+ const expr = this.bindingParser.parseInterpolation(valueNoNgsp, sourceSpan, interpolatedTokens);
15854
15892
  return expr ? new BoundText(expr, sourceSpan, i18n) : new Text$3(valueNoNgsp, sourceSpan);
15855
15893
  }
15856
15894
  parseVariable(identifier, value, sourceSpan, keySpan, valueSpan, variables) {
@@ -19736,7 +19774,7 @@ function publishFacade(global) {
19736
19774
  * Use of this source code is governed by an MIT-style license that can be
19737
19775
  * found in the LICENSE file at https://angular.io/license
19738
19776
  */
19739
- const VERSION = new Version('13.2.4');
19777
+ const VERSION = new Version('13.3.0-rc.0');
19740
19778
 
19741
19779
  /**
19742
19780
  * @license
@@ -21777,7 +21815,7 @@ const MINIMUM_PARTIAL_LINKER_VERSION$6 = '12.0.0';
21777
21815
  function compileDeclareClassMetadata(metadata) {
21778
21816
  const definitionMap = new DefinitionMap();
21779
21817
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$6));
21780
- definitionMap.set('version', literal('13.2.4'));
21818
+ definitionMap.set('version', literal('13.3.0-rc.0'));
21781
21819
  definitionMap.set('ngImport', importExpr(Identifiers.core));
21782
21820
  definitionMap.set('type', metadata.type);
21783
21821
  definitionMap.set('decorators', metadata.decorators);
@@ -21894,7 +21932,7 @@ function compileDeclareDirectiveFromMetadata(meta) {
21894
21932
  function createDirectiveDefinitionMap(meta) {
21895
21933
  const definitionMap = new DefinitionMap();
21896
21934
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$5));
21897
- definitionMap.set('version', literal('13.2.4'));
21935
+ definitionMap.set('version', literal('13.3.0-rc.0'));
21898
21936
  // e.g. `type: MyDirective`
21899
21937
  definitionMap.set('type', meta.internalType);
21900
21938
  // e.g. `selector: 'some-dir'`
@@ -22115,7 +22153,7 @@ const MINIMUM_PARTIAL_LINKER_VERSION$4 = '12.0.0';
22115
22153
  function compileDeclareFactoryFunction(meta) {
22116
22154
  const definitionMap = new DefinitionMap();
22117
22155
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$4));
22118
- definitionMap.set('version', literal('13.2.4'));
22156
+ definitionMap.set('version', literal('13.3.0-rc.0'));
22119
22157
  definitionMap.set('ngImport', importExpr(Identifiers.core));
22120
22158
  definitionMap.set('type', meta.internalType);
22121
22159
  definitionMap.set('deps', compileDependencies(meta.deps));
@@ -22157,7 +22195,7 @@ function compileDeclareInjectableFromMetadata(meta) {
22157
22195
  function createInjectableDefinitionMap(meta) {
22158
22196
  const definitionMap = new DefinitionMap();
22159
22197
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$3));
22160
- definitionMap.set('version', literal('13.2.4'));
22198
+ definitionMap.set('version', literal('13.3.0-rc.0'));
22161
22199
  definitionMap.set('ngImport', importExpr(Identifiers.core));
22162
22200
  definitionMap.set('type', meta.internalType);
22163
22201
  // Only generate providedIn property if it has a non-null value
@@ -22215,7 +22253,7 @@ function compileDeclareInjectorFromMetadata(meta) {
22215
22253
  function createInjectorDefinitionMap(meta) {
22216
22254
  const definitionMap = new DefinitionMap();
22217
22255
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$2));
22218
- definitionMap.set('version', literal('13.2.4'));
22256
+ definitionMap.set('version', literal('13.3.0-rc.0'));
22219
22257
  definitionMap.set('ngImport', importExpr(Identifiers.core));
22220
22258
  definitionMap.set('type', meta.internalType);
22221
22259
  definitionMap.set('providers', meta.providers);
@@ -22252,7 +22290,7 @@ function compileDeclareNgModuleFromMetadata(meta) {
22252
22290
  function createNgModuleDefinitionMap(meta) {
22253
22291
  const definitionMap = new DefinitionMap();
22254
22292
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$1));
22255
- definitionMap.set('version', literal('13.2.4'));
22293
+ definitionMap.set('version', literal('13.3.0-rc.0'));
22256
22294
  definitionMap.set('ngImport', importExpr(Identifiers.core));
22257
22295
  definitionMap.set('type', meta.internalType);
22258
22296
  // We only generate the keys in the metadata if the arrays contain values.
@@ -22310,7 +22348,7 @@ function compileDeclarePipeFromMetadata(meta) {
22310
22348
  function createPipeDefinitionMap(meta) {
22311
22349
  const definitionMap = new DefinitionMap();
22312
22350
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION));
22313
- definitionMap.set('version', literal('13.2.4'));
22351
+ definitionMap.set('version', literal('13.3.0-rc.0'));
22314
22352
  definitionMap.set('ngImport', importExpr(Identifiers.core));
22315
22353
  // e.g. `type: MyPipe`
22316
22354
  definitionMap.set('type', meta.internalType);