@xnoxs/flux-lang 3.1.1
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/CHANGELOG.md +103 -0
- package/README.md +1089 -0
- package/bin/flux.js +1397 -0
- package/dist/flux.cjs.js +6664 -0
- package/dist/flux.esm.js +6674 -0
- package/dist/flux.min.js +263 -0
- package/index.d.ts +202 -0
- package/index.js +26 -0
- package/package.json +77 -0
- package/scripts/build.js +76 -0
- package/src/bundler.js +216 -0
- package/src/checker.js +322 -0
- package/src/codegen.js +785 -0
- package/src/css-preprocessor.js +399 -0
- package/src/formatter.js +140 -0
- package/src/jsx.js +480 -0
- package/src/lexer.js +518 -0
- package/src/linter.js +758 -0
- package/src/mangler.js +280 -0
- package/src/parser.js +1671 -0
- package/src/self/bundler.flux +167 -0
- package/src/self/bundler.js +187 -0
- package/src/self/checker.flux +249 -0
- package/src/self/checker.js +338 -0
- package/src/self/codegen.flux +555 -0
- package/src/self/codegen.js +784 -0
- package/src/self/css-preprocessor.flux +373 -0
- package/src/self/css-preprocessor.js +387 -0
- package/src/self/formatter.flux +93 -0
- package/src/self/formatter.js +114 -0
- package/src/self/jsx.flux +430 -0
- package/src/self/jsx.js +396 -0
- package/src/self/lexer.flux +529 -0
- package/src/self/lexer.js +709 -0
- package/src/self/lexer.stage2.js +700 -0
- package/src/self/linter.flux +515 -0
- package/src/self/linter.js +804 -0
- package/src/self/mangler.flux +253 -0
- package/src/self/mangler.js +348 -0
- package/src/self/parser.flux +1146 -0
- package/src/self/parser.js +1571 -0
- package/src/self/sourcemap.flux +66 -0
- package/src/self/sourcemap.js +72 -0
- package/src/self/stdlib.flux +356 -0
- package/src/self/stdlib.js +396 -0
- package/src/self/test-runner.flux +201 -0
- package/src/self/test-runner.js +132 -0
- package/src/self/transpiler.flux +123 -0
- package/src/self/transpiler.js +83 -0
- package/src/self/type-checker.flux +821 -0
- package/src/self/type-checker.js +1106 -0
- package/src/sourcemap.js +82 -0
- package/src/stdlib.js +436 -0
- package/src/test-runner.js +239 -0
- package/src/transpiler.js +172 -0
- package/src/type-checker.js +1206 -0
package/src/self/jsx.js
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
// Flux JSX Runtime
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
function _fluxH(tag,props,...children){
|
|
5
|
+
if(tag===""){const f=document.createDocumentFragment();children.flat(Infinity).forEach(c=>{if(c==null)return;f.appendChild(c instanceof Node?c:document.createTextNode(String(c)));});return f;}
|
|
6
|
+
const el=document.createElement(tag);
|
|
7
|
+
if(props){for(const[k,v]of Object.entries(props)){if(k==="class"||k==="className"){el.className=v;}else if(k==="style"&&typeof v==="object"){Object.assign(el.style,v);}else if(k.startsWith("on")&&typeof v==="function"){el.addEventListener(k.slice(2).toLowerCase(),v);}else if(typeof v==="boolean"){if(v)el.setAttribute(k,"");}else{el.setAttribute(k,String(v));}}}
|
|
8
|
+
children.flat(Infinity).forEach(c=>{if(c==null)return;el.appendChild(c instanceof Node?c:document.createTextNode(String(c)));});
|
|
9
|
+
return el;
|
|
10
|
+
}
|
|
11
|
+
function _fluxCSS(css){const s=document.createElement("style");s.textContent=css;document.head.appendChild(s);return css;}
|
|
12
|
+
// ── Flux stdlib ──
|
|
13
|
+
|
|
14
|
+
function map(arr, fn) { return arr.map(fn); }
|
|
15
|
+
|
|
16
|
+
function forEach(arr, fn) { arr.forEach(fn); return arr; }
|
|
17
|
+
|
|
18
|
+
function join(arr, sep) { return arr.join(sep != null ? sep : ','); }
|
|
19
|
+
|
|
20
|
+
function flat(arr, depth) { return arr.flat(depth != null ? depth : 1); }
|
|
21
|
+
|
|
22
|
+
function includes(arr, val) { return arr.includes(val); }
|
|
23
|
+
// ── end stdlib ──
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const JSX_STYLE_VALUE_PROPS = { bg: (v) => ("background:" + v), fg: (v) => ("color:" + v), color: (v) => ("color:" + v), p: (v) => ("padding:" + v), px: (v) => ((("paddingLeft:" + v) + ",paddingRight:") + v), py: (v) => ((("paddingTop:" + v) + ",paddingBottom:") + v), pt: (v) => ("paddingTop:" + v), pb: (v) => ("paddingBottom:" + v), pl: (v) => ("paddingLeft:" + v), pr: (v) => ("paddingRight:" + v), m: (v) => ("margin:" + v), mx: (v) => ((("marginLeft:" + v) + ",marginRight:") + v), my: (v) => ((("marginTop:" + v) + ",marginBottom:") + v), mt: (v) => ("marginTop:" + v), mb: (v) => ("marginBottom:" + v), ml: (v) => ("marginLeft:" + v), mr: (v) => ("marginRight:" + v), radius: (v) => ("borderRadius:" + v), w: (v) => ("width:" + v), h: (v) => ("height:" + v), "min-w": (v) => ("minWidth:" + v), "max-w": (v) => ("maxWidth:" + v), "min-h": (v) => ("minHeight:" + v), "max-h": (v) => ("maxHeight:" + v), gap: (v) => ("gap:" + v), "col-gap": (v) => ("columnGap:" + v), "row-gap": (v) => ("rowGap:" + v), text: (v) => ("fontSize:" + v), font: (v) => ("fontFamily:" + v), weight: (v) => ("fontWeight:" + v), tracking: (v) => ("letterSpacing:" + v), leading: (v) => ("lineHeight:" + v), shadow: (v) => ("boxShadow:" + v), opacity: (v) => ("opacity:" + v), border: (v) => ("border:" + v), outline: (v) => ("outline:" + v), transition: (v) => ("transition:" + v), cursor: (v) => ("cursor:" + v), overflow: (v) => ("overflow:" + v), z: (v) => ("zIndex:" + v), transform: (v) => ("transform:" + v), direction: (v) => ("flexDirection:" + v), align: (v) => ("alignItems:" + v), justify: (v) => ("justifyContent:" + v), "align-self": (v) => ("alignSelf:" + v), "place-items": (v) => ("placeItems:" + v), grow: (v) => ("flexGrow:" + v), shrink: (v) => ("flexShrink:" + v), basis: (v) => ("flexBasis:" + v), cols: (v) => ("gridTemplateColumns:" + v), rows: (v) => ("gridTemplateRows:" + v), inset: (v) => ("inset:" + v), top: (v) => ("top:" + v), right: (v) => ("right:" + v), bottom: (v) => ("bottom:" + v), left: (v) => ("left:" + v), "object-fit": (v) => ("objectFit:" + v), "line-height": (v) => ("lineHeight:" + v), "text-align": (v) => ("textAlign:" + v), decoration: (v) => ("textDecoration:" + v), clip: (v) => ("clipPath:" + v), filter: (v) => ("filter:" + v), backdrop: (v) => ("backdropFilter:" + v), animation: (v) => ("animation:" + v) };
|
|
27
|
+
const JSX_STYLE_BOOL_PROPS = { flex: "display:\"flex\"", grid: "display:\"grid\"", block: "display:\"block\"", "inline-flex": "display:\"inline-flex\"", "inline-block": "display:\"inline-block\"", bold: "fontWeight:700", italic: "fontStyle:\"italic\"", underline: "textDecoration:\"underline\"", pointer: "cursor:\"pointer\"", hidden: "display:\"none\"", relative: "position:\"relative\"", absolute: "position:\"absolute\"", fixed: "position:\"fixed\"", sticky: "position:\"sticky\"", "flex-col": "flexDirection:\"column\"", "flex-row": "flexDirection:\"row\"", "flex-wrap": "flexWrap:\"wrap\"", "flex-1": "flex:1", "w-full": "width:\"100%\"", "h-full": "height:\"100%\"", center: "textAlign:\"center\"", truncate: "overflow:\"hidden\",textOverflow:\"ellipsis\",whiteSpace:\"nowrap\"", "select-none": "userSelect:\"none\"", "no-wrap": "whiteSpace:\"nowrap\"", "no-list": "listStyle:\"none\"", "no-outline": "outline:\"none\"", "no-border": "border:\"none\"", "box-border": "boxSizing:\"border-box\"" };
|
|
28
|
+
const FLUX_H_BROWSER = "function _fluxH(tag,props,...children){\n if(tag===\"\"){const f=document.createDocumentFragment();children.flat(Infinity).forEach(c=>{if(c==null)return;f.appendChild(c instanceof Node?c:document.createTextNode(String(c)));});return f;}\n const el=document.createElement(tag);\n if(props){for(const[k,v]of Object.entries(props)){if(k===\"class\"||k===\"className\"){el.className=v;}else if(k===\"style\"&&typeof v===\"object\"){Object.assign(el.style,v);}else if(k.startsWith(\"on\")&&typeof v===\"function\"){el.addEventListener(k.slice(2).toLowerCase(),v);}else if(typeof v===\"boolean\"){if(v)el.setAttribute(k,\"\");}else{el.setAttribute(k,String(v));}}}\n children.flat(Infinity).forEach(c=>{if(c==null)return;el.appendChild(c instanceof Node?c:document.createTextNode(String(c)));});\n return el;\n}";
|
|
29
|
+
module.exports.FLUX_H_BROWSER = FLUX_H_BROWSER;
|
|
30
|
+
const FLUX_H_SERVER = (((((((((((("function _fluxH(tag,props,...children){\n const VOID=new Set([\"area\",\"base\",\"br\",\"col\",\"embed\",\"hr\",\"img\",\"input\",\"link\",\"meta\",\"param\",\"source\",\"track\",\"wbr\"]);\n if(tag===\"\")return children.flat(Infinity).map(c=>c==null?\"\":String(c)).join(\"\");\n let attrs=\"\";\n if(props){for(const[k,v]of Object.entries(props)){if(k===\"class\"||k===\"className\")attrs+=" + "` class=\"${v}\"`") + ";else if(k===\"style\"&&typeof v===\"object\")attrs+=") + "` style=\"${Object.entries(v).map(([p,val])=>p.replace(/[A-Z]/g,m=>\"-\"+m.toLowerCase())+\":\"+val).join(\";\")}\"`") + ";else if(typeof v!==\"function\"&&typeof v!==\"boolean\")attrs+=") + "` ${k}=\"${String(v).replace(/\"/g,\""\")}\"`") + ";else if(v===true)attrs+=") + "` ${k}`") + ";}}\n const inner=children.flat(Infinity).map(c=>c==null?\"\":String(c)).join(\"\");\n if(VOID.has(tag))return") + "`<${tag}${attrs}>`") + ";\n return") + "`<${tag}${attrs}>${inner}</${tag}>`") + ";\n}");
|
|
31
|
+
module.exports.FLUX_H_SERVER = FLUX_H_SERVER;
|
|
32
|
+
const FLUX_CSS_BROWSER = "function _fluxCSS(css){const s=document.createElement(\"style\");s.textContent=css;document.head.appendChild(s);return css;}";
|
|
33
|
+
module.exports.FLUX_CSS_BROWSER = FLUX_CSS_BROWSER;
|
|
34
|
+
const FLUX_CSS_SERVER = "function _fluxCSS(css){return css;}";
|
|
35
|
+
module.exports.FLUX_CSS_SERVER = FLUX_CSS_SERVER;
|
|
36
|
+
class JsxPreprocessor {
|
|
37
|
+
constructor(src, pos, out, hasJsx) {
|
|
38
|
+
this.src = src;
|
|
39
|
+
this.pos = pos;
|
|
40
|
+
this.out = out;
|
|
41
|
+
this.hasJsx = hasJsx;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
transform() {
|
|
45
|
+
while ((this.pos < this.src.length)) {
|
|
46
|
+
this.scanTop();
|
|
47
|
+
}
|
|
48
|
+
this.hasJsx = (this.out != this.src);
|
|
49
|
+
return this.out;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
scanTop() {
|
|
53
|
+
const c = this.src[this.pos];
|
|
54
|
+
if (((c == "/") && (this.src[(this.pos + 1)] == "/"))) {
|
|
55
|
+
const end_ = this.src.indexOf("\n", this.pos);
|
|
56
|
+
if ((end_ == -1)) {
|
|
57
|
+
this.out = (this.out + this.src.slice(this.pos));
|
|
58
|
+
this.pos = this.src.length;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
this.out = (this.out + this.src.slice(this.pos, (end_ + 1)));
|
|
62
|
+
this.pos = (end_ + 1);
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (((c == "/") && (this.src[(this.pos + 1)] == "*"))) {
|
|
67
|
+
const end_ = this.src.indexOf("*/", (this.pos + 2));
|
|
68
|
+
if ((end_ == -1)) {
|
|
69
|
+
this.out = (this.out + this.src.slice(this.pos));
|
|
70
|
+
this.pos = this.src.length;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
this.out = (this.out + this.src.slice(this.pos, (end_ + 2)));
|
|
74
|
+
this.pos = (end_ + 2);
|
|
75
|
+
}
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if ((c == "\"")) {
|
|
79
|
+
this.passString("\"");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if ((c == "'")) {
|
|
83
|
+
this.passString("'");
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if ((c == "`")) {
|
|
87
|
+
this.passTemplateLit();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (((c == "<") && this.isJsxStart())) {
|
|
91
|
+
const jsxCode = this.parseJsxElement();
|
|
92
|
+
this.out = (this.out + jsxCode);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this.out = (this.out + c);
|
|
96
|
+
this.pos = (this.pos + 1);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
isJsxStart() {
|
|
100
|
+
const next = (this.src[(this.pos + 1)] ?? "");
|
|
101
|
+
if ((((next != ">") && !((next >= "a") && (next <= "z"))) && !((next >= "A") && (next <= "Z")))) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
let i = (this.pos - 1);
|
|
105
|
+
while (((i >= 0) && ((this.src[i] == " ") || (this.src[i] == "\t")))) {
|
|
106
|
+
i = (i - 1);
|
|
107
|
+
}
|
|
108
|
+
if ((i < 0)) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
const prev = this.src[i];
|
|
112
|
+
if ("=([{,:>\n?".includes(prev)) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
if (/[a-z]/.test(prev)) {
|
|
116
|
+
let j = i;
|
|
117
|
+
while (((j >= 0) && /[a-z]/.test(this.src[j]))) {
|
|
118
|
+
j = (j - 1);
|
|
119
|
+
}
|
|
120
|
+
const word = this.src.slice((j + 1), (i + 1));
|
|
121
|
+
const exprKw = new Set(["return", "not", "and", "or", "val", "var", "await", "yield", "else", "in", "throw"]);
|
|
122
|
+
if (exprKw.has(word)) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
passString(quote) {
|
|
130
|
+
this.out = (this.out + quote);
|
|
131
|
+
this.pos = (this.pos + 1);
|
|
132
|
+
while ((this.pos < this.src.length)) {
|
|
133
|
+
const c = this.src[this.pos];
|
|
134
|
+
if ((c == "\\")) {
|
|
135
|
+
this.out = ((this.out + c) + (this.src[(this.pos + 1)] ?? ""));
|
|
136
|
+
this.pos = (this.pos + 2);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
if ((c == quote)) {
|
|
140
|
+
this.out = (this.out + c);
|
|
141
|
+
this.pos = (this.pos + 1);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
this.out = (this.out + c);
|
|
145
|
+
this.pos = (this.pos + 1);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
passTemplateLit() {
|
|
150
|
+
this.out = (this.out + "`");
|
|
151
|
+
this.pos = (this.pos + 1);
|
|
152
|
+
while ((this.pos < this.src.length)) {
|
|
153
|
+
const c = this.src[this.pos];
|
|
154
|
+
if ((c == "\\")) {
|
|
155
|
+
this.out = ((this.out + c) + (this.src[(this.pos + 1)] ?? ""));
|
|
156
|
+
this.pos = (this.pos + 2);
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
if ((c == "`")) {
|
|
160
|
+
this.out = (this.out + c);
|
|
161
|
+
this.pos = (this.pos + 1);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
this.out = (this.out + c);
|
|
165
|
+
this.pos = (this.pos + 1);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
parseJsxElement() {
|
|
170
|
+
this.pos = (this.pos + 1);
|
|
171
|
+
if ((this.src[this.pos] == ">")) {
|
|
172
|
+
this.pos = (this.pos + 1);
|
|
173
|
+
const children = this.parseJsxChildren("");
|
|
174
|
+
this.expectClose("");
|
|
175
|
+
const childStr = ((children.length > 0) ? ("," + children.join(",")) : "");
|
|
176
|
+
return (("_fluxH(\"\",null" + childStr) + ")");
|
|
177
|
+
}
|
|
178
|
+
const tag = this.readTagName();
|
|
179
|
+
const attrs = this.parseJsxAttrs();
|
|
180
|
+
if (((this.src[this.pos] == "/") && (this.src[(this.pos + 1)] == ">"))) {
|
|
181
|
+
this.pos = (this.pos + 2);
|
|
182
|
+
return (((("_fluxH(\"" + tag) + "\",") + attrs) + ")");
|
|
183
|
+
}
|
|
184
|
+
if ((this.src[this.pos] == ">")) {
|
|
185
|
+
this.pos = (this.pos + 1);
|
|
186
|
+
const children = this.parseJsxChildren(tag);
|
|
187
|
+
this.expectClose(tag);
|
|
188
|
+
const childStr = ((children.length > 0) ? ("," + children.join(",")) : "");
|
|
189
|
+
return ((((("_fluxH(\"" + tag) + "\",") + attrs) + childStr) + ")");
|
|
190
|
+
}
|
|
191
|
+
return ("<" + tag);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
readTagName() {
|
|
195
|
+
let name = "";
|
|
196
|
+
while ((this.pos < this.src.length)) {
|
|
197
|
+
const c = this.src[this.pos];
|
|
198
|
+
if (/[a-zA-Z0-9\-_\.]/.test(c)) {
|
|
199
|
+
name = (name + c);
|
|
200
|
+
this.pos = (this.pos + 1);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return name;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
parseJsxAttrs() {
|
|
210
|
+
this.skipWs();
|
|
211
|
+
const pairs = [];
|
|
212
|
+
const styleParts = [];
|
|
213
|
+
let explicitStyle = null;
|
|
214
|
+
while ((this.pos < this.src.length)) {
|
|
215
|
+
const c = this.src[this.pos];
|
|
216
|
+
if (((c == ">") || ((c == "/") && (this.src[(this.pos + 1)] == ">")))) {
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
this.skipWs();
|
|
220
|
+
if (!/[a-zA-Z_\-]/.test((this.src[this.pos] ?? ""))) {
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
let attrName = "";
|
|
224
|
+
while (((this.pos < this.src.length) && /[a-zA-Z0-9\-_:]/.test(this.src[this.pos]))) {
|
|
225
|
+
attrName = (attrName + this.src[this.pos]);
|
|
226
|
+
this.pos = (this.pos + 1);
|
|
227
|
+
}
|
|
228
|
+
this.skipWs();
|
|
229
|
+
if ((this.src[this.pos] != "=")) {
|
|
230
|
+
const boolStyle = JSX_STYLE_BOOL_PROPS[attrName];
|
|
231
|
+
if ((boolStyle != undefined)) {
|
|
232
|
+
styleParts.push(boolStyle);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
pairs.push((("\"" + attrName) + "\":true"));
|
|
236
|
+
}
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
this.pos = (this.pos + 1);
|
|
240
|
+
this.skipWs();
|
|
241
|
+
const ch = this.src[this.pos];
|
|
242
|
+
let rawVal = "";
|
|
243
|
+
let exprVal_ = "";
|
|
244
|
+
if (((ch == "\"") || (ch == "'"))) {
|
|
245
|
+
const q = ch;
|
|
246
|
+
this.pos = (this.pos + 1);
|
|
247
|
+
let v = "";
|
|
248
|
+
while (((this.pos < this.src.length) && (this.src[this.pos] != q))) {
|
|
249
|
+
if ((this.src[this.pos] == "\\")) {
|
|
250
|
+
v = ((v + this.src[this.pos]) + this.src[(this.pos + 1)]);
|
|
251
|
+
this.pos = (this.pos + 2);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
v = (v + this.src[this.pos]);
|
|
255
|
+
this.pos = (this.pos + 1);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
this.pos = (this.pos + 1);
|
|
259
|
+
rawVal = v;
|
|
260
|
+
}
|
|
261
|
+
else if ((ch == "{")) {
|
|
262
|
+
exprVal_ = this.readBraced();
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
const boolStyle = JSX_STYLE_BOOL_PROPS[attrName];
|
|
266
|
+
if ((boolStyle != undefined)) {
|
|
267
|
+
styleParts.push(boolStyle);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
pairs.push((("\"" + attrName) + "\":true"));
|
|
271
|
+
}
|
|
272
|
+
this.skipWs();
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if (((rawVal != null) && JSX_STYLE_VALUE_PROPS[attrName])) {
|
|
276
|
+
const expanded = JSX_STYLE_VALUE_PROPS[attrName](JSON.stringify(rawVal));
|
|
277
|
+
styleParts.push(expanded);
|
|
278
|
+
}
|
|
279
|
+
else if (((exprVal_ != null) && (attrName == "style"))) {
|
|
280
|
+
explicitStyle = exprVal_;
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
if ((rawVal != null)) {
|
|
284
|
+
pairs.push(((("\"" + attrName) + "\":") + JSON.stringify(rawVal)));
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
pairs.push(((("\"" + attrName) + "\":") + exprVal_));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
this.skipWs();
|
|
291
|
+
}
|
|
292
|
+
if (((styleParts.length > 0) || (explicitStyle != null))) {
|
|
293
|
+
const utilObj = ((styleParts.length > 0) ? (("{" + styleParts.join(",")) + "}") : null);
|
|
294
|
+
if (((explicitStyle != null) && (utilObj != null))) {
|
|
295
|
+
pairs.push((((("\"style\":Object.assign(" + explicitStyle) + ",") + utilObj) + ")"));
|
|
296
|
+
}
|
|
297
|
+
else if ((explicitStyle != null)) {
|
|
298
|
+
pairs.push(("\"style\":" + explicitStyle));
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
pairs.push((("\"style\":{" + styleParts.join(",")) + "}"));
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return ((pairs.length > 0) ? (("{" + pairs.join(",")) + "}") : "null");
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
readBraced() {
|
|
308
|
+
this.pos = (this.pos + 1);
|
|
309
|
+
let depth = 1;
|
|
310
|
+
let content = "";
|
|
311
|
+
while (((this.pos < this.src.length) && (depth > 0))) {
|
|
312
|
+
const c = this.src[this.pos];
|
|
313
|
+
if ((c == "{")) {
|
|
314
|
+
depth = (depth + 1);
|
|
315
|
+
}
|
|
316
|
+
if ((c == "}")) {
|
|
317
|
+
depth = (depth - 1);
|
|
318
|
+
if ((depth == 0)) {
|
|
319
|
+
this.pos = (this.pos + 1);
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
content = (content + c);
|
|
324
|
+
this.pos = (this.pos + 1);
|
|
325
|
+
}
|
|
326
|
+
return content.trim();
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
parseJsxChildren(tag) {
|
|
330
|
+
const children = [];
|
|
331
|
+
while ((this.pos < this.src.length)) {
|
|
332
|
+
if (((this.src[this.pos] == "<") && (this.src[(this.pos + 1)] == "/"))) {
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
if ((this.src[this.pos] == "<")) {
|
|
336
|
+
const next = (this.src[(this.pos + 1)] ?? "");
|
|
337
|
+
if (((((next >= "a") && (next <= "z")) || ((next >= "A") && (next <= "Z"))) || (next == ">"))) {
|
|
338
|
+
children.push(this.parseJsxElement());
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if ((this.src[this.pos] == "{")) {
|
|
343
|
+
const expr = this.readBraced();
|
|
344
|
+
if (expr.trim()) {
|
|
345
|
+
children.push(expr);
|
|
346
|
+
}
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
349
|
+
let text = "";
|
|
350
|
+
while ((this.pos < this.src.length)) {
|
|
351
|
+
const c = this.src[this.pos];
|
|
352
|
+
if (((c == "<") || (c == "{"))) {
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
text = (text + c);
|
|
356
|
+
this.pos = (this.pos + 1);
|
|
357
|
+
}
|
|
358
|
+
const trimmed = text.replace(/\s+/g, " ").trim();
|
|
359
|
+
if (trimmed) {
|
|
360
|
+
children.push(JSON.stringify(trimmed));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return children;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
expectClose(tag) {
|
|
367
|
+
if (((this.src[this.pos] == "<") && (this.src[(this.pos + 1)] == "/"))) {
|
|
368
|
+
this.pos = (this.pos + 2);
|
|
369
|
+
while (((this.pos < this.src.length) && (this.src[this.pos] != ">"))) {
|
|
370
|
+
this.pos = (this.pos + 1);
|
|
371
|
+
}
|
|
372
|
+
if ((this.src[this.pos] == ">")) {
|
|
373
|
+
this.pos = (this.pos + 1);
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
skipWs() {
|
|
379
|
+
while (((this.pos < this.src.length) && ((this.src[this.pos] == " ") || (this.src[this.pos] == "\t")))) {
|
|
380
|
+
this.pos = (this.pos + 1);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
module.exports.JsxPreprocessor = JsxPreprocessor;
|
|
387
|
+
function transformJsx(src, opts) {
|
|
388
|
+
const target = ((opts ?? { }).target ?? "browser");
|
|
389
|
+
const proc = new JsxPreprocessor(src, 0, "", false);
|
|
390
|
+
const source = proc.transform();
|
|
391
|
+
const hasJsx = ((proc.hasJsx || src.includes("_fluxH")) || src.includes("_fluxCSS"));
|
|
392
|
+
const hHelper = ((target == "browser") ? FLUX_H_BROWSER : FLUX_H_SERVER);
|
|
393
|
+
const cssHelper = ((target == "browser") ? FLUX_CSS_BROWSER : FLUX_CSS_SERVER);
|
|
394
|
+
return { source, hasJsx, runtimeHelpers: (hHelper + cssHelper) };
|
|
395
|
+
}
|
|
396
|
+
module.exports.transformJsx = transformJsx;
|