UNPKG

876 BJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8/** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
9
10class BasicEffectRulePlugin {
11 constructor(ruleProperty, effectType) {
12 this.ruleProperty = ruleProperty;
13 this.effectType = effectType || ruleProperty;
14 }
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
27 const value = rule[this.ruleProperty];
28
29 result.effects.push({
30 type: this.effectType,
31 value
32 });
33 }
34 }
35 );
36 }
37}
38
39module.exports = BasicEffectRulePlugin;