From 1650d30a52b2d7df7e0cfc6d062ff124eae51c47 Mon Sep 17 00:00:00 2001 From: oceandrama Date: Tue, 13 Sep 2022 21:32:45 +0300 Subject: [PATCH 1/2] docs: document dts and disallowAmbiguousJSXLike options --- docs/plugin-syntax-typescript.md | 16 ++++++++++++++++ docs/plugin-transform-typescript.md | 16 +++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/docs/plugin-syntax-typescript.md b/docs/plugin-syntax-typescript.md index a8c7439c0d..18f9397f0c 100644 --- a/docs/plugin-syntax-typescript.md +++ b/docs/plugin-syntax-typescript.md @@ -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 (` y` type assertions and `() => {}` type arguments). It matches the `tsc` behavior when parsing `.mts` and `.mjs` files. + +### `dts` + +`boolean`, defaults to `false` + +Added in: `v7.14.0` + +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. + ### `isTSX` `boolean`, defaults to `false`. diff --git a/docs/plugin-transform-typescript.md b/docs/plugin-transform-typescript.md index bbb9791365..7a01e5c785 100644 --- a/docs/plugin-transform-typescript.md +++ b/docs/plugin-transform-typescript.md @@ -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 (` y` type assertions and `() => {}` type arguments). It matches the `tsc` behavior when parsing `.mts` and `.mjs` files. +### `dts` + +`boolean`, defaults to `false` + +Added in: `v7.14.0` + +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. + ### `isTSX` `boolean`, defaults to `false` @@ -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"; })(Animals || (Animals = {})); console.log(Animals.Fish); @@ -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 { From 82050f4de378bd59b126223c498e4a4361101129 Mon Sep 17 00:00:00 2001 From: Ruslan Baigunussov Date: Tue, 25 Oct 2022 22:16:37 +0300 Subject: [PATCH 2/2] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Huáng Jùnliàng --- docs/plugin-syntax-typescript.md | 4 ++-- docs/plugin-transform-typescript.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/plugin-syntax-typescript.md b/docs/plugin-syntax-typescript.md index 18f9397f0c..639c9190e9 100644 --- a/docs/plugin-syntax-typescript.md +++ b/docs/plugin-syntax-typescript.md @@ -50,9 +50,9 @@ Even when JSX parsing is not enabled, this option disallows using syntax that wo `boolean`, defaults to `false` -Added in: `v7.14.0` +Added in: `v7.20.0` -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. +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 [Official Handbook](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html) and [TypeScript Deep Dive](https://basarat.gitbook.io/typescript/type-system/intro) for more information about ambient contexts. ### `isTSX` diff --git a/docs/plugin-transform-typescript.md b/docs/plugin-transform-typescript.md index 7a01e5c785..0ea4ec2d97 100644 --- a/docs/plugin-transform-typescript.md +++ b/docs/plugin-transform-typescript.md @@ -99,9 +99,9 @@ Even when JSX parsing is not enabled, this option disallows using syntax that wo `boolean`, defaults to `false` -Added in: `v7.14.0` +Added in: `v7.20.0` -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. +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 [Official Handbook](https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html) and [TypeScript Deep Dive](https://basarat.gitbook.io/typescript/type-system/intro) for more information about ambient contexts. ### `isTSX`