@astrojs/compiler 0.11.0-next.0 → 0.11.3
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 +40 -5
- package/README.md +1 -34
- package/astro.wasm +0 -0
- package/browser/index.d.ts +0 -1
- package/browser/index.js +16 -25
- package/browser/wasm_exec.d.ts +29 -1
- package/browser/wasm_exec.js +249 -192
- package/node/index.d.ts +0 -1
- package/node/index.js +14 -19
- package/node/wasm_exec.d.ts +29 -1
- package/node/wasm_exec.js +270 -207
- package/package.json +2 -7
- package/shared/types.d.ts +0 -12
- package/shared/types.js +1 -1
- package/browser/utils.d.ts +0 -20
- package/browser/utils.js +0 -46
- package/node/utils.d.ts +0 -20
- package/node/utils.js +0 -46
- package/shared/ast.d.ts +0 -71
- package/shared/ast.js +0 -1
- package/utils.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,48 @@
|
|
|
1
1
|
# @astrojs/compiler
|
|
2
2
|
|
|
3
|
-
## 0.11.
|
|
3
|
+
## 0.11.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- dcf15bf: Fixes bug causing a crash when using Astro.resolve on a hoisted script
|
|
8
|
+
|
|
9
|
+
## 0.11.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 41cc6ef: Fix memory issue caused by duplicate WASM instantiations
|
|
14
|
+
|
|
15
|
+
## 0.11.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 4039682: Fixes hoist script tracking when passed a variable
|
|
20
|
+
|
|
21
|
+
## 0.11.0
|
|
22
|
+
|
|
23
|
+
### Minor Changes
|
|
24
|
+
|
|
25
|
+
- f5d4006: Switch from TinyGo to Go's built-in WASM output. While this is an unfortunate size increase for our `.wasm` file, it should also be significantly more stable and cut down on hard-to-reproduce bugs.
|
|
26
|
+
|
|
27
|
+
Please see https://github.com/withastro/compiler/pull/291 for more details.
|
|
28
|
+
|
|
29
|
+
## 0.11.0-next--wasm.0
|
|
4
30
|
|
|
5
31
|
### Minor Changes
|
|
6
32
|
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
33
|
+
- 9212ccc: Switch from TinyGo to Go's built-in WASM output. While this is an unfortunate size increase for our `WASM` file, it should also be significantly more stable and cut down on hard-to-reproduce bugs.
|
|
34
|
+
|
|
35
|
+
Please see https://github.com/withastro/compiler/pull/291 for more details.
|
|
36
|
+
|
|
37
|
+
## 0.10.2
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- 7f7c65c: Fix conditional rendering for special elements like `iframe` and `noscript`
|
|
42
|
+
- 9d789c9: Fix handling of nested template literals inside of expressions
|
|
43
|
+
- 5fa9e53: Fix handling of special characters inside of expressions
|
|
44
|
+
- 8aaa956: Formalize support for magic `data-astro-raw` attribute with new, official `is:raw` directive
|
|
45
|
+
- c698350: Improve MathML support. `{}` inside of `<math>` is now treated as raw text rather than an expression construct.
|
|
11
46
|
|
|
12
47
|
## 0.10.1
|
|
13
48
|
|
package/README.md
CHANGED
|
@@ -12,15 +12,7 @@ npm install @astrojs/compiler
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
_Note:
|
|
16
|
-
|
|
17
|
-
#### Transform `.astro` to valid TypeScript
|
|
18
|
-
|
|
19
|
-
The Astro compiler can convert `.astro` syntax to a TypeScript Module whose default export generates HTML.
|
|
20
|
-
|
|
21
|
-
**Some notes**...
|
|
22
|
-
- TypeScript is valid `.astro` syntax! The output code may need an additional post-processing step to generate valid JavaScript.
|
|
23
|
-
- `.astro` files rely on a server implementation exposed as `astro/internal` in the Node ecosystem. Other runtimes currently need to bring their own rendering implementation and reference it via `internalURL`. This is a pain point we're looking into fixing.
|
|
15
|
+
_Note: API will change before 1.0! Use at your own discretion._
|
|
24
16
|
|
|
25
17
|
```js
|
|
26
18
|
import { transform } from '@astrojs/compiler';
|
|
@@ -33,31 +25,6 @@ const result = await transform(source, {
|
|
|
33
25
|
});
|
|
34
26
|
```
|
|
35
27
|
|
|
36
|
-
#### Parse `.astro` and return an AST
|
|
37
|
-
|
|
38
|
-
The Astro compiler can emit an AST using the `parse` method.
|
|
39
|
-
|
|
40
|
-
**Some notes**...
|
|
41
|
-
- Position data is currently incomplete and in some cases incorrect. We're working on it!
|
|
42
|
-
- A `TextNode` can represent both HTML `text` and JavaScript/TypeScript source code.
|
|
43
|
-
- The `@astrojs/compiler/utils` entrypoint exposes a `walk` function that can be used to traverse the AST. It also exposes the `is` helper which can be used as guards to derive the proper types for each `node`.
|
|
44
|
-
|
|
45
|
-
```js
|
|
46
|
-
import { parse } from '@astrojs/compiler';
|
|
47
|
-
import { walk, is } from '@astrojs/compiler/utils';
|
|
48
|
-
|
|
49
|
-
const result = await parse(source, {
|
|
50
|
-
position: false, // defaults to `true`
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
walk(result.ast, (node) => {
|
|
54
|
-
// `tag` nodes are `element` | `custom-element` | `component`
|
|
55
|
-
if (is.tag(node)) {
|
|
56
|
-
console.log(node.name);
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
```
|
|
60
|
-
|
|
61
28
|
## Contributing
|
|
62
29
|
|
|
63
30
|
[CONTRIBUTING.md](./CONTRIBUTING.md)
|
package/astro.wasm
CHANGED
|
Binary file
|
package/browser/index.d.ts
CHANGED
package/browser/index.js
CHANGED
|
@@ -2,31 +2,29 @@ import Go from './wasm_exec.js';
|
|
|
2
2
|
export const transform = (input, options) => {
|
|
3
3
|
return ensureServiceIsRunning().transform(input, options);
|
|
4
4
|
};
|
|
5
|
-
export const parse = (input, options) => {
|
|
6
|
-
return ensureServiceIsRunning().parse(input, options);
|
|
7
|
-
};
|
|
8
5
|
let initializePromise;
|
|
9
6
|
let longLivedService;
|
|
10
|
-
export const initialize = (options) => {
|
|
7
|
+
export const initialize = async (options) => {
|
|
11
8
|
let wasmURL = options.wasmURL;
|
|
12
9
|
if (!wasmURL)
|
|
13
10
|
throw new Error('Must provide the "wasmURL" option');
|
|
14
11
|
wasmURL += '';
|
|
15
|
-
if (initializePromise)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
if (!initializePromise) {
|
|
13
|
+
initializePromise = startRunningService(wasmURL).catch((err) => {
|
|
14
|
+
// Let the caller try again if this fails.
|
|
15
|
+
initializePromise = void 0;
|
|
16
|
+
// But still, throw the error back up the caller.
|
|
17
|
+
throw err;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
longLivedService = longLivedService || (await initializePromise);
|
|
23
21
|
};
|
|
24
22
|
let ensureServiceIsRunning = () => {
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
if (
|
|
23
|
+
if (!initializePromise)
|
|
24
|
+
throw new Error('You need to call "initialize" before calling this');
|
|
25
|
+
if (!longLivedService)
|
|
28
26
|
throw new Error('You need to wait for the promise returned from "initialize" to be resolved before calling this');
|
|
29
|
-
|
|
27
|
+
return longLivedService;
|
|
30
28
|
};
|
|
31
29
|
const instantiateWASM = async (wasmURL, importObject) => {
|
|
32
30
|
let response = undefined;
|
|
@@ -46,15 +44,8 @@ const startRunningService = async (wasmURL) => {
|
|
|
46
44
|
const go = new Go();
|
|
47
45
|
const wasm = await instantiateWASM(wasmURL, go.importObject);
|
|
48
46
|
go.run(wasm.instance);
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
for (const key of apiKeys.values()) {
|
|
52
|
-
const globalKey = `__astro_${key}`;
|
|
53
|
-
service[key] = globalThis[globalKey];
|
|
54
|
-
delete globalThis[globalKey];
|
|
55
|
-
}
|
|
56
|
-
longLivedService = {
|
|
47
|
+
const service = globalThis['@astrojs/compiler'];
|
|
48
|
+
return {
|
|
57
49
|
transform: (input, options) => new Promise((resolve) => resolve(service.transform(input, options || {}))),
|
|
58
|
-
parse: (input, options) => new Promise((resolve) => resolve(service.parse(input, options || {}))).then((result) => ({ ...result, ast: JSON.parse(result.ast) })),
|
|
59
50
|
};
|
|
60
51
|
};
|
package/browser/wasm_exec.d.ts
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
export default class Go {
|
|
2
|
-
importObject:
|
|
2
|
+
importObject: {
|
|
3
|
+
go: {
|
|
4
|
+
'runtime.wasmExit': (sp: any) => void;
|
|
5
|
+
'runtime.wasmWrite': (sp: any) => void;
|
|
6
|
+
'runtime.resetMemoryDataView': (sp: any) => void;
|
|
7
|
+
'runtime.nanotime1': (sp: any) => void;
|
|
8
|
+
'runtime.walltime': (sp: any) => void;
|
|
9
|
+
'runtime.scheduleTimeoutEvent': (sp: any) => void;
|
|
10
|
+
'runtime.clearTimeoutEvent': (sp: any) => void;
|
|
11
|
+
'runtime.getRandomData': (sp: any) => void;
|
|
12
|
+
'syscall/js.finalizeRef': (sp: any) => void;
|
|
13
|
+
'syscall/js.stringVal': (sp: any) => void;
|
|
14
|
+
'syscall/js.valueGet': (sp: any) => void;
|
|
15
|
+
'syscall/js.valueSet': (sp: any) => void;
|
|
16
|
+
'syscall/js.valueDelete': (sp: any) => void;
|
|
17
|
+
'syscall/js.valueIndex': (sp: any) => void;
|
|
18
|
+
'syscall/js.valueSetIndex': (sp: any) => void;
|
|
19
|
+
'syscall/js.valueCall': (sp: any) => void;
|
|
20
|
+
'syscall/js.valueInvoke': (sp: any) => void;
|
|
21
|
+
'syscall/js.valueNew': (sp: any) => void;
|
|
22
|
+
'syscall/js.valueLength': (sp: any) => void;
|
|
23
|
+
'syscall/js.valuePrepareString': (sp: any) => void;
|
|
24
|
+
'syscall/js.valueLoadString': (sp: any) => void;
|
|
25
|
+
'syscall/js.valueInstanceOf': (sp: any) => void;
|
|
26
|
+
'syscall/js.copyBytesToGo': (sp: any) => void;
|
|
27
|
+
'syscall/js.copyBytesToJS': (sp: any) => void;
|
|
28
|
+
debug: (value: any) => void;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
3
31
|
constructor();
|
|
4
32
|
run(instance: any): Promise<void>;
|
|
5
33
|
private _resume;
|