Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify AST walker and remove "lodash" dependency #37

Merged
merged 2 commits into from
Jan 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* jshint node:true */
'use strict';

var _includes = require('lodash/includes');

module.exports = {
name: 'test-selectors',

Expand All @@ -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', {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 2 additions & 13 deletions strip-test-selectors.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/*jshint node:true*/
var _ = require('lodash/lodash');

var TEST_SELECTOR_PREFIX = /data-test-.*/;

function StripTestSelectorsTransform() {
Expand All @@ -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);
});
}
}
});

Expand Down