Skip to content
This repository was archived by the owner on Jan 14, 2019. It is now read-only.
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
1 change: 0 additions & 1 deletion src/ast-node-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ export enum AST_NODE_TYPES {
TSMethodSignature = 'TSMethodSignature',
TSModuleBlock = 'TSModuleBlock',
TSModuleDeclaration = 'TSModuleDeclaration',
TSNamespaceFunctionDeclaration = 'TSNamespaceFunctionDeclaration',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this node type is/was no longer used

TSNamespaceExportDeclaration = 'TSNamespaceExportDeclaration',
TSNonNullExpression = 'TSNonNullExpression',
TSNeverKeyword = 'TSNeverKeyword',
Expand Down
5 changes: 3 additions & 2 deletions src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,9 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
// Declarations

case SyntaxKind.FunctionDeclaration: {
const isDeclare = nodeUtils.hasModifier(SyntaxKind.DeclareKeyword, node);
let functionDeclarationType = AST_NODE_TYPES.FunctionDeclaration;
if (nodeUtils.hasModifier(SyntaxKind.DeclareKeyword, node)) {
if (isDeclare || !node.body) {
functionDeclarationType = AST_NODE_TYPES.TSDeclareFunction;
}

Expand All @@ -697,7 +698,7 @@ export default function convert(config: ConvertConfig): ESTreeNode | null {
result.returnType = convertTypeAnnotation(node.type);
}

if (functionDeclarationType === AST_NODE_TYPES.TSDeclareFunction) {
if (isDeclare) {
result.declare = true;
}

Expand Down
10 changes: 3 additions & 7 deletions tests/ast-alignment/fixtures-to-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,16 +466,12 @@ tester.addFixturePatternConfig('typescript/namespaces-and-modules', {
/**
* Minor AST difference
*/
'nested-internal-module',
/**
* Babel: TSDeclareFunction
* ts-estree: TSNamespaceFunctionDeclaration
*/
'declare-namespace-with-exported-function'
'nested-internal-module'
],
ignoreSourceType: [
'module-with-default-exports',
'ambient-module-declaration-with-import'
'ambient-module-declaration-with-import',
'declare-namespace-with-exported-function'
]
});

Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/typescript/basics/function-overloads.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function f(x: number): number;
export function f(x: string): string;
export function f(x: string | number): string | number {
return x;
}
4 changes: 2 additions & 2 deletions tests/lib/__snapshots__/javascript.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -119241,7 +119241,7 @@ Object {
0,
24,
],
"type": "FunctionDeclaration",
"type": "TSDeclareFunction",
},
],
"loc": Object {
Expand Down Expand Up @@ -119575,7 +119575,7 @@ Object {
0,
23,
],
"type": "FunctionDeclaration",
"type": "TSDeclareFunction",
},
],
"loc": Object {
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/__snapshots__/semantic-diagnostics-enabled.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,8 @@ exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" e

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/export-type-function-declaration.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/function-overloads.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/function-with-await.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;

exports[`Parse all fixtures with "errorOnTypeScriptSyntacticAndSemanticIssues" enabled fixtures/typescript/basics/function-with-object-type-with-optional-properties.src.ts.src 1`] = `"TEST OUTPUT: No semantic or syntactic issues found"`;
Expand Down
Loading