@ui5/webcomponents-tools 0.0.0-f734ea2da → 0.0.0-f79db712b

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.
Files changed (108) hide show
  1. package/CHANGELOG.md +808 -0
  2. package/README.md +6 -6
  3. package/assets-meta.js +18 -3
  4. package/bin/dev.js +1 -5
  5. package/components-package/eslint.js +36 -0
  6. package/components-package/nps.js +108 -66
  7. package/components-package/postcss.components.js +1 -21
  8. package/components-package/postcss.themes.js +1 -23
  9. package/components-package/vite.config.js +13 -0
  10. package/components-package/wdio.js +405 -344
  11. package/components-package/wdio.sync.js +368 -0
  12. package/icons-collection/nps.js +51 -18
  13. package/lib/cem/custom-elements-manifest.config.mjs +499 -0
  14. package/lib/cem/event.mjs +135 -0
  15. package/lib/cem/schema-internal.json +1354 -0
  16. package/lib/cem/schema.json +1098 -0
  17. package/lib/cem/types-internal.d.ts +801 -0
  18. package/lib/cem/types.d.ts +736 -0
  19. package/lib/cem/utils.mjs +354 -0
  20. package/lib/cem/validate.js +67 -0
  21. package/lib/copy-and-watch/index.js +24 -1
  22. package/lib/copy-list/index.js +17 -17
  23. package/lib/create-icons/index.js +124 -58
  24. package/lib/create-illustrations/index.js +165 -0
  25. package/lib/create-new-component/index.js +72 -97
  26. package/lib/create-new-component/jsFileContentTemplate.js +73 -0
  27. package/lib/create-new-component/tsFileContentTemplate.js +71 -0
  28. package/lib/css-processors/css-processor-components.mjs +77 -0
  29. package/lib/css-processors/css-processor-themes.mjs +79 -0
  30. package/lib/css-processors/scope-variables.mjs +46 -0
  31. package/lib/css-processors/shared.mjs +76 -0
  32. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  33. package/lib/dev-server/dev-server.js +66 -0
  34. package/lib/dev-server/virtual-index-html-plugin.js +52 -0
  35. package/lib/esm-abs-to-rel/index.js +17 -10
  36. package/lib/generate-custom-elements-manifest/index.js +327 -0
  37. package/lib/generate-js-imports/illustrations.js +86 -0
  38. package/lib/generate-json-imports/i18n.js +43 -31
  39. package/lib/generate-json-imports/themes.js +36 -24
  40. package/lib/hbs2lit/src/compiler.js +24 -4
  41. package/lib/hbs2lit/src/includesReplacer.js +5 -5
  42. package/lib/hbs2lit/src/litVisitor2.js +95 -24
  43. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  44. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +33 -11
  45. package/lib/hbs2ui5/index.js +56 -23
  46. package/lib/i18n/defaults.js +65 -57
  47. package/lib/i18n/toJSON.js +12 -11
  48. package/lib/jsdoc/configTypescript.json +29 -0
  49. package/lib/jsdoc/plugin.js +41 -0
  50. package/lib/jsdoc/preprocess.js +146 -0
  51. package/lib/jsdoc/template/publish.js +21 -2
  52. package/lib/postcss-combine-duplicated-selectors/index.js +185 -0
  53. package/lib/replace-global-core/index.js +13 -8
  54. package/lib/scoping/get-all-tags.js +2 -9
  55. package/lib/scoping/lint-src.js +1 -1
  56. package/lib/scoping/missing-dependencies.js +65 -0
  57. package/lib/scoping/report-tags-usage.js +28 -0
  58. package/lib/scoping/scope-test-pages.js +2 -1
  59. package/lib/test-runner/test-runner.js +71 -0
  60. package/package.json +36 -38
  61. package/bin/init-ui5-package.js +0 -3
  62. package/components-package/rollup.js +0 -216
  63. package/lib/documentation/index.js +0 -165
  64. package/lib/documentation/templates/api-component-since.js +0 -3
  65. package/lib/documentation/templates/api-css-variables-section.js +0 -24
  66. package/lib/documentation/templates/api-events-section.js +0 -35
  67. package/lib/documentation/templates/api-methods-section.js +0 -26
  68. package/lib/documentation/templates/api-properties-section.js +0 -40
  69. package/lib/documentation/templates/api-slots-section.js +0 -28
  70. package/lib/documentation/templates/template.js +0 -38
  71. package/lib/hash/config.js +0 -10
  72. package/lib/hash/generate.js +0 -19
  73. package/lib/hash/upToDate.js +0 -31
  74. package/lib/init-package/index.js +0 -136
  75. package/lib/init-package/resources/.eslintignore +0 -3
  76. package/lib/init-package/resources/bundle.es5.js +0 -25
  77. package/lib/init-package/resources/bundle.esm.js +0 -31
  78. package/lib/init-package/resources/config/.eslintrc.js +0 -1
  79. package/lib/init-package/resources/config/postcss.components/postcss.config.js +0 -1
  80. package/lib/init-package/resources/config/postcss.themes/postcss.config.js +0 -1
  81. package/lib/init-package/resources/config/rollup.config.js +0 -1
  82. package/lib/init-package/resources/config/wdio.conf.js +0 -1
  83. package/lib/init-package/resources/package-scripts.js +0 -11
  84. package/lib/init-package/resources/src/Assets.js +0 -5
  85. package/lib/init-package/resources/src/MyFirstComponent.hbs +0 -1
  86. package/lib/init-package/resources/src/MyFirstComponent.js +0 -56
  87. package/lib/init-package/resources/src/i18n/messagebundle.properties +0 -2
  88. package/lib/init-package/resources/src/i18n/messagebundle_de.properties +0 -1
  89. package/lib/init-package/resources/src/i18n/messagebundle_en.properties +0 -1
  90. package/lib/init-package/resources/src/i18n/messagebundle_es.properties +0 -1
  91. package/lib/init-package/resources/src/i18n/messagebundle_fr.properties +0 -1
  92. package/lib/init-package/resources/src/themes/MyFirstComponent.css +0 -11
  93. package/lib/init-package/resources/src/themes/sap_belize/parameters-bundle.css +0 -3
  94. package/lib/init-package/resources/src/themes/sap_belize_hcb/parameters-bundle.css +0 -3
  95. package/lib/init-package/resources/src/themes/sap_belize_hcw/parameters-bundle.css +0 -3
  96. package/lib/init-package/resources/src/themes/sap_fiori_3/parameters-bundle.css +0 -3
  97. package/lib/init-package/resources/src/themes/sap_fiori_3_dark/parameters-bundle.css +0 -3
  98. package/lib/init-package/resources/src/themes/sap_fiori_3_hcb/parameters-bundle.css +0 -3
  99. package/lib/init-package/resources/src/themes/sap_fiori_3_hcw/parameters-bundle.css +0 -3
  100. package/lib/init-package/resources/test/pages/index.html +0 -56
  101. package/lib/init-package/resources/test/specs/Demo.spec.js +0 -12
  102. package/lib/polyfill-placeholder/index.js +0 -5
  103. package/lib/postcss-css-to-esm/index.js +0 -45
  104. package/lib/postcss-css-to-json/index.js +0 -31
  105. package/lib/postcss-new-files/index.js +0 -36
  106. package/lib/serve/index.js +0 -46
  107. package/lib/serve/serve.json +0 -3
  108. package/package-lock.json +0 -48
@@ -0,0 +1,499 @@
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 packageJSON = JSON.parse(fs.readFileSync("./package.json"));
25
+
26
+ const extractClassNodeJSDoc = node => {
27
+ const fileContent = node.getFullText();
28
+ const allJSDocsRegExp = new RegExp(`\\/\\*\\*(.|\\n)+?\\s+\\*\\/`, "gm");
29
+ let allJSDocs = [...fileContent.matchAll(allJSDocsRegExp)];
30
+ allJSDocs = allJSDocs.map(match => match[0]); // all /** ..... */ comments
31
+
32
+ // Find where the class is defined in the original file
33
+ const tsClassDefinitionRegExp = new RegExp(`^\\s*(abstract\\s*)?class [\\w\\d_]+`, "gm");
34
+ let tsClassDefinitionMatch = fileContent.match(tsClassDefinitionRegExp);
35
+ if (!tsClassDefinitionMatch) {
36
+ return; // no class defined in this .ts file
37
+ }
38
+ const tsClassDefinition = tsClassDefinitionMatch[0];
39
+ const tsClassDefinitionIndex = fileContent.indexOf(tsClassDefinition);
40
+
41
+ return allJSDocs.find(JSDoc => {
42
+ return isClass(JSDoc) && (fileContent.indexOf(JSDoc) < tsClassDefinitionIndex)
43
+ });
44
+ }
45
+
46
+ function processClass(ts, classNode, moduleDoc) {
47
+ const className = classNode?.name?.text;
48
+ const currClass = moduleDoc?.declarations?.find(declaration => declaration?.name === className);
49
+ const currClassJSdoc = extractClassNodeJSDoc(classNode);
50
+
51
+ if (!currClassJSdoc) return;
52
+
53
+ const customElementDecorator = findDecorator(classNode, "customElement");
54
+ const classParsedJsDoc = parse(currClassJSdoc, { spacing: 'preserve' })[0];
55
+
56
+ validateJSDocComment("class", classParsedJsDoc, classNode.name?.text, moduleDoc);
57
+
58
+ const decoratorArg = customElementDecorator?.expression?.arguments[0];
59
+ currClass.tagName = decoratorArg?.text || (decoratorArg?.properties.find(property => property.name.text === "tag")?.initializer?.text);
60
+ currClass.customElement = !!customElementDecorator || className === "UI5Element" || undefined;
61
+ currClass.kind = "class";
62
+ currClass.deprecated = getDeprecatedStatus(classParsedJsDoc);
63
+ currClass._ui5since = getSinceStatus(classParsedJsDoc);
64
+ currClass._ui5privacy = getPrivacyStatus(classParsedJsDoc);
65
+ currClass._ui5abstract = hasTag(classParsedJsDoc, "abstract") ? true : undefined;
66
+ currClass.description = normalizeDescription(classParsedJsDoc.description || findTag(classParsedJsDoc, "class")?.description);
67
+ currClass._ui5implements = findAllTags(classParsedJsDoc, "implements")
68
+ .map(tag => getReference(ts, normalizeTagType(tag.type), classNode, moduleDoc.path))
69
+ .filter(Boolean);
70
+
71
+
72
+ if (hasTag(classParsedJsDoc, "extends")) {
73
+ const superclassTag = findTag(classParsedJsDoc, "extends");
74
+ currClass.superclass = getReference(ts, superclassTag.name, classNode, moduleDoc.path);
75
+
76
+ if (currClass.superclass?.name === "UI5Element") {
77
+ currClass.customElement = true;
78
+ }
79
+ }
80
+
81
+ if (!currClass._ui5implements.length) delete currClass._ui5implements;
82
+
83
+ // Slots
84
+
85
+ // Slots without accessort (defined in class comment)
86
+ if (hasTag(classParsedJsDoc, "slot") && currClass.slots) {
87
+ const slotTags = findAllTags(classParsedJsDoc, "slot");
88
+
89
+ currClass.slots.forEach(slot => {
90
+ const tag = slotTags.find(tag => tag.name === slot.name);
91
+
92
+ const typeRefs = (normalizeTagType(tag.type)
93
+ ?.replaceAll(/Array<|>|\[\]/g, "")
94
+ ?.split("|")
95
+ ?.map(e => getReference(ts, e.trim(), classNode, moduleDoc.path)).filter(Boolean));
96
+
97
+ slot._ui5privacy = "public";
98
+ slot._ui5type = { text: formatArrays(normalizeTagType(tag.type)) };
99
+ slot.description = normalizeDescription(tag.description)
100
+
101
+ if (typeRefs && typeRefs.length) {
102
+ slot._ui5type.references = typeRefs;
103
+ }
104
+
105
+ delete slot.type
106
+ })
107
+ }
108
+
109
+ // Events
110
+ currClass.events = findAllDecorators(classNode, "event")
111
+ ?.map(event => processEvent(ts, event, classNode, moduleDoc));
112
+
113
+ // Slots (with accessor), methods and fields
114
+ for (let i = 0; i < (currClass.members?.length || 0); i++) {
115
+ const member = currClass.members[i];
116
+ const classNodeMember = classNode.members?.find(nodeMember => nodeMember.name?.text === member?.name && nodeMember.jsDoc?.[0]);
117
+ const classNodeMemberJSdoc = classNodeMember?.jsDoc?.[0];
118
+
119
+ if (!classNodeMember || !classNodeMemberJSdoc) continue;
120
+
121
+ const memberParsedJsDoc = parse(classNodeMemberJSdoc?.getText())[0];
122
+
123
+ member._ui5since = getSinceStatus(memberParsedJsDoc);
124
+ member.deprecated === "true" && (member.deprecated = true)
125
+
126
+ // Slots with accessors are treated like fields by the tool, so we have to convert them into slots.
127
+ if (member.kind === "field") {
128
+ const slotDecorator = findDecorator(classNodeMember, "slot");
129
+ validateJSDocComment(slotDecorator ? "slot" : (member.readonly ? "getter" : "field"), memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
130
+
131
+ const typeRefs = (getTypeRefs(ts, classNodeMember, member)
132
+ ?.map(e => getReference(ts, e, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
133
+
134
+ if (member.type?.text) {
135
+ member.type.text = formatArrays(member.type.text);
136
+ }
137
+
138
+ if (member.type && typeRefs.length) {
139
+ member.type.references = typeRefs;
140
+ }
141
+
142
+ if (slotDecorator) {
143
+ if (!currClass.slots) currClass.slots = [];
144
+
145
+ const slot = currClass.members.splice(i, 1)[0];
146
+ const defaultProperty = slotDecorator.expression?.arguments?.[0]?.properties?.find(property => property.name.text === "default");
147
+
148
+ // name of the default slot declared with decorator will be overriden so we to provide it's accessor name
149
+ if (defaultProperty && defaultProperty.initializer?.kind === ts.SyntaxKind.TrueKeyword) {
150
+ slot._ui5propertyName = slot.name;
151
+ slot.name = "default";
152
+ }
153
+
154
+ // Slots don't have type, privacy and kind, so we have do convert them and to clean unused props
155
+ member._ui5type = member.type;
156
+ member._ui5privacy = member.privacy;
157
+ delete member.type;
158
+ delete member.privacy;
159
+ delete slot.kind;
160
+
161
+ currClass.slots.push(slot);
162
+ i--;
163
+ } else {
164
+ const propertyDecorator = findDecorator(classNodeMember, "property");
165
+
166
+ if (propertyDecorator) {
167
+ member._ui5validator = propertyDecorator?.expression?.arguments[0]?.properties?.find(property => ["validator", "type"].includes(property.name.text))?.initializer?.text || "String";
168
+ }
169
+
170
+ if (hasTag(memberParsedJsDoc, "formProperty")) {
171
+ member._ui5formProperty = true;
172
+ }
173
+
174
+ const formEventsTag = findTag(memberParsedJsDoc, "formEvents");
175
+ if (formEventsTag) {
176
+ const tagValue = formEventsTag.description ? `${formEventsTag.name} ${formEventsTag.description}` : formEventsTag.name;
177
+ member._ui5formEvents = tagValue.trim().replaceAll(/\s+/g, ",");
178
+ }
179
+
180
+ const defaultTag = findTag(memberParsedJsDoc, "default");
181
+ if (defaultTag) {
182
+ const tagValue = defaultTag.source?.[0]?.tokens?.name || defaultTag.source?.[0]?.tokens?.description || defaultTag.source?.[0]?.tokens?.type || "";
183
+ member.default = tagValue;
184
+ }
185
+
186
+ if (member.privacy === "public") {
187
+ const JSDocErrors = getJSDocErrors();
188
+
189
+ if (!member.default) {
190
+ JSDocErrors.push(
191
+ `=== ERROR: Problem found with ${member.name}'s JSDoc comment in ${moduleDoc.path}: Default value is missing`
192
+ );
193
+ }
194
+ }
195
+
196
+ // Getters are treated as fields so they should not have return, instead of return they should have default value defined with @default
197
+ if (member.readonly) {
198
+ if (member.privacy === "public" && !member.type) {
199
+ const JSDocErrors = getJSDocErrors();
200
+
201
+ JSDocErrors.push(
202
+ `=== ERROR: Problem found with ${member.name}'s JSDoc comment in ${moduleDoc.path}: Missing return type`
203
+ );
204
+ }
205
+
206
+ delete member.return;
207
+ }
208
+ }
209
+ } else if (member.kind === "method") {
210
+ validateJSDocComment("method", memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
211
+
212
+ member.parameters?.forEach(param => {
213
+ // Treat every parameter that has respective @param tag as public
214
+ param._ui5privacy = findAllTags(memberParsedJsDoc, "param").some(tag => tag.name === param.name) ? "public" : "private";
215
+ if (param._ui5privacy === "public") {
216
+ const paramNode = classNodeMember.parameters?.find(parameter => parameter.name?.text === param.name);
217
+ let type;
218
+
219
+ if (param.optional) {
220
+ const filename = classNode.getSourceFile().fileName;
221
+
222
+ const sourceFile = typeProgram.getSourceFile(filename);
223
+ const tsProgramClassNode = sourceFile.statements.find(statement => ts.isClassDeclaration(statement) && statement.name?.text === classNode.name?.text);
224
+ const tsProgramMember = tsProgramClassNode.members.find(m => ts.isMethodDeclaration(m) && m.name?.text === member.name);
225
+ const tsProgramParameter = tsProgramMember.parameters.find(p => ts.isParameter(p) && p.name?.text === param.name);
226
+
227
+ if (tsProgramParameter) {
228
+ const typeName = typeChecker.typeToString(typeChecker.getTypeAtLocation(tsProgramParameter), tsProgramParameter);
229
+
230
+ if (!param.type) {
231
+ param.type = {};
232
+ param.type.text = typeName;
233
+ }
234
+
235
+ type = typeName.replaceAll(/Array<|>|\[\]/g, "")
236
+ ?.split("|");
237
+ }
238
+ }
239
+
240
+ const typeRefs = ((type || getTypeRefs(ts, (type || paramNode), param))
241
+ ?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
242
+
243
+ if (typeRefs.length) {
244
+ param.type.references = typeRefs;
245
+ }
246
+ }
247
+ });
248
+
249
+ if (member.return) {
250
+ const returnTag = findTag(memberParsedJsDoc, "returns");
251
+ member.return.description = returnTag?.description ? `${returnTag.name} ${returnTag.description}` : returnTag?.name;
252
+ member.return.type.text = classNodeMember?.type?.getFullText?.()?.trim();
253
+ const typeRefs = (getTypeRefs(ts, classNodeMember, member.return)
254
+ ?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
255
+
256
+ if (typeRefs.length) {
257
+ member.return.type.references = typeRefs;
258
+ }
259
+ }
260
+
261
+ if (member.privacy === "public" && !member.return) {
262
+ const JSDocErrors = getJSDocErrors();
263
+
264
+ JSDocErrors.push(
265
+ `=== ERROR: Problem found with ${member.name}'s JSDoc comment in ${moduleDoc.path}: Missing return type`
266
+ );
267
+ }
268
+ }
269
+ }
270
+ }
271
+
272
+ function processInterface(ts, interfaceNode, moduleDoc) {
273
+ const interfaceJSdoc = interfaceNode?.jsDoc?.[0];
274
+ const interfaceName = interfaceNode?.name?.text;
275
+
276
+ if (!interfaceJSdoc) return;
277
+
278
+ const interfaceParsedJsDoc = parse(interfaceJSdoc?.getText(), { spacing: 'preserve' })[0];
279
+
280
+ validateJSDocComment("interface", interfaceParsedJsDoc, interfaceNode.name?.text, moduleDoc);
281
+
282
+ moduleDoc.declarations.push({
283
+ kind: "interface",
284
+ name: interfaceName,
285
+ description: normalizeDescription(interfaceParsedJsDoc?.description),
286
+ _ui5privacy: getPrivacyStatus(interfaceParsedJsDoc),
287
+ _ui5since: getSinceStatus(interfaceParsedJsDoc),
288
+ deprecated: getDeprecatedStatus(interfaceParsedJsDoc),
289
+ });
290
+ }
291
+
292
+ function processEnum(ts, enumNode, moduleDoc) {
293
+ const enumJSdoc = enumNode?.jsDoc?.[0];
294
+ const enumName = enumNode?.name?.text;
295
+
296
+ if (!enumJSdoc) return;
297
+
298
+ const enumParsedJsDoc = parse(enumJSdoc?.getText(), { spacing: 'preserve' })[0];
299
+
300
+ validateJSDocComment("enum", enumParsedJsDoc, enumNode.name?.text, moduleDoc);
301
+
302
+ const result = {
303
+ kind: "enum",
304
+ name: enumName,
305
+ description: normalizeDescription(enumJSdoc?.comment),
306
+ _ui5privacy: getPrivacyStatus(enumParsedJsDoc),
307
+ _ui5since: getSinceStatus(enumParsedJsDoc),
308
+ deprecated: getDeprecatedStatus(enumParsedJsDoc) || undefined,
309
+ members: (enumNode?.members || []).map(member => {
310
+ const memberJSdoc = member?.jsDoc?.[0];
311
+
312
+ if (!memberJSdoc) return;
313
+
314
+ const memberParsedJsDoc = parse(memberJSdoc?.getText())[0];
315
+
316
+ validateJSDocComment("enum", memberParsedJsDoc, member.name?.text, moduleDoc);
317
+
318
+ return {
319
+ kind: "field",
320
+ static: true,
321
+ privacy: getPrivacyStatus(memberParsedJsDoc),
322
+ _ui5since: getSinceStatus(memberParsedJsDoc),
323
+ description: memberJSdoc?.comment,
324
+ default: member.initializer?.text,
325
+ deprecated: getDeprecatedStatus(memberParsedJsDoc),
326
+ name: member.name?.text,
327
+ readonly: true,
328
+ };
329
+ }).filter(Boolean),
330
+ };
331
+
332
+ moduleDoc.declarations.push(result);
333
+ }
334
+
335
+ const processPublicAPI = object => {
336
+ if (!object) {
337
+ return true;
338
+ }
339
+ const keys = Object.keys(object);
340
+ if (!keys.includes("privacy") && !keys.includes("_ui5privacy")) {
341
+ return true;
342
+ }
343
+ for (const key of keys) {
344
+ if ((key === "privacy" && object[key] !== "public") || (key === "_ui5privacy" && object[key] !== "public")) {
345
+ return true;
346
+ } else if (typeof object[key] === "object") {
347
+ if (key === "cssParts" || key === "_ui5implements") {
348
+ continue;
349
+ }
350
+
351
+ if (Array.isArray(object[key])) {
352
+ for (let i = 0; i < object[key].length; i++) {
353
+ const shouldRemove = processPublicAPI(object[key][i]);
354
+ if (shouldRemove) {
355
+ object[key].splice(i, 1);
356
+ i--;
357
+ }
358
+ }
359
+ if (object[key].length === 0) {
360
+ delete object[key];
361
+ }
362
+ }
363
+ }
364
+ }
365
+ return false;
366
+ };
367
+
368
+ let typeChecker;
369
+ let typeProgram;
370
+
371
+ export default {
372
+ globs: ["src/!(*generated)/*.ts", "src/!(*bundle)*.ts"],
373
+ outdir: 'dist',
374
+ overrideModuleCreation: ({ ts, globs }) => {
375
+ typeProgram = ts.createProgram(globs, {
376
+ noEmitOnError: false,
377
+ allowJs: true,
378
+ experimentalDecorators: true,
379
+ target: 99,
380
+ downlevelIteration: true,
381
+ module: 99,
382
+ strictNullChecks: true,
383
+ moduleResolution: 2,
384
+ esModuleInterop: true,
385
+ noEmit: true,
386
+ pretty: true,
387
+ allowSyntheticDefaultImports: true,
388
+ allowUnreachableCode: true,
389
+ allowUnusedLabels: true,
390
+ skipLibCheck: true,
391
+ });
392
+ typeChecker = typeProgram.getTypeChecker();
393
+
394
+ return globs.map((glob) => {
395
+ const fullPath = path.resolve(process.cwd(), glob);
396
+ const source = fs.readFileSync(fullPath).toString();
397
+
398
+ return ts.createSourceFile(glob, source, ts.ScriptTarget.ES2015, true);
399
+ });
400
+ },
401
+ plugins: [
402
+ {
403
+ name: 'my-plugin',
404
+ analyzePhase({ ts, node, moduleDoc }) {
405
+ switch (true) {
406
+ case ts.isClassDeclaration(node):
407
+ processClass(ts, node, moduleDoc);
408
+ break;
409
+ case ts.isEnumDeclaration(node):
410
+ processEnum(ts, node, moduleDoc);
411
+ break;
412
+ case ts.isInterfaceDeclaration(node):
413
+ processInterface(ts, node, moduleDoc);
414
+ break;
415
+ }
416
+ },
417
+ moduleLinkPhase({ moduleDoc }) {
418
+ for (let i = 0; i < moduleDoc.declarations.length; i++) {
419
+ const shouldRemove = processPublicAPI(moduleDoc.declarations[i]) || ["function", "variable"].includes(moduleDoc.declarations[i].kind)
420
+ if (shouldRemove) {
421
+ moduleDoc.declarations.splice(i, 1);
422
+ i--;
423
+ }
424
+ }
425
+
426
+ moduleDoc.path = moduleDoc.path?.replace(/^src/, "dist").replace(/\.ts$/, ".js");
427
+
428
+ if (moduleDoc.exports) {
429
+ moduleDoc.exports = moduleDoc.exports.
430
+ filter(e => !(e.kind === "custom-element-definition" && !moduleDoc.declarations?.find(d => d.name === e.name)?.tagName))
431
+
432
+ moduleDoc.exports?.forEach(e => {
433
+ const classNode = moduleDoc.declarations.find(c => c.name === e.declaration.name);
434
+
435
+ if (e.declaration && e.declaration.module) {
436
+ e.declaration.module = e.declaration.module.replace(/^src/, "dist").replace(/\.ts$/, ".js");
437
+ }
438
+
439
+ if (classNode?.customElement && classNode.tagName && e.kind !== "custom-element-definition") {
440
+ moduleDoc.exports.push({
441
+ kind: "custom-element-definition",
442
+ name: classNode.tagName,
443
+ declaration: {
444
+ name: e.declaration.name,
445
+ module: e.declaration.module
446
+ }
447
+ })
448
+ }
449
+ })
450
+ }
451
+
452
+ const typeReferences = new Set();
453
+ const registerTypeReference = reference => typeReferences.add(JSON.stringify(reference))
454
+
455
+ moduleDoc.declarations.forEach(declaration => {
456
+ ["events", "slots", "members"].forEach(memberType => {
457
+ declaration[memberType]?.forEach(member => {
458
+ if (member.type?.references) {
459
+ member.type.references.forEach(registerTypeReference)
460
+ } else if (member._ui5type?.references) {
461
+ member._ui5type.references.forEach(registerTypeReference)
462
+ } else if (member.kind === "method") {
463
+ member.return?.type?.references?.forEach(registerTypeReference)
464
+
465
+ member.parameters?.forEach(parameter => {
466
+ parameter.type?.references?.forEach(registerTypeReference)
467
+ })
468
+ }
469
+ })
470
+ })
471
+ });
472
+
473
+ for (let reference in typeReferences) {
474
+ reference = JSON.parse(reference);
475
+
476
+ if (reference.package === packageJSON?.name && reference.module === moduleDoc.path) {
477
+ const hasExport = moduleDoc.exports.some(e => e.declaration?.name === reference.name && e.declaration?.module === reference.module)
478
+
479
+ if (!hasExport) {
480
+ const JSDocErrors = getJSDocErrors();
481
+ JSDocErrors.push(
482
+ `=== ERROR: Problem found with ${reference.name} type reference in ${moduleDoc.path?.replace(/^dist/, "src").replace(/\.js$/, ".ts")}: \n\t- ${reference.name} is used as type of public API, but it's not exported`)
483
+ }
484
+ }
485
+ }
486
+ },
487
+ packageLinkPhase({ context }) {
488
+ if (context.dev) {
489
+ const JSDocErrors = getJSDocErrors();
490
+ if (JSDocErrors.length > 0) {
491
+ console.log(JSDocErrors.join("\n"));
492
+ console.log(`Invalid JSDoc. ${JSDocErrors.length} were found.`);
493
+ throw new Error(`Invalid JSDoc.`);
494
+ }
495
+ }
496
+ }
497
+ },
498
+ ],
499
+ };
@@ -0,0 +1,135 @@
1
+ import { parse } from "comment-parser";
2
+ import {
3
+ getPrivacyStatus,
4
+ getDeprecatedStatus,
5
+ getSinceStatus,
6
+ getType,
7
+ getTypeRefs,
8
+ validateJSDocComment,
9
+ hasTag,
10
+ findTag,
11
+ findAllTags,
12
+ getReference,
13
+ normalizeDescription,
14
+ normalizeTagType,
15
+ getJSDocErrors
16
+ } from "./utils.mjs";
17
+
18
+ const jsDocRegExp = /\/\*\*(.|\n)+?\s+\*\//;
19
+
20
+ const getParams = (ts, eventDetails, commentParams, classNode, moduleDoc) => {
21
+ return commentParams?.map(commentParam => {
22
+ const decoratorParam = eventDetails?.find(prop => prop?.name?.text === commentParam?.name);
23
+
24
+ if (!decoratorParam || !decoratorParam?.jsDoc?.[0]) {
25
+ return;
26
+ }
27
+
28
+ const decoratorParamParsedComment = parse(decoratorParam?.jsDoc?.[0]?.getText?.(), { spacing: 'preserve' })[0];
29
+
30
+ validateJSDocComment("eventParam", decoratorParamParsedComment, decoratorParam.name?.text, moduleDoc);
31
+
32
+ const { typeName, name } = getType(normalizeTagType(commentParam?.type));
33
+ let type;
34
+
35
+ if (typeName) {
36
+ type = { text: typeName };
37
+
38
+ let typeRefs = name?.split("|")
39
+ ?.map(e => getReference(ts, e.trim(), classNode, moduleDoc.path))
40
+ .filter(Boolean);
41
+
42
+ if (typeRefs?.length) {
43
+ type.references = typeRefs;
44
+ }
45
+ }
46
+
47
+ return {
48
+ type,
49
+ name: commentParam?.name,
50
+ _ui5privacy: getPrivacyStatus(decoratorParamParsedComment),
51
+ description: normalizeDescription(commentParam?.description),
52
+ _ui5since: getSinceStatus(decoratorParamParsedComment),
53
+ deprecated: getDeprecatedStatus(decoratorParamParsedComment),
54
+ };
55
+ }).filter(pair => !!pair);
56
+ };
57
+
58
+ function processEvent(ts, event, classNode, moduleDoc) {
59
+ const name = event?.expression?.arguments?.[0]?.text;
60
+ const result = {
61
+ name,
62
+ _ui5privacy: "private",
63
+ type: { text: "CustomEvent" }
64
+ };
65
+
66
+ const comment = event.getFullText?.().match(jsDocRegExp)?.[0];
67
+
68
+ if (!comment) {
69
+ return result;
70
+ }
71
+
72
+ const eventParsedComment = parse(comment, { spacing: 'preserve' })[0];
73
+
74
+ validateJSDocComment("event", eventParsedComment, name, moduleDoc);
75
+
76
+ const deprecatedTag = findTag(eventParsedComment, "deprecated");
77
+ const privacy = findTag(eventParsedComment, ["public", "private", "protected"])?.tag || "private";
78
+ const sinceTag = findTag(eventParsedComment, "since");
79
+ const commentParams = findAllTags(eventParsedComment, "param");
80
+ const allowPreventDefault = hasTag(eventParsedComment, "allowPreventDefault") || undefined;
81
+ const description = normalizeDescription(eventParsedComment?.description);
82
+ const native = hasTag(eventParsedComment, "native");
83
+ const eventDetails = event?.expression?.arguments?.[1]?.properties?.find(prop => prop?.name?.text === "detail")?.initializer?.properties;
84
+
85
+ if (event?.expression?.arguments?.[1] && !event?.expression?.typeArguments) {
86
+ const JSDocErrors = getJSDocErrors();
87
+
88
+ JSDocErrors.push(
89
+ `=== ERROR: Problem found with ${name}'s description in ${moduleDoc.path}: \n\t- Event details have to be described with type via generics type passed to the decorator ( @event<TypeForDetails>("example-name", {details}) ) `
90
+ );
91
+ }
92
+
93
+ result.description = description;
94
+ result._ui5allowPreventDefault = allowPreventDefault;
95
+
96
+ if (native) {
97
+ result.type = { text: "Event" };
98
+ } else if (event?.expression?.typeArguments) {
99
+ const typesText = event?.expression?.typeArguments.map(type => type.typeName?.text).filter(Boolean).join(" | ");
100
+ const typeRefs = (getTypeRefs(ts, event.expression)
101
+ ?.map(e => getReference(ts, e, event, moduleDoc.path)).filter(Boolean)) || [];
102
+
103
+ result.type = { text: `CustomEvent<${typesText}>` };
104
+
105
+ if (typeRefs.length) {
106
+ result.type.references = typeRefs;
107
+ }
108
+ }
109
+
110
+ if (privacy) {
111
+ result._ui5privacy = privacy;
112
+ }
113
+
114
+ if (deprecatedTag?.name) {
115
+ result.deprecated = deprecatedTag.description
116
+ ? `${deprecatedTag.name} ${deprecatedTag.description}`
117
+ : deprecatedTag.name;
118
+ } else if (deprecatedTag) {
119
+ result.deprecated = true;
120
+ }
121
+
122
+ if (sinceTag?.name) {
123
+ result._ui5since = sinceTag?.description
124
+ ? `${sinceTag.name} ${sinceTag.description}`
125
+ : sinceTag.name;
126
+ }
127
+
128
+ if (commentParams && eventDetails) {
129
+ result._ui5parameters = getParams(ts, eventDetails, commentParams, classNode, moduleDoc);
130
+ }
131
+
132
+ return result;
133
+ }
134
+
135
+ export default processEvent;