Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: document dts and disallowAmbiguousJSXLike options #2676

Merged
merged 2 commits into from Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/plugin-syntax-typescript.md
Expand Up @@ -38,6 +38,22 @@ require("@babel/core").transformSync("code", {

## Options

### `disallowAmbiguousJSXLike`

`boolean`, defaults to `false`

Added in: `v7.16.0`

Even when JSX parsing is not enabled, this option disallows using syntax that would be ambiguous with JSX (`<X> y` type assertions and `<X>() => {}` type arguments). It matches the `tsc` behavior when parsing `.mts` and `.mjs` files.

### `dts`

`boolean`, defaults to `false`

Added in: `v7.14.0`
oceandrama marked this conversation as resolved.
Show resolved Hide resolved
oceandrama marked this conversation as resolved.
Show resolved Hide resolved

This option will enable parsing within a TypeScript ambient context, where certain syntax have different rules (like `.d.ts` files and inside `declare module` blocks). Please see https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html and https://basarat.gitbook.io/typescript/type-system/intro for more information about ambient contexts.
oceandrama marked this conversation as resolved.
Show resolved Hide resolved

### `isTSX`

`boolean`, defaults to `false`.
Expand Down
16 changes: 13 additions & 3 deletions docs/plugin-transform-typescript.md
Expand Up @@ -95,6 +95,14 @@ Added in: `v7.16.0`

Even when JSX parsing is not enabled, this option disallows using syntax that would be ambiguous with JSX (`<X> y` type assertions and `<X>() => {}` type arguments). It matches the `tsc` behavior when parsing `.mts` and `.mjs` files.

### `dts`

`boolean`, defaults to `false`

Added in: `v7.14.0`
oceandrama marked this conversation as resolved.
Show resolved Hide resolved

This option will enable parsing within a TypeScript ambient context, where certain syntax have different rules (like `.d.ts` files and inside `declare module` blocks). Please see https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html and https://basarat.gitbook.io/typescript/type-system/intro for more information about ambient contexts.
oceandrama marked this conversation as resolved.
Show resolved Hide resolved

### `isTSX`

`boolean`, defaults to `false`
Expand Down Expand Up @@ -137,18 +145,19 @@ class A {
Added in: `v7.15.0`

When set to `true`, Babel will inline enum values rather than using the usual `enum` output:

```typescript
// Input
const enum Animals {
Fish
Fish,
}
console.log(Animals.Fish);

// Default output
var Animals;

(function (Animals) {
Animals[Animals["Fish"] = 0] = "Fish";
(function(Animals) {
Animals[(Animals["Fish"] = 0)] = "Fish";
JLHwung marked this conversation as resolved.
Show resolved Hide resolved
})(Animals || (Animals = {}));

console.log(Animals.Fish);
Expand All @@ -160,6 +169,7 @@ console.log(0);
This option differs from TypeScript's `--isolatedModules` behavior, which ignores the `const` modifier and compiles them as normal enums, and aligns Babel's behavior with TypeScript's default behavior.

However, when _exporting_ a `const enum` Babel will compile it to a plain object literal so that it doesn't need to rely on cross-file analysis when compiling it:

```typescript
// Input
export const enum Animals {
Expand Down