From 6b4c4ca36a9d1930468fb105c1d88fa4d908c315 Mon Sep 17 00:00:00 2001 From: Kai Cataldo Date: Sat, 11 Mar 2017 22:15:47 -0500 Subject: [PATCH 01/29] Upgrade outdated dependencies --- package.json | 16 ++++---- yarn.lock | 113 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 80 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index 5c616f90..64bcfec3 100644 --- a/package.json +++ b/package.json @@ -12,10 +12,10 @@ "url": "https://github.com/babel/babel-eslint.git" }, "dependencies": { - "babel-code-frame": "^6.16.0", - "babel-traverse": "^6.15.0", - "babel-types": "^6.15.0", - "babylon": "^6.13.0", + "babel-code-frame": "^6.22.0", + "babel-traverse": "^6.23.1", + "babel-types": "^6.23.0", + "babylon": "^6.16.1", "lodash.pickby": "^4.6.0" }, "scripts": { @@ -39,11 +39,11 @@ "homepage": "https://github.com/babel/babel-eslint", "devDependencies": { "babel-eslint": "^7.0.0", - "eslint": "^3.9.1", + "eslint": "^3.17.1", "eslint-config-babel": "^6.0.0", - "eslint-plugin-babel": "^4.0.0", - "eslint-plugin-flowtype": "^2.4.0", - "espree": "^3.3.1", + "eslint-plugin-babel": "^4.1.1", + "eslint-plugin-flowtype": "^2.30.3", + "espree": "^3.4.0", "mocha": "^3.0.0" } } diff --git a/yarn.lock b/yarn.lock index 5cfc9dba..baea50f7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8,14 +8,14 @@ acorn-jsx@^3.0.0: dependencies: acorn "^3.0.4" +acorn@4.0.4: + version "4.0.4" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.4.tgz#17a8d6a7a6c4ef538b814ec9abac2779293bf30a" + acorn@^3.0.4: version "3.3.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a" -acorn@^4.0.1: - version "4.0.4" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.4.tgz#17a8d6a7a6c4ef538b814ec9abac2779293bf30a" - ajv-keywords@^1.0.0: version "1.5.0" resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-1.5.0.tgz#c11e6859eafff83e0dafc416929472eca946aa2c" @@ -67,6 +67,14 @@ babel-code-frame@^6.16.0, babel-code-frame@^6.20.0: esutils "^2.0.2" js-tokens "^2.0.0" +babel-code-frame@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4" + dependencies: + chalk "^1.1.0" + esutils "^2.0.2" + js-tokens "^3.0.0" + babel-eslint@^7.0.0: version "7.1.1" resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-7.1.1.tgz#8a6a884f085aa7060af69cfc77341c2f99370fb2" @@ -77,6 +85,12 @@ babel-eslint@^7.0.0: babylon "^6.13.0" lodash.pickby "^4.6.0" +babel-messages@^6.23.0: + version "6.23.0" + resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.23.0.tgz#f3cdf4703858035b2a2951c6ec5edf6c62f2630e" + dependencies: + babel-runtime "^6.22.0" + babel-messages@^6.8.0: version "6.8.0" resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.8.0.tgz#bf504736ca967e6d65ef0adb5a2a5f947c8e0eb9" @@ -90,6 +104,13 @@ babel-runtime@^6.0.0, babel-runtime@^6.20.0: core-js "^2.4.0" regenerator-runtime "^0.10.0" +babel-runtime@^6.22.0: + version "6.23.0" + resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.23.0.tgz#0a9489f144de70efb3ce4300accdb329e2fc543b" + dependencies: + core-js "^2.4.0" + regenerator-runtime "^0.10.0" + babel-traverse@^6.15.0: version "6.21.0" resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.21.0.tgz#69c6365804f1a4f69eb1213f85b00a818b8c21ad" @@ -104,6 +125,20 @@ babel-traverse@^6.15.0: invariant "^2.2.0" lodash "^4.2.0" +babel-traverse@^6.23.1: + version "6.23.1" + resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.23.1.tgz#d3cb59010ecd06a97d81310065f966b699e14f48" + dependencies: + babel-code-frame "^6.22.0" + babel-messages "^6.23.0" + babel-runtime "^6.22.0" + babel-types "^6.23.0" + babylon "^6.15.0" + debug "^2.2.0" + globals "^9.0.0" + invariant "^2.2.0" + lodash "^4.2.0" + babel-types@^6.15.0, babel-types@^6.21.0: version "6.21.0" resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.21.0.tgz#314b92168891ef6d3806b7f7a917fdf87c11a4b2" @@ -113,10 +148,23 @@ babel-types@^6.15.0, babel-types@^6.21.0: lodash "^4.2.0" to-fast-properties "^1.0.1" +babel-types@^6.23.0: + version "6.23.0" + resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.23.0.tgz#bb17179d7538bad38cd0c9e115d340f77e7e9acf" + dependencies: + babel-runtime "^6.22.0" + esutils "^2.0.2" + lodash "^4.2.0" + to-fast-properties "^1.0.1" + babylon@^6.11.0, babylon@^6.13.0: version "6.15.0" resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.15.0.tgz#ba65cfa1a80e1759b0e89fb562e27dccae70348e" +babylon@^6.15.0, babylon@^6.16.1: + version "6.16.1" + resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.16.1.tgz#30c5a22f481978a9e7f8cdfdf496b11d94b404d3" + balanced-match@^0.4.1: version "0.4.2" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-0.4.2.tgz#cb3f3e3c732dc0f01ee70b403f302e61d7709838" @@ -210,18 +258,12 @@ d@^0.1.1, d@~0.1.1: dependencies: es5-ext "~0.10.2" -debug@2.2.0: +debug@2.2.0, debug@^2.1.1, debug@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da" dependencies: ms "0.7.1" -debug@^2.1.1, debug@^2.2.0: - version "2.6.0" - resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.0.tgz#bc596bcabe7617f11d9fa15361eded5608b8499b" - dependencies: - ms "0.7.2" - deep-is@~0.1.3: version "0.1.3" resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" @@ -318,19 +360,19 @@ eslint-config-babel@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/eslint-config-babel/-/eslint-config-babel-6.0.0.tgz#66feedf6ce6e04abe585cec1a65b5bcc96bed50a" -eslint-plugin-babel@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/eslint-plugin-babel/-/eslint-plugin-babel-4.0.0.tgz#a92114e2c493ac3034b030d7ecf96e174a76ef3f" +eslint-plugin-babel@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/eslint-plugin-babel/-/eslint-plugin-babel-4.1.1.tgz#ef285c87039b67beb3bbd227f5b0eed4fb376b87" -eslint-plugin-flowtype@^2.4.0: - version "2.29.2" - resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.29.2.tgz#91b4fde0400c4c37ca4440b43bdbc95fc405bea9" +eslint-plugin-flowtype@^2.30.3: + version "2.30.3" + resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.30.3.tgz#57835d2c0ed388da7a2725803ec32af2f437c301" dependencies: lodash "^4.15.0" -eslint@^3.9.1: - version "3.13.1" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.13.1.tgz#564d2646b5efded85df96985332edd91a23bff25" +eslint@^3.17.1: + version "3.17.1" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.17.1.tgz#b80ae12d9c406d858406fccda627afce33ea10ea" dependencies: babel-code-frame "^6.16.0" chalk "^1.1.3" @@ -338,7 +380,7 @@ eslint@^3.9.1: debug "^2.1.1" doctrine "^1.2.2" escope "^3.6.0" - espree "^3.3.1" + espree "^3.4.0" estraverse "^4.2.0" esutils "^2.0.2" file-entry-cache "^2.0.0" @@ -367,11 +409,11 @@ eslint@^3.9.1: text-table "~0.2.0" user-home "^2.0.0" -espree@^3.3.1: - version "3.3.2" - resolved "https://registry.yarnpkg.com/espree/-/espree-3.3.2.tgz#dbf3fadeb4ecb4d4778303e50103b3d36c88b89c" +espree@^3.4.0: + version "3.4.0" + resolved "https://registry.yarnpkg.com/espree/-/espree-3.4.0.tgz#41656fa5628e042878025ef467e78f125cb86e1d" dependencies: - acorn "^4.0.1" + acorn "4.0.4" acorn-jsx "^3.0.0" esprima@^2.6.0: @@ -449,7 +491,7 @@ generate-object-property@^1.1.0: dependencies: is-property "^1.0.0" -glob@7.0.5: +glob@7.0.5, glob@^7.0.0, glob@^7.0.3, glob@^7.0.5: version "7.0.5" resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.5.tgz#b4202a69099bbb4d292a7c1b95b6682b67ebdc95" dependencies: @@ -460,17 +502,6 @@ glob@7.0.5: once "^1.3.0" path-is-absolute "^1.0.0" -glob@^7.0.0, glob@^7.0.3, glob@^7.0.5: - version "7.1.1" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" - dependencies: - fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^3.0.2" - once "^1.3.0" - path-is-absolute "^1.0.0" - globals@^9.0.0, globals@^9.14.0: version "9.14.0" resolved "https://registry.yarnpkg.com/globals/-/globals-9.14.0.tgz#8859936af0038741263053b39d0e76ca241e4034" @@ -608,6 +639,10 @@ js-tokens@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-2.0.0.tgz#79903f5563ee778cc1162e6dcf1a0027c97f9cb5" +js-tokens@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7" + js-yaml@^3.5.1: version "3.7.0" resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.7.0.tgz#5c967ddd837a9bfdca5f2de84253abe8a1c03b80" @@ -737,10 +772,6 @@ ms@0.7.1: version "0.7.1" resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098" -ms@0.7.2: - version "0.7.2" - resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.2.tgz#ae25cf2512b3885a1d95d7f037868d8431124765" - mute-stream@0.0.5: version "0.0.5" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.5.tgz#8fbfabb0a98a253d3184331f9e8deb7372fac6c0" From 702d6b8279549df555451e4fe64173eb4b803327 Mon Sep 17 00:00:00 2001 From: Kai Cataldo Date: Mon, 20 Mar 2017 10:27:28 -0400 Subject: [PATCH 02/29] Remove broken ESLint tests --- eslint | 1 - package.json | 2 -- 2 files changed, 3 deletions(-) delete mode 160000 eslint diff --git a/eslint b/eslint deleted file mode 160000 index fdce86d2..00000000 --- a/eslint +++ /dev/null @@ -1 +0,0 @@ -Subproject commit fdce86d24e30a31c0c819262b72ab6b454cb552a diff --git a/package.json b/package.json index 64bcfec3..e5d595ef 100644 --- a/package.json +++ b/package.json @@ -19,8 +19,6 @@ "lodash.pickby": "^4.6.0" }, "scripts": { - "bootstrap": "git submodule update --init && cd eslint && npm install", - "eslint": "cd eslint && mocha -c tests/lib/rules/*.js -r ../eslint-tester.js", "test": "npm run lint && npm run test-only", "test-only": "mocha", "lint": "eslint index.js babylon-to-espree test", From b49ab204a2091861f9645ce95e019ee88a9b08eb Mon Sep 17 00:00:00 2001 From: Kai Cataldo Date: Mon, 20 Mar 2017 10:33:14 -0400 Subject: [PATCH 03/29] Updates ESLint version/remove unnecessary config --- .eslintrc.js | 4 - eslint-tester.js | 6 - package.json | 3 +- yarn.lock | 282 ++++++++++++++++++++++------------------------- 4 files changed, 131 insertions(+), 164 deletions(-) delete mode 100644 eslint-tester.js diff --git a/.eslintrc.js b/.eslintrc.js index 1f91933f..20f31f1e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,10 +1,6 @@ module.exports = { root: true, extends: "babel", - parserOptions: { - ecmaVersion: 7, - sourceType: "module" - }, rules: { "no-var": 0, "max-len": 0 diff --git a/eslint-tester.js b/eslint-tester.js deleted file mode 100644 index 905a625d..00000000 --- a/eslint-tester.js +++ /dev/null @@ -1,6 +0,0 @@ -var ESLintTester = require("./eslint").RuleTester; - -console.log("Use babel-eslint for test suite"); -ESLintTester.setDefaultConfig({ - parser: "../../index" -}); diff --git a/package.json b/package.json index e5d595ef..9babfaba 100644 --- a/package.json +++ b/package.json @@ -37,9 +37,8 @@ "homepage": "https://github.com/babel/babel-eslint", "devDependencies": { "babel-eslint": "^7.0.0", - "eslint": "^3.17.1", + "eslint": "^3.18.0", "eslint-config-babel": "^6.0.0", - "eslint-plugin-babel": "^4.1.1", "eslint-plugin-flowtype": "^2.30.3", "espree": "^3.4.0", "mocha": "^3.0.0" diff --git a/yarn.lock b/yarn.lock index baea50f7..b17637e8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17,12 +17,12 @@ acorn@^3.0.4: resolved "https://registry.yarnpkg.com/acorn/-/acorn-3.3.0.tgz#45e37fb39e8da3f25baee3ff5369e2bb5f22017a" ajv-keywords@^1.0.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-1.5.0.tgz#c11e6859eafff83e0dafc416929472eca946aa2c" + version "1.5.1" + resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-1.5.1.tgz#314dd0a4b3368fad3dfcdc54ede6171b886daf3c" ajv@^4.7.0: - version "4.10.4" - resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.10.4.tgz#c0974dd00b3464984892d6010aa9c2c945933254" + version "4.11.5" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.11.5.tgz#b6ee74657b993a01dce44b7944d56f485828d5bd" dependencies: co "^4.6.0" json-stable-stringify "^1.0.1" @@ -59,15 +59,7 @@ arrify@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d" -babel-code-frame@^6.16.0, babel-code-frame@^6.20.0: - version "6.20.0" - resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.20.0.tgz#b968f839090f9a8bc6d41938fb96cb84f7387b26" - dependencies: - chalk "^1.1.0" - esutils "^2.0.2" - js-tokens "^2.0.0" - -babel-code-frame@^6.22.0: +babel-code-frame@^6.16.0, babel-code-frame@^6.22.0: version "6.22.0" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4" dependencies: @@ -91,19 +83,6 @@ babel-messages@^6.23.0: dependencies: babel-runtime "^6.22.0" -babel-messages@^6.8.0: - version "6.8.0" - resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.8.0.tgz#bf504736ca967e6d65ef0adb5a2a5f947c8e0eb9" - dependencies: - babel-runtime "^6.0.0" - -babel-runtime@^6.0.0, babel-runtime@^6.20.0: - version "6.20.0" - resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.20.0.tgz#87300bdcf4cd770f09bf0048c64204e17806d16f" - dependencies: - core-js "^2.4.0" - regenerator-runtime "^0.10.0" - babel-runtime@^6.22.0: version "6.23.0" resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.23.0.tgz#0a9489f144de70efb3ce4300accdb329e2fc543b" @@ -111,21 +90,7 @@ babel-runtime@^6.22.0: core-js "^2.4.0" regenerator-runtime "^0.10.0" -babel-traverse@^6.15.0: - version "6.21.0" - resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.21.0.tgz#69c6365804f1a4f69eb1213f85b00a818b8c21ad" - dependencies: - babel-code-frame "^6.20.0" - babel-messages "^6.8.0" - babel-runtime "^6.20.0" - babel-types "^6.21.0" - babylon "^6.11.0" - debug "^2.2.0" - globals "^9.0.0" - invariant "^2.2.0" - lodash "^4.2.0" - -babel-traverse@^6.23.1: +babel-traverse@^6.15.0, babel-traverse@^6.23.1: version "6.23.1" resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.23.1.tgz#d3cb59010ecd06a97d81310065f966b699e14f48" dependencies: @@ -139,16 +104,7 @@ babel-traverse@^6.23.1: invariant "^2.2.0" lodash "^4.2.0" -babel-types@^6.15.0, babel-types@^6.21.0: - version "6.21.0" - resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.21.0.tgz#314b92168891ef6d3806b7f7a917fdf87c11a4b2" - dependencies: - babel-runtime "^6.20.0" - esutils "^2.0.2" - lodash "^4.2.0" - to-fast-properties "^1.0.1" - -babel-types@^6.23.0: +babel-types@^6.15.0, babel-types@^6.23.0: version "6.23.0" resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.23.0.tgz#bb17179d7538bad38cd0c9e115d340f77e7e9acf" dependencies: @@ -157,11 +113,7 @@ babel-types@^6.23.0: lodash "^4.2.0" to-fast-properties "^1.0.1" -babylon@^6.11.0, babylon@^6.13.0: - version "6.15.0" - resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.15.0.tgz#ba65cfa1a80e1759b0e89fb562e27dccae70348e" - -babylon@^6.15.0, babylon@^6.16.1: +babylon@^6.13.0, babylon@^6.15.0, babylon@^6.16.1: version "6.16.1" resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.16.1.tgz#30c5a22f481978a9e7f8cdfdf496b11d94b404d3" @@ -236,7 +188,7 @@ concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" -concat-stream@^1.4.6: +concat-stream@^1.5.2: version "1.6.0" resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.0.tgz#0aac662fd52be78964d5532f694784e70110acf7" dependencies: @@ -252,18 +204,24 @@ core-util-is@~1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" -d@^0.1.1, d@~0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/d/-/d-0.1.1.tgz#da184c535d18d8ee7ba2aa229b914009fae11309" +d@1: + version "1.0.0" + resolved "https://registry.yarnpkg.com/d/-/d-1.0.0.tgz#754bb5bfe55451da69a58b94d45f4c5b0462d58f" dependencies: - es5-ext "~0.10.2" + es5-ext "^0.10.9" -debug@2.2.0, debug@^2.1.1, debug@^2.2.0: +debug@2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/debug/-/debug-2.2.0.tgz#f87057e995b1a1f6ae6a4960664137bc56f039da" dependencies: ms "0.7.1" +debug@^2.1.1, debug@^2.2.0: + version "2.6.3" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.3.tgz#0f7eb8c30965ec08c72accfa0130c8b79984141d" + dependencies: + ms "0.7.2" + deep-is@~0.1.3: version "0.1.3" resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" @@ -284,64 +242,64 @@ diff@1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf" -doctrine@^1.2.2: - version "1.5.0" - resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-1.5.0.tgz#379dce730f6166f76cefa4e6707a159b02c5a6fa" +doctrine@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.0.0.tgz#c73d8d2909d22291e1a007a395804da8b665fe63" dependencies: esutils "^2.0.2" isarray "^1.0.0" -es5-ext@^0.10.7, es5-ext@^0.10.8, es5-ext@~0.10.11, es5-ext@~0.10.2, es5-ext@~0.10.7: - version "0.10.12" - resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.12.tgz#aa84641d4db76b62abba5e45fd805ecbab140047" +es5-ext@^0.10.14, es5-ext@^0.10.9, es5-ext@~0.10.14: + version "0.10.14" + resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.14.tgz#625bc9ab9cac0f6fb9dc271525823d1800b3d360" dependencies: es6-iterator "2" es6-symbol "~3.1" -es6-iterator@2: - version "2.0.0" - resolved "https://registry.yarnpkg.com/es6-iterator/-/es6-iterator-2.0.0.tgz#bd968567d61635e33c0b80727613c9cb4b096bac" +es6-iterator@2, es6-iterator@^2.0.1, es6-iterator@~2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/es6-iterator/-/es6-iterator-2.0.1.tgz#8e319c9f0453bf575d374940a655920e59ca5512" dependencies: - d "^0.1.1" - es5-ext "^0.10.7" - es6-symbol "3" + d "1" + es5-ext "^0.10.14" + es6-symbol "^3.1" es6-map@^0.1.3: - version "0.1.4" - resolved "https://registry.yarnpkg.com/es6-map/-/es6-map-0.1.4.tgz#a34b147be224773a4d7da8072794cefa3632b897" - dependencies: - d "~0.1.1" - es5-ext "~0.10.11" - es6-iterator "2" - es6-set "~0.1.3" - es6-symbol "~3.1.0" - event-emitter "~0.3.4" - -es6-set@~0.1.3: - version "0.1.4" - resolved "https://registry.yarnpkg.com/es6-set/-/es6-set-0.1.4.tgz#9516b6761c2964b92ff479456233a247dc707ce8" - dependencies: - d "~0.1.1" - es5-ext "~0.10.11" - es6-iterator "2" - es6-symbol "3" - event-emitter "~0.3.4" - -es6-symbol@3, es6-symbol@~3.1, es6-symbol@~3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.0.tgz#94481c655e7a7cad82eba832d97d5433496d7ffa" + version "0.1.5" + resolved "https://registry.yarnpkg.com/es6-map/-/es6-map-0.1.5.tgz#9136e0503dcc06a301690f0bb14ff4e364e949f0" + dependencies: + d "1" + es5-ext "~0.10.14" + es6-iterator "~2.0.1" + es6-set "~0.1.5" + es6-symbol "~3.1.1" + event-emitter "~0.3.5" + +es6-set@~0.1.5: + version "0.1.5" + resolved "https://registry.yarnpkg.com/es6-set/-/es6-set-0.1.5.tgz#d2b3ec5d4d800ced818db538d28974db0a73ccb1" + dependencies: + d "1" + es5-ext "~0.10.14" + es6-iterator "~2.0.1" + es6-symbol "3.1.1" + event-emitter "~0.3.5" + +es6-symbol@3.1.1, es6-symbol@^3.1, es6-symbol@^3.1.1, es6-symbol@~3.1, es6-symbol@~3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.1.tgz#bf00ef4fdab6ba1b46ecb7b629b4c7ed5715cc77" dependencies: - d "~0.1.1" - es5-ext "~0.10.11" + d "1" + es5-ext "~0.10.14" es6-weak-map@^2.0.1: - version "2.0.1" - resolved "https://registry.yarnpkg.com/es6-weak-map/-/es6-weak-map-2.0.1.tgz#0d2bbd8827eb5fb4ba8f97fbfea50d43db21ea81" + version "2.0.2" + resolved "https://registry.yarnpkg.com/es6-weak-map/-/es6-weak-map-2.0.2.tgz#5e3ab32251ffd1538a1f8e5ffa1357772f92d96f" dependencies: - d "^0.1.1" - es5-ext "^0.10.8" - es6-iterator "2" - es6-symbol "3" + d "1" + es5-ext "^0.10.14" + es6-iterator "^2.0.1" + es6-symbol "^3.1.1" escape-string-regexp@1.0.5, escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: version "1.0.5" @@ -360,27 +318,24 @@ eslint-config-babel@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/eslint-config-babel/-/eslint-config-babel-6.0.0.tgz#66feedf6ce6e04abe585cec1a65b5bcc96bed50a" -eslint-plugin-babel@^4.1.1: - version "4.1.1" - resolved "https://registry.yarnpkg.com/eslint-plugin-babel/-/eslint-plugin-babel-4.1.1.tgz#ef285c87039b67beb3bbd227f5b0eed4fb376b87" - eslint-plugin-flowtype@^2.30.3: version "2.30.3" resolved "https://registry.yarnpkg.com/eslint-plugin-flowtype/-/eslint-plugin-flowtype-2.30.3.tgz#57835d2c0ed388da7a2725803ec32af2f437c301" dependencies: lodash "^4.15.0" -eslint@^3.17.1: - version "3.17.1" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.17.1.tgz#b80ae12d9c406d858406fccda627afce33ea10ea" +eslint@^3.18.0: + version "3.18.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.18.0.tgz#647e985c4ae71502d20ac62c109f66d5104c8a4b" dependencies: babel-code-frame "^6.16.0" chalk "^1.1.3" - concat-stream "^1.4.6" + concat-stream "^1.5.2" debug "^2.1.1" - doctrine "^1.2.2" + doctrine "^2.0.0" escope "^3.6.0" espree "^3.4.0" + esquery "^1.0.0" estraverse "^4.2.0" esutils "^2.0.2" file-entry-cache "^2.0.0" @@ -416,9 +371,15 @@ espree@^3.4.0: acorn "4.0.4" acorn-jsx "^3.0.0" -esprima@^2.6.0: - version "2.7.3" - resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581" +esprima@^3.1.1: + version "3.1.3" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633" + +esquery@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.0.0.tgz#cfba8b57d7fba93f17298a8a006a04cda13d80fa" + dependencies: + estraverse "^4.0.0" esrecurse@^4.1.0: version "4.1.0" @@ -427,7 +388,7 @@ esrecurse@^4.1.0: estraverse "~4.1.0" object-assign "^4.0.1" -estraverse@^4.1.1, estraverse@^4.2.0: +estraverse@^4.0.0, estraverse@^4.1.1, estraverse@^4.2.0: version "4.2.0" resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13" @@ -439,12 +400,12 @@ esutils@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" -event-emitter@~0.3.4: - version "0.3.4" - resolved "https://registry.yarnpkg.com/event-emitter/-/event-emitter-0.3.4.tgz#8d63ddfb4cfe1fae3b32ca265c4c720222080bb5" +event-emitter@~0.3.5: + version "0.3.5" + resolved "https://registry.yarnpkg.com/event-emitter/-/event-emitter-0.3.5.tgz#df8c69eef1647923c7157b9ce83840610b02cc39" dependencies: - d "~0.1.1" - es5-ext "~0.10.7" + d "1" + es5-ext "~0.10.14" exit-hook@^1.0.0: version "1.1.1" @@ -491,7 +452,7 @@ generate-object-property@^1.1.0: dependencies: is-property "^1.0.0" -glob@7.0.5, glob@^7.0.0, glob@^7.0.3, glob@^7.0.5: +glob@7.0.5: version "7.0.5" resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.5.tgz#b4202a69099bbb4d292a7c1b95b6682b67ebdc95" dependencies: @@ -502,9 +463,20 @@ glob@7.0.5, glob@^7.0.0, glob@^7.0.3, glob@^7.0.5: once "^1.3.0" path-is-absolute "^1.0.0" +glob@^7.0.0, glob@^7.0.3, glob@^7.0.5: + version "7.1.1" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.2" + once "^1.3.0" + path-is-absolute "^1.0.0" + globals@^9.0.0, globals@^9.14.0: - version "9.14.0" - resolved "https://registry.yarnpkg.com/globals/-/globals-9.14.0.tgz#8859936af0038741263053b39d0e76ca241e4034" + version "9.16.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-9.16.0.tgz#63e903658171ec2d9f51b1d31de5e2b8dc01fb80" globby@^5.0.0: version "5.0.0" @@ -540,8 +512,8 @@ has-flag@^1.0.0: resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa" ignore@^3.2.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.2.0.tgz#8d88f03c3002a0ac52114db25d2c673b0bf1e435" + version "3.2.6" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.2.6.tgz#26e8da0644be0bb4cb39516f6c79f0e0f4ffe48c" imurmurhash@^0.1.4: version "0.1.4" @@ -597,8 +569,8 @@ is-fullwidth-code-point@^2.0.0: resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" is-my-json-valid@^2.10.0: - version "2.15.0" - resolved "https://registry.yarnpkg.com/is-my-json-valid/-/is-my-json-valid-2.15.0.tgz#936edda3ca3c211fd98f3b2d3e08da43f7b2915b" + version "2.16.0" + resolved "https://registry.yarnpkg.com/is-my-json-valid/-/is-my-json-valid-2.16.0.tgz#f079dd9bfdae65ee2038aae8acbc86ab109e3693" dependencies: generate-function "^2.0.0" generate-object-property "^1.1.0" @@ -635,20 +607,16 @@ isarray@^1.0.0, isarray@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" -js-tokens@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-2.0.0.tgz#79903f5563ee778cc1162e6dcf1a0027c97f9cb5" - js-tokens@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.1.tgz#08e9f132484a2c45a30907e9dc4d5567b7f114d7" js-yaml@^3.5.1: - version "3.7.0" - resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.7.0.tgz#5c967ddd837a9bfdca5f2de84253abe8a1c03b80" + version "3.8.2" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.8.2.tgz#02d3e2c0f6beab20248d412c352203827d786721" dependencies: argparse "^1.0.7" - esprima "^2.6.0" + esprima "^3.1.1" json-stable-stringify@^1.0.0, json-stable-stringify@^1.0.1: version "1.0.1" @@ -731,10 +699,10 @@ lodash@^4.0.0, lodash@^4.15.0, lodash@^4.2.0, lodash@^4.3.0: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" loose-envify@^1.0.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.0.tgz#6b26248c42f6d4fa4b0d8542f78edfcde35642a8" + version "1.3.1" + resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848" dependencies: - js-tokens "^2.0.0" + js-tokens "^3.0.0" minimatch@^3.0.2: version "3.0.3" @@ -772,6 +740,10 @@ ms@0.7.1: version "0.7.1" resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.1.tgz#9cd13c03adbff25b65effde7ce864ee952017098" +ms@0.7.2: + version "0.7.2" + resolved "https://registry.yarnpkg.com/ms/-/ms-0.7.2.tgz#ae25cf2512b3885a1d95d7f037868d8431124765" + mute-stream@0.0.5: version "0.0.5" resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.5.tgz#8fbfabb0a98a253d3184331f9e8deb7372fac6c0" @@ -785,8 +757,8 @@ number-is-nan@^1.0.0: resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" object-assign@^4.0.1, object-assign@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.0.tgz#7a3b3d0e98063d43f4c03f2e8ae6cd51a86883a0" + version "4.1.1" + resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" once@^1.3.0: version "1.4.0" @@ -821,6 +793,10 @@ path-is-inside@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/path-is-inside/-/path-is-inside-1.0.2.tgz#365417dede44430d1c11af61027facf074bdfc53" +path-parse@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1" + pify@^2.0.0: version "2.3.0" resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c" @@ -852,8 +828,8 @@ progress@^1.1.8: resolved "https://registry.yarnpkg.com/progress/-/progress-1.1.8.tgz#e260c78f6161cdd9b0e56cc3e0a85de17c7a57be" readable-stream@^2.2.2: - version "2.2.2" - resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.2.tgz#a9e6fec3c7dda85f8bb1b3ba7028604556fc825e" + version "2.2.6" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.6.tgz#8b43aed76e71483938d12a8d46c6cf1a00b1f816" dependencies: buffer-shims "^1.0.0" core-util-is "~1.0.0" @@ -878,8 +854,8 @@ rechoir@^0.6.2: resolve "^1.1.6" regenerator-runtime@^0.10.0: - version "0.10.1" - resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.1.tgz#257f41961ce44558b18f7814af48c17559f9faeb" + version "0.10.3" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.3.tgz#8c4367a904b51ea62a908ac310bf99ff90a82a3e" require-uncached@^1.0.2: version "1.0.3" @@ -893,8 +869,10 @@ resolve-from@^1.0.0: resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226" resolve@^1.1.6: - version "1.2.0" - resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.2.0.tgz#9589c3f2f6149d1417a40becc1663db6ec6bc26c" + version "1.3.2" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.3.2.tgz#1f0442c9e0cbb8136e87b9305f932f46c7f28235" + dependencies: + path-parse "^1.0.5" restore-cursor@^1.0.1: version "1.0.1" @@ -904,8 +882,8 @@ restore-cursor@^1.0.1: onetime "^1.0.0" rimraf@^2.2.8: - version "2.5.4" - resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.5.4.tgz#96800093cbf1a0c86bd95b4625467535c29dfa04" + version "2.6.1" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.1.tgz#c2338ec643df7a1b7fe5c54fa86f57428a55f33d" dependencies: glob "^7.0.5" @@ -920,8 +898,8 @@ rx-lite@^3.1.2: resolved "https://registry.yarnpkg.com/rx-lite/-/rx-lite-3.1.2.tgz#19ce502ca572665f3b647b10939f97fd1615f102" shelljs@^0.7.5: - version "0.7.6" - resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.6.tgz#379cccfb56b91c8601e4793356eb5382924de9ad" + version "0.7.7" + resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.7.tgz#b2f5c77ef97148f4b4f6e22682e10bba8667cff1" dependencies: glob "^7.0.0" interpret "^1.0.0" From 515adefc54bb6097ad2fdc076614606ad0ae4262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Couto?= Date: Mon, 20 Mar 2017 21:45:11 +0000 Subject: [PATCH 04/29] Add option to disable code frame. (#446) * Add option to disable code hightlight. * Rename codeHighlight with codeFrame * Add codeFrame tests * Remove colors from test assertions --- index.js | 19 ++++++++---- test/fixtures/rules/syntax-error.js | 6 ++++ test/integration.js | 48 +++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 test/fixtures/rules/syntax-error.js diff --git a/index.js b/index.js index 7b742494..22e791b3 100644 --- a/index.js +++ b/index.js @@ -366,6 +366,7 @@ exports.parse = function (code, options) { exports.parseNoPatch = function (code, options) { var opts = { + codeFrame: options.hasOwnProperty("codeFrame") ? options.codeFrame : true, sourceType: options.sourceType, allowImportExportEverywhere: options.allowImportExportEverywhere, // consistent with espree allowReturnOutsideFunction: true, @@ -394,14 +395,20 @@ exports.parseNoPatch = function (code, options) { ast = parse(code, opts); } catch (err) { if (err instanceof SyntaxError) { + err.lineNumber = err.loc.line; - err.column = err.loc.column + 1; + err.column = err.loc.column; + + if (opts.codeFrame) { + err.lineNumber = err.loc.line; + err.column = err.loc.column + 1; - // remove trailing "(LINE:COLUMN)" acorn message and add in esprima syntax error message start - err.message = "Line " + err.lineNumber + ": " + err.message.replace(/ \((\d+):(\d+)\)$/, "") + - // add codeframe - "\n\n" + - codeFrame(code, err.lineNumber, err.column, { highlightCode: true }); + // remove trailing "(LINE:COLUMN)" acorn message and add in esprima syntax error message start + err.message = "Line " + err.lineNumber + ": " + err.message.replace(/ \((\d+):(\d+)\)$/, "") + + // add codeframe + "\n\n" + + codeFrame(code, err.lineNumber, err.column, { highlightCode: true }); + } } throw err; diff --git a/test/fixtures/rules/syntax-error.js b/test/fixtures/rules/syntax-error.js new file mode 100644 index 00000000..6fa194a1 --- /dev/null +++ b/test/fixtures/rules/syntax-error.js @@ -0,0 +1,6 @@ +class ClassName { + constructor() { + + }, + aMethod() {} +} diff --git a/test/integration.js b/test/integration.js index 2814b4c3..c446ed34 100644 --- a/test/integration.js +++ b/test/integration.js @@ -200,4 +200,52 @@ function strictSuite () { // it }); // describe + describe("When \"codeFrame\"", () => { + // Strip chalk colors, these are not relevant for the test + const stripAnsi = (str) => str.replace( + /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, + "" + ); + + it("should display codeFrame when option is absent", (done) => { + lint({ + fixture: ["syntax-error"], + eslint: baseEslintOpts + }, (err, report) => { + if (err) return done(err); + assert(stripAnsi(report[0].message).indexOf("^\n 5 |") > -1); + done(); + }); + }); + + it("should display codeFrame when option is true", (done) => { + lint({ + fixture: ["syntax-error"], + eslint: Object.assign({}, baseEslintOpts, { + parserOptions: { + codeFrame: true + } + }) + }, (err, report) => { + if (err) return done(err); + assert(stripAnsi(report[0].message).indexOf("^\n 5 |") > -1); + done(); + }); + }); + + it("should not display codeFrame when option is false", (done) => { + lint({ + fixture: ["syntax-error"], + eslint: Object.assign({}, baseEslintOpts, { + parserOptions: { + codeFrame: false + } + }) + }, (err, report) => { + if (err) return done(err); + assert(stripAnsi(report[0].message).indexOf("^\n 5 |") === -1); + done(); + }); + }); + }); } From a2c3b30e6a86a39e0cb44a95a1990ca54415bd1f Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Mon, 20 Mar 2017 14:46:07 -0700 Subject: [PATCH 05/29] [flow] Process polymorphic type bounds on functions (#444) --- index.js | 13 +++++++++++++ test/non-regression.js | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 22e791b3..3bb83811 100644 --- a/index.js +++ b/index.js @@ -176,6 +176,18 @@ function monkeypatch() { } } + function visitTypeParameters(typeParameters) { + var params = typeParameters.params; + + // visit bounds on polymorphpic types, eg; `Foo` in `fn(a: T): T` + for (var i = 0; i < params.length; i++) { + var param = params[i]; + if (param.typeAnnotation) { + visitTypeAnnotation.call(this, param.typeAnnotation); + } + } + } + function checkIdentifierOrVisit(node) { if (node.typeAnnotation) { visitTypeAnnotation.call(this, node.typeAnnotation); @@ -249,6 +261,7 @@ function monkeypatch() { var typeParamScope; if (node.typeParameters) { typeParamScope = nestTypeParamScope(this.scopeManager, node); + visitTypeParameters.call(this, node.typeParameters); } if (node.returnType) { checkIdentifierOrVisit.call(this, node.returnType); diff --git a/test/non-regression.js b/test/non-regression.js index ee8c03a9..395a6de5 100644 --- a/test/non-regression.js +++ b/test/non-regression.js @@ -222,13 +222,13 @@ describe("verify", () => { ); }); - it("type parameters", () => { + it("type parameter bounds", () => { verifyAndAssertMessages( unpad(` import type Foo from 'foo'; import type Foo2 from 'foo'; - function log(a: T1, b: T2) { return a + b; } - log(1, 2); + function log(a: T1, b: T2) { return a + b; } + log(1, 2); `), { "no-unused-vars": 1, "no-undef": 1 }, [] From 44994124941b1e50772ee2661cf5d8c910105308 Mon Sep 17 00:00:00 2001 From: wtgtybhertgeghgtwtg Date: Mon, 20 Mar 2017 14:50:09 -0700 Subject: [PATCH 06/29] Use `lodash` instead of `lodash.pickby`. (#435) --- index.js | 2 +- package.json | 2 +- yarn.lock | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 3bb83811..fea9d054 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ var babylonToEspree = require("./babylon-to-espree"); -var pick = require("lodash.pickby"); +var pick = require("lodash").pickBy; var Module = require("module"); var path = require("path"); var parse = require("babylon").parse; diff --git a/package.json b/package.json index 9babfaba..5996554d 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "babel-traverse": "^6.23.1", "babel-types": "^6.23.0", "babylon": "^6.16.1", - "lodash.pickby": "^4.6.0" + "lodash": "^4.17.4" }, "scripts": { "test": "npm run lint && npm run test-only", diff --git a/yarn.lock b/yarn.lock index b17637e8..9cb3a50a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -250,8 +250,8 @@ doctrine@^2.0.0: isarray "^1.0.0" es5-ext@^0.10.14, es5-ext@^0.10.9, es5-ext@~0.10.14: - version "0.10.14" - resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.14.tgz#625bc9ab9cac0f6fb9dc271525823d1800b3d360" + version "0.10.15" + resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.15.tgz#c330a5934c1ee21284a7c081a86e5fd937c91ea6" dependencies: es6-iterator "2" es6-symbol "~3.1" @@ -694,7 +694,7 @@ lodash.pickby@^4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash.pickby/-/lodash.pickby-4.6.0.tgz#7dea21d8c18d7703a27c704c15d3b84a67e33aff" -lodash@^4.0.0, lodash@^4.15.0, lodash@^4.2.0, lodash@^4.3.0: +lodash@^4.0.0, lodash@^4.15.0, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" From 4db4db54d18d5d2833ed9a02c5e4cde20474e995 Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Mon, 20 Mar 2017 17:53:26 -0400 Subject: [PATCH 07/29] 7.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5996554d..5909e7f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "babel-eslint", - "version": "7.1.1", + "version": "7.2.0", "description": "Custom parser for ESLint", "main": "index.js", "files": [ From 7972a052e72f44802d0860c5491abe80158a7e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Couto?= Date: Tue, 21 Mar 2017 00:11:30 +0000 Subject: [PATCH 08/29] Update README.md with codeFrame option (#448) --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ff6e41a5..fc5a5403 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ Check out the [ESLint docs](http://eslint.org/docs/rules/) for all possible rule `sourceType` can be set to `'module'`(default) or `'script'` if your code isn't using ECMAScript modules. `allowImportExportEverywhere` can be set to true to allow import and export declarations to appear anywhere a statement is allowed if your build environment supports that. By default, import and export declarations can only appear at a program's top level. +`codeFrame` can be set to false to disable the code frame in the reporter. This is useful since some eslint formatters don't play well with it. **.eslintrc** @@ -86,7 +87,8 @@ Check out the [ESLint docs](http://eslint.org/docs/rules/) for all possible rule "parser": "babel-eslint", "parserOptions": { "sourceType": "module", - "allowImportExportEverywhere": false + "allowImportExportEverywhere": false, + "codeFrame": false } } ``` From eb05812e8d3d7e203fa555f42288ff3e0ed8bd5f Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Wed, 22 Mar 2017 22:34:13 -0400 Subject: [PATCH 09/29] Format non-regression errors for legibility (#451) --- test/non-regression.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/non-regression.js b/test/non-regression.js index 395a6de5..ba83722a 100644 --- a/test/non-regression.js +++ b/test/non-regression.js @@ -31,7 +31,7 @@ function verifyAndAssertMessages(code, rules, expectedMessages, sourceType, over var messages = eslint.linter.verify(code, config); if (messages.length !== expectedMessages.length) { - throw new Error(`Expected ${expectedMessages.length} message(s), got ${messages.length} ${JSON.stringify(messages)}`); + throw new Error(`Expected ${expectedMessages.length} message(s), got ${messages.length}\n${JSON.stringify(messages, null, 2)}`); } messages.forEach((message, i) => { From f1cee0f23193fb222270d69986313a3bd2453ba6 Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Wed, 22 Mar 2017 22:35:31 -0400 Subject: [PATCH 10/29] Remove lodash dependency (#450) --- index.js | 30 +++++++++++++++++------------- package.json | 3 +-- yarn.lock | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/index.js b/index.js index fea9d054..39b6142a 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,4 @@ var babylonToEspree = require("./babylon-to-espree"); -var pick = require("lodash").pickBy; var Module = require("module"); var path = require("path"); var parse = require("babylon").parse; @@ -100,18 +99,23 @@ function monkeypatch() { } // iterate through part of t.VISITOR_KEYS - var visitorKeysMap = pick(t.VISITOR_KEYS, (k) => { - return t.FLIPPED_ALIAS_KEYS.Flow.concat([ - "ArrayPattern", - "ClassDeclaration", - "ClassExpression", - "FunctionDeclaration", - "FunctionExpression", - "Identifier", - "ObjectPattern", - "RestElement" - ]).indexOf(k) === -1; - }); + var flowFlippedAliasKeys = t.FLIPPED_ALIAS_KEYS.Flow.concat([ + "ArrayPattern", + "ClassDeclaration", + "ClassExpression", + "FunctionDeclaration", + "FunctionExpression", + "Identifier", + "ObjectPattern", + "RestElement" + ]); + var visitorKeysMap = Object.keys(t.VISITOR_KEYS).reduce(function(acc, key) { + var value = t.VISITOR_KEYS[key]; + if (flowFlippedAliasKeys.indexOf(value) === -1) { + acc[key] = value; + } + return acc; + }, {}); var propertyTypes = { // loops diff --git a/package.json b/package.json index 5909e7f9..64fff599 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,7 @@ "babel-code-frame": "^6.22.0", "babel-traverse": "^6.23.1", "babel-types": "^6.23.0", - "babylon": "^6.16.1", - "lodash": "^4.17.4" + "babylon": "^6.16.1" }, "scripts": { "test": "npm run lint && npm run test-only", diff --git a/yarn.lock b/yarn.lock index 9cb3a50a..afb72f46 100644 --- a/yarn.lock +++ b/yarn.lock @@ -694,7 +694,7 @@ lodash.pickby@^4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash.pickby/-/lodash.pickby-4.6.0.tgz#7dea21d8c18d7703a27c704c15d3b84a67e33aff" -lodash@^4.0.0, lodash@^4.15.0, lodash@^4.17.4, lodash@^4.2.0, lodash@^4.3.0: +lodash@^4.0.0, lodash@^4.15.0, lodash@^4.2.0, lodash@^4.3.0: version "4.17.4" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" From b5fb53b718d15e95252197b5f30787ca807d069a Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Thu, 23 Mar 2017 12:49:19 -0400 Subject: [PATCH 11/29] Fix type param and interface declaration scoping (#449) --- index.js | 40 +++++++++++++++------------ test/non-regression.js | 63 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 83 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index 39b6142a..8d05f794 100644 --- a/index.js +++ b/index.js @@ -180,18 +180,6 @@ function monkeypatch() { } } - function visitTypeParameters(typeParameters) { - var params = typeParameters.params; - - // visit bounds on polymorphpic types, eg; `Foo` in `fn(a: T): T` - for (var i = 0; i < params.length; i++) { - var param = params[i]; - if (param.typeAnnotation) { - visitTypeAnnotation.call(this, param.typeAnnotation); - } - } - } - function checkIdentifierOrVisit(node) { if (node.typeAnnotation) { visitTypeAnnotation.call(this, node.typeAnnotation); @@ -209,6 +197,9 @@ function monkeypatch() { for (var j = 0; j < node.typeParameters.params.length; j++) { var name = node.typeParameters.params[j]; scope.__define(name, new Definition("TypeParameter", name, name)); + if (name.typeAnnotation) { + checkIdentifierOrVisit.call(this, name); + } } scope.__define = function() { return parentScope.__define.apply(parentScope, arguments); @@ -222,7 +213,7 @@ function monkeypatch() { visitDecorators.call(this, node); var typeParamScope; if (node.typeParameters) { - typeParamScope = nestTypeParamScope(this.scopeManager, node); + typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node); } // visit flow type: ClassImplements if (node.implements) { @@ -264,8 +255,7 @@ function monkeypatch() { referencer.prototype.visitFunction = function(node) { var typeParamScope; if (node.typeParameters) { - typeParamScope = nestTypeParamScope(this.scopeManager, node); - visitTypeParameters.call(this, node.typeParameters); + typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node); } if (node.returnType) { checkIdentifierOrVisit.call(this, node.returnType); @@ -328,11 +318,27 @@ function monkeypatch() { ); } + referencer.prototype.InterfaceDeclaration = function(node) { + createScopeVariable.call(this, node, node.id); + var typeParamScope; + if (node.typeParameters) { + typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node); + } + // TODO: Handle mixins + for (var i = 0; i < node.extends.length; i++) { + visitTypeAnnotation.call(this, node.extends[i]); + } + visitTypeAnnotation.call(this, node.body); + if (typeParamScope) { + this.close(node); + } + }; + referencer.prototype.TypeAlias = function(node) { createScopeVariable.call(this, node, node.id); var typeParamScope; if (node.typeParameters) { - typeParamScope = nestTypeParamScope(this.scopeManager, node); + typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node); } if (node.right) { visitTypeAnnotation.call(this, node.right); @@ -352,7 +358,7 @@ function monkeypatch() { var typeParamScope; if (node.typeParameters) { - typeParamScope = nestTypeParamScope(this.scopeManager, node); + typeParamScope = nestTypeParamScope.call(this, this.scopeManager, node); } if (typeParamScope) { this.close(node); diff --git a/test/non-regression.js b/test/non-regression.js index ba83722a..107802ce 100644 --- a/test/non-regression.js +++ b/test/non-regression.js @@ -222,16 +222,73 @@ describe("verify", () => { ); }); - it("type parameter bounds", () => { + it("interface declaration", () => { + verifyAndAssertMessages( + unpad(` + interface Foo {}; + interface Bar { + foo: Foo, + }; + `), + { "no-unused-vars": 1, "no-undef": 1 }, + [ "2:11 'Bar' is defined but never used. no-unused-vars" ] + ); + }); + + it("type parameter bounds (classes)", () => { + verifyAndAssertMessages( + unpad(` + import type {Foo, Foo2} from 'foo'; + import Base from 'base'; + class Log extends Base { + messages: {[T1]: T2}; + } + new Log(); + `), + { "no-unused-vars": 1, "no-undef": 1 }, + [ "3:34 'T4' is defined but never used. no-unused-vars" ] + ); + }); + + it("type parameter bounds (interfaces)", () => { + verifyAndAssertMessages( + unpad(` + import type {Foo, Foo2, Bar} from ''; + interface Log extends Bar { + messages: {[T1]: T2}; + } + `), + { "no-unused-vars": 1, "no-undef": 1 }, + [ "2:11 'Log' is defined but never used. no-unused-vars", + "2:38 'T4' is defined but never used. no-unused-vars" ] + ); + }); + + it("type parameter bounds (type aliases)", () => { + verifyAndAssertMessages( + unpad(` + import type {Foo, Foo2, Foo3} from 'foo'; + type Log = { + messages: {[T1]: T2}; + delay: Foo3; + }; + `), + { "no-unused-vars": 1, "no-undef": 1 }, + [ "2:6 'Log' is defined but never used. no-unused-vars", + "2:29 'T3' is defined but never used. no-unused-vars" ] + ); + }); + + it("type parameter bounds (functions)", () => { verifyAndAssertMessages( unpad(` import type Foo from 'foo'; import type Foo2 from 'foo'; - function log(a: T1, b: T2) { return a + b; } + function log(a: T1, b: T2): T3 { return a + b; } log(1, 2); `), { "no-unused-vars": 1, "no-undef": 1 }, - [] + [ "3:37 'T4' is defined but never used. no-unused-vars" ] ); }); From 5626de120d866f7c99df78566af2514a1674199c Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Thu, 23 Mar 2017 14:02:24 -0400 Subject: [PATCH 12/29] Remove left over eslint 2 estraverse code (#452) This was missed in #361 --- index.js | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index 8d05f794..3b243cc8 100644 --- a/index.js +++ b/index.js @@ -36,17 +36,12 @@ function monkeypatch() { // get modules relative to what eslint will load var eslintMod = createModule(eslintLoc); - // contains all the instances of estraverse so we can modify them if necessary - var estraverses = []; // ESLint v1.9.0 uses estraverse directly to work around https://github.com/npm/npm/issues/9663 - var estraverseOfEslint = eslintMod.require("estraverse"); - estraverses.push(estraverseOfEslint); - Object.assign(estraverseOfEslint.VisitorKeys, t.VISITOR_KEYS); + var estraverse = eslintMod.require("estraverse"); - estraverses.forEach((estraverse) => { - estraverse.VisitorKeys.MethodDefinition.push("decorators"); - estraverse.VisitorKeys.Property.push("decorators"); - }); + Object.assign(estraverse.VisitorKeys, t.VISITOR_KEYS); + estraverse.VisitorKeys.MethodDefinition.push("decorators"); + estraverse.VisitorKeys.Property.push("decorators"); // monkeypatch escope var escopeLoc = Module._resolveFilename("escope", eslintMod); @@ -275,16 +270,12 @@ function monkeypatch() { } // set ArrayPattern/ObjectPattern visitor keys back to their original. otherwise // escope will traverse into them and include the identifiers within as declarations - estraverses.forEach((estraverse) => { - estraverse.VisitorKeys.ObjectPattern = ["properties"]; - estraverse.VisitorKeys.ArrayPattern = ["elements"]; - }); + estraverse.VisitorKeys.ObjectPattern = ["properties"]; + estraverse.VisitorKeys.ArrayPattern = ["elements"]; visitFunction.call(this, node); // set them back to normal... - estraverses.forEach((estraverse) => { - estraverse.VisitorKeys.ObjectPattern = t.VISITOR_KEYS.ObjectPattern; - estraverse.VisitorKeys.ArrayPattern = t.VISITOR_KEYS.ArrayPattern; - }); + estraverse.VisitorKeys.ObjectPattern = t.VISITOR_KEYS.ObjectPattern; + estraverse.VisitorKeys.ArrayPattern = t.VISITOR_KEYS.ArrayPattern; if (typeParamScope) { this.close(node); } From 3cda62ee066c741b766526155dcdb98db1a2a2d5 Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Thu, 23 Mar 2017 14:03:23 -0400 Subject: [PATCH 13/29] 7.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 64fff599..4b3acc0a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "babel-eslint", - "version": "7.2.0", + "version": "7.2.1", "description": "Custom parser for ESLint", "main": "index.js", "files": [ From 21dac7391470b8eb24a07cd11c527293df3c7a23 Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Thu, 23 Mar 2017 15:46:48 -0400 Subject: [PATCH 14/29] Add type parameter scope tests (#454) --- test/non-regression.js | 60 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/test/non-regression.js b/test/non-regression.js index 107802ce..711aa25e 100644 --- a/test/non-regression.js +++ b/test/non-regression.js @@ -250,6 +250,21 @@ describe("verify", () => { ); }); + it("type parameter scope (classes)", () => { + verifyAndAssertMessages( + unpad(` + T; + class Foo {} + T; + new Foo(); + `), + { "no-unused-vars": 1, "no-undef": 1 }, + [ "1:1 'T' is not defined. no-undef", + "2:11 'T' is defined but never used. no-unused-vars", + "3:1 'T' is not defined. no-undef" ] + ); + }); + it("type parameter bounds (interfaces)", () => { verifyAndAssertMessages( unpad(` @@ -264,6 +279,21 @@ describe("verify", () => { ); }); + it("type parameter scope (interfaces)", () => { + verifyAndAssertMessages( + unpad(` + T; + interface Foo {}; + T; + Foo; + `), + { "no-unused-vars": 1, "no-undef": 1 }, + [ "1:1 'T' is not defined. no-undef", + "2:15 'T' is defined but never used. no-unused-vars", + "3:1 'T' is not defined. no-undef" ] + ); + }); + it("type parameter bounds (type aliases)", () => { verifyAndAssertMessages( unpad(` @@ -279,6 +309,21 @@ describe("verify", () => { ); }); + it("type parameter scope (type aliases)", () => { + verifyAndAssertMessages( + unpad(` + T; + type Foo = {}; + T; + Foo; + `), + { "no-unused-vars": 1, "no-undef": 1 }, + [ "1:1 'T' is not defined. no-undef", + "2:10 'T' is defined but never used. no-unused-vars", + "3:1 'T' is not defined. no-undef" ] + ); + }); + it("type parameter bounds (functions)", () => { verifyAndAssertMessages( unpad(` @@ -292,6 +337,21 @@ describe("verify", () => { ); }); + it("type parameter scope (functions)", () => { + verifyAndAssertMessages( + unpad(` + T; + function log() {} + T; + log; + `), + { "no-unused-vars": 1, "no-undef": 1 }, + [ "1:1 'T' is not defined. no-undef", + "2:14 'T' is defined but never used. no-unused-vars", + "3:1 'T' is not defined. no-undef" ] + ); + }); + it("nested type annotations", () => { verifyAndAssertMessages( unpad(` From 2541fc93b9bacf179661d8e27e040afe011e2926 Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Sat, 25 Mar 2017 00:18:57 -0400 Subject: [PATCH 15/29] toAst pass "source" in state instead of keeping in scope --- babylon-to-espree/toAST.js | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/babylon-to-espree/toAST.js b/babylon-to-espree/toAST.js index c26fa5ba..ba1e8d74 100644 --- a/babylon-to-espree/toAST.js +++ b/babylon-to-espree/toAST.js @@ -1,18 +1,16 @@ -var source; - module.exports = function (ast, traverse, code) { - source = code; + var state = { source: code }; ast.range = [ast.start, ast.end]; - traverse(ast, astTransformVisitor); + traverse(ast, astTransformVisitor, null, state); }; -function changeToLiteral(node) { +function changeToLiteral(node, state) { node.type = "Literal"; if (!node.raw) { if (node.extra && node.extra.raw) { node.raw = node.extra.raw; } else { - node.raw = source.slice(node.start, node.end); + node.raw = state.source.slice(node.start, node.end); } } } @@ -55,14 +53,10 @@ var astTransformVisitor = { // make '_paths' non-enumerable (babel-eslint #200) Object.defineProperty(node, "_paths", { value: node._paths, writable: true }); }, - exit (path) { + exit (path, state) { var node = path.node; - [ - fixDirectives, - ].forEach((fixer) => { - fixer(path); - }); + fixDirectives(path, state); if (path.isJSXText()) { node.type = "Literal"; @@ -71,7 +65,7 @@ var astTransformVisitor = { if (path.isNumericLiteral() || path.isStringLiteral()) { - changeToLiteral(node); + changeToLiteral(node, state); } if (path.isBooleanLiteral()) { @@ -104,7 +98,7 @@ var astTransformVisitor = { } if (path.isClassMethod() || path.isObjectMethod()) { - var code = source.slice(node.key.end, node.body.start); + var code = state.source.slice(node.key.end, node.body.start); var offset = code.indexOf("("); node.value = { @@ -230,7 +224,7 @@ var astTransformVisitor = { }; -function fixDirectives (path) { +function fixDirectives (path, state) { if (!(path.isProgram() || path.isFunction())) return; var node = path.node; @@ -249,7 +243,7 @@ function fixDirectives (path) { directive.expression = directive.value; delete directive.value; directive.expression.type = "Literal"; - changeToLiteral(directive.expression); + changeToLiteral(directive.expression, state); body.unshift(directive); }); delete directivesContainer.directives; From 5d32ad0d56c8769aeea680cc7a4aafa1df4c2a04 Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Sat, 25 Mar 2017 17:07:41 -0400 Subject: [PATCH 16/29] Consolidate versions of "convertComments" --- babylon-to-espree/convertComments.js | 15 +++++++++++++++ babylon-to-espree/index.js | 16 +--------------- babylon-to-espree/toAST.js | 18 ++++-------------- 3 files changed, 20 insertions(+), 29 deletions(-) create mode 100644 babylon-to-espree/convertComments.js diff --git a/babylon-to-espree/convertComments.js b/babylon-to-espree/convertComments.js new file mode 100644 index 00000000..11c2a335 --- /dev/null +++ b/babylon-to-espree/convertComments.js @@ -0,0 +1,15 @@ +module.exports = function (comments) { + for (var i = 0; i < comments.length; i++) { + var comment = comments[i]; + if (comment.type === "CommentBlock") { + comment.type = "Block"; + } else if (comment.type === "CommentLine") { + comment.type = "Line"; + } + // sometimes comments don't get ranges computed, + // even with options.ranges === true + if (!comment.range) { + comment.range = [comment.start, comment.end]; + } + } +}; diff --git a/babylon-to-espree/index.js b/babylon-to-espree/index.js index 401570b6..4dd83f08 100644 --- a/babylon-to-espree/index.js +++ b/babylon-to-espree/index.js @@ -3,18 +3,4 @@ exports.attachComments = require("./attachComments"); exports.toTokens = require("./toTokens"); exports.toAST = require("./toAST"); -exports.convertComments = function (comments) { - for (var i = 0; i < comments.length; i++) { - var comment = comments[i]; - if (comment.type === "CommentBlock") { - comment.type = "Block"; - } else if (comment.type === "CommentLine") { - comment.type = "Line"; - } - // sometimes comments don't get ranges computed, - // even with options.ranges === true - if (!comment.range) { - comment.range = [comment.start, comment.end]; - } - } -}; +exports.convertComments = require("./convertComments"); diff --git a/babylon-to-espree/toAST.js b/babylon-to-espree/toAST.js index ba1e8d74..ecdb9366 100644 --- a/babylon-to-espree/toAST.js +++ b/babylon-to-espree/toAST.js @@ -1,3 +1,5 @@ +var convertComments = require("./convertComments"); + module.exports = function (ast, traverse, code) { var state = { source: code }; ast.range = [ast.start, ast.end]; @@ -15,18 +17,6 @@ function changeToLiteral(node, state) { } } -function changeComments(nodeComments) { - for (var i = 0; i < nodeComments.length; i++) { - var comment = nodeComments[i]; - if (comment.type === "CommentLine") { - comment.type = "Line"; - } else if (comment.type === "CommentBlock") { - comment.type = "Block"; - } - comment.range = [comment.start, comment.end]; - } -} - var astTransformVisitor = { noScope: true, enter (path) { @@ -43,11 +33,11 @@ var astTransformVisitor = { } if (node.trailingComments) { - changeComments(node.trailingComments); + convertComments(node.trailingComments); } if (node.leadingComments) { - changeComments(node.leadingComments); + convertComments(node.leadingComments); } // make '_paths' non-enumerable (babel-eslint #200) From 06c3a31b96cb890fe3544931f60f021e5186f62a Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Sat, 25 Mar 2017 17:28:01 -0400 Subject: [PATCH 17/29] Inline fixDirectives and use for-loop --- babylon-to-espree/toAST.js | 49 ++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 28 deletions(-) diff --git a/babylon-to-espree/toAST.js b/babylon-to-espree/toAST.js index ecdb9366..c21c7a11 100644 --- a/babylon-to-espree/toAST.js +++ b/babylon-to-espree/toAST.js @@ -46,7 +46,27 @@ var astTransformVisitor = { exit (path, state) { var node = path.node; - fixDirectives(path, state); + // fixDirectives + if (path.isFunction() || path.isProgram()) { + var directivesContainer = node; + var body = node.body; + if (node.type !== "Program") { + directivesContainer = body; + body = body.body; + } + if (directivesContainer.directives) { + for (var i = directivesContainer.directives.length - 1; i >= 0; i--) { + var directive = directivesContainer.directives[i]; + directive.type = "ExpressionStatement"; + directive.expression = directive.value; + delete directive.value; + directive.expression.type = "Literal"; + changeToLiteral(directive.expression, state); + body.unshift(directive); + } + delete directivesContainer.directives; + } + } if (path.isJSXText()) { node.type = "Literal"; @@ -212,30 +232,3 @@ var astTransformVisitor = { } } }; - - -function fixDirectives (path, state) { - if (!(path.isProgram() || path.isFunction())) return; - - var node = path.node; - var directivesContainer = node; - var body = node.body; - - if (node.type !== "Program") { - directivesContainer = body; - body = body.body; - } - - if (!directivesContainer.directives) return; - - directivesContainer.directives.reverse().forEach((directive) => { - directive.type = "ExpressionStatement"; - directive.expression = directive.value; - delete directive.value; - directive.expression.type = "Literal"; - changeToLiteral(directive.expression, state); - body.unshift(directive); - }); - delete directivesContainer.directives; -} -// fixDirectives From 539af05bae280d15059d783b59d77b8814a48084 Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Sat, 25 Mar 2017 17:36:20 -0400 Subject: [PATCH 18/29] Only iterate over tokens once --- babylon-to-espree/toTokens.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/babylon-to-espree/toTokens.js b/babylon-to-espree/toTokens.js index 1f06d3e5..f3c0e848 100644 --- a/babylon-to-espree/toTokens.js +++ b/babylon-to-espree/toTokens.js @@ -4,12 +4,13 @@ var toToken = require("./toToken"); module.exports = function (tokens, tt, code) { // transform tokens to type "Template" convertTemplateType(tokens, tt); - var transformedTokens = tokens.filter((token) => { - return token.type !== "CommentLine" && token.type !== "CommentBlock"; - }); - for (var i = 0, l = transformedTokens.length; i < l; i++) { - transformedTokens[i] = toToken(transformedTokens[i], tt, code); + var transformedTokens = []; + for (var i = 0; i < tokens.length; i++) { + var token = tokens[i]; + if (token.type !== "CommentLine" && token.type !== "CommentBlock") { + transformedTokens.push(toToken(token, tt, code)); + } } return transformedTokens; From d2ce7894bc864ed46c0c91eeef60af0a91886d8a Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Sat, 25 Mar 2017 17:42:51 -0400 Subject: [PATCH 19/29] Use for-loop for template literal conversion --- babylon-to-espree/toAST.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/babylon-to-espree/toAST.js b/babylon-to-espree/toAST.js index c21c7a11..0892563a 100644 --- a/babylon-to-espree/toAST.js +++ b/babylon-to-espree/toAST.js @@ -215,7 +215,8 @@ var astTransformVisitor = { // template string range fixes if (path.isTemplateLiteral()) { - node.quasis.forEach((q) => { + for (var j = 0; j < node.quasis.length; j++) { + var q = node.quasis[j]; q.range[0] -= 1; if (q.tail) { q.range[1] += 1; @@ -228,7 +229,7 @@ var astTransformVisitor = { } else { q.loc.end.column += 2; } - }); + } } } }; From 6c5beec589cbf343c528f1a78efe42874d7c83d4 Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Sat, 25 Mar 2017 18:01:13 -0400 Subject: [PATCH 20/29] Move ast convert steps to babylon-to-espree --- babylon-to-espree/index.js | 36 ++++++++++++++++++++++++++++++++---- index.js | 28 +--------------------------- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/babylon-to-espree/index.js b/babylon-to-espree/index.js index 4dd83f08..157a3ace 100644 --- a/babylon-to-espree/index.js +++ b/babylon-to-espree/index.js @@ -1,6 +1,34 @@ -exports.attachComments = require("./attachComments"); +var attachComments = require("./attachComments"); +var convertComments = require("./convertComments"); +var toTokens = require("./toTokens"); +var toAST = require("./toAST"); -exports.toTokens = require("./toTokens"); -exports.toAST = require("./toAST"); +module.exports = function (ast, traverse, tt, code) { + // remove EOF token, eslint doesn't use this for anything and it interferes + // with some rules see https://github.com/babel/babel-eslint/issues/2 + // todo: find a more elegant way to do this + ast.tokens.pop(); -exports.convertComments = require("./convertComments"); + // convert tokens + ast.tokens = toTokens(ast.tokens, tt, code); + + // add comments + convertComments(ast.comments); + + // transform esprima and acorn divergent nodes + toAST(ast, traverse, code); + + // ast.program.tokens = ast.tokens; + // ast.program.comments = ast.comments; + // ast = ast.program; + + // remove File + ast.type = "Program"; + ast.sourceType = ast.program.sourceType; + ast.directives = ast.program.directives; + ast.body = ast.program.body; + delete ast.program; + delete ast._paths; + + attachComments(ast, ast.comments, ast.tokens); +}; diff --git a/index.js b/index.js index 3b243cc8..b56f74e5 100644 --- a/index.js +++ b/index.js @@ -428,33 +428,7 @@ exports.parseNoPatch = function (code, options) { throw err; } - // remove EOF token, eslint doesn't use this for anything and it interferes with some rules - // see https://github.com/babel/babel-eslint/issues/2 for more info - // todo: find a more elegant way to do this - ast.tokens.pop(); - - // convert tokens - ast.tokens = babylonToEspree.toTokens(ast.tokens, tt, code); - - // add comments - babylonToEspree.convertComments(ast.comments); - - // transform esprima and acorn divergent nodes - babylonToEspree.toAST(ast, traverse, code); - - // ast.program.tokens = ast.tokens; - // ast.program.comments = ast.comments; - // ast = ast.program; - - // remove File - ast.type = "Program"; - ast.sourceType = ast.program.sourceType; - ast.directives = ast.program.directives; - ast.body = ast.program.body; - delete ast.program; - delete ast._paths; - - babylonToEspree.attachComments(ast, ast.comments, ast.tokens); + babylonToEspree(ast, traverse, tt, code); return ast; }; From ec14787172795c81fa2c544d100727d897521ebe Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Sat, 25 Mar 2017 18:03:17 -0400 Subject: [PATCH 21/29] Enable strict mode in all of babylon-to-espree --- babylon-to-espree/attachComments.js | 2 ++ babylon-to-espree/convertComments.js | 2 ++ babylon-to-espree/convertTemplateType.js | 2 ++ babylon-to-espree/index.js | 2 ++ babylon-to-espree/toAST.js | 2 ++ babylon-to-espree/toToken.js | 2 ++ babylon-to-espree/toTokens.js | 2 ++ 7 files changed, 14 insertions(+) diff --git a/babylon-to-espree/attachComments.js b/babylon-to-espree/attachComments.js index 4040ce7e..9fc9f339 100644 --- a/babylon-to-espree/attachComments.js +++ b/babylon-to-espree/attachComments.js @@ -1,3 +1,5 @@ +"use strict"; + // comment fixes module.exports = function (ast, comments, tokens) { if (comments.length) { diff --git a/babylon-to-espree/convertComments.js b/babylon-to-espree/convertComments.js index 11c2a335..19c6ce8c 100644 --- a/babylon-to-espree/convertComments.js +++ b/babylon-to-espree/convertComments.js @@ -1,3 +1,5 @@ +"use strict"; + module.exports = function (comments) { for (var i = 0; i < comments.length; i++) { var comment = comments[i]; diff --git a/babylon-to-espree/convertTemplateType.js b/babylon-to-espree/convertTemplateType.js index c9537ddd..8b647c39 100644 --- a/babylon-to-espree/convertTemplateType.js +++ b/babylon-to-espree/convertTemplateType.js @@ -1,3 +1,5 @@ +"use strict"; + module.exports = function (tokens, tt) { var startingToken = 0; var currentToken = 0; diff --git a/babylon-to-espree/index.js b/babylon-to-espree/index.js index 157a3ace..94e6832f 100644 --- a/babylon-to-espree/index.js +++ b/babylon-to-espree/index.js @@ -1,3 +1,5 @@ +"use strict"; + var attachComments = require("./attachComments"); var convertComments = require("./convertComments"); var toTokens = require("./toTokens"); diff --git a/babylon-to-espree/toAST.js b/babylon-to-espree/toAST.js index 0892563a..84d77a53 100644 --- a/babylon-to-espree/toAST.js +++ b/babylon-to-espree/toAST.js @@ -1,3 +1,5 @@ +"use strict"; + var convertComments = require("./convertComments"); module.exports = function (ast, traverse, code) { diff --git a/babylon-to-espree/toToken.js b/babylon-to-espree/toToken.js index dcfd48f8..6173f760 100644 --- a/babylon-to-espree/toToken.js +++ b/babylon-to-espree/toToken.js @@ -1,3 +1,5 @@ +"use strict"; + module.exports = function (token, tt, source) { var type = token.type; token.range = [token.start, token.end]; diff --git a/babylon-to-espree/toTokens.js b/babylon-to-espree/toTokens.js index f3c0e848..81ec9850 100644 --- a/babylon-to-espree/toTokens.js +++ b/babylon-to-espree/toTokens.js @@ -1,3 +1,5 @@ +"use strict"; + var convertTemplateType = require("./convertTemplateType"); var toToken = require("./toToken"); From a750684e477ab72d4a62822a965c7c8f909aa37d Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Sat, 25 Mar 2017 19:32:05 -0400 Subject: [PATCH 22/29] Use dedent for unpadding (#456) --- package.json | 1 + test/babel-eslint.js | 2 +- test/non-regression.js | 2 +- utils/unpad.js | 14 -------------- yarn.lock | 4 ++++ 5 files changed, 7 insertions(+), 16 deletions(-) delete mode 100644 utils/unpad.js diff --git a/package.json b/package.json index 4b3acc0a..cef295c6 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "homepage": "https://github.com/babel/babel-eslint", "devDependencies": { "babel-eslint": "^7.0.0", + "dedent": "^0.7.0", "eslint": "^3.18.0", "eslint-config-babel": "^6.0.0", "eslint-plugin-flowtype": "^2.30.3", diff --git a/test/babel-eslint.js b/test/babel-eslint.js index 41586c09..540170df 100644 --- a/test/babel-eslint.js +++ b/test/babel-eslint.js @@ -2,7 +2,7 @@ var assert = require("assert"); var babelEslint = require(".."); var espree = require("espree"); var util = require("util"); -var unpad = require("../utils/unpad"); +var unpad = require("dedent"); // Checks if the source ast implements the target ast. Ignores extra keys on source ast function assertImplementsAST(target, source, path) { diff --git a/test/non-regression.js b/test/non-regression.js index 711aa25e..015b0fd3 100644 --- a/test/non-regression.js +++ b/test/non-regression.js @@ -1,7 +1,7 @@ /*eslint-env mocha*/ "use strict"; var eslint = require("eslint"); -var unpad = require("../utils/unpad"); +var unpad = require("dedent"); function verifyAndAssertMessages(code, rules, expectedMessages, sourceType, overrideConfig) { var config = { diff --git a/utils/unpad.js b/utils/unpad.js deleted file mode 100644 index bf91100e..00000000 --- a/utils/unpad.js +++ /dev/null @@ -1,14 +0,0 @@ -// Remove padding from a string. -function unpad(str) { - const lines = str.split("\n"); - const m = lines[1] && lines[1].match(/^\s+/); - if (!m) { - return str; - } - const spaces = m[0].length; - return lines.map( - (line) => line.slice(spaces) - ).join("\n").trim(); -} - -module.exports = unpad; diff --git a/yarn.lock b/yarn.lock index afb72f46..c81f8409 100644 --- a/yarn.lock +++ b/yarn.lock @@ -222,6 +222,10 @@ debug@^2.1.1, debug@^2.2.0: dependencies: ms "0.7.2" +dedent@^0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/dedent/-/dedent-0.7.0.tgz#2495ddbaf6eb874abb0e1be9df22d2e5a544326c" + deep-is@~0.1.3: version "0.1.3" resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" From 1201e12800bbb4badb55620100bc871193572784 Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Sat, 25 Mar 2017 19:36:10 -0400 Subject: [PATCH 23/29] Remove unused .gitmodules (#457) --- .gitmodules | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .gitmodules diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index e922d16a..00000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "eslint"] - path = eslint - url = https://github.com/eslint/eslint From 0f611b83311d1b44912fc1dd0fc2cd88a0ae9d0c Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Thu, 30 Mar 2017 13:49:51 -0400 Subject: [PATCH 24/29] Separate finding peer deps from monkeypatching (#460) --- index.js | 79 +++++++++++++++++++++++--------------------------------- 1 file changed, 33 insertions(+), 46 deletions(-) diff --git a/index.js b/index.js index b56f74e5..3e8e2ffa 100644 --- a/index.js +++ b/index.js @@ -10,21 +10,10 @@ var codeFrame = require("babel-code-frame"); var hasPatched = false; var eslintOptions = {}; -function createModule(filename) { - var mod = new Module(filename); - mod.filename = filename; - mod.paths = Module._nodeModulePaths(path.dirname(filename)); - return mod; -} - -function monkeypatch() { - if (hasPatched) return; - hasPatched = true; - - var eslintLoc; +function getModules() { try { // avoid importing a local copy of eslint, try to find a peer dependency - eslintLoc = Module._resolveFilename("eslint", module.parent); + var eslintLoc = Module._resolveFilename("eslint", module.parent); } catch (err) { try { // avoids breaking in jest where module.parent is undefined @@ -35,18 +24,35 @@ function monkeypatch() { } // get modules relative to what eslint will load - var eslintMod = createModule(eslintLoc); - // ESLint v1.9.0 uses estraverse directly to work around https://github.com/npm/npm/issues/9663 + var eslintMod = new Module(eslintLoc); + eslintMod.filename = eslintLoc; + eslintMod.paths = Module._nodeModulePaths(path.dirname(eslintLoc)); + + var Definition = eslintMod.require("escope/lib/definition").Definition; + var escope = eslintMod.require("escope"); var estraverse = eslintMod.require("estraverse"); + var referencer = eslintMod.require("escope/lib/referencer"); + + if (referencer.__esModule) referencer = referencer.default; + + return { + Definition, + escope, + estraverse, + referencer, + }; +} + +function monkeypatch(modules) { + var Definition = modules.Definition; + var escope = modules.escope; + var estraverse = modules.estraverse; + var referencer = modules.referencer; Object.assign(estraverse.VisitorKeys, t.VISITOR_KEYS); estraverse.VisitorKeys.MethodDefinition.push("decorators"); estraverse.VisitorKeys.Property.push("decorators"); - // monkeypatch escope - var escopeLoc = Module._resolveFilename("escope", eslintMod); - var escopeMod = createModule(escopeLoc); - var escope = require(escopeLoc); var analyze = escope.analyze; escope.analyze = function (ast, opts) { opts.ecmaVersion = eslintOptions.ecmaVersion; @@ -59,28 +65,6 @@ function monkeypatch() { return results; }; - // monkeypatch escope/referencer - var referencerLoc; - try { - referencerLoc = Module._resolveFilename("./referencer", escopeMod); - } catch (err) { - throw new ReferenceError("couldn't resolve escope/referencer"); - } - var referencerMod = createModule(referencerLoc); - var referencer = require(referencerLoc); - if (referencer.__esModule) { - referencer = referencer.default; - } - - // reference Definition - var definitionLoc; - try { - definitionLoc = Module._resolveFilename("./definition", referencerMod); - } catch (err) { - throw new ReferenceError("couldn't resolve escope/definition"); - } - var Definition = require(definitionLoc).Definition; - // if there are decorators, then visit each function visitDecorators(node) { if (!node.decorators) { @@ -368,11 +352,14 @@ exports.parse = function (code, options) { delete eslintOptions.globalReturn; } - try { - monkeypatch(); - } catch (err) { - console.error(err.stack); - process.exit(1); + if (!hasPatched) { + hasPatched = true; + try { + monkeypatch(getModules()); + } catch (err) { + console.error(err.stack); + process.exit(1); + } } return exports.parseNoPatch(code, options); From 862200945ee2860cbd00e770280dda3d56b055eb Mon Sep 17 00:00:00 2001 From: Vitor Balocco Date: Wed, 12 Apr 2017 17:59:23 +0200 Subject: [PATCH 25/29] Fix: use eslint-scope instead of escope if present (#461) --- index.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 3e8e2ffa..0f871a90 100644 --- a/index.js +++ b/index.js @@ -28,10 +28,17 @@ function getModules() { eslintMod.filename = eslintLoc; eslintMod.paths = Module._nodeModulePaths(path.dirname(eslintLoc)); - var Definition = eslintMod.require("escope/lib/definition").Definition; - var escope = eslintMod.require("escope"); + try { + var escope = eslintMod.require("eslint-scope"); + var Definition = eslintMod.require("eslint-scope/lib/definition").Definition; + var referencer = eslintMod.require("eslint-scope/lib/referencer"); + } catch (err) { + escope = eslintMod.require("escope"); + Definition = eslintMod.require("escope/lib/definition").Definition; + referencer = eslintMod.require("escope/lib/referencer"); + } + var estraverse = eslintMod.require("estraverse"); - var referencer = eslintMod.require("escope/lib/referencer"); if (referencer.__esModule) referencer = referencer.default; From f59d2009652e14acf1231a1268a8324cf046514e Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Wed, 12 Apr 2017 12:07:05 -0400 Subject: [PATCH 26/29] 7.2.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cef295c6..a134201e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "babel-eslint", - "version": "7.2.1", + "version": "7.2.2", "description": "Custom parser for ESLint", "main": "index.js", "files": [ From dfaff04bad37823842aec19fe131f75a069b7799 Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Fri, 21 Apr 2017 11:48:52 -0400 Subject: [PATCH 27/29] Fix flow type spread handling (#465) --- index.js | 7 +++++-- package.json | 2 +- test/non-regression.js | 12 ++++++++++++ yarn.lock | 6 +++--- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 0f871a90..b647fbdf 100644 --- a/index.js +++ b/index.js @@ -107,7 +107,7 @@ function monkeypatch(modules) { // loops callProperties: { type: "loop", values: ["value"] }, indexers: { type: "loop", values: ["key", "value"] }, - properties: { type: "loop", values: ["value"] }, + properties: { type: "loop", values: ["argument", "value"] }, types: { type: "loop" }, params: { type: "loop" }, // single property @@ -142,7 +142,10 @@ function monkeypatch(modules) { for (var j = 0; j < nodeProperty.length; j++) { if (Array.isArray(propertyType.values)) { for (var k = 0; k < propertyType.values.length; k++) { - checkIdentifierOrVisit.call(this, nodeProperty[j][propertyType.values[k]]); + var loopPropertyNode = nodeProperty[j][propertyType.values[k]]; + if (loopPropertyNode) { + checkIdentifierOrVisit.call(this, loopPropertyNode); + } } } else { checkIdentifierOrVisit.call(this, nodeProperty[j]); diff --git a/package.json b/package.json index a134201e..343b99fc 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "babel-code-frame": "^6.22.0", "babel-traverse": "^6.23.1", "babel-types": "^6.23.0", - "babylon": "^6.16.1" + "babylon": "^6.17.0" }, "scripts": { "test": "npm run lint && npm run test-only", diff --git a/test/non-regression.js b/test/non-regression.js index 015b0fd3..f2cf3149 100644 --- a/test/non-regression.js +++ b/test/non-regression.js @@ -574,6 +574,18 @@ describe("verify", () => { ); }); + it("supports type spreading", () => { + verifyAndAssertMessages( + unpad(` + type U = {}; + type T = {a: number, ...U, ...V}; + `), + { "no-undef": 1, "no-unused-vars": 1 }, + [ "2:6 'T' is defined but never used. no-unused-vars", + "2:31 'V' is not defined. no-undef" ] + ); + }); + it("1", () => { verifyAndAssertMessages( unpad(` diff --git a/yarn.lock b/yarn.lock index c81f8409..f75d2314 100644 --- a/yarn.lock +++ b/yarn.lock @@ -113,9 +113,9 @@ babel-types@^6.15.0, babel-types@^6.23.0: lodash "^4.2.0" to-fast-properties "^1.0.1" -babylon@^6.13.0, babylon@^6.15.0, babylon@^6.16.1: - version "6.16.1" - resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.16.1.tgz#30c5a22f481978a9e7f8cdfdf496b11d94b404d3" +babylon@^6.13.0, babylon@^6.15.0, babylon@^6.17.0: + version "6.17.0" + resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.17.0.tgz#37da948878488b9c4e3c4038893fa3314b3fc932" balanced-match@^0.4.1: version "0.4.2" From 94bb5a1d36c5624fb612de2dd704ffa586d38845 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 21 Apr 2017 22:14:19 +0100 Subject: [PATCH 28/29] 7.2.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 343b99fc..a247678c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "babel-eslint", - "version": "7.2.2", + "version": "7.2.3", "description": "Custom parser for ESLint", "main": "index.js", "files": [ From 54ed517d2ecb3afb93ac338c019f8dff224918c2 Mon Sep 17 00:00:00 2001 From: Reyad Attiyat Date: Mon, 29 May 2017 20:41:14 -0500 Subject: [PATCH 29/29] Fix: Convert RegExpLieteral value to RegExp object (fixes #477) (#478) --- babylon-to-espree/toAST.js | 6 +++++- test/babel-eslint.js | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/babylon-to-espree/toAST.js b/babylon-to-espree/toAST.js index 84d77a53..53bc76be 100644 --- a/babylon-to-espree/toAST.js +++ b/babylon-to-espree/toAST.js @@ -94,7 +94,11 @@ var astTransformVisitor = { if (path.isRegExpLiteral()) { node.type = "Literal"; node.raw = node.extra.raw; - node.value = {}; + try { + node.value = new RegExp(node.pattern, node.flags); + } catch (err) { + node.value = null; + } node.regex = { pattern: node.pattern, flags: node.flags diff --git a/test/babel-eslint.js b/test/babel-eslint.js index 540170df..b7f0e699 100644 --- a/test/babel-eslint.js +++ b/test/babel-eslint.js @@ -20,6 +20,8 @@ function assertImplementsAST(target, source, path) { var typeB = source === null ? "null" : typeof source; if (typeA !== typeB) { error(`have different types (${typeA} !== ${typeB}) (${target} !== ${source})`); + } else if (typeA === "object" && ["RegExp"].indexOf(target.constructor.name) !== -1 && target.constructor.name !== source.constructor.name) { + error(`object have different constructors (${target.constructor.name} !== ${source.constructor.name}`); } else if (typeA === "object") { var keysTarget = Object.keys(target); for (var i in keysTarget) { @@ -305,6 +307,18 @@ describe("babylon-to-esprima", () => { parseAndAssertSame("/affix-top|affix-bottom|affix|[a-z]/"); }); + it("regexp", () => { + parseAndAssertSame("const foo = /foo/;"); + }); + + it("regexp y flag", () => { + parseAndAssertSame("const foo = /foo/y;"); + }); + + it("regexp u flag", () => { + parseAndAssertSame("const foo = /foo/u;"); + }); + it("regexp in a template string", () => { parseAndAssertSame("`${/\\d/.exec(\"1\")[0]}`"); });