vaderjs 1.3.3-4944326ca411 → 1.3.3-7924566dd811
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/package.json +1 -1
- package/vader.js +29 -90
package/package.json
CHANGED
package/vader.js
CHANGED
|
@@ -22,16 +22,8 @@ let writer = async (file, data) => {
|
|
|
22
22
|
globalThis.isWriting = null
|
|
23
23
|
return { _written: true };
|
|
24
24
|
};
|
|
25
|
-
|
|
26
|
-
let
|
|
27
|
-
let bundleSize = 0;
|
|
28
|
-
let errorCodes = {
|
|
29
|
-
"SyntaxError: Unexpected token '<'": "You forgot to enclose tags in a fragment <></>",
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* define directories
|
|
33
|
-
*/
|
|
34
|
-
|
|
25
|
+
|
|
26
|
+
let bundleSize = 0;
|
|
35
27
|
|
|
36
28
|
if (!fs.existsSync(process.cwd() + '/dist')) {
|
|
37
29
|
fs.mkdirSync(process.cwd() + '/dist')
|
|
@@ -48,44 +40,13 @@ if (typeof process.env.isCloudflare !== "undefined" || !fs.existsSync(process.cw
|
|
|
48
40
|
|
|
49
41
|
|
|
50
42
|
function Compiler(func, file) {
|
|
51
|
-
let string = func;
|
|
52
|
-
// Remove block comments
|
|
53
|
-
|
|
43
|
+
let string = func;
|
|
54
44
|
let returns = []
|
|
55
45
|
let comments = string.match(/\{\s*\/\*.*\*\/\s*}/gs)?.map((comment) => comment.trim());
|
|
56
46
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
)
|
|
61
|
-
?.map((match) => match.trim());
|
|
62
|
-
|
|
63
|
-
let functionNames = [];
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
functions && functions.forEach((func) => {
|
|
67
|
-
if (
|
|
68
|
-
!func.match(
|
|
69
|
-
/(?:const|let)\s*([a-zA-Z0-9_-]+)\s*=\s*function\s*\(([^)]*)\)|function\s*([a-zA-Z0-9_-]+)\s*\(([^)]*)\)/gs
|
|
70
|
-
)
|
|
71
|
-
) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
let name = func.split(" ")[1].split("(")[0].trim();
|
|
76
|
-
|
|
77
|
-
let lines = string.match(/return\s*\<>.*\<\/>/gs);
|
|
78
|
-
|
|
79
|
-
if (lines) {
|
|
80
|
-
for (let i = 0; i < lines.length; i++) {
|
|
81
|
-
let line = lines[i];
|
|
82
|
-
|
|
83
|
-
if (!functionNames.includes(name)) {
|
|
84
|
-
functionNames.push(name);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
});
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
89
50
|
|
|
90
51
|
// get all Obj({}) and parse to JSON.stringify
|
|
91
52
|
|
|
@@ -189,27 +150,10 @@ function Compiler(func, file) {
|
|
|
189
150
|
if (attributeValue && attributeValue.includes("=>") || attributeValue && attributeValue.includes("function")
|
|
190
151
|
&& !spreadFunctions.includes(attributeValue)
|
|
191
152
|
) {
|
|
192
|
-
|
|
193
|
-
// ref with no numbers
|
|
153
|
+
|
|
194
154
|
let ref = Math.random().toString(36).substring(2).split('').filter((e) => !Number(e)).join('')
|
|
195
155
|
let old = `${attributeName}${attributeValue}`
|
|
196
|
-
|
|
197
|
-
string.split("\n").forEach((line) => {
|
|
198
|
-
if (line.includes(name) && line.includes("function")) {
|
|
199
|
-
line = line.trim();
|
|
200
|
-
line = line.replace(/\s+/g, " ");
|
|
201
|
-
|
|
202
|
-
let ps = line.split("(").slice(1).join("(").split(")")[0].trim();
|
|
203
|
-
|
|
204
|
-
// remove comments
|
|
205
|
-
ps = ps.match(/\/\*.*\*\//gs)
|
|
206
|
-
? ps.replace(ps.match(/\/\*.*\*\//gs)[0], "")
|
|
207
|
-
: ps;
|
|
208
|
-
functionparams.push({ ref: ref, name: name, params: ps });
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
});
|
|
156
|
+
|
|
213
157
|
let elementMatch = string.match(/<([a-zA-Z0-9_-]+)([^>]*)>/gs);
|
|
214
158
|
let isJSXComponent = false;
|
|
215
159
|
elementMatch.forEach((element) => {
|
|
@@ -263,7 +207,7 @@ function Compiler(func, file) {
|
|
|
263
207
|
newvalue = newvalue.replace(/}\s*$/, '');
|
|
264
208
|
|
|
265
209
|
|
|
266
|
-
|
|
210
|
+
|
|
267
211
|
|
|
268
212
|
newvalue = newvalue.replaceAll(',,', ',')
|
|
269
213
|
let paramnames = params ? params.split(',').map((e) => e.trim()) : null
|
|
@@ -314,8 +258,7 @@ function Compiler(func, file) {
|
|
|
314
258
|
let returns = code.match(/return\s*\<>.*\<\/>|return\s*\(.*\)/gs);
|
|
315
259
|
|
|
316
260
|
return returns || [];
|
|
317
|
-
}
|
|
318
|
-
// throw error if return is not wrapped in <></> or
|
|
261
|
+
}
|
|
319
262
|
if (string.match(/return\s*\<>|return\s*\(.*\)/gs) && !string.match(/return\s*\<>.*\<\/>|return\s*\(.*\)/gs)
|
|
320
263
|
|| string.match(/return\s*\<[a-zA-Z0-9_-]+.*>/gs)
|
|
321
264
|
) {
|
|
@@ -348,8 +291,7 @@ function Compiler(func, file) {
|
|
|
348
291
|
}
|
|
349
292
|
let usesBraces = returnStatement.match(/return\s*\(/gs) ? true : false;
|
|
350
293
|
|
|
351
|
-
|
|
352
|
-
// Remove trailing ']' or trailing )
|
|
294
|
+
|
|
353
295
|
contents = contents.trim().replace(/\]$/, "")
|
|
354
296
|
contents = contents.replace(/\)$/, "");
|
|
355
297
|
usesBraces ? !contents.includes('<>') ? contents = `<>${contents}</>` : null : null
|
|
@@ -433,9 +375,7 @@ function Compiler(func, file) {
|
|
|
433
375
|
valuestate = valuestate.match(regex) ? valuestate.match(regex)[0].split("useState(")[1].split(")")[0].trim() : valuestate
|
|
434
376
|
|
|
435
377
|
|
|
436
|
-
let newState = `${varType} [${key}, ${setKey}] = this.useState('${key}', ${valuestate}
|
|
437
|
-
|
|
438
|
-
`;
|
|
378
|
+
let newState = `${varType} [${key}, ${setKey}] = this.useState('${key}', ${valuestate}`;
|
|
439
379
|
string = string.replace(line, newState);
|
|
440
380
|
break;
|
|
441
381
|
case line.includes("useRef") && !line.includes("import"):
|
|
@@ -496,9 +436,7 @@ function Compiler(func, file) {
|
|
|
496
436
|
let myChildrens = [];
|
|
497
437
|
|
|
498
438
|
let name = component.split("<")[1].split(">")[0].split(" ")[0].replace("/", "");
|
|
499
|
-
let componentAttributes = component.split("<")[1].split(">")[0].split(" ").join(" ").replace(name, "").trim();
|
|
500
|
-
// some components will have props that have html inside of them we need to only get the props ex: <Header title={<h1>hello</h1>}></Header> -> title={<h1>hello</h1>} // also spread props ex: <Header {...props}></Header> -> {...props} or {...props, title: 'hello'} or {...props, color:{color: 'red'}}
|
|
501
|
-
// grab ...( spread props )
|
|
439
|
+
let componentAttributes = component.split("<")[1].split(">")[0].split(" ").join(" ").replace(name, "").trim();
|
|
502
440
|
const dynamicAttributesRegex = /(\w+)(?:="([^"]*)")?(?:='([^']*)')?(?:=\{([^}]*)\})?(?:=\{(.*?)\})?(?:={([^}]*)})?(?:{([^}]*)})?|(?:{(?:[^{}]+|\{(?:[^{}]+|\{[^}]*\})*\})*\})|(\.{3}\{(?:[^{}]+|\{(?:[^{}]+|\{[^}]*\})*\})*\})|\$=\{(?:[^{}]+|\{(?:[^{}]+|\{[^}]*\})*\})*\}/gs;
|
|
503
441
|
|
|
504
442
|
|
|
@@ -517,8 +455,7 @@ function Compiler(func, file) {
|
|
|
517
455
|
for (let prop of props) {
|
|
518
456
|
|
|
519
457
|
if (prop === componentName) {
|
|
520
|
-
|
|
521
|
-
// If the component is encountered, start collecting props
|
|
458
|
+
|
|
522
459
|
isWithinComponent = true;
|
|
523
460
|
filteredProps.push(prop);
|
|
524
461
|
} else if (isWithinComponent && prop.includes('=')) {
|
|
@@ -535,8 +472,7 @@ function Compiler(func, file) {
|
|
|
535
472
|
$_ternaryprops.push(prop)
|
|
536
473
|
|
|
537
474
|
}
|
|
538
|
-
else if (prop.includes('${')) {
|
|
539
|
-
// if it has an object inside of it then we should just do soemting:object else we should do something: `${object}`
|
|
475
|
+
else if (prop.includes('${')) {
|
|
540
476
|
|
|
541
477
|
prop = prop.replace('="', ':').replace('}"', '}')
|
|
542
478
|
if (prop.includes('${')) {
|
|
@@ -618,6 +554,7 @@ function Compiler(func, file) {
|
|
|
618
554
|
}
|
|
619
555
|
|
|
620
556
|
myChildrens.push(child.children);
|
|
557
|
+
childs = childs.filter((e) => e.parent !== name);
|
|
621
558
|
}
|
|
622
559
|
});
|
|
623
560
|
|
|
@@ -680,6 +617,7 @@ function Compiler(func, file) {
|
|
|
680
617
|
let text = fs.readFileSync(file, "utf8");
|
|
681
618
|
if (!file.endsWith('.js') && file.endsWith('.jsx')) {
|
|
682
619
|
text = Compiler(text, file);
|
|
620
|
+
|
|
683
621
|
}
|
|
684
622
|
let dest = file.split('node_modules')[1]
|
|
685
623
|
dest = dest.split(baseFolder)[1]
|
|
@@ -897,14 +835,7 @@ async function Build() {
|
|
|
897
835
|
return text;
|
|
898
836
|
};
|
|
899
837
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
// Process files in the 'pages' directory
|
|
906
|
-
let appjs = '';
|
|
907
|
-
let hasWritten = []
|
|
838
|
+
|
|
908
839
|
function ssg(routes = []) {
|
|
909
840
|
globalThis.isBuilding = true
|
|
910
841
|
console.log(`Generating html files for ${routes.length} routes`)
|
|
@@ -1060,21 +991,30 @@ async function Build() {
|
|
|
1060
991
|
headless: "new", args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
1061
992
|
warning: false,
|
|
1062
993
|
})
|
|
1063
|
-
|
|
994
|
+
|
|
1064
995
|
const browserPID = browser.process().pid
|
|
1065
996
|
try {
|
|
1066
997
|
|
|
1067
998
|
route.url = route.url.replaceAll(/\/:[a-zA-Z0-9_-]+/gs, '')
|
|
1068
999
|
let page = await browser.newPage();
|
|
1069
1000
|
await page.goto(`http://localhost:${port}/`, { waitUntil: 'networkidle2' });
|
|
1001
|
+
await page.on('console', msg => console.log('PAGE LOG:', msg.text()));
|
|
1002
|
+
await page.on('error', err => console.log('PAGE LOG:', err));
|
|
1003
|
+
await page.on('pageerror', err => console.log('PAGE LOG:', err));
|
|
1004
|
+
await page.evaluate(() => {
|
|
1005
|
+
window.onerror = function (msg, url, lineNo, columnNo, error) {
|
|
1006
|
+
console.log(msg, url, lineNo, columnNo, error)
|
|
1007
|
+
}
|
|
1008
|
+
})
|
|
1070
1009
|
await page.waitForSelector('#root', { timeout: 10000 })
|
|
1071
1010
|
await page.evaluate(() => {
|
|
1072
1011
|
document.getElementById('meta').remove()
|
|
1073
1012
|
document.querySelector('#isServer').innerHTML = 'window.isServer = false'
|
|
1074
1013
|
if (document.head.getAttribute('prerender') === 'false') {
|
|
1075
1014
|
document.querySelector('#root').innerHTML = ''
|
|
1015
|
+
console.log(`Disabled prerendering for ${window.location.pathname}`)
|
|
1076
1016
|
}
|
|
1077
|
-
})
|
|
1017
|
+
})
|
|
1078
1018
|
const html = await page.content();
|
|
1079
1019
|
|
|
1080
1020
|
await page.close();
|
|
@@ -1137,7 +1077,6 @@ async function Build() {
|
|
|
1137
1077
|
data = Compiler(data, origin);
|
|
1138
1078
|
|
|
1139
1079
|
|
|
1140
|
-
|
|
1141
1080
|
await writer(process.cwd() + "/dist/" + fileName.replace('.jsx', '.js'), data).then(async () => {
|
|
1142
1081
|
|
|
1143
1082
|
|