j-vite-plugin-dynamic-base
Version:
Resolve all resource files dynamic publicPath, like Webpack's __webpack_public_path__
39 lines (38 loc) • 1.22 kB
TypeScript
import { ModuleItem, StringLiteral } from "@swc/core";
import Visitor from "@swc/core/Visitor";
/**
* Traverses an AST (or parts of it) to collect all StringLiterals that contain
* needle in their value.
*/
export declare class StringLiteralCollector extends Visitor {
baseStringLiterals: StringLiteral[];
private readonly needle;
constructor(needle: string);
visitStringLiteral(n: StringLiteral): StringLiteral;
}
/**
* Represents a string as bytes, so it can be sliced via
* byte-positions.
*/
export declare class StringAsBytes {
private string;
private decoder;
constructor(string: string);
/**
* Returns a slice of the string by providing byte indices.
* @param from - Byte index to slice from
* @param to - Optional byte index to slice to
*/
slice(from: number, to?: number): string;
}
/**
* Parses js code into a AST.
* @param code
*/
export declare function parseCode(code: string): Promise<[number, ModuleItem[]]>;
/**
* Returns an array of StringLiterals from an AST that contain needle in their value.
* @param needle
* @param ast
*/
export declare function collectMatchingStringLiterals(needle: string, ast: ModuleItem[]): StringLiteral[];