Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Breaking: Explicitly handle TSEnumDeclaration (fixes #345) #364

Merged
merged 1 commit into from
Aug 19, 2017
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: 1 addition & 0 deletions lib/ast-node-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ module.exports = {
TSConstructSignature: "TSConstructSignature",
TSDeclareKeyword: "TSDeclareKeyword",
TSEnumDeclaration: "TSEnumDeclaration",
TSEnumMember: "TSEnumMember",
TSExportAssignment: "TSExportAssigment",
TSIndexSignature: "TSIndexSignature",
TSInterfaceBody: "TSInterfaceBody",
Expand Down
30 changes: 30 additions & 0 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,36 @@ module.exports = function convert(config) {
});
break;

case SyntaxKind.EnumDeclaration: {
Object.assign(result, {
type: AST_NODE_TYPES.TSEnumDeclaration,
id: convertChild(node.name),
members: node.members.map(convertChild)
});
// check for exports
result = nodeUtils.fixExports(node, result, ast);
/**
* Semantically, decorators are not allowed on enum declarations,
* but the TypeScript compiler will parse them and produce a valid AST,
* so we handle them here too.
*/
if (node.decorators) {
result.decorators = convertDecorators(node.decorators);
}
break;
}

case SyntaxKind.EnumMember: {
Object.assign(result, {
type: AST_NODE_TYPES.TSEnumMember,
id: convertChild(node.name)
});
if (node.initializer) {
result.initializer = convertChild(node.initializer);
}
break;
}

default:
deeplyCopy();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"license": "BSD-2-Clause",
"devDependencies": {
"babel-code-frame": "^6.22.0",
"babylon": "^7.0.0-beta.19",
"babylon": "^7.0.0-beta.20",
Copy link
Member Author

Choose a reason for hiding this comment

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

FYI 7.0.0-beta.20 contained an important fix for exported TS constructs so that is why I have set that as the new baseline

"eslint": "3.19.0",
"eslint-config-eslint": "4.0.0",
"eslint-plugin-node": "4.2.2",
Expand Down
7 changes: 6 additions & 1 deletion tests/ast-alignment/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,12 @@ const fixturePatternsToTest = [
"typescript/basics/async-function-expression.src.ts",
"typescript/basics/async-function-with-var-declaration.src.ts",
"typescript/basics/function-with-await.src.ts",
"typescript/errorRecovery/class-extends-empty-implements.src.ts"
"typescript/errorRecovery/class-extends-empty-implements.src.ts",

{
pattern: "typescript/basics/export-named-enum.src.ts",
config: { babylonParserOptions: { sourceType: "module" } }
}

/**
* TypeScript-specific tests taken from "errorRecovery". Babylon is not being as forgiving as the TypeScript compiler here.
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/typescript/basics/export-named-enum.src.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum Foo {
foo = 1,
bar
}
Loading