Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions internal/parser/reparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,8 @@ func (p *Parser) reparseUnhosted(tag *ast.Node, parent *ast.Node, jsDoc *ast.Nod
if callbackTag.TypeExpression == nil {
break
}

export := p.factory.NewModifier(ast.KindExportKeyword)
export.Loc = tag.Loc
export.Flags = p.contextFlags | ast.NodeFlagsReparsed
modifiers := p.newModifierList(export.Loc, p.nodeSlicePool.NewSlice1(export))
functionType := p.reparseJSDocSignature(callbackTag.TypeExpression, tag, jsDoc, tag, nil)

typeAlias := p.factory.NewJSTypeAliasDeclaration(modifiers, p.factory.DeepCloneReparse(callbackTag.FullName), nil, functionType)
typeAlias := p.factory.NewJSTypeAliasDeclaration(nil, p.factory.DeepCloneReparse(callbackTag.FullName), nil, functionType)
typeAlias.AsTypeAliasDeclaration().TypeParameters = p.gatherTypeParameters(jsDoc, tag)
p.finishReparsedNode(typeAlias, tag)
p.reparseList = append(p.reparseList, typeAlias)
Expand Down
21 changes: 21 additions & 0 deletions testdata/baselines/reference/compiler/jsDocCallbackExport1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [tests/cases/compiler/jsDocCallbackExport1.ts] ////

//// [x.js]
/**
* @callback Foo
* @param {string} x
* @returns {number}
*/
function f1() {}




//// [x.d.ts]
type Foo = (x: string) => number;
/**
* @callback Foo
* @param {string} x
* @returns {number}
*/
declare function f1(): void;
11 changes: 11 additions & 0 deletions testdata/baselines/reference/compiler/jsDocCallbackExport1.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [tests/cases/compiler/jsDocCallbackExport1.ts] ////

=== x.js ===
/**
* @callback Foo
* @param {string} x
* @returns {number}
*/
function f1() {}
>f1 : Symbol(f1, Decl(x.js, 0, 0))

11 changes: 11 additions & 0 deletions testdata/baselines/reference/compiler/jsDocCallbackExport1.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [tests/cases/compiler/jsDocCallbackExport1.ts] ////

=== x.js ===
/**
* @callback Foo
* @param {string} x
* @returns {number}
*/
function f1() {}
>f1 : () => void

21 changes: 21 additions & 0 deletions testdata/baselines/reference/compiler/jsDocCallbackExport2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [tests/cases/compiler/jsDocCallbackExport2.ts] ////

//// [x.js]
/**
* @callback Foo
* @param {string} x
* @returns {number}
*/
export function f1() {}




//// [x.d.ts]
export type Foo = (x: string) => number;
/**
* @callback Foo
* @param {string} x
* @returns {number}
*/
export declare function f1(): void;
11 changes: 11 additions & 0 deletions testdata/baselines/reference/compiler/jsDocCallbackExport2.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [tests/cases/compiler/jsDocCallbackExport2.ts] ////

=== x.js ===
/**
* @callback Foo
* @param {string} x
* @returns {number}
*/
export function f1() {}
>f1 : Symbol(f1, Decl(x.js, 0, 0))

11 changes: 11 additions & 0 deletions testdata/baselines/reference/compiler/jsDocCallbackExport2.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [tests/cases/compiler/jsDocCallbackExport2.ts] ////

=== x.js ===
/**
* @callback Foo
* @param {string} x
* @returns {number}
*/
export function f1() {}
>f1 : () => void

Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ declare const example2: {
constructor: () => void;
};
declare function evaluate(): any;
export type callback = (error: any, result: any) ;
type callback = (error: any, result: any) ;
declare const example3: {
/**
* @overload evaluate(options = {}, [callback])
Expand All @@ -161,7 +161,7 @@ declare const example3: {
//// [DtsFileErrors]


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


==== dist/jsFileAlternativeUseOfOverloadTag.d.ts (1 errors) ====
Expand Down Expand Up @@ -198,8 +198,8 @@ dist/jsFileAlternativeUseOfOverloadTag.d.ts(34,50): error TS1005: '=>' expected.
constructor: () => void;
};
declare function evaluate(): any;
export type callback = (error: any, result: any) ;
~
type callback = (error: any, result: any) ;
~
!!! error TS1005: '=>' expected.
declare const example3: {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
+ constructor: () => void;
+};
+declare function evaluate(): any;
+export type callback = (error: any, result: any) ;
+type callback = (error: any, result: any) ;
+declare const example3: {
/**
* @overload evaluate(options = {}, [callback])
Expand All @@ -105,7 +105,7 @@
+//// [DtsFileErrors]
+
+
+dist/jsFileAlternativeUseOfOverloadTag.d.ts(34,50): error TS1005: '=>' expected.
+dist/jsFileAlternativeUseOfOverloadTag.d.ts(34,43): error TS1005: '=>' expected.
+
+
+==== dist/jsFileAlternativeUseOfOverloadTag.d.ts (1 errors) ====
Expand Down Expand Up @@ -142,8 +142,8 @@
+ constructor: () => void;
+ };
+ declare function evaluate(): any;
+ export type callback = (error: any, result: any) ;
+ ~
+ type callback = (error: any, result: any) ;
+ ~
+!!! error TS1005: '=>' expected.
+ declare const example3: {
+ /**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function eachPerson(callback) {
* @param {number} [person.age]
* @returns {void}
*/
export type WorksWithPeopleCallback = (person: {
type WorksWithPeopleCallback = (person: {
name: string;
age?: number;
}) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @param {number} [person.age]
* @returns {void}
*/
+export type WorksWithPeopleCallback = (person: {
+type WorksWithPeopleCallback = (person: {
+ name: string;
+ age?: number;
+}) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ declare namespace BaseFactory {
export = BaseFactory;
//// [file.d.ts]
type BaseFactory = import('./base');
export type BaseFactoryFactory = (factory: import('./base')) ;
type BaseFactoryFactory = (factory: import('./base')) ;
/** @typedef {import('./base')} BaseFactory */
/**
* @callback BaseFactoryFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
- };
-};
+type BaseFactory = import('./base');
+export type BaseFactoryFactory = (factory: import('./base')) ;
+type BaseFactoryFactory = (factory: import('./base')) ;
/** @typedef {import('./base')} BaseFactory */
/**
* @callback BaseFactoryFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function flatMap(array, iterable = identity) {


//// [templateInsideCallback.d.ts]
export type Call = () ;
type Call = () ;
/**
* @typedef Oops
* @template T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- * @returns {T[]}
- */
-declare function flatMap(): any;
+export type Call = () ;
+type Call = () ;
/**
* @typedef Oops
* @template T
Expand Down
12 changes: 12 additions & 0 deletions testdata/tests/cases/compiler/jsDocCallbackExport1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @emitDeclarationOnly: true
// @declaration: true
// @allowJs: true
// @checkJs: true

// @filename: x.js
/**
* @callback Foo
* @param {string} x
* @returns {number}
*/
function f1() {}
12 changes: 12 additions & 0 deletions testdata/tests/cases/compiler/jsDocCallbackExport2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @emitDeclarationOnly: true
// @declaration: true
// @allowJs: true
// @checkJs: true

// @filename: x.js
/**
* @callback Foo
* @param {string} x
* @returns {number}
*/
export function f1() {}
Loading