Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

Commit 2c754a8

Browse files
authored
Update Babel to ^7.7.0 and enable Flow enums parsing (#812)
* Update Babel to ^7.7.0 and enable Flow enums parsing * Update comment about Espree Flow enums support * Add EnumDeclaration to scope analyzer * Add test for unused enum
1 parent 183d13e commit 2c754a8

6 files changed

+113
-50
lines changed

lib/analyze-scope.js

+4
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ class Referencer extends OriginalReferencer {
149149
}
150150
}
151151

152+
EnumDeclaration(node) {
153+
this._createScopeVariable(node, node.id);
154+
}
155+
152156
TypeAlias(node) {
153157
this._createScopeVariable(node, node.id);
154158

lib/parse.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = function(code, options) {
1919
ranges: true,
2020
tokens: true,
2121
plugins: [
22-
["flow", { all: true }],
22+
["flow", { all: true, enums: true }],
2323
"jsx",
2424
"estree",
2525
"asyncFunctions",

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
},
1313
"dependencies": {
1414
"@babel/code-frame": "^7.0.0",
15-
"@babel/parser": "^7.0.0",
16-
"@babel/traverse": "^7.0.0",
17-
"@babel/types": "^7.0.0",
15+
"@babel/parser": "^7.7.0",
16+
"@babel/traverse": "^7.7.0",
17+
"@babel/types": "^7.7.0",
1818
"eslint-visitor-keys": "^1.0.0",
1919
"resolve": "^1.12.0"
2020
},

test/babel-eslint.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,11 @@ describe("babylon-to-espree", () => {
261261
});
262262

263263
it("export named", () => {
264-
parseAndAssertSame("export { foo };");
264+
parseAndAssertSame("const foo = 1; export { foo };");
265265
});
266266

267267
it("export named alias", () => {
268-
parseAndAssertSame("export { foo as bar };");
268+
parseAndAssertSame("const foo = 1; export { foo as bar };");
269269
});
270270

271271
// Espree doesn't support the optional chaining operator yet
@@ -298,6 +298,16 @@ describe("babylon-to-espree", () => {
298298
assert.strictEqual(babylonAST.tokens[1].type, "Punctuator");
299299
});
300300

301+
// Espree doesn't support Flow enums
302+
it("flow enums", () => {
303+
const code = "enum E {A, B}";
304+
const babylonAST = babelEslint.parseForESLint(code, {
305+
eslintVisitorKeys: true,
306+
eslintScopeManager: true,
307+
}).ast;
308+
assert.strictEqual(babylonAST.body[0].type, "EnumDeclaration");
309+
});
310+
301311
it.skip("empty program with line comment", () => {
302312
parseAndAssertSame("// single comment");
303313
});

test/non-regression.js

+18
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,24 @@ describe("verify", () => {
229229
);
230230
});
231231

232+
it("enum declaration", () => {
233+
verifyAndAssertMessages(
234+
`
235+
enum E {
236+
A,
237+
B,
238+
}
239+
E.A;
240+
enum UnusedEnum {
241+
A,
242+
B,
243+
}
244+
`,
245+
{ "no-unused-vars": 1, "no-undef": 1 },
246+
["6:6 'UnusedEnum' is defined but never used. no-unused-vars"]
247+
);
248+
});
249+
232250
it("type parameter bounds (classes)", () => {
233251
verifyAndAssertMessages(
234252
`

yarn.lock

+75-44
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
dependencies:
1515
"@babel/highlight" "^7.0.0"
1616

17+
"@babel/code-frame@^7.5.5":
18+
version "7.5.5"
19+
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.5.5.tgz#bc0782f6d69f7b7d49531219699b988f669a8f9d"
20+
integrity sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw==
21+
dependencies:
22+
"@babel/highlight" "^7.0.0"
23+
1724
1825
version "7.0.0-beta.44"
1926
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.0.0-beta.44.tgz#c7e67b9b5284afcf69b309b50d7d37f3e5033d42"
@@ -24,15 +31,15 @@
2431
source-map "^0.5.0"
2532
trim-right "^1.0.1"
2633

27-
"@babel/generator@^7.0.0":
28-
version "7.0.0"
29-
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.0.0.tgz#1efd58bffa951dc846449e58ce3a1d7f02d393aa"
34+
"@babel/generator@^7.7.4":
35+
version "7.7.4"
36+
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.7.4.tgz#db651e2840ca9aa66f327dcec1dc5f5fa9611369"
37+
integrity sha512-m5qo2WgdOJeyYngKImbkyQrnUN1mPceaG5BV+G0E3gWsa4l/jCSryWJdM2x8OuGAOyh+3d5pVYfZWCiNFtynxg==
3038
dependencies:
31-
"@babel/types" "^7.0.0"
39+
"@babel/types" "^7.7.4"
3240
jsesc "^2.5.1"
33-
lodash "^4.17.10"
41+
lodash "^4.17.13"
3442
source-map "^0.5.0"
35-
trim-right "^1.0.1"
3643

3744
3845
version "7.0.0-beta.44"
@@ -42,37 +49,40 @@
4249
"@babel/template" "7.0.0-beta.44"
4350
"@babel/types" "7.0.0-beta.44"
4451

45-
"@babel/helper-function-name@^7.0.0":
46-
version "7.0.0"
47-
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.0.0.tgz#a68cc8d04420ccc663dd258f9cc41b8261efa2d4"
52+
"@babel/helper-function-name@^7.7.4":
53+
version "7.7.4"
54+
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.7.4.tgz#ab6e041e7135d436d8f0a3eca15de5b67a341a2e"
55+
integrity sha512-AnkGIdiBhEuiwdoMnKm7jfPfqItZhgRaZfMg1XX3bS25INOnLPjPG1Ppnajh8eqgt5kPJnfqrRHqFqmjKDZLzQ==
4856
dependencies:
49-
"@babel/helper-get-function-arity" "^7.0.0"
50-
"@babel/template" "^7.0.0"
51-
"@babel/types" "^7.0.0"
57+
"@babel/helper-get-function-arity" "^7.7.4"
58+
"@babel/template" "^7.7.4"
59+
"@babel/types" "^7.7.4"
5260

5361
5462
version "7.0.0-beta.44"
5563
resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0-beta.44.tgz#d03ca6dd2b9f7b0b1e6b32c56c72836140db3a15"
5664
dependencies:
5765
"@babel/types" "7.0.0-beta.44"
5866

59-
"@babel/helper-get-function-arity@^7.0.0":
60-
version "7.0.0"
61-
resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0.tgz#83572d4320e2a4657263734113c42868b64e49c3"
67+
"@babel/helper-get-function-arity@^7.7.4":
68+
version "7.7.4"
69+
resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.7.4.tgz#cb46348d2f8808e632f0ab048172130e636005f0"
70+
integrity sha512-QTGKEdCkjgzgfJ3bAyRwF4yyT3pg+vDgan8DSivq1eS0gwi+KGKE5x8kRcbeFTb/673mkO5SN1IZfmCfA5o+EA==
6271
dependencies:
63-
"@babel/types" "^7.0.0"
72+
"@babel/types" "^7.7.4"
6473

6574
6675
version "7.0.0-beta.44"
6776
resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0-beta.44.tgz#c0b351735e0fbcb3822c8ad8db4e583b05ebd9dc"
6877
dependencies:
6978
"@babel/types" "7.0.0-beta.44"
7079

71-
"@babel/helper-split-export-declaration@^7.0.0":
72-
version "7.0.0"
73-
resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0.tgz#3aae285c0311c2ab095d997b8c9a94cad547d813"
80+
"@babel/helper-split-export-declaration@^7.7.4":
81+
version "7.7.4"
82+
resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.7.4.tgz#57292af60443c4a3622cf74040ddc28e68336fd8"
83+
integrity sha512-guAg1SXFcVr04Guk9eq0S4/rWS++sbmyqosJzVs8+1fH5NI+ZcmkaSkc7dmtAFbHFva6yRJnjW3yAcGxjueDug==
7484
dependencies:
75-
"@babel/types" "^7.0.0"
85+
"@babel/types" "^7.7.4"
7686

7787
7888
version "7.0.0-beta.44"
@@ -90,9 +100,10 @@
90100
esutils "^2.0.2"
91101
js-tokens "^4.0.0"
92102

93-
"@babel/parser@^7.0.0":
94-
version "7.0.0"
95-
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.0.0.tgz#697655183394facffb063437ddf52c0277698775"
103+
"@babel/parser@^7.7.0", "@babel/parser@^7.7.4":
104+
version "7.7.5"
105+
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.7.5.tgz#cbf45321619ac12d83363fcf9c94bb67fa646d71"
106+
integrity sha512-KNlOe9+/nk4i29g0VXgl8PEXIRms5xKLJeuZ6UptN0fHv+jDiriG+y94X6qAgWTR0h3KaoM1wK5G5h7MHFRSig==
96107

97108
98109
version "7.0.0-beta.44"
@@ -103,13 +114,14 @@
103114
babylon "7.0.0-beta.44"
104115
lodash "^4.2.0"
105116

106-
"@babel/template@^7.0.0":
107-
version "7.0.0"
108-
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.0.0.tgz#c2bc9870405959c89a9c814376a2ecb247838c80"
117+
"@babel/template@^7.7.4":
118+
version "7.7.4"
119+
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.7.4.tgz#428a7d9eecffe27deac0a98e23bf8e3675d2a77b"
120+
integrity sha512-qUzihgVPguAzXCK7WXw8pqs6cEwi54s3E+HrejlkuWO6ivMKx9hZl3Y2fSXp9i5HgyWmj7RKP+ulaYnKM4yYxw==
109121
dependencies:
110122
"@babel/code-frame" "^7.0.0"
111-
"@babel/parser" "^7.0.0"
112-
"@babel/types" "^7.0.0"
123+
"@babel/parser" "^7.7.4"
124+
"@babel/types" "^7.7.4"
113125

114126
115127
version "7.0.0-beta.44"
@@ -126,19 +138,20 @@
126138
invariant "^2.2.0"
127139
lodash "^4.2.0"
128140

129-
"@babel/traverse@^7.0.0":
130-
version "7.0.0"
131-
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.0.0.tgz#b1fe9b6567fdf3ab542cfad6f3b31f854d799a61"
132-
dependencies:
133-
"@babel/code-frame" "^7.0.0"
134-
"@babel/generator" "^7.0.0"
135-
"@babel/helper-function-name" "^7.0.0"
136-
"@babel/helper-split-export-declaration" "^7.0.0"
137-
"@babel/parser" "^7.0.0"
138-
"@babel/types" "^7.0.0"
139-
debug "^3.1.0"
141+
"@babel/traverse@^7.7.0":
142+
version "7.7.4"
143+
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.7.4.tgz#9c1e7c60fb679fe4fcfaa42500833333c2058558"
144+
integrity sha512-P1L58hQyupn8+ezVA2z5KBm4/Zr4lCC8dwKCMYzsa5jFMDMQAzaBNy9W5VjB+KAmBjb40U7a/H6ao+Xo+9saIw==
145+
dependencies:
146+
"@babel/code-frame" "^7.5.5"
147+
"@babel/generator" "^7.7.4"
148+
"@babel/helper-function-name" "^7.7.4"
149+
"@babel/helper-split-export-declaration" "^7.7.4"
150+
"@babel/parser" "^7.7.4"
151+
"@babel/types" "^7.7.4"
152+
debug "^4.1.0"
140153
globals "^11.1.0"
141-
lodash "^4.17.10"
154+
lodash "^4.17.13"
142155

143156
144157
version "7.0.0-beta.44"
@@ -148,12 +161,13 @@
148161
lodash "^4.2.0"
149162
to-fast-properties "^2.0.0"
150163

151-
"@babel/types@^7.0.0":
152-
version "7.0.0"
153-
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.0.0.tgz#6e191793d3c854d19c6749989e3bc55f0e962118"
164+
"@babel/types@^7.7.0", "@babel/types@^7.7.4":
165+
version "7.7.4"
166+
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.7.4.tgz#516570d539e44ddf308c07569c258ff94fde9193"
167+
integrity sha512-cz5Ji23KCi4T+YIE/BolWosrJuSmoZeN1EFnRtBwF+KKLi8GG/Z2c2hOJJeCXPk4mwk4QFvTmwIodJowXgttRA==
154168
dependencies:
155169
esutils "^2.0.2"
156-
lodash "^4.17.10"
170+
lodash "^4.17.13"
157171
to-fast-properties "^2.0.0"
158172

159173
"@samverschueren/stream-to-observable@^0.3.0":
@@ -511,6 +525,13 @@ debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
511525
dependencies:
512526
ms "2.0.0"
513527

528+
debug@^4.1.0:
529+
version "4.1.1"
530+
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
531+
integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==
532+
dependencies:
533+
ms "^2.1.1"
534+
514535
decode-uri-component@^0.2.0:
515536
version "0.2.0"
516537
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
@@ -1440,6 +1461,11 @@ lodash@^4.17.10, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0:
14401461
version "4.17.10"
14411462
resolved "http://registry.npm.taobao.org/lodash/download/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"
14421463

1464+
lodash@^4.17.13:
1465+
version "4.17.15"
1466+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
1467+
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==
1468+
14431469
log-symbols@^1.0.2:
14441470
version "1.0.2"
14451471
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-1.0.2.tgz#376ff7b58ea3086a0f09facc74617eca501e1a18"
@@ -1546,6 +1572,11 @@ [email protected]:
15461572
version "2.0.0"
15471573
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"
15481574

1575+
ms@^2.1.1:
1576+
version "2.1.2"
1577+
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
1578+
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
1579+
15491580
15501581
version "0.0.7"
15511582
resolved "http://registry.npm.taobao.org/mute-stream/download/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"

0 commit comments

Comments
 (0)