@angular/core 17.0.7 → 17.0.8

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.
Files changed (38) hide show
  1. package/esm2022/src/application/application_ref.mjs +4 -8
  2. package/esm2022/src/application/create_application.mjs +2 -2
  3. package/esm2022/src/change_detection/flags.mjs +16 -0
  4. package/esm2022/src/change_detection/scheduling/ng_zone_scheduling.mjs +164 -0
  5. package/esm2022/src/change_detection/scheduling/zoneless_scheduling.mjs +13 -0
  6. package/esm2022/src/core.mjs +2 -2
  7. package/esm2022/src/core_private_export.mjs +4 -2
  8. package/esm2022/src/event_emitter.mjs +1 -2
  9. package/esm2022/src/pending_tasks.mjs +57 -0
  10. package/esm2022/src/platform/platform_ref.mjs +2 -2
  11. package/esm2022/src/render3/after_render_hooks.mjs +2 -2
  12. package/esm2022/src/render3/component_ref.mjs +13 -9
  13. package/esm2022/src/render3/instructions/mark_view_dirty.mjs +3 -2
  14. package/esm2022/src/render3/instructions/shared.mjs +3 -2
  15. package/esm2022/src/render3/interfaces/view.mjs +1 -1
  16. package/esm2022/src/render3/util/view_utils.mjs +18 -5
  17. package/esm2022/src/render3/view_ref.mjs +2 -1
  18. package/esm2022/src/version.mjs +6 -5
  19. package/esm2022/src/zone/ng_zone.mjs +1 -61
  20. package/esm2022/testing/src/logger.mjs +3 -3
  21. package/fesm2022/core.mjs +172 -136
  22. package/fesm2022/core.mjs.map +1 -1
  23. package/fesm2022/primitives/signals.mjs +1 -1
  24. package/fesm2022/rxjs-interop.mjs +1 -1
  25. package/fesm2022/testing.mjs +1 -1
  26. package/index.d.ts +38 -22
  27. package/package.json +1 -1
  28. package/primitives/signals/index.d.ts +1 -1
  29. package/rxjs-interop/index.d.ts +1 -1
  30. package/schematics/migrations/block-template-entities/bundle.js +268 -229
  31. package/schematics/migrations/block-template-entities/bundle.js.map +4 -4
  32. package/schematics/ng-generate/control-flow-migration/bundle.js +433 -295
  33. package/schematics/ng-generate/control-flow-migration/bundle.js.map +4 -4
  34. package/schematics/ng-generate/standalone-migration/bundle.js +276 -215
  35. package/schematics/ng-generate/standalone-migration/bundle.js.map +4 -4
  36. package/testing/index.d.ts +1 -1
  37. package/esm2022/src/change_detection/scheduling.mjs +0 -103
  38. package/esm2022/src/initial_render_pending_tasks.mjs +0 -49
@@ -1805,7 +1805,7 @@ var ConstantPool = class {
1805
1805
  }))));
1806
1806
  }
1807
1807
  }
1808
- getSharedFunctionReference(fn2, prefix) {
1808
+ getSharedFunctionReference(fn2, prefix, useUniqueName = true) {
1809
1809
  var _a2;
1810
1810
  const isArrow = fn2 instanceof ArrowFunctionExpr;
1811
1811
  for (const current of this.statements) {
@@ -1816,7 +1816,7 @@ var ConstantPool = class {
1816
1816
  return variable(current.name);
1817
1817
  }
1818
1818
  }
1819
- const name = this.uniqueName(prefix);
1819
+ const name = useUniqueName ? this.uniqueName(prefix) : prefix;
1820
1820
  this.statements.push(fn2.toDeclStmt(name, StmtModifier.Final));
1821
1821
  return variable(name);
1822
1822
  }
@@ -3437,13 +3437,17 @@ var TagContentType;
3437
3437
  TagContentType2[TagContentType2["ESCAPABLE_RAW_TEXT"] = 1] = "ESCAPABLE_RAW_TEXT";
3438
3438
  TagContentType2[TagContentType2["PARSABLE_DATA"] = 2] = "PARSABLE_DATA";
3439
3439
  })(TagContentType || (TagContentType = {}));
3440
- function splitNsName(elementName) {
3440
+ function splitNsName(elementName, fatal = true) {
3441
3441
  if (elementName[0] != ":") {
3442
3442
  return [null, elementName];
3443
3443
  }
3444
3444
  const colonIndex = elementName.indexOf(":", 1);
3445
3445
  if (colonIndex === -1) {
3446
- throw new Error(`Unsupported format "${elementName}" expecting ":namespace:name"`);
3446
+ if (fatal) {
3447
+ throw new Error(`Unsupported format "${elementName}" expecting ":namespace:name"`);
3448
+ } else {
3449
+ return [null, elementName];
3450
+ }
3447
3451
  }
3448
3452
  return [elementName.slice(1, colonIndex), elementName.slice(colonIndex + 1)];
3449
3453
  }
@@ -3950,28 +3954,6 @@ var BlockPlaceholder = class {
3950
3954
  return visitor.visitBlockPlaceholder(this, context);
3951
3955
  }
3952
3956
  };
3953
- var RecurseVisitor = class {
3954
- visitText(text2, context) {
3955
- }
3956
- visitContainer(container, context) {
3957
- container.children.forEach((child) => child.visit(this));
3958
- }
3959
- visitIcu(icu, context) {
3960
- Object.keys(icu.cases).forEach((k) => {
3961
- icu.cases[k].visit(this);
3962
- });
3963
- }
3964
- visitTagPlaceholder(ph, context) {
3965
- ph.children.forEach((child) => child.visit(this));
3966
- }
3967
- visitPlaceholder(ph, context) {
3968
- }
3969
- visitIcuPlaceholder(ph, context) {
3970
- }
3971
- visitBlockPlaceholder(ph, context) {
3972
- ph.children.forEach((child) => child.visit(this));
3973
- }
3974
- };
3975
3957
  function serializeMessage(messageNodes) {
3976
3958
  const visitor = new LocalizeMessageStringVisitor();
3977
3959
  const str = messageNodes.map((n) => n.visit(visitor)).join("");
@@ -7039,8 +7021,9 @@ var OpKind;
7039
7021
  OpKind2[OpKind2["I18nApply"] = 40] = "I18nApply";
7040
7022
  OpKind2[OpKind2["IcuStart"] = 41] = "IcuStart";
7041
7023
  OpKind2[OpKind2["IcuEnd"] = 42] = "IcuEnd";
7042
- OpKind2[OpKind2["I18nContext"] = 43] = "I18nContext";
7043
- OpKind2[OpKind2["I18nAttributes"] = 44] = "I18nAttributes";
7024
+ OpKind2[OpKind2["IcuPlaceholder"] = 43] = "IcuPlaceholder";
7025
+ OpKind2[OpKind2["I18nContext"] = 44] = "I18nContext";
7026
+ OpKind2[OpKind2["I18nAttributes"] = 45] = "I18nAttributes";
7044
7027
  })(OpKind || (OpKind = {}));
7045
7028
  var ExpressionKind;
7046
7029
  (function(ExpressionKind2) {
@@ -7344,15 +7327,15 @@ function createRepeaterOp(repeaterCreate2, targetSlot, collection, sourceSpan) {
7344
7327
  }, NEW_OP), TRAIT_DEPENDS_ON_SLOT_CONTEXT);
7345
7328
  }
7346
7329
  function createDeferWhenOp(target, expr, prefetch, sourceSpan) {
7347
- return __spreadValues(__spreadValues({
7330
+ return __spreadValues(__spreadValues(__spreadValues({
7348
7331
  kind: OpKind.DeferWhen,
7349
7332
  target,
7350
7333
  expr,
7351
7334
  prefetch,
7352
7335
  sourceSpan
7353
- }, NEW_OP), TRAIT_DEPENDS_ON_SLOT_CONTEXT);
7336
+ }, NEW_OP), TRAIT_DEPENDS_ON_SLOT_CONTEXT), TRAIT_CONSUMES_VARS);
7354
7337
  }
7355
- function createI18nExpressionOp(context, target, i18nOwner, handle, expression, i18nPlaceholder, resolutionTime, usage, name, sourceSpan) {
7338
+ function createI18nExpressionOp(context, target, i18nOwner, handle, expression, icuPlaceholder, i18nPlaceholder, resolutionTime, usage, name, sourceSpan) {
7356
7339
  return __spreadValues(__spreadValues(__spreadValues({
7357
7340
  kind: OpKind.I18nExpression,
7358
7341
  context,
@@ -7360,6 +7343,7 @@ function createI18nExpressionOp(context, target, i18nOwner, handle, expression,
7360
7343
  i18nOwner,
7361
7344
  handle,
7362
7345
  expression,
7346
+ icuPlaceholder,
7363
7347
  i18nPlaceholder,
7364
7348
  resolutionTime,
7365
7349
  usage,
@@ -8092,6 +8076,9 @@ function transformExpressionsInOp(op, transform2, flags) {
8092
8076
  if (op.placeholderConfig !== null) {
8093
8077
  op.placeholderConfig = transformExpressionsInExpression(op.placeholderConfig, transform2, flags);
8094
8078
  }
8079
+ if (op.resolverFn !== null) {
8080
+ op.resolverFn = transformExpressionsInExpression(op.resolverFn, transform2, flags);
8081
+ }
8095
8082
  break;
8096
8083
  case OpKind.I18nMessage:
8097
8084
  for (const [placeholder, expr] of op.params) {
@@ -8128,6 +8115,7 @@ function transformExpressionsInOp(op, transform2, flags) {
8128
8115
  case OpKind.Template:
8129
8116
  case OpKind.Text:
8130
8117
  case OpKind.I18nAttributes:
8118
+ case OpKind.IcuPlaceholder:
8131
8119
  break;
8132
8120
  default:
8133
8121
  throw new Error(`AssertionError: transformExpressionsInOp doesn't handle ${OpKind[op.kind]}`);
@@ -8427,7 +8415,7 @@ var elementContainerOpKinds = /* @__PURE__ */ new Set([
8427
8415
  function isElementOrContainerOp(op) {
8428
8416
  return elementContainerOpKinds.has(op.kind);
8429
8417
  }
8430
- function createElementStartOp(tag, xref, namespace, i18nPlaceholder, sourceSpan) {
8418
+ function createElementStartOp(tag, xref, namespace, i18nPlaceholder, startSourceSpan, wholeSourceSpan) {
8431
8419
  return __spreadValues(__spreadValues({
8432
8420
  kind: OpKind.ElementStart,
8433
8421
  xref,
@@ -8438,10 +8426,11 @@ function createElementStartOp(tag, xref, namespace, i18nPlaceholder, sourceSpan)
8438
8426
  nonBindable: false,
8439
8427
  namespace,
8440
8428
  i18nPlaceholder,
8441
- sourceSpan
8429
+ startSourceSpan,
8430
+ wholeSourceSpan
8442
8431
  }, TRAIT_CONSUMES_SLOT), NEW_OP);
8443
8432
  }
8444
- function createTemplateOp(xref, templateKind, tag, functionNameSuffix, namespace, i18nPlaceholder, sourceSpan) {
8433
+ function createTemplateOp(xref, templateKind, tag, functionNameSuffix, namespace, i18nPlaceholder, startSourceSpan, wholeSourceSpan) {
8445
8434
  return __spreadValues(__spreadValues({
8446
8435
  kind: OpKind.Template,
8447
8436
  xref,
@@ -8456,11 +8445,12 @@ function createTemplateOp(xref, templateKind, tag, functionNameSuffix, namespace
8456
8445
  nonBindable: false,
8457
8446
  namespace,
8458
8447
  i18nPlaceholder,
8459
- sourceSpan
8448
+ startSourceSpan,
8449
+ wholeSourceSpan
8460
8450
  }, TRAIT_CONSUMES_SLOT), NEW_OP);
8461
8451
  }
8462
- function createRepeaterCreateOp(primaryView, emptyView, tag, track, varNames, i18nPlaceholder, emptyI18nPlaceholder, sourceSpan) {
8463
- return __spreadProps(__spreadValues(__spreadValues({
8452
+ function createRepeaterCreateOp(primaryView, emptyView, tag, track, varNames, i18nPlaceholder, emptyI18nPlaceholder, startSourceSpan, wholeSourceSpan) {
8453
+ return __spreadProps(__spreadValues(__spreadValues(__spreadValues({
8464
8454
  kind: OpKind.RepeaterCreate,
8465
8455
  attributes: null,
8466
8456
  xref: primaryView,
@@ -8479,8 +8469,9 @@ function createRepeaterCreateOp(primaryView, emptyView, tag, track, varNames, i1
8479
8469
  usesComponentInstance: false,
8480
8470
  i18nPlaceholder,
8481
8471
  emptyI18nPlaceholder,
8482
- sourceSpan
8483
- }, TRAIT_CONSUMES_SLOT), NEW_OP), {
8472
+ startSourceSpan,
8473
+ wholeSourceSpan
8474
+ }, TRAIT_CONSUMES_SLOT), NEW_OP), TRAIT_CONSUMES_VARS), {
8484
8475
  numSlotsUsed: emptyView === null ? 2 : 3
8485
8476
  });
8486
8477
  }
@@ -8503,12 +8494,13 @@ function createEnableBindingsOp(xref) {
8503
8494
  xref
8504
8495
  }, NEW_OP);
8505
8496
  }
8506
- function createTextOp(xref, initialValue, sourceSpan) {
8497
+ function createTextOp(xref, initialValue, icuPlaceholder, sourceSpan) {
8507
8498
  return __spreadValues(__spreadValues({
8508
8499
  kind: OpKind.Text,
8509
8500
  xref,
8510
8501
  handle: new SlotHandle(),
8511
8502
  initialValue,
8503
+ icuPlaceholder,
8512
8504
  sourceSpan
8513
8505
  }, TRAIT_CONSUMES_SLOT), NEW_OP);
8514
8506
  }
@@ -8659,6 +8651,15 @@ function createIcuEndOp(xref) {
8659
8651
  xref
8660
8652
  }, NEW_OP);
8661
8653
  }
8654
+ function createIcuPlaceholderOp(xref, name, strings) {
8655
+ return __spreadValues({
8656
+ kind: OpKind.IcuPlaceholder,
8657
+ xref,
8658
+ name,
8659
+ strings,
8660
+ expressionPlaceholders: []
8661
+ }, NEW_OP);
8662
+ }
8662
8663
  function createI18nContextOp(contextKind, xref, i18nBlock, message, sourceSpan) {
8663
8664
  if (i18nBlock === null && contextKind !== I18nContextKind.Attr) {
8664
8665
  throw new Error("AssertionError: i18nBlock must be provided for non-attribute contexts.");
@@ -9006,15 +9007,9 @@ function extractAttributeOp(unit, op, elements) {
9006
9007
  if (op.expression instanceof Interpolation2) {
9007
9008
  return;
9008
9009
  }
9009
- let extractable = op.expression.isConstant();
9010
+ let extractable = op.isTextAttribute || op.expression.isConstant();
9010
9011
  if (unit.job.compatibility === CompatibilityMode.TemplateDefinitionBuilder) {
9011
- extractable = isStringLiteral(op.expression);
9012
- if (op.name === "style" || op.name === "class") {
9013
- extractable && (extractable = op.isTextAttribute);
9014
- }
9015
- if (unit.job.kind === CompilationJobKind.Host) {
9016
- extractable && (extractable = op.isTextAttribute);
9017
- }
9012
+ extractable && (extractable = op.isTextAttribute);
9018
9013
  }
9019
9014
  if (extractable) {
9020
9015
  const extractedAttributeOp = createExtractedAttributeOp(op.target, op.isStructuralTemplateAttribute ? BindingKind.Template : BindingKind.Attribute, op.name, op.expression, op.i18nContext, op.i18nMessage, op.securityContext);
@@ -9249,7 +9244,7 @@ function collectElementConsts(job) {
9249
9244
  for (const unit of job.units) {
9250
9245
  for (const op of unit.create) {
9251
9246
  if (op.kind === OpKind.ExtractedAttribute) {
9252
- const attributes = allElementAttributes.get(op.target) || new ElementAttributes();
9247
+ const attributes = allElementAttributes.get(op.target) || new ElementAttributes(job.compatibility);
9253
9248
  allElementAttributes.set(op.target, attributes);
9254
9249
  attributes.add(op.bindingKind, op.name, op.expression, op.trustedValueFn);
9255
9250
  OpList.remove(op);
@@ -9284,11 +9279,6 @@ function collectElementConsts(job) {
9284
9279
  }
9285
9280
  var FLYWEIGHT_ARRAY = Object.freeze([]);
9286
9281
  var ElementAttributes = class {
9287
- constructor() {
9288
- this.known = /* @__PURE__ */ new Set();
9289
- this.byKind = /* @__PURE__ */ new Map();
9290
- this.projectAs = null;
9291
- }
9292
9282
  get attributes() {
9293
9283
  var _a2;
9294
9284
  return (_a2 = this.byKind.get(BindingKind.Attribute)) != null ? _a2 : FLYWEIGHT_ARRAY;
@@ -9313,12 +9303,28 @@ var ElementAttributes = class {
9313
9303
  var _a2;
9314
9304
  return (_a2 = this.byKind.get(BindingKind.I18n)) != null ? _a2 : FLYWEIGHT_ARRAY;
9315
9305
  }
9306
+ constructor(compatibility) {
9307
+ this.compatibility = compatibility;
9308
+ this.known = /* @__PURE__ */ new Map();
9309
+ this.byKind = /* @__PURE__ */ new Map();
9310
+ this.projectAs = null;
9311
+ }
9312
+ isKnown(kind, name, value) {
9313
+ var _a2;
9314
+ const nameToValue = (_a2 = this.known.get(kind)) != null ? _a2 : /* @__PURE__ */ new Set();
9315
+ this.known.set(kind, nameToValue);
9316
+ if (nameToValue.has(name)) {
9317
+ return true;
9318
+ }
9319
+ nameToValue.add(name);
9320
+ return false;
9321
+ }
9316
9322
  add(kind, name, value, trustedValueFn) {
9317
9323
  var _a2;
9318
- if (this.known.has(name)) {
9324
+ const allowDuplicates = this.compatibility === CompatibilityMode.TemplateDefinitionBuilder && (kind === BindingKind.Attribute || kind === BindingKind.ClassName || kind === BindingKind.StyleProperty);
9325
+ if (!allowDuplicates && this.isKnown(kind, name, value)) {
9319
9326
  return;
9320
9327
  }
9321
- this.known.add(name);
9322
9328
  if (name === "ngProjectAs") {
9323
9329
  if (value === null || !(value instanceof LiteralExpr) || value.value == null || typeof ((_a2 = value.value) == null ? void 0 : _a2.toString()) !== "string") {
9324
9330
  throw Error("ngProjectAs must have a string literal value");
@@ -9349,7 +9355,7 @@ var ElementAttributes = class {
9349
9355
  }
9350
9356
  };
9351
9357
  function getAttributeNameLiterals(name) {
9352
- const [attributeNamespace, attributeName] = splitNsName(name);
9358
+ const [attributeNamespace, attributeName] = splitNsName(name, false);
9353
9359
  const nameLiteral = literal(attributeName);
9354
9360
  if (attributeNamespace) {
9355
9361
  return [
@@ -9416,7 +9422,7 @@ function convertI18nBindings(job) {
9416
9422
  if (op.expression.i18nPlaceholders.length !== op.expression.expressions.length) {
9417
9423
  throw new Error(`AssertionError: An i18n attribute binding instruction requires the same number of expressions and placeholders, but found ${op.expression.i18nPlaceholders.length} placeholders and ${op.expression.expressions.length} expressions`);
9418
9424
  }
9419
- ops.push(createI18nExpressionOp(op.i18nContext, i18nAttributesForElem.target, i18nAttributesForElem.xref, i18nAttributesForElem.handle, expr, op.expression.i18nPlaceholders[i], I18nParamResolutionTime.Creation, I18nExpressionFor.I18nAttribute, op.name, op.sourceSpan));
9425
+ ops.push(createI18nExpressionOp(op.i18nContext, i18nAttributesForElem.target, i18nAttributesForElem.xref, i18nAttributesForElem.handle, expr, null, op.expression.i18nPlaceholders[i], I18nParamResolutionTime.Creation, I18nExpressionFor.I18nAttribute, op.name, op.sourceSpan));
9420
9426
  }
9421
9427
  OpList.replaceWithMany(op, ops);
9422
9428
  break;
@@ -9447,7 +9453,11 @@ function createDeferDepsFns(job) {
9447
9453
  if (op.handle.slot === null) {
9448
9454
  throw new Error("AssertionError: slot must be assigned bfore extracting defer deps functions");
9449
9455
  }
9450
- op.resolverFn = job.pool.getSharedFunctionReference(depsFnExpr, `${job.componentName}_Defer_${op.handle.slot}_DepsFn`);
9456
+ op.resolverFn = job.pool.getSharedFunctionReference(
9457
+ depsFnExpr,
9458
+ `${job.componentName}_Defer_${op.handle.slot}_DepsFn`,
9459
+ false
9460
+ );
9451
9461
  }
9452
9462
  }
9453
9463
  }
@@ -9455,62 +9465,99 @@ function createDeferDepsFns(job) {
9455
9465
 
9456
9466
  // bazel-out/darwin_arm64-fastbuild/bin/packages/compiler/src/template/pipeline/src/phases/create_i18n_contexts.mjs
9457
9467
  function createI18nContexts(job) {
9458
- const rootContexts = /* @__PURE__ */ new Map();
9459
- let currentI18nOp = null;
9460
- let xref;
9461
- const messageToContext = /* @__PURE__ */ new Map();
9468
+ const attrContextByMessage = /* @__PURE__ */ new Map();
9469
+ for (const unit of job.units) {
9470
+ for (const op of unit.ops()) {
9471
+ switch (op.kind) {
9472
+ case OpKind.Binding:
9473
+ case OpKind.Property:
9474
+ case OpKind.Attribute:
9475
+ case OpKind.ExtractedAttribute:
9476
+ if (op.i18nMessage === null) {
9477
+ continue;
9478
+ }
9479
+ if (!attrContextByMessage.has(op.i18nMessage)) {
9480
+ const i18nContext = createI18nContextOp(I18nContextKind.Attr, job.allocateXrefId(), null, op.i18nMessage, null);
9481
+ unit.create.push(i18nContext);
9482
+ attrContextByMessage.set(op.i18nMessage, i18nContext.xref);
9483
+ }
9484
+ op.i18nContext = attrContextByMessage.get(op.i18nMessage);
9485
+ break;
9486
+ }
9487
+ }
9488
+ }
9489
+ const blockContextByI18nBlock = /* @__PURE__ */ new Map();
9462
9490
  for (const unit of job.units) {
9463
9491
  for (const op of unit.create) {
9464
9492
  switch (op.kind) {
9465
9493
  case OpKind.I18nStart:
9466
- currentI18nOp = op;
9467
9494
  if (op.xref === op.root) {
9468
- xref = job.allocateXrefId();
9469
- unit.create.push(createI18nContextOp(I18nContextKind.RootI18n, xref, op.xref, op.message, null));
9470
- op.context = xref;
9471
- rootContexts.set(op.xref, xref);
9495
+ const contextOp = createI18nContextOp(I18nContextKind.RootI18n, job.allocateXrefId(), op.xref, op.message, null);
9496
+ unit.create.push(contextOp);
9497
+ op.context = contextOp.xref;
9498
+ blockContextByI18nBlock.set(op.xref, contextOp);
9472
9499
  }
9473
9500
  break;
9501
+ }
9502
+ }
9503
+ }
9504
+ for (const unit of job.units) {
9505
+ for (const op of unit.create) {
9506
+ if (op.kind === OpKind.I18nStart && op.xref !== op.root) {
9507
+ const rootContext = blockContextByI18nBlock.get(op.root);
9508
+ if (rootContext === void 0) {
9509
+ throw Error("AssertionError: Root i18n block i18n context should have been created.");
9510
+ }
9511
+ op.context = rootContext.xref;
9512
+ blockContextByI18nBlock.set(op.xref, rootContext);
9513
+ }
9514
+ }
9515
+ }
9516
+ let currentI18nOp = null;
9517
+ for (const unit of job.units) {
9518
+ for (const op of unit.create) {
9519
+ switch (op.kind) {
9520
+ case OpKind.I18nStart:
9521
+ currentI18nOp = op;
9522
+ break;
9474
9523
  case OpKind.I18nEnd:
9475
9524
  currentI18nOp = null;
9476
9525
  break;
9477
9526
  case OpKind.IcuStart:
9478
9527
  if (currentI18nOp === null) {
9479
- throw Error("Unexpected ICU outside of an i18n block.");
9528
+ throw Error("AssertionError: Unexpected ICU outside of an i18n block.");
9480
9529
  }
9481
9530
  if (op.message.id !== currentI18nOp.message.id) {
9482
- xref = job.allocateXrefId();
9483
- unit.create.push(createI18nContextOp(I18nContextKind.Icu, xref, currentI18nOp.xref, op.message, null));
9484
- op.context = xref;
9531
+ const contextOp = createI18nContextOp(I18nContextKind.Icu, job.allocateXrefId(), currentI18nOp.xref, op.message, null);
9532
+ unit.create.push(contextOp);
9533
+ op.context = contextOp.xref;
9485
9534
  } else {
9486
9535
  op.context = currentI18nOp.context;
9536
+ blockContextByI18nBlock.get(currentI18nOp.xref).contextKind = I18nContextKind.Icu;
9487
9537
  }
9488
9538
  break;
9489
9539
  }
9490
9540
  }
9491
- for (const op of unit.ops()) {
9492
- switch (op.kind) {
9493
- case OpKind.Binding:
9494
- case OpKind.Property:
9495
- case OpKind.Attribute:
9496
- case OpKind.ExtractedAttribute:
9497
- if (!op.i18nMessage) {
9498
- continue;
9499
- }
9500
- if (!messageToContext.has(op.i18nMessage)) {
9501
- const i18nContext = job.allocateXrefId();
9502
- unit.create.push(createI18nContextOp(I18nContextKind.Attr, i18nContext, null, op.i18nMessage, null));
9503
- messageToContext.set(op.i18nMessage, i18nContext);
9504
- }
9505
- op.i18nContext = messageToContext.get(op.i18nMessage);
9506
- break;
9507
- }
9508
- }
9509
9541
  }
9542
+ }
9543
+
9544
+ // bazel-out/darwin_arm64-fastbuild/bin/packages/compiler/src/template/pipeline/src/phases/deduplicate_text_bindings.mjs
9545
+ function deduplicateTextBindings(job) {
9546
+ const seen = /* @__PURE__ */ new Map();
9510
9547
  for (const unit of job.units) {
9511
- for (const op of unit.create) {
9512
- if (op.kind === OpKind.I18nStart && op.xref !== op.root) {
9513
- op.context = rootContexts.get(op.root);
9548
+ for (const op of unit.update.reversed()) {
9549
+ if (op.kind === OpKind.Binding && op.isTextAttribute) {
9550
+ const seenForElement = seen.get(op.target) || /* @__PURE__ */ new Set();
9551
+ if (seenForElement.has(op.name)) {
9552
+ if (job.compatibility === CompatibilityMode.TemplateDefinitionBuilder) {
9553
+ if (op.name === "style" || op.name === "class") {
9554
+ OpList.remove(op);
9555
+ }
9556
+ } else {
9557
+ }
9558
+ }
9559
+ seenForElement.add(op.name);
9560
+ seen.set(op.target, seenForElement);
9514
9561
  }
9515
9562
  }
9516
9563
  }
@@ -9800,12 +9847,16 @@ var LIST_START_MARKER = "[";
9800
9847
  var LIST_END_MARKER = "]";
9801
9848
  var LIST_DELIMITER = "|";
9802
9849
  function extractI18nMessages(job) {
9803
- const i18nContexts = /* @__PURE__ */ new Map();
9850
+ const i18nMessagesByContext = /* @__PURE__ */ new Map();
9804
9851
  const i18nBlocks = /* @__PURE__ */ new Map();
9852
+ const i18nContexts = /* @__PURE__ */ new Map();
9805
9853
  for (const unit of job.units) {
9806
9854
  for (const op of unit.create) {
9807
9855
  switch (op.kind) {
9808
9856
  case OpKind.I18nContext:
9857
+ const i18nMessageOp = createI18nMessage(job, op);
9858
+ unit.create.push(i18nMessageOp);
9859
+ i18nMessagesByContext.set(op.xref, i18nMessageOp);
9809
9860
  i18nContexts.set(op.xref, op);
9810
9861
  break;
9811
9862
  case OpKind.I18nStart:
@@ -9814,49 +9865,40 @@ function extractI18nMessages(job) {
9814
9865
  }
9815
9866
  }
9816
9867
  }
9817
- for (const unit of job.units) {
9818
- for (const op of unit.create) {
9819
- if (op.kind !== OpKind.I18nContext || op.contextKind !== I18nContextKind.Attr) {
9820
- continue;
9821
- }
9822
- const i18nMessageOp = createI18nMessage(job, op);
9823
- unit.create.push(i18nMessageOp);
9824
- }
9825
- }
9826
- const i18nBlockMessages = /* @__PURE__ */ new Map();
9827
- for (const unit of job.units) {
9828
- for (const op of unit.create) {
9829
- if (op.kind === OpKind.I18nStart && op.xref === op.root) {
9830
- if (!op.context) {
9831
- throw Error("I18n start op should have its context set.");
9832
- }
9833
- const i18nMessageOp = createI18nMessage(job, i18nContexts.get(op.context));
9834
- i18nBlockMessages.set(op.xref, i18nMessageOp);
9835
- unit.create.push(i18nMessageOp);
9836
- }
9837
- }
9838
- }
9868
+ let currentIcu = null;
9839
9869
  for (const unit of job.units) {
9840
9870
  for (const op of unit.create) {
9841
9871
  switch (op.kind) {
9842
9872
  case OpKind.IcuStart:
9843
- if (!op.context) {
9844
- throw Error("ICU op should have its context set.");
9873
+ currentIcu = op;
9874
+ OpList.remove(op);
9875
+ const icuContext = i18nContexts.get(op.context);
9876
+ if (icuContext.contextKind !== I18nContextKind.Icu) {
9877
+ continue;
9845
9878
  }
9846
- const i18nContext = i18nContexts.get(op.context);
9847
- if (i18nContext.contextKind === I18nContextKind.Icu) {
9848
- if (i18nContext.i18nBlock === null) {
9849
- throw Error("ICU context should have its i18n block set.");
9850
- }
9851
- const subMessage = createI18nMessage(job, i18nContext, op.messagePlaceholder);
9852
- unit.create.push(subMessage);
9853
- const rootI18nId = i18nBlocks.get(i18nContext.i18nBlock).root;
9854
- const parentMessage = i18nBlockMessages.get(rootI18nId);
9855
- parentMessage == null ? void 0 : parentMessage.subMessages.push(subMessage.xref);
9879
+ const i18nBlock = i18nBlocks.get(icuContext.i18nBlock);
9880
+ if (i18nBlock.context === icuContext.xref) {
9881
+ continue;
9856
9882
  }
9857
- OpList.remove(op);
9883
+ const rootI18nBlock = i18nBlocks.get(i18nBlock.root);
9884
+ const rootMessage = i18nMessagesByContext.get(rootI18nBlock.context);
9885
+ if (rootMessage === void 0) {
9886
+ throw Error("AssertionError: ICU sub-message should belong to a root message.");
9887
+ }
9888
+ const subMessage = i18nMessagesByContext.get(icuContext.xref);
9889
+ subMessage.messagePlaceholder = op.messagePlaceholder;
9890
+ rootMessage.subMessages.push(subMessage.xref);
9858
9891
  break;
9859
9892
  case OpKind.IcuEnd:
9893
+ currentIcu = null;
9894
+ OpList.remove(op);
9895
+ break;
9896
+ case OpKind.IcuPlaceholder:
9897
+ if (currentIcu === null || currentIcu.context == null) {
9898
+ throw Error("AssertionError: Unexpected ICU placeholder outside of i18n context");
9899
+ }
9900
+ const msg = i18nMessagesByContext.get(currentIcu.context);
9901
+ msg.postprocessingParams.set(op.name, literal(formatIcuPlaceholder(op)));
9860
9902
  OpList.remove(op);
9861
9903
  break;
9862
9904
  }
@@ -9866,14 +9908,16 @@ function extractI18nMessages(job) {
9866
9908
  function createI18nMessage(job, context, messagePlaceholder) {
9867
9909
  let formattedParams = formatParams(context.params);
9868
9910
  const formattedPostprocessingParams = formatParams(context.postprocessingParams);
9869
- let needsPostprocessing = formattedPostprocessingParams.size > 0;
9870
- for (const values of context.params.values()) {
9871
- if (values.length > 1) {
9872
- needsPostprocessing = true;
9873
- }
9874
- }
9911
+ let needsPostprocessing = [...context.params.values()].some((v) => v.length > 1);
9875
9912
  return createI18nMessageOp(job.allocateXrefId(), context.xref, context.i18nBlock, context.message, messagePlaceholder != null ? messagePlaceholder : null, formattedParams, formattedPostprocessingParams, needsPostprocessing);
9876
9913
  }
9914
+ function formatIcuPlaceholder(op) {
9915
+ if (op.strings.length !== op.expressionPlaceholders.length + 1) {
9916
+ throw Error(`AsserionError: Invalid ICU placeholder with ${op.strings.length} strings and ${op.expressionPlaceholders.length} expressions`);
9917
+ }
9918
+ const values = op.expressionPlaceholders.map(formatValue);
9919
+ return op.strings.flatMap((str, i) => [str, values[i] || ""]).join("");
9920
+ }
9877
9921
  function formatParams(params) {
9878
9922
  const formattedParams = /* @__PURE__ */ new Map();
9879
9923
  for (const [placeholder, placeholderValues] of params) {
@@ -10100,7 +10144,7 @@ var CLASS_BANG = "class!";
10100
10144
  var BANG_IMPORTANT = "!important";
10101
10145
  function parseHostStyleProperties(job) {
10102
10146
  for (const op of job.root.update) {
10103
- if (op.kind !== OpKind.Binding) {
10147
+ if (!(op.kind === OpKind.Binding && op.bindingKind === BindingKind.Property)) {
10104
10148
  continue;
10105
10149
  }
10106
10150
  if (op.name.endsWith(BANG_IMPORTANT)) {
@@ -16242,7 +16286,7 @@ function collectMessage(job, fileBasedI18nSuffix, messages, messageOp) {
16242
16286
  const mainVar = variable(job.pool.uniqueName(TRANSLATION_VAR_PREFIX2));
16243
16287
  const closureVar = i18nGenerateClosureVar(job.pool, messageOp.message.id, fileBasedI18nSuffix, job.i18nUseExternalIds);
16244
16288
  let transformFn = void 0;
16245
- if (messageOp.needsPostprocessing) {
16289
+ if (messageOp.needsPostprocessing || messageOp.postprocessingParams.size > 0) {
16246
16290
  const postprocessingParams = Object.fromEntries([...messageOp.postprocessingParams.entries()].sort());
16247
16291
  const formattedPostprocessingParams = formatI18nPlaceholderNamesInMap(postprocessingParams, false);
16248
16292
  const extraTransformFnParams = [];
@@ -16261,7 +16305,6 @@ function addSubMessageParams(messageOp, subMessagePlaceholders) {
16261
16305
  } else {
16262
16306
  messageOp.params.set(placeholder, literal(`${ESCAPE2}${I18N_ICU_MAPPING_PREFIX2}${placeholder}${ESCAPE2}`));
16263
16307
  messageOp.postprocessingParams.set(placeholder, literalArr(subMessages));
16264
- messageOp.needsPostprocessing = true;
16265
16308
  }
16266
16309
  }
16267
16310
  }
@@ -16295,12 +16338,13 @@ function i18nGenerateClosureVar(pool, messageId, fileBasedI18nSuffix, useExterna
16295
16338
 
16296
16339
  // bazel-out/darwin_arm64-fastbuild/bin/packages/compiler/src/template/pipeline/src/phases/i18n_text_extraction.mjs
16297
16340
  function convertI18nText(job) {
16298
- var _a2;
16341
+ var _a2, _b2, _c2;
16299
16342
  for (const unit of job.units) {
16300
16343
  let currentI18n = null;
16301
16344
  let currentIcu = null;
16302
16345
  const textNodeI18nBlocks = /* @__PURE__ */ new Map();
16303
16346
  const textNodeIcus = /* @__PURE__ */ new Map();
16347
+ const icuPlaceholderByText = /* @__PURE__ */ new Map();
16304
16348
  for (const op of unit.create) {
16305
16349
  switch (op.kind) {
16306
16350
  case OpKind.I18nStart:
@@ -16325,7 +16369,13 @@ function convertI18nText(job) {
16325
16369
  if (currentI18n !== null) {
16326
16370
  textNodeI18nBlocks.set(op.xref, currentI18n);
16327
16371
  textNodeIcus.set(op.xref, currentIcu);
16328
- OpList.remove(op);
16372
+ if (op.icuPlaceholder !== null) {
16373
+ const icuPlaceholderOp = createIcuPlaceholderOp(job.allocateXrefId(), op.icuPlaceholder, [op.initialValue]);
16374
+ OpList.replace(op, icuPlaceholderOp);
16375
+ icuPlaceholderByText.set(op.xref, icuPlaceholderOp);
16376
+ } else {
16377
+ OpList.remove(op);
16378
+ }
16329
16379
  }
16330
16380
  break;
16331
16381
  }
@@ -16338,14 +16388,18 @@ function convertI18nText(job) {
16338
16388
  }
16339
16389
  const i18nOp = textNodeI18nBlocks.get(op.target);
16340
16390
  const icuOp = textNodeIcus.get(op.target);
16391
+ const icuPlaceholder = icuPlaceholderByText.get(op.target);
16341
16392
  const contextId = icuOp ? icuOp.context : i18nOp.context;
16342
16393
  const resolutionTime = icuOp ? I18nParamResolutionTime.Postproccessing : I18nParamResolutionTime.Creation;
16343
16394
  const ops = [];
16344
16395
  for (let i = 0; i < op.interpolation.expressions.length; i++) {
16345
16396
  const expr = op.interpolation.expressions[i];
16346
- ops.push(createI18nExpressionOp(contextId, i18nOp.xref, i18nOp.xref, i18nOp.handle, expr, op.interpolation.i18nPlaceholders[i], resolutionTime, I18nExpressionFor.I18nText, "", (_a2 = expr.sourceSpan) != null ? _a2 : op.sourceSpan));
16397
+ ops.push(createI18nExpressionOp(contextId, i18nOp.xref, i18nOp.xref, i18nOp.handle, expr, (_a2 = icuPlaceholder == null ? void 0 : icuPlaceholder.xref) != null ? _a2 : null, (_b2 = op.interpolation.i18nPlaceholders[i]) != null ? _b2 : null, resolutionTime, I18nExpressionFor.I18nText, "", (_c2 = expr.sourceSpan) != null ? _c2 : op.sourceSpan));
16347
16398
  }
16348
16399
  OpList.replaceWithMany(op, ops);
16400
+ if (icuPlaceholder !== void 0) {
16401
+ icuPlaceholder.strings = op.interpolation.strings;
16402
+ }
16349
16403
  break;
16350
16404
  }
16351
16405
  }
@@ -16759,9 +16813,21 @@ function keepLast(ops) {
16759
16813
 
16760
16814
  // bazel-out/darwin_arm64-fastbuild/bin/packages/compiler/src/template/pipeline/src/phases/parse_extracted_styles.mjs
16761
16815
  function parseExtractedStyles(job) {
16816
+ const elements = /* @__PURE__ */ new Map();
16817
+ for (const unit of job.units) {
16818
+ for (const op of unit.create) {
16819
+ if (isElementOrContainerOp(op)) {
16820
+ elements.set(op.xref, op);
16821
+ }
16822
+ }
16823
+ }
16762
16824
  for (const unit of job.units) {
16763
16825
  for (const op of unit.create) {
16764
16826
  if (op.kind === OpKind.ExtractedAttribute && op.bindingKind === BindingKind.Attribute && isStringLiteral(op.expression)) {
16827
+ const target = elements.get(op.target);
16828
+ if (target !== void 0 && target.kind === OpKind.Template && target.templateKind === TemplateKind.Structural) {
16829
+ continue;
16830
+ }
16765
16831
  if (op.name === "style") {
16766
16832
  const parsedStyles = parse(op.expression.value);
16767
16833
  for (let i = 0; i < parsedStyles.length - 1; i += 2) {
@@ -17555,19 +17621,19 @@ function reifyCreateOperations(unit, ops) {
17555
17621
  OpList.replace(op, text(op.handle.slot, op.initialValue, op.sourceSpan));
17556
17622
  break;
17557
17623
  case OpKind.ElementStart:
17558
- OpList.replace(op, elementStart(op.handle.slot, op.tag, op.attributes, op.localRefs, op.sourceSpan));
17624
+ OpList.replace(op, elementStart(op.handle.slot, op.tag, op.attributes, op.localRefs, op.startSourceSpan));
17559
17625
  break;
17560
17626
  case OpKind.Element:
17561
- OpList.replace(op, element(op.handle.slot, op.tag, op.attributes, op.localRefs, op.sourceSpan));
17627
+ OpList.replace(op, element(op.handle.slot, op.tag, op.attributes, op.localRefs, op.wholeSourceSpan));
17562
17628
  break;
17563
17629
  case OpKind.ElementEnd:
17564
17630
  OpList.replace(op, elementEnd(op.sourceSpan));
17565
17631
  break;
17566
17632
  case OpKind.ContainerStart:
17567
- OpList.replace(op, elementContainerStart(op.handle.slot, op.attributes, op.localRefs, op.sourceSpan));
17633
+ OpList.replace(op, elementContainerStart(op.handle.slot, op.attributes, op.localRefs, op.startSourceSpan));
17568
17634
  break;
17569
17635
  case OpKind.Container:
17570
- OpList.replace(op, elementContainer(op.handle.slot, op.attributes, op.localRefs, op.sourceSpan));
17636
+ OpList.replace(op, elementContainer(op.handle.slot, op.attributes, op.localRefs, op.wholeSourceSpan));
17571
17637
  break;
17572
17638
  case OpKind.ContainerEnd:
17573
17639
  OpList.replace(op, elementContainerEnd());
@@ -17595,7 +17661,7 @@ function reifyCreateOperations(unit, ops) {
17595
17661
  throw new Error(`AssertionError: local refs array should have been extracted into a constant`);
17596
17662
  }
17597
17663
  const childView = unit.job.views.get(op.xref);
17598
- OpList.replace(op, template(op.handle.slot, variable(childView.fnName), childView.decls, childView.vars, op.tag, op.attributes, op.localRefs, op.sourceSpan));
17664
+ OpList.replace(op, template(op.handle.slot, variable(childView.fnName), childView.decls, childView.vars, op.tag, op.attributes, op.localRefs, op.startSourceSpan));
17599
17665
  break;
17600
17666
  case OpKind.DisableBindings:
17601
17667
  OpList.replace(op, disableBindings2());
@@ -17610,7 +17676,7 @@ function reifyCreateOperations(unit, ops) {
17610
17676
  const listenerFn = reifyListenerHandler(unit, op.handlerFnName, op.handlerOps, op.consumesDollarEvent);
17611
17677
  const eventTargetResolver = op.eventTarget ? GLOBAL_TARGET_RESOLVERS.get(op.eventTarget) : null;
17612
17678
  if (eventTargetResolver === void 0) {
17613
- throw new Error(`AssertionError: unknown event target ${op.eventTarget}`);
17679
+ throw new Error(`Unexpected global target '${op.eventTarget}' defined for '${op.name}' event. Supported list of global targets: window,document,body.`);
17614
17680
  }
17615
17681
  OpList.replace(op, listener(op.name, listenerFn, eventTargetResolver, op.hostListener && op.isAnimationListener, op.sourceSpan));
17616
17682
  break;
@@ -17697,7 +17763,7 @@ function reifyCreateOperations(unit, ops) {
17697
17763
  emptyDecls = emptyView.decls;
17698
17764
  emptyVars = emptyView.vars;
17699
17765
  }
17700
- OpList.replace(op, repeaterCreate(op.handle.slot, repeaterView.fnName, op.decls, op.vars, op.tag, op.attributes, op.trackByFn, op.usesComponentInstance, emptyViewFnName, emptyDecls, emptyVars, op.sourceSpan));
17766
+ OpList.replace(op, repeaterCreate(op.handle.slot, repeaterView.fnName, op.decls, op.vars, op.tag, op.attributes, op.trackByFn, op.usesComponentInstance, emptyViewFnName, emptyDecls, emptyVars, op.wholeSourceSpan));
17701
17767
  break;
17702
17768
  case OpKind.Statement:
17703
17769
  break;
@@ -18204,6 +18270,7 @@ function resolveI18nExpressionPlaceholders(job) {
18204
18270
  var _a2;
18205
18271
  const subTemplateIndicies = /* @__PURE__ */ new Map();
18206
18272
  const i18nContexts = /* @__PURE__ */ new Map();
18273
+ const icuPlaceholders = /* @__PURE__ */ new Map();
18207
18274
  for (const unit of job.units) {
18208
18275
  for (const op of unit.create) {
18209
18276
  switch (op.kind) {
@@ -18213,6 +18280,9 @@ function resolveI18nExpressionPlaceholders(job) {
18213
18280
  case OpKind.I18nContext:
18214
18281
  i18nContexts.set(op.xref, op);
18215
18282
  break;
18283
+ case OpKind.IcuPlaceholder:
18284
+ icuPlaceholders.set(op.xref, op);
18285
+ break;
18216
18286
  }
18217
18287
  }
18218
18288
  }
@@ -18221,66 +18291,32 @@ function resolveI18nExpressionPlaceholders(job) {
18221
18291
  for (const unit of job.units) {
18222
18292
  for (const op of unit.update) {
18223
18293
  if (op.kind === OpKind.I18nExpression) {
18224
- const i18nContext = i18nContexts.get(op.context);
18225
18294
  const index = expressionIndices.get(referenceIndex(op)) || 0;
18226
18295
  const subTemplateIndex = (_a2 = subTemplateIndicies.get(op.i18nOwner)) != null ? _a2 : null;
18227
- const params = op.resolutionTime === I18nParamResolutionTime.Creation ? i18nContext.params : i18nContext.postprocessingParams;
18228
- const values = params.get(op.i18nPlaceholder) || [];
18229
- values.push({
18296
+ const value = {
18230
18297
  value: index,
18231
18298
  subTemplateIndex,
18232
18299
  flags: I18nParamValueFlags.ExpressionIndex
18233
- });
18234
- params.set(op.i18nPlaceholder, values);
18300
+ };
18301
+ updatePlaceholder(op, value, i18nContexts, icuPlaceholders);
18235
18302
  expressionIndices.set(referenceIndex(op), index + 1);
18236
18303
  }
18237
18304
  }
18238
18305
  }
18239
18306
  }
18240
-
18241
- // bazel-out/darwin_arm64-fastbuild/bin/packages/compiler/src/template/pipeline/src/phases/resolve_i18n_icu_placeholders.mjs
18242
- function resolveI18nIcuPlaceholders(job) {
18243
- for (const unit of job.units) {
18244
- for (const op of unit.create) {
18245
- if (op.kind === OpKind.I18nContext && op.contextKind === I18nContextKind.Icu) {
18246
- for (const node of op.message.nodes) {
18247
- node.visit(new ResolveIcuPlaceholdersVisitor(op.postprocessingParams));
18248
- }
18249
- }
18250
- }
18307
+ function updatePlaceholder(op, value, i18nContexts, icuPlaceholders) {
18308
+ if (op.i18nPlaceholder !== null) {
18309
+ const i18nContext = i18nContexts.get(op.context);
18310
+ const params = op.resolutionTime === I18nParamResolutionTime.Creation ? i18nContext.params : i18nContext.postprocessingParams;
18311
+ const values = params.get(op.i18nPlaceholder) || [];
18312
+ values.push(value);
18313
+ params.set(op.i18nPlaceholder, values);
18251
18314
  }
18252
- }
18253
- var ResolveIcuPlaceholdersVisitor = class extends RecurseVisitor {
18254
- constructor(params) {
18255
- super();
18256
- this.params = params;
18315
+ if (op.icuPlaceholder !== null) {
18316
+ const icuPlaceholderOp = icuPlaceholders.get(op.icuPlaceholder);
18317
+ icuPlaceholderOp == null ? void 0 : icuPlaceholderOp.expressionPlaceholders.push(value);
18257
18318
  }
18258
- visitContainerPlaceholder(placeholder) {
18259
- var _a2, _b2;
18260
- if (placeholder.startName && placeholder.startSourceSpan && !this.params.has(placeholder.startName)) {
18261
- this.params.set(placeholder.startName, [{
18262
- value: (_a2 = placeholder.startSourceSpan) == null ? void 0 : _a2.toString(),
18263
- subTemplateIndex: null,
18264
- flags: I18nParamValueFlags.None
18265
- }]);
18266
- }
18267
- if (placeholder.closeName && placeholder.endSourceSpan && !this.params.has(placeholder.closeName)) {
18268
- this.params.set(placeholder.closeName, [{
18269
- value: (_b2 = placeholder.endSourceSpan) == null ? void 0 : _b2.toString(),
18270
- subTemplateIndex: null,
18271
- flags: I18nParamValueFlags.None
18272
- }]);
18273
- }
18274
- }
18275
- visitTagPlaceholder(placeholder) {
18276
- super.visitTagPlaceholder(placeholder);
18277
- this.visitContainerPlaceholder(placeholder);
18278
- }
18279
- visitBlockPlaceholder(placeholder) {
18280
- super.visitBlockPlaceholder(placeholder);
18281
- this.visitContainerPlaceholder(placeholder);
18282
- }
18283
- };
18319
+ }
18284
18320
 
18285
18321
  // bazel-out/darwin_arm64-fastbuild/bin/packages/compiler/src/template/pipeline/src/phases/resolve_names.mjs
18286
18322
  function resolveNames(job) {
@@ -18750,7 +18786,10 @@ function varsUsedByOp(op) {
18750
18786
  return op.interpolation.expressions.length;
18751
18787
  case OpKind.I18nExpression:
18752
18788
  case OpKind.Conditional:
18789
+ case OpKind.DeferWhen:
18753
18790
  return 1;
18791
+ case OpKind.RepeaterCreate:
18792
+ return op.emptyView ? 1 : 0;
18754
18793
  default:
18755
18794
  throw new Error(`Unhandled op: ${OpKind[op.kind]}`);
18756
18795
  }
@@ -19064,6 +19103,7 @@ var phases = [
19064
19103
  { kind: CompilationJobKind.Tmpl, fn: emitNamespaceChanges },
19065
19104
  { kind: CompilationJobKind.Tmpl, fn: propagateI18nBlocks },
19066
19105
  { kind: CompilationJobKind.Tmpl, fn: wrapI18nIcus },
19106
+ { kind: CompilationJobKind.Both, fn: deduplicateTextBindings },
19067
19107
  { kind: CompilationJobKind.Both, fn: specializeStyleBindings },
19068
19108
  { kind: CompilationJobKind.Both, fn: specializeBindings },
19069
19109
  { kind: CompilationJobKind.Both, fn: extractAttributes },
@@ -19102,7 +19142,6 @@ var phases = [
19102
19142
  { kind: CompilationJobKind.Tmpl, fn: createDeferDepsFns },
19103
19143
  { kind: CompilationJobKind.Tmpl, fn: resolveI18nElementPlaceholders },
19104
19144
  { kind: CompilationJobKind.Tmpl, fn: resolveI18nExpressionPlaceholders },
19105
- { kind: CompilationJobKind.Tmpl, fn: resolveI18nIcuPlaceholders },
19106
19145
  { kind: CompilationJobKind.Tmpl, fn: extractI18nMessages },
19107
19146
  { kind: CompilationJobKind.Tmpl, fn: generateTrackFns },
19108
19147
  { kind: CompilationJobKind.Tmpl, fn: collectI18nConsts },
@@ -19245,7 +19284,7 @@ function ingestHostBinding(input, bindingParser, constantPool) {
19245
19284
  bindingKind = BindingKind.Animation;
19246
19285
  }
19247
19286
  const securityContexts = bindingParser.calcPossibleSecurityContexts(input.componentSelector, property2.name, bindingKind === BindingKind.Attribute).filter((context) => context !== SecurityContext.NONE);
19248
- ingestHostProperty(job, property2, bindingKind, false, securityContexts);
19287
+ ingestHostProperty(job, property2, bindingKind, securityContexts);
19249
19288
  }
19250
19289
  for (const [name, expr] of (_b2 = Object.entries(input.attributes)) != null ? _b2 : []) {
19251
19290
  const securityContexts = bindingParser.calcPossibleSecurityContexts(input.componentSelector, name, true).filter((context) => context !== SecurityContext.NONE);
@@ -19256,7 +19295,7 @@ function ingestHostBinding(input, bindingParser, constantPool) {
19256
19295
  }
19257
19296
  return job;
19258
19297
  }
19259
- function ingestHostProperty(job, property2, bindingKind, isTextAttribute, securityContexts) {
19298
+ function ingestHostProperty(job, property2, bindingKind, securityContexts) {
19260
19299
  let expression;
19261
19300
  const ast = property2.expression.ast;
19262
19301
  if (ast instanceof Interpolation) {
@@ -19264,7 +19303,7 @@ function ingestHostProperty(job, property2, bindingKind, isTextAttribute, securi
19264
19303
  } else {
19265
19304
  expression = convertAst(ast, job, property2.sourceSpan);
19266
19305
  }
19267
- job.root.update.push(createBindingOp(job.root.xref, bindingKind, property2.name, expression, null, securityContexts, isTextAttribute, false, null, null, property2.sourceSpan));
19306
+ job.root.update.push(createBindingOp(job.root.xref, bindingKind, property2.name, expression, null, securityContexts, false, false, null, null, property2.sourceSpan));
19268
19307
  }
19269
19308
  function ingestHostAttribute(job, name, value, securityContexts) {
19270
19309
  const attrBinding = createBindingOp(
@@ -19278,14 +19317,13 @@ function ingestHostAttribute(job, name, value, securityContexts) {
19278
19317
  false,
19279
19318
  null,
19280
19319
  null,
19281
- null
19320
+ value.sourceSpan
19282
19321
  );
19283
19322
  job.root.update.push(attrBinding);
19284
19323
  }
19285
19324
  function ingestHostEvent(job, event) {
19286
19325
  const [phase, target] = event.type === 0 ? [null, event.targetOrPhase] : [event.targetOrPhase, null];
19287
- const eventBinding = createListenerOp(job.root.xref, new SlotHandle(), event.name, null, [], phase, target, true, event.sourceSpan);
19288
- eventBinding.handlerOps.push(createStatementOp(new ReturnStatement(convertAst(event.handler.ast, job, event.sourceSpan), event.handlerSpan)));
19326
+ const eventBinding = createListenerOp(job.root.xref, new SlotHandle(), event.name, null, makeListenerHandlerOps(job.root, event.handler, event.handlerSpan), phase, target, true, event.sourceSpan);
19289
19327
  job.root.create.push(eventBinding);
19290
19328
  }
19291
19329
  function ingestNodes(unit, template2) {
@@ -19297,9 +19335,9 @@ function ingestNodes(unit, template2) {
19297
19335
  } else if (node instanceof Content) {
19298
19336
  ingestContent(unit, node);
19299
19337
  } else if (node instanceof Text) {
19300
- ingestText(unit, node);
19338
+ ingestText(unit, node, null);
19301
19339
  } else if (node instanceof BoundText) {
19302
- ingestBoundText(unit, node);
19340
+ ingestBoundText(unit, node, null);
19303
19341
  } else if (node instanceof IfBlock) {
19304
19342
  ingestIfBlock(unit, node);
19305
19343
  } else if (node instanceof SwitchBlock) {
@@ -19322,7 +19360,7 @@ function ingestElement(unit, element2) {
19322
19360
  }
19323
19361
  const id = unit.job.allocateXrefId();
19324
19362
  const [namespaceKey, elementName] = splitNsName(element2.name);
19325
- const startOp = createElementStartOp(elementName, id, namespaceForKey(namespaceKey), element2.i18n instanceof TagPlaceholder ? element2.i18n : void 0, element2.startSourceSpan);
19363
+ const startOp = createElementStartOp(elementName, id, namespaceForKey(namespaceKey), element2.i18n instanceof TagPlaceholder ? element2.i18n : void 0, element2.startSourceSpan, element2.sourceSpan);
19326
19364
  unit.create.push(startOp);
19327
19365
  ingestElementBindings(unit, startOp, element2);
19328
19366
  ingestReferences(startOp, element2);
@@ -19352,7 +19390,7 @@ function ingestTemplate(unit, tmpl) {
19352
19390
  const namespace = namespaceForKey(namespacePrefix);
19353
19391
  const functionNameSuffix = tagNameWithoutNamespace === null ? "" : prefixWithNamespace(tagNameWithoutNamespace, namespace);
19354
19392
  const templateKind = isPlainTemplate(tmpl) ? TemplateKind.NgTemplate : TemplateKind.Structural;
19355
- const templateOp = createTemplateOp(childView.xref, templateKind, tagNameWithoutNamespace, functionNameSuffix, namespace, i18nPlaceholder, tmpl.startSourceSpan);
19393
+ const templateOp = createTemplateOp(childView.xref, templateKind, tagNameWithoutNamespace, functionNameSuffix, namespace, i18nPlaceholder, tmpl.startSourceSpan, tmpl.sourceSpan);
19356
19394
  unit.create.push(templateOp);
19357
19395
  ingestTemplateBindings(unit, templateOp, tmpl, templateKind);
19358
19396
  ingestReferences(templateOp, tmpl);
@@ -19378,10 +19416,10 @@ function ingestContent(unit, content) {
19378
19416
  }
19379
19417
  unit.create.push(op);
19380
19418
  }
19381
- function ingestText(unit, text2) {
19382
- unit.create.push(createTextOp(unit.job.allocateXrefId(), text2.value, text2.sourceSpan));
19419
+ function ingestText(unit, text2, icuPlaceholder) {
19420
+ unit.create.push(createTextOp(unit.job.allocateXrefId(), text2.value, icuPlaceholder, text2.sourceSpan));
19383
19421
  }
19384
- function ingestBoundText(unit, text2, i18nPlaceholders) {
19422
+ function ingestBoundText(unit, text2, icuPlaceholder) {
19385
19423
  var _a2;
19386
19424
  let value = text2.value;
19387
19425
  if (value instanceof ASTWithSource) {
@@ -19393,14 +19431,12 @@ function ingestBoundText(unit, text2, i18nPlaceholders) {
19393
19431
  if (text2.i18n !== void 0 && !(text2.i18n instanceof Container)) {
19394
19432
  throw Error(`Unhandled i18n metadata type for text interpolation: ${(_a2 = text2.i18n) == null ? void 0 : _a2.constructor.name}`);
19395
19433
  }
19396
- if (i18nPlaceholders === void 0) {
19397
- i18nPlaceholders = text2.i18n instanceof Container ? text2.i18n.children.filter((node) => node instanceof Placeholder).map((placeholder) => placeholder.name) : [];
19398
- }
19434
+ const i18nPlaceholders = text2.i18n instanceof Container ? text2.i18n.children.filter((node) => node instanceof Placeholder).map((placeholder) => placeholder.name) : [];
19399
19435
  if (i18nPlaceholders.length > 0 && i18nPlaceholders.length !== value.expressions.length) {
19400
19436
  throw Error(`Unexpected number of i18n placeholders (${value.expressions.length}) for BoundText with ${value.expressions.length} expressions`);
19401
19437
  }
19402
19438
  const textXref = unit.job.allocateXrefId();
19403
- unit.create.push(createTextOp(textXref, "", text2.sourceSpan));
19439
+ unit.create.push(createTextOp(textXref, "", icuPlaceholder, text2.sourceSpan));
19404
19440
  const baseSourceSpan = unit.job.compatibility ? null : text2.sourceSpan;
19405
19441
  unit.update.push(createInterpolateTextOp(textXref, new Interpolation2(value.strings, value.expressions.map((expr) => convertAst(expr, unit.job, baseSourceSpan)), i18nPlaceholders), text2.sourceSpan));
19406
19442
  }
@@ -19426,7 +19462,7 @@ function ingestIfBlock(unit, ifBlock) {
19426
19462
  }
19427
19463
  ifCaseI18nMeta = ifCase.i18n;
19428
19464
  }
19429
- const templateOp = createTemplateOp(cView.xref, TemplateKind.Block, tagName, "Conditional", Namespace.HTML, ifCaseI18nMeta, ifCase.sourceSpan);
19465
+ const templateOp = createTemplateOp(cView.xref, TemplateKind.Block, tagName, "Conditional", Namespace.HTML, ifCaseI18nMeta, ifCase.startSourceSpan, ifCase.sourceSpan);
19430
19466
  unit.create.push(templateOp);
19431
19467
  if (firstXref === null) {
19432
19468
  firstXref = cView.xref;
@@ -19454,7 +19490,7 @@ function ingestSwitchBlock(unit, switchBlock) {
19454
19490
  }
19455
19491
  switchCaseI18nMeta = switchCase.i18n;
19456
19492
  }
19457
- const templateOp = createTemplateOp(cView.xref, TemplateKind.Block, null, "Case", Namespace.HTML, switchCaseI18nMeta, switchCase.sourceSpan);
19493
+ const templateOp = createTemplateOp(cView.xref, TemplateKind.Block, null, "Case", Namespace.HTML, switchCaseI18nMeta, switchCase.startSourceSpan, switchCase.sourceSpan);
19458
19494
  unit.create.push(templateOp);
19459
19495
  if (firstXref === null) {
19460
19496
  firstXref = cView.xref;
@@ -19477,7 +19513,7 @@ function ingestDeferView(unit, suffix, i18nMeta, children, sourceSpan) {
19477
19513
  }
19478
19514
  const secondaryView = unit.job.allocateView(unit.xref);
19479
19515
  ingestNodes(secondaryView, children);
19480
- const templateOp = createTemplateOp(secondaryView.xref, TemplateKind.Block, null, `Defer${suffix}`, Namespace.HTML, i18nMeta, sourceSpan);
19516
+ const templateOp = createTemplateOp(secondaryView.xref, TemplateKind.Block, null, `Defer${suffix}`, Namespace.HTML, i18nMeta, sourceSpan, sourceSpan);
19481
19517
  unit.create.push(templateOp);
19482
19518
  return templateOp;
19483
19519
  }
@@ -19551,6 +19587,9 @@ function ingestDeferBlock(unit, deferBlock) {
19551
19587
  deferOnOps.push(deferOnOp);
19552
19588
  }
19553
19589
  if (triggers.when !== void 0) {
19590
+ if (triggers.when.value instanceof Interpolation) {
19591
+ throw new Error(`Unexpected interpolation in defer block when trigger`);
19592
+ }
19554
19593
  const deferOnOp = createDeferWhenOp(deferXref, convertAst(triggers.when.value, unit.job, triggers.when.sourceSpan), prefetch, triggers.when.sourceSpan);
19555
19594
  deferWhenOps.push(deferOnOp);
19556
19595
  }
@@ -19570,9 +19609,9 @@ function ingestIcu(unit, icu) {
19570
19609
  unit.create.push(createIcuStartOp(xref, icu.i18n, icuFromI18nMessage(icu.i18n).name, null));
19571
19610
  for (const [placeholder, text2] of Object.entries(__spreadValues(__spreadValues({}, icu.vars), icu.placeholders))) {
19572
19611
  if (text2 instanceof BoundText) {
19573
- ingestBoundText(unit, text2, [placeholder]);
19612
+ ingestBoundText(unit, text2, placeholder);
19574
19613
  } else {
19575
- ingestText(unit, text2);
19614
+ ingestText(unit, text2, placeholder);
19576
19615
  }
19577
19616
  }
19578
19617
  unit.create.push(createIcuEndOp(xref));
@@ -19624,7 +19663,7 @@ function ingestForBlock(unit, forBlock) {
19624
19663
  const i18nPlaceholder = forBlock.i18n;
19625
19664
  const emptyI18nPlaceholder = (_b2 = forBlock.empty) == null ? void 0 : _b2.i18n;
19626
19665
  const tagName = ingestControlFlowInsertionPoint(unit, repeaterView.xref, forBlock);
19627
- const repeaterCreate2 = createRepeaterCreateOp(repeaterView.xref, (_c2 = emptyView == null ? void 0 : emptyView.xref) != null ? _c2 : null, tagName, track, varNames, i18nPlaceholder, emptyI18nPlaceholder, forBlock.sourceSpan);
19666
+ const repeaterCreate2 = createRepeaterCreateOp(repeaterView.xref, (_c2 = emptyView == null ? void 0 : emptyView.xref) != null ? _c2 : null, tagName, track, varNames, i18nPlaceholder, emptyI18nPlaceholder, forBlock.startSourceSpan, forBlock.sourceSpan);
19628
19667
  unit.create.push(repeaterCreate2);
19629
19668
  const expression = convertAst(forBlock.expression, unit.job, convertSourceSpan(forBlock.expression.span, forBlock.sourceSpan));
19630
19669
  const repeater2 = createRepeaterOp(repeaterCreate2.xref, repeaterCreate2.handle, expression, forBlock.sourceSpan);
@@ -19712,13 +19751,13 @@ function convertAst(ast, job, baseSourceSpan) {
19712
19751
  throw new Error(`Unhandled expression type "${ast.constructor.name}" in file "${baseSourceSpan == null ? void 0 : baseSourceSpan.start.file.url}"`);
19713
19752
  }
19714
19753
  }
19715
- function convertAstWithInterpolation(job, value, i18nMeta) {
19754
+ function convertAstWithInterpolation(job, value, i18nMeta, sourceSpan) {
19716
19755
  var _a2, _b2;
19717
19756
  let expression;
19718
19757
  if (value instanceof Interpolation) {
19719
- expression = new Interpolation2(value.strings, value.expressions.map((e) => convertAst(e, job, null)), Object.keys((_b2 = (_a2 = asMessage(i18nMeta)) == null ? void 0 : _a2.placeholders) != null ? _b2 : {}));
19758
+ expression = new Interpolation2(value.strings, value.expressions.map((e) => convertAst(e, job, sourceSpan != null ? sourceSpan : null)), Object.keys((_b2 = (_a2 = asMessage(i18nMeta)) == null ? void 0 : _a2.placeholders) != null ? _b2 : {}));
19720
19759
  } else if (value instanceof AST) {
19721
- expression = convertAst(value, job, null);
19760
+ expression = convertAst(value, job, sourceSpan != null ? sourceSpan : null);
19722
19761
  } else {
19723
19762
  expression = literal(value);
19724
19763
  }
@@ -23396,12 +23435,15 @@ var BindingScope = class {
23396
23435
  }
23397
23436
  };
23398
23437
  var TrackByBindingScope = class extends BindingScope {
23399
- constructor(parentScope, globalAliases) {
23438
+ constructor(parentScope, globalOverrides) {
23400
23439
  super(parentScope.bindingLevel + 1, parentScope);
23401
- this.globalAliases = globalAliases;
23440
+ this.globalOverrides = globalOverrides;
23402
23441
  this.componentAccessCount = 0;
23403
23442
  }
23404
23443
  get(name) {
23444
+ if (this.globalOverrides.hasOwnProperty(name)) {
23445
+ return variable(this.globalOverrides[name]);
23446
+ }
23405
23447
  let current = this.parent;
23406
23448
  while (current) {
23407
23449
  if (current.hasLocal(name)) {
@@ -23409,9 +23451,6 @@ var TrackByBindingScope = class extends BindingScope {
23409
23451
  }
23410
23452
  current = current.parent;
23411
23453
  }
23412
- if (this.globalAliases[name]) {
23413
- return variable(this.globalAliases[name]);
23414
- }
23415
23454
  this.componentAccessCount++;
23416
23455
  return variable("this").prop(name);
23417
23456
  }
@@ -25413,7 +25452,7 @@ function publishFacade(global) {
25413
25452
  }
25414
25453
 
25415
25454
  // bazel-out/darwin_arm64-fastbuild/bin/packages/compiler/src/version.mjs
25416
- var VERSION2 = new Version("17.0.7");
25455
+ var VERSION2 = new Version("17.0.8");
25417
25456
 
25418
25457
  // bazel-out/darwin_arm64-fastbuild/bin/packages/compiler/src/i18n/extractor_merger.mjs
25419
25458
  var _VisitorMode;
@@ -25457,6 +25496,20 @@ var FactoryTarget2;
25457
25496
  // bazel-out/darwin_arm64-fastbuild/bin/packages/compiler/src/compiler.mjs
25458
25497
  publishFacade(_global);
25459
25498
 
25499
+ // bazel-out/darwin_arm64-fastbuild/bin/packages/core/schematics/ng-generate/control-flow-migration/identifier-lookup.mjs
25500
+ var import_typescript5 = __toESM(require("typescript"), 1);
25501
+ function lookupIdentifiersInSourceFile(sourceFile, names) {
25502
+ const results = /* @__PURE__ */ new Set();
25503
+ const visit = (node) => {
25504
+ if (import_typescript5.default.isIdentifier(node) && names.includes(node.text)) {
25505
+ results.add(node);
25506
+ }
25507
+ import_typescript5.default.forEachChild(node, visit);
25508
+ };
25509
+ visit(sourceFile);
25510
+ return results;
25511
+ }
25512
+
25460
25513
  // bazel-out/darwin_arm64-fastbuild/bin/packages/core/schematics/ng-generate/control-flow-migration/types.mjs
25461
25514
  var ngtemplate = "ng-template";
25462
25515
  var boundngifelse = "[ngIfElse]";
@@ -25467,6 +25520,18 @@ var startMarker = "\u25EC";
25467
25520
  var endMarker = "\u2722";
25468
25521
  var startI18nMarker = "\u2688";
25469
25522
  var endI18nMarker = "\u2689";
25523
+ var importRemovals = [
25524
+ "NgIf",
25525
+ "NgIfElse",
25526
+ "NgIfThenElse",
25527
+ "NgFor",
25528
+ "NgForOf",
25529
+ "NgForTrackBy",
25530
+ "NgSwitch",
25531
+ "NgSwitchCase",
25532
+ "NgSwitchDefault"
25533
+ ];
25534
+ var importWithCommonRemovals = [...importRemovals, "CommonModule"];
25470
25535
  function allFormsOf(selector) {
25471
25536
  return [
25472
25537
  selector,
@@ -25616,22 +25681,24 @@ var Template2 = class {
25616
25681
  }
25617
25682
  };
25618
25683
  var AnalyzedFile = class {
25619
- constructor() {
25684
+ constructor(sourceFile) {
25620
25685
  __publicField(this, "ranges", []);
25621
25686
  __publicField(this, "removeCommonModule", false);
25622
25687
  __publicField(this, "canRemoveImports", false);
25623
- __publicField(this, "sourceFilePath", "");
25688
+ __publicField(this, "sourceFile");
25689
+ __publicField(this, "importRanges", []);
25690
+ __publicField(this, "templateRanges", []);
25691
+ this.sourceFile = sourceFile;
25624
25692
  }
25625
25693
  getSortedRanges() {
25626
- const templateRanges = this.ranges.slice().filter((x) => x.type !== "import").sort((aStart, bStart) => bStart.start - aStart.start);
25627
- const importRanges = this.ranges.slice().filter((x) => x.type === "import").sort((aStart, bStart) => bStart.start - aStart.start);
25628
- return [...templateRanges, ...importRanges];
25694
+ this.templateRanges = this.ranges.slice().filter((x) => x.type === "template" || x.type === "templateUrl").sort((aStart, bStart) => bStart.start - aStart.start);
25695
+ this.importRanges = this.ranges.slice().filter((x) => x.type === "importDecorator" || x.type === "importDeclaration").sort((aStart, bStart) => bStart.start - aStart.start);
25696
+ return [...this.templateRanges, ...this.importRanges];
25629
25697
  }
25630
- static addRange(path2, sourceFilePath, analyzedFiles, range) {
25698
+ static addRange(path2, sourceFile, analyzedFiles, range) {
25631
25699
  let analysis = analyzedFiles.get(path2);
25632
25700
  if (!analysis) {
25633
- analysis = new AnalyzedFile();
25634
- analysis.sourceFilePath = sourceFilePath;
25701
+ analysis = new AnalyzedFile(sourceFile);
25635
25702
  analyzedFiles.set(path2, analysis);
25636
25703
  }
25637
25704
  const duplicate = analysis.ranges.find((current) => current.start === range.start && current.end === range.end);
@@ -25639,6 +25706,25 @@ var AnalyzedFile = class {
25639
25706
  analysis.ranges.push(range);
25640
25707
  }
25641
25708
  }
25709
+ verifyCanRemoveImports() {
25710
+ const importDeclaration = this.importRanges.find((r) => r.type === "importDeclaration");
25711
+ const instances = lookupIdentifiersInSourceFile(this.sourceFile, importWithCommonRemovals);
25712
+ let foundImportDeclaration = false;
25713
+ let count = 0;
25714
+ for (let range of this.importRanges) {
25715
+ for (let instance of instances) {
25716
+ if (instance.getStart() >= range.start && instance.getEnd() <= range.end) {
25717
+ if (range === importDeclaration) {
25718
+ foundImportDeclaration = true;
25719
+ }
25720
+ count++;
25721
+ }
25722
+ }
25723
+ }
25724
+ if (instances.size !== count && importDeclaration !== void 0 && foundImportDeclaration) {
25725
+ importDeclaration.remove = false;
25726
+ }
25727
+ }
25642
25728
  };
25643
25729
  var CommonCollector = class extends RecursiveVisitor {
25644
25730
  constructor() {
@@ -25759,19 +25845,7 @@ var TemplateCollector = class extends RecursiveVisitor {
25759
25845
 
25760
25846
  // bazel-out/darwin_arm64-fastbuild/bin/packages/core/schematics/ng-generate/control-flow-migration/util.mjs
25761
25847
  var import_path2 = require("path");
25762
- var import_typescript5 = __toESM(require("typescript"), 1);
25763
- var importRemovals = [
25764
- "NgIf",
25765
- "NgIfElse",
25766
- "NgIfThenElse",
25767
- "NgFor",
25768
- "NgForOf",
25769
- "NgForTrackBy",
25770
- "NgSwitch",
25771
- "NgSwitchCase",
25772
- "NgSwitchDefault"
25773
- ];
25774
- var importWithCommonRemovals = [...importRemovals, "CommonModule"];
25848
+ var import_typescript6 = __toESM(require("typescript"), 1);
25775
25849
  var startMarkerRegex = new RegExp(startMarker, "gm");
25776
25850
  var endMarkerRegex = new RegExp(endMarker, "gm");
25777
25851
  var startI18nMarkerRegex = new RegExp(startI18nMarker, "gm");
@@ -25779,16 +25853,20 @@ var endI18nMarkerRegex = new RegExp(endI18nMarker, "gm");
25779
25853
  var replaceMarkerRegex = new RegExp(`${startMarker}|${endMarker}`, "gm");
25780
25854
  function analyze(sourceFile, analyzedFiles) {
25781
25855
  forEachClass(sourceFile, (node) => {
25782
- if (import_typescript5.default.isClassDeclaration(node)) {
25856
+ if (import_typescript6.default.isClassDeclaration(node)) {
25783
25857
  analyzeDecorators(node, sourceFile, analyzedFiles);
25784
25858
  } else {
25785
25859
  analyzeImportDeclarations(node, sourceFile, analyzedFiles);
25786
25860
  }
25787
25861
  });
25788
25862
  }
25789
- function checkIfShouldChange(decl, removeCommonModule) {
25863
+ function checkIfShouldChange(decl, file) {
25864
+ const range = file.importRanges.find((r) => r.type === "importDeclaration");
25865
+ if (range === void 0 || !range.remove) {
25866
+ return false;
25867
+ }
25790
25868
  const clause = decl.getChildAt(1);
25791
- return !(!removeCommonModule && clause.namedBindings && import_typescript5.default.isNamedImports(clause.namedBindings) && clause.namedBindings.elements.length === 1 && clause.namedBindings.elements[0].getText() === "CommonModule");
25869
+ return !(!file.removeCommonModule && clause.namedBindings && import_typescript6.default.isNamedImports(clause.namedBindings) && clause.namedBindings.elements.length === 1 && clause.namedBindings.elements[0].getText() === "CommonModule");
25792
25870
  }
25793
25871
  function updateImportDeclaration(decl, removeCommonModule) {
25794
25872
  const clause = decl.getChildAt(1);
@@ -25796,81 +25874,89 @@ function updateImportDeclaration(decl, removeCommonModule) {
25796
25874
  if (updatedClause === null) {
25797
25875
  return "";
25798
25876
  }
25799
- const printer = import_typescript5.default.createPrinter({
25877
+ const printer = import_typescript6.default.createPrinter({
25800
25878
  removeComments: true
25801
25879
  });
25802
- const updated = import_typescript5.default.factory.updateImportDeclaration(decl, decl.modifiers, updatedClause, decl.moduleSpecifier, void 0);
25803
- return printer.printNode(import_typescript5.default.EmitHint.Unspecified, updated, clause.getSourceFile());
25880
+ const updated = import_typescript6.default.factory.updateImportDeclaration(decl, decl.modifiers, updatedClause, decl.moduleSpecifier, void 0);
25881
+ return printer.printNode(import_typescript6.default.EmitHint.Unspecified, updated, clause.getSourceFile());
25804
25882
  }
25805
25883
  function updateImportClause(clause, removeCommonModule) {
25806
- if (clause.namedBindings && import_typescript5.default.isNamedImports(clause.namedBindings)) {
25884
+ if (clause.namedBindings && import_typescript6.default.isNamedImports(clause.namedBindings)) {
25807
25885
  const removals = removeCommonModule ? importWithCommonRemovals : importRemovals;
25808
25886
  const elements = clause.namedBindings.elements.filter((el) => !removals.includes(el.getText()));
25809
25887
  if (elements.length === 0) {
25810
25888
  return null;
25811
25889
  }
25812
- clause = import_typescript5.default.factory.updateImportClause(clause, clause.isTypeOnly, clause.name, import_typescript5.default.factory.createNamedImports(elements));
25890
+ clause = import_typescript6.default.factory.updateImportClause(clause, clause.isTypeOnly, clause.name, import_typescript6.default.factory.createNamedImports(elements));
25813
25891
  }
25814
25892
  return clause;
25815
25893
  }
25816
25894
  function updateClassImports(propAssignment, removeCommonModule) {
25817
- const printer = import_typescript5.default.createPrinter();
25895
+ const printer = import_typescript6.default.createPrinter();
25818
25896
  const importList = propAssignment.initializer;
25819
25897
  const removals = removeCommonModule ? importWithCommonRemovals : importRemovals;
25820
25898
  const elements = importList.elements.filter((el) => !removals.includes(el.getText()));
25821
25899
  if (elements.length === importList.elements.length) {
25822
25900
  return null;
25823
25901
  }
25824
- const updatedElements = import_typescript5.default.factory.updateArrayLiteralExpression(importList, elements);
25825
- const updatedAssignment = import_typescript5.default.factory.updatePropertyAssignment(propAssignment, propAssignment.name, updatedElements);
25826
- return printer.printNode(import_typescript5.default.EmitHint.Unspecified, updatedAssignment, updatedAssignment.getSourceFile());
25902
+ const updatedElements = import_typescript6.default.factory.updateArrayLiteralExpression(importList, elements);
25903
+ const updatedAssignment = import_typescript6.default.factory.updatePropertyAssignment(propAssignment, propAssignment.name, updatedElements);
25904
+ return printer.printNode(import_typescript6.default.EmitHint.Unspecified, updatedAssignment, updatedAssignment.getSourceFile());
25827
25905
  }
25828
25906
  function analyzeImportDeclarations(node, sourceFile, analyzedFiles) {
25829
25907
  if (node.getText().indexOf("@angular/common") === -1) {
25830
25908
  return;
25831
25909
  }
25832
25910
  const clause = node.getChildAt(1);
25833
- if (clause.namedBindings && import_typescript5.default.isNamedImports(clause.namedBindings)) {
25911
+ if (clause.namedBindings && import_typescript6.default.isNamedImports(clause.namedBindings)) {
25834
25912
  const elements = clause.namedBindings.elements.filter((el) => importWithCommonRemovals.includes(el.getText()));
25835
25913
  if (elements.length > 0) {
25836
- AnalyzedFile.addRange(sourceFile.fileName, sourceFile.fileName, analyzedFiles, { start: node.getStart(), end: node.getEnd(), node, type: "import" });
25914
+ AnalyzedFile.addRange(sourceFile.fileName, sourceFile, analyzedFiles, {
25915
+ start: node.getStart(),
25916
+ end: node.getEnd(),
25917
+ node,
25918
+ type: "importDeclaration",
25919
+ remove: true
25920
+ });
25837
25921
  }
25838
25922
  }
25839
25923
  }
25840
25924
  function analyzeDecorators(node, sourceFile, analyzedFiles) {
25841
25925
  var _a2;
25842
- const decorator = (_a2 = import_typescript5.default.getDecorators(node)) == null ? void 0 : _a2.find((dec) => {
25843
- return import_typescript5.default.isCallExpression(dec.expression) && import_typescript5.default.isIdentifier(dec.expression.expression) && dec.expression.expression.text === "Component";
25926
+ const decorator = (_a2 = import_typescript6.default.getDecorators(node)) == null ? void 0 : _a2.find((dec) => {
25927
+ return import_typescript6.default.isCallExpression(dec.expression) && import_typescript6.default.isIdentifier(dec.expression.expression) && dec.expression.expression.text === "Component";
25844
25928
  });
25845
- const metadata = decorator && decorator.expression.arguments.length > 0 && import_typescript5.default.isObjectLiteralExpression(decorator.expression.arguments[0]) ? decorator.expression.arguments[0] : null;
25929
+ const metadata = decorator && decorator.expression.arguments.length > 0 && import_typescript6.default.isObjectLiteralExpression(decorator.expression.arguments[0]) ? decorator.expression.arguments[0] : null;
25846
25930
  if (!metadata) {
25847
25931
  return;
25848
25932
  }
25849
25933
  for (const prop of metadata.properties) {
25850
- if (!import_typescript5.default.isPropertyAssignment(prop) || !import_typescript5.default.isIdentifier(prop.name) && !import_typescript5.default.isStringLiteralLike(prop.name)) {
25934
+ if (!import_typescript6.default.isPropertyAssignment(prop) || !import_typescript6.default.isIdentifier(prop.name) && !import_typescript6.default.isStringLiteralLike(prop.name)) {
25851
25935
  continue;
25852
25936
  }
25853
25937
  switch (prop.name.text) {
25854
25938
  case "template":
25855
- AnalyzedFile.addRange(sourceFile.fileName, sourceFile.fileName, analyzedFiles, {
25939
+ AnalyzedFile.addRange(sourceFile.fileName, sourceFile, analyzedFiles, {
25856
25940
  start: prop.initializer.getStart() + 1,
25857
25941
  end: prop.initializer.getEnd() - 1,
25858
25942
  node: prop,
25859
- type: "template"
25943
+ type: "template",
25944
+ remove: true
25860
25945
  });
25861
25946
  break;
25862
25947
  case "imports":
25863
- AnalyzedFile.addRange(sourceFile.fileName, sourceFile.fileName, analyzedFiles, {
25948
+ AnalyzedFile.addRange(sourceFile.fileName, sourceFile, analyzedFiles, {
25864
25949
  start: prop.name.getStart(),
25865
25950
  end: prop.initializer.getEnd(),
25866
25951
  node: prop,
25867
- type: "import"
25952
+ type: "importDecorator",
25953
+ remove: true
25868
25954
  });
25869
25955
  break;
25870
25956
  case "templateUrl":
25871
- if (import_typescript5.default.isStringLiteralLike(prop.initializer)) {
25957
+ if (import_typescript6.default.isStringLiteralLike(prop.initializer)) {
25872
25958
  const path2 = (0, import_path2.join)((0, import_path2.dirname)(sourceFile.fileName), prop.initializer.text);
25873
- AnalyzedFile.addRange(path2, sourceFile.fileName, analyzedFiles, { start: 0, node: prop, type: "templateUrl" });
25959
+ AnalyzedFile.addRange(path2, sourceFile, analyzedFiles, { start: 0, node: prop, type: "templateUrl", remove: true });
25874
25960
  }
25875
25961
  break;
25876
25962
  }
@@ -25905,6 +25991,41 @@ function parseTemplate2(template2) {
25905
25991
  }
25906
25992
  return { tree: parsed, errors: [] };
25907
25993
  }
25994
+ function validateMigratedTemplate(migrated, fileName) {
25995
+ const parsed = parseTemplate2(migrated);
25996
+ let errors = [];
25997
+ if (parsed.errors.length > 0) {
25998
+ errors.push({
25999
+ type: "parse",
26000
+ error: new Error(`The migration resulted in invalid HTML for ${fileName}. Please check the template for valid HTML structures and run the migration again.`)
26001
+ });
26002
+ }
26003
+ if (parsed.tree) {
26004
+ const i18nError = validateI18nStructure(parsed.tree, fileName);
26005
+ if (i18nError !== null) {
26006
+ errors.push({ type: "i18n", error: i18nError });
26007
+ }
26008
+ }
26009
+ return errors;
26010
+ }
26011
+ function validateI18nStructure(parsed, fileName) {
26012
+ const visitor = new i18nCollector();
26013
+ visitAll2(visitor, parsed.rootNodes);
26014
+ const parents = visitor.elements.filter((el) => el.children.length > 0);
26015
+ for (const p of parents) {
26016
+ for (const el of visitor.elements) {
26017
+ if (el === p)
26018
+ continue;
26019
+ if (isChildOf(p, el)) {
26020
+ return new Error(`i18n Nesting error: The migration would result in invalid i18n nesting for ${fileName}. Element with i18n attribute "${p.name}" would result having a child of element with i18n attribute "${el.name}". Please fix and re-run the migration.`);
26021
+ }
26022
+ }
26023
+ }
26024
+ return null;
26025
+ }
26026
+ function isChildOf(parent, el) {
26027
+ return parent.sourceSpan.start.offset < el.sourceSpan.start.offset && parent.sourceSpan.end.offset > el.sourceSpan.end.offset;
26028
+ }
25908
26029
  function calculateNesting(visitor, hasLineBreaks2) {
25909
26030
  let nestedQueue = [];
25910
26031
  for (let i = 0; i < visitor.elements.length; i++) {
@@ -26026,12 +26147,12 @@ function canRemoveCommonModule(template2) {
26026
26147
  }
26027
26148
  return removeCommonModule;
26028
26149
  }
26029
- function removeImports(template2, node, removeCommonModule) {
26030
- if (template2.startsWith("imports") && import_typescript5.default.isPropertyAssignment(node)) {
26031
- const updatedImport = updateClassImports(node, removeCommonModule);
26150
+ function removeImports(template2, node, file) {
26151
+ if (template2.startsWith("imports") && import_typescript6.default.isPropertyAssignment(node)) {
26152
+ const updatedImport = updateClassImports(node, file.removeCommonModule);
26032
26153
  return updatedImport != null ? updatedImport : template2;
26033
- } else if (import_typescript5.default.isImportDeclaration(node) && checkIfShouldChange(node, removeCommonModule)) {
26034
- return updateImportDeclaration(node, removeCommonModule);
26154
+ } else if (import_typescript6.default.isImportDeclaration(node) && checkIfShouldChange(node, file)) {
26155
+ return updateImportDeclaration(node, file.removeCommonModule);
26035
26156
  }
26036
26157
  return template2;
26037
26158
  }
@@ -26136,6 +26257,10 @@ function formatTemplate(tmpl, templateType) {
26136
26257
  let openSelfClosingEl = false;
26137
26258
  const openBlockRegex = /^\s*\@(if|switch|case|default|for)|^\s*\}\s\@else/;
26138
26259
  const openElRegex = /^\s*<([a-z0-9]+)(?![^>]*\/>)[^>]*>?/;
26260
+ const openAttrDoubleRegex = /="([^"]|\\")*$/;
26261
+ const openAttrSingleRegex = /='([^']|\\')*$/;
26262
+ const closeAttrDoubleRegex = /^\s*([^><]|\\")*"/;
26263
+ const closeAttrSingleRegex = /^\s*([^><]|\\')*'/;
26139
26264
  const selfClosingRegex = new RegExp(`^\\s*<(${selfClosingList}).+\\/?>`);
26140
26265
  const openSelfClosingRegex = new RegExp(`^\\s*<(${selfClosingList})(?![^>]*\\/>)[^>]*$`);
26141
26266
  const closeBlockRegex = /^\s*\}\s*$|^\s*\}\s\@else/;
@@ -26151,6 +26276,8 @@ function formatTemplate(tmpl, templateType) {
26151
26276
  let i18nDepth = 0;
26152
26277
  let inMigratedBlock = false;
26153
26278
  let inI18nBlock = false;
26279
+ let inAttribute = false;
26280
+ let isDoubleQuotes = false;
26154
26281
  for (let [index, line] of lines.entries()) {
26155
26282
  depth += [...line.matchAll(startMarkerRegex)].length - [...line.matchAll(endMarkerRegex)].length;
26156
26283
  inMigratedBlock = depth > 0;
@@ -26160,7 +26287,7 @@ function formatTemplate(tmpl, templateType) {
26160
26287
  line = line.replace(replaceMarkerRegex, "");
26161
26288
  lineWasMigrated = true;
26162
26289
  }
26163
- if (line.trim() === "" && index !== 0 && index !== lines.length - 1 && (inMigratedBlock || lineWasMigrated)) {
26290
+ if (line.trim() === "" && index !== 0 && index !== lines.length - 1 && (inMigratedBlock || lineWasMigrated) && !inI18nBlock && !inAttribute) {
26164
26291
  continue;
26165
26292
  }
26166
26293
  if (templateType === "template" && index <= 1) {
@@ -26170,8 +26297,20 @@ function formatTemplate(tmpl, templateType) {
26170
26297
  if ((closeBlockRegex.test(line) || closeElRegex.test(line) && (!singleLineElRegex.test(line) && !closeMultiLineElRegex.test(line))) && indent !== "") {
26171
26298
  indent = indent.slice(2);
26172
26299
  }
26173
- const newLine = inI18nBlock ? line : mindent + (line.trim() !== "" ? indent : "") + line.trim();
26300
+ const isOpenDoubleAttr = openAttrDoubleRegex.test(line);
26301
+ const isOpenSingleAttr = openAttrSingleRegex.test(line);
26302
+ if (!inAttribute && isOpenDoubleAttr) {
26303
+ inAttribute = true;
26304
+ isDoubleQuotes = true;
26305
+ } else if (!inAttribute && isOpenSingleAttr) {
26306
+ inAttribute = true;
26307
+ isDoubleQuotes = false;
26308
+ }
26309
+ const newLine = inI18nBlock || inAttribute ? line : mindent + (line.trim() !== "" ? indent : "") + line.trim();
26174
26310
  formatted.push(newLine);
26311
+ if (!isOpenDoubleAttr && !isOpenSingleAttr && (inAttribute && isDoubleQuotes && closeAttrDoubleRegex.test(line) || inAttribute && !isDoubleQuotes && closeAttrSingleRegex.test(line))) {
26312
+ inAttribute = false;
26313
+ }
26175
26314
  if (closeMultiLineElRegex.test(line)) {
26176
26315
  indent = indent.slice(2);
26177
26316
  if (openSelfClosingEl) {
@@ -26197,7 +26336,7 @@ function formatTemplate(tmpl, templateType) {
26197
26336
  }
26198
26337
  function forEachClass(sourceFile, callback) {
26199
26338
  sourceFile.forEachChild(function walk(node) {
26200
- if (import_typescript5.default.isClassDeclaration(node) || import_typescript5.default.isImportDeclaration(node)) {
26339
+ if (import_typescript6.default.isClassDeclaration(node) || import_typescript6.default.isImportDeclaration(node)) {
26201
26340
  callback(node);
26202
26341
  }
26203
26342
  node.forEachChild(walk);
@@ -26438,10 +26577,10 @@ function getNgForParts(expression) {
26438
26577
  current = "";
26439
26578
  continue;
26440
26579
  }
26441
- if (stringPairs.has(char)) {
26442
- stringStack.push(stringPairs.get(char));
26443
- } else if (stringStack.length > 0 && stringStack[stringStack.length - 1] === char) {
26580
+ if (stringStack.length > 0 && stringStack[stringStack.length - 1] === char) {
26444
26581
  stringStack.pop();
26582
+ } else if (stringPairs.has(char)) {
26583
+ stringStack.push(stringPairs.get(char));
26445
26584
  }
26446
26585
  if (commaSeparatedSyntax.has(char)) {
26447
26586
  commaSeparatedStack.push(commaSeparatedSyntax.get(char));
@@ -26696,13 +26835,9 @@ function migrateTemplate(template2, templateType, node, file, format = true, ana
26696
26835
  migrated = templateResult.migrated;
26697
26836
  const changed = ifResult.changed || forResult.changed || switchResult.changed || caseResult.changed;
26698
26837
  if (changed) {
26699
- const parsed = parseTemplate2(migrated);
26700
- if (parsed.errors.length > 0) {
26701
- const parsingError = {
26702
- type: "parse",
26703
- error: new Error(`The migration resulted in invalid HTML for ${file.sourceFilePath}. Please check the template for valid HTML structures and run the migration again.`)
26704
- };
26705
- return { migrated: template2, errors: [parsingError] };
26838
+ const errors2 = validateMigratedTemplate(migrated, file.sourceFile.fileName);
26839
+ if (errors2.length > 0) {
26840
+ return { migrated: template2, errors: errors2 };
26706
26841
  }
26707
26842
  }
26708
26843
  if (format && changed) {
@@ -26712,11 +26847,14 @@ function migrateTemplate(template2, templateType, node, file, format = true, ana
26712
26847
  migrated = migrated.replace(markerRegex, "");
26713
26848
  file.removeCommonModule = canRemoveCommonModule(template2);
26714
26849
  file.canRemoveImports = true;
26715
- if (templateType === "templateUrl" && analyzedFiles !== null && analyzedFiles.has(file.sourceFilePath)) {
26716
- const componentFile = analyzedFiles.get(file.sourceFilePath);
26850
+ if (templateType === "templateUrl" && analyzedFiles !== null && analyzedFiles.has(file.sourceFile.fileName)) {
26851
+ const componentFile = analyzedFiles.get(file.sourceFile.fileName);
26852
+ componentFile.getSortedRanges();
26717
26853
  componentFile.removeCommonModule = file.removeCommonModule;
26718
26854
  componentFile.canRemoveImports = file.canRemoveImports;
26855
+ componentFile.verifyCanRemoveImports();
26719
26856
  }
26857
+ file.verifyCanRemoveImports();
26720
26858
  errors = [
26721
26859
  ...ifResult.errors,
26722
26860
  ...forResult.errors,
@@ -26724,7 +26862,7 @@ function migrateTemplate(template2, templateType, node, file, format = true, ana
26724
26862
  ...caseResult.errors
26725
26863
  ];
26726
26864
  } else if (file.canRemoveImports) {
26727
- migrated = removeImports(template2, node, file.removeCommonModule);
26865
+ migrated = removeImports(template2, node, file);
26728
26866
  }
26729
26867
  return { migrated, errors };
26730
26868
  }