From 037139f614f685280d15789e27aa388b20fd655d Mon Sep 17 00:00:00 2001 From: "Nicholas C. Zakas" Date: Tue, 28 Jun 2016 11:03:34 -0700 Subject: [PATCH] Chore: First ES6 refactoring (refs #6407) First steps in taking advantage of ES6 features: 1. Remove es6-map dependency (no longer needed) 2. Use babelify to create browser bundle 3. Refactor a couple files into ES6 classes --- .eslintrc.yml | 4 ++++ Makefile.js | 6 +++--- lib/config/environments.js | 20 ++++++++++---------- lib/rules/no-unmodified-loop-condition.js | 3 +-- lib/rules/prefer-const.js | 1 - package.json | 4 +++- 6 files changed, 21 insertions(+), 17 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 84f6d55539c..0486c031a8f 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -2,6 +2,10 @@ root: true env: node: true + es6: true + +parserOptions: + ecmaVersion: 6 extends: "./packages/eslint-config-eslint/default.yml" diff --git a/Makefile.js b/Makefile.js index 64082c5076f..bcb55628c7f 100644 --- a/Makefile.js +++ b/Makefile.js @@ -688,13 +688,13 @@ target.browserify = function() { generateRulesIndex(TEMP_DIR); // 5. browserify the temp directory - nodeCLI.exec("browserify", "-x espree", TEMP_DIR + "eslint.js", "-o", BUILD_DIR + "eslint.js", "-s eslint"); + nodeCLI.exec("browserify", "-x espree", TEMP_DIR + "eslint.js", "-o", BUILD_DIR + "eslint.js", "-s eslint", "-t [ babelify --presets [ es2015 ] ]"); // 6. Browserify espree nodeCLI.exec("browserify", "-r espree", "-o", TEMP_DIR + "espree.js"); - // 7. Concatenate the two files together - cat(TEMP_DIR + "espree.js", BUILD_DIR + "eslint.js").to(BUILD_DIR + "eslint.js"); + // 7. Concatenate Babel polyfill, Espree, and ESLint files together + cat("./node_modules/babel-polyfill/dist/polyfill.js", TEMP_DIR + "espree.js", BUILD_DIR + "eslint.js").to(BUILD_DIR + "eslint.js"); // 8. remove temp directory rm("-r", TEMP_DIR); diff --git a/lib/config/environments.js b/lib/config/environments.js index 8daef864e31..d1ef5703f03 100644 --- a/lib/config/environments.js +++ b/lib/config/environments.js @@ -14,7 +14,7 @@ var envs = require("../../conf/environments"); // Private //------------------------------------------------------------------------------ -var environments = Object.create(null); +var environments = new Map(); /** * Loads the default environments. @@ -23,7 +23,7 @@ var environments = Object.create(null); */ function load() { Object.keys(envs).forEach(function(envName) { - environments[envName] = envs[envName]; + environments.set(envName, envs[envName]); }); } @@ -36,15 +36,15 @@ load(); module.exports = { - load: load, + load, /** * Gets the environment with the given name. * @param {string} name The name of the environment to retrieve. * @returns {Object?} The environment object or null if not found. */ - get: function(name) { - return environments[name] || null; + get(name) { + return environments.get(name) || null; }, /** @@ -53,8 +53,8 @@ module.exports = { * @param {Object} env The environment settings. * @returns {void} */ - define: function(name, env) { - environments[name] = env; + define(name, env) { + environments.set(name, env); }, /** @@ -63,7 +63,7 @@ module.exports = { * @param {string} pluginName The name of the plugin. * @returns {void} */ - importPlugin: function(plugin, pluginName) { + importPlugin(plugin, pluginName) { if (plugin.environments) { Object.keys(plugin.environments).forEach(function(envName) { this.define(pluginName + "/" + envName, plugin.environments[envName]); @@ -75,8 +75,8 @@ module.exports = { * Resets all environments. Only use for tests! * @returns {void} */ - testReset: function() { - environments = Object.create(null); + testReset() { + environments = new Map(); load(); } }; diff --git a/lib/rules/no-unmodified-loop-condition.js b/lib/rules/no-unmodified-loop-condition.js index ed49b5996ef..efb65434836 100644 --- a/lib/rules/no-unmodified-loop-condition.js +++ b/lib/rules/no-unmodified-loop-condition.js @@ -9,8 +9,7 @@ // Requirements //------------------------------------------------------------------------------ -var Map = require("es6-map"), - Traverser = require("../util/traverser"), +var Traverser = require("../util/traverser"), astUtils = require("../ast-utils"); //------------------------------------------------------------------------------ diff --git a/lib/rules/prefer-const.js b/lib/rules/prefer-const.js index 7b8ac425193..121021118c4 100644 --- a/lib/rules/prefer-const.js +++ b/lib/rules/prefer-const.js @@ -9,7 +9,6 @@ // Requirements //------------------------------------------------------------------------------ -var Map = require("es6-map"); var lodash = require("lodash"); //------------------------------------------------------------------------------ diff --git a/package.json b/package.json index abe440dcd62..c7f6fc5ae13 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "concat-stream": "^1.4.6", "debug": "^2.1.1", "doctrine": "^1.2.2", - "es6-map": "^0.1.3", "escope": "^3.6.0", "espree": "^3.1.6", "estraverse": "^4.2.0", @@ -71,6 +70,9 @@ "user-home": "^2.0.0" }, "devDependencies": { + "babel-polyfill": "^6.9.1", + "babel-preset-es2015": "^6.9.0", + "babelify": "^7.3.0", "beefy": "^2.0.0", "brfs": "0.0.9", "browserify": "^12.0.1",