lilact 0.21.0 → 0.22.0
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/README.md +17 -4
- package/dist/lilact.development.js +486 -39
- package/dist/lilact.development.js.map +4 -4
- package/dist/lilact.development.min.js +33 -23
- package/dist/lilact.development.min.js.map +4 -4
- package/dist/lilact.production.min.js +32 -22
- package/docs/assets/highlight.css +20 -20
- package/docs/classes/accessories.ErrorBoundary.html +8 -8
- package/docs/classes/accessories.Suspense.html +7 -7
- package/docs/classes/components.Component.html +11 -11
- package/docs/classes/components.HTMLComponent.html +12 -12
- package/docs/classes/components.RootComponent.html +12 -12
- package/docs/functions/accessories.DragHandle.html +2 -2
- package/docs/functions/accessories.Spinner.html +2 -2
- package/docs/functions/components.createComponent.html +1 -1
- package/docs/functions/components.createPortal.html +1 -1
- package/docs/functions/components.createRoot.html +1 -1
- package/docs/functions/components.memo.html +1 -1
- package/docs/functions/components.render.html +1 -1
- package/docs/functions/redux.Provider.html +2 -2
- package/docs/functions/redux.connect.html +2 -2
- package/docs/functions/router.HashRouter.html +2 -2
- package/docs/functions/router.Link.html +2 -2
- package/docs/functions/router.NavLink.html +2 -2
- package/docs/functions/router.Routes.html +2 -2
- package/docs/functions/run.lazy.html +9 -3
- package/docs/functions/run.require.html +4 -4
- package/docs/functions/run.run.html +1 -1
- package/docs/functions/run.runScripts.html +1 -1
- package/docs/functions/timers.animationFramePromise.html +1 -1
- package/docs/functions/timers.clearInterval.html +1 -1
- package/docs/functions/timers.clearTimeout.html +1 -1
- package/docs/functions/timers.grabTimers.html +1 -1
- package/docs/functions/timers.pauseTimers.html +1 -1
- package/docs/functions/timers.releaseTimers.html +1 -1
- package/docs/functions/timers.resetTimers.html +1 -1
- package/docs/functions/timers.resumeTimers.html +1 -1
- package/docs/functions/timers.setInterval.html +1 -1
- package/docs/functions/timers.setTimeout.html +1 -1
- package/docs/functions/timers.timeoutPromise.html +3 -145
- package/docs/functions/transition.CSSTransition.html +4 -4
- package/docs/functions/transition.SwitchTransition.html +2 -2
- package/docs/functions/transition.Transition.html +3 -3
- package/docs/index.html +17 -10
- package/docs/static/demos/actionstate.jsx +2 -2
- package/docs/static/demos/capture.jsx +2 -2
- package/docs/static/demos/context.jsx +3 -3
- package/docs/static/demos/css-transition.jsx +3 -3
- package/docs/static/demos/error-boundary.jsx +2 -2
- package/docs/static/demos/error-callback.jsx +1 -1
- package/docs/static/demos/error-component-stack.jsx +2 -2
- package/docs/static/demos/error-init.jsx +1 -1
- package/docs/static/demos/error-parser.jsx +1 -1
- package/docs/static/demos/form-elements.jsx +1 -1
- package/docs/static/demos/forwardref.jsx +2 -2
- package/docs/static/demos/lazy.jsx +3 -3
- package/docs/static/demos/legacy-context.jsx +2 -2
- package/docs/static/demos/memo.jsx +2 -2
- package/docs/static/demos/modal.jsx +2 -2
- package/docs/static/demos/pane.jsx +2 -2
- package/docs/static/demos/portal.jsx +4 -2
- package/docs/static/demos/priorities.jsx +2 -2
- package/docs/static/demos/proptypes.jsx +2 -2
- package/docs/static/demos/reducer.jsx +2 -2
- package/docs/static/demos/redux.jsx +3 -3
- package/docs/static/demos/router.jsx +2 -2
- package/docs/static/demos/stopwatch.jsx +2 -2
- package/docs/static/demos/suspense.jsx +2 -2
- package/docs/static/demos/switch-transition.jsx +2 -2
- package/docs/static/demos/transition.jsx +2 -2
- package/docs/static/demos/usedefered.jsx +2 -2
- package/docs/static/demos/usetransition.jsx +3 -3
- package/docs/static/index.html +3 -3
- package/docs/static/lilact.development.js +486 -39
- package/docs/static/lilact.development.js.map +4 -4
- package/docs/static/lilact.development.min.js +33 -23
- package/docs/static/lilact.development.min.js.map +4 -4
- package/docs/static/lilact.production.min.js +32 -22
- package/docs/variables/accessories.SplitPane.html +1 -1
- package/examples/demos/actionstate.jsx +2 -2
- package/examples/demos/capture.jsx +2 -2
- package/examples/demos/context.jsx +3 -3
- package/examples/demos/css-transition.jsx +3 -3
- package/examples/demos/error-boundary.jsx +2 -2
- package/examples/demos/error-callback.jsx +1 -1
- package/examples/demos/error-component-stack.jsx +2 -2
- package/examples/demos/error-init.jsx +1 -1
- package/examples/demos/error-parser.jsx +1 -1
- package/examples/demos/form-elements.jsx +1 -1
- package/examples/demos/forwardref.jsx +2 -2
- package/examples/demos/lazy.jsx +3 -3
- package/examples/demos/legacy-context.jsx +2 -2
- package/examples/demos/memo.jsx +2 -2
- package/examples/demos/modal.jsx +2 -2
- package/examples/demos/pane.jsx +2 -2
- package/examples/demos/portal.jsx +4 -2
- package/examples/demos/priorities.jsx +2 -2
- package/examples/demos/proptypes.jsx +2 -2
- package/examples/demos/reducer.jsx +2 -2
- package/examples/demos/redux.jsx +3 -3
- package/examples/demos/router.jsx +2 -2
- package/examples/demos/stopwatch.jsx +2 -2
- package/examples/demos/suspense.jsx +2 -2
- package/examples/demos/switch-transition.jsx +2 -2
- package/examples/demos/transition.jsx +2 -2
- package/examples/demos/usedefered.jsx +2 -2
- package/examples/demos/usetransition.jsx +3 -3
- package/examples/index.html +3 -3
- package/examples/lilact.development.js +486 -39
- package/examples/lilact.development.js.map +4 -4
- package/examples/lilact.development.min.js +33 -23
- package/examples/lilact.development.min.js.map +4 -4
- package/examples/lilact.production.min.js +32 -22
- package/impexptest.js +51 -0
- package/package.json +4 -4
- package/src/components.jsx +1 -6
- package/src/expscan.js +404 -0
- package/src/jsx.js +26 -28
- package/src/lilact.jsx +10 -1
- package/src/run.jsx +86 -37
- package/src/timers.jsx +0 -5
- package/src/jsx.addons.js +0 -70
package/impexptest.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Imports
|
|
2
|
+
import foo from "foo";
|
|
3
|
+
import { a, b } from "foo";
|
|
4
|
+
import {a as alpha, b as beta} from "foo";
|
|
5
|
+
import * as utils from "foo";
|
|
6
|
+
import foo, { a, b as c, d } from "foo";
|
|
7
|
+
import "foo";
|
|
8
|
+
|
|
9
|
+
// Re-exports from other modules
|
|
10
|
+
export * from "foo";
|
|
11
|
+
export { a, b } from "foo";
|
|
12
|
+
export { default as Foo } from "foo";
|
|
13
|
+
|
|
14
|
+
export * from "./some-module.js";
|
|
15
|
+
export { exportedThing } from "./another-module.js";
|
|
16
|
+
export { default as depDefault } from "./yet-another-module.js";
|
|
17
|
+
export { default as depDefault, a, b, c as depC } from "./...";
|
|
18
|
+
|
|
19
|
+
// Default export forms
|
|
20
|
+
const defaultValue = { ok: true };
|
|
21
|
+
export default defaultValue;
|
|
22
|
+
|
|
23
|
+
export default function defaultFn() {
|
|
24
|
+
return "defaultFn";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default class DefaultClass {
|
|
28
|
+
constructor() {}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export {localA as a, localB as b, localC as c};
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
export { localFn as renamedFn };
|
|
36
|
+
|
|
37
|
+
// Additional named exports (declared bindings)
|
|
38
|
+
export const namedConst = 1;
|
|
39
|
+
export let namedLet = 2;
|
|
40
|
+
export var namedVar = 3;
|
|
41
|
+
|
|
42
|
+
export function namedFn() {
|
|
43
|
+
return "namedFn";
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
export class NamedClass {}
|
|
48
|
+
|
|
49
|
+
// Re-exporting local bindings is OK (examples)
|
|
50
|
+
export defaultValue;
|
|
51
|
+
export { defaultValue };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lilact",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "A Little React/JSX Runtime Implementation for Browser",
|
|
5
5
|
"repository": "github:arashkazemi/lilact",
|
|
6
6
|
"homepage": "https://arashkazemi.github.io/lilact/",
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"typedoc": "^0.28.19"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@emotion/css": "
|
|
45
|
-
"esbuild": "
|
|
46
|
-
"redux": "
|
|
44
|
+
"@emotion/css": ">=11.13.0",
|
|
45
|
+
"esbuild": ">=0.28.1",
|
|
46
|
+
"redux": ">=5.0.1"
|
|
47
47
|
},
|
|
48
48
|
"exports": {
|
|
49
49
|
".": "./dist/lilact.development.js",
|
package/src/components.jsx
CHANGED
|
@@ -198,7 +198,7 @@ if(DEBUG) {
|
|
|
198
198
|
if(this?.parent?.component?.context || this?.parent?.component?.getChildContext ) {
|
|
199
199
|
this.context = { ...this.parent.component.context, ...this.parent.component.getChildContext?.() };
|
|
200
200
|
|
|
201
|
-
if(this.component.constructor.contextTypes) {
|
|
201
|
+
if(DEBUG && this.component.constructor.contextTypes) {
|
|
202
202
|
PropTypes.checkPropTypes(this.component.constructor.contextTypes, this.context, 'context', this.entity.name);
|
|
203
203
|
}
|
|
204
204
|
}
|
|
@@ -384,11 +384,6 @@ if(DEBUG) {
|
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
catch(e) {
|
|
387
|
-
// todo: should did catch be called? and state be modified?
|
|
388
|
-
/*if(this.component.componentDidCatch) {
|
|
389
|
-
this.component.componentDidCatch(e);
|
|
390
|
-
}
|
|
391
|
-
else */
|
|
392
387
|
throw(e);
|
|
393
388
|
}
|
|
394
389
|
}
|
package/src/expscan.js
ADDED
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
/*
|
|
2
|
+
|
|
3
|
+
Lilact
|
|
4
|
+
Copyright (C) 2024-2026 Arash Kazemi <contact.arash.kazemi@gmail.com>
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
BSD-2-Clause
|
|
8
|
+
|
|
9
|
+
Redistribution and use in source and binary forms, with or without
|
|
10
|
+
modification, are permitted provided that the following conditions are met:
|
|
11
|
+
|
|
12
|
+
* Redistributions of source code must retain the above copyright
|
|
13
|
+
notice, this list of conditions and the following disclaimer.
|
|
14
|
+
* Redistributions in binary form must reproduce the above copyright
|
|
15
|
+
notice, this list of conditions and the following disclaimer in the
|
|
16
|
+
documentation and/or other materials provided with the distribution.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
21
|
+
ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
|
22
|
+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
23
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
24
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
25
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
26
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
27
|
+
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28
|
+
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const keywords = new Set([
|
|
32
|
+
"break","case","catch","class","const","continue","debugger","default",
|
|
33
|
+
"do","else","export","extends","finally","for","function","if","import","in",
|
|
34
|
+
"instanceof","super","switch","this","throw","try",
|
|
35
|
+
"var","while","with","yield", "return",
|
|
36
|
+
"true","false","null","undefined",
|
|
37
|
+
"enum","implements","interface","let","package","private","protected",
|
|
38
|
+
"public","static","yield",
|
|
39
|
+
"as","from","of","async","get","set","static","super",
|
|
40
|
+
"delete", "void", "typeof", "new", "await",
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
const operators = new Set([
|
|
44
|
+
"(", ")", "{", "}", "[", "]", "...", ".",
|
|
45
|
+
"=>", ",", ";", ":" , "?",
|
|
46
|
+
"++", "--",
|
|
47
|
+
"+", "-", "*", "/", "%", "**",
|
|
48
|
+
">>", "<<", ">>>", "<<<",
|
|
49
|
+
"&", "|", "^", "~",
|
|
50
|
+
"==", "!=", "===", "!==",
|
|
51
|
+
">", "<", ">=", "<=",
|
|
52
|
+
"&&", "||", "??", "?.", "=",
|
|
53
|
+
"+=", "-=", "*=", "/=", "%=",
|
|
54
|
+
"**=", "<<=", ">>=", ">>>=",
|
|
55
|
+
"&=", "|=", "^=",
|
|
56
|
+
"??=", "&&=", "||=",
|
|
57
|
+
"!",
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
function isNumber(s) {
|
|
61
|
+
if (!/^(?:[+-]?(?:(?:\d(?:\d|_)*)(?:\.(?:\d(?:\d|_)*))?|\.(?:\d(?:\d|_)*))(?:[eE][+-]?(?:\d(?:\d|_)*))?|[+-]?Infinity|[+-]?NaN|[+-]?(?:(?:0[xX](?:[0-9a-fA-F](?:[0-9a-fA-F]|_)*))|(?:0[oO](?:[0-7](?:[0-7]|_)*))|(?:0[bB](?:[01](?:[01]|_)*))|(?:\d(?:\d|_)*))n)$/u.test(s)) return false;
|
|
62
|
+
return !keywords.has(s);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function isUnicodeEscapeSequence(s) {
|
|
66
|
+
if (!/(?:\\u\{[0-9a-fA-F]+\}|\\u[0-9a-fA-F]{4})/g.test(s)) return false;
|
|
67
|
+
return !keywords.has(s);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function isValidIdentifierName(s) {
|
|
71
|
+
if (!/^(?:[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}]*)$/u.test(s)) return false;
|
|
72
|
+
return !keywords.has(s);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function labeler(custom_words, x) {
|
|
76
|
+
if( typeof(x)==='string' ) {
|
|
77
|
+
if(custom_words && custom_words.hasOwnProperty(x)) return custom_words[x];
|
|
78
|
+
|
|
79
|
+
if(x.trim()==='') {
|
|
80
|
+
if(x.indexOf('\n')!==-1) return '\n';
|
|
81
|
+
return ' ';
|
|
82
|
+
}
|
|
83
|
+
if(keywords.has(x)) return 'K';
|
|
84
|
+
if(operators.has(x)) return 'O';
|
|
85
|
+
if(isValidIdentifierName(x)) return 'I';
|
|
86
|
+
if(isUnicodeEscapeSequence(x)) return 'U';
|
|
87
|
+
if(isNumber(x)) return 'N';
|
|
88
|
+
}
|
|
89
|
+
else if(typeof(x)==='object') {
|
|
90
|
+
if(x.type==='comment') return 'C';
|
|
91
|
+
if(x.type==='regexp') return 'R';
|
|
92
|
+
if(x.type==='js') return 'J';
|
|
93
|
+
if(x.type==='paranthesis') return 'P';
|
|
94
|
+
if(x.type==='string') return 'S';
|
|
95
|
+
if(x.type==='xml') return 'X';
|
|
96
|
+
}
|
|
97
|
+
return "?"
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function generateSequence(arr, labeler = labeler.bind(null, null))
|
|
101
|
+
{
|
|
102
|
+
return arr.map(labeler).join('');
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const import_export_regexp = /(?:i[C \n]*(?:(?:I|J|(?:\*[C \n]*a[C \n]*I))[C \n]*,[C \n]*)*(?:(?:(?:I(?:[C \n]*a[C \n]*I)?)|J|(?:\*[C \n]*a[C \n]*I))[C \n]*f[C \n]*)?S)|(?:e[C \n]*(?:(?:[*J][C \n]*f[C \n]*S)|(?:d[C \n]*[IFJ])|J|(?:[VF][c \n]*I)|I))|(?:r[c \n]*P)/mg;
|
|
106
|
+
const props_regexp = /O[C \n]*(?:[Id](?:[C \n]*a[C \n]*I)?[C \n]*,[C \n]*)*(?:I(?:[C \n]*a[C \n]*I)?)[C \n]*O/mg;
|
|
107
|
+
|
|
108
|
+
export function processImportExports(node, jsx)
|
|
109
|
+
{
|
|
110
|
+
const s = generateSequence(node.out,
|
|
111
|
+
labeler.bind(null,
|
|
112
|
+
{'import': 'i', 'export': 'e', 'as': 'a', 'from': 'f',
|
|
113
|
+
',': ',', '.': '.', '*': '*', ';': ';',
|
|
114
|
+
'var': 'V', 'let': 'V', 'const': 'V',
|
|
115
|
+
'function': 'F', 'class': 'F', '=':'=', 'default': 'd',
|
|
116
|
+
'require': 'r'
|
|
117
|
+
})
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
// todo: should detect illegal imports too: "i"s that are not matched.
|
|
121
|
+
// but it may cause problems. x.import = ... is correct, but it will raise error this way.
|
|
122
|
+
|
|
123
|
+
let i;
|
|
124
|
+
const skip_spaces = (dir=1) => {
|
|
125
|
+
while(s[i]===' ' || s[i]==='\n' || s[i]==='C') {
|
|
126
|
+
if(dir===1) node.out[i]=null;
|
|
127
|
+
i+=dir
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
// Parse Imports
|
|
133
|
+
|
|
134
|
+
let begin = node.begin;
|
|
135
|
+
|
|
136
|
+
const begins = [];
|
|
137
|
+
|
|
138
|
+
for(i=0;i<node.out.length;i++) {
|
|
139
|
+
if(i==0) begins.push(node.begin);
|
|
140
|
+
else {
|
|
141
|
+
if( typeof(node.out[i-1]) === 'string' ) {
|
|
142
|
+
begins.push(begins[i-1]+node.out[i-1].length);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
begins.push(node.out[i-1].end);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
begins.push(node.end);
|
|
151
|
+
|
|
152
|
+
for (const m of s.matchAll(import_export_regexp)) {
|
|
153
|
+
|
|
154
|
+
// Require (to inject requirer argument)
|
|
155
|
+
// todo: should also check for . before require, but this is more complex than import
|
|
156
|
+
// and export, and also much less likely to collide with user space.
|
|
157
|
+
if(m[0].startsWith('r')) {
|
|
158
|
+
const req = m[0];
|
|
159
|
+
const args = node.out[m.index+req.length-1].out;
|
|
160
|
+
if(args.length===1) {
|
|
161
|
+
args.push(', {requirer:module}');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Import
|
|
165
|
+
else if(m[0].startsWith('i')) {
|
|
166
|
+
|
|
167
|
+
const imp = m[0];
|
|
168
|
+
|
|
169
|
+
i = m.index-1;
|
|
170
|
+
|
|
171
|
+
skip_spaces(-1); // check if this is a member (x.import)
|
|
172
|
+
if(s[i]==='.') continue;
|
|
173
|
+
|
|
174
|
+
const src = jsx.substring(node.out[m.index+imp.length-1].begin, node.out[m.index+imp.length-1].end);
|
|
175
|
+
const imports = {};
|
|
176
|
+
let star_imports = [];
|
|
177
|
+
|
|
178
|
+
for(i = m.index+1;i<m.index+imp.length-1;i++) {
|
|
179
|
+
|
|
180
|
+
node.out.splice(m.index, 1, {
|
|
181
|
+
type: "import",
|
|
182
|
+
begin: begins[m.index],
|
|
183
|
+
end: begins[m.index+imp.length],
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
skip_spaces();
|
|
187
|
+
|
|
188
|
+
switch(s[i]) {
|
|
189
|
+
case ',':
|
|
190
|
+
break;
|
|
191
|
+
case 'I': {
|
|
192
|
+
const prop = node.out[i];
|
|
193
|
+
imports[prop] = 'default';
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
case 'J': {
|
|
197
|
+
let sj = generateSequence(node.out[i].out,
|
|
198
|
+
labeler.bind(null,
|
|
199
|
+
{'as': 'a', ',': ','})
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
props_regexp.lastIndex=-1;
|
|
203
|
+
if(!props_regexp.test(sj)) throw "incorrect import properties definition."
|
|
204
|
+
|
|
205
|
+
const ps = node.out[i].out;
|
|
206
|
+
|
|
207
|
+
for(let j=1; j<sj.length-1; j++) {
|
|
208
|
+
while(sj[j]===' ' || sj[j]==='\n' || sj[j]==='C' || sj[j]===',') j++;
|
|
209
|
+
const prop = ps[j];
|
|
210
|
+
j++;
|
|
211
|
+
while(sj[j]===' ' || sj[j]==='\n' || sj[j]==='C') j++;
|
|
212
|
+
if(sj[j]==='a') {
|
|
213
|
+
j++;
|
|
214
|
+
while(sj[j]===' ' || sj[j]==='\n' || sj[j]==='C') j++;
|
|
215
|
+
imports[ps[j]] = prop;
|
|
216
|
+
j++;
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
imports[prop] = prop;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
continue;
|
|
223
|
+
|
|
224
|
+
}
|
|
225
|
+
case '*': {
|
|
226
|
+
i++;
|
|
227
|
+
skip_spaces();
|
|
228
|
+
i++;
|
|
229
|
+
skip_spaces();
|
|
230
|
+
|
|
231
|
+
star_imports.push(node.out[i]);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
case 'S':
|
|
235
|
+
// 1. mark unnecessary nodes to be removed
|
|
236
|
+
for(i = m.index+1;i<m.index+imp.length;i++) {
|
|
237
|
+
node.out[i]=null;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
let cjs = '';
|
|
241
|
+
for(const s of star_imports) {
|
|
242
|
+
cjs+=`const ${s} = require(${src},{requirer:module});\n`;
|
|
243
|
+
}
|
|
244
|
+
if(Object.keys(imports).length) {
|
|
245
|
+
let o = '{';
|
|
246
|
+
let ls = '[';
|
|
247
|
+
|
|
248
|
+
for(const p in imports) {
|
|
249
|
+
if(o.length>1) {
|
|
250
|
+
o+=',';
|
|
251
|
+
ls+=',';
|
|
252
|
+
}
|
|
253
|
+
if(p===imports[p]) {
|
|
254
|
+
o+=p;
|
|
255
|
+
ls+=`'${p}'`;
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
o+=p+":"+imports[p];
|
|
259
|
+
ls+=`'${imports[p]}'`;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
}
|
|
263
|
+
o+='}';
|
|
264
|
+
ls+=']';
|
|
265
|
+
|
|
266
|
+
cjs+=`const ${o} = require(${src}, {checkExport: ${ls},requirer:module})`;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
cjs+=`require(${src},{requirer:module})`;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// 2. add nodes
|
|
273
|
+
node.out[m.index].cjs = cjs;
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
// Export
|
|
279
|
+
else {
|
|
280
|
+
const exp = m[0];
|
|
281
|
+
|
|
282
|
+
node.out.splice(m.index, 1, {
|
|
283
|
+
type: "export",
|
|
284
|
+
begin: begins[m.index],
|
|
285
|
+
end: begins[m.index+1],
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
i = m.index-1;
|
|
289
|
+
|
|
290
|
+
skip_spaces(-1); // check if this is a member (x.export)
|
|
291
|
+
if(s[i]==='.') continue;
|
|
292
|
+
|
|
293
|
+
i = m.index+1;
|
|
294
|
+
skip_spaces();
|
|
295
|
+
|
|
296
|
+
switch(s[i]) {
|
|
297
|
+
case 'd':
|
|
298
|
+
node.out[i] = null;
|
|
299
|
+
node.out[m.index].cjs = 'module.exports.default =';
|
|
300
|
+
continue;
|
|
301
|
+
|
|
302
|
+
case 'V':
|
|
303
|
+
case 'F':
|
|
304
|
+
const j = i;
|
|
305
|
+
const type = s[i]==='F'?`= ${node.out[i]} `:'';
|
|
306
|
+
node.out[i] = null;
|
|
307
|
+
i++;
|
|
308
|
+
skip_spaces();
|
|
309
|
+
const name = node.out[i];
|
|
310
|
+
if(s[j]==='V') {
|
|
311
|
+
node.out[i] = null;
|
|
312
|
+
i++;
|
|
313
|
+
}
|
|
314
|
+
skip_spaces();
|
|
315
|
+
node.out[m.index].cjs = `module.exports.${name} ${type}`;
|
|
316
|
+
continue;
|
|
317
|
+
|
|
318
|
+
case '*':
|
|
319
|
+
node.out[i] = null;
|
|
320
|
+
i++;
|
|
321
|
+
skip_spaces();
|
|
322
|
+
node.out[i] = null;
|
|
323
|
+
i++;
|
|
324
|
+
skip_spaces();
|
|
325
|
+
const src = jsx.substring(node.out[i].begin, node.out[i].end);
|
|
326
|
+
node.out[i] = null;
|
|
327
|
+
node.out[m.index].cjs = `Object.assign(module.exports, require(${src},{requirer:module}))`;
|
|
328
|
+
continue;
|
|
329
|
+
|
|
330
|
+
case 'I':
|
|
331
|
+
node.out[m.index].cjs = `module.exports.${node.out[i]} = `;
|
|
332
|
+
continue;
|
|
333
|
+
|
|
334
|
+
case 'J': {
|
|
335
|
+
const exports = {};
|
|
336
|
+
let sj = generateSequence(node.out[i].out,
|
|
337
|
+
labeler.bind(null,
|
|
338
|
+
{'as': 'a', ',': ',', 'default': 'I'})
|
|
339
|
+
);
|
|
340
|
+
|
|
341
|
+
props_regexp.lastIndex=-1;
|
|
342
|
+
if(!props_regexp.test(sj)) throw "incorrect export properties definition."
|
|
343
|
+
|
|
344
|
+
const ps = node.out[i].out;
|
|
345
|
+
for(let j=1; j<sj.length-1; j++) {
|
|
346
|
+
while(sj[j]===' ' || sj[j]==='\n' || sj[j]==='C' || sj[j]===',') j++;
|
|
347
|
+
const prop = ps[j];
|
|
348
|
+
j++;
|
|
349
|
+
while(sj[j]===' ' || sj[j]==='\n' || sj[j]==='C') j++;
|
|
350
|
+
if(sj[j]==='a') {
|
|
351
|
+
j++;
|
|
352
|
+
while(sj[j]===' ' || sj[j]==='\n' || sj[j]==='C') j++;
|
|
353
|
+
exports[ps[j]] = prop;
|
|
354
|
+
j++;
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
exports[prop] = prop;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
let o = '{';
|
|
362
|
+
let ls = '{';
|
|
363
|
+
|
|
364
|
+
for(const p in exports) {
|
|
365
|
+
if(o.length>1) {
|
|
366
|
+
o+=',';
|
|
367
|
+
ls+=',';
|
|
368
|
+
}
|
|
369
|
+
if(p===exports[p]) {
|
|
370
|
+
o+=p;
|
|
371
|
+
ls+=p;
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
o+=p+":"+exports[p];
|
|
375
|
+
ls+=exports[p];
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
}
|
|
379
|
+
o+='}';
|
|
380
|
+
ls+='}';
|
|
381
|
+
|
|
382
|
+
node.out[i] = null;
|
|
383
|
+
i++;
|
|
384
|
+
skip_spaces();
|
|
385
|
+
|
|
386
|
+
if(node.out[i]==='from') {
|
|
387
|
+
node.out[i] = null;
|
|
388
|
+
i++;
|
|
389
|
+
skip_spaces();
|
|
390
|
+
|
|
391
|
+
const src = jsx.substring(node.out[i].begin, node.out[i].end);
|
|
392
|
+
node.out[i]=null;
|
|
393
|
+
|
|
394
|
+
node.out[m.index].cjs = `{ const ${o} = require(${src},{requirer:module}); Object.assign(module.exports, ${ls}); }`;
|
|
395
|
+
}
|
|
396
|
+
else {
|
|
397
|
+
node.out[m.index].cjs = `Object.assign(module.exports, ${o})`;
|
|
398
|
+
}
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
package/src/jsx.js
CHANGED
|
@@ -46,11 +46,8 @@
|
|
|
46
46
|
// note: JSX or preprocessors are not processed inside template strings
|
|
47
47
|
// todo: injected string try catchs should be generated by a function
|
|
48
48
|
|
|
49
|
-
//import * as jsxAddons from './jsx.addons.js';
|
|
50
|
-
|
|
51
49
|
/** @ignore */
|
|
52
50
|
export const transpilerConfig = {
|
|
53
|
-
//addons: jsxAddons, // addons are not used anymore
|
|
54
51
|
setBlockLabels: true,
|
|
55
52
|
enableLabelStack: false,
|
|
56
53
|
injectLabels: true,
|
|
@@ -59,14 +56,17 @@ export const transpilerConfig = {
|
|
|
59
56
|
preprocessorDelimiter: 'ʔ', // alt+shift+. on apple abc extended layout
|
|
60
57
|
}
|
|
61
58
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
import * as vlq from './vlq.js';
|
|
59
|
+
import * as vlq from './vlq.js'
|
|
60
|
+
import {processImportExports} from './expscan.js'
|
|
66
61
|
|
|
67
62
|
let raiseError;
|
|
68
63
|
let tab=0;
|
|
69
64
|
|
|
65
|
+
|
|
66
|
+
const TOKENIZE_RE =
|
|
67
|
+
/(\{|\}|\[|\]|\(|\)|\.\.\.|=>|\?\?=|\?\?|\?\.|===|!==|>>>|<<=|>>=|>>>=|\*\*=|\*\*|&&=|\|\|=|<=|>=|==|!=|<<|>>|\+\+|--|\+=|-=|\*=|\/=|%=|&=|\^=|\|=|=|\+|-|\*|\/|%|&|\^|\||!|~|\?|:|<|>|=|\.|,|;|\n+|[\s^\n]+)/gm;
|
|
68
|
+
|
|
69
|
+
|
|
70
70
|
function lookAhead(f, code, index, ...args)
|
|
71
71
|
{
|
|
72
72
|
const b = f(code, index, ...args);
|
|
@@ -347,7 +347,7 @@ function parseString(code, index, q, container)
|
|
|
347
347
|
case '$':
|
|
348
348
|
if(q==='`') {
|
|
349
349
|
if(code[index+1]==='{') {
|
|
350
|
-
[index] = lookAhead( parseJS, code, index+1, true
|
|
350
|
+
[index] = lookAhead( parseJS, code, index+1, true );
|
|
351
351
|
index--;
|
|
352
352
|
}
|
|
353
353
|
}
|
|
@@ -639,7 +639,7 @@ function parseParanthesis(code, index, container)
|
|
|
639
639
|
case '\"':
|
|
640
640
|
case '\'':
|
|
641
641
|
case '\`':
|
|
642
|
-
[index] = lookAhead( parseString, code, index, ch );
|
|
642
|
+
[index] = lookAhead( parseString, code, index, ch, b );
|
|
643
643
|
break;
|
|
644
644
|
|
|
645
645
|
case '{':
|
|
@@ -703,7 +703,7 @@ function parseJS(code, index=0, is_block=false, container)
|
|
|
703
703
|
case '\"':
|
|
704
704
|
case '\'':
|
|
705
705
|
case '\`':
|
|
706
|
-
[index] = lookAhead( parseString, code, index, ch );
|
|
706
|
+
[index] = lookAhead( parseString, code, index, ch, b );
|
|
707
707
|
break;
|
|
708
708
|
|
|
709
709
|
case '{': {
|
|
@@ -855,6 +855,7 @@ function labelFunctions(node, eols, blocks_info)
|
|
|
855
855
|
|
|
856
856
|
}
|
|
857
857
|
|
|
858
|
+
|
|
858
859
|
function scanEOLs(code)
|
|
859
860
|
{
|
|
860
861
|
const endlines = [0];
|
|
@@ -903,14 +904,13 @@ function generateSourceMap(json, path, jsx_eols, out_eols, mappings=[])
|
|
|
903
904
|
|
|
904
905
|
|
|
905
906
|
const scan_leaves = (node)=>{
|
|
906
|
-
|
|
907
|
-
if(node.out?.length>0) {
|
|
907
|
+
if(node?.out?.length>0) {
|
|
908
908
|
|
|
909
909
|
for(const ch of node.out) {
|
|
910
910
|
scan_leaves(ch);
|
|
911
911
|
}
|
|
912
912
|
}
|
|
913
|
-
if(node
|
|
913
|
+
if(node?.begin!==undefined && node?.out_index!==undefined) {
|
|
914
914
|
mpps.push( [ ...getRowCol(out_eols,node.out_index), ...getRowCol(jsx_eols,node.begin), node ] );
|
|
915
915
|
}
|
|
916
916
|
}
|
|
@@ -975,6 +975,8 @@ export function transpileJSX( jsx, {
|
|
|
975
975
|
injectTraceLabels = false,
|
|
976
976
|
discardComments = false,
|
|
977
977
|
|
|
978
|
+
produceCJS = false,
|
|
979
|
+
|
|
978
980
|
// lilact internal
|
|
979
981
|
blocks_info = {
|
|
980
982
|
labels: {},
|
|
@@ -998,8 +1000,6 @@ export function transpileJSX( jsx, {
|
|
|
998
1000
|
throw er;
|
|
999
1001
|
}).bind(null, eols);
|
|
1000
1002
|
|
|
1001
|
-
const tokenize_re = /([\{\}\(\),;\[\]\n]|[\s^\n]+)/g;
|
|
1002
|
-
|
|
1003
1003
|
const json = parseJS(jsx);
|
|
1004
1004
|
json.data = jsx;
|
|
1005
1005
|
|
|
@@ -1028,7 +1028,7 @@ export function transpileJSX( jsx, {
|
|
|
1028
1028
|
node.children.splice(chi, 0, '"'+s.replaceAll("\n", "\\\n").replaceAll("\"", "\\\"")+'"');
|
|
1029
1029
|
}
|
|
1030
1030
|
else {
|
|
1031
|
-
node.children.splice(chi, 0, ...s.split(
|
|
1031
|
+
node.children.splice(chi, 0, ...s.split(TOKENIZE_RE));
|
|
1032
1032
|
}
|
|
1033
1033
|
chi++;
|
|
1034
1034
|
}
|
|
@@ -1052,7 +1052,7 @@ export function transpileJSX( jsx, {
|
|
|
1052
1052
|
}[m]))+'"' );
|
|
1053
1053
|
}
|
|
1054
1054
|
else {
|
|
1055
|
-
node.children.push( ...s.split(
|
|
1055
|
+
node.children.push( ...s.split(TOKENIZE_RE) );
|
|
1056
1056
|
}
|
|
1057
1057
|
}
|
|
1058
1058
|
}
|
|
@@ -1060,7 +1060,7 @@ export function transpileJSX( jsx, {
|
|
|
1060
1060
|
node.children = node.children.filter( (x)=>x!=="" );
|
|
1061
1061
|
|
|
1062
1062
|
if(transpilerConfig.setBlockLabels && !node.already_labeled) {
|
|
1063
|
-
labelFunctions(node,eols, blocks_info);
|
|
1063
|
+
labelFunctions(node, eols, blocks_info);
|
|
1064
1064
|
}
|
|
1065
1065
|
}
|
|
1066
1066
|
}
|
|
@@ -1072,11 +1072,15 @@ export function transpileJSX( jsx, {
|
|
|
1072
1072
|
const codify = (outlen, node, is_attr=false, is_xml=false)=> {
|
|
1073
1073
|
|
|
1074
1074
|
if(typeof(node)!=='object') return node;
|
|
1075
|
+
if(node===null) return '';
|
|
1075
1076
|
|
|
1076
1077
|
node.out_index = outlen;
|
|
1078
|
+
|
|
1077
1079
|
//console.log("CODIFY", node, node.out_index);
|
|
1078
1080
|
|
|
1079
1081
|
if(node.type==='string') return jsx.substring(node.begin, node.end);
|
|
1082
|
+
if(node.type==='import') return node.cjs;
|
|
1083
|
+
if(node.type==='export') return node.cjs;
|
|
1080
1084
|
if(node.type==='regex') return jsx.substring(node.begin, node.end);
|
|
1081
1085
|
if(node.type==='comment') return (discardComments || is_attr)?'':jsx.substring(node.begin, node.end);
|
|
1082
1086
|
if(node.type==='directive') return node.value;
|
|
@@ -1086,6 +1090,7 @@ export function transpileJSX( jsx, {
|
|
|
1086
1090
|
let out = "(";
|
|
1087
1091
|
|
|
1088
1092
|
if(node.out) {
|
|
1093
|
+
if(produceCJS) processImportExports(node, jsx);
|
|
1089
1094
|
for(const ch of node.out) {
|
|
1090
1095
|
out+=codify(outlen+out.length-1, ch);
|
|
1091
1096
|
}
|
|
@@ -1094,9 +1099,12 @@ export function transpileJSX( jsx, {
|
|
|
1094
1099
|
}
|
|
1095
1100
|
|
|
1096
1101
|
if(node.type==='js') {
|
|
1102
|
+
|
|
1103
|
+
|
|
1097
1104
|
let out = "";
|
|
1098
1105
|
|
|
1099
1106
|
if(node.out) {
|
|
1107
|
+
if(produceCJS) processImportExports(node, jsx);
|
|
1100
1108
|
for(const ch of node.out) {
|
|
1101
1109
|
if(is_xml && ch.type==='comment') continue;
|
|
1102
1110
|
out+=codify( outlen + out.length - (is_attr?1:0), ch);
|
|
@@ -1182,16 +1190,6 @@ export function transpileJSX( jsx, {
|
|
|
1182
1190
|
if(appendSourcemap) {
|
|
1183
1191
|
out += inline_sm;
|
|
1184
1192
|
}
|
|
1185
|
-
|
|
1186
|
-
// if(globalThis[TRANSPILER_OUTPUT]) {
|
|
1187
|
-
// try {
|
|
1188
|
-
// const fs = import('fs');
|
|
1189
|
-
// fs.writeFileSync(globalThis[TRANSPILER_OUTPUT], out);
|
|
1190
|
-
// }
|
|
1191
|
-
// catch(e) {}
|
|
1192
|
-
// globalThis[TRANSPILER_OUTPUT] = undefined;
|
|
1193
|
-
// }
|
|
1194
|
-
|
|
1195
1193
|
//console.log(out);
|
|
1196
1194
|
|
|
1197
1195
|
return out;
|
package/src/lilact.jsx
CHANGED
|
@@ -92,7 +92,7 @@ export {transpileJSX, transpilerConfig} from "./jsx";
|
|
|
92
92
|
export const Lilact =
|
|
93
93
|
{
|
|
94
94
|
|
|
95
|
-
VERSION: "beta.
|
|
95
|
+
VERSION: "beta.22",
|
|
96
96
|
|
|
97
97
|
// Configuration
|
|
98
98
|
|
|
@@ -123,11 +123,20 @@ export const Lilact =
|
|
|
123
123
|
redux,
|
|
124
124
|
emotion,
|
|
125
125
|
|
|
126
|
+
default: Lilact,
|
|
127
|
+
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
Lilact.importObjectPaths = {
|
|
131
|
+
"lilact": Lilact,
|
|
132
|
+
"@emotion/css": Lilact.emotion,
|
|
133
|
+
"redux": Lilact.redux
|
|
126
134
|
}
|
|
127
135
|
|
|
128
136
|
globalThis.Lilact = Lilact;
|
|
129
137
|
globalThis.createComponent = Lilact.createComponent;
|
|
130
138
|
globalThis.Fragment = Lilact.Fragment;
|
|
139
|
+
globalThis.require = Lilact.require;
|
|
131
140
|
|
|
132
141
|
document.addEventListener('DOMContentLoaded', () => {
|
|
133
142
|
Lilact.runScripts();
|