From 2c754a8189d290f145e23ac962331fd1abd877bd Mon Sep 17 00:00:00 2001 From: George Zahariev Date: Tue, 25 Feb 2020 15:00:24 -0800 Subject: [PATCH] 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 --- lib/analyze-scope.js | 4 ++ lib/parse.js | 2 +- package.json | 6 +-- test/babel-eslint.js | 14 ++++- test/non-regression.js | 18 +++++++ yarn.lock | 119 ++++++++++++++++++++++++++--------------- 6 files changed, 113 insertions(+), 50 deletions(-) diff --git a/lib/analyze-scope.js b/lib/analyze-scope.js index 9ad95bd2..80bdff09 100644 --- a/lib/analyze-scope.js +++ b/lib/analyze-scope.js @@ -149,6 +149,10 @@ class Referencer extends OriginalReferencer { } } + EnumDeclaration(node) { + this._createScopeVariable(node, node.id); + } + TypeAlias(node) { this._createScopeVariable(node, node.id); diff --git a/lib/parse.js b/lib/parse.js index b23b9dc9..d0fe8e55 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -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", diff --git a/package.json b/package.json index 2b475640..f3fa3617 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/babel-eslint.js b/test/babel-eslint.js index 99b03f25..f0bb1fc8 100644 --- a/test/babel-eslint.js +++ b/test/babel-eslint.js @@ -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 @@ -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"); }); diff --git a/test/non-regression.js b/test/non-regression.js index 4c43b29f..f8d0d16b 100644 --- a/test/non-regression.js +++ b/test/non-regression.js @@ -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( ` diff --git a/yarn.lock b/yarn.lock index 412d5be7..894e2071 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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/generator@7.0.0-beta.44": version "7.0.0-beta.44" resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.0.0-beta.44.tgz#c7e67b9b5284afcf69b309b50d7d37f3e5033d42" @@ -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/helper-function-name@7.0.0-beta.44": version "7.0.0-beta.44" @@ -42,13 +49,14 @@ "@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/helper-get-function-arity@7.0.0-beta.44": version "7.0.0-beta.44" @@ -56,11 +64,12 @@ 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/helper-split-export-declaration@7.0.0-beta.44": version "7.0.0-beta.44" @@ -68,11 +77,12 @@ 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/highlight@7.0.0-beta.44": version "7.0.0-beta.44" @@ -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/template@7.0.0-beta.44": version "7.0.0-beta.44" @@ -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/traverse@7.0.0-beta.44": version "7.0.0-beta.44" @@ -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/types@7.0.0-beta.44": version "7.0.0-beta.44" @@ -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": @@ -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" @@ -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" @@ -1546,6 +1572,11 @@ ms@2.0.0: 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== + mute-stream@0.0.7: version "0.0.7" resolved "http://registry.npm.taobao.org/mute-stream/download/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab"