diff --git a/internal/parser/reparser.go b/internal/parser/reparser.go index 46e5598c50..bf4f651e57 100644 --- a/internal/parser/reparser.go +++ b/internal/parser/reparser.go @@ -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) diff --git a/testdata/baselines/reference/compiler/jsDocCallbackExport1.js b/testdata/baselines/reference/compiler/jsDocCallbackExport1.js new file mode 100644 index 0000000000..eac66bbf52 --- /dev/null +++ b/testdata/baselines/reference/compiler/jsDocCallbackExport1.js @@ -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; diff --git a/testdata/baselines/reference/compiler/jsDocCallbackExport1.symbols b/testdata/baselines/reference/compiler/jsDocCallbackExport1.symbols new file mode 100644 index 0000000000..bcf7834faf --- /dev/null +++ b/testdata/baselines/reference/compiler/jsDocCallbackExport1.symbols @@ -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)) + diff --git a/testdata/baselines/reference/compiler/jsDocCallbackExport1.types b/testdata/baselines/reference/compiler/jsDocCallbackExport1.types new file mode 100644 index 0000000000..f5d648222c --- /dev/null +++ b/testdata/baselines/reference/compiler/jsDocCallbackExport1.types @@ -0,0 +1,11 @@ +//// [tests/cases/compiler/jsDocCallbackExport1.ts] //// + +=== x.js === +/** + * @callback Foo + * @param {string} x + * @returns {number} + */ +function f1() {} +>f1 : () => void + diff --git a/testdata/baselines/reference/compiler/jsDocCallbackExport2.js b/testdata/baselines/reference/compiler/jsDocCallbackExport2.js new file mode 100644 index 0000000000..8a894ce57d --- /dev/null +++ b/testdata/baselines/reference/compiler/jsDocCallbackExport2.js @@ -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; diff --git a/testdata/baselines/reference/compiler/jsDocCallbackExport2.symbols b/testdata/baselines/reference/compiler/jsDocCallbackExport2.symbols new file mode 100644 index 0000000000..cccf7626e6 --- /dev/null +++ b/testdata/baselines/reference/compiler/jsDocCallbackExport2.symbols @@ -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)) + diff --git a/testdata/baselines/reference/compiler/jsDocCallbackExport2.types b/testdata/baselines/reference/compiler/jsDocCallbackExport2.types new file mode 100644 index 0000000000..2a6b035028 --- /dev/null +++ b/testdata/baselines/reference/compiler/jsDocCallbackExport2.types @@ -0,0 +1,11 @@ +//// [tests/cases/compiler/jsDocCallbackExport2.ts] //// + +=== x.js === +/** + * @callback Foo + * @param {string} x + * @returns {number} + */ +export function f1() {} +>f1 : () => void + diff --git a/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js b/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js index 8fbcf1ca16..885131f809 100644 --- a/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js +++ b/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js @@ -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]) @@ -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) ==== @@ -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: { /** diff --git a/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js.diff b/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js.diff index e6be9c01f3..d133646bf0 100644 --- a/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js.diff +++ b/testdata/baselines/reference/submodule/compiler/jsFileAlternativeUseOfOverloadTag.js.diff @@ -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]) @@ -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) ==== @@ -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: { + /** diff --git a/testdata/baselines/reference/submodule/conformance/callbackTagNestedParameter.js b/testdata/baselines/reference/submodule/conformance/callbackTagNestedParameter.js index 6021aa159f..88bac0df52 100644 --- a/testdata/baselines/reference/submodule/conformance/callbackTagNestedParameter.js +++ b/testdata/baselines/reference/submodule/conformance/callbackTagNestedParameter.js @@ -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; diff --git a/testdata/baselines/reference/submodule/conformance/callbackTagNestedParameter.js.diff b/testdata/baselines/reference/submodule/conformance/callbackTagNestedParameter.js.diff index 8fe8a594c2..2f50a7a418 100644 --- a/testdata/baselines/reference/submodule/conformance/callbackTagNestedParameter.js.diff +++ b/testdata/baselines/reference/submodule/conformance/callbackTagNestedParameter.js.diff @@ -4,7 +4,7 @@ * @param {number} [person.age] * @returns {void} */ -+export type WorksWithPeopleCallback = (person: { ++type WorksWithPeopleCallback = (person: { + name: string; + age?: number; +}) => void; diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js index 5806719ef7..bd3ba2627c 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js @@ -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 diff --git a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff index 192a51589c..d941bf0e81 100644 --- a/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff +++ b/testdata/baselines/reference/submodule/conformance/jsDeclarationsParameterTagReusesInputNodeInEmit1.js.diff @@ -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 diff --git a/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js b/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js index 26167e83cb..4f99ceb207 100644 --- a/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js +++ b/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js @@ -113,7 +113,7 @@ function flatMap(array, iterable = identity) { //// [templateInsideCallback.d.ts] -export type Call = () ; +type Call = () ; /** * @typedef Oops * @template T diff --git a/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js.diff b/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js.diff index 17015f2613..2abe09db9b 100644 --- a/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js.diff +++ b/testdata/baselines/reference/submodule/conformance/templateInsideCallback.js.diff @@ -28,7 +28,7 @@ - * @returns {T[]} - */ -declare function flatMap(): any; -+export type Call = () ; ++type Call = () ; /** * @typedef Oops * @template T diff --git a/testdata/tests/cases/compiler/jsDocCallbackExport1.ts b/testdata/tests/cases/compiler/jsDocCallbackExport1.ts new file mode 100644 index 0000000000..a46c07f8d6 --- /dev/null +++ b/testdata/tests/cases/compiler/jsDocCallbackExport1.ts @@ -0,0 +1,12 @@ +// @emitDeclarationOnly: true +// @declaration: true +// @allowJs: true +// @checkJs: true + +// @filename: x.js +/** + * @callback Foo + * @param {string} x + * @returns {number} + */ +function f1() {} diff --git a/testdata/tests/cases/compiler/jsDocCallbackExport2.ts b/testdata/tests/cases/compiler/jsDocCallbackExport2.ts new file mode 100644 index 0000000000..a37d2c1b4d --- /dev/null +++ b/testdata/tests/cases/compiler/jsDocCallbackExport2.ts @@ -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() {}