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.
@@ -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(process.env.FREE_PATH || '', 'templates/auth', name + '.html');
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 = `\${eventName}_\${tag.name}_\${Math.random().toString(36).substring(7)}`;
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 = `\${eventName}_child_\${Math.random().toString(36).substring(7)}`;
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
  }
@@ -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
- const sName = tokens.shift().value;
136
- if (tokens[0] && tokens[0].value === '=') tokens.shift();
137
-
138
- let sVal = "";
139
- let braceCount = 0;
140
- let bracketCount = 0;
141
-
142
- while (tokens.length > 0) {
143
- const t = tokens.shift();
144
- sVal += t.value;
145
- if (t.value === '{') braceCount++;
146
- if (t.value === '}') braceCount--;
147
- if (t.value === '[') bracketCount++;
148
- if (t.value === ']') bracketCount--;
149
-
150
- if (braceCount === 0 && bracketCount === 0) {
151
- // Check if next token is on same line (simple case) or if we are done with complex
152
- if (tokens[0] && tokens[0].line !== t.line && !['{', '[', '(', ','].includes(t.value)) {
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
- states.push({ name: sName, default: sVal.trim() || "null" });
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) });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "free-framework",
3
- "version": "4.5.6",
3
+ "version": "4.5.7",
4
4
  "description": "Professional Node.js engine for the .free language. Blazing-fast SSR, Islands Architecture, and built-in ORM.",
5
5
  "main": "index.js",
6
6
  "bin": {