/* eslint-env node */
'use strict';
const htmlTags = require('html-tags');
const diff = require('lodash/difference');
const compileCSS = require('broccoli-postcss');

const removeableElements = () => {
  const whitelistedTags = ['html', 'body'];
  const removeableTags = diff(htmlTags, whitelistedTags);

  const { getItemSync } = process.emberAddonStateBucket;

  const htmlElementsInApp = getItemSync('ember-dom-inventory:htmlElements') || [];

  return diff(
    removeableTags,
    htmlElementsInApp
  );
};

module.exports = {
  name: 'ember-tachyons-sweeper',

  postprocessTree(type, tree) {

    const selectorBlacklist = removeableElements();

    return compileCSS(tree, {
      plugins: [
        {
          module: require('postcss-discard-comments'),
          options: {
            removeAll: true
          },
        },
        {
          module: require('postcss-strip-selectors'),
          options: {
            selectors: selectorBlacklist,
          },
        },
        {
          module: require('postcss-discard-empty'),
          options: {},
        }
      ]
    });
  },
};

@@ -107,24 +107,63 @@
 fference');%0A
+const merge = require('lodash/merge');%0A
 const compil
@@ -198,16 +198,16 @@
 tcss');%0A
-
 %0Aconst r
@@ -545,16 +545,444 @@
  );%0A%7D;%0A%0A
+const removeableClasses = () =%3E %7B%0A  const %7B getItemSync %7D = process.emberAddonStateBucket;%0A  const cssClassesInApp = getItemSync('ember-dom-inventory:htmlClasses') %7C%7C %5B%5D;%0A%0A  if (cssClassesInApp.length) %7B%0A    const klasses = cssClassesInApp.join('%7C');%0A    const regex = new RegExp(%60%5E%5C%5C.(?!($%7Bklasses%7D)$).*%60)%0A    return %5Bregex%5D;%0A  %7D%0A%0A  const regexMatchingAllClasses = new RegExp(/%5E%5C..*$/);%0A  return %5BregexMatchingAllClasses%5D;%0A%7D;%0A%0A
 module.e
@@ -1111,16 +1111,66 @@
 ments();
+%0A    const regexenBlacklist = removeableClasses();
 %0A%0A    re
@@ -1425,32 +1425,32 @@
      options: %7B%0A
-
             sele
@@ -1475,16 +1475,55 @@
 cklist,%0A
+            regexen: regexenBlacklist,%0A
         

Remove classes that are not present in application