jsii 6.0.23 → 6.0.25-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/assembler.js CHANGED
@@ -983,11 +983,18 @@ class Assembler {
983
983
  // base classes ("extends foo")
984
984
  // Crawl up the inheritance tree if the current base type is not exported, so we identify the type(s) to be
985
985
  // erased, and identify the closest exported base class, should there be one.
986
- while (base && this._isPrivateOrInternal(base.symbol)) {
986
+ while (base?.symbol && this._isPrivateOrInternal(base.symbol)) {
987
987
  LOG.debug(`Base class of ${chalk_1.default.green(jsiiType.fqn)} named ${chalk_1.default.green(base.symbol.name)} is not exported, erasing it...`);
988
988
  erasedBases.push(base);
989
989
  base = (base.getBaseTypes() ?? [])[0];
990
990
  }
991
+ if (base && !base.symbol) {
992
+ const extendsClause = classDeclaration.heritageClauses?.find((clause) => clause.token === ts.SyntaxKind.ExtendsKeyword);
993
+ if (extendsClause) {
994
+ this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_3004_INVALID_SUPERTYPE.create(extendsClause.types[0], extendsClause));
995
+ }
996
+ continue;
997
+ }
991
998
  if (!base || isInternalSymbol(base.symbol)) {
992
999
  // There is no exported base class to be found, pretend this class has no base class.
993
1000
  continue;
@@ -1498,19 +1505,29 @@ class Assembler {
1498
1505
  }
1499
1506
  }
1500
1507
  });
1501
- // Check that no interface declares a member that's already declared
1502
- // in a base type (not allowed in C#).
1503
- const names = memberNames(jsiiType);
1508
+ // Check that any member an interface re-declares from a base type keeps
1509
+ // the exact same shape. Re-declaring is useful to change documentation
1510
+ // (e.g. a different `@default`), but C# interfaces cannot narrow a member's
1511
+ // type (no covariance), so anything else is rejected.
1512
+ const members = typeMembers(jsiiType);
1504
1513
  const checkNoIntersection = (...bases) => {
1505
1514
  for (const base of bases) {
1506
1515
  if (!spec.isInterfaceType(base)) {
1507
1516
  continue;
1508
1517
  }
1509
- const baseMembers = memberNames(base);
1510
- for (const memberName of names) {
1511
- if (baseMembers.includes(memberName)) {
1512
- this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_5015_REDECLARED_INTERFACE_MEMBER.create(type.symbol.valueDeclaration ?? type.symbol.declarations?.[0], memberName, jsiiType));
1518
+ const baseMembers = typeMembers(base);
1519
+ for (const [memberName, member] of Object.entries(members)) {
1520
+ const baseMember = baseMembers[memberName];
1521
+ if (memberName === '' || baseMember == null) {
1522
+ continue;
1513
1523
  }
1524
+ if (isIdenticalRedeclaration(member, baseMember)) {
1525
+ // Bases are visited nearest-first, so the closest one wins.
1526
+ member.overrides ??= base.fqn;
1527
+ this.usedFeatures.add('interface-member-doc-overrides');
1528
+ continue;
1529
+ }
1530
+ this._diagnostics.push(jsii_diagnostic_1.JsiiDiagnostic.JSII_5015_REDECLARED_INTERFACE_MEMBER.create(type.symbol.valueDeclaration ?? type.symbol.declarations?.[0], memberName, jsiiType));
1514
1531
  }
1515
1532
  // Recurse upwards
1516
1533
  this._deferUntilTypesAvailable(fqn, base.interfaces ?? [], type.symbol.valueDeclaration, checkNoIntersection);
@@ -2306,12 +2323,29 @@ function apply(x, fn) {
2306
2323
  return x !== undefined ? fn(x) : undefined;
2307
2324
  }
2308
2325
  /**
2309
- * Return all members names of a JSII interface type
2310
- *
2311
- * Returns empty string for a non-interface type.
2326
+ * Whether `member` re-declares `baseMember` with exactly the same shape, so
2327
+ * that only its documentation differs. Such re-declarations can be represented
2328
+ * in all target languages (C# needs the `new` modifier).
2312
2329
  */
2313
- function memberNames(jsiiType) {
2314
- return Object.keys(typeMembers(jsiiType)).filter((n) => n !== '');
2330
+ function isIdenticalRedeclaration(member, baseMember) {
2331
+ if (spec.isMethod(member) && spec.isMethod(baseMember)) {
2332
+ const params = member.parameters ?? [];
2333
+ const baseParams = baseMember.parameters ?? [];
2334
+ return (!!member.static === !!baseMember.static &&
2335
+ !!member.async === !!baseMember.async &&
2336
+ (0, es6_1.default)(member.returns, baseMember.returns) &&
2337
+ params.length === baseParams.length &&
2338
+ params.every((param, i) => (0, es6_1.default)(param.type, baseParams[i].type) &&
2339
+ !!param.optional === !!baseParams[i].optional &&
2340
+ !!param.variadic === !!baseParams[i].variadic));
2341
+ }
2342
+ if (!spec.isMethod(member) && !spec.isMethod(baseMember)) {
2343
+ return (!!member.static === !!baseMember.static &&
2344
+ !!member.optional === !!baseMember.optional &&
2345
+ !!member.immutable === !!baseMember.immutable &&
2346
+ (0, es6_1.default)(member.type, baseMember.type));
2347
+ }
2348
+ return false;
2315
2349
  }
2316
2350
  function typeMembers(jsiiType) {
2317
2351
  const ret = {};