Skip to content

Commit 8b18e01

Browse files
committed
fix(dts-generator): fix name of $Settings interface for module:* classes
When a managed object class has a module:* name, the name is now correctly split into prefix and base name when calculating the name of the $Settings interface for the class.
1 parent f00f850 commit 8b18e01

File tree

2 files changed

+73
-9
lines changed

2 files changed

+73
-9
lines changed

packages/dts-generator/src/utils/json-constructor-settings-interfaces.ts

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,72 @@ const log = getLogger("@ui5/dts-generator/constructor-settings-interfaces");
1212
import { splitName } from "./base-utils.js";
1313
import { TypeReference } from "../types/ast.js";
1414

15-
export function makeSettingsName(fqn: string) {
16-
const [pkgname, basename] = splitName(fqn);
17-
return `${pkgname}.\$${basename}Settings`;
15+
/*
16+
* Calculates the name for the $Settings interface, the basename of the name
17+
* (last name segment) and the assumed export name under which the settings
18+
* are exported from the containing module.
19+
*
20+
* Examples:
21+
* (1) sap.m.Button -->
22+
* name: "sap.m.$ButtonSettings"
23+
* basename: "$ButtonSettings"
24+
* exportName: "$ButtonSettings"
25+
*
26+
* (2) module:my/lib//NotificationListGroupItem -->
27+
* name: "module:my/lib/NotificationListGroupItem.$NotificationListGroupItemSettings"
28+
* basename: "$NotificationListGroupItemSettings"
29+
* exportName: "$NotificationListGroupItemSettings"
30+
*
31+
* (3) module:my/lib/SegmentedButton.Item
32+
* name: "module:my/lib/SegmentedButton.$ItemSettings"
33+
* basename: "$ItemSettings"
34+
* exportName: "$ItemSettings"
35+
*
36+
* (4) module:my/lib/SegmentedButton.Item.SubItem
37+
* name: "module:my/lib/SegmentedButton.Item.$SubItemSettings"
38+
* basename: "$SubItemSettings"
39+
* exportName: "Item.$SubItemSettings"
40+
*/
41+
export function makeSettingsNames(fqn: string) {
42+
const makeNameAndBasename = (fqn: string) => {
43+
const [prefix, basename] = splitName(fqn);
44+
const settings = `\$${basename}Settings`;
45+
return [`${prefix}${prefix ? "." : ""}${settings}`, settings];
46+
};
47+
48+
if (fqn.startsWith("module:")) {
49+
const [pkgname, moduleAndExport] = splitName(
50+
fqn.slice("module:".length),
51+
"/",
52+
);
53+
const pos = moduleAndExport.indexOf(".");
54+
if (pos < 0) {
55+
// case (2), default export
56+
const [, settingsName] = makeNameAndBasename(moduleAndExport);
57+
return {
58+
name: `${fqn}.${settingsName}`,
59+
basename: settingsName,
60+
exportName: settingsName,
61+
};
62+
}
63+
// case (3) and (4), named export
64+
const moduleBaseName = moduleAndExport.slice(0, pos);
65+
const exportName = moduleAndExport.slice(pos + 1);
66+
const [settingsNameWithPrefix, settingsName] =
67+
makeNameAndBasename(exportName);
68+
return {
69+
name: `module:${pkgname}${pkgname ? "/" : ""}${moduleBaseName}.${settingsNameWithPrefix}`,
70+
basename: settingsName,
71+
exportName: settingsNameWithPrefix,
72+
};
73+
}
74+
// case (1), global name
75+
const [fqSettingsName, settingsName] = makeNameAndBasename(fqn);
76+
return {
77+
name: fqSettingsName,
78+
basename: settingsName,
79+
exportName: settingsName,
80+
};
1881
}
1982

2083
export function isA(
@@ -383,13 +446,14 @@ function createConstructorSettingsInterfaces(
383446
symbols.forEach((symbol) => {
384447
if (isManagedObject(symbol)) {
385448
log.verbose(`adding settings interface for ${symbol.name}`);
449+
const { name, basename, exportName } = makeSettingsNames(symbol.name);
386450
const settings: InterfaceSymbol = {
387451
kind: "interface",
388-
name: makeSettingsName(symbol.name),
389-
basename: `\$${symbol.basename}Settings`,
452+
name,
453+
basename,
390454
module: symbol.module,
391455
resource: symbol.resource,
392-
export: `\$${symbol.basename}Settings`,
456+
export: exportName,
393457
properties: addDetails
394458
? dedup([
395459
...settingsForProperties(symbol),
@@ -402,7 +466,7 @@ function createConstructorSettingsInterfaces(
402466
__isNotAMarkerInterface: true,
403467
};
404468
if (isManagedObject(symbol.extends)) {
405-
settings.extends = makeSettingsName(symbol.extends);
469+
settings.extends = makeSettingsNames(symbol.extends).name;
406470
}
407471
settings.description = `Describes the settings that can be provided to the ${symbol.basename} constructor.`;
408472
if (symbol.deprecated) {

packages/dts-generator/src/utils/json-event-parameter-interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { splitName } from "./base-utils.js";
1515
import {
1616
addJsDocProps,
1717
isA,
18-
makeSettingsName,
18+
makeSettingsNames,
1919
} from "./json-constructor-settings-interfaces.js";
2020
import { FunctionType, TypeReference } from "../types/ast.js";
2121

@@ -380,7 +380,7 @@ function createEventParameterInterfaces(
380380

381381
// finally also add the event parameter interface to the settings object
382382
const settingsInterface = typeUniverse.get(
383-
makeSettingsName(symbol.name),
383+
makeSettingsNames(symbol.name).name,
384384
);
385385
let eventProperty;
386386
if (

0 commit comments

Comments
 (0)