free-framework 4.5.6 → 4.5.7
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/compiler/generator.js +4 -4
- package/compiler/parser.js +24 -24
- package/package.json +1 -1
package/compiler/generator.js
CHANGED
|
@@ -51,8 +51,8 @@ function generate(ast) {
|
|
|
51
51
|
|
|
52
52
|
output += `const loadAuthTemplate = (name, vars = {}) => {
|
|
53
53
|
const userTemplate = path.join(process.cwd(), 'resources/views/auth', name + '.html');
|
|
54
|
-
const coreTemplate = path.join(
|
|
55
|
-
let html = fs.existsSync(userTemplate) ? fs.readFileSync(userTemplate, 'utf8') : (fs.existsSync(coreTemplate) ? fs.readFileSync(coreTemplate, 'utf8') : 'Template not found');
|
|
54
|
+
const coreTemplate = path.join(__dirname, '../templates/auth', name + '.html');
|
|
55
|
+
let html = fs.existsSync(userTemplate) ? fs.readFileSync(userTemplate, 'utf8') : (fs.existsSync(coreTemplate) ? fs.readFileSync(coreTemplate, 'utf8') : 'Template not found: ' + name);
|
|
56
56
|
Object.keys(vars).forEach(k => html = html.replace(new RegExp('{{' + k + '}}', 'g'), vars[k]));
|
|
57
57
|
return html;
|
|
58
58
|
};\n`;
|
|
@@ -338,7 +338,7 @@ function generateTagCode(tag, stateNames) {
|
|
|
338
338
|
Object.keys(tag.attributes).forEach(a => {
|
|
339
339
|
if (a.startsWith('on')) {
|
|
340
340
|
const eventName = a.substring(2).toLowerCase();
|
|
341
|
-
const uniqueId =
|
|
341
|
+
const uniqueId = `${eventName}_${tag.name}_${Math.random().toString(36).substring(7)}`;
|
|
342
342
|
if (tag.attributes[a].includes('++')) {
|
|
343
343
|
const key = tag.attributes[a].split('++')[0].trim();
|
|
344
344
|
code += ` _events.push({ id: '${uniqueId}', fn: function(state) { state['${key}']++; } });\n`;
|
|
@@ -357,7 +357,7 @@ function generateTagCode(tag, stateNames) {
|
|
|
357
357
|
tag.children.forEach(child => {
|
|
358
358
|
if (child.type === 'event') {
|
|
359
359
|
const eventName = child.event.toLowerCase();
|
|
360
|
-
const uniqueId =
|
|
360
|
+
const uniqueId = `${eventName}_child_${Math.random().toString(36).substring(7)}`;
|
|
361
361
|
code += ` _events.push({ id: '${uniqueId}', fn: function(state, event) { ${child.code} } });\n`;
|
|
362
362
|
code += ` html += " data-on-${eventName}='${uniqueId}'";\n`;
|
|
363
363
|
}
|
package/compiler/parser.js
CHANGED
|
@@ -132,33 +132,33 @@ function parseComponent(tokens, filename, source) {
|
|
|
132
132
|
while (tokens.length > 0 && tokens[0].value !== '}' && tokens[0].value !== 'component') {
|
|
133
133
|
const next = tokens.shift();
|
|
134
134
|
if (next.value === 'state') {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
break;
|
|
135
|
+
if (tokens[0] && tokens[0].value === '{') {
|
|
136
|
+
tokens.shift(); // consume {
|
|
137
|
+
while (tokens.length > 0 && tokens[0].value !== '}') {
|
|
138
|
+
const sName = tokens.shift().value;
|
|
139
|
+
if (tokens[0] && tokens[0].value === ':') tokens.shift();
|
|
140
|
+
|
|
141
|
+
let sVal = "";
|
|
142
|
+
let bCount = 0;
|
|
143
|
+
while (tokens.length > 0) {
|
|
144
|
+
const t = tokens.shift();
|
|
145
|
+
if (t.value === '{') bCount++;
|
|
146
|
+
if (t.value === '}') bCount--;
|
|
147
|
+
if (bCount < 0) { tokens.unshift(t); break; }
|
|
148
|
+
if (bCount === 0 && (t.value === ',' || t.line !== tokens[0]?.line)) {
|
|
149
|
+
if (t.value !== ',') sVal += t.value;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
sVal += t.value;
|
|
154
153
|
}
|
|
154
|
+
states.push({ name: sName, default: sVal.trim().replace(/^'|'$/g, '"') || "null" });
|
|
155
155
|
}
|
|
156
|
-
|
|
157
|
-
sVal = sVal.replace(/"/g, '');
|
|
158
|
-
if (!isNaN(sVal) && sVal.trim() !== "" && !sVal.includes('.')) {
|
|
159
|
-
states.push({ name: sName, default: Number(sVal) });
|
|
156
|
+
if (tokens[0] && tokens[0].value === '}') tokens.shift();
|
|
160
157
|
} else {
|
|
161
|
-
|
|
158
|
+
const sName = tokens.shift().value;
|
|
159
|
+
if (tokens[0] && (tokens[0].value === '=' || tokens[0].value === ':')) tokens.shift();
|
|
160
|
+
let sVal = tokens.shift().value;
|
|
161
|
+
states.push({ name: sName, default: sVal });
|
|
162
162
|
}
|
|
163
163
|
} else if (next.value === 'onMount') {
|
|
164
164
|
body.push({ type: 'onMount', code: parseActionBody(tokens, source) });
|