BasicEffectRulePlugin.js 985 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. /** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
  7. class BasicEffectRulePlugin {
  8. /**
  9. * @param {string} ruleProperty the rule property
  10. * @param {string=} effectType the effect type
  11. */
  12. constructor(ruleProperty, effectType) {
  13. this.ruleProperty = ruleProperty;
  14. this.effectType = effectType || ruleProperty;
  15. }
  16. /**
  17. * @param {RuleSetCompiler} ruleSetCompiler the rule set compiler
  18. * @returns {void}
  19. */
  20. apply(ruleSetCompiler) {
  21. ruleSetCompiler.hooks.rule.tap(
  22. "BasicEffectRulePlugin",
  23. (path, rule, unhandledProperties, result, references) => {
  24. if (unhandledProperties.has(this.ruleProperty)) {
  25. unhandledProperties.delete(this.ruleProperty);
  26. const value = rule[this.ruleProperty];
  27. result.effects.push({
  28. type: this.effectType,
  29. value
  30. });
  31. }
  32. }
  33. );
  34. }
  35. }
  36. module.exports = BasicEffectRulePlugin;