| | |
| | | const quoteMeta = (str) => str.replace(/[-[\]\\/{}()*+?.^$|]/g, "\\$&"); |
| | | |
| | | /** |
| | | * Split context from prefix. |
| | | * @param {string} prefix prefix |
| | | * @returns {{prefix: string, context: string}} result |
| | | * @returns {{ prefix: string, context: string }} result |
| | | */ |
| | | const splitContextFromPrefix = (prefix) => { |
| | | const idx = prefix.lastIndexOf("/"); |
| | |
| | | }; |
| | | |
| | | /** @typedef {Partial<Omit<ContextDependencyOptions, "resource">>} PartialContextDependencyOptions */ |
| | | /** @typedef {{ new(options: ContextDependencyOptions, range: Range, valueRange: Range, ...args: any[]): ContextDependency }} ContextDependencyConstructor */ |
| | | /** @typedef {{ new (options: ContextDependencyOptions, range: Range, valueRange: Range, ...args: EXPECTED_ANY[]): ContextDependency }} ContextDependencyConstructor */ |
| | | |
| | | /** |
| | | * @param {ContextDependencyConstructor} Dep the Dependency class |
| | | * Defines the get additional dep args type used by this module. |
| | | * @template T |
| | | * @typedef {T extends new (options: ContextDependencyOptions, range: Range, valueRange: Range, ...remains: infer R) => EXPECTED_ANY ? R : []} GetAdditionalDepArgs |
| | | */ |
| | | |
| | | /** |
| | | * Returns the created Dependency. |
| | | * @template {ContextDependencyConstructor} T |
| | | * @param {T} Dep the Dependency class |
| | | * @param {Range} range source range |
| | | * @param {BasicEvaluatedExpression} param context param |
| | | * @param {Expression} expr expr |
| | | * @param {Pick<JavascriptParserOptions, `${"expr"|"wrapped"}Context${"Critical"|"Recursive"|"RegExp"}` | "exprContextRequest">} options options for context creation |
| | | * @param {Pick<JavascriptParserOptions, `${"expr" | "wrapped"}Context${"Critical" | "Recursive" | "RegExp"}` | "exprContextRequest">} options options for context creation |
| | | * @param {PartialContextDependencyOptions} contextOptions options for the ContextModule |
| | | * @param {JavascriptParser} parser the parser |
| | | * @param {...EXPECTED_ANY} depArgs depArgs |
| | | * @param {GetAdditionalDepArgs<T>} depArgs depArgs |
| | | * @returns {ContextDependency} the created Dependency |
| | | */ |
| | | module.exports.create = ( |
| | |
| | | ...depArgs |
| | | ); |
| | | dep.loc = /** @type {DependencyLocation} */ (expr.loc); |
| | | /** @type {Replaces} */ |
| | | const replaces = []; |
| | | if (prefixRange) { |
| | | replaces.push({ |