juxscript 1.1.4 → 1.1.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.
- package/machinery/compiler3.js +78 -0
- package/package.json +1 -1
package/machinery/compiler3.js
CHANGED
|
@@ -91,6 +91,84 @@ export class JuxCompiler {
|
|
|
91
91
|
return name.replace(/[^a-zA-Z0-9]/g, '_');
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
+
async loadJuxscriptExports() {
|
|
95
|
+
if (this._juxscriptExports) return this._juxscriptExports;
|
|
96
|
+
|
|
97
|
+
try {
|
|
98
|
+
const juxscriptPath = this.findJuxscriptPath();
|
|
99
|
+
if (juxscriptPath) {
|
|
100
|
+
const indexContent = fs.readFileSync(juxscriptPath, 'utf8');
|
|
101
|
+
const exports = new Set();
|
|
102
|
+
|
|
103
|
+
for (const match of indexContent.matchAll(/export\s*\{\s*([^}]+)\s*\}/g)) {
|
|
104
|
+
match[1].split(',').forEach(exp => {
|
|
105
|
+
const name = exp.trim().split(/\s+as\s+/)[0].trim();
|
|
106
|
+
if (name) exports.add(name);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
this._juxscriptExports = [...exports];
|
|
111
|
+
if (this._juxscriptExports.length > 0) {
|
|
112
|
+
console.log(`📦 juxscript exports: ${this._juxscriptExports.join(', ')}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
} catch (err) {
|
|
116
|
+
this._juxscriptExports = [];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return this._juxscriptExports;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
validateViewCode(viewName, code) {
|
|
123
|
+
const issues = [];
|
|
124
|
+
|
|
125
|
+
let ast;
|
|
126
|
+
try {
|
|
127
|
+
ast = acorn.parse(code, { ecmaVersion: 'latest', sourceType: 'module', locations: true });
|
|
128
|
+
} catch (parseError) {
|
|
129
|
+
issues.push({
|
|
130
|
+
type: 'error',
|
|
131
|
+
view: viewName,
|
|
132
|
+
line: parseError.loc?.line || 0,
|
|
133
|
+
message: `Syntax error: ${parseError.message}`,
|
|
134
|
+
code: ''
|
|
135
|
+
});
|
|
136
|
+
return issues;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const allImports = new Set();
|
|
140
|
+
|
|
141
|
+
walk(ast, {
|
|
142
|
+
ImportDeclaration(node) {
|
|
143
|
+
node.specifiers.forEach(spec => {
|
|
144
|
+
allImports.add(spec.local.name);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Default known facades/components if load fails
|
|
150
|
+
const knownComponents = this._juxscriptExports || ['element', 'input', 'buttonGroup'];
|
|
151
|
+
|
|
152
|
+
walk(ast, {
|
|
153
|
+
Identifier(node, parent) {
|
|
154
|
+
if (parent?.type === 'CallExpression' && parent.callee === node) {
|
|
155
|
+
const name = node.name;
|
|
156
|
+
if (!allImports.has(name) && knownComponents.includes(name)) {
|
|
157
|
+
issues.push({
|
|
158
|
+
type: 'warning',
|
|
159
|
+
view: viewName,
|
|
160
|
+
line: node.loc?.start?.line || 0,
|
|
161
|
+
message: `"${name}" is used but not imported from juxscript`,
|
|
162
|
+
code: ''
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
return issues;
|
|
170
|
+
}
|
|
171
|
+
|
|
94
172
|
/**
|
|
95
173
|
* Generate entry point without layout/theme logic
|
|
96
174
|
*/
|