jsii 5.9.59 → 5.9.60

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/lib/assembler.js CHANGED
@@ -935,11 +935,18 @@ class Assembler {
935
935
  // base classes ("extends foo")
936
936
  // Crawl up the inheritance tree if the current base type is not exported, so we identify the type(s) to be
937
937
  // erased, and identify the closest exported base class, should there be one.
938
- while (base && this._isPrivateOrInternal(base.symbol)) {
938
+ while (base?.symbol && this._isPrivateOrInternal(base.symbol)) {
939
939
  LOG.debug(`Base class of ${chalk.green(jsiiType.fqn)} named ${chalk.green(base.symbol.name)} is not exported, erasing it...`);
940
940
  erasedBases.push(base);
941
941
  base = (base.getBaseTypes() ?? [])[0];
942
942
  }
943
+ if (base && !base.symbol) {
944
+ const extendsClause = classDeclaration.heritageClauses?.find((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword);
945
+ if (extendsClause) {
946
+ this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_3004_INVALID_SUPERTYPE.create(extendsClause.types[0], extendsClause));
947
+ }
948
+ continue;
949
+ }
943
950
  if (!base || isInternalSymbol(base.symbol)) {
944
951
  // There is no exported base class to be found, pretend this class has no base class.
945
952
  continue;
@@ -1450,19 +1457,29 @@ class Assembler {
1450
1457
  }
1451
1458
  }
1452
1459
  });
1453
- // Check that no interface declares a member that's already declared
1454
- // in a base type (not allowed in C#).
1455
- const names = memberNames(jsiiType);
1460
+ // Check that any member an interface re-declares from a base type keeps
1461
+ // the exact same shape. Re-declaring is useful to change documentation
1462
+ // (e.g. a different `@default`), but C# interfaces cannot narrow a member's
1463
+ // type (no covariance), so anything else is rejected.
1464
+ const members = typeMembers(jsiiType);
1456
1465
  const checkNoIntersection = (...bases) => {
1457
1466
  for (const base of bases) {
1458
1467
  if (!spec.isInterfaceType(base)) {
1459
1468
  continue;
1460
1469
  }
1461
- const baseMembers = memberNames(base);
1462
- for (const memberName of names) {
1463
- if (baseMembers.includes(memberName)) {
1464
- this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_5015_REDECLARED_INTERFACE_MEMBER.create(type.symbol.valueDeclaration ?? type.symbol.declarations?.[0], memberName, jsiiType));
1470
+ const baseMembers = typeMembers(base);
1471
+ for (const [memberName, member] of Object.entries(members)) {
1472
+ const baseMember = baseMembers[memberName];
1473
+ if (memberName === '' || baseMember == null) {
1474
+ continue;
1465
1475
  }
1476
+ if (isIdenticalRedeclaration(member, baseMember)) {
1477
+ // Bases are visited nearest-first, so the closest one wins.
1478
+ member.overrides ?? (member.overrides = base.fqn);
1479
+ this.usedFeatures.add('interface-member-doc-overrides');
1480
+ continue;
1481
+ }
1482
+ this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_5015_REDECLARED_INTERFACE_MEMBER.create(type.symbol.valueDeclaration ?? type.symbol.declarations?.[0], memberName, jsiiType));
1466
1483
  }
1467
1484
  // Recurse upwards
1468
1485
  this._deferUntilTypesAvailable(fqn, base.interfaces ?? [], type.symbol.valueDeclaration, checkNoIntersection);
@@ -2258,12 +2275,29 @@ function apply(x, fn) {
2258
2275
  return x !== undefined ? fn(x) : undefined;
2259
2276
  }
2260
2277
  /**
2261
- * Return all members names of a JSII interface type
2262
- *
2263
- * Returns empty string for a non-interface type.
2278
+ * Whether `member` re-declares `baseMember` with exactly the same shape, so
2279
+ * that only its documentation differs. Such re-declarations can be represented
2280
+ * in all target languages (C# needs the `new` modifier).
2264
2281
  */
2265
- function memberNames(jsiiType) {
2266
- return Object.keys(typeMembers(jsiiType)).filter((n) => n !== '');
2282
+ function isIdenticalRedeclaration(member, baseMember) {
2283
+ if (spec.isMethod(member) && spec.isMethod(baseMember)) {
2284
+ const params = member.parameters ?? [];
2285
+ const baseParams = baseMember.parameters ?? [];
2286
+ return (!!member.static === !!baseMember.static &&
2287
+ !!member.async === !!baseMember.async &&
2288
+ deepEqual(member.returns, baseMember.returns) &&
2289
+ params.length === baseParams.length &&
2290
+ params.every((param, i) => deepEqual(param.type, baseParams[i].type) &&
2291
+ !!param.optional === !!baseParams[i].optional &&
2292
+ !!param.variadic === !!baseParams[i].variadic));
2293
+ }
2294
+ if (!spec.isMethod(member) && !spec.isMethod(baseMember)) {
2295
+ return (!!member.static === !!baseMember.static &&
2296
+ !!member.optional === !!baseMember.optional &&
2297
+ !!member.immutable === !!baseMember.immutable &&
2298
+ deepEqual(member.type, baseMember.type));
2299
+ }
2300
+ return false;
2267
2301
  }
2268
2302
  function typeMembers(jsiiType) {
2269
2303
  const ret = {};