@ui5/webcomponents-tools 2.15.0 → 2.16.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/components-package/nps.js +0 -1
  3. package/lib/cem/cem.js +1 -1
  4. package/lib/cem/patch/@custom-elements-manifest/analyzer/cli.js +128 -0
  5. package/lib/cem/patch/@custom-elements-manifest/analyzer/package.json +59 -0
  6. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/browser-entrypoint.js +23 -0
  7. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/create.js +117 -0
  8. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/arrow-function.js +26 -0
  9. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/class-jsdoc.js +157 -0
  10. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/classes.js +20 -0
  11. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createArrowFunction.js +17 -0
  12. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createAttribute.js +24 -0
  13. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createClass.js +301 -0
  14. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createClassField.js +26 -0
  15. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createFunctionLike.js +73 -0
  16. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createMixin.js +33 -0
  17. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/createVariable.js +22 -0
  18. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/creators/handlers.js +338 -0
  19. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/custom-elements-define-calls.js +90 -0
  20. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/exports.js +156 -0
  21. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/function-like.js +24 -0
  22. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/mixins.js +29 -0
  23. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/reexported-wrapped-mixin-exports.js +84 -0
  24. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/analyse-phase/variables.js +34 -0
  25. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/collect-phase/collect-imports.js +101 -0
  26. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst/catalyst.js +11 -0
  27. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst/controller.js +34 -0
  28. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst-major-2/catalyst.js +11 -0
  29. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/catalyst-major-2/controller.js +34 -0
  30. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/decorators/attr.js +53 -0
  31. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/decorators/custom-element-decorator.js +36 -0
  32. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/fast/fast.js +7 -0
  33. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/lit.js +13 -0
  34. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/member-denylist.js +21 -0
  35. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/method-denylist.js +20 -0
  36. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/property-decorator.js +94 -0
  37. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/static-properties.js +121 -0
  38. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/lit/utils.js +66 -0
  39. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/framework-plugins/stencil/stencil.js +129 -0
  40. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/index.js +80 -0
  41. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/link-phase/cleanup-classes.js +25 -0
  42. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/link-phase/field-denylist.js +22 -0
  43. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/link-phase/method-denylist.js +25 -0
  44. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/apply-inheritance.js +78 -0
  45. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/is-custom-element.js +34 -0
  46. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/link-class-to-tagname.js +27 -0
  47. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/remove-unexported-declarations.js +23 -0
  48. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/features/post-processing/resolve-initializers.js +52 -0
  49. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/ast-helpers.js +186 -0
  50. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/cli-helpers.js +164 -0
  51. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/exports.js +44 -0
  52. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/find-external-manifests.js +67 -0
  53. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/imports.js +25 -0
  54. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/index.js +71 -0
  55. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/jsdoc.js +19 -0
  56. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/manifest-helpers.js +194 -0
  57. package/lib/cem/patch/@custom-elements-manifest/analyzer/src/utils/mixins.js +112 -0
  58. package/package.json +3 -3
@@ -0,0 +1,194 @@
1
+ /**
2
+ * UTILITIES RELATED TO GETTING INFORMATION OUT OF A MANIFEST OR DOC
3
+ */
4
+
5
+ import { has } from "./index.js";
6
+
7
+ /**
8
+ * @typedef {import('custom-elements-manifest/schema').Package} Package
9
+ */
10
+
11
+ function loopThroughDeclarations(manifest, predicate) {
12
+ manifest?.modules?.forEach(_module => {
13
+ _module?.declarations?.forEach(predicate);
14
+ });
15
+ }
16
+
17
+ function loopThroughExports(manifest, predicate) {
18
+ manifest?.modules?.forEach(_module => {
19
+ _module?.exports?.forEach(predicate);
20
+ });
21
+ }
22
+
23
+ /**
24
+ * Loops through all modules' exports, and returns the kind provided by the users
25
+ *
26
+ * @example getKind('class');
27
+ * @example getKind('custom-element-definition');
28
+ */
29
+ export function getAllExportsOfKind(manifest, kind) {
30
+ const result = [];
31
+ loopThroughExports(manifest, (_export) => {
32
+ if(_export.kind === kind) {
33
+ result.push(_export);
34
+ }
35
+ });
36
+ return result;
37
+ }
38
+
39
+
40
+ /**
41
+ * Loops through all modules' declarations, and returns the kind provided by the users
42
+ *
43
+ * @example getKind('class');
44
+ * @example getKind('custom-element-definition');
45
+ */
46
+ export function getAllDeclarationsOfKind(manifest, kind) {
47
+ const result = [];
48
+ loopThroughDeclarations(manifest, (declaration) => {
49
+ if(declaration.kind === kind) {
50
+ result.push(declaration);
51
+ }
52
+ });
53
+ return result;
54
+ }
55
+
56
+ /**
57
+ * Gets the inheritance tree from a manifest given a className
58
+ * Returns an array of a classes mixins/superclasses all the way up the chain
59
+ *
60
+ * @param {Package[]} manifests
61
+ * @param {string} className
62
+ */
63
+ export function getInheritanceTree(manifests, className) {
64
+ const tree = [];
65
+ const allClassLikes = new Map();
66
+ const _classes = [];
67
+ const _mixins = [];
68
+
69
+ manifests.forEach((cem) => {
70
+ _classes.push(...getAllDeclarationsOfKind(cem, 'class'));
71
+ _mixins.push(...getAllDeclarationsOfKind(cem, 'mixin'));
72
+ });
73
+
74
+ [..._mixins, ..._classes].forEach((klass) => {
75
+ allClassLikes.set(klass.name, klass);
76
+ });
77
+
78
+ let klass = allClassLikes.get(className)
79
+
80
+ if(klass) {
81
+ tree.push(klass)
82
+
83
+ klass?.mixins?.forEach(mixin => {
84
+ let foundMixin = _mixins.find(m => m.name === mixin.name);
85
+ if(foundMixin) {
86
+ tree.push(foundMixin);
87
+
88
+ while(has(foundMixin?.mixins)) {
89
+ foundMixin?.mixins?.forEach(mixin => {
90
+ foundMixin = _mixins.find(m => m.name === mixin.name);
91
+ if(foundMixin) {
92
+ tree.push(foundMixin);
93
+ }
94
+ });
95
+ }
96
+ }
97
+ });
98
+
99
+ while(allClassLikes.has(klass.superclass?.name)) {
100
+ const newKlass = allClassLikes.get(klass.superclass.name);
101
+ let allMixins = [];
102
+ if (klass?.mixins) {
103
+ allMixins = [...klass.mixins];
104
+ }
105
+ if (newKlass?.mixins) {
106
+ allMixins = [...allMixins, ...newKlass.mixins];
107
+ }
108
+
109
+ allMixins.forEach(mixin => {
110
+ let foundMixin = _mixins.find(m => m.name === mixin.name);
111
+ if(foundMixin) {
112
+ tree.push(foundMixin);
113
+
114
+ while(has(foundMixin?.mixins)) {
115
+ foundMixin?.mixins?.forEach(mixin => {
116
+ foundMixin = _mixins.find(m => m.name === mixin.name);
117
+ if(foundMixin) {
118
+ tree.push(foundMixin);
119
+ }
120
+ });
121
+ }
122
+ }
123
+ });
124
+
125
+ tree.push(newKlass);
126
+ klass = newKlass;
127
+ }
128
+ return tree;
129
+ }
130
+ return [];
131
+ }
132
+
133
+ /**
134
+ * @param {Package[]} manifests
135
+ * @param {string} modulePath
136
+ */
137
+ export function getModuleFromManifests(manifests, modulePath) {
138
+ let result = undefined;
139
+
140
+ manifests.forEach((cem) => {
141
+ cem?.modules?.forEach((_module) => {
142
+ if (_module.path === modulePath) {
143
+ result = _module;
144
+ }
145
+ });
146
+ });
147
+
148
+ return result;
149
+ }
150
+
151
+ /**
152
+ * @param {Package[]} manifests
153
+ * @param {string} className
154
+ */
155
+ export function getModuleForClassLike(manifests, className) {
156
+ let result = undefined;
157
+
158
+ manifests.forEach((cem) => {
159
+ cem?.modules?.forEach(_module => {
160
+ _module?.declarations?.forEach(declaration => {
161
+ if((declaration.kind === 'class' || declaration.kind === 'mixin') && declaration.name === className) {
162
+ result = _module.path;
163
+ }
164
+ });
165
+ });
166
+ });
167
+
168
+ return result;
169
+ }
170
+
171
+ /**
172
+ * Given a manifest module, a class name, and a class member name, gets the
173
+ * manifest doc for the module's class' member.
174
+ *
175
+ * @param {Partial<import('custom-elements-manifest/schema').Module>} moduleDoc Manifest module
176
+ * @param {string} className Class to get member of
177
+ * @param {string} memberName Class member to get
178
+ * @param {boolean} isStatic Is it a static member?
179
+ * @return {import('custom-elements-manifest/schema').ClassMember|void} the requested class member
180
+ */
181
+ export function getClassMemberDoc(moduleDoc, className, memberName, isStatic = false) {
182
+ /** @type {import('custom-elements-manifest/schema').ClassDeclaration} */
183
+ const classDoc = (moduleDoc.declarations.find(x => x.name === className));
184
+
185
+ if (!classDoc || !has(classDoc.members))
186
+ return;
187
+
188
+ const memberDoc = classDoc.members.find(x =>
189
+ x.name === memberName &&
190
+ (x.static ?? false) === isStatic
191
+ );
192
+
193
+ return memberDoc;
194
+ }
@@ -0,0 +1,112 @@
1
+ import ts from 'typescript';
2
+
3
+ import { getReturnValue } from '../utils/ast-helpers.js';
4
+
5
+ export const isMixin = node => !!extractMixinNodes(node);
6
+
7
+ export function extractMixinNodes(node) {
8
+ if (ts.isVariableStatement(node) || ts.isFunctionDeclaration(node)) {
9
+ if (ts.isVariableStatement(node)) {
10
+ /**
11
+ * @example const MyMixin = klass => class MyMixin extends klass {}
12
+ * @example export const MyMixin = klass => class MyMixin extends klass {}
13
+ */
14
+ const variableDeclaration = node.declarationList.declarations.find(declaration =>
15
+ ts.isVariableDeclaration(declaration),
16
+ );
17
+ if (variableDeclaration) {
18
+ const body = variableDeclaration?.initializer?.body;
19
+ if (body && ts.isClassExpression(body)) {
20
+ return {
21
+ mixinFunction: node,
22
+ mixinClass: body,
23
+ };
24
+ }
25
+
26
+ /**
27
+ * @example const MyMixin = klass => { return class MyMixin extends Klass{} }
28
+ */
29
+ if (body && ts.isBlock(body)) {
30
+ const returnStatement = body.statements.find(statement => ts.isReturnStatement(statement));
31
+
32
+ if (returnStatement && returnStatement?.expression?.kind && ts.isClassExpression(returnStatement.expression)) {
33
+ return {
34
+ mixinFunction: variableDeclaration.initializer,
35
+ mixinClass: returnStatement.expression
36
+ };
37
+ }
38
+ }
39
+
40
+ /**
41
+ * @example const MyMixin = klass => { class MyMixin extends klass {} return MyMixin;}
42
+ */
43
+ if (body && ts.isBlock(body)) {
44
+ const classDeclaration = body.statements.find(statement => ts.isClassDeclaration(statement));
45
+ const returnStatement = body.statements.find(statement => ts.isReturnStatement(statement));
46
+ /** Avoid undefined === undefined */
47
+ if(!(classDeclaration && returnStatement))
48
+ return;
49
+ const classDeclarationName = classDeclaration.name?.getText?.();
50
+ const returnValue = getReturnValue(returnStatement)
51
+ /**
52
+ * If the classDeclaration inside the function body has the same name as whats being
53
+ * returned from the function, consider it a mixin
54
+ */
55
+ if (classDeclarationName === returnValue) {
56
+ return {
57
+ mixinFunction: node,
58
+ mixinClass: classDeclaration
59
+ }
60
+ }
61
+ }
62
+ }
63
+ }
64
+
65
+ /**
66
+ * @example function MyMixin(klass) { return class MyMixin extends Klass{} }
67
+ */
68
+ if (ts.isFunctionDeclaration(node)) {
69
+ if (node.body && ts.isBlock(node.body)) {
70
+
71
+ const returnStatement = node.body.statements.find(statement => ts.isReturnStatement(statement));
72
+
73
+ if (returnStatement?.expression && ts.isClassExpression(returnStatement.expression)) {
74
+ return {
75
+ mixinFunction: node,
76
+ mixinClass: returnStatement.expression
77
+ };
78
+ }
79
+ }
80
+ }
81
+
82
+ /**
83
+ * @example function MyMixin(klass) {class A extends klass {} return A;}
84
+ */
85
+ if (ts.isFunctionDeclaration(node)) {
86
+ if (node.body && ts.isBlock(node.body)) {
87
+ const classDeclaration = node.body.statements.find(statement => ts.isClassDeclaration(statement));
88
+ const returnStatement = node.body.statements.find(statement => ts.isReturnStatement(statement));
89
+
90
+ /** Avoid undefined === undefined */
91
+ if(!(classDeclaration && returnStatement))
92
+ return;
93
+
94
+ const classDeclarationName = classDeclaration.name?.getText?.();
95
+
96
+ const returnValue = getReturnValue(returnStatement)
97
+
98
+ /**
99
+ * If the classDeclaration inside the function body has the same name as whats being
100
+ * returned from the function, consider it a mixin
101
+ */
102
+ if (classDeclarationName === returnValue) {
103
+ return {
104
+ mixinFunction: node,
105
+ mixinClass: classDeclaration
106
+ }
107
+ }
108
+ }
109
+ }
110
+ }
111
+ return false;
112
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ui5/webcomponents-tools",
3
- "version": "2.15.0",
3
+ "version": "2.16.0-rc.1",
4
4
  "description": "UI5 Web Components: webcomponents.tools",
5
5
  "author": "SAP SE (https://www.sap.com)",
6
6
  "license": "Apache-2.0",
@@ -20,7 +20,7 @@
20
20
  "directory": "packages/tools"
21
21
  },
22
22
  "dependencies": {
23
- "@custom-elements-manifest/analyzer": "patch:@custom-elements-manifest/analyzer@npm%3A0.10.6#~/.yarn/patches/@custom-elements-manifest-analyzer-npm-0.10.6-9b5ff0c50b.patch",
23
+ "@custom-elements-manifest/analyzer": "^0.10.10",
24
24
  "@typescript-eslint/eslint-plugin": "^6.9.0",
25
25
  "@typescript-eslint/parser": "^6.9.0",
26
26
  "@wdio/cli": "^7.19.7",
@@ -81,5 +81,5 @@
81
81
  "esbuild": "^0.25.0",
82
82
  "yargs": "^17.5.1"
83
83
  },
84
- "gitHead": "5c40df56e6b1b834e277adee102d0e299a5c772c"
84
+ "gitHead": "265099a61a699bab43272f38673a637a9caf7ca5"
85
85
  }