Skip to content

Commit

Permalink
📃 docs: Add docs for transpile
Browse files Browse the repository at this point in the history
  • Loading branch information
caoccao committed May 13, 2024
1 parent 4665568 commit 21a06c6
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* Minify
* Multiple Target ES Version
* Source Map
* Transpile
* [Transpile](docs/transpile.md)
* TS → JS
* JSX → JS
* TSX → JS
Expand Down
4 changes: 2 additions & 2 deletions docs/transform.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Transform

`transform()` transforms the code, but does not transform the code.
`transform()` transforms the code, but does not transpile the code.

## Features

Expand All @@ -14,7 +14,7 @@

## Options

The following options are shared with `parse().
The following options are shared with [Parse](parse.md).

* Media Type
* Parse Mode
Expand Down
87 changes: 87 additions & 0 deletions docs/transpile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Transpile

`transpile()` transpiles the code from various languages into JavaScript.

## Features

* Custom JSX factory
* Custom JSX fragment factory
* Emit metadata
* Generate the source map
* Inline source code in the source map
* Keep the comments
* Precompile JSX
* Update the AST via plugins on-the-fly

## Options

The following options are shared with [Parse](parse.md).

* Media Type
* Parse Mode
* Plugin Host
* Specifier

The following options are shared with [Transform](transform.md).

* Inline Sources
* Keep Comments
* Source Map

### Emit Metadata

It determines when emit a legacy decorator, whether also emit experimental decorator meta data. Defaults to `false`.

### Imports Not Used As Values

What to do with import statements that only import types i.e. whether to remove them (`Remove`), keep them as side-effect imports (`Preserve`) or error (`Error`). Defaults to `Remove`. The values are as follows:

| Value |
|----------|
| Remove |
| Preserve |
| Error |

### JSX Automatic

It determines whether the program should use an implicit JSX import source/the `new` JSX transforms. Defaults to `false`.

### JSX Development

If JSX is automatic, if it is in development mode, meaning that it should import `jsx-dev-runtime` and transform JSX using `jsxDEV` import from the JSX import source as well as provide additional debug information to the JSX factory.

### JSX Factory

When transforming JSX, what value should be used for the JSX factory. Defaults to `React.createElement`.

### JSX Fragment Factory

When transforming JSX, what value should be used for the JSX fragment factory. Defaults to `React.Fragment`.

### JSX Import Source

The string module specifier to implicitly import JSX factories from when transpiling JSX.

### Precompile JSX

Should JSX be precompiled into static strings that need to be concatenated with dynamic content. Defaults to `false`, mutually exclusive with `transform_jsx`.

### Precompile JSX Skip Elements

List of elements that should not be precompiled when the JSX precompile transform is used.

### Transform JSX

Should JSX be transformed. Defaults to `true`.

### Use Decorators Proposal

TC39 Decorators Proposal - https://github.com/tc39/proposal-decorators

### Use TS Decorators

TypeScript experimental decorators.

### Var Decl Imports

Should import declarations be transformed to variable declarations using a dynamic import. This is useful for import and export declaration support in script contexts such as the Deno REPL. Defaults to `false`.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Swc4jTranspileOptions extends Swc4jParseOptions {
*/
public static final String DEFAULT_JSX_FRAGMENT_FACTORY = "React.Fragment";
/**
* When emitting a legacy decorator, also emit experimental decorator meta data.
* When emitting a legacy decorator, whether also emit experimental decorator meta data.
* Defaults to `false`.
*
* @since 0.1.0
Expand All @@ -71,7 +71,8 @@ public class Swc4jTranspileOptions extends Swc4jParseOptions {
*/
protected boolean inlineSources;
/**
* `true` if the program should use an implicit JSX import source/the "new" JSX transforms.
* `true` if the program should use an implicit JSX import source/the `new` JSX transforms.
* Defaults to `false`.
*
* @since 0.1.0
*/
Expand Down

0 comments on commit 21a06c6

Please sign in to comment.