sveld 0.24.2 → 0.24.3
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/lib/ComponentParser.d.ts
CHANGED
|
@@ -119,6 +119,11 @@ export default class ComponentParser {
|
|
|
119
119
|
* TypeScript directives are stripped before parsing, so we can safely take the last comment.
|
|
120
120
|
*/
|
|
121
121
|
private static findJSDocComment;
|
|
122
|
+
/**
|
|
123
|
+
* Check if a MemberExpression represents a well-known numeric constant.
|
|
124
|
+
* (e.g., Number.POSITIVE_INFINITY, Math.PI, etc.)
|
|
125
|
+
*/
|
|
126
|
+
private isNumericConstant;
|
|
122
127
|
private sourceAtPos;
|
|
123
128
|
private collectReactiveVars;
|
|
124
129
|
private addProp;
|
package/lib/ComponentParser.js
CHANGED
|
@@ -62,6 +62,34 @@ class ComponentParser {
|
|
|
62
62
|
return undefined;
|
|
63
63
|
return leadingComments[leadingComments.length - 1];
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if a MemberExpression represents a well-known numeric constant.
|
|
67
|
+
* (e.g., Number.POSITIVE_INFINITY, Math.PI, etc.)
|
|
68
|
+
*/
|
|
69
|
+
isNumericConstant(memberExpr) {
|
|
70
|
+
if (memberExpr.type !== "MemberExpression")
|
|
71
|
+
return false;
|
|
72
|
+
const objectName = memberExpr.object?.name;
|
|
73
|
+
const propertyName = memberExpr.property?.name;
|
|
74
|
+
if (!objectName || !propertyName)
|
|
75
|
+
return false;
|
|
76
|
+
if (objectName === "Number") {
|
|
77
|
+
return [
|
|
78
|
+
"POSITIVE_INFINITY",
|
|
79
|
+
"NEGATIVE_INFINITY",
|
|
80
|
+
"MAX_VALUE",
|
|
81
|
+
"MIN_VALUE",
|
|
82
|
+
"MAX_SAFE_INTEGER",
|
|
83
|
+
"MIN_SAFE_INTEGER",
|
|
84
|
+
"EPSILON",
|
|
85
|
+
"NaN",
|
|
86
|
+
].includes(propertyName);
|
|
87
|
+
}
|
|
88
|
+
if (objectName === "Math") {
|
|
89
|
+
return ["PI", "E", "LN2", "LN10", "LOG2E", "LOG10E", "SQRT2", "SQRT1_2"].includes(propertyName);
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
65
93
|
sourceAtPos(start, end) {
|
|
66
94
|
return this.source?.slice(start, end);
|
|
67
95
|
}
|
|
@@ -643,6 +671,15 @@ class ComponentParser {
|
|
|
643
671
|
// Don't infer type, just preserve existing type annotation.
|
|
644
672
|
value = this.sourceAtPos(init.start, init.end);
|
|
645
673
|
}
|
|
674
|
+
else if (init.type === "MemberExpression") {
|
|
675
|
+
// Handle member expressions like Number.POSITIVE_INFINITY, Math.PI, etc.
|
|
676
|
+
value = this.sourceAtPos(init.start, init.end);
|
|
677
|
+
// Infer type as "number" for well-known numeric constants
|
|
678
|
+
if (this.isNumericConstant(init)) {
|
|
679
|
+
type = "number";
|
|
680
|
+
}
|
|
681
|
+
// Otherwise, don't infer type, just preserve existing type annotation.
|
|
682
|
+
}
|
|
646
683
|
else {
|
|
647
684
|
value = init.raw;
|
|
648
685
|
type = init.value == null ? undefined : typeof init.value;
|
|
@@ -804,6 +841,15 @@ class ComponentParser {
|
|
|
804
841
|
// Don't infer type, just preserve existing type annotation.
|
|
805
842
|
value = this.sourceAtPos(init.start, init.end);
|
|
806
843
|
}
|
|
844
|
+
else if (init.type === "MemberExpression") {
|
|
845
|
+
// Handle member expressions like Number.POSITIVE_INFINITY, Math.PI, etc.
|
|
846
|
+
value = this.sourceAtPos(init.start, init.end);
|
|
847
|
+
// Infer type as "number" for well-known numeric constants
|
|
848
|
+
if (this.isNumericConstant(init)) {
|
|
849
|
+
type = "number";
|
|
850
|
+
}
|
|
851
|
+
// Otherwise, don't infer type, just preserve existing type annotation.
|
|
852
|
+
}
|
|
807
853
|
else {
|
|
808
854
|
value = init.raw;
|
|
809
855
|
type = init.value == null ? undefined : typeof init.value;
|
|
@@ -354,6 +354,10 @@ function genModuleExports(def) {
|
|
|
354
354
|
const rest_type = rest.map((item) => `=>${item}`).join("");
|
|
355
355
|
type_def = `export declare function ${prop.name}${first}:${second}${rest_type};`;
|
|
356
356
|
}
|
|
357
|
+
else if (prop.kind === "const") {
|
|
358
|
+
// For const exports from script context="module", use declare const instead of type
|
|
359
|
+
type_def = `export declare const ${prop.name}: ${prop.type || ANY_TYPE};`;
|
|
360
|
+
}
|
|
357
361
|
return `
|
|
358
362
|
${prop_comments.length > 0 ? `/**\n${prop_comments}*/` : EMPTY_STR}
|
|
359
363
|
${type_def}`;
|