@tishlang/tish 1.0.28 → 1.0.33
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/Cargo.toml +1 -0
- package/crates/js_to_tish/src/transform/expr.rs +15 -6
- package/crates/tish/Cargo.toml +1 -1
- package/crates/tish/src/main.rs +8 -55
- package/crates/tish/tests/integration_test.rs +4 -3
- package/crates/tish_ast/src/ast.rs +65 -2
- package/crates/tish_build_utils/src/lib.rs +10 -2
- package/crates/tish_builtins/src/construct.rs +177 -0
- package/crates/tish_builtins/src/globals.rs +3 -5
- package/crates/tish_builtins/src/helpers.rs +2 -3
- package/crates/tish_builtins/src/lib.rs +1 -0
- package/crates/tish_builtins/src/object.rs +3 -4
- package/crates/tish_bytecode/src/compiler.rs +85 -11
- package/crates/tish_bytecode/src/opcode.rs +7 -3
- package/crates/tish_compile/Cargo.toml +1 -0
- package/crates/tish_compile/src/codegen.rs +233 -71
- package/crates/tish_compile/src/lib.rs +35 -0
- package/crates/tish_compile_js/Cargo.toml +1 -1
- package/crates/tish_compile_js/src/codegen.rs +43 -147
- package/crates/tish_compile_js/src/lib.rs +4 -7
- package/crates/tish_compile_js/src/tests_jsx.rs +89 -19
- package/crates/tish_compiler_wasm/src/lib.rs +2 -3
- package/crates/tish_core/Cargo.toml +4 -0
- package/crates/tish_core/src/console_style.rs +7 -1
- package/crates/tish_core/src/json.rs +1 -2
- package/crates/tish_core/src/macros.rs +2 -3
- package/crates/tish_core/src/value.rs +10 -5
- package/crates/tish_eval/Cargo.toml +2 -0
- package/crates/tish_eval/src/eval.rs +149 -72
- package/crates/tish_eval/src/http.rs +3 -4
- package/crates/tish_eval/src/regex.rs +3 -2
- package/crates/tish_eval/src/value.rs +11 -13
- package/crates/tish_eval/src/value_convert.rs +4 -8
- package/crates/tish_fmt/src/lib.rs +49 -10
- package/crates/tish_jsx_web/Cargo.toml +1 -1
- package/crates/tish_jsx_web/README.md +3 -16
- package/crates/tish_jsx_web/src/lib.rs +2 -157
- package/crates/tish_lexer/src/token.rs +2 -0
- package/crates/tish_lint/src/lib.rs +9 -0
- package/crates/tish_lsp/README.md +1 -1
- package/crates/tish_native/src/build.rs +16 -2
- package/crates/tish_opt/src/lib.rs +15 -0
- package/crates/tish_parser/src/lib.rs +101 -1
- package/crates/tish_parser/src/parser.rs +161 -50
- package/crates/tish_runtime/src/http.rs +4 -5
- package/crates/tish_runtime/src/http_fetch.rs +9 -10
- package/crates/tish_runtime/src/lib.rs +9 -2
- package/crates/tish_runtime/src/promise.rs +2 -3
- package/crates/tish_runtime/src/promise_io.rs +2 -3
- package/crates/tish_runtime/src/ws.rs +7 -7
- package/crates/tish_ui/Cargo.toml +17 -0
- package/crates/tish_ui/src/jsx.rs +390 -0
- package/crates/tish_ui/src/lib.rs +16 -0
- package/crates/tish_ui/src/runtime/hooks.rs +122 -0
- package/crates/tish_ui/src/runtime/mod.rs +173 -0
- package/crates/tish_vm/src/vm.rs +121 -27
- package/justfile +3 -3
- package/package.json +1 -1
- package/platform/darwin-arm64/tish +0 -0
- package/platform/darwin-x64/tish +0 -0
- package/platform/linux-arm64/tish +0 -0
- package/platform/linux-x64/tish +0 -0
- package/platform/win32-x64/tish.exe +0 -0
- package/crates/tish_compile_js/src/js_intrinsics.rs +0 -82
- package/crates/tish_jsx_web/vendor/Lattish.tish +0 -362
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
// Lattish: Lattish runtime for compiled JSX. Publish to npm; consumed by tish and tish-playground.
|
|
2
|
-
// With `tish compile --target js --jsx vdom`, the compiler injects a prelude that sets
|
|
3
|
-
// window.__LATTISH_JSX_VDOM and __lattishVdomPatch; createRoot then reconciles vnodes.
|
|
4
|
-
|
|
5
|
-
export let Fragment = Symbol("Lattish.Fragment")
|
|
6
|
-
|
|
7
|
-
fn __lattishAppend(parent, c) {
|
|
8
|
-
if (c === null || c === undefined) {
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
if (Array.isArray(c)) {
|
|
12
|
-
let i = 0
|
|
13
|
-
while (i < c.length) {
|
|
14
|
-
__lattishAppend(parent, c[i])
|
|
15
|
-
i = i + 1
|
|
16
|
-
}
|
|
17
|
-
return
|
|
18
|
-
}
|
|
19
|
-
if (typeof c === "string") {
|
|
20
|
-
parent.appendChild(document.createTextNode(c))
|
|
21
|
-
} else {
|
|
22
|
-
parent.appendChild(c)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export fn h(tag, props, children) {
|
|
27
|
-
if (children === undefined || children === null) {
|
|
28
|
-
children = []
|
|
29
|
-
}
|
|
30
|
-
if (typeof tag === "function") {
|
|
31
|
-
let p = props && props !== null ? props : {}
|
|
32
|
-
if (children.length > 0) {
|
|
33
|
-
let newProps = {}
|
|
34
|
-
let keys = Object.keys(p)
|
|
35
|
-
let i = 0
|
|
36
|
-
while (i < keys.length) {
|
|
37
|
-
newProps[keys[i]] = p[keys[i]]
|
|
38
|
-
i = i + 1
|
|
39
|
-
}
|
|
40
|
-
newProps.children = children
|
|
41
|
-
p = newProps
|
|
42
|
-
}
|
|
43
|
-
return tag(p)
|
|
44
|
-
}
|
|
45
|
-
if (tag === Fragment) {
|
|
46
|
-
let f = document.createDocumentFragment()
|
|
47
|
-
let i = 0
|
|
48
|
-
while (i < children.length) {
|
|
49
|
-
__lattishAppend(f, children[i])
|
|
50
|
-
i = i + 1
|
|
51
|
-
}
|
|
52
|
-
return f
|
|
53
|
-
}
|
|
54
|
-
let el = document.createElement(tag)
|
|
55
|
-
let refVal = null
|
|
56
|
-
if (props && props !== null) {
|
|
57
|
-
let keys = Object.keys(props)
|
|
58
|
-
let ki = 0
|
|
59
|
-
while (ki < keys.length) {
|
|
60
|
-
let k = keys[ki]
|
|
61
|
-
let v = props[k]
|
|
62
|
-
if (k === "ref") {
|
|
63
|
-
refVal = v
|
|
64
|
-
} else {
|
|
65
|
-
if (k === "disabled") {
|
|
66
|
-
el.disabled = !!v
|
|
67
|
-
} else {
|
|
68
|
-
if (v === true) {
|
|
69
|
-
el.setAttribute(k, k)
|
|
70
|
-
} else {
|
|
71
|
-
if (v !== false && v !== null && v !== undefined) {
|
|
72
|
-
if (k === "class" || k === "className") {
|
|
73
|
-
el.className = v
|
|
74
|
-
} else {
|
|
75
|
-
if (k.length >= 3 && k[0] === "o" && k[1] === "n" && typeof v === "function") {
|
|
76
|
-
let eventType = k.slice(2).toLowerCase()
|
|
77
|
-
el.addEventListener(eventType, v)
|
|
78
|
-
} else {
|
|
79
|
-
if (k === "value" && (tag === "input" || tag === "textarea")) {
|
|
80
|
-
el.value = v
|
|
81
|
-
} else {
|
|
82
|
-
if (k !== "ref") {
|
|
83
|
-
el.setAttribute(k, String(v))
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
ki = ki + 1
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
let ci = 0
|
|
96
|
-
while (ci < children.length) {
|
|
97
|
-
__lattishAppend(el, children[ci])
|
|
98
|
-
ci = ci + 1
|
|
99
|
-
}
|
|
100
|
-
if (refVal !== null && refVal !== undefined && typeof refVal === "object") {
|
|
101
|
-
refVal.current = el
|
|
102
|
-
}
|
|
103
|
-
return el
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export fn text(s) {
|
|
107
|
-
return s
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
let __state = []
|
|
111
|
-
let __cursor = 0
|
|
112
|
-
let __container = null
|
|
113
|
-
let __App = null
|
|
114
|
-
let __rootVnode = null
|
|
115
|
-
|
|
116
|
-
let __memoSlots = []
|
|
117
|
-
let __refSlots = []
|
|
118
|
-
let __layoutEffectSlots = []
|
|
119
|
-
let __effectSlots = []
|
|
120
|
-
|
|
121
|
-
let __flushScheduled = false
|
|
122
|
-
let __batchDepth = 0
|
|
123
|
-
let __dirtyFromBatch = false
|
|
124
|
-
let __effectsMicrotaskScheduled = false
|
|
125
|
-
|
|
126
|
-
fn __depsChanged(prev, next) {
|
|
127
|
-
if (prev === null) {
|
|
128
|
-
return true
|
|
129
|
-
}
|
|
130
|
-
if (next === null || prev === null) {
|
|
131
|
-
return true
|
|
132
|
-
}
|
|
133
|
-
if (prev.length !== next.length) {
|
|
134
|
-
return true
|
|
135
|
-
}
|
|
136
|
-
let j = 0
|
|
137
|
-
while (j < next.length) {
|
|
138
|
-
if (prev[j] !== next[j]) {
|
|
139
|
-
return true
|
|
140
|
-
}
|
|
141
|
-
j = j + 1
|
|
142
|
-
}
|
|
143
|
-
return false
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
fn __runLayoutEffects() {
|
|
147
|
-
let i = 0
|
|
148
|
-
while (i < __layoutEffectSlots.length) {
|
|
149
|
-
let s = __layoutEffectSlots[i]
|
|
150
|
-
if (s && s.pending) {
|
|
151
|
-
s.pending = false
|
|
152
|
-
if (s.cleanup) {
|
|
153
|
-
s.cleanup()
|
|
154
|
-
s.cleanup = null
|
|
155
|
-
}
|
|
156
|
-
let c = s.effect()
|
|
157
|
-
if (typeof c === "function") {
|
|
158
|
-
s.cleanup = c
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
i = i + 1
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
fn __scheduleEffectsFlush() {
|
|
166
|
-
if (__effectsMicrotaskScheduled) {
|
|
167
|
-
return
|
|
168
|
-
}
|
|
169
|
-
__effectsMicrotaskScheduled = true
|
|
170
|
-
queueMicrotask(() => {
|
|
171
|
-
__effectsMicrotaskScheduled = false
|
|
172
|
-
let i = 0
|
|
173
|
-
while (i < __effectSlots.length) {
|
|
174
|
-
let s = __effectSlots[i]
|
|
175
|
-
if (s && s.pending) {
|
|
176
|
-
s.pending = false
|
|
177
|
-
if (s.cleanup) {
|
|
178
|
-
s.cleanup()
|
|
179
|
-
s.cleanup = null
|
|
180
|
-
}
|
|
181
|
-
let c = s.effect()
|
|
182
|
-
if (typeof c === "function") {
|
|
183
|
-
s.cleanup = c
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
i = i + 1
|
|
187
|
-
}
|
|
188
|
-
})
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/// Runs synchronously after DOM is updated (before paint in typical browsers).
|
|
192
|
-
export fn useLayoutEffect(effect, deps) {
|
|
193
|
-
let i = __cursor
|
|
194
|
-
__cursor = __cursor + 1
|
|
195
|
-
while (i >= __layoutEffectSlots.length) {
|
|
196
|
-
__layoutEffectSlots.push(null)
|
|
197
|
-
}
|
|
198
|
-
let slot = __layoutEffectSlots[i]
|
|
199
|
-
if (slot === null) {
|
|
200
|
-
slot = { deps: null, effect: null, cleanup: null, pending: false }
|
|
201
|
-
__layoutEffectSlots[i] = slot
|
|
202
|
-
}
|
|
203
|
-
if (__depsChanged(slot.deps, deps)) {
|
|
204
|
-
slot.deps = deps
|
|
205
|
-
slot.effect = effect
|
|
206
|
-
slot.pending = true
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/// Runs after paint (microtask after flush).
|
|
211
|
-
export fn useEffect(effect, deps) {
|
|
212
|
-
let i = __cursor
|
|
213
|
-
__cursor = __cursor + 1
|
|
214
|
-
while (i >= __effectSlots.length) {
|
|
215
|
-
__effectSlots.push(null)
|
|
216
|
-
}
|
|
217
|
-
let slot = __effectSlots[i]
|
|
218
|
-
if (slot === null) {
|
|
219
|
-
slot = { deps: null, effect: null, cleanup: null, pending: false }
|
|
220
|
-
__effectSlots[i] = slot
|
|
221
|
-
}
|
|
222
|
-
if (__depsChanged(slot.deps, deps)) {
|
|
223
|
-
slot.deps = deps
|
|
224
|
-
slot.effect = effect
|
|
225
|
-
slot.pending = true
|
|
226
|
-
__scheduleEffectsFlush()
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
fn __usingVdom() {
|
|
231
|
-
return typeof window !== "undefined" && window.__LATTISH_JSX_VDOM && window.__lattishVdomPatch
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
fn __flushRender() {
|
|
235
|
-
__cursor = 0
|
|
236
|
-
if (__container && __App) {
|
|
237
|
-
if (__usingVdom()) {
|
|
238
|
-
let newTree = __App()
|
|
239
|
-
window.__lattishVdomPatch(__container, __rootVnode, newTree)
|
|
240
|
-
__rootVnode = newTree
|
|
241
|
-
} else {
|
|
242
|
-
let el = __App()
|
|
243
|
-
__container.replaceChildren(el)
|
|
244
|
-
__rootVnode = null
|
|
245
|
-
}
|
|
246
|
-
__runLayoutEffects()
|
|
247
|
-
__scheduleEffectsFlush()
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
fn __scheduleFlush() {
|
|
252
|
-
if (__batchDepth > 0) {
|
|
253
|
-
__dirtyFromBatch = true
|
|
254
|
-
return
|
|
255
|
-
}
|
|
256
|
-
if (__flushScheduled) {
|
|
257
|
-
return
|
|
258
|
-
}
|
|
259
|
-
__flushScheduled = true
|
|
260
|
-
queueMicrotask(() => {
|
|
261
|
-
__flushScheduled = false
|
|
262
|
-
__flushRender()
|
|
263
|
-
})
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
export fn unstable_batchedUpdates(run) {
|
|
267
|
-
__batchDepth = __batchDepth + 1
|
|
268
|
-
run()
|
|
269
|
-
__batchDepth = __batchDepth - 1
|
|
270
|
-
if (__batchDepth === 0 && __dirtyFromBatch) {
|
|
271
|
-
__dirtyFromBatch = false
|
|
272
|
-
__flushScheduled = false
|
|
273
|
-
__flushRender()
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
export fn useState(init) {
|
|
278
|
-
let i = __cursor
|
|
279
|
-
__cursor = __cursor + 1
|
|
280
|
-
if (i >= __state.length) {
|
|
281
|
-
__state.push(init)
|
|
282
|
-
}
|
|
283
|
-
fn setState(v) {
|
|
284
|
-
if (typeof v === "function") {
|
|
285
|
-
__state[i] = v(__state[i])
|
|
286
|
-
} else {
|
|
287
|
-
__state[i] = v
|
|
288
|
-
}
|
|
289
|
-
__scheduleFlush()
|
|
290
|
-
}
|
|
291
|
-
return [__state[i], setState]
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
export fn useMemo(deps, factory) {
|
|
295
|
-
let i = __cursor
|
|
296
|
-
__cursor = __cursor + 1
|
|
297
|
-
while (i >= __memoSlots.length) {
|
|
298
|
-
__memoSlots.push(null)
|
|
299
|
-
}
|
|
300
|
-
let slot = __memoSlots[i]
|
|
301
|
-
let stale = true
|
|
302
|
-
if (slot) {
|
|
303
|
-
stale = false
|
|
304
|
-
if (slot.deps.length !== deps.length) {
|
|
305
|
-
stale = true
|
|
306
|
-
} else {
|
|
307
|
-
let j = 0
|
|
308
|
-
while (j < deps.length) {
|
|
309
|
-
if (slot.deps[j] !== deps[j]) {
|
|
310
|
-
stale = true
|
|
311
|
-
break
|
|
312
|
-
}
|
|
313
|
-
j = j + 1
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
if (stale) {
|
|
318
|
-
__memoSlots[i] = { deps: deps, value: factory() }
|
|
319
|
-
}
|
|
320
|
-
return __memoSlots[i].value
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
export fn useRef(initial) {
|
|
324
|
-
let i = __cursor
|
|
325
|
-
__cursor = __cursor + 1
|
|
326
|
-
while (i >= __refSlots.length) {
|
|
327
|
-
__refSlots.push(null)
|
|
328
|
-
}
|
|
329
|
-
if (__refSlots[i] === null) {
|
|
330
|
-
__refSlots[i] = { current: initial }
|
|
331
|
-
}
|
|
332
|
-
return __refSlots[i]
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
export fn createRoot(container) {
|
|
336
|
-
fn render(App) {
|
|
337
|
-
__container = container
|
|
338
|
-
__App = App
|
|
339
|
-
__state = []
|
|
340
|
-
__memoSlots = []
|
|
341
|
-
__refSlots = []
|
|
342
|
-
__layoutEffectSlots = []
|
|
343
|
-
__effectSlots = []
|
|
344
|
-
__cursor = 0
|
|
345
|
-
__flushScheduled = false
|
|
346
|
-
__batchDepth = 0
|
|
347
|
-
__dirtyFromBatch = false
|
|
348
|
-
__effectsMicrotaskScheduled = false
|
|
349
|
-
__rootVnode = null
|
|
350
|
-
if (__usingVdom()) {
|
|
351
|
-
__rootVnode = App()
|
|
352
|
-
window.__lattishVdomPatch(container, null, __rootVnode)
|
|
353
|
-
} else {
|
|
354
|
-
let el = App()
|
|
355
|
-
container.replaceChildren(el)
|
|
356
|
-
}
|
|
357
|
-
__cursor = 0
|
|
358
|
-
__runLayoutEffects()
|
|
359
|
-
__scheduleEffectsFlush()
|
|
360
|
-
}
|
|
361
|
-
return { render: render }
|
|
362
|
-
}
|