From 23597d2b3b0ea5204cd883e8ab2fa55325348a32 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 9 Jan 2017 10:56:22 +0100 Subject: [PATCH] Simplify AST walker and remove "lodash" dependency (#37) * strip-test-selectors: Simplify AST walker * Replace "lodash" dependency with indexOf() !== -1 --- index.js | 4 +--- package.json | 3 +-- strip-test-selectors.js | 15 ++------------- 3 files changed, 4 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index 3e079bbe..fc5e5897 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,6 @@ /* jshint node:true */ 'use strict'; -var _includes = require('lodash/includes'); - module.exports = { name: 'test-selectors', @@ -11,7 +9,7 @@ module.exports = { var addonOptions = appOptions['ember-test-selectors'] || {}; var environments = addonOptions.environments || ['production']; - if (_includes(environments, registry.app.env)) { + if (environments.indexOf(registry.app.env) !== -1) { var StripTestSelectorsTransform = require('./strip-test-selectors'); registry.add('htmlbars-ast-plugin', { diff --git a/package.json b/package.json index 85ee2b33..891731be 100644 --- a/package.json +++ b/package.json @@ -22,8 +22,7 @@ "test:strip": "STRIP_TEST_SELECTORS=true ember test" }, "dependencies": { - "ember-cli-babel": "^5.1.7", - "lodash": "^4.0.0" + "ember-cli-babel": "^5.1.7" }, "devDependencies": { "broccoli-asset-rev": "^2.4.5", diff --git a/strip-test-selectors.js b/strip-test-selectors.js index 3970be79..355b22ef 100644 --- a/strip-test-selectors.js +++ b/strip-test-selectors.js @@ -1,6 +1,4 @@ /*jshint node:true*/ -var _ = require('lodash/lodash'); - var TEST_SELECTOR_PREFIX = /data-test-.*/; function StripTestSelectorsTransform() { @@ -12,18 +10,9 @@ StripTestSelectorsTransform.prototype.transform = function(ast) { walker.visit(ast, function(node) { if (node.type === 'ElementNode') { - var attributesToDelete = []; - node.attributes.forEach(function(attribute) { - if (TEST_SELECTOR_PREFIX.test(attribute.name)) { - attributesToDelete.push(attribute.name); - } + node.attributes = node.attributes.filter(function(attribute) { + return !TEST_SELECTOR_PREFIX.test(attribute.name); }); - - if (attributesToDelete.length > 0) { - _.remove(node.attributes, function(attribute) { - return _.includes(attributesToDelete, attribute.name); - }); - } } });