Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

Commit 32c0cc8

Browse filesBrowse files
authored
Breaking: Explicitly handle TSEnumDeclaration (fixes eslint#345) (eslint#364)
1 parent 5f741a9 commit 32c0cc8
Copy full SHA for 32c0cc8

File tree

Expand file treeCollapse file tree

6 files changed

+404
-14
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+404
-14
lines changed

‎lib/ast-node-types.js

Copy file name to clipboardExpand all lines: lib/ast-node-types.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ module.exports = {
109109
TSConstructSignature: "TSConstructSignature",
110110
TSDeclareKeyword: "TSDeclareKeyword",
111111
TSEnumDeclaration: "TSEnumDeclaration",
112+
TSEnumMember: "TSEnumMember",
112113
TSExportAssignment: "TSExportAssigment",
113114
TSIndexSignature: "TSIndexSignature",
114115
TSInterfaceBody: "TSInterfaceBody",

‎lib/convert.js

Copy file name to clipboardExpand all lines: lib/convert.js
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,36 @@ module.exports = function convert(config) {
19941994
});
19951995
break;
19961996

1997+
case SyntaxKind.EnumDeclaration: {
1998+
Object.assign(result, {
1999+
type: AST_NODE_TYPES.TSEnumDeclaration,
2000+
id: convertChild(node.name),
2001+
members: node.members.map(convertChild)
2002+
});
2003+
// check for exports
2004+
result = nodeUtils.fixExports(node, result, ast);
2005+
/**
2006+
* Semantically, decorators are not allowed on enum declarations,
2007+
* but the TypeScript compiler will parse them and produce a valid AST,
2008+
* so we handle them here too.
2009+
*/
2010+
if (node.decorators) {
2011+
result.decorators = convertDecorators(node.decorators);
2012+
}
2013+
break;
2014+
}
2015+
2016+
case SyntaxKind.EnumMember: {
2017+
Object.assign(result, {
2018+
type: AST_NODE_TYPES.TSEnumMember,
2019+
id: convertChild(node.name)
2020+
});
2021+
if (node.initializer) {
2022+
result.initializer = convertChild(node.initializer);
2023+
}
2024+
break;
2025+
}
2026+
19972027
default:
19982028
deeplyCopy();
19992029
}

‎package.json

Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"license": "BSD-2-Clause",
2020
"devDependencies": {
2121
"babel-code-frame": "^6.22.0",
22-
"babylon": "^7.0.0-beta.19",
22+
"babylon": "^7.0.0-beta.20",
2323
"eslint": "3.19.0",
2424
"eslint-config-eslint": "4.0.0",
2525
"eslint-plugin-node": "4.2.2",

‎tests/ast-alignment/spec.js

Copy file name to clipboardExpand all lines: tests/ast-alignment/spec.js
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,12 @@ const fixturePatternsToTest = [
421421
"typescript/basics/async-function-expression.src.ts",
422422
"typescript/basics/async-function-with-var-declaration.src.ts",
423423
"typescript/basics/function-with-await.src.ts",
424-
"typescript/errorRecovery/class-extends-empty-implements.src.ts"
424+
"typescript/errorRecovery/class-extends-empty-implements.src.ts",
425+
426+
{
427+
pattern: "typescript/basics/export-named-enum.src.ts",
428+
config: { babylonParserOptions: { sourceType: "module" } }
429+
}
425430

426431
/**
427432
* TypeScript-specific tests taken from "errorRecovery". Babylon is not being as forgiving as the TypeScript compiler here.
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export enum Foo {
2+
foo = 1,
3+
bar
4+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.