@astrojs/compiler 1.3.0 → 1.3.2
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 +13 -0
- package/README.md +1 -1
- package/astro.wasm +0 -0
- package/browser/utils.d.ts +1 -1
- package/node/index.d.ts +1 -1
- package/node/index.js +1 -1
- package/node/sync.cjs +532 -0
- package/node/sync.cts +62 -0
- package/node/sync.d.cts +12 -0
- package/node/utils.d.ts +1 -1
- package/package.json +9 -4
- package/shared/ast.d.ts +4 -4
- package/shared/types.d.ts +2 -2
- package/sync.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @astrojs/compiler
|
|
2
2
|
|
|
3
|
+
## 1.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 19c0176: Fix TSX sourcemapping for components using Windows-style line returns
|
|
8
|
+
- b0e0cfd: Add a sync entrypoint
|
|
9
|
+
|
|
10
|
+
## 1.3.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- e0baa85: Preserve whitespace in slots
|
|
15
|
+
|
|
3
16
|
## 1.3.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/README.md
CHANGED
package/astro.wasm
CHANGED
|
Binary file
|
package/browser/utils.d.ts
CHANGED
|
@@ -23,5 +23,5 @@ export interface SerializeOptions {
|
|
|
23
23
|
selfClose: boolean;
|
|
24
24
|
}
|
|
25
25
|
/** @deprecated Please use `SerializeOptions` */
|
|
26
|
-
export
|
|
26
|
+
export type SerializeOtions = SerializeOptions;
|
|
27
27
|
export declare function serialize(root: Node, opts?: SerializeOptions): string;
|
package/node/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { HoistedScript, ParseOptions, ParseResult, PreprocessorResult, TransformOptions, TransformResult } from '../shared/types';
|
|
2
2
|
import type * as types from '../shared/types';
|
|
3
3
|
export declare const transform: typeof types.transform;
|
|
4
4
|
export declare const parse: typeof types.parse;
|
package/node/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { promises as fs } from 'fs';
|
|
2
|
-
import Go from './wasm_exec.js';
|
|
3
2
|
import { fileURLToPath } from 'url';
|
|
3
|
+
import Go from './wasm_exec.js';
|
|
4
4
|
export const transform = async (input, options) => {
|
|
5
5
|
return getService().then((service) => service.transform(input, options));
|
|
6
6
|
};
|
package/node/sync.cjs
ADDED
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// node/sync.cts
|
|
31
|
+
var sync_exports = {};
|
|
32
|
+
__export(sync_exports, {
|
|
33
|
+
convertToTSX: () => convertToTSX,
|
|
34
|
+
parse: () => parse,
|
|
35
|
+
startRunningService: () => startRunningService,
|
|
36
|
+
transform: () => transform
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(sync_exports);
|
|
39
|
+
var import_node_fs = require("node:fs");
|
|
40
|
+
var import_node_path = require("node:path");
|
|
41
|
+
|
|
42
|
+
// node/wasm_exec.js
|
|
43
|
+
var import_fs = __toESM(require("fs"), 1);
|
|
44
|
+
var import_crypto = __toESM(require("crypto"), 1);
|
|
45
|
+
var import_util = require("util");
|
|
46
|
+
if (!globalThis.fs) {
|
|
47
|
+
Object.defineProperty(globalThis, "fs", {
|
|
48
|
+
value: import_fs.default
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (!globalThis.process) {
|
|
52
|
+
Object.defineProperties(globalThis, "process", {
|
|
53
|
+
value: process
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (!globalThis.crypto) {
|
|
57
|
+
Object.defineProperty(globalThis, "crypto", {
|
|
58
|
+
value: {
|
|
59
|
+
getRandomValues(b) {
|
|
60
|
+
return import_crypto.default.randomFillSync(b);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (!globalThis.performance) {
|
|
66
|
+
Object.defineProperty(globalThis, "performance", {
|
|
67
|
+
value: {
|
|
68
|
+
now() {
|
|
69
|
+
const [sec, nsec] = process.hrtime();
|
|
70
|
+
return sec * 1e3 + nsec / 1e6;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
var encoder = new import_util.TextEncoder("utf-8");
|
|
76
|
+
var decoder = new import_util.TextDecoder("utf-8");
|
|
77
|
+
var Go = class {
|
|
78
|
+
constructor() {
|
|
79
|
+
this.argv = ["js"];
|
|
80
|
+
this.env = {};
|
|
81
|
+
this.exit = (code) => {
|
|
82
|
+
if (code !== 0) {
|
|
83
|
+
console.warn("exit code:", code);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
this._exitPromise = new Promise((resolve) => {
|
|
87
|
+
this._resolveExitPromise = resolve;
|
|
88
|
+
});
|
|
89
|
+
this._pendingEvent = null;
|
|
90
|
+
this._scheduledTimeouts = /* @__PURE__ */ new Map();
|
|
91
|
+
this._nextCallbackTimeoutID = 1;
|
|
92
|
+
const setInt64 = (addr, v) => {
|
|
93
|
+
this.mem.setUint32(addr + 0, v, true);
|
|
94
|
+
this.mem.setUint32(addr + 4, Math.floor(v / 4294967296), true);
|
|
95
|
+
};
|
|
96
|
+
const getInt64 = (addr) => {
|
|
97
|
+
const low = this.mem.getUint32(addr + 0, true);
|
|
98
|
+
const high = this.mem.getInt32(addr + 4, true);
|
|
99
|
+
return low + high * 4294967296;
|
|
100
|
+
};
|
|
101
|
+
const loadValue = (addr) => {
|
|
102
|
+
const f = this.mem.getFloat64(addr, true);
|
|
103
|
+
if (f === 0) {
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
if (!isNaN(f)) {
|
|
107
|
+
return f;
|
|
108
|
+
}
|
|
109
|
+
const id = this.mem.getUint32(addr, true);
|
|
110
|
+
return this._values[id];
|
|
111
|
+
};
|
|
112
|
+
const storeValue = (addr, v) => {
|
|
113
|
+
const nanHead = 2146959360;
|
|
114
|
+
if (typeof v === "number" && v !== 0) {
|
|
115
|
+
if (isNaN(v)) {
|
|
116
|
+
this.mem.setUint32(addr + 4, nanHead, true);
|
|
117
|
+
this.mem.setUint32(addr, 0, true);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
this.mem.setFloat64(addr, v, true);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (v === void 0) {
|
|
124
|
+
this.mem.setFloat64(addr, 0, true);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
let id = this._ids.get(v);
|
|
128
|
+
if (id === void 0) {
|
|
129
|
+
id = this._idPool.pop();
|
|
130
|
+
if (id === void 0) {
|
|
131
|
+
id = this._values.length;
|
|
132
|
+
}
|
|
133
|
+
this._values[id] = v;
|
|
134
|
+
this._goRefCounts[id] = 0;
|
|
135
|
+
this._ids.set(v, id);
|
|
136
|
+
}
|
|
137
|
+
this._goRefCounts[id]++;
|
|
138
|
+
let typeFlag = 0;
|
|
139
|
+
switch (typeof v) {
|
|
140
|
+
case "object":
|
|
141
|
+
if (v !== null) {
|
|
142
|
+
typeFlag = 1;
|
|
143
|
+
}
|
|
144
|
+
break;
|
|
145
|
+
case "string":
|
|
146
|
+
typeFlag = 2;
|
|
147
|
+
break;
|
|
148
|
+
case "symbol":
|
|
149
|
+
typeFlag = 3;
|
|
150
|
+
break;
|
|
151
|
+
case "function":
|
|
152
|
+
typeFlag = 4;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
this.mem.setUint32(addr + 4, nanHead | typeFlag, true);
|
|
156
|
+
this.mem.setUint32(addr, id, true);
|
|
157
|
+
};
|
|
158
|
+
const loadSlice = (addr) => {
|
|
159
|
+
const array = getInt64(addr + 0);
|
|
160
|
+
const len = getInt64(addr + 8);
|
|
161
|
+
return new Uint8Array(this._inst.exports.mem.buffer, array, len);
|
|
162
|
+
};
|
|
163
|
+
const loadSliceOfValues = (addr) => {
|
|
164
|
+
const array = getInt64(addr + 0);
|
|
165
|
+
const len = getInt64(addr + 8);
|
|
166
|
+
const a = new Array(len);
|
|
167
|
+
for (let i = 0; i < len; i++) {
|
|
168
|
+
a[i] = loadValue(array + i * 8);
|
|
169
|
+
}
|
|
170
|
+
return a;
|
|
171
|
+
};
|
|
172
|
+
const loadString = (addr) => {
|
|
173
|
+
const saddr = getInt64(addr + 0);
|
|
174
|
+
const len = getInt64(addr + 8);
|
|
175
|
+
return decoder.decode(new DataView(this._inst.exports.mem.buffer, saddr, len));
|
|
176
|
+
};
|
|
177
|
+
const timeOrigin = Date.now() - performance.now();
|
|
178
|
+
this.importObject = {
|
|
179
|
+
go: {
|
|
180
|
+
// Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters)
|
|
181
|
+
// may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported
|
|
182
|
+
// function. A goroutine can switch to a new stack if the current stack is too small (see morestack function).
|
|
183
|
+
// This changes the SP, thus we have to update the SP used by the imported function.
|
|
184
|
+
// func wasmExit(code int32)
|
|
185
|
+
"runtime.wasmExit": (sp) => {
|
|
186
|
+
sp >>>= 0;
|
|
187
|
+
const code = this.mem.getInt32(sp + 8, true);
|
|
188
|
+
this.exited = true;
|
|
189
|
+
delete this._inst;
|
|
190
|
+
delete this._values;
|
|
191
|
+
delete this._goRefCounts;
|
|
192
|
+
delete this._ids;
|
|
193
|
+
delete this._idPool;
|
|
194
|
+
this.exit(code);
|
|
195
|
+
},
|
|
196
|
+
// func wasmWrite(fd uintptr, p unsafe.Pointer, n int32)
|
|
197
|
+
"runtime.wasmWrite": (sp) => {
|
|
198
|
+
sp >>>= 0;
|
|
199
|
+
const fd = getInt64(sp + 8);
|
|
200
|
+
const p = getInt64(sp + 16);
|
|
201
|
+
const n = this.mem.getInt32(sp + 24, true);
|
|
202
|
+
import_fs.default.writeSync(fd, new Uint8Array(this._inst.exports.mem.buffer, p, n));
|
|
203
|
+
},
|
|
204
|
+
// func resetMemoryDataView()
|
|
205
|
+
"runtime.resetMemoryDataView": (sp) => {
|
|
206
|
+
sp >>>= 0;
|
|
207
|
+
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
208
|
+
},
|
|
209
|
+
// func nanotime1() int64
|
|
210
|
+
"runtime.nanotime1": (sp) => {
|
|
211
|
+
sp >>>= 0;
|
|
212
|
+
setInt64(sp + 8, (timeOrigin + performance.now()) * 1e6);
|
|
213
|
+
},
|
|
214
|
+
// func walltime() (sec int64, nsec int32)
|
|
215
|
+
"runtime.walltime": (sp) => {
|
|
216
|
+
sp >>>= 0;
|
|
217
|
+
const msec = (/* @__PURE__ */ new Date()).getTime();
|
|
218
|
+
setInt64(sp + 8, msec / 1e3);
|
|
219
|
+
this.mem.setInt32(sp + 16, msec % 1e3 * 1e6, true);
|
|
220
|
+
},
|
|
221
|
+
// func scheduleTimeoutEvent(delay int64) int32
|
|
222
|
+
"runtime.scheduleTimeoutEvent": (sp) => {
|
|
223
|
+
sp >>>= 0;
|
|
224
|
+
const id = this._nextCallbackTimeoutID;
|
|
225
|
+
this._nextCallbackTimeoutID++;
|
|
226
|
+
this._scheduledTimeouts.set(id, setTimeout(
|
|
227
|
+
() => {
|
|
228
|
+
this._resume();
|
|
229
|
+
while (this._scheduledTimeouts.has(id)) {
|
|
230
|
+
console.warn("scheduleTimeoutEvent: missed timeout event");
|
|
231
|
+
this._resume();
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
getInt64(sp + 8) + 1
|
|
235
|
+
// setTimeout has been seen to fire up to 1 millisecond early
|
|
236
|
+
));
|
|
237
|
+
this.mem.setInt32(sp + 16, id, true);
|
|
238
|
+
},
|
|
239
|
+
// func clearTimeoutEvent(id int32)
|
|
240
|
+
"runtime.clearTimeoutEvent": (sp) => {
|
|
241
|
+
sp >>>= 0;
|
|
242
|
+
const id = this.mem.getInt32(sp + 8, true);
|
|
243
|
+
clearTimeout(this._scheduledTimeouts.get(id));
|
|
244
|
+
this._scheduledTimeouts.delete(id);
|
|
245
|
+
},
|
|
246
|
+
// func getRandomData(r []byte)
|
|
247
|
+
"runtime.getRandomData": (sp) => {
|
|
248
|
+
sp >>>= 0;
|
|
249
|
+
globalThis.crypto.getRandomValues(loadSlice(sp + 8));
|
|
250
|
+
},
|
|
251
|
+
// func finalizeRef(v ref)
|
|
252
|
+
"syscall/js.finalizeRef": (sp) => {
|
|
253
|
+
sp >>>= 0;
|
|
254
|
+
const id = this.mem.getUint32(sp + 8, true);
|
|
255
|
+
this._goRefCounts[id]--;
|
|
256
|
+
if (this._goRefCounts[id] === 0) {
|
|
257
|
+
const v = this._values[id];
|
|
258
|
+
this._values[id] = null;
|
|
259
|
+
this._ids.delete(v);
|
|
260
|
+
this._idPool.push(id);
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
// func stringVal(value string) ref
|
|
264
|
+
"syscall/js.stringVal": (sp) => {
|
|
265
|
+
sp >>>= 0;
|
|
266
|
+
storeValue(sp + 24, loadString(sp + 8));
|
|
267
|
+
},
|
|
268
|
+
// func valueGet(v ref, p string) ref
|
|
269
|
+
"syscall/js.valueGet": (sp) => {
|
|
270
|
+
sp >>>= 0;
|
|
271
|
+
const result = Reflect.get(loadValue(sp + 8), loadString(sp + 16));
|
|
272
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
273
|
+
storeValue(sp + 32, result);
|
|
274
|
+
},
|
|
275
|
+
// func valueSet(v ref, p string, x ref)
|
|
276
|
+
"syscall/js.valueSet": (sp) => {
|
|
277
|
+
sp >>>= 0;
|
|
278
|
+
Reflect.set(loadValue(sp + 8), loadString(sp + 16), loadValue(sp + 32));
|
|
279
|
+
},
|
|
280
|
+
// func valueDelete(v ref, p string)
|
|
281
|
+
"syscall/js.valueDelete": (sp) => {
|
|
282
|
+
sp >>>= 0;
|
|
283
|
+
Reflect.deleteProperty(loadValue(sp + 8), loadString(sp + 16));
|
|
284
|
+
},
|
|
285
|
+
// func valueIndex(v ref, i int) ref
|
|
286
|
+
"syscall/js.valueIndex": (sp) => {
|
|
287
|
+
sp >>>= 0;
|
|
288
|
+
storeValue(sp + 24, Reflect.get(loadValue(sp + 8), getInt64(sp + 16)));
|
|
289
|
+
},
|
|
290
|
+
// valueSetIndex(v ref, i int, x ref)
|
|
291
|
+
"syscall/js.valueSetIndex": (sp) => {
|
|
292
|
+
sp >>>= 0;
|
|
293
|
+
Reflect.set(loadValue(sp + 8), getInt64(sp + 16), loadValue(sp + 24));
|
|
294
|
+
},
|
|
295
|
+
// func valueCall(v ref, m string, args []ref) (ref, bool)
|
|
296
|
+
"syscall/js.valueCall": (sp) => {
|
|
297
|
+
sp >>>= 0;
|
|
298
|
+
try {
|
|
299
|
+
const v = loadValue(sp + 8);
|
|
300
|
+
const m = Reflect.get(v, loadString(sp + 16));
|
|
301
|
+
const args = loadSliceOfValues(sp + 32);
|
|
302
|
+
const result = Reflect.apply(m, v, args);
|
|
303
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
304
|
+
storeValue(sp + 56, result);
|
|
305
|
+
this.mem.setUint8(sp + 64, 1);
|
|
306
|
+
} catch (err) {
|
|
307
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
308
|
+
storeValue(sp + 56, err);
|
|
309
|
+
this.mem.setUint8(sp + 64, 0);
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
// func valueInvoke(v ref, args []ref) (ref, bool)
|
|
313
|
+
"syscall/js.valueInvoke": (sp) => {
|
|
314
|
+
sp >>>= 0;
|
|
315
|
+
try {
|
|
316
|
+
const v = loadValue(sp + 8);
|
|
317
|
+
const args = loadSliceOfValues(sp + 16);
|
|
318
|
+
const result = Reflect.apply(v, void 0, args);
|
|
319
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
320
|
+
storeValue(sp + 40, result);
|
|
321
|
+
this.mem.setUint8(sp + 48, 1);
|
|
322
|
+
} catch (err) {
|
|
323
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
324
|
+
storeValue(sp + 40, err);
|
|
325
|
+
this.mem.setUint8(sp + 48, 0);
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
// func valueNew(v ref, args []ref) (ref, bool)
|
|
329
|
+
"syscall/js.valueNew": (sp) => {
|
|
330
|
+
sp >>>= 0;
|
|
331
|
+
try {
|
|
332
|
+
const v = loadValue(sp + 8);
|
|
333
|
+
const args = loadSliceOfValues(sp + 16);
|
|
334
|
+
const result = Reflect.construct(v, args);
|
|
335
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
336
|
+
storeValue(sp + 40, result);
|
|
337
|
+
this.mem.setUint8(sp + 48, 1);
|
|
338
|
+
} catch (err) {
|
|
339
|
+
sp = this._inst.exports.getsp() >>> 0;
|
|
340
|
+
storeValue(sp + 40, err);
|
|
341
|
+
this.mem.setUint8(sp + 48, 0);
|
|
342
|
+
}
|
|
343
|
+
},
|
|
344
|
+
// func valueLength(v ref) int
|
|
345
|
+
"syscall/js.valueLength": (sp) => {
|
|
346
|
+
sp >>>= 0;
|
|
347
|
+
setInt64(sp + 16, parseInt(loadValue(sp + 8).length));
|
|
348
|
+
},
|
|
349
|
+
// valuePrepareString(v ref) (ref, int)
|
|
350
|
+
"syscall/js.valuePrepareString": (sp) => {
|
|
351
|
+
sp >>>= 0;
|
|
352
|
+
const str = encoder.encode(String(loadValue(sp + 8)));
|
|
353
|
+
storeValue(sp + 16, str);
|
|
354
|
+
setInt64(sp + 24, str.length);
|
|
355
|
+
},
|
|
356
|
+
// valueLoadString(v ref, b []byte)
|
|
357
|
+
"syscall/js.valueLoadString": (sp) => {
|
|
358
|
+
sp >>>= 0;
|
|
359
|
+
const str = loadValue(sp + 8);
|
|
360
|
+
loadSlice(sp + 16).set(str);
|
|
361
|
+
},
|
|
362
|
+
// func valueInstanceOf(v ref, t ref) bool
|
|
363
|
+
"syscall/js.valueInstanceOf": (sp) => {
|
|
364
|
+
sp >>>= 0;
|
|
365
|
+
this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16) ? 1 : 0);
|
|
366
|
+
},
|
|
367
|
+
// func copyBytesToGo(dst []byte, src ref) (int, bool)
|
|
368
|
+
"syscall/js.copyBytesToGo": (sp) => {
|
|
369
|
+
sp >>>= 0;
|
|
370
|
+
const dst = loadSlice(sp + 8);
|
|
371
|
+
const src = loadValue(sp + 32);
|
|
372
|
+
if (!(src instanceof Uint8Array || src instanceof Uint8ClampedArray)) {
|
|
373
|
+
this.mem.setUint8(sp + 48, 0);
|
|
374
|
+
return;
|
|
375
|
+
}
|
|
376
|
+
const toCopy = src.subarray(0, dst.length);
|
|
377
|
+
dst.set(toCopy);
|
|
378
|
+
setInt64(sp + 40, toCopy.length);
|
|
379
|
+
this.mem.setUint8(sp + 48, 1);
|
|
380
|
+
},
|
|
381
|
+
// func copyBytesToJS(dst ref, src []byte) (int, bool)
|
|
382
|
+
"syscall/js.copyBytesToJS": (sp) => {
|
|
383
|
+
sp >>>= 0;
|
|
384
|
+
const dst = loadValue(sp + 8);
|
|
385
|
+
const src = loadSlice(sp + 16);
|
|
386
|
+
if (!(dst instanceof Uint8Array || dst instanceof Uint8ClampedArray)) {
|
|
387
|
+
this.mem.setUint8(sp + 48, 0);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
const toCopy = src.subarray(0, dst.length);
|
|
391
|
+
dst.set(toCopy);
|
|
392
|
+
setInt64(sp + 40, toCopy.length);
|
|
393
|
+
this.mem.setUint8(sp + 48, 1);
|
|
394
|
+
},
|
|
395
|
+
debug: (value) => {
|
|
396
|
+
console.log(value);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
async run(instance) {
|
|
402
|
+
if (!(instance instanceof WebAssembly.Instance)) {
|
|
403
|
+
throw new Error("Go.run: WebAssembly.Instance expected");
|
|
404
|
+
}
|
|
405
|
+
this._inst = instance;
|
|
406
|
+
this.mem = new DataView(this._inst.exports.mem.buffer);
|
|
407
|
+
this._values = [
|
|
408
|
+
// JS values that Go currently has references to, indexed by reference id
|
|
409
|
+
NaN,
|
|
410
|
+
0,
|
|
411
|
+
null,
|
|
412
|
+
true,
|
|
413
|
+
false,
|
|
414
|
+
globalThis,
|
|
415
|
+
this
|
|
416
|
+
];
|
|
417
|
+
this._goRefCounts = new Array(this._values.length).fill(Infinity);
|
|
418
|
+
this._ids = /* @__PURE__ */ new Map([
|
|
419
|
+
// mapping from JS values to reference ids
|
|
420
|
+
[0, 1],
|
|
421
|
+
[null, 2],
|
|
422
|
+
[true, 3],
|
|
423
|
+
[false, 4],
|
|
424
|
+
[globalThis, 5],
|
|
425
|
+
[this, 6]
|
|
426
|
+
]);
|
|
427
|
+
this._idPool = [];
|
|
428
|
+
this.exited = false;
|
|
429
|
+
let offset = 4096;
|
|
430
|
+
const strPtr = (str) => {
|
|
431
|
+
const ptr = offset;
|
|
432
|
+
const bytes = encoder.encode(str + "\0");
|
|
433
|
+
new Uint8Array(this.mem.buffer, offset, bytes.length).set(bytes);
|
|
434
|
+
offset += bytes.length;
|
|
435
|
+
if (offset % 8 !== 0) {
|
|
436
|
+
offset += 8 - offset % 8;
|
|
437
|
+
}
|
|
438
|
+
return ptr;
|
|
439
|
+
};
|
|
440
|
+
const argc = this.argv.length;
|
|
441
|
+
const argvPtrs = [];
|
|
442
|
+
this.argv.forEach((arg) => {
|
|
443
|
+
argvPtrs.push(strPtr(arg));
|
|
444
|
+
});
|
|
445
|
+
argvPtrs.push(0);
|
|
446
|
+
const keys = Object.keys(this.env).sort();
|
|
447
|
+
keys.forEach((key) => {
|
|
448
|
+
argvPtrs.push(strPtr(`${key}=${this.env[key]}`));
|
|
449
|
+
});
|
|
450
|
+
argvPtrs.push(0);
|
|
451
|
+
const argv = offset;
|
|
452
|
+
argvPtrs.forEach((ptr) => {
|
|
453
|
+
this.mem.setUint32(offset, ptr, true);
|
|
454
|
+
this.mem.setUint32(offset + 4, 0, true);
|
|
455
|
+
offset += 8;
|
|
456
|
+
});
|
|
457
|
+
this._inst.exports.run(argc, argv);
|
|
458
|
+
if (this.exited) {
|
|
459
|
+
this._resolveExitPromise();
|
|
460
|
+
}
|
|
461
|
+
await this._exitPromise;
|
|
462
|
+
}
|
|
463
|
+
_resume() {
|
|
464
|
+
if (this.exited) {
|
|
465
|
+
throw new Error("Go program has already exited");
|
|
466
|
+
}
|
|
467
|
+
this._inst.exports.resume();
|
|
468
|
+
if (this.exited) {
|
|
469
|
+
this._resolveExitPromise();
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
_makeFuncWrapper(id) {
|
|
473
|
+
const go = this;
|
|
474
|
+
return function() {
|
|
475
|
+
const event = { id, this: this, args: arguments };
|
|
476
|
+
go._pendingEvent = event;
|
|
477
|
+
go._resume();
|
|
478
|
+
return event.result;
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
// node/sync.cts
|
|
484
|
+
function getService() {
|
|
485
|
+
if (!longLivedService) {
|
|
486
|
+
longLivedService = startRunningService();
|
|
487
|
+
}
|
|
488
|
+
return longLivedService;
|
|
489
|
+
}
|
|
490
|
+
var longLivedService;
|
|
491
|
+
var transform = (input, options) => getService().transform(input, options);
|
|
492
|
+
var parse = (input, options) => {
|
|
493
|
+
return getService().parse(input, options);
|
|
494
|
+
};
|
|
495
|
+
var convertToTSX = (input, options) => {
|
|
496
|
+
return getService().convertToTSX(input, options);
|
|
497
|
+
};
|
|
498
|
+
function startRunningService() {
|
|
499
|
+
const go = new Go();
|
|
500
|
+
const wasm = instantiateWASM((0, import_node_path.join)(__dirname, "../astro.wasm"), go.importObject);
|
|
501
|
+
go.run(wasm);
|
|
502
|
+
const _service = globalThis["@astrojs/compiler"];
|
|
503
|
+
return {
|
|
504
|
+
transform: (input, options) => {
|
|
505
|
+
try {
|
|
506
|
+
return _service.transform(input, options || {});
|
|
507
|
+
} catch (err) {
|
|
508
|
+
longLivedService = void 0;
|
|
509
|
+
throw err;
|
|
510
|
+
}
|
|
511
|
+
},
|
|
512
|
+
parse: (input, options) => {
|
|
513
|
+
const result = _service.parse(input, options || {});
|
|
514
|
+
return { ...result, ast: JSON.parse(result.ast) };
|
|
515
|
+
},
|
|
516
|
+
convertToTSX: (input, options) => {
|
|
517
|
+
const result = _service.convertToTSX(input, options || {});
|
|
518
|
+
return { ...result, map: JSON.parse(result.map) };
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
function instantiateWASM(wasmURL, importObject) {
|
|
523
|
+
const wasmArrayBuffer = (0, import_node_fs.readFileSync)(wasmURL);
|
|
524
|
+
return new WebAssembly.Instance(new WebAssembly.Module(wasmArrayBuffer), importObject);
|
|
525
|
+
}
|
|
526
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
527
|
+
0 && (module.exports = {
|
|
528
|
+
convertToTSX,
|
|
529
|
+
parse,
|
|
530
|
+
startRunningService,
|
|
531
|
+
transform
|
|
532
|
+
});
|
package/node/sync.cts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import type * as types from '../shared/types';
|
|
4
|
+
import Go from './wasm_exec.js';
|
|
5
|
+
|
|
6
|
+
type UnwrappedPromise<T> = T extends (...params: any) => Promise<infer Return> ? (...params: Parameters<T>) => Return : T;
|
|
7
|
+
|
|
8
|
+
interface Service {
|
|
9
|
+
transform: UnwrappedPromise<typeof types.transform>;
|
|
10
|
+
parse: UnwrappedPromise<typeof types.parse>;
|
|
11
|
+
convertToTSX: UnwrappedPromise<typeof types.convertToTSX>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function getService(): Service {
|
|
15
|
+
if (!longLivedService) {
|
|
16
|
+
longLivedService = startRunningService();
|
|
17
|
+
}
|
|
18
|
+
return longLivedService;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let longLivedService: Service | undefined;
|
|
22
|
+
|
|
23
|
+
export const transform = ((input, options) => getService().transform(input, options)) satisfies Service['transform'];
|
|
24
|
+
|
|
25
|
+
export const parse = ((input, options) => {
|
|
26
|
+
return getService().parse(input, options);
|
|
27
|
+
}) satisfies Service['parse'];
|
|
28
|
+
|
|
29
|
+
export const convertToTSX = ((input, options) => {
|
|
30
|
+
return getService().convertToTSX(input, options);
|
|
31
|
+
}) satisfies Service['convertToTSX'];
|
|
32
|
+
|
|
33
|
+
export function startRunningService(): Service {
|
|
34
|
+
const go = new Go();
|
|
35
|
+
const wasm = instantiateWASM(join(__dirname, '../astro.wasm'), go.importObject);
|
|
36
|
+
go.run(wasm);
|
|
37
|
+
const _service: any = (globalThis as any)['@astrojs/compiler'];
|
|
38
|
+
return {
|
|
39
|
+
transform: (input, options) => {
|
|
40
|
+
try {
|
|
41
|
+
return _service.transform(input, options || {});
|
|
42
|
+
} catch (err) {
|
|
43
|
+
// Recreate the service next time on panic
|
|
44
|
+
longLivedService = void 0;
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
parse: (input, options) => {
|
|
49
|
+
const result = _service.parse(input, options || {});
|
|
50
|
+
return { ...result, ast: JSON.parse(result.ast) };
|
|
51
|
+
},
|
|
52
|
+
convertToTSX: (input, options) => {
|
|
53
|
+
const result = _service.convertToTSX(input, options || {});
|
|
54
|
+
return { ...result, map: JSON.parse(result.map) };
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function instantiateWASM(wasmURL: string, importObject: Record<string, any>): WebAssembly.Instance {
|
|
60
|
+
const wasmArrayBuffer = readFileSync(wasmURL);
|
|
61
|
+
return new WebAssembly.Instance(new WebAssembly.Module(wasmArrayBuffer), importObject);
|
|
62
|
+
}
|
package/node/sync.d.cts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type * as types from '../shared/types';
|
|
2
|
+
type UnwrappedPromise<T> = T extends (...params: any) => Promise<infer Return> ? (...params: Parameters<T>) => Return : T;
|
|
3
|
+
interface Service {
|
|
4
|
+
transform: UnwrappedPromise<typeof types.transform>;
|
|
5
|
+
parse: UnwrappedPromise<typeof types.parse>;
|
|
6
|
+
convertToTSX: UnwrappedPromise<typeof types.convertToTSX>;
|
|
7
|
+
}
|
|
8
|
+
export declare const transform: (input: string, options: types.TransformOptions | undefined) => types.TransformResult;
|
|
9
|
+
export declare const parse: (input: string, options: types.ParseOptions | undefined) => types.ParseResult;
|
|
10
|
+
export declare const convertToTSX: (input: string, options: types.ConvertToTSXOptions | undefined) => types.TSXResult;
|
|
11
|
+
export declare function startRunningService(): Service;
|
|
12
|
+
export {};
|
package/node/utils.d.ts
CHANGED
|
@@ -23,5 +23,5 @@ export interface SerializeOptions {
|
|
|
23
23
|
selfClose: boolean;
|
|
24
24
|
}
|
|
25
25
|
/** @deprecated Please use `SerializeOptions` */
|
|
26
|
-
export
|
|
26
|
+
export type SerializeOtions = SerializeOptions;
|
|
27
27
|
export declare function serialize(root: Node, opts?: SerializeOptions): string;
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bugs": "https://github.com/withastro/compiler/issues",
|
|
7
7
|
"homepage": "https://astro.build",
|
|
8
|
-
"version": "1.3.
|
|
8
|
+
"version": "1.3.2",
|
|
9
9
|
"main": "./node/index.js",
|
|
10
10
|
"types": "./node",
|
|
11
11
|
"repository": {
|
|
@@ -18,6 +18,10 @@
|
|
|
18
18
|
"import": "./node/index.js",
|
|
19
19
|
"default": "./browser/index.js"
|
|
20
20
|
},
|
|
21
|
+
"./sync": {
|
|
22
|
+
"import": "./node/sync.cjs",
|
|
23
|
+
"default": "./node/sync.cjs"
|
|
24
|
+
},
|
|
21
25
|
"./utils": {
|
|
22
26
|
"browser": "./browser/utils.js",
|
|
23
27
|
"import": "./node/utils.js",
|
|
@@ -28,12 +32,13 @@
|
|
|
28
32
|
},
|
|
29
33
|
"devDependencies": {
|
|
30
34
|
"@jridgewell/trace-mapping": "^0.3.16",
|
|
31
|
-
"@types/node": "^
|
|
35
|
+
"@types/node": "^18.15.11",
|
|
32
36
|
"@types/sass": "^1.43.1",
|
|
33
37
|
"acorn": "^8.8.1",
|
|
34
|
-
"
|
|
38
|
+
"esbuild": "^0.17.17",
|
|
39
|
+
"typescript": "~4.9.0"
|
|
35
40
|
},
|
|
36
41
|
"scripts": {
|
|
37
|
-
"build": "tsc -p ."
|
|
42
|
+
"build": "tsc -p . && esbuild node/sync.cts --bundle --format=cjs --platform=node --outfile=node/sync.cjs"
|
|
38
43
|
}
|
|
39
44
|
}
|
package/shared/ast.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export type ParentNode = RootNode | ElementNode | ComponentNode | CustomElementNode | FragmentNode | ExpressionNode;
|
|
2
|
+
export type LiteralNode = TextNode | DoctypeNode | CommentNode | FrontmatterNode;
|
|
3
|
+
export type Node = RootNode | ElementNode | ComponentNode | CustomElementNode | FragmentNode | ExpressionNode | TextNode | FrontmatterNode | DoctypeNode | CommentNode;
|
|
4
4
|
export interface Position {
|
|
5
5
|
start: Point;
|
|
6
6
|
end?: Point;
|
|
@@ -56,7 +56,7 @@ export interface CustomElementNode extends ParentLikeNode {
|
|
|
56
56
|
name: string;
|
|
57
57
|
attributes: AttributeNode[];
|
|
58
58
|
}
|
|
59
|
-
export
|
|
59
|
+
export type TagLikeNode = ElementNode | FragmentNode | ComponentNode | CustomElementNode;
|
|
60
60
|
export interface DoctypeNode extends ValueNode {
|
|
61
61
|
type: 'doctype';
|
|
62
62
|
}
|
package/shared/types.d.ts
CHANGED
|
@@ -46,8 +46,8 @@ export interface TransformOptions {
|
|
|
46
46
|
resolvePath?: (specifier: string) => Promise<string>;
|
|
47
47
|
preprocessStyle?: (content: string, attrs: Record<string, string>) => null | Promise<PreprocessorResult | PreprocessorError>;
|
|
48
48
|
}
|
|
49
|
-
export
|
|
50
|
-
export
|
|
49
|
+
export type ConvertToTSXOptions = Pick<TransformOptions, 'filename' | 'normalizedFilename'>;
|
|
50
|
+
export type HoistedScript = {
|
|
51
51
|
type: string;
|
|
52
52
|
} & ({
|
|
53
53
|
type: 'external';
|
package/sync.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './node/sync.cjs';
|