| | |
| | | |
| | | /** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").Falsy} Falsy */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").RuleSetUseItem} RuleSetUseItem */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").RuleSetLoaderOptions} RuleSetLoaderOptions */ |
| | | /** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */ |
| | | |
| | | /** @typedef {(Falsy | RuleSetRule)[]} RuleSetRules */ |
| | | |
| | | /** |
| | | * Defines the rule condition function type used by this module. |
| | | * @typedef {(value: EffectData[keyof EffectData]) => boolean} RuleConditionFunction |
| | | */ |
| | | |
| | | /** |
| | | * Defines the rule condition type used by this module. |
| | | * @typedef {object} RuleCondition |
| | | * @property {string | string[]} property |
| | | * @property {boolean} matchWhenEmpty |
| | |
| | | */ |
| | | |
| | | /** |
| | | * Defines the condition type used by this module. |
| | | * @typedef {object} Condition |
| | | * @property {boolean} matchWhenEmpty |
| | | * @property {RuleConditionFunction} fn |
| | | */ |
| | | |
| | | /** |
| | | * Defines the effect data type used by this module. |
| | | * @typedef {object} EffectData |
| | | * @property {string=} resource |
| | | * @property {string=} realResource |
| | |
| | | * @property {string=} compiler |
| | | * @property {string} issuer |
| | | * @property {string} issuerLayer |
| | | * @property {string=} phase |
| | | */ |
| | | |
| | | /** |
| | | * Defines the compiled rule type used by this module. |
| | | * @typedef {object} CompiledRule |
| | | * @property {RuleCondition[]} conditions |
| | | * @property {(Effect | ((effectData: EffectData) => Effect[]))[]} effects |
| | |
| | | /** @typedef {"use" | "use-pre" | "use-post"} EffectUseType */ |
| | | |
| | | /** |
| | | * Defines the effect use type used by this module. |
| | | * @typedef {object} EffectUse |
| | | * @property {EffectUseType} type |
| | | * @property {{ loader: string, options?: string | null | Record<string, EXPECTED_ANY>, ident?: string }} value |
| | | */ |
| | | |
| | | /** |
| | | * Defines the effect basic type used by this module. |
| | | * @typedef {object} EffectBasic |
| | | * @property {string} type |
| | | * @property {EXPECTED_ANY} value |
| | |
| | | /** @typedef {Map<string, RuleSetLoaderOptions>} References */ |
| | | |
| | | /** |
| | | * Defines the rule set type used by this module. |
| | | * @typedef {object} RuleSet |
| | | * @property {References} references map of references in the rule set (may grow over time) |
| | | * @property {(effectData: EffectData) => Effect[]} exec execute the rule set |
| | | */ |
| | | |
| | | /** |
| | | * Defines the keys of types type used by this module. |
| | | * @template T |
| | | * @template {T[keyof T]} V |
| | | * @typedef {({ [P in keyof Required<T>]: Required<T>[P] extends V ? P : never })[keyof T]} KeysOfTypes |
| | | * @typedef {({ [key in keyof Required<T>]: Required<T>[key] extends V ? key : never })[keyof T]} KeysOfTypes |
| | | */ |
| | | |
| | | /** @typedef {Set<string>} UnhandledProperties */ |
| | | |
| | | /** @typedef {(data: EffectData) => (RuleSetUseItem | (Falsy | RuleSetUseItem)[])} RuleSetUseFn */ |
| | | /** @typedef {(value: string) => boolean} RuleSetConditionFn */ |
| | | |
| | | /** @typedef {{ apply: (ruleSetCompiler: RuleSetCompiler) => void }} RuleSetPlugin */ |
| | | |
| | | class RuleSetCompiler { |
| | | /** |
| | | * Creates an instance of RuleSetCompiler. |
| | | * @param {RuleSetPlugin[]} plugins plugins |
| | | */ |
| | | constructor(plugins) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns compiled RuleSet. |
| | | * @param {RuleSetRules} ruleSet raw user provided rules |
| | | * @returns {RuleSet} compiled RuleSet |
| | | */ |
| | | compile(ruleSet) { |
| | | /** @type {References} */ |
| | | const refs = new Map(); |
| | | const rules = this.compileRules("ruleSet", ruleSet, refs); |
| | | |
| | | /** |
| | | * Returns true, if the rule has matched. |
| | | * @param {EffectData} data data passed in |
| | | * @param {CompiledRule} rule the compiled rule |
| | | * @param {Effect[]} effects an array where effects are pushed to |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns rules. |
| | | * @param {string} path current path |
| | | * @param {RuleSetRules} rules the raw rules provided by user |
| | | * @param {References} refs references |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns normalized and compiled rule for processing. |
| | | * @param {string} path current path |
| | | * @param {RuleSetRule} rule the raw rule provided by user |
| | | * @param {References} refs references |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns compiled condition. |
| | | * @param {string} path current path |
| | | * @param {RuleSetLoaderOptions} condition user provided condition value |
| | | * @returns {Condition} compiled condition |
| | |
| | | ); |
| | | } |
| | | |
| | | /** @type {Condition[]} */ |
| | | const conditions = []; |
| | | for (const key of Object.keys(condition)) { |
| | | const value = condition[key]; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Combine conditions or. |
| | | * @param {Condition[]} conditions some conditions |
| | | * @returns {Condition} merged condition |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Combine conditions and. |
| | | * @param {Condition[]} conditions some conditions |
| | | * @returns {Condition} merged condition |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns an error object. |
| | | * @param {string} path current path |
| | | * @param {EXPECTED_ANY} value value at the error location |
| | | * @param {string} message message explaining the problem |