@ui5/webcomponents-tools 0.0.0-07460127d → 0.0.0-093de5dd1

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 (161) hide show
  1. package/CHANGELOG.md +2440 -1
  2. package/LICENSE.txt +201 -0
  3. package/README.md +7 -10
  4. package/assets-meta.js +154 -0
  5. package/bin/dev.js +13 -1
  6. package/bin/ui5nps.js +274 -0
  7. package/components-package/eslint.js +66 -2
  8. package/components-package/nps.js +147 -48
  9. package/components-package/postcss.components.js +1 -21
  10. package/components-package/postcss.themes.js +1 -23
  11. package/components-package/vite.config.js +9 -0
  12. package/components-package/wdio.js +161 -73
  13. package/icons-collection/nps.js +80 -28
  14. package/lib/amd-to-es6/index.js +107 -0
  15. package/lib/amd-to-es6/no-remaining-require.js +33 -0
  16. package/lib/cem/cem.js +12 -0
  17. package/lib/cem/custom-elements-manifest.config.mjs +546 -0
  18. package/lib/cem/event.mjs +168 -0
  19. package/lib/cem/merge.mjs +220 -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 +423 -0
  79. package/lib/cem/validate.js +76 -0
  80. package/lib/chokidar/chokidar.js +28 -0
  81. package/lib/copy-and-watch/index.js +153 -0
  82. package/lib/copy-list/index.js +34 -0
  83. package/lib/create-icons/index.js +131 -54
  84. package/lib/create-illustrations/index.js +204 -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 +66 -93
  88. package/lib/css-processors/css-processor-components.mjs +92 -0
  89. package/lib/css-processors/css-processor-themes.mjs +102 -0
  90. package/lib/css-processors/scope-variables.mjs +49 -0
  91. package/lib/css-processors/shared.mjs +46 -0
  92. package/lib/dev-server/custom-hot-update-plugin.js +39 -0
  93. package/lib/dev-server/dev-server.mjs +78 -0
  94. package/lib/dev-server/virtual-index-html-plugin.js +56 -0
  95. package/lib/eslint/eslint.js +44 -0
  96. package/lib/generate-js-imports/illustrations.js +85 -0
  97. package/lib/generate-json-imports/i18n.js +91 -47
  98. package/lib/generate-json-imports/themes.js +63 -19
  99. package/lib/hbs2lit/index.js +2 -4
  100. package/lib/hbs2lit/src/compiler.js +30 -9
  101. package/lib/hbs2lit/src/includesReplacer.js +23 -17
  102. package/lib/hbs2lit/src/litVisitor2.js +125 -26
  103. package/lib/hbs2lit/src/svgProcessor.js +12 -5
  104. package/lib/hbs2ui5/RenderTemplates/LitRenderer.js +40 -7
  105. package/lib/hbs2ui5/index.js +69 -30
  106. package/lib/i18n/defaults.js +79 -46
  107. package/lib/i18n/toJSON.js +54 -16
  108. package/lib/icons-hash/icons-hash.mjs +149 -0
  109. package/lib/postcss-combine-duplicated-selectors/index.js +185 -0
  110. package/lib/remove-dev-mode/remove-dev-mode.mjs +51 -0
  111. package/lib/rimraf/rimraf.js +31 -0
  112. package/lib/scoping/get-all-tags.js +44 -0
  113. package/lib/scoping/lint-src.js +32 -0
  114. package/lib/scoping/missing-dependencies.js +65 -0
  115. package/lib/scoping/report-tags-usage.js +28 -0
  116. package/lib/scoping/scope-test-pages.js +41 -0
  117. package/lib/test-runner/test-runner.js +79 -0
  118. package/lib/vite-bundler/vite-bundler.mjs +35 -0
  119. package/package.json +64 -60
  120. package/tsconfig.json +18 -0
  121. package/bin/init-ui5-package.js +0 -3
  122. package/components-package/rollup.js +0 -134
  123. package/components-package/serve.json +0 -3
  124. package/lib/documentation/index.js +0 -143
  125. package/lib/documentation/templates/api-component-since.js +0 -3
  126. package/lib/documentation/templates/api-css-variables-section.js +0 -24
  127. package/lib/documentation/templates/api-events-section.js +0 -35
  128. package/lib/documentation/templates/api-methods-section.js +0 -26
  129. package/lib/documentation/templates/api-properties-section.js +0 -40
  130. package/lib/documentation/templates/api-slots-section.js +0 -28
  131. package/lib/documentation/templates/template.js +0 -38
  132. package/lib/init-package/index.js +0 -119
  133. package/lib/init-package/resources/.eslintignore +0 -3
  134. package/lib/init-package/resources/bundle.es5.js +0 -25
  135. package/lib/init-package/resources/bundle.esm.js +0 -34
  136. package/lib/init-package/resources/config/.eslintrc.js +0 -1
  137. package/lib/init-package/resources/config/postcss.components/postcss.config.js +0 -1
  138. package/lib/init-package/resources/config/postcss.themes/postcss.config.js +0 -1
  139. package/lib/init-package/resources/config/rollup.config.js +0 -1
  140. package/lib/init-package/resources/config/wdio.conf.js +0 -1
  141. package/lib/init-package/resources/package-scripts.js +0 -11
  142. package/lib/init-package/resources/src/Assets.js +0 -6
  143. package/lib/init-package/resources/src/Demo.hbs +0 -1
  144. package/lib/init-package/resources/src/Demo.js +0 -56
  145. package/lib/init-package/resources/src/i18n/messagebundle.properties +0 -2
  146. package/lib/init-package/resources/src/i18n/messagebundle_de.properties +0 -1
  147. package/lib/init-package/resources/src/i18n/messagebundle_en.properties +0 -1
  148. package/lib/init-package/resources/src/i18n/messagebundle_es.properties +0 -1
  149. package/lib/init-package/resources/src/i18n/messagebundle_fr.properties +0 -1
  150. package/lib/init-package/resources/src/themes/Demo.css +0 -11
  151. package/lib/init-package/resources/src/themes/sap_belize/parameters-bundle.css +0 -3
  152. package/lib/init-package/resources/src/themes/sap_belize_hcb/parameters-bundle.css +0 -3
  153. package/lib/init-package/resources/src/themes/sap_fiori_3/parameters-bundle.css +0 -3
  154. package/lib/init-package/resources/src/themes/sap_fiori_3_dark/parameters-bundle.css +0 -3
  155. package/lib/init-package/resources/test/pages/index.html +0 -51
  156. package/lib/init-package/resources/test/specs/Demo.spec.js +0 -12
  157. package/lib/jsdoc/config.json +0 -29
  158. package/lib/jsdoc/plugin.js +0 -2407
  159. package/lib/jsdoc/template/publish.js +0 -4092
  160. package/lib/postcss-css-to-esm/index.js +0 -33
  161. package/lib/postcss-css-to-json/index.js +0 -20
@@ -0,0 +1,73 @@
1
+ import ts from 'typescript';
2
+ import { has } from '../../../utils/index.js';
3
+ import { handleModifiers, handleJsDoc } from './handlers.js';
4
+
5
+ /**
6
+ * Creates a functionLike, does _not_ handle arrow functions
7
+ */
8
+ export function createFunctionLike(node) {
9
+ let functionLikeTemplate = {
10
+ kind: '',
11
+ name: node?.name?.getText() || ''
12
+ };
13
+
14
+ functionLikeTemplate = handleKind(functionLikeTemplate, node);
15
+ functionLikeTemplate = handleModifiers(functionLikeTemplate, node);
16
+ functionLikeTemplate = handleParametersAndReturnType(functionLikeTemplate, node);
17
+ functionLikeTemplate = handleJsDoc(functionLikeTemplate, node);
18
+
19
+ return functionLikeTemplate;
20
+ }
21
+
22
+ /**
23
+ * Determine the kind of the functionLike, either `'function'` or `'method'`
24
+ */
25
+ export function handleKind(functionLike, node) {
26
+ switch(node.kind) {
27
+ case ts.SyntaxKind.FunctionDeclaration:
28
+ functionLike.kind = 'function';
29
+ break;
30
+ case ts.SyntaxKind.MethodDeclaration:
31
+ functionLike.kind = 'method';
32
+ break;
33
+ }
34
+ return functionLike;
35
+ }
36
+
37
+ /**
38
+ * Handle a functionLikes return type and parameters/parameter types
39
+ */
40
+ export function handleParametersAndReturnType(functionLike, node) {
41
+ if(node?.type) {
42
+ functionLike.return = {
43
+ type: { text: node.type.getText() }
44
+ }
45
+ }
46
+
47
+ const parameters = [];
48
+ node?.parameters?.forEach((param) => {
49
+ const parameter = {
50
+ name: param.name.getText(),
51
+ }
52
+
53
+ if(param?.initializer) {
54
+ parameter.default = param.initializer.getText();
55
+ }
56
+
57
+ if(param?.questionToken) {
58
+ parameter.optional = true;
59
+ }
60
+
61
+ if(param?.type) {
62
+ parameter.type = {text: param.type.getText() }
63
+ }
64
+
65
+ parameters.push(parameter);
66
+ });
67
+
68
+ if(has(parameters)) {
69
+ functionLike.parameters = parameters;
70
+ }
71
+
72
+ return functionLike;
73
+ }
@@ -0,0 +1,33 @@
1
+ import { createClass } from './createClass.js';
2
+ import { handleParametersAndReturnType } from './createFunctionLike.js';
3
+ import { handleJsDoc } from './handlers.js';
4
+
5
+ /**
6
+ * Takes a mixinFunctionNode, which is the function/arrow function containing the mixin class
7
+ * and the actual class node returned by the mixin declaration
8
+ */
9
+ export function createMixin(mixinFunctionNode, mixinClassNode, moduleDoc, context) {
10
+ let mixinTemplate = createClass(mixinClassNode, moduleDoc, context);
11
+
12
+ mixinTemplate = handleParametersAndReturnType(mixinTemplate, mixinFunctionNode?.declarationList?.declarations?.[0]?.initializer || mixinFunctionNode);
13
+ mixinTemplate = handleJsDoc(mixinTemplate, mixinFunctionNode);
14
+ mixinTemplate = handleName(mixinTemplate, mixinFunctionNode);
15
+ mixinTemplate = turnClassDocIntoMixin(mixinTemplate);
16
+
17
+ return mixinTemplate;
18
+ }
19
+
20
+ export function handleName(mixin, node) {
21
+ mixin.name = node?.name?.getText() || node?.parent?.name?.getText() || node?.declarationList?.declarations?.[0]?.name?.getText() || '';
22
+ return mixin;
23
+ }
24
+
25
+ /**
26
+ * Turns a classDoc into a mixin
27
+ */
28
+ function turnClassDocIntoMixin(mixin) {
29
+ mixin.kind = 'mixin';
30
+ delete mixin.superclass;
31
+ delete mixin.return;
32
+ return mixin;
33
+ }
@@ -0,0 +1,22 @@
1
+ import {
2
+ handleDefaultValue,
3
+ handleExplicitType,
4
+ handleJsDoc,
5
+ handleTypeInference,
6
+ handleWellKnownTypes
7
+ } from './handlers.js';
8
+
9
+ export function createVariable(variableStatementNode, declarationNode) {
10
+ let variableTemplate = {
11
+ kind: 'variable',
12
+ name: declarationNode?.name?.getText() || ''
13
+ };
14
+
15
+ variableTemplate = handleTypeInference(variableTemplate, declarationNode);
16
+ variableTemplate = handleExplicitType(variableTemplate, declarationNode);
17
+ variableTemplate = handleWellKnownTypes(variableTemplate, declarationNode);
18
+ variableTemplate = handleDefaultValue(variableTemplate, declarationNode);
19
+ variableTemplate = handleJsDoc(variableTemplate, variableStatementNode);
20
+
21
+ return variableTemplate;
22
+ }
@@ -0,0 +1,338 @@
1
+ import ts from 'typescript';
2
+ import { parse } from 'comment-parser';
3
+
4
+ import { has, resolveModuleOrPackageSpecifier, safe } from '../../../utils/index.js';
5
+ import { handleJsDocType, normalizeDescription } from '../../../utils/jsdoc.js';
6
+ import { isWellKnownType } from '../../../utils/ast-helpers.js';
7
+
8
+ /**
9
+ * @example static foo;
10
+ * @example public foo;
11
+ * @example private foo;
12
+ * @example protected foo;
13
+ */
14
+ export function handleModifiers(doc, node) {
15
+ node?.modifiers?.forEach(modifier => {
16
+ if(modifier?.kind === ts.SyntaxKind.StaticKeyword) {
17
+ doc.static = true;
18
+ }
19
+
20
+ if (modifier?.kind === ts.SyntaxKind.ReadonlyKeyword) {
21
+ doc.readonly = true;
22
+ }
23
+
24
+ switch (modifier.kind) {
25
+ case ts.SyntaxKind.PublicKeyword:
26
+ doc.privacy = 'public';
27
+ break;
28
+ case ts.SyntaxKind.PrivateKeyword:
29
+ doc.privacy = 'private';
30
+ break;
31
+ case ts.SyntaxKind.ProtectedKeyword:
32
+ doc.privacy = 'protected';
33
+ break;
34
+ }
35
+ });
36
+
37
+ if (node.name?.text?.startsWith('#')) {
38
+ doc.privacy = 'private';
39
+ }
40
+
41
+ return doc;
42
+ }
43
+
44
+ /**
45
+ * Handles JsDoc
46
+ */
47
+ export function handleJsDoc(doc, node) {
48
+ node?.jsDoc?.forEach(jsDocComment => {
49
+ if(jsDocComment?.comment) {
50
+ if(has(jsDocComment?.comment)) {
51
+ doc.description = jsDocComment.comment.map(com => `${safe(() => com?.name?.getText()) ?? ''}${com.text}`).join('');
52
+ } else {
53
+ doc.description = normalizeDescription(jsDocComment.comment);
54
+ }
55
+ }
56
+
57
+ jsDocComment?.tags?.forEach(tag => {
58
+ /** @readonly */
59
+ if(tag.kind === ts.SyntaxKind.JSDocReadonlyTag) {
60
+ doc.readonly = true;
61
+ }
62
+
63
+ /** @param */
64
+ if(tag.kind === ts.SyntaxKind.JSDocParameterTag) {
65
+ const parameter = doc?.parameters?.find(parameter => parameter.name === tag.name.text);
66
+ const parameterAlreadyExists = !!parameter;
67
+ const parameterTemplate = parameter || {};
68
+
69
+ if(tag?.comment) {
70
+ parameterTemplate.description = normalizeDescription(tag.comment);
71
+ }
72
+
73
+ if(tag?.name) {
74
+ parameterTemplate.name = tag.name.getText();
75
+ }
76
+
77
+ /**
78
+ * If its bracketed, that means its optional
79
+ * @example [foo]
80
+ */
81
+ if(tag?.isBracketed) {
82
+ parameterTemplate.optional = true;
83
+ }
84
+
85
+ if(tag?.typeExpression) {
86
+ parameterTemplate.type = {
87
+ text: handleJsDocType(tag.typeExpression.type.getText())
88
+ }
89
+ }
90
+
91
+ if(!parameterAlreadyExists) {
92
+ doc.parameters = [...(doc?.parameters || []), parameterTemplate];
93
+ }
94
+ }
95
+
96
+ /** @returns */
97
+ if(tag.kind === ts.SyntaxKind.JSDocReturnTag) {
98
+ doc.return = {
99
+ type: {
100
+ text: handleJsDocType(tag?.typeExpression?.type?.getText())
101
+ }
102
+ }
103
+ }
104
+
105
+ /** @type */
106
+ if(tag.kind === ts.SyntaxKind.JSDocTypeTag) {
107
+ if(tag?.comment) {
108
+ doc.description = normalizeDescription(tag.comment);
109
+ }
110
+
111
+ doc.type = {
112
+ text: handleJsDocType(tag.typeExpression.type.getText())
113
+ }
114
+ }
115
+
116
+ /** @reflect */
117
+ if(safe(() => tag?.tagName?.getText()) === 'reflect' && doc?.kind === 'field') {
118
+ doc.reflects = true;
119
+ }
120
+
121
+ /** @summary */
122
+ if(safe(() => tag?.tagName?.getText()) === 'summary') {
123
+ doc.summary = tag.comment;
124
+ }
125
+
126
+ /** @deprecated */
127
+ if(safe(() => tag?.tagName?.getText()) === 'deprecated') {
128
+ doc.deprecated = tag.comment || "true";
129
+ }
130
+
131
+ /** @default */
132
+ if (safe(() => tag?.tagName?.getText()) === 'default' && doc?.kind === 'field') {
133
+ doc.default ??= tag.comment;
134
+ }
135
+
136
+ /**
137
+ * Overwrite privacy
138
+ * @public
139
+ * @private
140
+ * @protected
141
+ */
142
+ switch(tag.kind) {
143
+ case ts.SyntaxKind.JSDocPublicTag:
144
+ doc.privacy = 'public';
145
+ break;
146
+ case ts.SyntaxKind.JSDocPrivateTag:
147
+ doc.privacy = 'private';
148
+ break;
149
+ case ts.SyntaxKind.JSDocProtectedTag:
150
+ doc.privacy = 'protected';
151
+ break;
152
+ }
153
+ });
154
+ });
155
+
156
+ return doc;
157
+ }
158
+
159
+
160
+
161
+ /**
162
+ * Creates a mixin for inside a classDoc
163
+ */
164
+ export function createClassDeclarationMixin(name, moduleDoc, context) {
165
+ const mixin = {
166
+ name,
167
+ ...resolveModuleOrPackageSpecifier(moduleDoc, context, name)
168
+ };
169
+ return mixin;
170
+ }
171
+
172
+ /**
173
+ * Handles mixins and superclass
174
+ */
175
+ export function handleHeritage(classTemplate, moduleDoc, context, node) {
176
+ node?.heritageClauses?.forEach((clause) => {
177
+ /* Ignoring `ImplementsKeyword` for now, future revisions may retrieve docs per-field for the implemented methods. */
178
+ if (clause.token !== ts.SyntaxKind.ExtendsKeyword) return;
179
+
180
+ clause?.types?.forEach((type) => {
181
+ const mixins = [];
182
+ let node = type.expression;
183
+ let superClass;
184
+
185
+ /* gather mixin calls */
186
+ if (ts.isCallExpression(node)) {
187
+ const mixinName = node.expression.getText();
188
+ mixins.push(createClassDeclarationMixin(mixinName, moduleDoc, context))
189
+ while (ts.isCallExpression(node.arguments[0])) {
190
+ node = node.arguments[0];
191
+ const mixinName = node.expression.getText();
192
+ mixins.push(createClassDeclarationMixin(mixinName, moduleDoc, context));
193
+ }
194
+ superClass = node.arguments[0].text;
195
+ } else {
196
+ superClass = node.text;
197
+ }
198
+
199
+ if (has(mixins)) {
200
+ classTemplate.mixins = mixins;
201
+ }
202
+
203
+ classTemplate.superclass = {
204
+ name: superClass,
205
+ ...resolveModuleOrPackageSpecifier(moduleDoc, context, superClass)
206
+ };
207
+
208
+ if(superClass === 'HTMLElement') {
209
+ delete classTemplate.superclass.module;
210
+ }
211
+ });
212
+ });
213
+
214
+ return classTemplate;
215
+ }
216
+
217
+ /**
218
+ * Handles fields that have an @attr jsdoc annotation and gets the attribute name (if specified) and the description
219
+ * @example @attr my-attr this is the attr description
220
+ */
221
+ export function handleAttrJsDoc(node, doc) {
222
+ node?.jsDoc?.forEach(jsDoc => {
223
+ const docs = parse(jsDoc?.getFullText())?.find(doc => doc?.tags?.some(({tag}) => ["attribute", "attr"].includes(tag)));
224
+ const attrTag = docs?.tags?.find(({tag}) => ["attribute", "attr"].includes(tag));
225
+
226
+ if(attrTag?.name) {
227
+ doc.name = attrTag.name;
228
+ }
229
+
230
+ if(attrTag?.description) {
231
+ doc.description = normalizeDescription(attrTag.description);
232
+ }
233
+ });
234
+
235
+ return doc;
236
+ }
237
+
238
+ export function handleTypeInference(doc, node) {
239
+ const n = node?.initializer || node;
240
+ switch(n?.kind) {
241
+ case ts.SyntaxKind.TrueKeyword:
242
+ case ts.SyntaxKind.FalseKeyword:
243
+ doc.type = { text: "boolean" }
244
+ break;
245
+ case ts.SyntaxKind.StringLiteral:
246
+ doc.type = { text: "string" }
247
+ break;
248
+ case ts.SyntaxKind.PrefixUnaryExpression:
249
+ doc.type = n?.operator === ts.SyntaxKind.ExclamationToken ? { text: "boolean" } : { text: "number" };
250
+ break;
251
+ case ts.SyntaxKind.NumericLiteral:
252
+ doc.type = { text: "number" }
253
+ break;
254
+ case ts.SyntaxKind.NullKeyword:
255
+ doc.type = { text: "null" }
256
+ break;
257
+ case ts.SyntaxKind.ArrayLiteralExpression:
258
+ doc.type = { text: "array" }
259
+ break;
260
+ case ts.SyntaxKind.ObjectLiteralExpression:
261
+ doc.type = { text: "object" }
262
+ break;
263
+ }
264
+ return doc;
265
+ }
266
+
267
+ /**
268
+ * For `as const` and namespace/enum types
269
+ * @example class A { b = 'b' as const }
270
+ * @example class A { b = B.b }
271
+ */
272
+ export function handleWellKnownTypes(doc, node) {
273
+ if (!!node.initializer?.expression) {
274
+ const text = node?.initializer?.expression?.getText();
275
+ if (isWellKnownType(node)) {
276
+ doc.type = { text };
277
+ }
278
+ }
279
+ return doc;
280
+ }
281
+
282
+ export function handleDefaultValue(doc, node, expression) {
283
+ /**
284
+ * In case of a class field node?.initializer
285
+ * In case of a property assignment in constructor node?.expression?.right
286
+ */
287
+ const initializer = node?.initializer || expression?.right;
288
+
289
+ /** Ignore the following */
290
+ if(initializer?.kind === ts.SyntaxKind.BinaryExpression) return doc;
291
+ if(initializer?.kind === ts.SyntaxKind.ConditionalExpression) return doc;
292
+ if(initializer?.kind === ts.SyntaxKind.PropertyAccessExpression) return doc;
293
+ if(initializer?.kind === ts.SyntaxKind.CallExpression) return doc;
294
+ if(initializer?.kind === ts.SyntaxKind.ArrowFunction) return doc;
295
+
296
+ let defaultValue;
297
+ /**
298
+ * Check if value has `as const`
299
+ * @example const foo = 'foo' as const;
300
+ */
301
+ if(initializer?.kind === ts.SyntaxKind.AsExpression) {
302
+ defaultValue = initializer?.expression?.getText()
303
+ } else {
304
+ defaultValue = initializer?.getText()
305
+ }
306
+
307
+ if(defaultValue) {
308
+ doc.default = defaultValue.replace(/\s+/g, ' ').trim();
309
+ }
310
+ return doc;
311
+ }
312
+
313
+ /**
314
+ * Add TS type
315
+ * @example class Foo { bar: string = ''; }
316
+ */
317
+ export function handleExplicitType(doc, node) {
318
+ if(node.type) {
319
+ doc.type = { text: node.type.getText() }
320
+
321
+ if(node?.questionToken) {
322
+ doc.type.text += ' | undefined';
323
+ }
324
+ }
325
+
326
+ return doc;
327
+ }
328
+
329
+ /**
330
+ * if is private field
331
+ * @example class Foo { #bar = ''; }
332
+ */
333
+ export function handlePrivateMember(doc, node) {
334
+ if (ts.isPrivateIdentifier(node.name)) {
335
+ doc.privacy = 'private';
336
+ }
337
+ return doc;
338
+ }
@@ -0,0 +1,90 @@
1
+ import { getDeclarationInFile, hasIgnoreJSDoc, isCustomElementsDefineCall } from '../../utils/ast-helpers.js';
2
+ import { resolveModuleOrPackageSpecifier } from '../../utils/index.js';
3
+ import { createClass } from './creators/createClass.js';
4
+
5
+ /**
6
+ * CUSTOM-ELEMENTS-DEFINE-CALLS
7
+ *
8
+ * Analyzes calls for:
9
+ * @example customElements.define()
10
+ * @example window.customElements.define()
11
+ */
12
+ export function customElementsDefineCallsPlugin() {
13
+ let counter;
14
+ return {
15
+ name: 'CORE - CUSTOM-ELEMENTS-DEFINE-CALLS',
16
+ analyzePhase({ts, node, moduleDoc, context}){
17
+ if(node?.kind === ts.SyntaxKind.SourceFile) {
18
+ counter = 0;
19
+ }
20
+
21
+ if (hasIgnoreJSDoc(node))
22
+ return;
23
+
24
+ /**
25
+ * @example customElements.define('my-el', MyEl);
26
+ * @example window.customElements.define('my-el', MyEl);
27
+ */
28
+ if(isCustomElementsDefineCall(node)) {
29
+ const classArg = node.parent.arguments[1];
30
+ let isAnonymousClass = classArg?.kind === ts.SyntaxKind.ClassExpression;
31
+ let isUnnamed = classArg?.name === undefined;
32
+
33
+ if(isAnonymousClass) {
34
+ const klass = createClass(classArg, moduleDoc, context);
35
+
36
+ if(isUnnamed) {
37
+ klass.name = `anonymous_${counter}`;
38
+ }
39
+ moduleDoc.declarations.push(klass);
40
+ }
41
+
42
+ let elementClass;
43
+
44
+ /**
45
+ * @example customElements.define('m-e', class extends HTMLElement{})
46
+ * ^
47
+ */
48
+ if(isUnnamed) {
49
+ elementClass = `anonymous_${counter}`;
50
+ counter = counter + 1;
51
+ }
52
+
53
+ /**
54
+ * @example customElements.define('m-e', MyElement)
55
+ * ^^^^^^^^^
56
+ */
57
+ if(node?.parent?.arguments?.[1]?.text) {
58
+ elementClass = node.parent.arguments[1].text;
59
+ }
60
+
61
+ /**
62
+ * @example customElements.define('m-e', class MyElement extends HTMLElement{})
63
+ * ^^^^^^^^^
64
+ */
65
+ if(classArg?.name) {
66
+ elementClass = classArg?.name?.getText();
67
+ }
68
+
69
+ const elementTag = node.parent.arguments[0].text;
70
+
71
+ const klass = getDeclarationInFile(elementClass, node?.getSourceFile());
72
+
73
+ if (hasIgnoreJSDoc(klass))
74
+ return;
75
+
76
+ const definitionDoc = {
77
+ kind: 'custom-element-definition',
78
+ name: elementTag,
79
+ declaration: {
80
+ name: elementClass,
81
+ ...resolveModuleOrPackageSpecifier(moduleDoc, context, elementClass)
82
+ },
83
+ };
84
+
85
+ moduleDoc.exports = [...(moduleDoc.exports || []), definitionDoc];
86
+ }
87
+ }
88
+ }
89
+ }
90
+