@ui5/webcomponents-tools 0.0.0-037d08c67

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 (124) hide show
  1. package/CHANGELOG.md +2474 -0
  2. package/LICENSE.txt +201 -0
  3. package/README.md +21 -0
  4. package/assets-meta.js +154 -0
  5. package/bin/create-ui5-element.js +3 -0
  6. package/bin/dev.js +22 -0
  7. package/bin/ui5nps.js +301 -0
  8. package/components-package/eslint.js +195 -0
  9. package/components-package/nps.js +177 -0
  10. package/components-package/postcss.components.js +1 -0
  11. package/components-package/postcss.themes.js +1 -0
  12. package/components-package/vite.config.js +9 -0
  13. package/components-package/wdio.js +421 -0
  14. package/icons-collection/nps.js +80 -0
  15. package/lib/amd-to-es6/index.js +109 -0
  16. package/lib/amd-to-es6/no-remaining-require.js +33 -0
  17. package/lib/cem/cem.js +16 -0
  18. package/lib/cem/custom-elements-manifest.config.mjs +575 -0
  19. package/lib/cem/event.mjs +168 -0
  20. package/lib/cem/patch/@custom-elements-manifest/analyzer/cli.js +128 -0
  21. package/lib/cem/patch/@custom-elements-manifest/analyzer/package.json +59 -0
  22. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/browser-entrypoint.js +23 -0
  23. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/create.js +117 -0
  24. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/arrow-function.js +26 -0
  25. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/class-jsdoc.js +157 -0
  26. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/classes.js +20 -0
  27. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createArrowFunction.js +17 -0
  28. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createAttribute.js +24 -0
  29. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createClass.js +301 -0
  30. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createClassField.js +26 -0
  31. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createFunctionLike.js +73 -0
  32. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createMixin.js +33 -0
  33. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createVariable.js +22 -0
  34. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/handlers.js +338 -0
  35. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/custom-elements-define-calls.js +90 -0
  36. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/exports.js +156 -0
  37. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/function-like.js +24 -0
  38. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/mixins.js +29 -0
  39. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/reexported-wrapped-mixin-exports.js +84 -0
  40. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/variables.js +34 -0
  41. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/collect-phase/collect-imports.js +101 -0
  42. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst/catalyst.js +11 -0
  43. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst/controller.js +34 -0
  44. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst-major-2/catalyst.js +11 -0
  45. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst-major-2/controller.js +34 -0
  46. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/decorators/attr.js +53 -0
  47. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/decorators/custom-element-decorator.js +36 -0
  48. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/fast/fast.js +7 -0
  49. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/lit.js +13 -0
  50. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/member-denylist.js +21 -0
  51. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/method-denylist.js +20 -0
  52. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/property-decorator.js +94 -0
  53. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/static-properties.js +121 -0
  54. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/utils.js +66 -0
  55. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/stencil/stencil.js +129 -0
  56. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/index.js +80 -0
  57. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/link-phase/cleanup-classes.js +25 -0
  58. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/link-phase/field-denylist.js +22 -0
  59. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/link-phase/method-denylist.js +25 -0
  60. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/apply-inheritance.js +78 -0
  61. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/is-custom-element.js +34 -0
  62. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/link-class-to-tagname.js +27 -0
  63. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/remove-unexported-declarations.js +23 -0
  64. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/resolve-initializers.js +52 -0
  65. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/ast-helpers.js +186 -0
  66. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/cli-helpers.js +164 -0
  67. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/exports.js +44 -0
  68. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/find-external-manifests.js +67 -0
  69. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/imports.js +25 -0
  70. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/index.js +71 -0
  71. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/jsdoc.js +19 -0
  72. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/manifest-helpers.js +194 -0
  73. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/mixins.js +112 -0
  74. package/lib/cem/schema-internal.json +1422 -0
  75. package/lib/cem/schema.json +1098 -0
  76. package/lib/cem/types-internal.d.ts +808 -0
  77. package/lib/cem/types.d.ts +736 -0
  78. package/lib/cem/utils.mjs +429 -0
  79. package/lib/cem/validate.js +81 -0
  80. package/lib/chokidar/chokidar.js +28 -0
  81. package/lib/copy-and-watch/index.js +158 -0
  82. package/lib/copy-list/index.js +36 -0
  83. package/lib/create-icons/index.js +131 -0
  84. package/lib/create-illustrations/index.js +210 -0
  85. package/lib/create-new-component/Component.js +74 -0
  86. package/lib/create-new-component/ComponentTemplate.js +12 -0
  87. package/lib/create-new-component/index.js +115 -0
  88. package/lib/css-processors/css-processor-components.mjs +101 -0
  89. package/lib/css-processors/css-processor-themes.mjs +121 -0
  90. package/lib/css-processors/postcss-plugin.mjs +153 -0
  91. package/lib/css-processors/scope-variables.mjs +51 -0
  92. package/lib/css-processors/shared.mjs +47 -0
  93. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  94. package/lib/dev-server/dev-server.mjs +78 -0
  95. package/lib/dev-server/virtual-index-html-plugin.js +56 -0
  96. package/lib/eslint/eslint.js +44 -0
  97. package/lib/generate-js-imports/illustrations.js +87 -0
  98. package/lib/generate-json-imports/i18n.js +93 -0
  99. package/lib/generate-json-imports/themes.js +75 -0
  100. package/lib/hbs2lit/index.js +3 -0
  101. package/lib/hbs2lit/src/compiler.js +60 -0
  102. package/lib/hbs2lit/src/extendedAttributeMapping.js +12 -0
  103. package/lib/hbs2lit/src/includesReplacer.js +31 -0
  104. package/lib/hbs2lit/src/litVisitor2.js +278 -0
  105. package/lib/hbs2lit/src/partials2.js +51 -0
  106. package/lib/hbs2lit/src/partialsVisitor.js +187 -0
  107. package/lib/hbs2lit/src/svgProcessor.js +76 -0
  108. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +45 -0
  109. package/lib/hbs2ui5/index.js +119 -0
  110. package/lib/i18n/defaults.js +90 -0
  111. package/lib/i18n/toJSON.js +71 -0
  112. package/lib/icons-hash/icons-hash.mjs +149 -0
  113. package/lib/postcss-combine-duplicated-selectors/index.js +185 -0
  114. package/lib/remove-dev-mode/remove-dev-mode.mjs +51 -0
  115. package/lib/rimraf/rimraf.js +31 -0
  116. package/lib/scoping/get-all-tags.js +44 -0
  117. package/lib/scoping/lint-src.js +32 -0
  118. package/lib/scoping/missing-dependencies.js +65 -0
  119. package/lib/scoping/report-tags-usage.js +28 -0
  120. package/lib/scoping/scope-test-pages.js +41 -0
  121. package/lib/test-runner/test-runner.js +79 -0
  122. package/lib/vite-bundler/vite-bundler.mjs +35 -0
  123. package/package.json +86 -0
  124. package/tsconfig.json +18 -0
@@ -0,0 +1,575 @@
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
+ getExperimentalStatus,
8
+ getSinceStatus,
9
+ getPrivacyStatus,
10
+ getReference,
11
+ validateJSDocComment,
12
+ findDecorator,
13
+ findAllDecorators,
14
+ hasTag,
15
+ findTag,
16
+ findAllTags,
17
+ getTypeRefs,
18
+ normalizeDescription,
19
+ formatArrays,
20
+ formatSlotTypes,
21
+ isClass,
22
+ normalizeTagType,
23
+ logDocumentationError,
24
+ displayDocumentationErrors,
25
+ toKebabCase
26
+ } from "./utils.mjs";
27
+ import { generateCustomData } from "cem-plugin-vs-code-custom-data-generator";
28
+ import { customElementJetBrainsPlugin } from "custom-element-jet-brains-integration";
29
+
30
+ const packageJSON = JSON.parse(fs.readFileSync("./package.json"));
31
+ let aliasMap = {};
32
+
33
+ const devMode = process.env.UI5_CEM_MODE === "dev";
34
+ const isVerbose = process.env.UI5_VERBOSE === "true";
35
+
36
+ /**
37
+ * Wraps a CEM plugin to suppress console output in quiet mode.
38
+ * @param {Object} plugin - The plugin to wrap
39
+ * @returns {Object} - Wrapped plugin with silent console during packageLinkPhase
40
+ */
41
+ const wrapPluginForQuietMode = (plugin) => {
42
+ if (isVerbose) return plugin;
43
+
44
+ const originalPackageLinkPhase = plugin.packageLinkPhase;
45
+ if (!originalPackageLinkPhase) return plugin;
46
+
47
+ return {
48
+ ...plugin,
49
+ packageLinkPhase(context) {
50
+ const originalLog = console.log;
51
+ console.log = () => {};
52
+ try {
53
+ return originalPackageLinkPhase.call(plugin, context);
54
+ } finally {
55
+ console.log = originalLog;
56
+ }
57
+ }
58
+ };
59
+ };
60
+
61
+ try {
62
+ aliasMap = JSON.parse(fs.readFileSync("./.ui5-cem-aliases.json"));
63
+ } catch (e) {
64
+ if (devMode && isVerbose) {
65
+ console.warn("No .ui5-cem-aliases.json file found. Continuing without aliases.");
66
+ }
67
+ }
68
+
69
+
70
+ const extractClassNodeJSDoc = node => {
71
+ const fileContent = node.getFullText();
72
+ const allJSDocsRegExp = new RegExp(`\\/\\*\\*(.|\\n)+?\\s+\\*\\/`, "gm");
73
+ let allJSDocs = [...fileContent.matchAll(allJSDocsRegExp)];
74
+ allJSDocs = allJSDocs.map(match => match[0]); // all /** ..... */ comments
75
+
76
+ // Find where the class is defined in the original file
77
+ const tsClassDefinitionRegExp = new RegExp(`^\\s*(abstract\\s*)?class [\\w\\d_]+`, "gm");
78
+ let tsClassDefinitionMatch = fileContent.match(tsClassDefinitionRegExp);
79
+ if (!tsClassDefinitionMatch) {
80
+ return; // no class defined in this .ts file
81
+ }
82
+ const tsClassDefinition = tsClassDefinitionMatch[0];
83
+ const tsClassDefinitionIndex = fileContent.indexOf(tsClassDefinition);
84
+
85
+ return allJSDocs.find(JSDoc => {
86
+ return isClass(JSDoc) && (fileContent.indexOf(JSDoc) < tsClassDefinitionIndex)
87
+ });
88
+ }
89
+
90
+ function processClass(ts, classNode, moduleDoc) {
91
+ const className = classNode?.name?.text;
92
+ const currClass = moduleDoc?.declarations?.find(declaration => declaration?.name === className);
93
+ const currClassJSdoc = extractClassNodeJSDoc(classNode);
94
+
95
+ if (!currClassJSdoc) return;
96
+
97
+ const customElementDecorator = findDecorator(classNode, "customElement");
98
+ const classParsedJsDoc = parse(currClassJSdoc, { spacing: 'preserve' })[0];
99
+
100
+ validateJSDocComment("class", classParsedJsDoc, classNode.name?.text, moduleDoc);
101
+
102
+ const decoratorArg = customElementDecorator?.expression?.arguments[0];
103
+ currClass.tagName = decoratorArg?.text || (decoratorArg?.properties.find(property => property.name.text === "tag")?.initializer?.text);
104
+ currClass.customElement = !!customElementDecorator || className === "UI5Element" || undefined;
105
+ currClass.kind = "class";
106
+ currClass.deprecated = getDeprecatedStatus(classParsedJsDoc);
107
+ currClass._ui5experimental = getExperimentalStatus(classParsedJsDoc);
108
+ currClass._ui5since = getSinceStatus(classParsedJsDoc);
109
+ currClass._ui5privacy = getPrivacyStatus(classParsedJsDoc);
110
+ currClass._ui5abstract = hasTag(classParsedJsDoc, "abstract") ? true : undefined;
111
+ currClass.description = normalizeDescription(classParsedJsDoc.description || findTag(classParsedJsDoc, "class")?.description);
112
+ currClass._ui5implements = findAllTags(classParsedJsDoc, "implements")
113
+ .map(tag => {
114
+ const correctInterfaceDescription = classNode?.heritageClauses?.some(heritageClause => {
115
+ return heritageClause?.types?.some(type => type.expression?.text === normalizeTagType(tag.type));
116
+ });
117
+
118
+ if (!correctInterfaceDescription) {
119
+ logDocumentationError(moduleDoc.path, `@interface {${tag.type}} tag is used, but the class doesn't implement the corresponding interface`)
120
+ }
121
+
122
+ return getReference(ts, normalizeTagType(tag.type), classNode, moduleDoc.path)
123
+ })
124
+ .filter(Boolean);
125
+
126
+
127
+ if (hasTag(classParsedJsDoc, "extends")) {
128
+ const superclassTag = findTag(classParsedJsDoc, "extends");
129
+ currClass.superclass = getReference(ts, superclassTag.name, classNode, moduleDoc.path);
130
+
131
+ if (classNode?.heritageClauses?.[0]?.types?.[0]?.expression?.text !== superclassTag.name) {
132
+ logDocumentationError(moduleDoc.path, `@extends ${superclassTag.name} is used, but the class doesn't extend the corresponding superclass`)
133
+ }
134
+
135
+ if (currClass.superclass?.name === "UI5Element") {
136
+ currClass.customElement = true;
137
+ }
138
+ }
139
+
140
+ if (!currClass._ui5implements.length) delete currClass._ui5implements;
141
+
142
+ // Slots
143
+
144
+ // Slots without accessort (defined in class comment)
145
+ if (hasTag(classParsedJsDoc, "slot") && currClass.slots) {
146
+ const slotTags = findAllTags(classParsedJsDoc, "slot");
147
+
148
+ currClass.slots.forEach(slot => {
149
+ const tag = slotTags.find(tag => tag.name === slot.name);
150
+
151
+ const typeRefs = (normalizeTagType(tag.type)
152
+ ?.replaceAll(/Array<|>|\[\]/g, "")
153
+ ?.split("|")
154
+ ?.map(e => getReference(ts, e.trim(), classNode, moduleDoc.path)).filter(Boolean));
155
+
156
+ slot._ui5privacy = "public";
157
+ slot._ui5type = { text: formatArrays(normalizeTagType(tag.type)) };
158
+ slot.description = normalizeDescription(tag.description)
159
+
160
+ if (typeRefs && typeRefs.length) {
161
+ slot._ui5type.references = typeRefs;
162
+ }
163
+
164
+ delete slot.type
165
+ })
166
+ }
167
+
168
+ // Events
169
+ currClass.events = findAllDecorators(classNode, ["event", "eventStrict"])
170
+ ?.map(event => processEvent(ts, event, classNode, moduleDoc));
171
+
172
+ const filename = classNode.getSourceFile().fileName;
173
+ const sourceFile = typeProgram.getSourceFile(filename);
174
+ const tsProgramClassNode = sourceFile.statements.find(statement => ts.isClassDeclaration(statement) && statement.name?.text === classNode.name?.text);
175
+
176
+ // Slots (with accessor), methods and fields
177
+ for (let i = 0; i < (currClass.members?.length || 0); i++) {
178
+ const member = currClass.members[i];
179
+ const classNodeMember = classNode.members?.find(nodeMember => nodeMember.name?.text === member?.name && nodeMember.jsDoc?.[0]);
180
+ const classNodeMemberJSdoc = classNodeMember?.jsDoc?.[0];
181
+
182
+ if (!classNodeMember || !classNodeMemberJSdoc) continue;
183
+
184
+ const memberParsedJsDoc = parse(classNodeMemberJSdoc?.getText())[0];
185
+
186
+ member._ui5since = getSinceStatus(memberParsedJsDoc);
187
+ member.deprecated === "true" && (member.deprecated = true)
188
+
189
+ // Slots with accessors are treated like fields by the tool, so we have to convert them into slots.
190
+ if (member.kind === "field") {
191
+ const slotDecorator = findDecorator(classNodeMember, "slot");
192
+ validateJSDocComment(slotDecorator ? "slot" : (member.readonly ? "getter" : "field"), memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
193
+
194
+ const typeRefs = (getTypeRefs(ts, classNodeMember, member)
195
+ ?.map(e => getReference(ts, e, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
196
+
197
+ if (member.type?.text) {
198
+ member.type.text = formatArrays(member.type.text);
199
+ member.type.text = formatSlotTypes(member.type.text);
200
+ }
201
+
202
+ if (member.type && typeRefs.length) {
203
+ member.type.references = typeRefs;
204
+ }
205
+
206
+ if (slotDecorator) {
207
+ if (!currClass.slots) currClass.slots = [];
208
+
209
+ const slot = currClass.members.splice(i, 1)[0];
210
+ const defaultProperty = slotDecorator.expression?.arguments?.[0]?.properties?.find(property => property.name.text === "default");
211
+
212
+ // name of the default slot declared with decorator will be overriden so we to provide it's accessor name
213
+ if (defaultProperty && defaultProperty.initializer?.kind === ts.SyntaxKind.TrueKeyword) {
214
+ slot._ui5propertyName = slot.name;
215
+ slot.name = "default";
216
+ }
217
+
218
+ // Slots don't have type, privacy and kind, so we have do convert them and to clean unused props
219
+ member._ui5type = member.type;
220
+ member._ui5privacy = member.privacy;
221
+ delete member.type;
222
+ delete member.privacy;
223
+ delete slot.kind;
224
+
225
+ currClass.slots.push(slot);
226
+ i--;
227
+ } else {
228
+ const propertyDecorator = findDecorator(classNodeMember, "property");
229
+
230
+ if (propertyDecorator) {
231
+ member._ui5noAttribute = propertyDecorator?.expression?.arguments[0]?.properties?.find(property => property.name.text === "noAttribute")?.initializer?.kind === ts.SyntaxKind.TrueKeyword || undefined;
232
+ }
233
+
234
+ if (currClass.customElement && member.privacy === "public") {
235
+ const tsProgramMember = tsProgramClassNode.members.find(m => ts.isPropertyDeclaration(m) && m.name?.text === member.name);
236
+ const attributeValue = typeChecker.typeToString(typeChecker.getTypeAtLocation(tsProgramMember), tsProgramMember);
237
+
238
+ if (attributeValue === "boolean" && member.default === "true") {
239
+ logDocumentationError(moduleDoc.path, `Boolean properties must be initialzed to false. [${member.name}] property of class [${className}] is intialized to \`true\``)
240
+ }
241
+
242
+ if (!member.type) {
243
+ logDocumentationError(moduleDoc.path, `Public properties must have type. The type of [${member.name}] property is not determinated automatically. Please check it.`)
244
+ }
245
+
246
+ currClass.attributes.push({
247
+ description: member.description,
248
+ name: toKebabCase(member.name),
249
+ default: member.default,
250
+ fieldName: member.name,
251
+ type: { text: attributeValue },
252
+ deprecated: member.deprecated
253
+ })
254
+ }
255
+
256
+ if (hasTag(memberParsedJsDoc, "formProperty")) {
257
+ member._ui5formProperty = true;
258
+ }
259
+
260
+ const formEventsTag = findTag(memberParsedJsDoc, "formEvents");
261
+ if (formEventsTag) {
262
+ const tagValue = formEventsTag.description ? `${formEventsTag.name} ${formEventsTag.description}` : formEventsTag.name;
263
+ member._ui5formEvents = tagValue.trim().replaceAll(/\s+/g, ",");
264
+ }
265
+
266
+ const defaultTag = findTag(memberParsedJsDoc, "default");
267
+ if (defaultTag) {
268
+ const tagValue = defaultTag.source?.[0]?.tokens?.name || defaultTag.source?.[0]?.tokens?.description || defaultTag.source?.[0]?.tokens?.type || "";
269
+ member.default = tagValue;
270
+ }
271
+
272
+ if (member.privacy === "public" && !member.default) {
273
+ logDocumentationError(moduleDoc.path, `Missing default value for '${member.name}'.`)
274
+ }
275
+
276
+ // Getters are treated as fields so they should not have return, instead of return they should have default value defined with @default
277
+ if (member.readonly) {
278
+ if (member.privacy === "public" && !member.type) {
279
+ logDocumentationError(moduleDoc.path, `Missing return type for read-only field '${member.name}'.`)
280
+ }
281
+
282
+ delete member.return;
283
+ }
284
+ }
285
+ } else if (member.kind === "method") {
286
+ validateJSDocComment("method", memberParsedJsDoc, classNodeMember.name?.text, moduleDoc);
287
+
288
+ member.parameters?.forEach(param => {
289
+ // Treat every parameter that has respective @param tag as public
290
+ param._ui5privacy = findAllTags(memberParsedJsDoc, "param").some(tag => tag.name === param.name) ? "public" : "private";
291
+ if (param._ui5privacy === "public") {
292
+ const paramNode = classNodeMember.parameters?.find(parameter => parameter.name?.text === param.name);
293
+ let type;
294
+
295
+ if (param.optional) {
296
+ const filename = classNode.getSourceFile().fileName;
297
+
298
+ const sourceFile = typeProgram.getSourceFile(filename);
299
+ const tsProgramClassNode = sourceFile.statements.find(statement => ts.isClassDeclaration(statement) && statement.name?.text === classNode.name?.text);
300
+ const tsProgramMember = tsProgramClassNode.members.find(m => ts.isMethodDeclaration(m) && m.name?.text === member.name);
301
+ const tsProgramParameter = tsProgramMember.parameters.find(p => ts.isParameter(p) && p.name?.text === param.name);
302
+
303
+ if (tsProgramParameter) {
304
+ const typeName = typeChecker.typeToString(typeChecker.getTypeAtLocation(tsProgramParameter), tsProgramParameter);
305
+
306
+ if (!param.type) {
307
+ param.type = {};
308
+ param.type.text = typeName;
309
+ }
310
+
311
+ type = typeName.replaceAll(/Array<|>|\[\]/g, "")
312
+ ?.split("|");
313
+ }
314
+ }
315
+
316
+ const typeRefs = ((type || getTypeRefs(ts, (type || paramNode), param))
317
+ ?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
318
+
319
+ if (typeRefs.length) {
320
+ param.type.references = typeRefs;
321
+ }
322
+ }
323
+ });
324
+
325
+ if (member.return) {
326
+ const returnTag = findTag(memberParsedJsDoc, "returns");
327
+ member.return.description = returnTag?.description ? `${returnTag.name} ${returnTag.description}` : returnTag?.name;
328
+ member.return.type.text = formatArrays(classNodeMember?.type?.getFullText?.()?.trim());
329
+ const typeRefs = (getTypeRefs(ts, classNodeMember, member.return)
330
+ ?.map(typeRef => getReference(ts, typeRef, classNodeMember, moduleDoc.path)).filter(Boolean)) || [];
331
+
332
+ if (typeRefs.length) {
333
+ member.return.type.references = typeRefs;
334
+ }
335
+
336
+ if (member.privacy === "public" && !member.return.type.text) {
337
+ logDocumentationError(moduleDoc.path, `Missing return type for function '${member.name}'.`)
338
+ }
339
+ } else if (member.privacy === "public") {
340
+ logDocumentationError(moduleDoc.path, `Missing return type for function '${member.name}'.`)
341
+ }
342
+ }
343
+ }
344
+ }
345
+
346
+ function processInterface(ts, interfaceNode, moduleDoc) {
347
+ const interfaceJSdoc = interfaceNode?.jsDoc?.[0];
348
+ const interfaceName = interfaceNode?.name?.text;
349
+
350
+ if (!interfaceJSdoc) return;
351
+
352
+ const interfaceParsedJsDoc = parse(interfaceJSdoc?.getText(), { spacing: 'preserve' })[0];
353
+
354
+ validateJSDocComment("interface", interfaceParsedJsDoc, interfaceNode.name?.text, moduleDoc);
355
+
356
+ moduleDoc.declarations.push({
357
+ kind: "interface",
358
+ name: interfaceName,
359
+ description: normalizeDescription(interfaceParsedJsDoc?.description),
360
+ _ui5experimental: getExperimentalStatus(interfaceParsedJsDoc),
361
+ _ui5privacy: getPrivacyStatus(interfaceParsedJsDoc),
362
+ _ui5since: getSinceStatus(interfaceParsedJsDoc),
363
+ deprecated: getDeprecatedStatus(interfaceParsedJsDoc),
364
+ });
365
+ }
366
+
367
+ function processEnum(ts, enumNode, moduleDoc) {
368
+ const enumJSdoc = enumNode?.jsDoc?.[0];
369
+ const enumName = enumNode?.name?.text;
370
+
371
+ if (!enumJSdoc) return;
372
+
373
+ const enumParsedJsDoc = parse(enumJSdoc?.getText(), { spacing: 'preserve' })[0];
374
+
375
+ validateJSDocComment("enum", enumParsedJsDoc, enumNode.name?.text, moduleDoc);
376
+
377
+ const result = {
378
+ kind: "enum",
379
+ name: enumName,
380
+ description: normalizeDescription(enumJSdoc?.comment),
381
+ _ui5experimental: getExperimentalStatus(enumParsedJsDoc),
382
+ _ui5privacy: getPrivacyStatus(enumParsedJsDoc),
383
+ _ui5since: getSinceStatus(enumParsedJsDoc),
384
+ deprecated: getDeprecatedStatus(enumParsedJsDoc) || undefined,
385
+ members: (enumNode?.members || []).map(member => {
386
+ const memberJSdoc = member?.jsDoc?.[0];
387
+
388
+ if (!memberJSdoc) return;
389
+
390
+ const memberParsedJsDoc = parse(memberJSdoc?.getText())[0];
391
+
392
+ validateJSDocComment("enum", memberParsedJsDoc, member.name?.text, moduleDoc);
393
+
394
+ return {
395
+ kind: "field",
396
+ static: true,
397
+ privacy: getPrivacyStatus(memberParsedJsDoc),
398
+ _ui5since: getSinceStatus(memberParsedJsDoc),
399
+ description: memberJSdoc?.comment,
400
+ default: member.initializer?.text,
401
+ deprecated: getDeprecatedStatus(memberParsedJsDoc),
402
+ name: member.name?.text,
403
+ readonly: true,
404
+ };
405
+ }).filter(Boolean),
406
+ };
407
+
408
+ moduleDoc.declarations.push(result);
409
+ }
410
+
411
+ const processPublicAPI = object => {
412
+ if (!object) {
413
+ return true;
414
+ }
415
+ const keys = Object.keys(object);
416
+ if (!keys.includes("privacy") && !keys.includes("_ui5privacy")) {
417
+ return true;
418
+ }
419
+ for (const key of keys) {
420
+ if ((key === "privacy" && object[key] !== "public") || (key === "_ui5privacy" && object[key] !== "public")) {
421
+ return true;
422
+ } else if (typeof object[key] === "object") {
423
+ if (key === "cssParts" || key === "attributes" || key === "_ui5implements") {
424
+ continue;
425
+ }
426
+
427
+ if (Array.isArray(object[key])) {
428
+ for (let i = 0; i < object[key].length; i++) {
429
+ const shouldRemove = processPublicAPI(object[key][i]);
430
+ if (shouldRemove) {
431
+ object[key].splice(i, 1);
432
+ i--;
433
+ }
434
+ }
435
+ if (object[key].length === 0) {
436
+ delete object[key];
437
+ }
438
+ }
439
+ }
440
+ }
441
+ return false;
442
+ };
443
+
444
+ let typeChecker;
445
+ let typeProgram;
446
+
447
+ export default {
448
+ globs: ["src/!(*generated)/*.ts", "src/!(*bundle)*.ts"],
449
+ outdir: 'dist',
450
+ overrideModuleCreation: ({ ts, globs }) => {
451
+ typeProgram = ts.createProgram(globs, {
452
+ noEmitOnError: false,
453
+ allowJs: true,
454
+ experimentalDecorators: true,
455
+ target: 99,
456
+ downlevelIteration: true,
457
+ module: 99,
458
+ strictNullChecks: true,
459
+ moduleResolution: 2,
460
+ esModuleInterop: true,
461
+ noEmit: true,
462
+ pretty: true,
463
+ allowSyntheticDefaultImports: true,
464
+ allowUnreachableCode: true,
465
+ allowUnusedLabels: true,
466
+ skipLibCheck: true,
467
+ });
468
+ typeChecker = typeProgram.getTypeChecker();
469
+
470
+ return globs.map((glob) => {
471
+ const fullPath = path.resolve(process.cwd(), glob);
472
+ const source = fs.readFileSync(fullPath).toString();
473
+
474
+ return ts.createSourceFile(glob, source, ts.ScriptTarget.ES2015, true);
475
+ });
476
+ },
477
+ plugins: [
478
+ {
479
+ name: 'my-plugin',
480
+ analyzePhase({ ts, node, moduleDoc }) {
481
+ switch (true) {
482
+ case ts.isClassDeclaration(node):
483
+ processClass(ts, node, moduleDoc);
484
+ break;
485
+ case ts.isEnumDeclaration(node):
486
+ processEnum(ts, node, moduleDoc);
487
+ break;
488
+ case ts.isInterfaceDeclaration(node):
489
+ processInterface(ts, node, moduleDoc);
490
+ break;
491
+ }
492
+ },
493
+ moduleLinkPhase({ moduleDoc }) {
494
+ moduleDoc.path = moduleDoc.path?.replace(/^src/, "dist").replace(/\.ts$/, ".js");
495
+
496
+ moduleDoc.exports = moduleDoc.exports.
497
+ filter(e => !(e.kind === "custom-element-definition" && !moduleDoc.declarations?.find(d => d.name === e.name)?.tagName))
498
+
499
+ moduleDoc.exports.forEach(e => {
500
+ const classNode = moduleDoc.declarations.find(c => c.name === e.declaration.name);
501
+
502
+ if (e.declaration && e.declaration.module) {
503
+ e.declaration.module = e.declaration.module.replace(/^src/, "dist").replace(/\.ts$/, ".js");
504
+ }
505
+
506
+ if (classNode?.customElement && classNode.tagName && e.kind !== "custom-element-definition") {
507
+ moduleDoc.exports.push({
508
+ kind: "custom-element-definition",
509
+ name: classNode.tagName,
510
+ declaration: {
511
+ name: e.declaration.name,
512
+ module: e.declaration.module
513
+ }
514
+ })
515
+ }
516
+ })
517
+ },
518
+ packageLinkPhase({ customElementsManifest }) {
519
+ customElementsManifest.modules.forEach(moduleDoc => {
520
+ for (let i = 0; i < moduleDoc.declarations.length; i++) {
521
+ const shouldRemove = processPublicAPI(moduleDoc.declarations[i]) || ["function", "variable"].includes(moduleDoc.declarations[i].kind)
522
+ if (shouldRemove) {
523
+ moduleDoc.declarations.splice(i, 1);
524
+ i--;
525
+ }
526
+ }
527
+
528
+ moduleDoc.declarations.forEach(declaration => {
529
+ if (declaration.superclass?.name && aliasMap[declaration.superclass.name]) {
530
+ declaration.superclass.name = aliasMap[declaration.superclass.name];
531
+ }
532
+ })
533
+
534
+ const typeReferences = new Set();
535
+ const registerTypeReference = reference => typeReferences.add(JSON.stringify(reference))
536
+
537
+ moduleDoc.declarations.forEach(declaration => {
538
+ ["events", "slots", "members"].forEach(memberType => {
539
+ declaration[memberType]?.forEach(member => {
540
+ if (member.type?.references) {
541
+ member.type.references.forEach(registerTypeReference)
542
+ } else if (member._ui5type?.references) {
543
+ member._ui5type.references.forEach(registerTypeReference)
544
+ } else if (member.kind === "method") {
545
+ member.return?.type?.references?.forEach(registerTypeReference)
546
+
547
+ member.parameters?.forEach(parameter => {
548
+ parameter.type?.references?.forEach(registerTypeReference)
549
+ })
550
+ }
551
+ })
552
+ })
553
+ });
554
+
555
+ typeReferences.forEach(reference => {
556
+ reference = JSON.parse(reference);
557
+ if (reference.package === packageJSON?.name && reference.module === moduleDoc.path) {
558
+ const hasExport = moduleDoc.exports.some(e => e.declaration?.name === reference.name && e.declaration?.module === reference.module)
559
+
560
+ if (!hasExport) {
561
+ logDocumentationError(moduleDoc.path?.replace(/^dist/, "src").replace(/\.js$/, ".ts"), `Type '${reference.name}' is used to describe a public API but is not exported.`,)
562
+ }
563
+ }
564
+ })
565
+ });
566
+
567
+ if (devMode) {
568
+ displayDocumentationErrors();
569
+ }
570
+ }
571
+ },
572
+ wrapPluginForQuietMode(generateCustomData({ outdir: "dist", cssFileName: null, cssPropertiesDocs: false })),
573
+ wrapPluginForQuietMode(customElementJetBrainsPlugin({ outdir: "dist", cssFileName: null, cssPropertiesDocs: false }))
574
+ ],
575
+ };