@stacksjs/stx 0.2.188 → 0.2.189
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.
- package/dist/cli.js +422 -422
- package/dist/component-library.js +20 -3
- package/dist/craft.js +343 -343
- package/dist/pwa.js +443 -443
- package/dist/ssg.d.ts +1 -1
- package/dist/ssg.js +362 -362
- package/dist/utils.js +23 -44
- package/dist/variable-extractor.js +3 -6
- package/package.json +5 -5
|
@@ -110,6 +110,20 @@ function extractStyles(source) {
|
|
|
110
110
|
|
|
111
111
|
`);
|
|
112
112
|
}
|
|
113
|
+
function typeFromDeclaration(declaration) {
|
|
114
|
+
if (!declaration)
|
|
115
|
+
return null;
|
|
116
|
+
const type = declaration.replace(/\s*\|\s*(?:undefined|null)\b/g, "").trim();
|
|
117
|
+
if (/^string$/.test(type))
|
|
118
|
+
return "string";
|
|
119
|
+
if (/^number$/.test(type))
|
|
120
|
+
return "number";
|
|
121
|
+
if (/^boolean$/.test(type))
|
|
122
|
+
return "boolean";
|
|
123
|
+
if (/^(?:'[^']*'|"[^"]*")(?:\s*\|\s*(?:'[^']*'|"[^"]*"))*$/.test(type))
|
|
124
|
+
return "string";
|
|
125
|
+
return "object";
|
|
126
|
+
}
|
|
113
127
|
function inferPropertyType(fallback) {
|
|
114
128
|
if (fallback === void 0)
|
|
115
129
|
return "object";
|
|
@@ -194,7 +208,7 @@ function compileScriptScope(source, file, outputDir) {
|
|
|
194
208
|
if (!block)
|
|
195
209
|
return { imports: [], body: "", propNames: [], defaults: {} };
|
|
196
210
|
let code = block[2];
|
|
197
|
-
const imports = [], propNames = [], defaults = {};
|
|
211
|
+
const imports = [], propNames = [], defaults = {}, declared = {};
|
|
198
212
|
code = code.replace(/^\s*import\s+[\s\S]*?from\s*['"][^'"]+['"];?\s*$/gm, (statement) => {
|
|
199
213
|
if (/from\s*['"]stx['"]/.test(statement))
|
|
200
214
|
return "";
|
|
@@ -215,8 +229,11 @@ function compileScriptScope(source, file, outputDir) {
|
|
|
215
229
|
defaults[pair[1]] = pair[2].trim();
|
|
216
230
|
code = code.replace(propMatch[0], "");
|
|
217
231
|
}
|
|
232
|
+
for (const block of code.matchAll(/(?:export\s+)?interface\s+[A-Za-z_$][\w$]*\s*\{([\s\S]*?)\n\}/g))
|
|
233
|
+
for (const member of block[1].matchAll(/^\s*(?:\/\*\*[\s\S]*?\*\/\s*)?([A-Za-z_$][\w$]*)\??\s*:\s*([^\n;]+)/gm))
|
|
234
|
+
declared[member[1]] = member[2].trim();
|
|
218
235
|
code = code.replace(/(?:export\s+)?interface\s+[A-Za-z_$][\w$]*\s*\{[\s\S]*?\n\}/g, "");
|
|
219
|
-
return { imports, body: code.trim(), propNames, defaults };
|
|
236
|
+
return { imports, body: code.trim(), propNames, defaults, declared };
|
|
220
237
|
}
|
|
221
238
|
function compileEventDirectives(template) {
|
|
222
239
|
const eventTypes = new Set;
|
|
@@ -264,7 +281,7 @@ async function compileComponent(inputDir, entry, defaults) {
|
|
|
264
281
|
continue;
|
|
265
282
|
const fallback = scope.defaults[propertyName];
|
|
266
283
|
properties[propertyName] = normalizeProperty(propertyName, {
|
|
267
|
-
type: inferPropertyType(fallback),
|
|
284
|
+
type: typeFromDeclaration(scope.declared[propertyName]) ?? inferPropertyType(fallback),
|
|
268
285
|
...fallback === void 0 ? {} : { default: literalValue(fallback) }
|
|
269
286
|
});
|
|
270
287
|
}
|