@angular/language-service 12.2.3 → 12.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bundles/ivy.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v12.2.3
2
+ * @license Angular v12.2.4
3
3
  * Copyright Google LLC All Rights Reserved.
4
4
  * License: MIT
5
5
  */
@@ -19938,7 +19938,7 @@ define(['exports', 'typescript/lib/tsserverlibrary', 'os', 'typescript', 'fs', '
19938
19938
  * Use of this source code is governed by an MIT-style license that can be
19939
19939
  * found in the LICENSE file at https://angular.io/license
19940
19940
  */
19941
- const VERSION$1 = new Version('12.2.3');
19941
+ const VERSION$1 = new Version('12.2.4');
19942
19942
 
19943
19943
  /**
19944
19944
  * @license
@@ -20577,7 +20577,7 @@ define(['exports', 'typescript/lib/tsserverlibrary', 'os', 'typescript', 'fs', '
20577
20577
  function compileDeclareClassMetadata(metadata) {
20578
20578
  const definitionMap = new DefinitionMap();
20579
20579
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION));
20580
- definitionMap.set('version', literal('12.2.3'));
20580
+ definitionMap.set('version', literal('12.2.4'));
20581
20581
  definitionMap.set('ngImport', importExpr(Identifiers.core));
20582
20582
  definitionMap.set('type', metadata.type);
20583
20583
  definitionMap.set('decorators', metadata.decorators);
@@ -20617,7 +20617,7 @@ define(['exports', 'typescript/lib/tsserverlibrary', 'os', 'typescript', 'fs', '
20617
20617
  function createDirectiveDefinitionMap(meta) {
20618
20618
  const definitionMap = new DefinitionMap();
20619
20619
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$1));
20620
- definitionMap.set('version', literal('12.2.3'));
20620
+ definitionMap.set('version', literal('12.2.4'));
20621
20621
  // e.g. `type: MyDirective`
20622
20622
  definitionMap.set('type', meta.internalType);
20623
20623
  // e.g. `selector: 'some-dir'`
@@ -20834,7 +20834,7 @@ define(['exports', 'typescript/lib/tsserverlibrary', 'os', 'typescript', 'fs', '
20834
20834
  function compileDeclareFactoryFunction(meta) {
20835
20835
  const definitionMap = new DefinitionMap();
20836
20836
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$2));
20837
- definitionMap.set('version', literal('12.2.3'));
20837
+ definitionMap.set('version', literal('12.2.4'));
20838
20838
  definitionMap.set('ngImport', importExpr(Identifiers.core));
20839
20839
  definitionMap.set('type', meta.internalType);
20840
20840
  definitionMap.set('deps', compileDependencies(meta.deps));
@@ -20876,7 +20876,7 @@ define(['exports', 'typescript/lib/tsserverlibrary', 'os', 'typescript', 'fs', '
20876
20876
  function createInjectableDefinitionMap(meta) {
20877
20877
  const definitionMap = new DefinitionMap();
20878
20878
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$3));
20879
- definitionMap.set('version', literal('12.2.3'));
20879
+ definitionMap.set('version', literal('12.2.4'));
20880
20880
  definitionMap.set('ngImport', importExpr(Identifiers.core));
20881
20881
  definitionMap.set('type', meta.internalType);
20882
20882
  // Only generate providedIn property if it has a non-null value
@@ -20955,7 +20955,7 @@ define(['exports', 'typescript/lib/tsserverlibrary', 'os', 'typescript', 'fs', '
20955
20955
  function createInjectorDefinitionMap(meta) {
20956
20956
  const definitionMap = new DefinitionMap();
20957
20957
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$4));
20958
- definitionMap.set('version', literal('12.2.3'));
20958
+ definitionMap.set('version', literal('12.2.4'));
20959
20959
  definitionMap.set('ngImport', importExpr(Identifiers.core));
20960
20960
  definitionMap.set('type', meta.internalType);
20961
20961
  definitionMap.set('providers', meta.providers);
@@ -20992,7 +20992,7 @@ define(['exports', 'typescript/lib/tsserverlibrary', 'os', 'typescript', 'fs', '
20992
20992
  function createNgModuleDefinitionMap(meta) {
20993
20993
  const definitionMap = new DefinitionMap();
20994
20994
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$5));
20995
- definitionMap.set('version', literal('12.2.3'));
20995
+ definitionMap.set('version', literal('12.2.4'));
20996
20996
  definitionMap.set('ngImport', importExpr(Identifiers.core));
20997
20997
  definitionMap.set('type', meta.internalType);
20998
20998
  // We only generate the keys in the metadata if the arrays contain values.
@@ -21050,7 +21050,7 @@ define(['exports', 'typescript/lib/tsserverlibrary', 'os', 'typescript', 'fs', '
21050
21050
  function createPipeDefinitionMap(meta) {
21051
21051
  const definitionMap = new DefinitionMap();
21052
21052
  definitionMap.set('minVersion', literal(MINIMUM_PARTIAL_LINKER_VERSION$6));
21053
- definitionMap.set('version', literal('12.2.3'));
21053
+ definitionMap.set('version', literal('12.2.4'));
21054
21054
  definitionMap.set('ngImport', importExpr(Identifiers.core));
21055
21055
  // e.g. `type: MyPipe`
21056
21056
  definitionMap.set('type', meta.internalType);
@@ -21082,7 +21082,7 @@ define(['exports', 'typescript/lib/tsserverlibrary', 'os', 'typescript', 'fs', '
21082
21082
  * Use of this source code is governed by an MIT-style license that can be
21083
21083
  * found in the LICENSE file at https://angular.io/license
21084
21084
  */
21085
- const VERSION$2 = new Version('12.2.3');
21085
+ const VERSION$2 = new Version('12.2.4');
21086
21086
 
21087
21087
  /**
21088
21088
  * @license
@@ -21294,6 +21294,15 @@ define(['exports', 'typescript/lib/tsserverlibrary', 'os', 'typescript', 'fs', '
21294
21294
  * ```
21295
21295
  */
21296
21296
  ErrorCode[ErrorCode["INVALID_BANANA_IN_BOX"] = 8101] = "INVALID_BANANA_IN_BOX";
21297
+ /**
21298
+ * The left side of a nullish coalescing operation is not nullable.
21299
+ *
21300
+ * ```
21301
+ * {{ foo ?? bar }}
21302
+ * ```
21303
+ * When the type of foo doesn't include `null` or `undefined`.
21304
+ */
21305
+ ErrorCode[ErrorCode["NULLISH_COALESCING_NOT_NULLABLE"] = 8102] = "NULLISH_COALESCING_NOT_NULLABLE";
21297
21306
  /**
21298
21307
  * The template type-checking engine would need to generate an inline type check block for a
21299
21308
  * component, but the current type-checking environment doesn't support it.
@@ -40125,12 +40134,11 @@ Either add the @Injectable() decorator to '${provider.node.name
40125
40134
  */
40126
40135
  class ExtendedTemplateCheckerImpl {
40127
40136
  constructor(templateTypeChecker, typeChecker, templateChecks) {
40128
- this.templateTypeChecker = templateTypeChecker;
40129
- this.typeChecker = typeChecker;
40130
40137
  this.templateChecks = templateChecks;
40138
+ this.ctx = { templateTypeChecker: templateTypeChecker, typeChecker: typeChecker };
40131
40139
  }
40132
40140
  getDiagnosticsForComponent(component) {
40133
- const template = this.templateTypeChecker.getTemplate(component);
40141
+ const template = this.ctx.templateTypeChecker.getTemplate(component);
40134
40142
  // Skip checks if component has no template. This can happen if the user writes a
40135
40143
  // `@Component()` but doesn't add the template, could happen in the language service
40136
40144
  // when users are in the middle of typing code.
@@ -40138,66 +40146,100 @@ Either add the @Injectable() decorator to '${provider.node.name
40138
40146
  return [];
40139
40147
  }
40140
40148
  const diagnostics = [];
40141
- const ctx = {
40142
- templateTypeChecker: this.templateTypeChecker,
40143
- typeChecker: this.typeChecker,
40144
- component
40145
- };
40146
40149
  for (const check of this.templateChecks) {
40147
- diagnostics.push(...deduplicateDiagnostics(check.run(ctx, template)));
40150
+ diagnostics.push(...check.run(this.ctx, component, template));
40148
40151
  }
40149
40152
  return diagnostics;
40150
40153
  }
40151
40154
  }
40152
- // Filter out duplicated diagnostics, this is possible due to the way the compiler
40153
- // handles desugaring and produces `AST`s. Ex.
40154
- //
40155
- // ```
40156
- // <div *ngIf="true" (foo)="bar">test</div>
40157
- // ```
40158
- //
40159
- // Would result in the following AST:
40160
- //
40161
- // ```
40162
- // Template {
40163
- // outputs: [
40164
- // BoundEvent {
40165
- // name: 'foo',
40166
- // /.../
40167
- // }
40168
- // ],
40169
- // children: [
40170
- // Element {
40171
- // outputs: [
40172
- // BoundEvent {
40173
- // name: 'foo',
40174
- // /.../
40175
- // }
40176
- // ]
40177
- // }
40178
- // ],
40179
- // /.../
40180
- // }
40181
- // ```
40182
- //
40183
- // In this case a duplicated diagnostic could be generated for the output `foo`.
40184
- // TODO(danieltrevino): handle duplicated diagnostics when they are being generated
40185
- // to avoid extra work (could be directly in the visitor).
40186
- // https://github.com/angular/angular/pull/42984#discussion_r684823926
40187
- function deduplicateDiagnostics(diagnostics) {
40188
- const result = [];
40189
- for (const newDiag of diagnostics) {
40190
- const isDuplicateDiag = result.some(existingDiag => areDiagnosticsEqual(newDiag, existingDiag));
40191
- if (!isDuplicateDiag) {
40192
- result.push(newDiag);
40193
- }
40155
+
40156
+ /**
40157
+ * @license
40158
+ * Copyright Google LLC All Rights Reserved.
40159
+ *
40160
+ * Use of this source code is governed by an MIT-style license that can be
40161
+ * found in the LICENSE file at https://angular.io/license
40162
+ */
40163
+ /**
40164
+ * This abstract class provides a base implementation for the run method.
40165
+ */
40166
+ class TemplateCheckWithVisitor {
40167
+ /**
40168
+ * Base implementation for run function, visits all nodes in template and calls
40169
+ * `visitNode()` for each one.
40170
+ */
40171
+ run(ctx, component, template) {
40172
+ const visitor = new TemplateVisitor$1(ctx, component, this);
40173
+ return visitor.getDiagnostics(template);
40194
40174
  }
40195
- return result;
40196
40175
  }
40197
- function areDiagnosticsEqual(first, second) {
40198
- var _a, _b;
40199
- return ((_a = first.file) === null || _a === void 0 ? void 0 : _a.fileName) === ((_b = second.file) === null || _b === void 0 ? void 0 : _b.fileName) && first.start === second.start &&
40200
- first.length === second.length && first.code === second.code;
40176
+ /**
40177
+ * Visits all nodes in a template (TmplAstNode and AST) and calls `visitNode` for each one.
40178
+ */
40179
+ class TemplateVisitor$1 extends RecursiveAstVisitor {
40180
+ constructor(ctx, component, check) {
40181
+ super();
40182
+ this.ctx = ctx;
40183
+ this.component = component;
40184
+ this.check = check;
40185
+ this.diagnostics = [];
40186
+ }
40187
+ visit(node, context) {
40188
+ this.diagnostics.push(...this.check.visitNode(this.ctx, this.component, node));
40189
+ node.visit(this);
40190
+ }
40191
+ visitAllNodes(nodes) {
40192
+ for (const node of nodes) {
40193
+ this.visit(node);
40194
+ }
40195
+ }
40196
+ visitAst(ast) {
40197
+ if (ast instanceof ASTWithSource) {
40198
+ ast = ast.ast;
40199
+ }
40200
+ this.visit(ast);
40201
+ }
40202
+ visitElement(element) {
40203
+ this.visitAllNodes(element.attributes);
40204
+ this.visitAllNodes(element.inputs);
40205
+ this.visitAllNodes(element.outputs);
40206
+ this.visitAllNodes(element.references);
40207
+ this.visitAllNodes(element.children);
40208
+ }
40209
+ visitTemplate(template) {
40210
+ this.visitAllNodes(template.attributes);
40211
+ if (template.tagName === 'ng-template') {
40212
+ // Only visit input/outputs/templateAttrs if this isn't an inline template node
40213
+ // generated for a structural directive (like `<div *ngIf></div>`). These nodes
40214
+ // would be visited when the underlying element of an inline template node is processed.
40215
+ this.visitAllNodes(template.inputs);
40216
+ this.visitAllNodes(template.outputs);
40217
+ this.visitAllNodes(template.templateAttrs);
40218
+ }
40219
+ this.visitAllNodes(template.variables);
40220
+ this.visitAllNodes(template.references);
40221
+ this.visitAllNodes(template.children);
40222
+ }
40223
+ visitContent(content) { }
40224
+ visitVariable(variable) { }
40225
+ visitReference(reference) { }
40226
+ visitTextAttribute(attribute) { }
40227
+ visitBoundAttribute(attribute) {
40228
+ this.visitAst(attribute.value);
40229
+ }
40230
+ visitBoundEvent(attribute) {
40231
+ this.visitAst(attribute.handler);
40232
+ }
40233
+ visitText(text) { }
40234
+ visitBoundText(text) {
40235
+ this.visitAst(text.value);
40236
+ }
40237
+ visitIcu(icu) { }
40238
+ getDiagnostics(template) {
40239
+ this.diagnostics = [];
40240
+ this.visitAllNodes(template);
40241
+ return this.diagnostics;
40242
+ }
40201
40243
  }
40202
40244
 
40203
40245
  /**
@@ -40212,42 +40254,63 @@ Either add the @Injectable() decorator to '${provider.node.name
40212
40254
  * Parentheses should be inside the brackets "[()]".
40213
40255
  * Will return diagnostic information when "([])" is found.
40214
40256
  */
40215
- class InvalidBananaInBoxCheck {
40257
+ class InvalidBananaInBoxCheck extends TemplateCheckWithVisitor {
40216
40258
  constructor() {
40217
- this.code = 8101;
40259
+ super(...arguments);
40260
+ this.code = ErrorCode.INVALID_BANANA_IN_BOX;
40218
40261
  }
40219
- run(ctx, template) {
40220
- const visitor = new BananaVisitor(ctx);
40221
- return visitor.getDiagnostics(template);
40262
+ visitNode(ctx, component, node) {
40263
+ if (!(node instanceof BoundEvent))
40264
+ return [];
40265
+ const name = node.name;
40266
+ if (!name.startsWith('[') || !name.endsWith(']'))
40267
+ return [];
40268
+ const boundSyntax = node.sourceSpan.toString();
40269
+ const expectedBoundSyntax = boundSyntax.replace(`(${name})`, `[(${name.slice(1, -1)})]`);
40270
+ const diagnostic = ctx.templateTypeChecker.makeTemplateDiagnostic(component, node.sourceSpan, ts$1.DiagnosticCategory.Warning, ErrorCode.INVALID_BANANA_IN_BOX, `In the two-way binding syntax the parentheses should be inside the brackets, ex. '${expectedBoundSyntax}'.
40271
+ Find more at https://angular.io/guide/two-way-binding`);
40272
+ return [diagnostic];
40222
40273
  }
40223
40274
  }
40224
- class BananaVisitor extends RecursiveVisitor {
40225
- constructor(ctx) {
40226
- super();
40227
- this.ctx = ctx;
40228
- this.diagnostics = [];
40275
+
40276
+ /**
40277
+ * @license
40278
+ * Copyright Google LLC All Rights Reserved.
40279
+ *
40280
+ * Use of this source code is governed by an MIT-style license that can be
40281
+ * found in the LICENSE file at https://angular.io/license
40282
+ */
40283
+ /**
40284
+ * Ensures the left side of a nullish coalescing operation is nullable.
40285
+ * Returns diagnostics for the cases where the operator is useless.
40286
+ * This check should only be use if `strictNullChecks` is enabled,
40287
+ * otherwise it would produce inaccurate results.
40288
+ */
40289
+ class NullishCoalescingNotNullableCheck extends TemplateCheckWithVisitor {
40290
+ constructor() {
40291
+ super(...arguments);
40292
+ this.code = ErrorCode.NULLISH_COALESCING_NOT_NULLABLE;
40229
40293
  }
40230
- /**
40231
- * Check for outputs with names surrounded in brackets "[]".
40232
- * The syntax '([foo])="bar"' would be interpreted as an @Output()
40233
- * with name '[foo]'. Just like '(foo)="bar"' would have the name 'foo'.
40234
- * Generate diagnostic information for the cases found.
40235
- */
40236
- visitBoundEvent(boundEvent) {
40237
- const name = boundEvent.name;
40238
- if (name.startsWith('[') && name.endsWith(']')) {
40239
- const boundSyntax = boundEvent.sourceSpan.toString();
40240
- const expectedBoundSyntax = boundSyntax.replace(`(${name})`, `[(${name.slice(1, -1)})]`);
40241
- this.diagnostics.push(this.ctx.templateTypeChecker.makeTemplateDiagnostic(this.ctx.component, boundEvent.sourceSpan, ts$1.DiagnosticCategory.Warning, ErrorCode.INVALID_BANANA_IN_BOX, `In the two-way binding syntax the parentheses should be inside the brackets, ex. '${expectedBoundSyntax}'.
40242
- Find more at https://angular.io/guide/two-way-binding`));
40294
+ visitNode(ctx, component, node) {
40295
+ if (!(node instanceof Binary) || node.operation !== '??')
40296
+ return [];
40297
+ const symbolLeft = ctx.templateTypeChecker.getSymbolOfNode(node.left, component);
40298
+ if (symbolLeft.kind !== SymbolKind.Expression) {
40299
+ return [];
40243
40300
  }
40244
- }
40245
- getDiagnostics(template) {
40246
- this.diagnostics = [];
40247
- for (const node of template) {
40248
- node.visit(this);
40301
+ const typeLeft = symbolLeft.tsType;
40302
+ // If the left operand's type is different from its non-nullable self, then it must
40303
+ // contain a null or undefined so this nullish coalescing operator is useful. No diagnostic to
40304
+ // report.
40305
+ if (typeLeft.getNonNullableType() !== typeLeft)
40306
+ return [];
40307
+ const symbol = ctx.templateTypeChecker.getSymbolOfNode(node, component);
40308
+ if (symbol.kind !== SymbolKind.Expression) {
40309
+ return [];
40249
40310
  }
40250
- return this.diagnostics;
40311
+ const span = ctx.templateTypeChecker.getTemplateMappingAtShimLocation(symbol.shimLocation).span;
40312
+ const diagnostic = ctx.templateTypeChecker.makeTemplateDiagnostic(component, span, ts$1.DiagnosticCategory.Warning, ErrorCode.NULLISH_COALESCING_NOT_NULLABLE, `The left side of this nullish coalescing operation does not include 'null' or 'undefined' in its type, therefore the '??' operator can be safely removed.`);
40313
+ return [diagnostic];
40251
40314
  }
40252
40315
  }
40253
40316
 
@@ -41034,6 +41097,9 @@ Either add the @Injectable() decorator to '${provider.node.name
41034
41097
  });
41035
41098
  const templateTypeChecker = new TemplateTypeCheckerImpl(this.inputProgram, notifyingDriver, traitCompiler, this.getTypeCheckingConfig(), refEmitter, reflector, this.adapter, this.incrementalCompilation, scopeRegistry, typeCheckScopeRegistry, this.delegatingPerfRecorder);
41036
41099
  const templateChecks = [new InvalidBananaInBoxCheck()];
41100
+ if (this.options.strictNullChecks) {
41101
+ templateChecks.push(new NullishCoalescingNotNullableCheck());
41102
+ }
41037
41103
  const extendedTemplateChecker = new ExtendedTemplateCheckerImpl(templateTypeChecker, checker, templateChecks);
41038
41104
  return {
41039
41105
  isCore,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v12.2.3
2
+ * @license Angular v12.2.4
3
3
  * Copyright Google LLC All Rights Reserved.
4
4
  * License: MIT
5
5
  */
@@ -21475,7 +21475,7 @@ define(['exports', 'typescript/lib/tsserverlibrary', 'typescript', 'path'], func
21475
21475
  * Use of this source code is governed by an MIT-style license that can be
21476
21476
  * found in the LICENSE file at https://angular.io/license
21477
21477
  */
21478
- const VERSION$1 = new Version('12.2.3');
21478
+ const VERSION$1 = new Version('12.2.4');
21479
21479
 
21480
21480
  /**
21481
21481
  * @license
@@ -37554,7 +37554,7 @@ define(['exports', 'typescript/lib/tsserverlibrary', 'typescript', 'path'], func
37554
37554
  /**
37555
37555
  * @publicApi
37556
37556
  */
37557
- const VERSION$2 = new Version$1('12.2.3');
37557
+ const VERSION$2 = new Version$1('12.2.4');
37558
37558
 
37559
37559
  /**
37560
37560
  * @license
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular/language-service",
3
- "version": "12.2.3",
3
+ "version": "12.2.4",
4
4
  "description": "Angular - language services",
5
5
  "main": "./index.js",
6
6
  "typings": "./index.d.ts",