From e5a93fa43931a93a5b085b91cc5accb4c0eb01ce Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 6 May 2021 16:08:56 +0200 Subject: [PATCH 1/7] Extract `stripTestSelectors()` function --- strip-test-selectors.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/strip-test-selectors.js b/strip-test-selectors.js index f6aeea2a..b1d9d762 100644 --- a/strip-test-selectors.js +++ b/strip-test-selectors.js @@ -8,6 +8,20 @@ function isTestSelector(attribute) { return TEST_SELECTOR_PREFIX.test(attribute); } +function stripTestSelectors(node) { + if ('sexpr' in node) { + node = node.sexpr; + } + + node.params = node.params.filter(function(param) { + return !isTestSelector(param.original); + }); + + node.hash.pairs = node.hash.pairs.filter(function(pair) { + return !isTestSelector(pair.key); + }); +} + function StripTestSelectorsTransform() { this.syntax = null; } @@ -21,17 +35,7 @@ StripTestSelectorsTransform.prototype.transform = function(ast) { return !isTestSelector(attribute.name); }); } else if (node.type === 'MustacheStatement' || node.type === 'BlockStatement') { - if ('sexpr' in node) { - node = node.sexpr; - } - - node.params = node.params.filter(function(param) { - return !isTestSelector(param.original); - }); - - node.hash.pairs = node.hash.pairs.filter(function(pair) { - return !isTestSelector(pair.key); - }); + stripTestSelectors(node); } }); From ceea32dc631efab5c5b00722ec331f16a1751a4e Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 6 May 2021 16:09:26 +0200 Subject: [PATCH 2/7] Use `traverse()` instead of the deprecated `Walker` class --- strip-test-selectors.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/strip-test-selectors.js b/strip-test-selectors.js index b1d9d762..220a19e7 100644 --- a/strip-test-selectors.js +++ b/strip-test-selectors.js @@ -27,16 +27,22 @@ function StripTestSelectorsTransform() { } StripTestSelectorsTransform.prototype.transform = function(ast) { - let walker = new this.syntax.Walker(); + let { traverse } = this.syntax; - walker.visit(ast, function(node) { - if (node.type === 'ElementNode') { + traverse(ast, { + ElementNode(node) { node.attributes = node.attributes.filter(function(attribute) { return !isTestSelector(attribute.name); }); - } else if (node.type === 'MustacheStatement' || node.type === 'BlockStatement') { + }, + + MustacheStatement(node) { + stripTestSelectors(node); + }, + + BlockStatement(node) { stripTestSelectors(node); - } + }, }); return ast; From fc27e649659cf0df98989934ecb9cb395dffa52e Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 6 May 2021 16:11:49 +0200 Subject: [PATCH 3/7] Drop Ember v1.11/1.12 compatibility code We don't support these old Ember versions anymore, so we can drop this codepath now --- strip-test-selectors.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/strip-test-selectors.js b/strip-test-selectors.js index 220a19e7..766c21aa 100644 --- a/strip-test-selectors.js +++ b/strip-test-selectors.js @@ -9,10 +9,6 @@ function isTestSelector(attribute) { } function stripTestSelectors(node) { - if ('sexpr' in node) { - node = node.sexpr; - } - node.params = node.params.filter(function(param) { return !isTestSelector(param.original); }); From 84640e4ce7e6578c0189e55ba3bf2844798487a6 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 6 May 2021 16:16:32 +0200 Subject: [PATCH 4/7] Convert class based template compilation plugin to functional style --- strip-test-selectors.js | 46 +++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/strip-test-selectors.js b/strip-test-selectors.js index 766c21aa..08045bec 100644 --- a/strip-test-selectors.js +++ b/strip-test-selectors.js @@ -18,30 +18,26 @@ function stripTestSelectors(node) { }); } -function StripTestSelectorsTransform() { - this.syntax = null; +function transform() { + return { + name: 'strip-test-selectors', + + visitor: { + ElementNode(node) { + node.attributes = node.attributes.filter(function(attribute) { + return !isTestSelector(attribute.name); + }); + }, + + MustacheStatement(node) { + stripTestSelectors(node); + }, + + BlockStatement(node) { + stripTestSelectors(node); + }, + } + }; } -StripTestSelectorsTransform.prototype.transform = function(ast) { - let { traverse } = this.syntax; - - traverse(ast, { - ElementNode(node) { - node.attributes = node.attributes.filter(function(attribute) { - return !isTestSelector(attribute.name); - }); - }, - - MustacheStatement(node) { - stripTestSelectors(node); - }, - - BlockStatement(node) { - stripTestSelectors(node); - }, - }); - - return ast; -}; - -module.exports = StripTestSelectorsTransform; +module.exports = transform; From 8c63b8a9b488ed4f84d4f7e3536c36661ead38ea Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 6 May 2021 16:20:33 +0200 Subject: [PATCH 5/7] Convert callbacks to arrow functions --- strip-test-selectors.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/strip-test-selectors.js b/strip-test-selectors.js index 08045bec..a6262a9f 100644 --- a/strip-test-selectors.js +++ b/strip-test-selectors.js @@ -9,13 +9,8 @@ function isTestSelector(attribute) { } function stripTestSelectors(node) { - node.params = node.params.filter(function(param) { - return !isTestSelector(param.original); - }); - - node.hash.pairs = node.hash.pairs.filter(function(pair) { - return !isTestSelector(pair.key); - }); + node.params = node.params.filter(param => !isTestSelector(param.original)); + node.hash.pairs = node.hash.pairs.filter(pair => !isTestSelector(pair.key)); } function transform() { @@ -24,9 +19,7 @@ function transform() { visitor: { ElementNode(node) { - node.attributes = node.attributes.filter(function(attribute) { - return !isTestSelector(attribute.name); - }); + node.attributes = node.attributes.filter(attribute => !isTestSelector(attribute.name)); }, MustacheStatement(node) { From a591926e4f62657d4b157e26ceee70564120134b Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 6 May 2021 16:21:02 +0200 Subject: [PATCH 6/7] Inline `stripTestSelectors()` function It's no longer worth it for just two lines of code... --- strip-test-selectors.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/strip-test-selectors.js b/strip-test-selectors.js index a6262a9f..15a93878 100644 --- a/strip-test-selectors.js +++ b/strip-test-selectors.js @@ -8,11 +8,6 @@ function isTestSelector(attribute) { return TEST_SELECTOR_PREFIX.test(attribute); } -function stripTestSelectors(node) { - node.params = node.params.filter(param => !isTestSelector(param.original)); - node.hash.pairs = node.hash.pairs.filter(pair => !isTestSelector(pair.key)); -} - function transform() { return { name: 'strip-test-selectors', @@ -23,11 +18,13 @@ function transform() { }, MustacheStatement(node) { - stripTestSelectors(node); + node.params = node.params.filter(param => !isTestSelector(param.original)); + node.hash.pairs = node.hash.pairs.filter(pair => !isTestSelector(pair.key)); }, BlockStatement(node) { - stripTestSelectors(node); + node.params = node.params.filter(param => !isTestSelector(param.original)); + node.hash.pairs = node.hash.pairs.filter(pair => !isTestSelector(pair.key)); }, } }; From f99912746e0e71e9b2cb694f5510c646b1e10a53 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Thu, 6 May 2021 16:21:44 +0200 Subject: [PATCH 7/7] Inline `transform()` function --- strip-test-selectors.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/strip-test-selectors.js b/strip-test-selectors.js index 15a93878..5587c457 100644 --- a/strip-test-selectors.js +++ b/strip-test-selectors.js @@ -8,7 +8,7 @@ function isTestSelector(attribute) { return TEST_SELECTOR_PREFIX.test(attribute); } -function transform() { +module.exports = function() { return { name: 'strip-test-selectors', @@ -28,6 +28,4 @@ function transform() { }, } }; -} - -module.exports = transform; +};