jsii 7.1.0-dev.3 → 7.1.0-dev.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.
@@ -170,6 +170,12 @@ export declare class Assembler {
170
170
  * violations) is not performed here.
171
171
  */
172
172
  private _finalizeInheritance;
173
+ /**
174
+ * Whether an interface re-declares an inherited member with exactly the same
175
+ * shape, so that only its documentation differs. `overrides` already points
176
+ * at the nearest base interface that declares the member.
177
+ */
178
+ private _redeclaresInterfaceMember;
173
179
  /**
174
180
  * Declaration rank of a type FQN for union ordering: own types by (program file
175
181
  * order, position in file); types of dependencies before them, by name.
package/lib/assembler.js CHANGED
@@ -401,7 +401,14 @@ class Assembler {
401
401
  }
402
402
  commentLines.push(line);
403
403
  }
404
- const rawComment = commentLines.join('\n');
404
+ // TypeScript ends a `{@link}` at a newline and leaks the rest of its label as text, so
405
+ // put a label that continues on the next JSDoc line back on one line. The TypeScript 7
406
+ // rendering of such a link is broken, so the raw comment is used instead.
407
+ let rejoined = false;
408
+ const rawComment = commentLines.join('\n').replace(/\{@(?:link|linkcode|linkplain)\b[^}]*\n[^}]*\}/g, (link) => {
409
+ rejoined = true;
410
+ return link.replace(/\s*\n\s*/g, ' ').replace(/\s+\}$/, '}');
411
+ });
405
412
  if (!/\{@link(code|plain)?\b/.test(rawComment)) {
406
413
  return comment;
407
414
  }
@@ -409,7 +416,7 @@ class Assembler {
409
416
  let result = comment;
410
417
  let cursor = 0;
411
418
  let rawRendered = rawComment;
412
- let allFound = true;
419
+ let allFound = !rejoined;
413
420
  let rawCursor = 0;
414
421
  for (const m of rawComment.matchAll(linkRe)) {
415
422
  // Anchor the search on the (end of the) raw text preceding this link, so a
@@ -442,8 +449,10 @@ class Assembler {
442
449
  classic = `{@${kind} ${name}${rest}}`;
443
450
  }
444
451
  else {
452
+ // The classic parser skips the whitespace between a link name and its text.
453
+ const unresolvedRest = suffix === 0 ? skipSeparatorFromLinkText(text.replace(/^\s+/, '')) : rest;
445
454
  const separator = suffix === 0 || (text.charCodeAt(suffix) === 124 && !name.endsWith(' ')) ? ' ' : '';
446
- classic = `{@${kind} ${name}${separator}${rest}}`;
455
+ classic = `{@${kind} ${name}${separator}${unresolvedRest}}`;
447
456
  }
448
457
  modern = `${name0.replace(/#/g, '.')}${text}`;
449
458
  }
@@ -833,7 +842,9 @@ class Assembler {
833
842
  if (!isModuleFile) {
834
843
  return result;
835
844
  }
836
- const submoduleMain = moduleSym.declarations?.[0]?.path;
845
+ // The declaration handle's path is lowercased on case-insensitive file systems; the
846
+ // source file's name keeps the case, so paths derived from it stay relative to the root.
847
+ const submoduleMain = moduleSym.declarations?.[0]?.resolve(this.project)?.fileName;
837
848
  if (submoduleMain == null) {
838
849
  return result;
839
850
  }
@@ -994,9 +1005,46 @@ class Assembler {
994
1005
  implementationOf(property, type, (t) => t.properties);
995
1006
  }
996
1007
  }
1008
+ if (spec.isInterfaceType(type) && this._redeclaresInterfaceMember(type, dereference, same)) {
1009
+ this.usedFeatures.add('interface-member-doc-overrides');
1010
+ }
997
1011
  }
998
1012
  return this.usedFeatures.size > 0 ? Array.from(this.usedFeatures).sort() : undefined;
999
1013
  }
1014
+ /**
1015
+ * Whether an interface re-declares an inherited member with exactly the same
1016
+ * shape, so that only its documentation differs. `overrides` already points
1017
+ * at the nearest base interface that declares the member.
1018
+ */
1019
+ _redeclaresInterfaceMember(type, dereference, same) {
1020
+ const baseMember = (member, pick) => {
1021
+ const base = member.overrides != null ? dereference(member.overrides) : undefined;
1022
+ return base != null && spec.isInterfaceType(base) ? pick(base)?.find((m) => m.name === member.name) : undefined;
1023
+ };
1024
+ const sameMethod = (member, base) => {
1025
+ const params = member.parameters ?? [];
1026
+ const baseParams = base.parameters ?? [];
1027
+ return (!!member.static === !!base.static &&
1028
+ !!member.async === !!base.async &&
1029
+ same(member.returns, base.returns) &&
1030
+ params.length === baseParams.length &&
1031
+ params.every((param, i) => same(param.type, baseParams[i].type) &&
1032
+ !!param.optional === !!baseParams[i].optional &&
1033
+ !!param.variadic === !!baseParams[i].variadic));
1034
+ };
1035
+ const sameProperty = (member, base) => !!member.static === !!base.static &&
1036
+ !!member.optional === !!base.optional &&
1037
+ !!member.immutable === !!base.immutable &&
1038
+ same(member.type, base.type);
1039
+ return ((type.methods ?? []).some((m) => {
1040
+ const base = baseMember(m, (t) => t.methods);
1041
+ return base != null && sameMethod(m, base);
1042
+ }) ||
1043
+ (type.properties ?? []).some((p) => {
1044
+ const base = baseMember(p, (t) => t.properties);
1045
+ return base != null && sameProperty(p, base);
1046
+ }));
1047
+ }
1000
1048
  /**
1001
1049
  * Declaration rank of a type FQN for union ordering: own types by (program file
1002
1050
  * order, position in file); types of dependencies before them, by name.