Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
garag-lib committed Jun 8, 2024
1 parent 62ae513 commit 3a04112
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 60 deletions.
2 changes: 1 addition & 1 deletion docs/gtpl.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/gtpl.min.js.map

Large diffs are not rendered by default.

24 changes: 18 additions & 6 deletions docs/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<body>
<a href="https://github.com/garag-lib/GTPL">GTPL github</a>
<!-- ##################################################### -->
<div class="code-block">
<!-- <div class="code-block">
<pre><code class="language-html"></code></pre>
<template>
<div class="preload">load default data: <b>{{
Expand All @@ -66,7 +66,7 @@
</div>
<div class="rendered-block">
<div class="rendered-content"></div>
</div>
</div> -->
<!-- ##################################################### -->
<div class="code-block">
<pre><code class="language-html"></code></pre>
Expand All @@ -76,10 +76,16 @@
const var1 = 'aaa';
let var2 = 'bbb';
var var3 = 'ccc';
this.fn = function() { console.log(arguments); let var4; var4 = 'ddd'; return ''; }.bind(this);
const fn1 = function(ee,ff) { console.log(arguments, ee, ff); const fn1 = function(gg,hh) { let var4
= 123; } }.bind(this);
const fn2 = function (eee,fff) { console.log(arguments); const fn1 = function (ggg,hhh) { let var4 =
123; } }.bind(this);
const reault = ( 123 + 345 );
const fn3 = (aa,bb) => { console.log(aa,bb); const fn3 = (cc,dd) => { console.log(cc,dd); let var5 = 123; }; };
const fn4 = (aaa,bbb) => 111;
const fn5 = function () { return estasi };
return 'OK';
}}</b></div>
<div>{{ '':fn }}</div>
</template>
</div>
<div class="rendered-block">
Expand All @@ -95,19 +101,25 @@
const GCompile = gtpl.jit.GCompile;
const GAddToo = gtpl.GAddToo;
const GTpl = gtpl.GTpl;
function decodeHTMLEntities(text) {
const textarea = document.createElement('textarea');
textarea.innerHTML = text;
return textarea.value;
}
document.addEventListener('DOMContentLoaded', (event) => {
document.querySelectorAll('.code-block > template').forEach(async (template) => {
//---
let content = decodeHTMLEntities(template.innerHTML);
//---
const renderedContent = template.parentElement.nextElementSibling.querySelector('.rendered-content');
const aot = await GCode(template.innerHTML);
const aot = await GCode(content);
const objRoot = {};
const gtpl = new GTpl({ root: objRoot, generator: GCompile(aot) });
console.log(gtpl.Root);
objRoot.gtpl = gtpl;
gtpl.addTo(renderedContent);
//---
const codeBlock = template.previousElementSibling.querySelector('code');
let content = template.innerHTML;
content = content.replace(/^\n+/, '');
content = content.replace(/\n\s+$/, '');
const lines = content.split('\n');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gtpl",
"version": "1.1.0",
"version": "1.1.1",
"repository": "https://github.com/garag-lib/GTPL",
"description": "GTPL is a TypeScript library designed for creating reactive template systems with a unique approach that incorporates Direct DOM and Proxy. Inspired by technologies like Vue.js, angular aot or jsx, GTPL offers an efficient and powerful way to build reactive applications with optimized performance and all of this in a compact 9 KB javascript package.",
"main": "gtpl.js",
Expand Down
102 changes: 51 additions & 51 deletions src/compiler/GParse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export class GParse {
return false;
continue;
}

return true;
}
}
Expand Down Expand Up @@ -410,36 +409,61 @@ export class GParse {
this.i = 0;
let arr: TplVar[] = [], ret: null | IVarOrConst = null;
let ignoreall: boolean = false;
let cstop: string | null = null;
let cstop: string[] = [];
let ignore: any = [[]];
let declares = ['const', 'var', 'let'];
let arrowIndex = null;
while (true) {
if (!this.nop(true, cstop))
let cs = cstop.length ? cstop[cstop.length - 1] : null;
if (arrowIndex !== null) {
if (cs == '}' || cs === null) {
cs = '>';
} else {
arrowIndex = null;
}
}
if (!this.nop(true, cs))
break;
if (cstop !== null) {
const current = this.s[this.i];
if (cs !== null) {
let current = this.s[this.i];
if (current == '>') {
if (!this.next())
break;
if (this.ln == '=' && arrowIndex !== null) {
ignore.push(arr.splice(arrowIndex).map(v => v[0]));
if (!this.nop(true, '{'))
break;
current = this.s[this.i];
if (current == '{') {
cstop.push('}');
} else {
ignore.pop();
}
}
arrowIndex = null;
continue;
}
if (current == '(') {
ignoreall = true;
cstop = ')';
if (!this.nop(true, cstop))
break;
cstop.pop();
cstop.push(')');
continue;
}
if (current == ')') {
ignoreall = false;
cstop = '{';
if (!this.nop(true, cstop))
break;
cstop.pop();
cstop.push('{');
continue;
}
if (current == '{') {
cstop = '}';
if (!this.nop(true, cstop))
break;
cstop.pop();
cstop.push('}');
continue;
}
if (current == '}') {
cstop.pop();
ignore.pop();
cstop = null;
if (!this.nop(true, cstop))
break;
continue;
}
}
ret = this.getVOrC();
Expand All @@ -448,41 +472,40 @@ export class GParse {
if (palabrasReservadas.indexOf(va[0]) >= 0) {
if (ret.va[0] == 'function') {
ignore.push([]);
cstop = '(';
}
if (declares.includes(va[0])) {
cstop.push('(');
} else if (declares.includes(va[0])) {
if (!this.nop(true))
break;
ret = this.getVOrC();
if (ret && ret.va) {
ignore[ignore.length - 1].push(ret.va[0]);
}
}
if (!this.next())
break;
continue;
}
if (globalObject.hasOwnProperty(va[0]))
continue;
if (this.ln == '.') {
if (!this.next())
break;
continue;
}
if (ignoreall) {
ignore[ignore.length - 1].push(va[0]);
} else {
if (ignore.length) {
if (ignore.some((list: any) => list.includes(va[0]))) {
if (!this.next())
break;
continue;
}
}
if (!arr.some(list => list[0] == va[0]))
if (!arr.some(list => list[0] == va[0])) {
if (this.ln == '(') {
arrowIndex = arr.length;
} else if (this.ln != ',' && arrowIndex !== null) {
arrowIndex = null;
}
arr.push(va);
}
}
} else if (!this.next() /*&& this.isArrowFunction()*/) {
} else if (!this.next()) {
break;
}
}
Expand All @@ -492,27 +515,4 @@ export class GParse {
return arr;
}

isArrowFunction(): boolean {

console.error(this.s[this.i]);

return true;
/*
// Save current index
const savedIndex = this.i;
// Move backwards to check for "=>" indicating an arrow function
while (this.i > 0 && (this.s[this.i] === ' ' || this.s[this.i] === '\t' || this.s[this.i] === '\n')) {
this.i--;
}
// Check for arrow function "=>"
if (this.s[this.i] === '>' && this.i > 0 && this.s[this.i - 1] === '=') {
this.i = savedIndex;
return true;
}
// Restore original index and return false
this.i = savedIndex;
return false;
*/
}

}

0 comments on commit 3a04112

Please sign in to comment.