2.10.3 • Published 3 months ago

@astrojs/compiler v2.10.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

Astro Compiler

Astro’s Go + WASM compiler.

Install

npm install @astrojs/compiler

Usage

Transform .astro to valid TypeScript

The Astro compiler can convert .astro syntax to a TypeScript Module whose default export generates HTML.

Some notes...

  • TypeScript is valid .astro syntax! The output code may need an additional post-processing step to generate valid JavaScript.
  • .astro files rely on a server implementation exposed as astro/runtime/server/index.js 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.
import { transform, type TransformResult } from "@astrojs/compiler";

const result = await transform(source, {
  filename: "/Users/astro/Code/project/src/pages/index.astro",
  sourcemap: "both",
  internalURL: "astro/runtime/server/index.js",
});

Parse .astro and return an AST

The Astro compiler can emit an AST using the parse method.

Some notes...

  • Position data is currently incomplete and in some cases incorrect. We're working on it!
  • A TextNode can represent both HTML text and JavaScript/TypeScript source code.
  • 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.
import { parse } from "@astrojs/compiler";
import { walk, is } from "@astrojs/compiler/utils";

const result = await parse(source, {
  position: false, // defaults to `true`
});

walk(result.ast, (node) => {
  // `tag` nodes are `element` | `custom-element` | `component`
  if (is.tag(node)) {
    console.log(node.name);
  }
});

Develop

VSCode / CodeSpaces

A devcontainer configuration is available for use with VSCode's Remote Development extension pack and GitHub CodeSpaces.

Contributing

CONTRIBUTING.md

2.10.1

4 months ago

2.10.2

3 months ago

2.10.0

4 months ago

2.10.3

3 months ago

2.9.0

4 months ago

2.8.1

5 months ago

2.9.2

4 months ago

2.9.1

4 months ago

2.8.2

4 months ago

2.8.0

7 months ago

2.7.1

8 months ago

2.7.0

9 months ago

2.6.0

9 months ago

2.5.3

9 months ago

2.5.2

10 months ago

2.5.1

10 months ago

2.5.0

10 months ago

2.4.2

10 months ago

2.4.1

10 months ago

2.4.0

11 months ago

2.3.4

11 months ago

2.3.3

11 months ago

2.3.0

1 year ago

2.3.2

1 year ago

2.3.1

1 year ago

2.2.2

1 year ago

1.6.3

1 year ago

1.6.2

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.7.0-pre.0

1 year ago

1.7.0-pre.1

1 year ago

1.7.0-pre.2

1 year ago

1.5.5

1 year ago

1.5.4

1 year ago

1.5.3

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

1.5.7

1 year ago

1.5.6

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.6.0-pre.9

1 year ago

1.6.0-pre.6

1 year ago

1.6.0-pre.5

1 year ago

1.6.0-pre.8

1 year ago

1.6.0-pre.7

1 year ago

1.6.0-pre.4

1 year ago

1.8.2

1 year ago

1.8.1

1 year ago

1.8.0

1 year ago

1.6.0-pre.10

1 year ago

1.6.0-pre.11

1 year ago

1.6.0-pre.12

1 year ago

1.6.0-pre.13

1 year ago

1.7.0

1 year ago

1.5.2

1 year ago

1.6.0-pre.2

1 year ago

1.6.0-pre.1

1 year ago

1.6.0-pre.3

1 year ago

1.6.0-pre.0

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.2

2 years ago

1.0.2

2 years ago

0.32.0

2 years ago

0.33.0

2 years ago

0.31.4

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.29.9

2 years ago

0.29.0

2 years ago

0.29.8

2 years ago

0.29.7

2 years ago

0.29.6

2 years ago

0.29.5

2 years ago

0.29.4

2 years ago

0.29.3

2 years ago

0.29.2

2 years ago

0.29.1

2 years ago

0.29.18

2 years ago

0.29.19

2 years ago

0.29.12

2 years ago

0.29.13

2 years ago

0.29.10

2 years ago

0.29.11

2 years ago

0.29.16

2 years ago

0.29.17

2 years ago

0.29.14

2 years ago

0.29.15

2 years ago

0.30.1

2 years ago

0.30.0

2 years ago

0.27.2

2 years ago

0.27.1

2 years ago

0.31.3

2 years ago

0.31.2

2 years ago

0.31.1

2 years ago

0.31.0

2 years ago

0.28.1

2 years ago

0.28.0

2 years ago

0.25.2

2 years ago

0.25.1

2 years ago

0.25.0

2 years ago

0.26.1

2 years ago

0.26.0

2 years ago

0.27.0

2 years ago

0.23.5

2 years ago

0.23.4

2 years ago

0.24.0

2 years ago

0.19.0-pre.0

2 years ago

0.20.0

2 years ago

0.17.0

2 years ago

0.17.1

2 years ago

0.15.2-pre.0

2 years ago

0.21.0

2 years ago

0.18.1

2 years ago

0.18.2

2 years ago

0.18.0

2 years ago

0.17.0-pre.1

2 years ago

0.17.0-pre.0

2 years ago

0.22.1

2 years ago

0.22.0

2 years ago

0.17.0-pre.4

2 years ago

0.17.0-pre.3

2 years ago

0.17.0-pre.2

2 years ago

0.19.0

2 years ago

0.15.0

2 years ago

0.15.1

2 years ago

0.15.2

2 years ago

0.23.3

2 years ago

0.23.2

2 years ago

0.23.1

2 years ago

0.23.0

2 years ago

0.20.0-next.1

2 years ago

0.20.0-next.0

2 years ago

0.20.0-next.2

2 years ago

0.16.0

2 years ago

0.16.1

2 years ago

0.14.3

2 years ago

0.13.0

3 years ago

0.13.1

3 years ago

0.13.2

3 years ago

0.12.0-next.9

3 years ago

0.14.0

3 years ago

0.14.1

3 years ago

0.14.2

3 years ago

0.12.0

3 years ago

0.12.1

3 years ago

0.12.0-next.8

3 years ago

0.12.0-next.7

3 years ago

0.12.0-next.2

3 years ago

0.12.0-next.1

3 years ago

0.12.0-next.6

3 years ago

0.12.0-next.5

3 years ago

0.12.0-next.4

3 years ago

0.12.0-next.3

3 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.7.4

3 years ago

0.7.3

3 years ago

0.7.0

3 years ago

0.8.4-pre.0

3 years ago

0.8.4-pre.1

3 years ago

0.12.0-next.0

3 years ago

0.8.4-pre.2

3 years ago

0.8.4-pre.3

3 years ago

0.8.4-pre.4

3 years ago

0.8.4-pre.5

3 years ago

0.8.4-pre.6

3 years ago

0.9.2-pre.0

3 years ago

0.8.4-pre.7

3 years ago

0.10.1

3 years ago

0.10.2

3 years ago

0.10.0

3 years ago

0.8.4-pre.8

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.8.2

3 years ago

0.11.0

3 years ago

0.11.1

3 years ago

0.11.2

3 years ago

0.11.3

3 years ago

0.11.4

3 years ago

0.11.0-next.0

3 years ago

0.9.0

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.8.3-pre.0

3 years ago

0.6.2

3 years ago

0.6.1

3 years ago

0.6.0

3 years ago

0.2.27

3 years ago

0.2.26

3 years ago

0.3.0

3 years ago

0.5.4

3 years ago

0.3.6

3 years ago

0.5.3

3 years ago

0.3.5

3 years ago

0.5.6

3 years ago

0.3.8

3 years ago

0.5.5

3 years ago

0.3.7

3 years ago

0.5.0

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.5.2

3 years ago

0.3.4

3 years ago

0.5.1

3 years ago

0.3.3

3 years ago

0.5.7

3 years ago

0.3.9

3 years ago

0.4.0

3 years ago

0.2.25

3 years ago

0.2.24

3 years ago

0.2.23

3 years ago

0.2.22

3 years ago

0.2.21

3 years ago

0.2.20

3 years ago

0.2.19

3 years ago

0.2.18

3 years ago

0.2.17

3 years ago

0.2.16

3 years ago

0.2.16-rc.0

3 years ago

0.2.16-rc.1

3 years ago

0.2.15

3 years ago

0.2.14

3 years ago

0.2.13

3 years ago

0.2.12

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.1.10

3 years ago

0.1.11

3 years ago

0.1.12

3 years ago

0.1.13

3 years ago

0.1.14

3 years ago

0.1.15

3 years ago

0.1.0

3 years ago

0.2.1

3 years ago

0.1.2

3 years ago

0.2.0

3 years ago

0.1.1

3 years ago

0.1.8

3 years ago

0.1.9

3 years ago

0.2.3

3 years ago

0.1.4

3 years ago

0.2.2

3 years ago

0.1.0-canary.47

3 years ago

0.2.5

3 years ago

0.1.6

3 years ago

0.2.4

3 years ago

0.1.5

3 years ago

0.1.0-canary.46

3 years ago

0.1.0-canary.45

3 years ago

0.1.0-canary.37

3 years ago

0.1.0-canary.36

3 years ago

0.1.0-canary.35

3 years ago

0.1.0-canary.34

3 years ago

0.1.0-canary.31

3 years ago

0.1.0-canary.32

3 years ago

0.1.0-canary.33

3 years ago

0.1.0-canary.30

3 years ago

0.1.0-canary.29

3 years ago

0.1.0-canary.28

3 years ago

0.1.0-canary.25

3 years ago

0.1.0-canary.26

3 years ago

0.1.0-canary.27

3 years ago

0.1.0-canary.24

3 years ago

0.1.0-canary.23

3 years ago

0.1.0-canary.3

3 years ago

0.1.0-canary.2

3 years ago

0.1.0-canary.1

3 years ago

0.1.0-canary.0

3 years ago