| | |
| | | const PLUGIN_NAME = "URLParserPlugin"; |
| | | |
| | | /** |
| | | * Returns file url. |
| | | * @param {NormalModule} module module |
| | | * @returns {URL} file url |
| | | */ |
| | | const getUrl = (module) => pathToFileURL(module.resource); |
| | | |
| | | /** |
| | | * Checks whether this object is meta url. |
| | | * @param {JavascriptParser} parser parser parser |
| | | * @param {MemberExpression} arg arg |
| | | * @returns {boolean} true when it is `meta.url`, otherwise false |
| | |
| | | return true; |
| | | }; |
| | | |
| | | /** |
| | | * @type {WeakMap<NewExpressionNode, BasicEvaluatedExpression | undefined>} |
| | | */ |
| | | /** @type {WeakMap<NewExpressionNode, BasicEvaluatedExpression | undefined>} */ |
| | | const getEvaluatedExprCache = new WeakMap(); |
| | | |
| | | /** |
| | | * Gets evaluated expr. |
| | | * @param {NewExpressionNode} expr expression |
| | | * @param {JavascriptParser} parser parser parser |
| | | * @returns {BasicEvaluatedExpression | undefined} basic evaluated expression |
| | |
| | | if (result !== undefined) return result; |
| | | |
| | | /** |
| | | * Returns basic evaluated expression. |
| | | * @returns {BasicEvaluatedExpression | undefined} basic evaluated expression |
| | | */ |
| | | const evaluate = () => { |
| | |
| | | |
| | | class URLParserPlugin { |
| | | /** |
| | | * Creates an instance of URLParserPlugin. |
| | | * @param {JavascriptParserOptions} options options |
| | | */ |
| | | constructor(options) { |
| | | /** @type {JavascriptParserOptions} */ |
| | | this.options = options; |
| | | } |
| | | |
| | | /** |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {JavascriptParser} parser the parser |
| | | * @returns {void} |
| | | */ |
| | |
| | | const evaluatedExpr = getEvaluatedExpr(expr, parser); |
| | | if (!evaluatedExpr) return; |
| | | |
| | | /** @type {string | undefined} */ |
| | | let request; |
| | | |
| | | // static URL |
| | |
| | | if (this.options.dynamicUrl === false) return; |
| | | |
| | | // context URL |
| | | /** @type {undefined | RegExp} */ |
| | | let include; |
| | | /** @type {undefined | RegExp} */ |
| | | let exclude; |
| | | |
| | | if (importOptions) { |