@astrojs/compiler 1.4.1 → 1.5.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/{astro.wasm → dist/astro.wasm} +0 -0
- package/dist/browser/index.cjs +2 -0
- package/dist/browser/index.d.ts +11 -0
- package/dist/browser/index.js +1 -0
- package/dist/browser/utils.cjs +3 -0
- package/{browser → dist/browser}/utils.d.ts +10 -7
- package/dist/browser/utils.js +3 -0
- package/dist/browser/wasm_exec.cjs +2 -0
- package/{node → dist/browser}/wasm_exec.d.ts +3 -1
- package/dist/browser/wasm_exec.js +1 -0
- package/dist/chunk-GFDH6LQW.js +1 -0
- package/dist/chunk-XZNZIE5X.js +2 -0
- package/dist/node/index.cjs +1 -0
- package/dist/node/index.d.ts +12 -0
- package/dist/node/index.js +1 -0
- package/dist/node/sync.cjs +1 -0
- package/dist/node/sync.d.ts +16 -0
- package/dist/node/sync.js +1 -0
- package/dist/node/utils.cjs +3 -0
- package/{node → dist/node}/utils.d.ts +10 -7
- package/dist/node/utils.js +3 -0
- package/dist/node/wasm_exec.cjs +1 -0
- package/{browser → dist/node}/wasm_exec.d.ts +3 -1
- package/dist/node/wasm_exec.js +1 -0
- package/dist/shared/ast.cjs +1 -0
- package/dist/shared/ast.d.ts +73 -0
- package/dist/shared/ast.js +0 -0
- package/dist/shared/diagnostics.cjs +1 -0
- package/{shared → dist/shared}/diagnostics.d.ts +3 -1
- package/dist/shared/diagnostics.js +1 -0
- package/dist/shared/types.cjs +1 -0
- package/{shared → dist/shared}/types.d.ts +26 -24
- package/dist/shared/types.js +1 -0
- package/package.json +29 -15
- package/sync.d.ts +1 -1
- package/types.d.ts +1 -1
- package/utils.d.ts +1 -1
- package/CHANGELOG.md +0 -1277
- package/browser/index.d.ts +0 -6
- package/browser/index.js +0 -67
- package/browser/utils.js +0 -116
- package/browser/wasm_exec.js +0 -559
- package/node/index.d.ts +0 -7
- package/node/index.js +0 -75
- package/node/sync.cjs +0 -542
- package/node/sync.cts +0 -72
- package/node/sync.d.cts +0 -12
- package/node/utils.js +0 -116
- package/node/wasm_exec.js +0 -451
- package/shared/ast.d.ts +0 -71
- package/shared/ast.js +0 -1
- package/shared/diagnostics.js +0 -1
- package/shared/types.js +0 -10
package/browser/index.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type * as types from '../shared/types';
|
|
2
|
-
export declare const transform: typeof types.transform;
|
|
3
|
-
export declare const parse: typeof types.parse;
|
|
4
|
-
export declare const convertToTSX: typeof types.convertToTSX;
|
|
5
|
-
export declare const teardown: typeof types.teardown;
|
|
6
|
-
export declare const initialize: typeof types.initialize;
|
package/browser/index.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import Go from './wasm_exec.js';
|
|
2
|
-
export const transform = (input, options) => {
|
|
3
|
-
return ensureServiceIsRunning().transform(input, options);
|
|
4
|
-
};
|
|
5
|
-
export const parse = (input, options) => {
|
|
6
|
-
return ensureServiceIsRunning().parse(input, options);
|
|
7
|
-
};
|
|
8
|
-
export const convertToTSX = (input, options) => {
|
|
9
|
-
return ensureServiceIsRunning().convertToTSX(input, options);
|
|
10
|
-
};
|
|
11
|
-
let initializePromise;
|
|
12
|
-
let longLivedService;
|
|
13
|
-
export const teardown = () => {
|
|
14
|
-
initializePromise = undefined;
|
|
15
|
-
longLivedService = undefined;
|
|
16
|
-
globalThis['@astrojs/compiler'] = undefined;
|
|
17
|
-
};
|
|
18
|
-
export const initialize = async (options) => {
|
|
19
|
-
let wasmURL = options.wasmURL;
|
|
20
|
-
if (!wasmURL)
|
|
21
|
-
throw new Error('Must provide the "wasmURL" option');
|
|
22
|
-
wasmURL += '';
|
|
23
|
-
if (!initializePromise) {
|
|
24
|
-
initializePromise = startRunningService(wasmURL).catch((err) => {
|
|
25
|
-
// Let the caller try again if this fails.
|
|
26
|
-
initializePromise = void 0;
|
|
27
|
-
// But still, throw the error back up the caller.
|
|
28
|
-
throw err;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
longLivedService = longLivedService || (await initializePromise);
|
|
32
|
-
};
|
|
33
|
-
let ensureServiceIsRunning = () => {
|
|
34
|
-
if (!initializePromise)
|
|
35
|
-
throw new Error('You need to call "initialize" before calling this');
|
|
36
|
-
if (!longLivedService)
|
|
37
|
-
throw new Error('You need to wait for the promise returned from "initialize" to be resolved before calling this');
|
|
38
|
-
return longLivedService;
|
|
39
|
-
};
|
|
40
|
-
const instantiateWASM = async (wasmURL, importObject) => {
|
|
41
|
-
let response = undefined;
|
|
42
|
-
if (WebAssembly.instantiateStreaming) {
|
|
43
|
-
response = await WebAssembly.instantiateStreaming(fetch(wasmURL), importObject);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
const fetchAndInstantiateTask = async () => {
|
|
47
|
-
const wasmArrayBuffer = await fetch(wasmURL).then((res) => res.arrayBuffer());
|
|
48
|
-
return WebAssembly.instantiate(wasmArrayBuffer, importObject);
|
|
49
|
-
};
|
|
50
|
-
response = await fetchAndInstantiateTask();
|
|
51
|
-
}
|
|
52
|
-
return response;
|
|
53
|
-
};
|
|
54
|
-
const startRunningService = async (wasmURL) => {
|
|
55
|
-
const go = new Go();
|
|
56
|
-
const wasm = await instantiateWASM(wasmURL, go.importObject);
|
|
57
|
-
go.run(wasm.instance);
|
|
58
|
-
const service = globalThis['@astrojs/compiler'];
|
|
59
|
-
return {
|
|
60
|
-
transform: (input, options) => new Promise((resolve) => resolve(service.transform(input, options || {}))),
|
|
61
|
-
convertToTSX: (input, options) => new Promise((resolve) => resolve(service.convertToTSX(input, options || {}))).then((result) => ({
|
|
62
|
-
...result,
|
|
63
|
-
map: JSON.parse(result.map),
|
|
64
|
-
})),
|
|
65
|
-
parse: (input, options) => new Promise((resolve) => resolve(service.parse(input, options || {}))).then((result) => ({ ...result, ast: JSON.parse(result.ast) })),
|
|
66
|
-
};
|
|
67
|
-
};
|
package/browser/utils.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
function guard(type) {
|
|
2
|
-
return (node) => node.type === type;
|
|
3
|
-
}
|
|
4
|
-
export const is = {
|
|
5
|
-
parent(node) {
|
|
6
|
-
return Array.isArray(node.children);
|
|
7
|
-
},
|
|
8
|
-
literal(node) {
|
|
9
|
-
return typeof node.value === 'string';
|
|
10
|
-
},
|
|
11
|
-
tag(node) {
|
|
12
|
-
return node.type === 'element' || node.type === 'custom-element' || node.type === 'component' || node.type === 'fragment';
|
|
13
|
-
},
|
|
14
|
-
whitespace(node) {
|
|
15
|
-
return node.type === 'text' && node.value.trim().length === 0;
|
|
16
|
-
},
|
|
17
|
-
root: guard('root'),
|
|
18
|
-
element: guard('element'),
|
|
19
|
-
customElement: guard('custom-element'),
|
|
20
|
-
component: guard('component'),
|
|
21
|
-
fragment: guard('fragment'),
|
|
22
|
-
expression: guard('expression'),
|
|
23
|
-
text: guard('text'),
|
|
24
|
-
doctype: guard('doctype'),
|
|
25
|
-
comment: guard('comment'),
|
|
26
|
-
frontmatter: guard('frontmatter'),
|
|
27
|
-
};
|
|
28
|
-
class Walker {
|
|
29
|
-
constructor(callback) {
|
|
30
|
-
this.callback = callback;
|
|
31
|
-
}
|
|
32
|
-
async visit(node, parent, index) {
|
|
33
|
-
await this.callback(node, parent, index);
|
|
34
|
-
if (is.parent(node)) {
|
|
35
|
-
let promises = [];
|
|
36
|
-
for (let i = 0; i < node.children.length; i++) {
|
|
37
|
-
const child = node.children[i];
|
|
38
|
-
promises.push(this.callback(child, node, i));
|
|
39
|
-
}
|
|
40
|
-
await Promise.all(promises);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export function walk(node, callback) {
|
|
45
|
-
const walker = new Walker(callback);
|
|
46
|
-
walker.visit(node);
|
|
47
|
-
}
|
|
48
|
-
function serializeAttributes(node) {
|
|
49
|
-
let output = '';
|
|
50
|
-
for (const attr of node.attributes) {
|
|
51
|
-
output += ' ';
|
|
52
|
-
switch (attr.kind) {
|
|
53
|
-
case 'empty': {
|
|
54
|
-
output += `${attr.name}`;
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
case 'expression': {
|
|
58
|
-
output += `${attr.name}={${attr.value}}`;
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
case 'quoted': {
|
|
62
|
-
output += `${attr.name}="${attr.value}"`;
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
case 'template-literal': {
|
|
66
|
-
output += `${attr.name}=\`${attr.value}\``;
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
case 'shorthand': {
|
|
70
|
-
output += `{${attr.name}}`;
|
|
71
|
-
break;
|
|
72
|
-
}
|
|
73
|
-
case 'spread': {
|
|
74
|
-
output += `{...${attr.value}}`;
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return output;
|
|
80
|
-
}
|
|
81
|
-
export function serialize(root, opts = { selfClose: true }) {
|
|
82
|
-
let output = '';
|
|
83
|
-
function visitor(node) {
|
|
84
|
-
if (is.root(node)) {
|
|
85
|
-
node.children.forEach((child) => visitor(child));
|
|
86
|
-
}
|
|
87
|
-
else if (is.frontmatter(node)) {
|
|
88
|
-
output += `---${node.value}---\n\n`;
|
|
89
|
-
}
|
|
90
|
-
else if (is.comment(node)) {
|
|
91
|
-
output += `<!--${node.value}-->`;
|
|
92
|
-
}
|
|
93
|
-
else if (is.expression(node)) {
|
|
94
|
-
output += `{`;
|
|
95
|
-
node.children.forEach((child) => visitor(child));
|
|
96
|
-
output += `}`;
|
|
97
|
-
}
|
|
98
|
-
else if (is.literal(node)) {
|
|
99
|
-
output += node.value;
|
|
100
|
-
}
|
|
101
|
-
else if (is.tag(node)) {
|
|
102
|
-
output += `<${node.name}`;
|
|
103
|
-
output += serializeAttributes(node);
|
|
104
|
-
if (node.children.length == 0 && opts.selfClose) {
|
|
105
|
-
output += ` />`;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
output += '>';
|
|
109
|
-
node.children.forEach((child) => visitor(child));
|
|
110
|
-
output += `</${node.name}>`;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
visitor(root);
|
|
115
|
-
return output;
|
|
116
|
-
}
|