Skip to content

Commit

Permalink
Expose dts option in @babel/plugin-syntax-typescript (#14923)
Browse files Browse the repository at this point in the history
  • Loading branch information
oceandrama committed Oct 26, 2022
1 parent 8300960 commit 8f3cd4c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 32 deletions.
67 changes: 35 additions & 32 deletions packages/babel-plugin-syntax-typescript/src/index.ts
Expand Up @@ -18,38 +18,41 @@ function removePlugin(plugins: ParserPlugin[], name: string) {

export interface Options {
disallowAmbiguousJSXLike?: boolean;
dts?: boolean;
isTSX?: boolean;
}

export default declare((api, { isTSX, disallowAmbiguousJSXLike }: Options) => {
api.assertVersion(7);

return {
name: "syntax-typescript",

manipulateOptions(opts, parserOpts) {
const { plugins } = parserOpts;
// If the Flow syntax plugin already ran, remove it since Typescript
// takes priority.
removePlugin(plugins, "flow");

// If the JSX syntax plugin already ran, remove it because JSX handling
// in TS depends on the extensions, and is purely dependent on 'isTSX'.
removePlugin(plugins, "jsx");

plugins.push(
["typescript", { disallowAmbiguousJSXLike }],
"classProperties",
);

if (!process.env.BABEL_8_BREAKING) {
// This is enabled by default since @babel/parser 7.1.5
plugins.push("objectRestSpread");
}

if (isTSX) {
plugins.push("jsx");
}
},
};
});
export default declare(
(api, { disallowAmbiguousJSXLike, dts, isTSX }: Options) => {
api.assertVersion(7);

return {
name: "syntax-typescript",

manipulateOptions(opts, parserOpts) {
const { plugins } = parserOpts;
// If the Flow syntax plugin already ran, remove it since Typescript
// takes priority.
removePlugin(plugins, "flow");

// If the JSX syntax plugin already ran, remove it because JSX handling
// in TS depends on the extensions, and is purely dependent on 'isTSX'.
removePlugin(plugins, "jsx");

plugins.push(
["typescript", { disallowAmbiguousJSXLike, dts }],
"classProperties",
);

if (!process.env.BABEL_8_BREAKING) {
// This is enabled by default since @babel/parser 7.1.5
plugins.push("objectRestSpread");
}

if (isTSX) {
plugins.push("jsx");
}
},
};
},
);
@@ -0,0 +1 @@
const foo: string;
@@ -0,0 +1,3 @@
{
"plugins": [["syntax-typescript", { "dts": true }]]
}
@@ -0,0 +1 @@
const foo: string;

0 comments on commit 8f3cd4c

Please sign in to comment.