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

Commit

Permalink
Update Babel to ^7.7.0 and enable Flow enums parsing (#812)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gkz authored Feb 25, 2020
1 parent 183d13e commit 2c754a8
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 50 deletions.
4 changes: 4 additions & 0 deletions lib/analyze-scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ class Referencer extends OriginalReferencer {
}
}

EnumDeclaration(node) {
this._createScopeVariable(node, node.id);
}

TypeAlias(node) {
this._createScopeVariable(node, node.id);

Expand Down
2 changes: 1 addition & 1 deletion lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(code, options) {
ranges: true,
tokens: true,
plugins: [
["flow", { all: true }],
["flow", { all: true, enums: true }],
"jsx",
"estree",
"asyncFunctions",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
},
"dependencies": {
"@babel/code-frame": "^7.0.0",
"@babel/parser": "^7.0.0",
"@babel/traverse": "^7.0.0",
"@babel/types": "^7.0.0",
"@babel/parser": "^7.7.0",
"@babel/traverse": "^7.7.0",
"@babel/types": "^7.7.0",
"eslint-visitor-keys": "^1.0.0",
"resolve": "^1.12.0"
},
Expand Down
14 changes: 12 additions & 2 deletions test/babel-eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ describe("babylon-to-espree", () => {
});

it("export named", () => {
parseAndAssertSame("export { foo };");
parseAndAssertSame("const foo = 1; export { foo };");
});

it("export named alias", () => {
parseAndAssertSame("export { foo as bar };");
parseAndAssertSame("const foo = 1; export { foo as bar };");
});

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

// Espree doesn't support Flow enums
it("flow enums", () => {
const code = "enum E {A, B}";
const babylonAST = babelEslint.parseForESLint(code, {
eslintVisitorKeys: true,
eslintScopeManager: true,
}).ast;
assert.strictEqual(babylonAST.body[0].type, "EnumDeclaration");
});

it.skip("empty program with line comment", () => {
parseAndAssertSame("// single comment");
});
Expand Down
18 changes: 18 additions & 0 deletions test/non-regression.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,24 @@ describe("verify", () => {
);
});

it("enum declaration", () => {
verifyAndAssertMessages(
`
enum E {
A,
B,
}
E.A;
enum UnusedEnum {
A,
B,
}
`,
{ "no-unused-vars": 1, "no-undef": 1 },
["6:6 'UnusedEnum' is defined but never used. no-unused-vars"]
);
});

it("type parameter bounds (classes)", () => {
verifyAndAssertMessages(
`
Expand Down
119 changes: 75 additions & 44 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
dependencies:
"@babel/highlight" "^7.0.0"

"@babel/code-frame@^7.5.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.5.5.tgz#bc0782f6d69f7b7d49531219699b988f669a8f9d"
integrity sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw==
dependencies:
"@babel/highlight" "^7.0.0"

"@babel/[email protected]":
version "7.0.0-beta.44"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.0.0-beta.44.tgz#c7e67b9b5284afcf69b309b50d7d37f3e5033d42"
Expand All @@ -24,15 +31,15 @@
source-map "^0.5.0"
trim-right "^1.0.1"

"@babel/generator@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.0.0.tgz#1efd58bffa951dc846449e58ce3a1d7f02d393aa"
"@babel/generator@^7.7.4":
version "7.7.4"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.7.4.tgz#db651e2840ca9aa66f327dcec1dc5f5fa9611369"
integrity sha512-m5qo2WgdOJeyYngKImbkyQrnUN1mPceaG5BV+G0E3gWsa4l/jCSryWJdM2x8OuGAOyh+3d5pVYfZWCiNFtynxg==
dependencies:
"@babel/types" "^7.0.0"
"@babel/types" "^7.7.4"
jsesc "^2.5.1"
lodash "^4.17.10"
lodash "^4.17.13"
source-map "^0.5.0"
trim-right "^1.0.1"

"@babel/[email protected]":
version "7.0.0-beta.44"
Expand All @@ -42,37 +49,40 @@
"@babel/template" "7.0.0-beta.44"
"@babel/types" "7.0.0-beta.44"

"@babel/helper-function-name@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.0.0.tgz#a68cc8d04420ccc663dd258f9cc41b8261efa2d4"
"@babel/helper-function-name@^7.7.4":
version "7.7.4"
resolved "https://registry.yarnpkg.com/@babel/helper-function-name/-/helper-function-name-7.7.4.tgz#ab6e041e7135d436d8f0a3eca15de5b67a341a2e"
integrity sha512-AnkGIdiBhEuiwdoMnKm7jfPfqItZhgRaZfMg1XX3bS25INOnLPjPG1Ppnajh8eqgt5kPJnfqrRHqFqmjKDZLzQ==
dependencies:
"@babel/helper-get-function-arity" "^7.0.0"
"@babel/template" "^7.0.0"
"@babel/types" "^7.0.0"
"@babel/helper-get-function-arity" "^7.7.4"
"@babel/template" "^7.7.4"
"@babel/types" "^7.7.4"

"@babel/[email protected]":
version "7.0.0-beta.44"
resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0-beta.44.tgz#d03ca6dd2b9f7b0b1e6b32c56c72836140db3a15"
dependencies:
"@babel/types" "7.0.0-beta.44"

"@babel/helper-get-function-arity@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.0.0.tgz#83572d4320e2a4657263734113c42868b64e49c3"
"@babel/helper-get-function-arity@^7.7.4":
version "7.7.4"
resolved "https://registry.yarnpkg.com/@babel/helper-get-function-arity/-/helper-get-function-arity-7.7.4.tgz#cb46348d2f8808e632f0ab048172130e636005f0"
integrity sha512-QTGKEdCkjgzgfJ3bAyRwF4yyT3pg+vDgan8DSivq1eS0gwi+KGKE5x8kRcbeFTb/673mkO5SN1IZfmCfA5o+EA==
dependencies:
"@babel/types" "^7.0.0"
"@babel/types" "^7.7.4"

"@babel/[email protected]":
version "7.0.0-beta.44"
resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0-beta.44.tgz#c0b351735e0fbcb3822c8ad8db4e583b05ebd9dc"
dependencies:
"@babel/types" "7.0.0-beta.44"

"@babel/helper-split-export-declaration@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0.tgz#3aae285c0311c2ab095d997b8c9a94cad547d813"
"@babel/helper-split-export-declaration@^7.7.4":
version "7.7.4"
resolved "https://registry.yarnpkg.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.7.4.tgz#57292af60443c4a3622cf74040ddc28e68336fd8"
integrity sha512-guAg1SXFcVr04Guk9eq0S4/rWS++sbmyqosJzVs8+1fH5NI+ZcmkaSkc7dmtAFbHFva6yRJnjW3yAcGxjueDug==
dependencies:
"@babel/types" "^7.0.0"
"@babel/types" "^7.7.4"

"@babel/[email protected]":
version "7.0.0-beta.44"
Expand All @@ -90,9 +100,10 @@
esutils "^2.0.2"
js-tokens "^4.0.0"

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

"@babel/[email protected]":
version "7.0.0-beta.44"
Expand All @@ -103,13 +114,14 @@
babylon "7.0.0-beta.44"
lodash "^4.2.0"

"@babel/template@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.0.0.tgz#c2bc9870405959c89a9c814376a2ecb247838c80"
"@babel/template@^7.7.4":
version "7.7.4"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.7.4.tgz#428a7d9eecffe27deac0a98e23bf8e3675d2a77b"
integrity sha512-qUzihgVPguAzXCK7WXw8pqs6cEwi54s3E+HrejlkuWO6ivMKx9hZl3Y2fSXp9i5HgyWmj7RKP+ulaYnKM4yYxw==
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/parser" "^7.0.0"
"@babel/types" "^7.0.0"
"@babel/parser" "^7.7.4"
"@babel/types" "^7.7.4"

"@babel/[email protected]":
version "7.0.0-beta.44"
Expand All @@ -126,19 +138,20 @@
invariant "^2.2.0"
lodash "^4.2.0"

"@babel/traverse@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.0.0.tgz#b1fe9b6567fdf3ab542cfad6f3b31f854d799a61"
dependencies:
"@babel/code-frame" "^7.0.0"
"@babel/generator" "^7.0.0"
"@babel/helper-function-name" "^7.0.0"
"@babel/helper-split-export-declaration" "^7.0.0"
"@babel/parser" "^7.0.0"
"@babel/types" "^7.0.0"
debug "^3.1.0"
"@babel/traverse@^7.7.0":
version "7.7.4"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.7.4.tgz#9c1e7c60fb679fe4fcfaa42500833333c2058558"
integrity sha512-P1L58hQyupn8+ezVA2z5KBm4/Zr4lCC8dwKCMYzsa5jFMDMQAzaBNy9W5VjB+KAmBjb40U7a/H6ao+Xo+9saIw==
dependencies:
"@babel/code-frame" "^7.5.5"
"@babel/generator" "^7.7.4"
"@babel/helper-function-name" "^7.7.4"
"@babel/helper-split-export-declaration" "^7.7.4"
"@babel/parser" "^7.7.4"
"@babel/types" "^7.7.4"
debug "^4.1.0"
globals "^11.1.0"
lodash "^4.17.10"
lodash "^4.17.13"

"@babel/[email protected]":
version "7.0.0-beta.44"
Expand All @@ -148,12 +161,13 @@
lodash "^4.2.0"
to-fast-properties "^2.0.0"

"@babel/types@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.0.0.tgz#6e191793d3c854d19c6749989e3bc55f0e962118"
"@babel/types@^7.7.0", "@babel/types@^7.7.4":
version "7.7.4"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.7.4.tgz#516570d539e44ddf308c07569c258ff94fde9193"
integrity sha512-cz5Ji23KCi4T+YIE/BolWosrJuSmoZeN1EFnRtBwF+KKLi8GG/Z2c2hOJJeCXPk4mwk4QFvTmwIodJowXgttRA==
dependencies:
esutils "^2.0.2"
lodash "^4.17.10"
lodash "^4.17.13"
to-fast-properties "^2.0.0"

"@samverschueren/stream-to-observable@^0.3.0":
Expand Down Expand Up @@ -511,6 +525,13 @@ debug@^2.2.0, debug@^2.3.3, debug@^2.6.8, debug@^2.6.9:
dependencies:
ms "2.0.0"

debug@^4.1.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
integrity sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==
dependencies:
ms "^2.1.1"

decode-uri-component@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
Expand Down Expand Up @@ -1440,6 +1461,11 @@ lodash@^4.17.10, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.2.0:
version "4.17.10"
resolved "http://registry.npm.taobao.org/lodash/download/lodash-4.17.10.tgz#1b7793cf7259ea38fb3661d4d38b3260af8ae4e7"

lodash@^4.17.13:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==

log-symbols@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-1.0.2.tgz#376ff7b58ea3086a0f09facc74617eca501e1a18"
Expand Down Expand Up @@ -1546,6 +1572,11 @@ [email protected]:
version "2.0.0"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8"

ms@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==

[email protected]:
version "0.0.7"
resolved "http://registry.npm.taobao.org/mute-stream/download/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"
Expand Down

0 comments on commit 2c754a8

Please sign in to comment.