olum-compiler 1.5.0 → 1.6.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/bin/build.js +1 -1
- package/bin/bundle.js +32 -30
- package/bin/compiler.js +20 -10
- package/bin/copySrc.js +45 -41
- package/bin/dev.js +46 -39
- package/bin/index.js +6 -3
- package/bin/server.js +58 -33
- package/bin/watcher.js +11 -14
- package/bin/ws.js +16 -11
- package/lib/attr.js +1 -25
- package/lib/boolAttr.js +32 -15
- package/lib/chokidar.js +52 -101
- package/lib/colors.js +1 -7
- package/lib/compPlaceholder.js +5 -3
- package/lib/compiler.js +3 -6
- package/lib/coreLibs.js +1 -10
- package/lib/cross-spawn.js +45 -59
- package/lib/cssParser.js +61 -37
- package/lib/domEvents.js +6 -2
- package/lib/events.js +75 -77
- package/lib/for.js +56 -28
- package/lib/getImports.js +35 -17
- package/lib/getTempPath.js +8 -4
- package/lib/helpers.js +289 -184
- package/lib/html.js +3 -10
- package/lib/htmlParser.js +45 -45
- package/lib/if.js +40 -20
- package/lib/importMap.js +49 -24
- package/lib/jsParser.js +8 -13
- package/lib/lineCounter.js +18 -5
- package/lib/liveProps.js +124 -78
- package/lib/log.js +30 -0
- package/lib/magic-string.js +45 -52
- package/lib/models.js +8 -7
- package/lib/parser.js +76 -44
- package/lib/placeholder.js +73 -58
- package/lib/regex.js +4 -3
- package/lib/show.js +16 -8
- package/lib/sourcemap.js +23 -24
- package/lib/styles.js +7 -13
- package/lib/textarea.js +3 -6
- package/lib/toJs.js +1 -1
- package/lib/tokens.js +10 -22
- package/lib/transition.js +86 -0
- package/lib/websocket.js +68 -62
- package/package.json +1 -1
- package/tests/compiler.test.js +423 -188
- package/.claude/settings.local.json +0 -12
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const { getLineInfo } = require("./lineCounter");
|
|
2
|
+
|
|
3
|
+
function parseDef(val) {
|
|
4
|
+
const m = String(val)
|
|
5
|
+
.trim()
|
|
6
|
+
.match(/^([A-Za-z_$][\w$]*)\s*(?:\(([\s\S]*)\))?$/);
|
|
7
|
+
if (!m) return null;
|
|
8
|
+
return { name: m[1], args: (m[2] || "").trim() };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function buildSpec(item, counter, filePath) {
|
|
12
|
+
const parts = [];
|
|
13
|
+
const add = (dir, raw) => {
|
|
14
|
+
const def = parseDef(raw);
|
|
15
|
+
if (!def) {
|
|
16
|
+
getLineInfo(
|
|
17
|
+
counter,
|
|
18
|
+
item,
|
|
19
|
+
filePath,
|
|
20
|
+
"Malformed <transition> value (expected name or name(params)):",
|
|
21
|
+
);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
parts.push(dir + ":" + def.name + "=${JSON.stringify([" + def.args + "])}");
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
if (item.hasAttribute("transition")) {
|
|
29
|
+
add("in", item.getAttribute("transition"));
|
|
30
|
+
add("out", item.getAttribute("transition"));
|
|
31
|
+
}
|
|
32
|
+
if (item.hasAttribute("in")) add("in", item.getAttribute("in"));
|
|
33
|
+
if (item.hasAttribute("out")) add("out", item.getAttribute("out"));
|
|
34
|
+
|
|
35
|
+
if (item.hasAttribute("flip")) {
|
|
36
|
+
const raw = (item.getAttribute("flip") || "").trim();
|
|
37
|
+
parts.push("flip=${JSON.stringify([" + raw + "])}");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
["onintrostart", "onintroend", "onoutrostart", "onoutroend"].forEach(
|
|
41
|
+
(attr) => {
|
|
42
|
+
if (item.hasAttribute(attr))
|
|
43
|
+
parts.push("@" + attr.slice(2) + "=" + item.getAttribute(attr).trim());
|
|
44
|
+
},
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
let chain = parts.join("&");
|
|
48
|
+
chain = chain.replace(/{/g, "<-olum->");
|
|
49
|
+
return "-[[-" + chain + "-]]-";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function handleTransition(body, counter, filePath) {
|
|
53
|
+
const els = new Array().slice.call(body.querySelectorAll("transition"));
|
|
54
|
+
els.forEach((item) => {
|
|
55
|
+
const child = item.firstElementChild;
|
|
56
|
+
if (!child) {
|
|
57
|
+
getLineInfo(
|
|
58
|
+
counter,
|
|
59
|
+
item,
|
|
60
|
+
filePath,
|
|
61
|
+
"Empty <transition> — expected a single element child:",
|
|
62
|
+
);
|
|
63
|
+
item.remove();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (
|
|
67
|
+
!item.hasAttribute("in") &&
|
|
68
|
+
!item.hasAttribute("out") &&
|
|
69
|
+
!item.hasAttribute("transition") &&
|
|
70
|
+
!item.hasAttribute("flip")
|
|
71
|
+
) {
|
|
72
|
+
getLineInfo(
|
|
73
|
+
counter,
|
|
74
|
+
item,
|
|
75
|
+
filePath,
|
|
76
|
+
"<transition> needs an in / out / transition / flip attribute:",
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
child.setAttribute("data-o-trans", buildSpec(item, counter, filePath));
|
|
80
|
+
|
|
81
|
+
while (item.firstChild) item.parentNode.insertBefore(item.firstChild, item);
|
|
82
|
+
item.remove();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
module.exports = handleTransition;
|
package/lib/websocket.js
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* websocket.js — standalone single-file WebSocket server (RFC 6455)
|
|
3
|
-
* Minimal replacement for the `ws` package's server side, using only node
|
|
4
|
-
* built-ins (http, crypto, events). Cross-platform by construction.
|
|
5
|
-
*
|
|
6
|
-
* Covered (same API shape as ws@8.21.0):
|
|
7
|
-
* const WebSocket = require("./websocket");
|
|
8
|
-
* const wss = new WebSocket.Server({ port }); // or { server } / { noServer: true }
|
|
9
|
-
* wss.on("listening" | "connection" | "error" | "close" | "headers", ...)
|
|
10
|
-
* ws.send(data, [cb]) / ws.ping() / ws.close(code, reason) / ws.terminate()
|
|
11
|
-
* ws.on("message" | "close" | "error" | "ping" | "pong", ...)
|
|
12
|
-
*
|
|
13
|
-
* Not included: the client-side WebSocket(url) constructor (browsers provide
|
|
14
|
-
* their own) and the permessage-deflate extension (never negotiated, so
|
|
15
|
-
* clients transparently fall back to uncompressed frames per the RFC).
|
|
16
|
-
*/
|
|
17
1
|
"use strict";
|
|
18
2
|
|
|
19
3
|
const crypto = require("crypto");
|
|
20
4
|
const http = require("http");
|
|
21
5
|
const { EventEmitter } = require("events");
|
|
22
6
|
|
|
23
|
-
const GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
7
|
+
const GUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
|
|
24
8
|
const EMPTY = Buffer.alloc(0);
|
|
25
9
|
|
|
26
10
|
const CONNECTING = 0;
|
|
@@ -28,7 +12,6 @@ const OPEN = 1;
|
|
|
28
12
|
const CLOSING = 2;
|
|
29
13
|
const CLOSED = 3;
|
|
30
14
|
|
|
31
|
-
// build one server→client frame: FIN set, no mask (RFC 6455 §5.1: servers must not mask)
|
|
32
15
|
function encodeFrame(opcode, payload) {
|
|
33
16
|
const len = payload.length;
|
|
34
17
|
let header;
|
|
@@ -47,13 +30,14 @@ function encodeFrame(opcode, payload) {
|
|
|
47
30
|
header.writeUInt32BE(len >>> 0, 6);
|
|
48
31
|
}
|
|
49
32
|
|
|
50
|
-
header[0] = 0x80 | opcode;
|
|
33
|
+
header[0] = 0x80 | opcode;
|
|
51
34
|
return Buffer.concat([header, payload]);
|
|
52
35
|
}
|
|
53
36
|
|
|
54
37
|
function toBuffer(data) {
|
|
55
38
|
if (Buffer.isBuffer(data)) return data;
|
|
56
|
-
if (ArrayBuffer.isView(data))
|
|
39
|
+
if (ArrayBuffer.isView(data))
|
|
40
|
+
return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
57
41
|
if (data instanceof ArrayBuffer) return Buffer.from(data);
|
|
58
42
|
return Buffer.from(String(data));
|
|
59
43
|
}
|
|
@@ -68,21 +52,18 @@ class WebSocket extends EventEmitter {
|
|
|
68
52
|
this._fragmentOpcode = 0;
|
|
69
53
|
this._closeSent = false;
|
|
70
54
|
this._closeReceived = false;
|
|
71
|
-
this._closeCode = 1006;
|
|
55
|
+
this._closeCode = 1006;
|
|
72
56
|
this._closeReason = EMPTY;
|
|
73
57
|
this.readyState = OPEN;
|
|
74
58
|
|
|
75
59
|
socket.setNoDelay(true);
|
|
76
|
-
socket.on("data", chunk => this._parse(chunk));
|
|
77
|
-
|
|
78
|
-
// close frame, end our side too so the tcp socket can actually close
|
|
60
|
+
socket.on("data", (chunk) => this._parse(chunk));
|
|
61
|
+
|
|
79
62
|
socket.on("end", () => {
|
|
80
63
|
this.readyState = CLOSING;
|
|
81
64
|
socket.end();
|
|
82
65
|
});
|
|
83
|
-
socket.on("error", err => {
|
|
84
|
-
// only forward if someone listens — an unhandled 'error' on an EventEmitter
|
|
85
|
-
// would throw and take down the whole process on any abrupt disconnect
|
|
66
|
+
socket.on("error", (err) => {
|
|
86
67
|
if (this.listenerCount("error") > 0) this.emit("error", err);
|
|
87
68
|
socket.destroy();
|
|
88
69
|
});
|
|
@@ -92,7 +73,6 @@ class WebSocket extends EventEmitter {
|
|
|
92
73
|
});
|
|
93
74
|
}
|
|
94
75
|
|
|
95
|
-
// ------------------------------------------------------------ outgoing
|
|
96
76
|
send(data, options, cb) {
|
|
97
77
|
if (typeof options === "function") {
|
|
98
78
|
cb = options;
|
|
@@ -100,9 +80,10 @@ class WebSocket extends EventEmitter {
|
|
|
100
80
|
}
|
|
101
81
|
|
|
102
82
|
if (this.readyState !== OPEN) {
|
|
103
|
-
// match ws: sending on a closed socket is a no-op unless a callback wants the error
|
|
104
83
|
if (cb) {
|
|
105
|
-
const err = new Error(
|
|
84
|
+
const err = new Error(
|
|
85
|
+
"WebSocket is not open: readyState " + this.readyState,
|
|
86
|
+
);
|
|
106
87
|
process.nextTick(cb, err);
|
|
107
88
|
}
|
|
108
89
|
return;
|
|
@@ -113,17 +94,26 @@ class WebSocket extends EventEmitter {
|
|
|
113
94
|
}
|
|
114
95
|
|
|
115
96
|
ping(data) {
|
|
116
|
-
if (this.readyState === OPEN)
|
|
97
|
+
if (this.readyState === OPEN)
|
|
98
|
+
this._socket.write(
|
|
99
|
+
encodeFrame(0x9, toBuffer(data == null ? EMPTY : data)),
|
|
100
|
+
);
|
|
117
101
|
}
|
|
118
102
|
|
|
119
103
|
pong(data) {
|
|
120
|
-
if (this.readyState === OPEN)
|
|
104
|
+
if (this.readyState === OPEN)
|
|
105
|
+
this._socket.write(
|
|
106
|
+
encodeFrame(0xa, toBuffer(data == null ? EMPTY : data)),
|
|
107
|
+
);
|
|
121
108
|
}
|
|
122
109
|
|
|
123
110
|
close(code, reason) {
|
|
124
111
|
if (this.readyState !== OPEN && this.readyState !== CLOSING) return;
|
|
125
|
-
this._sendClose(
|
|
126
|
-
|
|
112
|
+
this._sendClose(
|
|
113
|
+
code === undefined ? 1000 : code,
|
|
114
|
+
reason == null ? EMPTY : toBuffer(reason),
|
|
115
|
+
);
|
|
116
|
+
|
|
127
117
|
const timer = setTimeout(() => this._socket.destroy(), 30000);
|
|
128
118
|
if (timer.unref) timer.unref();
|
|
129
119
|
}
|
|
@@ -143,21 +133,21 @@ class WebSocket extends EventEmitter {
|
|
|
143
133
|
payload.writeUInt16BE(code, 0);
|
|
144
134
|
reason.copy(payload, 2);
|
|
145
135
|
}
|
|
146
|
-
if (this._socket.writable && !this._socket.writableEnded)
|
|
147
|
-
|
|
136
|
+
if (this._socket.writable && !this._socket.writableEnded)
|
|
137
|
+
this._socket.write(encodeFrame(0x8, payload));
|
|
138
|
+
|
|
148
139
|
if (this._closeReceived) this._socket.end();
|
|
149
140
|
}
|
|
150
141
|
|
|
151
|
-
// ------------------------------------------------------------ incoming
|
|
152
142
|
_abort(code) {
|
|
153
|
-
// protocol violation: send close frame with the given code and cut the connection
|
|
154
143
|
this._closeCode = code;
|
|
155
144
|
this._sendClose(code, EMPTY);
|
|
156
145
|
this._socket.end();
|
|
157
146
|
}
|
|
158
147
|
|
|
159
148
|
_parse(chunk) {
|
|
160
|
-
this._buffer =
|
|
149
|
+
this._buffer =
|
|
150
|
+
this._buffer.length === 0 ? chunk : Buffer.concat([this._buffer, chunk]);
|
|
161
151
|
|
|
162
152
|
while (true) {
|
|
163
153
|
const buf = this._buffer;
|
|
@@ -170,7 +160,6 @@ class WebSocket extends EventEmitter {
|
|
|
170
160
|
let length = buf[1] & 0x7f;
|
|
171
161
|
let offset = 2;
|
|
172
162
|
|
|
173
|
-
// no extension negotiated → RSV bits must be 0; clients must always mask
|
|
174
163
|
if (rsv !== 0 || !masked) return this._abort(1002);
|
|
175
164
|
|
|
176
165
|
if (length === 126) {
|
|
@@ -180,12 +169,13 @@ class WebSocket extends EventEmitter {
|
|
|
180
169
|
} else if (length === 127) {
|
|
181
170
|
if (buf.length < 10) return;
|
|
182
171
|
const length64 = buf.readBigUInt64BE(2);
|
|
183
|
-
if (length64 > BigInt(Number.MAX_SAFE_INTEGER))
|
|
172
|
+
if (length64 > BigInt(Number.MAX_SAFE_INTEGER))
|
|
173
|
+
return this._abort(1009);
|
|
184
174
|
length = Number(length64);
|
|
185
175
|
offset = 10;
|
|
186
176
|
}
|
|
187
177
|
|
|
188
|
-
if (length > 100 * 1024 * 1024) return this._abort(1009);
|
|
178
|
+
if (length > 100 * 1024 * 1024) return this._abort(1009);
|
|
189
179
|
|
|
190
180
|
if (buf.length < offset + 4 + length) return;
|
|
191
181
|
const mask = buf.slice(offset, offset + 4);
|
|
@@ -201,13 +191,12 @@ class WebSocket extends EventEmitter {
|
|
|
201
191
|
}
|
|
202
192
|
|
|
203
193
|
_handleFrame(fin, opcode, payload) {
|
|
204
|
-
// control frames (§5.5): never fragmented, payload ≤ 125
|
|
205
194
|
if (opcode >= 0x8) {
|
|
206
195
|
if (!fin || payload.length > 125) return this._abort(1002);
|
|
207
196
|
|
|
208
197
|
if (opcode === 0x8) {
|
|
209
198
|
this._closeReceived = true;
|
|
210
|
-
let code = 1005;
|
|
199
|
+
let code = 1005;
|
|
211
200
|
let reason = EMPTY;
|
|
212
201
|
if (payload.length >= 2) {
|
|
213
202
|
code = payload.readUInt16BE(0);
|
|
@@ -217,10 +206,10 @@ class WebSocket extends EventEmitter {
|
|
|
217
206
|
}
|
|
218
207
|
this._closeCode = code === 1005 ? 1000 : code;
|
|
219
208
|
this._closeReason = reason;
|
|
220
|
-
this._sendClose(payload.length >= 2 ? code : undefined, reason);
|
|
209
|
+
this._sendClose(payload.length >= 2 ? code : undefined, reason);
|
|
221
210
|
this._socket.end();
|
|
222
211
|
} else if (opcode === 0x9) {
|
|
223
|
-
this.pong(payload);
|
|
212
|
+
this.pong(payload);
|
|
224
213
|
this.emit("ping", payload);
|
|
225
214
|
} else if (opcode === 0xa) {
|
|
226
215
|
this.emit("pong", payload);
|
|
@@ -230,14 +219,13 @@ class WebSocket extends EventEmitter {
|
|
|
230
219
|
return;
|
|
231
220
|
}
|
|
232
221
|
|
|
233
|
-
// data frames: 0x1 text, 0x2 binary, 0x0 continuation of a fragmented message
|
|
234
222
|
if (opcode === 0x1 || opcode === 0x2) {
|
|
235
|
-
if (this._fragments.length > 0) return this._abort(1002);
|
|
223
|
+
if (this._fragments.length > 0) return this._abort(1002);
|
|
236
224
|
if (fin) return this.emit("message", payload, opcode === 0x2);
|
|
237
225
|
this._fragmentOpcode = opcode;
|
|
238
226
|
this._fragments.push(payload);
|
|
239
227
|
} else if (opcode === 0x0) {
|
|
240
|
-
if (this._fragments.length === 0) return this._abort(1002);
|
|
228
|
+
if (this._fragments.length === 0) return this._abort(1002);
|
|
241
229
|
this._fragments.push(payload);
|
|
242
230
|
if (fin) {
|
|
243
231
|
const message = Buffer.concat(this._fragments);
|
|
@@ -246,7 +234,7 @@ class WebSocket extends EventEmitter {
|
|
|
246
234
|
this.emit("message", message, isBinary);
|
|
247
235
|
}
|
|
248
236
|
} else {
|
|
249
|
-
this._abort(1002);
|
|
237
|
+
this._abort(1002);
|
|
250
238
|
}
|
|
251
239
|
}
|
|
252
240
|
}
|
|
@@ -269,21 +257,30 @@ class WebSocketServer extends EventEmitter {
|
|
|
269
257
|
this._server = null;
|
|
270
258
|
this._ownServer = false;
|
|
271
259
|
} else {
|
|
272
|
-
// plain http requests get the same answer ws gives: 426 Upgrade Required
|
|
273
260
|
this._server = http.createServer((req, res) => {
|
|
274
261
|
const body = http.STATUS_CODES[426];
|
|
275
|
-
res.writeHead(426, {
|
|
262
|
+
res.writeHead(426, {
|
|
263
|
+
"Content-Length": body.length,
|
|
264
|
+
"Content-Type": "text/plain",
|
|
265
|
+
});
|
|
276
266
|
res.end(body);
|
|
277
267
|
});
|
|
278
268
|
this._ownServer = true;
|
|
279
|
-
this._server.listen(
|
|
269
|
+
this._server.listen(
|
|
270
|
+
options.port,
|
|
271
|
+
options.host,
|
|
272
|
+
options.backlog,
|
|
273
|
+
callback,
|
|
274
|
+
);
|
|
280
275
|
}
|
|
281
276
|
|
|
282
277
|
if (this._server) {
|
|
283
278
|
this._server.on("listening", () => this.emit("listening"));
|
|
284
|
-
this._server.on("error", err => this.emit("error", err));
|
|
279
|
+
this._server.on("error", (err) => this.emit("error", err));
|
|
285
280
|
this._server.on("upgrade", (req, socket, head) => {
|
|
286
|
-
this.handleUpgrade(req, socket, head, ws =>
|
|
281
|
+
this.handleUpgrade(req, socket, head, (ws) =>
|
|
282
|
+
this.emit("connection", ws, req),
|
|
283
|
+
);
|
|
287
284
|
});
|
|
288
285
|
}
|
|
289
286
|
}
|
|
@@ -297,23 +294,32 @@ class WebSocketServer extends EventEmitter {
|
|
|
297
294
|
|
|
298
295
|
const key = req.headers["sec-websocket-key"];
|
|
299
296
|
const version = +req.headers["sec-websocket-version"];
|
|
300
|
-
const upgrade = (req.headers.upgrade || "")
|
|
301
|
-
|
|
302
|
-
|
|
297
|
+
const upgrade = (req.headers.upgrade || "")
|
|
298
|
+
.split(/, */)
|
|
299
|
+
.some((p) => p.toLowerCase() === "websocket");
|
|
300
|
+
|
|
301
|
+
if (
|
|
302
|
+
req.method !== "GET" ||
|
|
303
|
+
!upgrade ||
|
|
304
|
+
!key ||
|
|
305
|
+
(version !== 13 && version !== 8)
|
|
306
|
+
) {
|
|
303
307
|
const body = http.STATUS_CODES[400];
|
|
304
308
|
socket.write(
|
|
305
309
|
"HTTP/1.1 400 Bad Request\r\n" +
|
|
306
310
|
"Connection: close\r\n" +
|
|
307
311
|
"Content-Type: text/plain\r\n" +
|
|
308
312
|
`Content-Length: ${body.length}\r\n\r\n` +
|
|
309
|
-
body
|
|
313
|
+
body,
|
|
310
314
|
);
|
|
311
315
|
socket.destroy();
|
|
312
316
|
return;
|
|
313
317
|
}
|
|
314
318
|
|
|
315
|
-
|
|
316
|
-
|
|
319
|
+
const accept = crypto
|
|
320
|
+
.createHash("sha1")
|
|
321
|
+
.update(key + GUID)
|
|
322
|
+
.digest("base64");
|
|
317
323
|
const headers = [
|
|
318
324
|
"HTTP/1.1 101 Switching Protocols",
|
|
319
325
|
"Upgrade: websocket",
|
|
@@ -325,7 +331,7 @@ class WebSocketServer extends EventEmitter {
|
|
|
325
331
|
socket.write(headers.concat("\r\n").join("\r\n"));
|
|
326
332
|
|
|
327
333
|
const ws = new WebSocket(socket);
|
|
328
|
-
if (head && head.length > 0) ws._parse(head);
|
|
334
|
+
if (head && head.length > 0) ws._parse(head);
|
|
329
335
|
|
|
330
336
|
this.clients.add(ws);
|
|
331
337
|
ws.on("close", () => this.clients.delete(ws));
|