@angular-eslint/bundled-angular-compiler 18.1.1-alpha.0 → 18.1.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +130 -44
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
- * @license Angular v18.0.5
4
+ * @license Angular v18.1.2
5
5
  * (c) 2010-2024 Google LLC. https://angular.io/
6
6
  * License: MIT
7
7
  */
@@ -6552,6 +6552,45 @@ class AbstractJsEmitterVisitor extends AbstractEmitterVisitor {
6552
6552
  this.visitAllObjects((param) => ctx.print(null, param.name), params, ctx, ',');
6553
6553
  }
6554
6554
  }
6555
+
6556
+ /**
6557
+ * @fileoverview
6558
+ * A module to facilitate use of a Trusted Types policy within the JIT
6559
+ * compiler. It lazily constructs the Trusted Types policy, providing helper
6560
+ * utilities for promoting strings to Trusted Types. When Trusted Types are not
6561
+ * available, strings are used as a fallback.
6562
+ * @security All use of this module is security-sensitive and should go through
6563
+ * security review.
6564
+ */
6565
+ /**
6566
+ * The Trusted Types policy, or null if Trusted Types are not
6567
+ * enabled/supported, or undefined if the policy has not been created yet.
6568
+ */
6569
+ let policy;
6570
+ /**
6571
+ * Returns the Trusted Types policy, or null if Trusted Types are not
6572
+ * enabled/supported. The first call to this function will create the policy.
6573
+ */
6574
+ function getPolicy() {
6575
+ if (policy === undefined) {
6576
+ const trustedTypes = _global['trustedTypes'];
6577
+ policy = null;
6578
+ if (trustedTypes) {
6579
+ try {
6580
+ policy = trustedTypes.createPolicy('angular#unsafe-jit', {
6581
+ createScript: (s) => s,
6582
+ });
6583
+ }
6584
+ catch {
6585
+ // trustedTypes.createPolicy throws if called with a name that is
6586
+ // already registered, even in report-only mode. Until the API changes,
6587
+ // catch the error not to break the applications functionally. In such
6588
+ // cases, the code will fall back to using strings.
6589
+ }
6590
+ }
6591
+ }
6592
+ return policy;
6593
+ }
6555
6594
  /**
6556
6595
  * Unsafely promote a string to a TrustedScript, falling back to strings when
6557
6596
  * Trusted Types are not available.
@@ -6560,7 +6599,7 @@ class AbstractJsEmitterVisitor extends AbstractEmitterVisitor {
6560
6599
  * interpreted and executed as a script by a browser, e.g. when calling eval.
6561
6600
  */
6562
6601
  function trustedScriptFromString(script) {
6563
- return script;
6602
+ return getPolicy()?.createScript(script) || script;
6564
6603
  }
6565
6604
  /**
6566
6605
  * Unsafely call the Function constructor with the given string arguments.
@@ -7161,8 +7200,8 @@ class ShadowCss {
7161
7200
  * animation declaration (with possibly multiple animation definitions)
7162
7201
  *
7163
7202
  * The regular expression can be divided in three parts
7164
- * - (^|\s+)
7165
- * simply captures how many (if any) leading whitespaces are present
7203
+ * - (^|\s+|,)
7204
+ * captures how many (if any) leading whitespaces are present or a comma
7166
7205
  * - (?:(?:(['"])((?:\\\\|\\\2|(?!\2).)+)\2)|(-?[A-Za-z][\w\-]*))
7167
7206
  * captures two different possible keyframes, ones which are quoted or ones which are valid css
7168
7207
  * idents (custom properties excluded)
@@ -7170,7 +7209,7 @@ class ShadowCss {
7170
7209
  * simply matches the end of the possible keyframe, valid endings are: a comma, a space, a
7171
7210
  * semicolon or the end of the string
7172
7211
  */
7173
- this._animationDeclarationKeyframesRe = /(^|\s+)(?:(?:(['"])((?:\\\\|\\\2|(?!\2).)+)\2)|(-?[A-Za-z][\w\-]*))(?=[,\s]|$)/g;
7212
+ this._animationDeclarationKeyframesRe = /(^|\s+|,)(?:(?:(['"])((?:\\\\|\\\2|(?!\2).)+)\2)|(-?[A-Za-z][\w\-]*))(?=[,\s]|$)/g;
7174
7213
  }
7175
7214
  /*
7176
7215
  * Shim some cssText with the given selector. Returns cssText that can be included in the document
@@ -7327,7 +7366,7 @@ class ShadowCss {
7327
7366
  * @returns the updated css rule.
7328
7367
  **/
7329
7368
  _scopeAnimationRule(rule, scopeSelector, unscopedKeyframesSet) {
7330
- let content = rule.content.replace(/((?:^|\s+|;)(?:-webkit-)?animation(?:\s*):(?:\s*))([^;]+)/g, (_, start, animationDeclarations) => start +
7369
+ let content = rule.content.replace(/((?:^|\s+|;)(?:-webkit-)?animation\s*:\s*),*([^;]+)/g, (_, start, animationDeclarations) => start +
7331
7370
  animationDeclarations.replace(this._animationDeclarationKeyframesRe, (original, leadingSpaces, quote = '', quotedName, nonQuotedName) => {
7332
7371
  if (quotedName) {
7333
7372
  return `${leadingSpaces}${this._scopeAnimationKeyframe(`${quote}${quotedName}${quote}`, scopeSelector, unscopedKeyframesSet)}`;
@@ -11117,6 +11156,12 @@ const CHAINABLE = new Set([
11117
11156
  Identifiers.twoWayListener,
11118
11157
  Identifiers.declareLet,
11119
11158
  ]);
11159
+ /**
11160
+ * Chaining results in repeated call expressions, causing a deep AST of receiver expressions. To prevent running out of
11161
+ * stack depth the maximum number of chained instructions is limited to this threshold, which has been selected
11162
+ * arbitrarily.
11163
+ */
11164
+ const MAX_CHAIN_LENGTH = 256;
11120
11165
  /**
11121
11166
  * Post-process a reified view compilation and convert sequential calls to chainable instructions
11122
11167
  * into chain calls.
@@ -11162,11 +11207,12 @@ function chainOperationsInList(opList) {
11162
11207
  }
11163
11208
  // This instruction can be chained. It can either be added on to the previous chain (if
11164
11209
  // compatible) or it can be the start of a new chain.
11165
- if (chain !== null && chain.instruction === instruction) {
11210
+ if (chain !== null && chain.instruction === instruction && chain.length < MAX_CHAIN_LENGTH) {
11166
11211
  // This instruction can be added onto the previous chain.
11167
11212
  const expression = chain.expression.callFn(op.statement.expr.args, op.statement.expr.sourceSpan, op.statement.expr.pure);
11168
11213
  chain.expression = expression;
11169
11214
  chain.op.statement = expression.toStmt();
11215
+ chain.length++;
11170
11216
  OpList.remove(op);
11171
11217
  }
11172
11218
  else {
@@ -11175,6 +11221,7 @@ function chainOperationsInList(opList) {
11175
11221
  op,
11176
11222
  instruction,
11177
11223
  expression: op.statement.expr,
11224
+ length: 1,
11178
11225
  };
11179
11226
  }
11180
11227
  }
@@ -12428,6 +12475,7 @@ function getScopeForView(view, parent) {
12428
12475
  kind: SemanticVariableKind.Identifier,
12429
12476
  name: null,
12430
12477
  identifier,
12478
+ local: false,
12431
12479
  });
12432
12480
  }
12433
12481
  for (const op of view.create) {
@@ -12448,6 +12496,7 @@ function getScopeForView(view, parent) {
12448
12496
  kind: SemanticVariableKind.Identifier,
12449
12497
  name: null,
12450
12498
  identifier: op.localRefs[offset].name,
12499
+ local: false,
12451
12500
  },
12452
12501
  });
12453
12502
  }
@@ -12460,6 +12509,7 @@ function getScopeForView(view, parent) {
12460
12509
  kind: SemanticVariableKind.Identifier,
12461
12510
  name: null,
12462
12511
  identifier: op.declaredName,
12512
+ local: false,
12463
12513
  },
12464
12514
  });
12465
12515
  break;
@@ -17704,8 +17754,7 @@ class _Tokenizer {
17704
17754
  this._preserveLineEndings = options.preserveLineEndings || false;
17705
17755
  this._i18nNormalizeLineEndingsInICUs = options.i18nNormalizeLineEndingsInICUs || false;
17706
17756
  this._tokenizeBlocks = options.tokenizeBlocks ?? true;
17707
- // TODO(crisbeto): eventually set this to true.
17708
- this._tokenizeLet = options.tokenizeLet || false;
17757
+ this._tokenizeLet = options.tokenizeLet ?? true;
17709
17758
  try {
17710
17759
  this._cursor.init();
17711
17760
  }
@@ -17903,8 +17952,11 @@ class _Tokenizer {
17903
17952
  const nameCursor = this._cursor.clone();
17904
17953
  let allowDigit = false;
17905
17954
  this._attemptCharCodeUntilFn((code) => {
17906
- // `@let` names can't start with a digit, but digits are valid anywhere else in the name.
17907
- if (isAsciiLetter(code) || code === $_ || (allowDigit && isDigit(code))) {
17955
+ if (isAsciiLetter(code) ||
17956
+ code === $$ ||
17957
+ code === $_ ||
17958
+ // `@let` names can't start with a digit, but digits are valid anywhere else in the name.
17959
+ (allowDigit && isDigit(code))) {
17908
17960
  allowDigit = true;
17909
17961
  return false;
17910
17962
  }
@@ -22584,6 +22636,8 @@ function processLexicalScope(unit, ops, savedView) {
22584
22636
  // Since variables are generated in each view for the entire lexical scope (including any
22585
22637
  // identifiers from parent templates) only local variables need be considered here.
22586
22638
  const scope = new Map();
22639
+ // Symbols defined within the current scope. They take precedence over ones defined outside.
22640
+ const localDefinitions = new Map();
22587
22641
  // First, step through the operations list and:
22588
22642
  // 1) build up the `scope` mapping
22589
22643
  // 2) recurse into any listener functions
@@ -22592,6 +22646,17 @@ function processLexicalScope(unit, ops, savedView) {
22592
22646
  case OpKind.Variable:
22593
22647
  switch (op.variable.kind) {
22594
22648
  case SemanticVariableKind.Identifier:
22649
+ if (op.variable.local) {
22650
+ if (localDefinitions.has(op.variable.identifier)) {
22651
+ continue;
22652
+ }
22653
+ localDefinitions.set(op.variable.identifier, op.xref);
22654
+ }
22655
+ else if (scope.has(op.variable.identifier)) {
22656
+ continue;
22657
+ }
22658
+ scope.set(op.variable.identifier, op.xref);
22659
+ break;
22595
22660
  case SemanticVariableKind.Alias:
22596
22661
  // This variable represents some kind of identifier which can be used in the template.
22597
22662
  if (scope.has(op.variable.identifier)) {
@@ -22630,7 +22695,10 @@ function processLexicalScope(unit, ops, savedView) {
22630
22695
  // `expr` is a read of a name within the lexical scope of this view.
22631
22696
  // Either that name is defined within the current view, or it represents a property from the
22632
22697
  // main component context.
22633
- if (scope.has(expr.name)) {
22698
+ if (localDefinitions.has(expr.name)) {
22699
+ return new ReadVariableExpr(localDefinitions.get(expr.name));
22700
+ }
22701
+ else if (scope.has(expr.name)) {
22634
22702
  // This was a defined variable in the current scope.
22635
22703
  return new ReadVariableExpr(scope.get(expr.name));
22636
22704
  }
@@ -23841,6 +23909,7 @@ function generateLocalLetReferences(job) {
23841
23909
  kind: SemanticVariableKind.Identifier,
23842
23910
  name: null,
23843
23911
  identifier: op.declaredName,
23912
+ local: true,
23844
23913
  };
23845
23914
  OpList.replace(op, createVariableOp(job.allocateXrefId(), variable, new StoreLetExpr(op.target, op.value, op.sourceSpan), VariableFlags.None));
23846
23915
  }
@@ -27287,7 +27356,7 @@ function parseTemplate(template, templateUrl, options = {}) {
27287
27356
  ...options,
27288
27357
  tokenizeExpansionForms: true,
27289
27358
  tokenizeBlocks: options.enableBlockSyntax ?? true,
27290
- tokenizeLet: options.enableLetSyntax ?? false,
27359
+ tokenizeLet: options.enableLetSyntax ?? true,
27291
27360
  });
27292
27361
  if (!options.alwaysAttemptHtmlToR3AstConversion &&
27293
27362
  parseResult.errors &&
@@ -28713,7 +28782,6 @@ function extractScopedNodeEntities(rootScope) {
28713
28782
  class ResourceLoader {
28714
28783
  }
28715
28784
 
28716
- let enableLetSyntax = false;
28717
28785
  class CompilerFacadeImpl {
28718
28786
  constructor(jitEvaluator = new JitEvaluator()) {
28719
28787
  this.jitEvaluator = jitEvaluator;
@@ -28961,6 +29029,25 @@ function convertDirectiveFacadeToMetadata(facade) {
28961
29029
  });
28962
29030
  }
28963
29031
  }
29032
+ const hostDirectives = facade.hostDirectives?.length
29033
+ ? facade.hostDirectives.map((hostDirective) => {
29034
+ return typeof hostDirective === 'function'
29035
+ ? {
29036
+ directive: wrapReference(hostDirective),
29037
+ inputs: null,
29038
+ outputs: null,
29039
+ isForwardReference: false,
29040
+ }
29041
+ : {
29042
+ directive: wrapReference(hostDirective.directive),
29043
+ isForwardReference: false,
29044
+ inputs: hostDirective.inputs ? parseMappingStringArray(hostDirective.inputs) : null,
29045
+ outputs: hostDirective.outputs
29046
+ ? parseMappingStringArray(hostDirective.outputs)
29047
+ : null,
29048
+ };
29049
+ })
29050
+ : null;
28964
29051
  return {
28965
29052
  ...facade,
28966
29053
  typeArgumentCount: 0,
@@ -28976,10 +29063,18 @@ function convertDirectiveFacadeToMetadata(facade) {
28976
29063
  providers: facade.providers != null ? new WrappedNodeExpr(facade.providers) : null,
28977
29064
  viewQueries: facade.viewQueries.map(convertToR3QueryMetadata),
28978
29065
  fullInheritance: false,
28979
- hostDirectives: convertHostDirectivesToMetadata(facade),
29066
+ hostDirectives,
28980
29067
  };
28981
29068
  }
28982
29069
  function convertDeclareDirectiveFacadeToMetadata(declaration, typeSourceSpan) {
29070
+ const hostDirectives = declaration.hostDirectives?.length
29071
+ ? declaration.hostDirectives.map((dir) => ({
29072
+ directive: wrapReference(dir.directive),
29073
+ isForwardReference: false,
29074
+ inputs: dir.inputs ? getHostDirectiveBindingMapping(dir.inputs) : null,
29075
+ outputs: dir.outputs ? getHostDirectiveBindingMapping(dir.outputs) : null,
29076
+ }))
29077
+ : null;
28983
29078
  return {
28984
29079
  name: declaration.type.name,
28985
29080
  type: wrapReference(declaration.type),
@@ -28999,7 +29094,7 @@ function convertDeclareDirectiveFacadeToMetadata(declaration, typeSourceSpan) {
28999
29094
  fullInheritance: false,
29000
29095
  isStandalone: declaration.isStandalone ?? false,
29001
29096
  isSignal: declaration.isSignal ?? false,
29002
- hostDirectives: convertHostDirectivesToMetadata(declaration),
29097
+ hostDirectives,
29003
29098
  };
29004
29099
  }
29005
29100
  function convertHostDeclarationToMetadata(host = {}) {
@@ -29013,25 +29108,17 @@ function convertHostDeclarationToMetadata(host = {}) {
29013
29108
  },
29014
29109
  };
29015
29110
  }
29016
- function convertHostDirectivesToMetadata(metadata) {
29017
- if (metadata.hostDirectives?.length) {
29018
- return metadata.hostDirectives.map((hostDirective) => {
29019
- return typeof hostDirective === 'function'
29020
- ? {
29021
- directive: wrapReference(hostDirective),
29022
- inputs: null,
29023
- outputs: null,
29024
- isForwardReference: false,
29025
- }
29026
- : {
29027
- directive: wrapReference(hostDirective.directive),
29028
- isForwardReference: false,
29029
- inputs: hostDirective.inputs ? parseMappingStringArray(hostDirective.inputs) : null,
29030
- outputs: hostDirective.outputs ? parseMappingStringArray(hostDirective.outputs) : null,
29031
- };
29032
- });
29111
+ /**
29112
+ * Parses a host directive mapping where each odd array key is the name of an input/output
29113
+ * and each even key is its public name, e.g. `['one', 'oneAlias', 'two', 'two']`.
29114
+ */
29115
+ function getHostDirectiveBindingMapping(array) {
29116
+ let result = null;
29117
+ for (let i = 1; i < array.length; i += 2) {
29118
+ result = result || {};
29119
+ result[array[i - 1]] = array[i];
29033
29120
  }
29034
- return null;
29121
+ return result;
29035
29122
  }
29036
29123
  function convertOpaqueValuesToExpressions(obj) {
29037
29124
  const result = {};
@@ -29125,7 +29212,6 @@ function parseJitTemplate(template, typeName, sourceMapUrl, preserveWhitespaces,
29125
29212
  const parsed = parseTemplate(template, sourceMapUrl, {
29126
29213
  preserveWhitespaces,
29127
29214
  interpolationConfig,
29128
- enableLetSyntax,
29129
29215
  });
29130
29216
  if (parsed.errors !== null) {
29131
29217
  const errors = parsed.errors.map((err) => err.toString()).join(', ');
@@ -29355,7 +29441,7 @@ function publishFacade(global) {
29355
29441
  * @description
29356
29442
  * Entry point for all public APIs of the compiler package.
29357
29443
  */
29358
- const VERSION = new Version('18.0.5');
29444
+ const VERSION = new Version('18.1.2');
29359
29445
 
29360
29446
  class CompilerConfig {
29361
29447
  constructor({ defaultEncapsulation = exports.ViewEncapsulation.Emulated, preserveWhitespaces, strictInjectionParameters, } = {}) {
@@ -30993,7 +31079,7 @@ const MINIMUM_PARTIAL_LINKER_DEFER_SUPPORT_VERSION = '18.0.0';
30993
31079
  function compileDeclareClassMetadata(metadata) {
30994
31080
  const definitionMap = new DefinitionMap();
30995
31081
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$5));
30996
- definitionMap.set('version', literal('18.0.5'));
31082
+ definitionMap.set('version', literal('18.1.2'));
30997
31083
  definitionMap.set('ngImport', importExpr(Identifiers.core));
30998
31084
  definitionMap.set('type', metadata.type);
30999
31085
  definitionMap.set('decorators', metadata.decorators);
@@ -31011,7 +31097,7 @@ function compileComponentDeclareClassMetadata(metadata, dependencies) {
31011
31097
  callbackReturnDefinitionMap.set('ctorParameters', metadata.ctorParameters ?? literal(null));
31012
31098
  callbackReturnDefinitionMap.set('propDecorators', metadata.propDecorators ?? literal(null));
31013
31099
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_DEFER_SUPPORT_VERSION));
31014
- definitionMap.set('version', literal('18.0.5'));
31100
+ definitionMap.set('version', literal('18.1.2'));
31015
31101
  definitionMap.set('ngImport', importExpr(Identifiers.core));
31016
31102
  definitionMap.set('type', metadata.type);
31017
31103
  definitionMap.set('resolveDeferredDeps', compileComponentMetadataAsyncResolver(dependencies));
@@ -31106,7 +31192,7 @@ function createDirectiveDefinitionMap(meta) {
31106
31192
  const definitionMap = new DefinitionMap();
31107
31193
  const minVersion = getMinimumVersionForPartialOutput(meta);
31108
31194
  definitionMap.set('minVersion', literal(minVersion));
31109
- definitionMap.set('version', literal('18.0.5'));
31195
+ definitionMap.set('version', literal('18.1.2'));
31110
31196
  // e.g. `type: MyDirective`
31111
31197
  definitionMap.set('type', meta.type.value);
31112
31198
  if (meta.isStandalone) {
@@ -31525,7 +31611,7 @@ const MINIMUM_PARTIAL_LINKER_VERSION$4 = '12.0.0';
31525
31611
  function compileDeclareFactoryFunction(meta) {
31526
31612
  const definitionMap = new DefinitionMap();
31527
31613
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$4));
31528
- definitionMap.set('version', literal('18.0.5'));
31614
+ definitionMap.set('version', literal('18.1.2'));
31529
31615
  definitionMap.set('ngImport', importExpr(Identifiers.core));
31530
31616
  definitionMap.set('type', meta.type.value);
31531
31617
  definitionMap.set('deps', compileDependencies(meta.deps));
@@ -31560,7 +31646,7 @@ function compileDeclareInjectableFromMetadata(meta) {
31560
31646
  function createInjectableDefinitionMap(meta) {
31561
31647
  const definitionMap = new DefinitionMap();
31562
31648
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$3));
31563
- definitionMap.set('version', literal('18.0.5'));
31649
+ definitionMap.set('version', literal('18.1.2'));
31564
31650
  definitionMap.set('ngImport', importExpr(Identifiers.core));
31565
31651
  definitionMap.set('type', meta.type.value);
31566
31652
  // Only generate providedIn property if it has a non-null value
@@ -31611,7 +31697,7 @@ function compileDeclareInjectorFromMetadata(meta) {
31611
31697
  function createInjectorDefinitionMap(meta) {
31612
31698
  const definitionMap = new DefinitionMap();
31613
31699
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$2));
31614
- definitionMap.set('version', literal('18.0.5'));
31700
+ definitionMap.set('version', literal('18.1.2'));
31615
31701
  definitionMap.set('ngImport', importExpr(Identifiers.core));
31616
31702
  definitionMap.set('type', meta.type.value);
31617
31703
  definitionMap.set('providers', meta.providers);
@@ -31644,7 +31730,7 @@ function createNgModuleDefinitionMap(meta) {
31644
31730
  throw new Error('Invalid path! Local compilation mode should not get into the partial compilation path');
31645
31731
  }
31646
31732
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$1));
31647
- definitionMap.set('version', literal('18.0.5'));
31733
+ definitionMap.set('version', literal('18.1.2'));
31648
31734
  definitionMap.set('ngImport', importExpr(Identifiers.core));
31649
31735
  definitionMap.set('type', meta.type.value);
31650
31736
  // We only generate the keys in the metadata if the arrays contain values.
@@ -31695,7 +31781,7 @@ function compileDeclarePipeFromMetadata(meta) {
31695
31781
  function createPipeDefinitionMap(meta) {
31696
31782
  const definitionMap = new DefinitionMap();
31697
31783
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION));
31698
- definitionMap.set('version', literal('18.0.5'));
31784
+ definitionMap.set('version', literal('18.1.2'));
31699
31785
  definitionMap.set('ngImport', importExpr(Identifiers.core));
31700
31786
  // e.g. `type: MyPipe`
31701
31787
  definitionMap.set('type', meta.type.value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-eslint/bundled-angular-compiler",
3
- "version": "18.1.1-alpha.0",
3
+ "version": "18.1.1-alpha.1",
4
4
  "description": "A CJS bundled version of @angular/compiler",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",