UNPKG

@textlint/kernel

Version:
25 lines 843 B
import { isPluginParsedObject } from "./isPluginParsedObject"; /** * Parse text by plugin * If parse error is occurred, return an Error * @param preProcess * @param sourceText * @param filePath */ export const parseByPlugin = async ({ preProcess, sourceText, filePath }) => { try { const preProcessResult = await preProcess(sourceText, filePath); const isParsedObject = isPluginParsedObject(preProcessResult); const textForAST = isParsedObject ? preProcessResult.text : sourceText; const ast = isParsedObject ? preProcessResult.ast : preProcessResult; return { text: textForAST, ast }; } catch (error) { // Parse error return error instanceof Error ? error : new Error(String(error)); } }; //# sourceMappingURL=parse-by-plugin.js.map