import type { ChoiceSupportOption, SupportOptions } from "prettier"; import { type AutocompleteStringList, fallbackIndicator, makeCommentsOptionName, makeIdentifiersOptionName, makeParserOptionName, makeTagsOptionName, type StringListToInterfaceKey, } from "../utils.js"; import { language } from "./language.js"; const DEFAULT_COMMENTS_OR_TAGS = [ "js", "jsx", "es", "es6", "mjs", "cjs", "pac", "javascript", ] as const; const DEFAULT_COMMENTS = DEFAULT_COMMENTS_OR_TAGS; type Comments = AutocompleteStringList<(typeof DEFAULT_COMMENTS)[number]>; type DefaultCommentsHolder = StringListToInterfaceKey; const DEFAULT_TAGS = DEFAULT_COMMENTS_OR_TAGS; type Tags = AutocompleteStringList<(typeof DEFAULT_TAGS)[number]>; type DefaultTagsHolder = StringListToInterfaceKey; // TODO: keep in sync with prettier somehow const ES_PARSERS = [ "babel", "babel-flow", "acorn", "espree", "flow", "meriyah", ] as const; export type EsParser = (typeof ES_PARSERS)[number]; const EMBEDDED_LANGUAGE_IDENTIFIERS = makeIdentifiersOptionName(language); const EMBEDDED_LANGUAGE_COMMENTS = makeCommentsOptionName(language); const EMBEDDED_LANGUAGE_TAGS = makeTagsOptionName(language); const EMBEDDED_LANGUAGE_PARSER = makeParserOptionName(language); export const options = { [EMBEDDED_LANGUAGE_IDENTIFIERS]: { category: "Embed", type: "string", array: true, default: [{ value: [...DEFAULT_COMMENTS_OR_TAGS] }], description: "Tag or comment identifiers that make their subsequent template literals be identified as embedded ECMAScript/JavaScript language.", deprecated: `Please use \`${EMBEDDED_LANGUAGE_COMMENTS}\` or \`${EMBEDDED_LANGUAGE_TAGS}\`.`, }, [EMBEDDED_LANGUAGE_COMMENTS]: { category: "Embed", type: "string", array: true, default: [{ value: [fallbackIndicator] }], description: "Block comments that make their subsequent template literals be identified as embedded ECMAScript/JavaScript language.", }, [EMBEDDED_LANGUAGE_TAGS]: { category: "Embed", type: "string", array: true, default: [{ value: [fallbackIndicator] }], description: "Tags that make their subsequent template literals be identified as embedded ECMAScript/JavaScript language.", }, [EMBEDDED_LANGUAGE_PARSER]: { category: "Embed", type: "choice", default: "babel", description: "The parser used to parse the embedded ECMASCript/JavaScript language.", choices: ES_PARSERS.map((parser) => ({ value: parser, description: `Use the "${parser}" parser.`, })), } satisfies ChoiceSupportOption, } as const satisfies SupportOptions; type Options = typeof options; declare module "../types.js" { interface EmbeddedOptions extends Options {} interface EmbeddedDefaultCommentsHolder extends DefaultCommentsHolder {} interface EmbeddedDefaultTagsHolder extends DefaultTagsHolder {} interface PluginEmbedOptions { /** * @deprecated Please use `embeddedEsComments` or `embeddedEsTags`. */ [EMBEDDED_LANGUAGE_IDENTIFIERS]?: (Comments[number] | Tags[number])[]; [EMBEDDED_LANGUAGE_COMMENTS]?: Comments; [EMBEDDED_LANGUAGE_TAGS]?: Tags; [EMBEDDED_LANGUAGE_PARSER]?: EsParser; } }