Skip to content

Commit 90bc90f

Browse files
authored
Don't add export modifier to JSTypeAliasDeclaration from @callback (#2063)
1 parent 3e97dac commit 90bc90f

17 files changed

+125
-21
lines changed

internal/parser/reparser.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,8 @@ func (p *Parser) reparseUnhosted(tag *ast.Node, parent *ast.Node, jsDoc *ast.Nod
9393
if callbackTag.TypeExpression == nil {
9494
break
9595
}
96-
97-
export := p.factory.NewModifier(ast.KindExportKeyword)
98-
export.Loc = tag.Loc
99-
export.Flags = p.contextFlags | ast.NodeFlagsReparsed
100-
modifiers := p.newModifierList(export.Loc, p.nodeSlicePool.NewSlice1(export))
10196
functionType := p.reparseJSDocSignature(callbackTag.TypeExpression, tag, jsDoc, tag, nil)
102-
103-
typeAlias := p.factory.NewJSTypeAliasDeclaration(modifiers, p.factory.DeepCloneReparse(callbackTag.FullName), nil, functionType)
97+
typeAlias := p.factory.NewJSTypeAliasDeclaration(nil, p.factory.DeepCloneReparse(callbackTag.FullName), nil, functionType)
10498
typeAlias.AsTypeAliasDeclaration().TypeParameters = p.gatherTypeParameters(jsDoc, tag)
10599
p.finishReparsedNode(typeAlias, tag)
106100
p.reparseList = append(p.reparseList, typeAlias)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//// [tests/cases/compiler/jsDocCallbackExport1.ts] ////
2+
3+
//// [x.js]
4+
/**
5+
* @callback Foo
6+
* @param {string} x
7+
* @returns {number}
8+
*/
9+
function f1() {}
10+
11+
12+
13+
14+
//// [x.d.ts]
15+
type Foo = (x: string) => number;
16+
/**
17+
* @callback Foo
18+
* @param {string} x
19+
* @returns {number}
20+
*/
21+
declare function f1(): void;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [tests/cases/compiler/jsDocCallbackExport1.ts] ////
2+
3+
=== x.js ===
4+
/**
5+
* @callback Foo
6+
* @param {string} x
7+
* @returns {number}
8+
*/
9+
function f1() {}
10+
>f1 : Symbol(f1, Decl(x.js, 0, 0))
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [tests/cases/compiler/jsDocCallbackExport1.ts] ////
2+
3+
=== x.js ===
4+
/**
5+
* @callback Foo
6+
* @param {string} x
7+
* @returns {number}
8+
*/
9+
function f1() {}
10+
>f1 : () => void
11+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//// [tests/cases/compiler/jsDocCallbackExport2.ts] ////
2+
3+
//// [x.js]
4+
/**
5+
* @callback Foo
6+
* @param {string} x
7+
* @returns {number}
8+
*/
9+
export function f1() {}
10+
11+
12+
13+
14+
//// [x.d.ts]
15+
export type Foo = (x: string) => number;
16+
/**
17+
* @callback Foo
18+
* @param {string} x
19+
* @returns {number}
20+
*/
21+
export declare function f1(): void;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [tests/cases/compiler/jsDocCallbackExport2.ts] ////
2+
3+
=== x.js ===
4+
/**
5+
* @callback Foo
6+
* @param {string} x
7+
* @returns {number}
8+
*/
9+
export function f1() {}
10+
>f1 : Symbol(f1, Decl(x.js, 0, 0))
11+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [tests/cases/compiler/jsDocCallbackExport2.ts] ////
2+
3+
=== x.js ===
4+
/**
5+
* @callback Foo
6+
* @param {string} x
7+
* @returns {number}
8+
*/
9+
export function f1() {}
10+
>f1 : () => void
11+

testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ declare const example2: {
139139
constructor: () => void;
140140
};
141141
declare function evaluate(): any;
142-
export type callback = (error: any, result: any) ;
142+
type callback = (error: any, result: any) ;
143143
declare const example3: {
144144
/**
145145
* @overload evaluate(options = {}, [callback])
@@ -161,7 +161,7 @@ declare const example3: {
161161
//// [DtsFileErrors]
162162

163163

164-
dist/jsFileAlternativeUseOfOverloadTag.d.ts(34,50): error TS1005: '=>' expected.
164+
dist/jsFileAlternativeUseOfOverloadTag.d.ts(34,43): error TS1005: '=>' expected.
165165

166166

167167
==== dist/jsFileAlternativeUseOfOverloadTag.d.ts (1 errors) ====
@@ -198,8 +198,8 @@ dist/jsFileAlternativeUseOfOverloadTag.d.ts(34,50): error TS1005: '=>' expected.
198198
constructor: () => void;
199199
};
200200
declare function evaluate(): any;
201-
export type callback = (error: any, result: any) ;
202-
~
201+
type callback = (error: any, result: any) ;
202+
~
203203
!!! error TS1005: '=>' expected.
204204
declare const example3: {
205205
/**

testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js.diff

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
+ constructor: () => void;
8383
+};
8484
+declare function evaluate(): any;
85-
+export type callback = (error: any, result: any) ;
85+
+type callback = (error: any, result: any) ;
8686
+declare const example3: {
8787
/**
8888
* @overload evaluate(options = {}, [callback])
@@ -105,7 +105,7 @@
105105
+//// [DtsFileErrors]
106106
+
107107
+
108-
+dist/jsFileAlternativeUseOfOverloadTag.d.ts(34,50): error TS1005: '=>' expected.
108+
+dist/jsFileAlternativeUseOfOverloadTag.d.ts(34,43): error TS1005: '=>' expected.
109109
+
110110
+
111111
+==== dist/jsFileAlternativeUseOfOverloadTag.d.ts (1 errors) ====
@@ -142,8 +142,8 @@
142142
+ constructor: () => void;
143143
+ };
144144
+ declare function evaluate(): any;
145-
+ export type callback = (error: any, result: any) ;
146-
+ ~
145+
+ type callback = (error: any, result: any) ;
146+
+ ~
147147
+!!! error TS1005: '=>' expected.
148148
+ declare const example3: {
149149
+ /**

testdata/baselines/reference/submodule/conformance/callbackTagNestedParameter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function eachPerson(callback) {
2929
* @param {number} [person.age]
3030
* @returns {void}
3131
*/
32-
export type WorksWithPeopleCallback = (person: {
32+
type WorksWithPeopleCallback = (person: {
3333
name: string;
3434
age?: number;
3535
}) => void;

0 commit comments

Comments
 (0)