@ui5/webcomponents-tools 1.21.2 → 1.22.0-rc.1
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/CHANGELOG.md +11 -3
- package/components-package/eslint.js +1 -0
- package/components-package/nps.js +4 -2
- package/lib/cem/custom-elements-manifest.config.mjs +463 -0
- package/lib/cem/event.mjs +114 -0
- package/lib/cem/schema-internal.json +1354 -0
- package/lib/cem/schema.json +1098 -0
- package/lib/cem/types-internal.d.ts +1032 -0
- package/lib/cem/types.d.ts +871 -0
- package/lib/cem/utils.mjs +355 -0
- package/lib/cem/validate.js +63 -0
- package/lib/create-illustrations/index.js +21 -31
- package/lib/create-new-component/tsFileContentTemplate.js +2 -11
- package/lib/generate-js-imports/illustrations.js +9 -9
- package/package.json +5 -2
package/CHANGELOG.md
CHANGED
@@ -3,12 +3,20 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
-
|
6
|
+
# [1.22.0-rc.1](https://github.com/SAP/ui5-webcomponents/compare/v1.22.0-rc.0...v1.22.0-rc.1) (2024-01-18)
|
7
|
+
|
8
|
+
|
9
|
+
### Features
|
10
|
+
|
11
|
+
* **illustration:** use illustration name as default module export ([#8074](https://github.com/SAP/ui5-webcomponents/issues/8074)) ([a9c0705](https://github.com/SAP/ui5-webcomponents/commit/a9c07055d4e06e4d1f69b7a2a48b36eb77fae4aa))
|
7
12
|
|
8
13
|
|
9
|
-
### Bug Fixes
|
10
14
|
|
11
|
-
|
15
|
+
|
16
|
+
|
17
|
+
# [1.22.0-rc.0](https://github.com/SAP/ui5-webcomponents/compare/v1.21.0...v1.22.0-rc.0) (2024-01-11)
|
18
|
+
|
19
|
+
**Note:** Version bump only for package @ui5/webcomponents-tools
|
12
20
|
|
13
21
|
|
14
22
|
|
@@ -28,6 +28,7 @@ const overrides = tsMode ? [{
|
|
28
28
|
"@typescript-eslint/no-unsafe-call": "off",
|
29
29
|
"@typescript-eslint/no-non-null-assertion": "off",
|
30
30
|
"@typescript-eslint/no-empty-function": "off",
|
31
|
+
"@typescript-eslint/no-empty-interface": "off",
|
31
32
|
"lines-between-class-members": "off",
|
32
33
|
}
|
33
34
|
}] : [];
|
@@ -12,7 +12,7 @@ const getScripts = (options) => {
|
|
12
12
|
const createIllustrationsJSImportsScript = illustrations.join(" && ");
|
13
13
|
|
14
14
|
// The script creates the "src/generated/js-imports/Illustration.js" file that registers loaders (dynamic JS imports) for each illustration
|
15
|
-
const createIllustrationsLoadersScript = illustrationsData.map(illustrations => `node ${LIB}/generate-js-imports/illustrations.js ${illustrations.destinationPath} ${illustrations.dynamicImports.outputFile} ${illustrations.
|
15
|
+
const createIllustrationsLoadersScript = illustrationsData.map(illustrations => `node ${LIB}/generate-js-imports/illustrations.js ${illustrations.destinationPath} ${illustrations.dynamicImports.outputFile} ${illustrations.set} ${illustrations.collection} ${illustrations.dynamicImports.location} ${illustrations.dynamicImports.filterOut.join(" ")}`).join(" && ");
|
16
16
|
|
17
17
|
const tsOption = options.typescript;
|
18
18
|
const tsCommandOld = tsOption ? "tsc" : "";
|
@@ -135,7 +135,9 @@ const getScripts = (options) => {
|
|
135
135
|
bundle: `node ${LIB}/dev-server/dev-server.js ${viteConfig}`,
|
136
136
|
},
|
137
137
|
generateAPI: {
|
138
|
-
default:
|
138
|
+
default: `nps ${ tsOption ? "generateAPI.generateCEM generateAPI.validateCEM" : "generateAPI.prepare generateAPI.preprocess generateAPI.jsdoc generateAPI.cleanup generateAPI.prepareManifest"}`,
|
139
|
+
generateCEM: `cem analyze --config "${LIB}/cem/custom-elements-manifest.config.mjs"`,
|
140
|
+
validateCEM: `node "${LIB}/cem/validate.js"`,
|
139
141
|
prepare: `node "${LIB}/copy-and-watch/index.js" --silent "dist/**/*.js" jsdoc-dist/`,
|
140
142
|
prepareManifest: `node "${LIB}/generate-custom-elements-manifest/index.js" dist dist`,
|
141
143
|
preprocess: `node "${preprocessJSDocScript}" jsdoc-dist/ src`,
|
@@ -0,0 +1,463 @@
|
|
1
|
+
import { parse } from "comment-parser";
|
2
|
+
import processEvent from "./event.mjs";
|
3
|
+
import path from "path";
|
4
|
+
import fs from 'fs';
|
5
|
+
import {
|
6
|
+
getDeprecatedStatus,
|
7
|
+
getSinceStatus,
|
8
|
+
getPrivacyStatus,
|
9
|
+
getReference,
|
10
|
+
validateJSDocComment,
|
11
|
+
findDecorator,
|
12
|
+
findAllDecorators,
|
13
|
+
hasTag,
|
14
|
+
findTag,
|
15
|
+
findAllTags,
|
16
|
+
getJSDocErrors,
|
17
|
+
getTypeRefs,
|
18
|
+
normalizeDescription,
|
19
|
+
formatArrays,
|
20
|
+
isClass,
|
21
|
+
normalizeTagType
|
22
|
+
} from "./utils.mjs";
|
23
|
+
|
24
|
+
const extractClassNodeJSDoc = node => {
|
25
|
+
const fileContent = node.getFullText();
|
26
|
+
const allJSDocsRegExp = new RegExp(`\\/\\*\\*(.|\\n)+?\\s+\\*\\/`, "gm");
|
27
|
+
let allJSDocs = [...fileContent.matchAll(allJSDocsRegExp)];
|
28
|
+
allJSDocs = allJSDocs.map(match => match[0]); // all /** ..... */ comments
|
29
|
+
|
30
|
+
// Find where the class is defined in the original file
|
31
|
+
const tsClassDefinitionRegExp = new RegExp(`^\\s*(abstract\\s*)?class [\\w\\d_]+`, "gm");
|
32
|
+
let tsClassDefinitionMatch = fileContent.match(tsClassDefinitionRegExp);
|
33
|
+
if (!tsClassDefinitionMatch) {
|
34
|
+
return; // no class defined in this .ts file
|
35
|
+
}
|
36
|
+
const tsClassDefinition = tsClassDefinitionMatch[0];
|
37
|
+
const tsClassDefinitionIndex = fileContent.indexOf(tsClassDefinition);
|
38
|
+
|
39
|
+
return allJSDocs.find(JSDoc => {
|
40
|
+
return isClass(JSDoc) && (fileContent.indexOf(JSDoc) < tsClassDefinitionIndex)
|
41
|
+
});
|
42
|
+
}
|
43
|
+
|
44
|
+
function processClass(ts, classNode, moduleDoc) {
|
45
|
+
const className = classNode?.name?.text;
|
46
|
+
const currClass = moduleDoc?.declarations?.find(declaration => declaration?.name === className);
|
47
|
+
const currClassJSdoc = extractClassNodeJSDoc(classNode);
|
48
|
+
|
49
|
+
if (!currClassJSdoc) return;
|
50
|
+
|
51
|
+
const customElementDecorator = findDecorator(classNode, "customElement");
|
52
|
+
const classParsedJsDoc = parse(currClassJSdoc, { spacing: 'preserve' })[0];
|
53
|
+
|
54
|
+
validateJSDocComment("class", classParsedJsDoc, classNode.name?.text, moduleDoc);
|
55
|
+
|
56
|
+
const decoratorArg = customElementDecorator?.expression?.arguments[0];
|
57
|
+
currClass.tagName = decoratorArg?.text || (decoratorArg?.properties.find(property => property.name.text === "tag")?.initializer?.text);
|
58
|
+
currClass.customElement = !!customElementDecorator || className === "UI5Element" || undefined;
|
59
|
+
currClass.kind = "class";
|
60
|
+
currClass.deprecated = getDeprecatedStatus(classParsedJsDoc);
|
61
|
+
currClass._ui5since = getSinceStatus(classParsedJsDoc);
|
62
|
+
currClass._ui5privacy = getPrivacyStatus(classParsedJsDoc);
|
63
|
+
currClass._ui5abstract = hasTag(classParsedJsDoc, "abstract") ? true : undefined;
|
64
|
+
currClass.description = normalizeDescription(classParsedJsDoc.description || findTag(classParsedJsDoc, "class")?.description);
|
65
|
+
currClass._ui5implements = findAllTags(classParsedJsDoc, "implements")
|
66
|
+
.map(tag => getReference(ts, normalizeTagType(tag.type), classNode, moduleDoc.path))
|
67
|
+
.filter(Boolean);
|
68
|
+
|
69
|
+
|
70
|
+
if (hasTag(classParsedJsDoc, "extends")) {
|
71
|
+
const superclassTag = findTag(classParsedJsDoc, "extends");
|
72
|
+
currClass.superclass = getReference(ts, superclassTag.name, classNode, moduleDoc.path);
|
73
|
+
|
74
|
+
if (currClass.superclass?.name === "UI5Element") {
|
75
|
+
currClass.customElement = true;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
if (!currClass._ui5implements.length) delete currClass._ui5implements;
|
80
|
+
|
81
|
+
// Slots
|
82
|
+
|
83
|
+
// Slots without accessort (defined in class comment)
|
84
|
+
if (hasTag(classParsedJsDoc, "slot") && currClass.slots) {
|
85
|
+
const slotTags = findAllTags(classParsedJsDoc, "slot");
|
86
|
+
|
87
|
+
currClass.slots.forEach(slot => {
|
88
|
+
const tag = slotTags.find(tag => tag.name === slot.name);
|
89
|
+
|
90
|
+
const typeRefs = (normalizeTagType(tag.type)
|
91
|
+
?.replaceAll(/Array<|>|\[\]/g, "")
|
92
|
+
?.split("|")
|
93
|
+
?.map(e => getReference(ts, e.trim(), classNode, moduleDoc.path)).filter(Boolean));
|
94
|
+
|
95
|
+
slot._ui5privacy = "public";
|
96
|
+
slot._ui5type = { text: formatArrays(normalizeTagType(tag.type)) };
|
97
|
+
slot.description = normalizeDescription(tag.description)
|
98
|
+
|
99
|
+
if (typeRefs && typeRefs.length) {
|
100
|
+
slot._ui5type.references = typeRefs;
|
101
|
+
}
|
102
|
+
|
103
|
+
delete slot.type
|
104
|
+
})
|
105
|
+
}
|
106
|
+
|
107
|
+
// Events
|
108
|
+
currClass.events = findAllDecorators(classNode, "event")
|
109
|
+
?.map(event => processEvent(ts, event, classNode, moduleDoc));
|
110
|
+
|
111
|
+
// Slots (with accessor), methods and fields
|
112
|
+
for (let i = 0; i < (currClass.members?.length || 0); i++) {
|
113
|
+
const member = currClass.members[i];
|
114
|
+
const classNodeMember = classNode.members?.find(nodeMember => nodeMember.name?.text === member?.name && nodeMember.jsDoc?.[0]);
|
115
|
+
const classNodeMemberJSdoc = classNodeMember?.jsDoc?.[0];
|
116
|
+
|
117
|
+
if (!classNodeMember || !classNodeMemberJSdoc) continue;
|
118
|
+
|
119
|
+
const memberParsedJsDoc = parse(classNodeMemberJSdoc?.getText())[0];
|
120
|
+
|
121
|
+
member._ui5since = getSinceStatus(memberParsedJsDoc);
|
122
|
+
member.deprecated === "true" && (member.deprecated = true)
|
123
|
+
|
124
|
+
// Slots with accessors are treated like fields by the tool, so we have to convert them into slots.
|
125
|
+
if (member.kind === "field") {
|
126
|
+
const slotDecorator = findDecorator(classNodeMember, "slot");
|
127
|
+
validateJSDocComment(slotDecorator ? "slot" : (member.readonly ? "getter" : "field"), memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
|
128
|
+
|
129
|
+
const typeRefs = (getTypeRefs(ts, classNodeMember, member)
|
130
|
+
?.map(e => getReference(ts, e, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
|
131
|
+
|
132
|
+
if (member.type?.text) {
|
133
|
+
member.type.text = formatArrays(member.type.text);
|
134
|
+
}
|
135
|
+
|
136
|
+
if (member.type && typeRefs.length) {
|
137
|
+
member.type.references = typeRefs;
|
138
|
+
}
|
139
|
+
|
140
|
+
if (slotDecorator) {
|
141
|
+
if (!currClass.slots) currClass.slots = [];
|
142
|
+
|
143
|
+
const slot = currClass.members.splice(i, 1)[0];
|
144
|
+
const defaultProperty = slotDecorator.expression?.arguments?.[0]?.properties?.find(property => property.name.text === "default");
|
145
|
+
|
146
|
+
// name of the default slot declared with decorator will be overriden so we to provide it's accessor name
|
147
|
+
if (defaultProperty && defaultProperty.initializer?.kind === ts.SyntaxKind.TrueKeyword) {
|
148
|
+
slot._ui5propertyName = slot.name;
|
149
|
+
slot.name = "default";
|
150
|
+
}
|
151
|
+
|
152
|
+
// Slots don't have type, privacy and kind, so we have do convert them and to clean unused props
|
153
|
+
member._ui5type = member.type;
|
154
|
+
member._ui5privacy = member.privacy;
|
155
|
+
delete member.type;
|
156
|
+
delete member.privacy;
|
157
|
+
delete slot.kind;
|
158
|
+
|
159
|
+
currClass.slots.push(slot);
|
160
|
+
i--;
|
161
|
+
} else {
|
162
|
+
const propertyDecorator = findDecorator(classNodeMember, "property");
|
163
|
+
|
164
|
+
if (propertyDecorator) {
|
165
|
+
member._ui5validator = propertyDecorator?.expression?.arguments[0]?.properties?.find(property => ["validator", "type"].includes(property.name.text))?.initializer?.text || "String";
|
166
|
+
}
|
167
|
+
|
168
|
+
if (hasTag(memberParsedJsDoc, "formProperty")) {
|
169
|
+
member._ui5formProperty = true;
|
170
|
+
}
|
171
|
+
|
172
|
+
const formEventsTag = findTag(memberParsedJsDoc, "formEvents");
|
173
|
+
if (formEventsTag) {
|
174
|
+
const tagValue = formEventsTag.description ? `${formEventsTag.name} ${formEventsTag.description}` : formEventsTag.name;
|
175
|
+
member._ui5formEvents = tagValue.trim().replaceAll(/\s+/g, ",");
|
176
|
+
}
|
177
|
+
|
178
|
+
const defaultTag = findTag(memberParsedJsDoc, "default");
|
179
|
+
if (defaultTag) {
|
180
|
+
const tagValue = defaultTag.source?.[0]?.tokens?.name || defaultTag.source?.[0]?.tokens?.description || defaultTag.source?.[0]?.tokens?.type || "";
|
181
|
+
member.default = tagValue;
|
182
|
+
}
|
183
|
+
|
184
|
+
if (member.privacy === "public") {
|
185
|
+
const JSDocErrors = getJSDocErrors();
|
186
|
+
|
187
|
+
if (!member.default) {
|
188
|
+
JSDocErrors.push(
|
189
|
+
`=== ERROR: Problem found with ${member.name}'s JSDoc comment in ${moduleDoc.path}: Default value is missing`
|
190
|
+
);
|
191
|
+
}
|
192
|
+
}
|
193
|
+
|
194
|
+
// Getters are treated as fields so they should not have return, instead of return they should have default value defined with @default
|
195
|
+
if (member.readonly) {
|
196
|
+
if (member.privacy === "public" && !member.type) {
|
197
|
+
const JSDocErrors = getJSDocErrors();
|
198
|
+
|
199
|
+
JSDocErrors.push(
|
200
|
+
`=== ERROR: Problem found with ${member.name}'s JSDoc comment in ${moduleDoc.path}: Missing return type`
|
201
|
+
);
|
202
|
+
}
|
203
|
+
|
204
|
+
delete member.return;
|
205
|
+
}
|
206
|
+
}
|
207
|
+
} else if (member.kind === "method") {
|
208
|
+
validateJSDocComment("method", memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
|
209
|
+
|
210
|
+
member.parameters?.forEach(param => {
|
211
|
+
// Treat every parameter that has respective @param tag as public
|
212
|
+
param._ui5privacy = findAllTags(memberParsedJsDoc, "param").some(tag => tag.name === param.name) ? "public" : "private";
|
213
|
+
if (param._ui5privacy === "public") {
|
214
|
+
const paramNode = classNodeMember.parameters?.find(parameter => parameter.name?.text === param.name);
|
215
|
+
let type;
|
216
|
+
|
217
|
+
if (param.optional) {
|
218
|
+
const filename = classNode.getSourceFile().fileName;
|
219
|
+
|
220
|
+
const sourceFile = typeProgram.getSourceFile(filename);
|
221
|
+
const tsProgramClassNode = sourceFile.statements.find(statement => ts.isClassDeclaration(statement) && statement.name?.text === classNode.name?.text);
|
222
|
+
const tsProgramMember = tsProgramClassNode.members.find(m => ts.isMethodDeclaration(m) && m.name?.text === member.name);
|
223
|
+
const tsProgramParameter = tsProgramMember.parameters.find(p => ts.isParameter(p) && p.name?.text === param.name);
|
224
|
+
|
225
|
+
if (tsProgramParameter) {
|
226
|
+
const typeName = typeChecker.typeToString(typeChecker.getTypeAtLocation(tsProgramParameter), tsProgramParameter);
|
227
|
+
|
228
|
+
if (!param.type) {
|
229
|
+
param.type = {};
|
230
|
+
param.type.text = typeName;
|
231
|
+
}
|
232
|
+
|
233
|
+
type = typeName.replaceAll(/Array<|>|\[\]/g, "")
|
234
|
+
?.split("|");
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
const typeRefs = ((type || getTypeRefs(ts, (type || paramNode), param))
|
239
|
+
?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
|
240
|
+
|
241
|
+
if (typeRefs.length) {
|
242
|
+
param.type.references = typeRefs;
|
243
|
+
}
|
244
|
+
}
|
245
|
+
});
|
246
|
+
|
247
|
+
if (member.return) {
|
248
|
+
const returnTag = findTag(memberParsedJsDoc, "returns");
|
249
|
+
member.return.description = returnTag?.description ? `${returnTag.name} ${returnTag.description}` : returnTag?.name;
|
250
|
+
member.return.type.text = classNodeMember?.type?.getFullText?.()?.trim();
|
251
|
+
const typeRefs = (getTypeRefs(ts, classNodeMember, member.return)
|
252
|
+
?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
|
253
|
+
|
254
|
+
if (typeRefs.length) {
|
255
|
+
member.return.type.references = typeRefs;
|
256
|
+
}
|
257
|
+
}
|
258
|
+
|
259
|
+
if (member.privacy === "public" && !member.return) {
|
260
|
+
const JSDocErrors = getJSDocErrors();
|
261
|
+
|
262
|
+
JSDocErrors.push(
|
263
|
+
`=== ERROR: Problem found with ${member.name}'s JSDoc comment in ${moduleDoc.path}: Missing return type`
|
264
|
+
);
|
265
|
+
}
|
266
|
+
}
|
267
|
+
}
|
268
|
+
}
|
269
|
+
|
270
|
+
function processInterface(ts, interfaceNode, moduleDoc) {
|
271
|
+
const interfaceJSdoc = interfaceNode?.jsDoc?.[0];
|
272
|
+
const interfaceName = interfaceNode?.name?.text;
|
273
|
+
|
274
|
+
if (!interfaceJSdoc) return;
|
275
|
+
|
276
|
+
const interfaceParsedJsDoc = parse(interfaceJSdoc?.getText(), { spacing: 'preserve' })[0];
|
277
|
+
|
278
|
+
validateJSDocComment("interface", interfaceParsedJsDoc, interfaceNode.name?.text, moduleDoc);
|
279
|
+
|
280
|
+
moduleDoc.declarations.push({
|
281
|
+
kind: "interface",
|
282
|
+
name: interfaceName,
|
283
|
+
description: normalizeDescription(interfaceParsedJsDoc?.description),
|
284
|
+
_ui5privacy: getPrivacyStatus(interfaceParsedJsDoc),
|
285
|
+
_ui5since: getSinceStatus(interfaceParsedJsDoc),
|
286
|
+
deprecated: getDeprecatedStatus(interfaceParsedJsDoc),
|
287
|
+
});
|
288
|
+
}
|
289
|
+
|
290
|
+
function processEnum(ts, enumNode, moduleDoc) {
|
291
|
+
const enumJSdoc = enumNode?.jsDoc?.[0];
|
292
|
+
const enumName = enumNode?.name?.text;
|
293
|
+
|
294
|
+
if (!enumJSdoc) return;
|
295
|
+
|
296
|
+
const enumParsedJsDoc = parse(enumJSdoc?.getText(), { spacing: 'preserve' })[0];
|
297
|
+
|
298
|
+
validateJSDocComment("enum", enumParsedJsDoc, enumNode.name?.text, moduleDoc);
|
299
|
+
|
300
|
+
const result = {
|
301
|
+
kind: "enum",
|
302
|
+
name: enumName,
|
303
|
+
description: normalizeDescription(enumJSdoc?.comment),
|
304
|
+
_ui5privacy: getPrivacyStatus(enumParsedJsDoc),
|
305
|
+
_ui5since: getSinceStatus(enumParsedJsDoc),
|
306
|
+
deprecated: getDeprecatedStatus(enumParsedJsDoc) || undefined,
|
307
|
+
members: (enumNode?.members || []).map(member => {
|
308
|
+
const memberJSdoc = member?.jsDoc?.[0];
|
309
|
+
|
310
|
+
if (!memberJSdoc) return;
|
311
|
+
|
312
|
+
const memberParsedJsDoc = parse(memberJSdoc?.getText())[0];
|
313
|
+
|
314
|
+
validateJSDocComment("enum", memberParsedJsDoc, member.name?.text, moduleDoc);
|
315
|
+
|
316
|
+
return {
|
317
|
+
kind: "field",
|
318
|
+
static: true,
|
319
|
+
privacy: getPrivacyStatus(memberParsedJsDoc),
|
320
|
+
_ui5since: getSinceStatus(memberParsedJsDoc),
|
321
|
+
description: memberJSdoc?.comment,
|
322
|
+
default: member.initializer?.text,
|
323
|
+
deprecated: getDeprecatedStatus(memberParsedJsDoc),
|
324
|
+
name: member.name?.text,
|
325
|
+
readonly: true,
|
326
|
+
};
|
327
|
+
}).filter(Boolean),
|
328
|
+
};
|
329
|
+
|
330
|
+
moduleDoc.declarations.push(result);
|
331
|
+
}
|
332
|
+
|
333
|
+
const processPublicAPI = object => {
|
334
|
+
if (!object) {
|
335
|
+
return true;
|
336
|
+
}
|
337
|
+
const keys = Object.keys(object);
|
338
|
+
if (!keys.includes("privacy") && !keys.includes("_ui5privacy")) {
|
339
|
+
return true;
|
340
|
+
}
|
341
|
+
for (const key of keys) {
|
342
|
+
if ((key === "privacy" && object[key] !== "public") || (key === "_ui5privacy" && object[key] !== "public")) {
|
343
|
+
return true;
|
344
|
+
} else if (typeof object[key] === "object") {
|
345
|
+
if (key === "cssParts" || key === "_ui5implements") {
|
346
|
+
continue;
|
347
|
+
}
|
348
|
+
|
349
|
+
if (Array.isArray(object[key])) {
|
350
|
+
for (let i = 0; i < object[key].length; i++) {
|
351
|
+
const shouldRemove = processPublicAPI(object[key][i]);
|
352
|
+
if (shouldRemove) {
|
353
|
+
object[key].splice(i, 1);
|
354
|
+
i--;
|
355
|
+
}
|
356
|
+
}
|
357
|
+
if (object[key].length === 0) {
|
358
|
+
delete object[key];
|
359
|
+
}
|
360
|
+
}
|
361
|
+
}
|
362
|
+
}
|
363
|
+
return false;
|
364
|
+
};
|
365
|
+
|
366
|
+
let typeChecker;
|
367
|
+
let typeProgram;
|
368
|
+
|
369
|
+
export default {
|
370
|
+
globs: ["src/!(*generated)/*.ts", "src/!(*bundle)*.ts"],
|
371
|
+
outdir: 'dist',
|
372
|
+
overrideModuleCreation: ({ ts, globs }) => {
|
373
|
+
typeProgram = ts.createProgram(globs, {
|
374
|
+
noEmitOnError: false,
|
375
|
+
allowJs: true,
|
376
|
+
experimentalDecorators: true,
|
377
|
+
target: 99,
|
378
|
+
downlevelIteration: true,
|
379
|
+
module: 99,
|
380
|
+
strictNullChecks: true,
|
381
|
+
moduleResolution: 2,
|
382
|
+
esModuleInterop: true,
|
383
|
+
noEmit: true,
|
384
|
+
pretty: true,
|
385
|
+
allowSyntheticDefaultImports: true,
|
386
|
+
allowUnreachableCode: true,
|
387
|
+
allowUnusedLabels: true,
|
388
|
+
skipLibCheck: true,
|
389
|
+
});
|
390
|
+
typeChecker = typeProgram.getTypeChecker();
|
391
|
+
|
392
|
+
return globs.map((glob) => {
|
393
|
+
const fullPath = path.resolve(process.cwd(), glob);
|
394
|
+
const source = fs.readFileSync(fullPath).toString();
|
395
|
+
|
396
|
+
return ts.createSourceFile(glob, source, ts.ScriptTarget.ES2015, true);
|
397
|
+
});
|
398
|
+
},
|
399
|
+
plugins: [
|
400
|
+
{
|
401
|
+
name: 'my-plugin',
|
402
|
+
analyzePhase({ ts, node, moduleDoc }) {
|
403
|
+
switch (true) {
|
404
|
+
case ts.isClassDeclaration(node):
|
405
|
+
processClass(ts, node, moduleDoc);
|
406
|
+
break;
|
407
|
+
case ts.isEnumDeclaration(node):
|
408
|
+
processEnum(ts, node, moduleDoc);
|
409
|
+
break;
|
410
|
+
case ts.isInterfaceDeclaration(node):
|
411
|
+
processInterface(ts, node, moduleDoc);
|
412
|
+
break;
|
413
|
+
}
|
414
|
+
},
|
415
|
+
moduleLinkPhase({ moduleDoc }) {
|
416
|
+
for (let i = 0; i < moduleDoc.declarations.length; i++) {
|
417
|
+
const shouldRemove = processPublicAPI(moduleDoc.declarations[i]) || ["function", "variable"].includes(moduleDoc.declarations[i].kind)
|
418
|
+
if (shouldRemove) {
|
419
|
+
moduleDoc.declarations.splice(i, 1);
|
420
|
+
i--;
|
421
|
+
}
|
422
|
+
}
|
423
|
+
|
424
|
+
if (moduleDoc.exports) {
|
425
|
+
moduleDoc.exports = moduleDoc.exports.filter(e => !(e.kind === "custom-element-definition" && !moduleDoc.declarations?.find(d => d.name === e.name)?.tagName))
|
426
|
+
}
|
427
|
+
|
428
|
+
moduleDoc.exports?.forEach(e => {
|
429
|
+
const classNode = moduleDoc.declarations.find(c => c.name === e.declaration.name);
|
430
|
+
|
431
|
+
if (classNode?.customElement && classNode.tagName && e.kind !== "custom-element-definition") {
|
432
|
+
moduleDoc.exports.push({
|
433
|
+
kind: "custom-element-definition",
|
434
|
+
name: classNode.tagName,
|
435
|
+
declaration: {
|
436
|
+
name: e.declaration.name,
|
437
|
+
module: e.declaration.module
|
438
|
+
}
|
439
|
+
})
|
440
|
+
}
|
441
|
+
})
|
442
|
+
},
|
443
|
+
packageLinkPhase({ customElementsManifest }) {
|
444
|
+
// Uncomment and handle errors appropriately
|
445
|
+
// const JSDocErrors = getJSDocErrors();
|
446
|
+
// if (JSDocErrors.length > 0) {
|
447
|
+
// console.log(JSDocErrors.join("\n"));
|
448
|
+
// console.log(`Invalid JSDoc. ${JSDocErrors.length} were found.`);
|
449
|
+
// throw new Error(`Invalid JSDoc.`);
|
450
|
+
// }
|
451
|
+
|
452
|
+
customElementsManifest.modules?.forEach(m => {
|
453
|
+
m.path = m.path?.replace(/^src/, "dist").replace(/\.ts$/, ".js");
|
454
|
+
|
455
|
+
m.exports?.forEach(e => {
|
456
|
+
if (e.declaration && e.declaration.module)
|
457
|
+
e.declaration.module = e.declaration?.module?.replace(/^src/, "dist").replace(/\.ts$/, ".js");
|
458
|
+
});
|
459
|
+
})
|
460
|
+
}
|
461
|
+
},
|
462
|
+
],
|
463
|
+
};
|
@@ -0,0 +1,114 @@
|
|
1
|
+
import { parse } from "comment-parser";
|
2
|
+
import {
|
3
|
+
getPrivacyStatus,
|
4
|
+
getDeprecatedStatus,
|
5
|
+
getSinceStatus,
|
6
|
+
getType,
|
7
|
+
validateJSDocComment,
|
8
|
+
hasTag,
|
9
|
+
findTag,
|
10
|
+
findAllTags,
|
11
|
+
getReference,
|
12
|
+
normalizeDescription,
|
13
|
+
normalizeTagType
|
14
|
+
} from "./utils.mjs";
|
15
|
+
|
16
|
+
const jsDocRegExp = /\/\*\*(.|\n)+?\s+\*\//;
|
17
|
+
|
18
|
+
const getParams = (ts, eventDetails, commentParams, classNode, moduleDoc) => {
|
19
|
+
return commentParams?.map(commentParam => {
|
20
|
+
const decoratorParam = eventDetails?.find(prop => prop?.name?.text === commentParam?.name);
|
21
|
+
|
22
|
+
if (!decoratorParam || !decoratorParam?.jsDoc?.[0]) {
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
|
26
|
+
const decoratorParamParsedComment = parse(decoratorParam?.jsDoc?.[0]?.getText?.(), { spacing: 'preserve' })[0];
|
27
|
+
|
28
|
+
validateJSDocComment("eventParam", decoratorParamParsedComment, decoratorParam.name?.text, moduleDoc);
|
29
|
+
|
30
|
+
const { typeName, name } = getType(normalizeTagType(commentParam?.type));
|
31
|
+
let type;
|
32
|
+
|
33
|
+
if (typeName) {
|
34
|
+
type = { text: typeName };
|
35
|
+
|
36
|
+
let typeRefs = name?.split("|")
|
37
|
+
?.map(e => getReference(ts, e.trim(), classNode, moduleDoc.path))
|
38
|
+
.filter(Boolean);
|
39
|
+
|
40
|
+
if (typeRefs?.length) {
|
41
|
+
type.references = typeRefs;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
return {
|
46
|
+
type,
|
47
|
+
name: commentParam?.name,
|
48
|
+
_ui5privacy: getPrivacyStatus(decoratorParamParsedComment),
|
49
|
+
description: normalizeDescription(commentParam?.description),
|
50
|
+
_ui5since: getSinceStatus(decoratorParamParsedComment),
|
51
|
+
deprecated: getDeprecatedStatus(decoratorParamParsedComment),
|
52
|
+
};
|
53
|
+
}).filter(pair => !!pair);
|
54
|
+
};
|
55
|
+
|
56
|
+
function processEvent(ts, event, classNode, moduleDoc) {
|
57
|
+
const result = {
|
58
|
+
name: event?.expression?.arguments?.[0]?.text,
|
59
|
+
_ui5privacy: "private",
|
60
|
+
type: { text: "CustomEvent" }
|
61
|
+
};
|
62
|
+
|
63
|
+
const comment = event.getFullText?.().match(jsDocRegExp)?.[0];
|
64
|
+
|
65
|
+
if (!comment) {
|
66
|
+
return result;
|
67
|
+
}
|
68
|
+
|
69
|
+
const eventParsedComment = parse(comment, { spacing: 'preserve' })[0];
|
70
|
+
|
71
|
+
validateJSDocComment("event", eventParsedComment, event?.expression?.arguments?.[0]?.text, moduleDoc);
|
72
|
+
|
73
|
+
const deprecatedTag = findTag(eventParsedComment, "deprecated");
|
74
|
+
const privacy = findTag(eventParsedComment, ["public", "private", "protected"])?.tag || "private";
|
75
|
+
const sinceTag = findTag(eventParsedComment, "since");
|
76
|
+
const commentParams = findAllTags(eventParsedComment, "param");
|
77
|
+
const allowPreventDefault = hasTag(eventParsedComment, "allowPreventDefault") || undefined;
|
78
|
+
const description = normalizeDescription(eventParsedComment?.description);
|
79
|
+
const native = hasTag(eventParsedComment, "native");
|
80
|
+
const eventDetails = event?.expression?.arguments?.[1]?.properties?.find(prop => prop?.name?.text === "detail")?.initializer?.properties;
|
81
|
+
|
82
|
+
result.description = description;
|
83
|
+
result._ui5allowPreventDefault = allowPreventDefault;
|
84
|
+
|
85
|
+
if (native) {
|
86
|
+
result.type = { text: "Event" };
|
87
|
+
}
|
88
|
+
|
89
|
+
if (privacy) {
|
90
|
+
result._ui5privacy = privacy;
|
91
|
+
}
|
92
|
+
|
93
|
+
if (deprecatedTag?.name) {
|
94
|
+
result.deprecated = deprecatedTag.description
|
95
|
+
? `${deprecatedTag.name} ${deprecatedTag.description}`
|
96
|
+
: deprecatedTag.name;
|
97
|
+
} else if (deprecatedTag) {
|
98
|
+
result.deprecated = true;
|
99
|
+
}
|
100
|
+
|
101
|
+
if (sinceTag?.name) {
|
102
|
+
result._ui5since = sinceTag?.description
|
103
|
+
? `${sinceTag.name} ${sinceTag.description}`
|
104
|
+
: sinceTag.name;
|
105
|
+
}
|
106
|
+
|
107
|
+
if (commentParams && eventDetails) {
|
108
|
+
result._ui5parameters = getParams(ts, eventDetails, commentParams, classNode, moduleDoc);
|
109
|
+
}
|
110
|
+
|
111
|
+
return result;
|
112
|
+
}
|
113
|
+
|
114
|
+
export default processEvent;
|