BasicEffectRulePlugin.js 876 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. constructor(ruleProperty, effectType) {
  9. this.ruleProperty = ruleProperty;
  10. this.effectType = effectType || ruleProperty;
  11. }
  12. /**
  13. * @param {RuleSetCompiler} ruleSetCompiler the rule set compiler
  14. * @returns {void}
  15. */
  16. apply(ruleSetCompiler) {
  17. ruleSetCompiler.hooks.rule.tap(
  18. "BasicEffectRulePlugin",
  19. (path, rule, unhandledProperties, result, references) => {
  20. if (unhandledProperties.has(this.ruleProperty)) {
  21. unhandledProperties.delete(this.ruleProperty);
  22. const value = rule[this.ruleProperty];
  23. result.effects.push({
  24. type: this.effectType,
  25. value
  26. });
  27. }
  28. }
  29. );
  30. }
  31. }
  32. module.exports = BasicEffectRulePlugin;