Skip to content

Commit d5f4505

Browse files
authored
fix: allow exporting TSDeclareFunction as default (#14763)
1 parent 354c259 commit d5f4505

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

packages/babel-plugin-transform-modules-systemjs/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ export default declare<PluginState>((api, options: Options) => {
436436
}
437437
removedPaths.push(path);
438438
} else {
439+
// @ts-expect-error TSDeclareFunction is not expected here
439440
path.replaceWith(buildExportCall("default", declar));
440441
}
441442
} else if (path.isExportNamedDeclaration()) {

packages/babel-types/src/ast-types/generated/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,11 @@ export interface ExportAllDeclaration extends BaseNode {
813813

814814
export interface ExportDefaultDeclaration extends BaseNode {
815815
type: "ExportDefaultDeclaration";
816-
declaration: FunctionDeclaration | ClassDeclaration | Expression;
816+
declaration:
817+
| TSDeclareFunction
818+
| FunctionDeclaration
819+
| ClassDeclaration
820+
| Expression;
817821
exportKind?: "value" | null;
818822
}
819823

@@ -6722,6 +6726,7 @@ export interface ParentMaps {
67226726
TSDeclareFunction:
67236727
| BlockStatement
67246728
| DoWhileStatement
6729+
| ExportDefaultDeclaration
67256730
| ExportNamedDeclaration
67266731
| ForInStatement
67276732
| ForOfStatement

packages/babel-types/src/builders/generated/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,11 @@ export function exportAllDeclaration(
639639
});
640640
}
641641
export function exportDefaultDeclaration(
642-
declaration: t.FunctionDeclaration | t.ClassDeclaration | t.Expression,
642+
declaration:
643+
| t.TSDeclareFunction
644+
| t.FunctionDeclaration
645+
| t.ClassDeclaration
646+
| t.Expression,
643647
): t.ExportDefaultDeclaration {
644648
return validateNode<t.ExportDefaultDeclaration>({
645649
type: "ExportDefaultDeclaration",

packages/babel-types/src/definitions/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,7 @@ defineType("ExportDefaultDeclaration", {
15211521
fields: {
15221522
declaration: {
15231523
validate: assertNodeType(
1524+
"TSDeclareFunction",
15241525
"FunctionDeclaration",
15251526
"ClassDeclaration",
15261527
"Expression",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as t from "../../../lib/index.js";
2+
3+
describe("builders", function () {
4+
describe("typescript", function () {
5+
describe("exportDefaultDeclaration", function () {
6+
it("accept TSDeclareFunction as argument for exportDefaultDeclaration", function () {
7+
// this can be used when having function overrides for function exported as default
8+
// export default function test();
9+
// export default function test() {};
10+
expect(() => {
11+
t.exportDefaultDeclaration(
12+
t.tsDeclareFunction(
13+
t.identifier("test"),
14+
null,
15+
[],
16+
t.tsTypeAnnotation(t.tsVoidKeyword()),
17+
),
18+
);
19+
}).not.toThrow();
20+
});
21+
});
22+
});
23+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy