@qds.dev/tools 0.6.2 → 0.7.5

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 (67) hide show
  1. package/lib/{vite → rolldown}/as-child.qwik.mjs +21 -18
  2. package/lib/{vite → rolldown}/icons.qwik.mjs +55 -44
  3. package/lib/rolldown/index.qwik.mjs +3 -2
  4. package/lib/rolldown/inline-css.qwik.mjs +25 -17
  5. package/lib/vite/index.qwik.mjs +5 -3
  6. package/lib/vite/minify-content.qwik.mjs +57 -0
  7. package/lib-types/tools/rolldown/as-child.d.ts +24 -0
  8. package/lib-types/tools/rolldown/icons.d.ts +47 -0
  9. package/lib-types/tools/rolldown/index.d.ts +4 -1
  10. package/lib-types/tools/rolldown/inline-css.d.ts +15 -5
  11. package/lib-types/tools/utils/icons/import-resolver.d.ts +1 -1
  12. package/lib-types/tools/utils/icons/transform/mdx.d.ts +1 -1
  13. package/lib-types/tools/utils/icons/transform/shared.d.ts +1 -1
  14. package/lib-types/tools/utils/icons/transform/tsx.d.ts +1 -1
  15. package/lib-types/tools/vite/index.d.ts +3 -3
  16. package/lib-types/tools/vite/minify-content.d.ts +9 -0
  17. package/package.json +9 -6
  18. package/lib/docs/component-props.qwik.mjs +0 -481
  19. package/lib/docs/index.qwik.mjs +0 -3
  20. package/lib/rolldown/qds-transform.qwik.mjs +0 -111
  21. package/lib/vite/component-props.qwik.mjs +0 -315
  22. package/lib-types/docs/component-props.d.ts +0 -25
  23. package/lib-types/docs/index.d.ts +0 -2
  24. package/lib-types/linter/qds-internal.d.ts +0 -7
  25. package/lib-types/linter/qds-internal.unit.d.ts +0 -1
  26. package/lib-types/linter/rule-tester.d.ts +0 -100
  27. package/lib-types/rolldown/index.d.ts +0 -3
  28. package/lib-types/rolldown/inline-css.d.ts +0 -16
  29. package/lib-types/rolldown/qds-transform.d.ts +0 -11
  30. package/lib-types/rolldown/qds-transform.unit.d.ts +0 -1
  31. package/lib-types/rolldown/qwik-rolldown.d.ts +0 -9
  32. package/lib-types/src/generate/icon-types.d.ts +0 -25
  33. package/lib-types/src/index.d.ts +0 -1
  34. package/lib-types/src/vite.d.ts +0 -1
  35. package/lib-types/tools/rolldown/qds-transform.d.ts +0 -11
  36. package/lib-types/tools/rolldown/qds-transform.unit.d.ts +0 -1
  37. package/lib-types/tools/vite/as-child.d.ts +0 -13
  38. package/lib-types/tools/vite/icons.d.ts +0 -19
  39. package/lib-types/utils/ast/core.d.ts +0 -4
  40. package/lib-types/utils/ast/imports.d.ts +0 -19
  41. package/lib-types/utils/ast/jsx-helpers.d.ts +0 -3
  42. package/lib-types/utils/ast/qwik.d.ts +0 -13
  43. package/lib-types/utils/fs.d.ts +0 -4
  44. package/lib-types/utils/icons/ast/expressions.d.ts +0 -50
  45. package/lib-types/utils/icons/ast/expressions.unit.d.ts +0 -1
  46. package/lib-types/utils/icons/ast/jsx.d.ts +0 -81
  47. package/lib-types/utils/icons/ast/jsx.unit.d.ts +0 -1
  48. package/lib-types/utils/icons/collections/loader.d.ts +0 -38
  49. package/lib-types/utils/icons/import-resolver.d.ts +0 -37
  50. package/lib-types/utils/icons/naming.d.ts +0 -46
  51. package/lib-types/utils/icons/transform/mdx.d.ts +0 -28
  52. package/lib-types/utils/icons/transform/shared.d.ts +0 -31
  53. package/lib-types/utils/icons/transform/tsx.d.ts +0 -51
  54. package/lib-types/utils/icons/types/mdx-ast.d.ts +0 -74
  55. package/lib-types/utils/index.d.ts +0 -13
  56. package/lib-types/utils/package-json.d.ts +0 -13
  57. package/lib-types/utils/transform-dts.d.ts +0 -15
  58. package/lib-types/utils/transform-dts.unit.d.ts +0 -1
  59. package/lib-types/vite/as-child.d.ts +0 -13
  60. package/lib-types/vite/as-child.unit.d.ts +0 -1
  61. package/lib-types/vite/component-props.d.ts +0 -24
  62. package/lib-types/vite/icons.d.ts +0 -19
  63. package/lib-types/vite/icons.unit.d.ts +0 -1
  64. package/lib-types/vite/index.d.ts +0 -3
  65. /package/lib-types/tools/{vite → rolldown}/as-child.unit.d.ts +0 -0
  66. /package/lib-types/tools/{vite → rolldown}/icons.unit.d.ts +0 -0
  67. /package/lib-types/{docs/component-props.unit.d.ts → tools/vite/minify-content.unit.d.ts} +0 -0
@@ -1,481 +0,0 @@
1
- import { parseSync } from "oxc-parser";
2
- import { walk } from "oxc-walker";
3
- import { existsSync, statSync } from "node:fs";
4
- import { dirname, join, relative } from "node:path";
5
- import { charIn, charNotIn, createRegExp, exactly, maybe, oneOrMore, whitespace } from "magic-regexp";
6
- import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
7
-
8
- //#region docs/component-props.ts
9
- const JSDOC_LINE_PATTERN = createRegExp(maybe(whitespace.times.any()), exactly("*"), maybe(whitespace));
10
- const JSDOC_START_PATTERN = createRegExp(exactly("/**"));
11
- const JSDOC_END_PATTERN = createRegExp(exactly("*/"));
12
- const JSDOC_PATTERN = createRegExp(exactly("/**"), charNotIn("*").or(exactly("*").notAfter(exactly("/"))).times.any(), exactly("*/"));
13
- const componentProps = (options) => {
14
- const { componentsDir, outputDir, debug: isDebugMode = false } = options;
15
- const debug = (message, ...data) => {
16
- if (!isDebugMode) return;
17
- console.log(`[component-props] ${message}`, ...data);
18
- };
19
- return {
20
- name: "vite-plugin-qds-component-props",
21
- enforce: "pre",
22
- configResolved() {
23
- debug("Component props plugin initialized");
24
- generateAllComponentMetadata(componentsDir, outputDir, debug).catch((error) => {
25
- console.error("[component-props] Error generating metadata:", error);
26
- });
27
- },
28
- async handleHotUpdate(ctx) {
29
- if (!ctx.file.includes(componentsDir) || !ctx.file.endsWith(".tsx")) return;
30
- const componentName = extractComponentName(ctx.file, componentsDir);
31
- if (!componentName) return;
32
- await generateComponentMetadata(componentName, componentsDir, outputDir, debug);
33
- }
34
- };
35
- };
36
- async function generateAllComponentMetadata(componentsDir, outputDir, debug) {
37
- const componentDirs = await findComponentDirs(componentsDir);
38
- await Promise.all(componentDirs.map(async (componentName) => generateComponentMetadata(componentName, componentsDir, outputDir, debug)));
39
- }
40
- async function generateComponentMetadata(componentName, componentsDir, outputDir, debug) {
41
- try {
42
- debug(`Generating metadata for component: ${componentName}`);
43
- const pieces = await parseComponentPieces(componentName, componentsDir, debug);
44
- debug(`Found ${pieces.length} pieces for ${componentName}:`, pieces.map((p) => p.name));
45
- const metadata = {
46
- componentName,
47
- pieces
48
- };
49
- const outputPath = join(outputDir, `${componentName}.json`);
50
- await mkdir(dirname(outputPath), { recursive: true });
51
- await writeFile(outputPath, JSON.stringify(metadata, null, 2), "utf-8");
52
- debug(`Wrote metadata to ${outputPath}`);
53
- } catch (error) {
54
- debug(`Error generating metadata for ${componentName}:`, error);
55
- console.error(`[component-props] Error generating metadata for ${componentName}:`, error);
56
- }
57
- }
58
- async function parseComponentPieces(componentName, componentsDir, debug) {
59
- const componentPath = join(componentsDir, componentName);
60
- debug(`Parsing pieces for ${componentName}`);
61
- if (!existsSync(componentPath)) {
62
- debug(`Component path does not exist: ${componentPath}`);
63
- return [];
64
- }
65
- const files = await readdir(componentPath);
66
- debug(`Found ${files.length} files in directory:`, files);
67
- const pieceFiles = files.filter((file) => isPieceFile(file, debug));
68
- debug(`Filtered to ${pieceFiles.length} piece files:`, pieceFiles);
69
- const piecePromises = pieceFiles.map(async (file) => {
70
- const filePath = join(componentPath, file);
71
- if (!statSync(filePath).isFile()) {
72
- debug(`Skipping ${filePath} (not a file)`);
73
- return null;
74
- }
75
- const pieceName = extractPieceName(file, componentName);
76
- debug(`Parsing piece file: ${file} -> piece name: ${pieceName}`);
77
- const props = await parseComponentFile(filePath, pieceName, debug);
78
- if (props.length === 0) {
79
- debug(`Skipping ${pieceName} (no props)`);
80
- return null;
81
- }
82
- debug(`Found ${props.length} props in ${pieceName}`);
83
- return {
84
- name: pieceName,
85
- props
86
- };
87
- });
88
- const pieces = (await Promise.all(piecePromises)).filter((piece) => piece !== null);
89
- pieces.sort((a, b) => {
90
- if (a.name === "Root") return -1;
91
- if (b.name === "Root") return 1;
92
- return a.name.localeCompare(b.name);
93
- });
94
- debug(`Final pieces for ${componentName}:`, pieces.map((p) => p.name));
95
- return pieces;
96
- }
97
- function isPieceFile(file, debug) {
98
- if (!file.endsWith(".tsx")) {
99
- debug(`Skipping ${file} (not .tsx)`);
100
- return false;
101
- }
102
- if (file.endsWith("-context.tsx")) {
103
- debug(`Skipping ${file} (is -context.tsx)`);
104
- return false;
105
- }
106
- if (file.includes(".browser.")) {
107
- debug(`Skipping ${file} (contains .browser.)`);
108
- return false;
109
- }
110
- debug(`Including ${file} as piece file`);
111
- return true;
112
- }
113
- function extractPieceName(file, componentName) {
114
- return file.replace(`${componentName}-`, "").replace(".tsx", "").split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
115
- }
116
- async function parseComponentFile(filePath, pieceName, debug) {
117
- debug(`parseComponentFile: ${filePath} (piece: ${pieceName})`);
118
- const source = await readFile(filePath, "utf-8");
119
- const ast = parseSync(filePath, source);
120
- if (ast.errors.length > 0) {
121
- debug(`Parse errors in ${filePath}:`, ast.errors);
122
- return [];
123
- }
124
- const typeAliasCache = buildTypeAliasCache(ast.program);
125
- const analysisResult = analyzeProgram(ast.program, debug, typeAliasCache);
126
- if (!analysisResult.propsType) {
127
- debug(`No props type found in ${filePath}`);
128
- return [];
129
- }
130
- debug(`Bindable props:`, Array.from(analysisResult.bindableProps));
131
- const typeLiterals = /* @__PURE__ */ new Set();
132
- const bindableInlineTypes = /* @__PURE__ */ new Set();
133
- collectTypeLiterals(analysisResult.propsType, typeAliasCache, typeLiterals);
134
- collectBindableInlineTypes(analysisResult.propsType, bindableInlineTypes);
135
- for (const bindableType of bindableInlineTypes) typeLiterals.add(bindableType);
136
- for (const bindableType of analysisResult.aliasBindableTypes) {
137
- bindableInlineTypes.add(bindableType);
138
- typeLiterals.add(bindableType);
139
- }
140
- const propsMap = /* @__PURE__ */ new Map();
141
- for (const typeLiteral of typeLiterals) {
142
- const isFromBindable = bindableInlineTypes.has(typeLiteral);
143
- extractPropsFromType(typeLiteral, source, analysisResult.bindableProps, propsMap, typeAliasCache, isFromBindable);
144
- }
145
- if (analysisResult.bindableTypeName) {
146
- const bindableTypeAlias = typeAliasCache.get(analysisResult.bindableTypeName);
147
- if (bindableTypeAlias) {
148
- const typeAnnotation = "typeAnnotation" in bindableTypeAlias ? bindableTypeAlias.typeAnnotation : null;
149
- if (typeAnnotation?.type === "TSTypeLiteral") extractPropsFromType(typeAnnotation, source, analysisResult.bindableProps, propsMap, typeAliasCache, true);
150
- else if (typeAnnotation?.type === "TSTypeReference") {
151
- const resolvedType = resolveTypeAliasCached(typeAnnotation, typeAliasCache);
152
- if (resolvedType?.type === "TSTypeLiteral") extractPropsFromType(resolvedType, source, analysisResult.bindableProps, propsMap, typeAliasCache, true);
153
- }
154
- }
155
- }
156
- const finalProps = Array.from(propsMap.values());
157
- debug(`Extracted ${finalProps.length} props from ${filePath}`);
158
- return finalProps;
159
- }
160
- function buildTypeAliasCache(program) {
161
- const cache = /* @__PURE__ */ new Map();
162
- walk(program, { enter(node) {
163
- if (node.type === "TSTypeAliasDeclaration") {
164
- const typeName = getTypeName(node);
165
- if (typeName) cache.set(typeName, node);
166
- }
167
- } });
168
- return cache;
169
- }
170
- function analyzeProgram(program, debug, typeAliasCache) {
171
- let propsType = null;
172
- const bindableProps = /* @__PURE__ */ new Set();
173
- let bindableTypeName = null;
174
- const aliasBindableTypes = [];
175
- let foundComponentCall = false;
176
- walk(program, { enter(node) {
177
- if (!foundComponentCall && node.type === "CallExpression") {
178
- const callee = "callee" in node ? node.callee : null;
179
- if (callee) {
180
- if (callee.type === "Identifier" && "name" in callee && callee.name === "component$" || callee.type === "MemberExpression" && "property" in callee && callee.property && typeof callee.property === "object" && "name" in callee.property && callee.property.name === "component$") {
181
- foundComponentCall = true;
182
- const firstArg = ("arguments" in node ? node.arguments : [])[0];
183
- if (firstArg && typeof firstArg === "object" && firstArg.type === "ArrowFunctionExpression") {
184
- if ("typeArguments" in node && node.typeArguments) {
185
- const typeArgs = node.typeArguments;
186
- if (Array.isArray(typeArgs.params) && typeArgs.params.length > 0) {
187
- const firstTypeArg = typeArgs.params[0];
188
- if (firstTypeArg && typeof firstTypeArg === "object" && "type" in firstTypeArg) {
189
- debug(`Found component$ call with generic type parameter`);
190
- propsType = firstTypeArg;
191
- return;
192
- }
193
- }
194
- }
195
- const firstParam = ("params" in firstArg ? firstArg.params : [])[0];
196
- if (firstParam && typeof firstParam === "object") {
197
- const typeAnnotation = "typeAnnotation" in firstParam ? firstParam.typeAnnotation : null;
198
- if (typeAnnotation && typeof typeAnnotation === "object") {
199
- const paramType = "typeAnnotation" in typeAnnotation ? typeAnnotation.typeAnnotation : null;
200
- if (paramType && typeof paramType === "object") {
201
- debug(`Found component$ call with props type`);
202
- propsType = paramType;
203
- return;
204
- }
205
- }
206
- }
207
- }
208
- }
209
- }
210
- }
211
- if (node.type === "TSTypeAliasDeclaration") {
212
- const typeName = getTypeName(node);
213
- if (!typeName) return;
214
- const typeAnnotation = "typeAnnotation" in node ? node.typeAnnotation : null;
215
- if (!typeAnnotation) return;
216
- if (!propsType && typeName.endsWith("Props")) {
217
- debug(`Found *Props type: ${typeName}`);
218
- if ("type" in typeAnnotation) propsType = typeAnnotation;
219
- }
220
- if (typeName.endsWith("Props") && typeAnnotation.type === "TSIntersectionType") {
221
- const types = "types" in typeAnnotation ? typeAnnotation.types : [];
222
- for (const type of types) {
223
- if (type.type !== "TSTypeReference") continue;
224
- const typeNameNode = "typeName" in type ? type.typeName : null;
225
- if (!typeNameNode || !("name" in typeNameNode) || typeNameNode.name !== "BindableProps") continue;
226
- const firstParam = getTypeParameters(type)[0];
227
- if (firstParam && typeof firstParam === "object" && firstParam !== null && "type" in firstParam) {
228
- if (firstParam.type === "TSTypeReference") {
229
- const refTypeName = firstParam.typeName?.name;
230
- if (typeof refTypeName === "string") bindableTypeName = refTypeName;
231
- } else if (firstParam.type === "TSTypeLiteral") aliasBindableTypes.push(firstParam);
232
- }
233
- }
234
- }
235
- if (bindableTypeName && typeName === bindableTypeName) {
236
- if (typeAnnotation.type === "TSTypeLiteral") extractPropNames(typeAnnotation, bindableProps);
237
- else if (typeAnnotation.type === "TSTypeReference") {
238
- const resolvedType = resolveTypeAliasCached(typeAnnotation, typeAliasCache);
239
- if (resolvedType?.type === "TSTypeLiteral") extractPropNames(resolvedType, bindableProps);
240
- }
241
- }
242
- }
243
- } });
244
- return {
245
- propsType,
246
- bindableProps,
247
- bindableTypeName,
248
- aliasBindableTypes
249
- };
250
- }
251
- function resolveTypeAliasCached(type, typeAliasCache) {
252
- if (type.type !== "TSTypeReference") return null;
253
- const typeName = getTypeReferenceName(type);
254
- if (!typeName) return null;
255
- const aliasNode = typeAliasCache.get(typeName);
256
- if (!aliasNode) return null;
257
- const typeAnnotation = "typeAnnotation" in aliasNode ? aliasNode.typeAnnotation : null;
258
- if (typeAnnotation && "type" in typeAnnotation && typeAnnotation.type !== "TSTypeAnnotation") return typeAnnotation;
259
- return null;
260
- }
261
- function collectTypeLiterals(type, typeAliasCache, collected) {
262
- if (!type) return;
263
- if (type.type === "TSTypeLiteral") {
264
- collected.add(type);
265
- return;
266
- }
267
- if (type.type === "TSIntersectionType" && "types" in type) {
268
- for (const intersectionType of type.types) collectTypeLiterals(intersectionType, typeAliasCache, collected);
269
- return;
270
- }
271
- if (type.type === "TSTypeReference") {
272
- const resolved = resolveTypeAliasCached(type, typeAliasCache);
273
- if (resolved) collectTypeLiterals(resolved, typeAliasCache, collected);
274
- }
275
- }
276
- function collectBindableInlineTypes(type, collected) {
277
- if (!type) return;
278
- if (type.type === "TSIntersectionType" && "types" in type) for (const intersectionType of type.types) {
279
- if (intersectionType.type === "TSTypeReference") {
280
- if (getTypeReferenceName(intersectionType) === "BindableProps") {
281
- const firstParam = getTypeParameters(intersectionType)[0];
282
- if (firstParam && typeof firstParam === "object" && firstParam !== null && "type" in firstParam && firstParam.type === "TSTypeLiteral") collected.add(firstParam);
283
- }
284
- }
285
- collectBindableInlineTypes(intersectionType, collected);
286
- }
287
- }
288
- function getTypeName(node) {
289
- if (node.type !== "TSTypeAliasDeclaration") return "";
290
- if (!("id" in node) || !("name" in node.id)) return "";
291
- return node.id.name;
292
- }
293
- function getTypeReferenceName(type) {
294
- if (type.type !== "TSTypeReference") return "";
295
- if (!("typeName" in type)) return "";
296
- const typeName = type.typeName;
297
- if (!typeName || !("name" in typeName) || typeof typeName.name !== "string") return "";
298
- return typeName.name;
299
- }
300
- function getTypeParameters(type) {
301
- if (type.type === "TSTypeReference") {
302
- if ("typeArguments" in type && type.typeArguments) {
303
- const typeArgs = type.typeArguments;
304
- if (Array.isArray(typeArgs.params)) return typeArgs.params;
305
- }
306
- return [];
307
- }
308
- if (!("typeParameters" in type) || !type.typeParameters || typeof type.typeParameters !== "object" || !("params" in type.typeParameters) || !Array.isArray(type.typeParameters.params)) return [];
309
- return type.typeParameters.params;
310
- }
311
- function extractPropNames(typeLiteral, props) {
312
- if (!("members" in typeLiteral)) return;
313
- for (const member of typeLiteral.members) {
314
- if (member.type !== "TSPropertySignature") continue;
315
- const key = getPropertyKey(member);
316
- if (key) props.add(key);
317
- }
318
- }
319
- function extractPropsFromType(typeLiteral, source, bindableProps, propsMap, typeAliasCache, forceBindable = false) {
320
- if (!("members" in typeLiteral)) return;
321
- for (const member of typeLiteral.members) {
322
- if (member.type !== "TSPropertySignature") continue;
323
- const prop = extractPropFromSignature(member, source, bindableProps, typeAliasCache, forceBindable);
324
- if (prop) {
325
- const existing = propsMap.get(prop.name);
326
- if (existing) {
327
- if (prop.isBindable) existing.isBindable = true;
328
- if (prop.comment && !existing.comment) existing.comment = prop.comment;
329
- if (prop.type !== "unknown" && existing.type === "unknown") {
330
- existing.type = prop.type;
331
- existing.unionValues = prop.unionValues;
332
- existing.isFunction = prop.isFunction;
333
- existing.initialValue = prop.initialValue;
334
- }
335
- } else propsMap.set(prop.name, prop);
336
- }
337
- }
338
- }
339
- function extractPropFromSignature(signature, source, bindableProps, typeAliasCache, forceBindable = false) {
340
- const key = getPropertyKey(signature);
341
- if (!key || key.startsWith("_")) return null;
342
- const typeAnnotation = "typeAnnotation" in signature ? signature.typeAnnotation : null;
343
- if (!typeAnnotation) return null;
344
- const type = typeAnnotation.typeAnnotation;
345
- const comment = extractComment(signature, source, key);
346
- const propType = parseType(type, source, typeAliasCache);
347
- return {
348
- name: key,
349
- type: propType.type,
350
- unionValues: propType.unionValues,
351
- isBindable: forceBindable || bindableProps.has(key),
352
- isFunction: propType.isFunction,
353
- initialValue: propType.initialValue,
354
- comment: comment || void 0
355
- };
356
- }
357
- function getPropertyKey(signature) {
358
- const keyNode = "key" in signature ? signature.key : null;
359
- if (!keyNode || !("name" in keyNode)) return null;
360
- if (typeof keyNode.name === "string") return keyNode.name;
361
- return keyNode.name.name;
362
- }
363
- function extractComment(node, source, propName) {
364
- if ("leadingComments" in node && node.leadingComments && Array.isArray(node.leadingComments)) for (const comment of node.leadingComments) {
365
- if (typeof comment !== "object" || comment === null || !("type" in comment) || !("value" in comment)) continue;
366
- const commentTyped = comment;
367
- if (commentTyped.type !== "CommentBlock") continue;
368
- const commentValue = commentTyped.value;
369
- if (typeof commentValue !== "string" || !commentValue.startsWith("*")) continue;
370
- return commentValue.split("\n").map((line) => line.replace(JSDOC_LINE_PATTERN, "").trim()).filter((line) => line && !line.startsWith("@")).join(" ").trim() || null;
371
- }
372
- if (!propName) return null;
373
- const propPattern = createRegExp(maybe(whitespace), exactly(propName), maybe(whitespace.times.any()), charIn("?:"));
374
- const propPatternGlobal = new RegExp(propPattern.source, "g");
375
- let match;
376
- while ((match = propPatternGlobal.exec(source)) !== null) {
377
- const propStart = match.index;
378
- const jsdocMatch = source.slice(Math.max(0, propStart - 500), propStart).match(JSDOC_PATTERN);
379
- if (jsdocMatch && jsdocMatch[0]) return jsdocMatch[0].replace(JSDOC_START_PATTERN, "").replace(JSDOC_END_PATTERN, "").split("\n").map((line) => line.replace(JSDOC_LINE_PATTERN, "").trim()).filter((line) => line && !line.startsWith("@")).join(" ").trim() || null;
380
- }
381
- return null;
382
- }
383
- function parseType(type, _source, typeAliasCache) {
384
- if (type.type === "TSUnionType") return parseUnionType(type, typeAliasCache);
385
- if (type.type === "TSBooleanKeyword") return {
386
- type: "boolean",
387
- initialValue: false
388
- };
389
- if (type.type === "TSStringKeyword") return {
390
- type: "string",
391
- initialValue: ""
392
- };
393
- if (type.type === "TSNumberKeyword") return {
394
- type: "number",
395
- initialValue: 0
396
- };
397
- if (type.type === "TSLiteralType") return parseLiteralType(type);
398
- if (type.type === "TSFunctionType") return {
399
- type: "function",
400
- isFunction: true
401
- };
402
- if (type.type === "TSTypeReference") {
403
- if (getTypeReferenceName(type) === "QRL") return {
404
- type: "function",
405
- isFunction: true
406
- };
407
- const resolvedType = resolveTypeAliasCached(type, typeAliasCache);
408
- if (resolvedType) return parseType(resolvedType, _source, typeAliasCache);
409
- }
410
- return { type: "unknown" };
411
- }
412
- function parseUnionType(type, typeAliasCache) {
413
- if (type.type !== "TSUnionType" || !("types" in type)) return { type: "unknown" };
414
- const unionTypes = type.types;
415
- const stringLiterals = [];
416
- for (let i = 0; i < unionTypes.length; i++) {
417
- let unionType = unionTypes[i];
418
- if (unionType.type === "TSTypeReference") {
419
- const resolvedType = resolveTypeAliasCached(unionType, typeAliasCache);
420
- if (resolvedType) {
421
- if (resolvedType.type === "TSUnionType") {
422
- const nestedResult = parseUnionType(resolvedType, typeAliasCache);
423
- if (nestedResult.type === "union" && nestedResult.unionValues) stringLiterals.push(...nestedResult.unionValues);
424
- continue;
425
- }
426
- unionType = resolvedType;
427
- }
428
- }
429
- if (unionType.type === "TSLiteralType" && "literal" in unionType) {
430
- const literal = unionType.literal;
431
- if (literal && typeof literal === "object" && "type" in literal && "value" in literal) {
432
- const literalValue = literal.value;
433
- if (typeof literalValue === "string") stringLiterals.push(literalValue);
434
- }
435
- }
436
- }
437
- const hasBoolean = unionTypes.some((t) => {
438
- if (t.type === "TSBooleanKeyword") return true;
439
- if (t.type === "TSLiteralType" && "literal" in t) {
440
- const literal = t.literal;
441
- if (literal && typeof literal === "object" && "value" in literal) return typeof literal.value === "boolean";
442
- }
443
- return false;
444
- });
445
- const unionValues = [];
446
- if (hasBoolean) unionValues.push("false", "true");
447
- if (stringLiterals.length > 0) unionValues.push(...stringLiterals);
448
- if (unionValues.length > 0) return {
449
- type: "union",
450
- unionValues
451
- };
452
- return { type: "unknown" };
453
- }
454
- function parseLiteralType(type) {
455
- if (type.type !== "TSLiteralType" || !("literal" in type)) return { type: "unknown" };
456
- const literal = type.literal;
457
- if (!literal || typeof literal !== "object" || !("type" in literal) || !("value" in literal)) return { type: "unknown" };
458
- const literalValue = literal.value;
459
- if (typeof literalValue === "string") return {
460
- type: "union",
461
- unionValues: [literalValue]
462
- };
463
- if (typeof literalValue === "boolean") return {
464
- type: "boolean",
465
- initialValue: literalValue
466
- };
467
- return { type: "unknown" };
468
- }
469
- function extractComponentName(filePath, componentsDir) {
470
- const relativePath = relative(componentsDir, filePath);
471
- const componentNamePattern = createRegExp(oneOrMore(charNotIn("/")).groupedAs("componentName"), exactly("/"));
472
- return relativePath.match(componentNamePattern)?.groups?.componentName ?? null;
473
- }
474
- async function findComponentDirs(componentsDir) {
475
- const components = (await readdir(componentsDir, { withFileTypes: true })).filter((entry) => entry.isDirectory()).map((entry) => entry.name);
476
- if (components.length === 0) throw new Error(`No component directories found in ${componentsDir}`);
477
- return components;
478
- }
479
-
480
- //#endregion
481
- export { componentProps, generateComponentMetadata };
@@ -1,3 +0,0 @@
1
- import { componentProps, generateComponentMetadata } from "./component-props.qwik.mjs";
2
-
3
- export { componentProps, generateComponentMetadata };
@@ -1,111 +0,0 @@
1
- import MagicString from "magic-string";
2
- import { parseSync } from "oxc-parser";
3
- import { walk } from "oxc-walker";
4
-
5
- //#region rolldown/qds-transform.ts
6
- /**
7
- * This plugin transforms hooks and patterns used in our libraries to improve developer experience.
8
- */ function qdsTransformPlugin() {
9
- return {
10
- name: "qds-transform",
11
- enforce: "pre",
12
- transform(code, id) {
13
- if (!/\.[jt]sx?$/.test(id)) return null;
14
- let ast;
15
- try {
16
- ast = parseSync(id, code);
17
- } catch {
18
- return null;
19
- }
20
- const s = new MagicString(code);
21
- let hasChanges = false;
22
- let needsDollarImport = false;
23
- walk(ast.program, { enter(node) {
24
- if (node.type !== "CallExpression") return;
25
- const callExpr = node;
26
- if (!isUseMountTaskCall(callExpr, code)) return;
27
- const callback = callExpr.arguments[0];
28
- if (!callback) return;
29
- if (callback.type !== "ArrowFunctionExpression" && callback.type !== "FunctionExpression") return;
30
- processCleanupCalls(callback, code, s, () => {
31
- hasChanges = true;
32
- needsDollarImport = true;
33
- });
34
- } });
35
- if (!hasChanges) return null;
36
- if (needsDollarImport) injectDollarImport(ast, code, s);
37
- return {
38
- code: s.toString(),
39
- map: s.generateMap({ hires: true })
40
- };
41
- }
42
- };
43
- }
44
- /**
45
- * Process cleanup calls within a useMountTask$ callback
46
- */ function processCleanupCalls(callback, code, s, onTransform) {
47
- walk(callback, { enter(node) {
48
- if (node.type !== "CallExpression") return;
49
- const callExpr = node;
50
- if (!isCleanupCall(callExpr, code)) return;
51
- const cleanupArg = callExpr.arguments[0];
52
- if (!cleanupArg) return;
53
- if (cleanupArg.type !== "ArrowFunctionExpression" && cleanupArg.type !== "FunctionExpression") return;
54
- if (isAlreadyWrappedWithQrl(callExpr, code)) return;
55
- s.prependLeft(cleanupArg.start, "$(");
56
- s.appendRight(cleanupArg.end, ")");
57
- onTransform();
58
- } });
59
- }
60
- /**
61
- * Check if a call expression is useMountTask$
62
- */ function isUseMountTaskCall(node, code) {
63
- if (node.callee.type === "Identifier") return code.slice(node.callee.start, node.callee.end) === "useMountTask$";
64
- return false;
65
- }
66
- /**
67
- * Check if a call expression is cleanup()
68
- */ function isCleanupCall(node, code) {
69
- if (node.callee.type === "Identifier") return code.slice(node.callee.start, node.callee.end) === "cleanup";
70
- return false;
71
- }
72
- /**
73
- * Check if the cleanup callback is already wrapped with $()
74
- */ function isAlreadyWrappedWithQrl(cleanupCall, code) {
75
- const arg = cleanupCall.arguments[0];
76
- if (!arg) return false;
77
- if (arg.type === "CallExpression") {
78
- const callExpr = arg;
79
- if (callExpr.callee.type === "Identifier") return code.slice(callExpr.callee.start, callExpr.callee.end) === "$";
80
- }
81
- return false;
82
- }
83
- function injectDollarImport(ast, code, s) {
84
- let qwikCoreImport = null;
85
- let hasDollarImport = false;
86
- for (const node of ast.program.body) {
87
- if (node.type !== "ImportDeclaration") continue;
88
- const importDecl = node;
89
- if (code.slice(importDecl.source.start + 1, importDecl.source.end - 1) === "@qwik.dev/core") {
90
- qwikCoreImport = importDecl;
91
- if (importDecl.specifiers) {
92
- for (const specifier of importDecl.specifiers) if (specifier.type === "ImportSpecifier" && "imported" in specifier) {
93
- const imported = specifier.imported;
94
- if ((imported.name || code.slice(imported.start, imported.end)) === "$") {
95
- hasDollarImport = true;
96
- break;
97
- }
98
- }
99
- }
100
- break;
101
- }
102
- }
103
- if (hasDollarImport) return;
104
- if (qwikCoreImport?.specifiers && qwikCoreImport.specifiers.length > 0) {
105
- const firstSpecifier = qwikCoreImport.specifiers[0];
106
- if (firstSpecifier.type === "ImportSpecifier") s.prependLeft(firstSpecifier.start, "$, ");
107
- }
108
- }
109
-
110
- //#endregion
111
- export { qdsTransformPlugin };