import { postcss } from "opticss"; import { Block } from "../BlockTree"; import { Options } from "../configuration"; import { FileIdentifier, ImportedFile } from "../importing"; import { BlockFactoryBase } from "./BlockFactoryBase"; import { BlockParser } from "./BlockParser"; import { Preprocessor, Preprocessors } from "./preprocessing"; /** * This factory ensures that instances of a block are re-used when blocks are * going to be compiled/optimized together. Multiple instances of the same * block will result in analysis and optimization bugs. * * This also ensures that importers and preprocessors are correctly used when loading a block file. */ export declare class BlockFactory extends BlockFactoryBase { parser: BlockParser; preprocessors: Preprocessors; private promises; private blocks; private paths; private preprocessQueue; get isSync(): false; constructor(options: Options, postcssImpl?: typeof postcss, faultTolerant?: boolean); /** * Toss out any caches in this BlockFactory. Any future requests for a block * or block path will be loaded fresh from persistent storage. */ reset(): void; /** * Parse a `postcss.Root` into a Block object. Save the Block promise and * return it. Use parseRoot if we need to catch errors. * * This function is referenced only in tests. * @param root The postcss.Root to parse. * @param identifier A unique identifier for this Block file. * @param name Default name for the block. * @param isDfnFile Whether to treat this as a definition file. * @returns The Block object promise. */ parseRootFaultTolerant(root: postcss.Root, identifier: string, name: string, isDfnFile?: boolean, expectedGuid?: string): Promise; /** * Parse a `postcss.Root` into a Block object. Save the Block promise and return it. * Also assert that the block is valid so that we can catch any errors that * the block contains. * * This function is only used in tests * @param root The postcss.Root to parse. * @param identifier A unique identifier for this Block file. * @param name Default name for the block. * @param isDfnFile Whether to treat this as a definition file. * @returns The Block object promise. */ parseRoot(root: postcss.Root, identifier: string, name: string, isDfnFile?: boolean, expectedGuid?: string): Promise; /** * In some cases (like when using preprocessors with native bindings), it may * be necessary to wait until the block factory has completed current * asynchronous work before exiting. Calling this method stops new pending * work from being performed and returns a promise that resolves when it is * safe to exit. */ prepareForExit(): Promise; /** * Given a file path (or other data path reference), load data from storage and parse it * into a CSS Block. * * @param filePath - The path to the file or data in persistent storage. The Importer that you've * configured to use will resolve this to a location in the storage system. * @returns A promise that resolves to the parsed block. */ getBlockFromPath(filePath: string): Promise; /** * Given a FileIdentifier that points to block data on storage, load the data and parse it * into a CSS Block. In most cases, you'll likely want to use getBlockFromPath() instead. * * If the block for the given identifier has already been loaded and parsed, * the cached data will be returned instead. If loading and parsing is already in progress, * the existing promise for that identifier will be returned. * * @param identifier - An identifier that points at a data file or blob in persistent storage. * These identifiers are created by the Importer that you've configured * to use. * @returns A promise that resolves to the parsed block. */ getBlock(identifier: FileIdentifier): Promise; /** * Make a promise to load and parse a CSS Block data file, add it to the cache, * and return it. * * @param identifier - An identifier that points at a data file or blob in persistent storage. * @returns A promise that resolves to the parsed block. */ private _getBlockPromise; /** * An async method that loads and parses a CSS Block data file. We load the data here, using * the Importer, then defer to another method to actually parse the data file into a Block. * * @param identifier - An identifier that points at a data file or blob in persistent storage. * @returns A promise that resolves to the parsed block. */ private _getBlockPromiseAsync; /** * Parse the file into a `Block`. Specifically, this method runs the data through any related * preprocessor (such as a SASS or LESS compiler), parses the CSS into an AST using PostCSS, then * hands the AST off to the Block parser to validate the CSS and transform it into the Block * class used by CSS Blocks. * * Notably, this method expects that any related file data has already been loaded from memory * using the Importer. * * @param file - The file information that has been previously imported by the Importer, for * a single block identifier. * @returns A promise that resolves to a parsed block. **/ private _importAndPreprocessBlock; private _reconstituteCompiledCssSource; /** * Similar to getBlock(), this imports and parses a block data file. However, this * method parses a block relative to another block. * * @param fromIdentifier - The FileIdentifier that references the base location that the * import path is relative to. * @param importPath - The relative import path for the file to import. * @returns A promise that resolves to a parsed block. */ getBlockRelative(fromIdentifier: FileIdentifier, importPath: string): Promise; preprocessor(file: ImportedFile): Preprocessor; } //# sourceMappingURL=BlockFactory.d.ts.map