diff --git a/README.md b/README.md index 9463a015..fdbc9b62 100644 --- a/README.md +++ b/README.md @@ -144,18 +144,16 @@ You can also tell Prettier to leave entire regions as they are: Let's look at an example of a plugin to the plugin: ```javascript -const melodyIconPlugin = require("../melody-plugin-icon-tag"); +import melodyIconPlugin from "../melody-plugin-icon-tag.js"; const printIconTag = (node, path, print, options) => { // Implementation of printing // ... }; -module.exports = { - melodyExtensions: [melodyIconPlugin], - printers: { - IconTag: printIconTag - } +export const melodyExtensions = [melodyIconPlugin]; +export const printers = { + IconTag: printIconTag }; ``` diff --git a/plugins.md b/plugins.md index 89c355f9..81afc83c 100644 --- a/plugins.md +++ b/plugins.md @@ -32,16 +32,14 @@ tbd A plugin has to export an object of the following shape: ``` -module.exports = { - melodyExtensions: [ - ext1, - ext2, - ... - ], - printers: { - nodeTypeName1: printNodeType1, - nodeTypeName2: printNodeType2, - ... - } +export const melodyExtensions = [ + ext1, + ext2, + ... +]; +export const printers: { + nodeTypeName1: printNodeType1, + nodeTypeName2: printNodeType2, + ... }; ``` diff --git a/src/index.js b/src/index.js index e4db05f4..42936d80 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ -const { print } = require("./printer.js"); -const { parse } = require("./parser.js"); -const symbols = require("./util/publicSymbols.js"); -const publicFunctions = require("./util/publicFunctions.js"); +import { print } from "./printer.js"; +import { parse } from "./parser.js"; +import * as symbols from "./util/publicSymbols.js"; +import * as publicFunctions from "./util/publicFunctions.js"; const languages = [ { @@ -135,4 +135,4 @@ const combinedExports = Object.assign( // This exports defines the Prettier plugin // See https://github.com/prettier/prettier/blob/master/docs/plugins.md -module.exports = combinedExports; +export default combinedExports; diff --git a/src/parser.js b/src/parser.js index dd456b8d..d4c4fc3d 100644 --- a/src/parser.js +++ b/src/parser.js @@ -1,9 +1,9 @@ -const { CharStream, Lexer, TokenStream, Parser } = require("melody-parser"); -const { extension: coreExtension } = require("melody-extension-core"); -const { +import { CharStream, Lexer, TokenStream, Parser } from "melody-parser"; +import { extension as coreExtension } from "melody-extension-core"; +import { getAdditionalMelodyExtensions, getPluginPathsFromOptions -} = require("./util"); +} from "./util/index.js"; const ORIGINAL_SOURCE = Symbol("ORIGINAL_SOURCE"); @@ -86,7 +86,4 @@ const parse = (text, parsers, options) => { return ast; }; -module.exports = { - parse, - ORIGINAL_SOURCE -}; +export { parse, ORIGINAL_SOURCE }; diff --git a/src/plugins/switch-plugin/index.js b/src/plugins/switch-plugin/index.js index 8b29b396..4524b44e 100644 --- a/src/plugins/switch-plugin/index.js +++ b/src/plugins/switch-plugin/index.js @@ -1,12 +1,13 @@ -const prettier = require("prettier"); -const { indent, hardline } = prettier.doc.builders; -const { +import { doc } from "prettier"; +import { Node } from "melody-types"; +import { STRING_NEEDS_QUOTES, printSingleTwigTag, indentWithHardline, isEmptySequence -} = require("../../util"); -const { Node } = require("melody-types"); +} from "../../util/index.js"; + +const { indent, hardline } = doc.builders; const printSwitch = (node, path, print) => { node[STRING_NEEDS_QUOTES] = true; @@ -30,8 +31,6 @@ const printSwitch = (node, path, print) => { return parts; }; -module.exports = { - printers: { - switchTag: printSwitch - } +export const printers = { + switchTag: printSwitch }; diff --git a/src/print/AliasExpression.js b/src/print/AliasExpression.js index cd68279f..8fca7c27 100644 --- a/src/print/AliasExpression.js +++ b/src/print/AliasExpression.js @@ -2,6 +2,4 @@ const p = (node, path, print) => { return [path.call(print, "name"), " as ", path.call(print, "alias")]; }; -module.exports = { - printAliasExpression: p -}; +export { p as printAliasExpression }; diff --git a/src/print/ArrayExpression.js b/src/print/ArrayExpression.js index 66f51b05..d62cc5f7 100644 --- a/src/print/ArrayExpression.js +++ b/src/print/ArrayExpression.js @@ -1,6 +1,7 @@ -const prettier = require("prettier"); -const { group, softline, line, indent, join } = prettier.doc.builders; -const { STRING_NEEDS_QUOTES } = require("../util"); +import { doc } from "prettier"; +import { STRING_NEEDS_QUOTES } from "../util/index.js"; + +const { group, softline, line, indent, join } = doc.builders; const p = (node, path, print) => { node[STRING_NEEDS_QUOTES] = true; @@ -10,6 +11,4 @@ const p = (node, path, print) => { return group(["[", indent(indentedContent), softline, "]"]); }; -module.exports = { - printArrayExpression: p -}; +export { p as printArrayExpression }; diff --git a/src/print/Attribute.js b/src/print/Attribute.js index 8a5817f4..0a9da697 100644 --- a/src/print/Attribute.js +++ b/src/print/Attribute.js @@ -1,5 +1,5 @@ -const { EXPRESSION_NEEDED, STRING_NEEDS_QUOTES } = require("../util"); -const { Node } = require("melody-types"); +import { Node } from "melody-types"; +import { EXPRESSION_NEEDED, STRING_NEEDS_QUOTES } from "../util/index.js"; const mayCorrectWhitespace = attrName => ["id", "class", "type"].indexOf(attrName) > -1; @@ -47,6 +47,4 @@ const p = (node, path, print = print) => { return docs; }; -module.exports = { - printAttribute: p -}; +export { p as printAttribute }; diff --git a/src/print/AutoescapeBlock.js b/src/print/AutoescapeBlock.js index 837a6110..e69f80da 100644 --- a/src/print/AutoescapeBlock.js +++ b/src/print/AutoescapeBlock.js @@ -1,6 +1,7 @@ -const prettier = require("prettier"); -const { hardline } = prettier.doc.builders; -const { printChildBlock, quoteChar } = require("../util"); +import { doc } from "prettier"; +import { printChildBlock, quoteChar } from "../util/index.js"; + +const { hardline } = doc.builders; const createOpener = (node, options) => { return [ @@ -27,6 +28,4 @@ const p = (node, path, print, options) => { return parts; }; -module.exports = { - printAutoescapeBlock: p -}; +export { p as printAutoescapeBlock }; diff --git a/src/print/BinaryExpression.js b/src/print/BinaryExpression.js index a7ec429f..5a631122 100644 --- a/src/print/BinaryExpression.js +++ b/src/print/BinaryExpression.js @@ -1,7 +1,7 @@ -const prettier = require("prettier"); -const { group, line, softline, indent } = prettier.doc.builders; -const { Node } = require("melody-types"); -const { +import { doc } from "prettier"; +import { Node } from "melody-types"; +import { extension as coreExtension } from "melody-extension-core"; +import { EXPRESSION_NEEDED, STRING_NEEDS_QUOTES, INSIDE_OF_STRING, @@ -10,8 +10,9 @@ const { firstValueInAncestorChain, findParentNode, wrapExpressionIfNeeded -} = require("../util"); -const { extension: coreExtension } = require("melody-extension-core"); +} from "../util/index.js"; + +const { group, line, softline, indent } = doc.builders; const ALREADY_INDENTED = Symbol("ALREADY_INDENTED"); const OPERATOR_PRECEDENCE = Symbol("OPERATOR_PRECEDENCE"); const NO_WHITESPACE_AROUND = [".."]; @@ -151,6 +152,4 @@ const p = (node, path, print, options) => { return printBinaryExpression(node, path, print); }; -module.exports = { - printBinaryExpression: p -}; +export { p as printBinaryExpression }; diff --git a/src/print/BlockStatement.js b/src/print/BlockStatement.js index 9a47f52f..5b053b2a 100644 --- a/src/print/BlockStatement.js +++ b/src/print/BlockStatement.js @@ -1,7 +1,8 @@ -const prettier = require("prettier"); -const { hardline, group } = prettier.doc.builders; -const { Node } = require("melody-types"); -const { EXPRESSION_NEEDED, printChildBlock } = require("../util"); +import { doc } from "prettier"; +import { Node } from "melody-types"; +import { EXPRESSION_NEEDED, printChildBlock } from "../util/index.js"; + +const { hardline, group } = doc.builders; const p = (node, path, print, options) => { node[EXPRESSION_NEEDED] = false; @@ -44,6 +45,4 @@ const p = (node, path, print, options) => { } }; -module.exports = { - printBlockStatement: p -}; +export { p as printBlockStatement }; diff --git a/src/print/CallExpression.js b/src/print/CallExpression.js index 73d62b76..7506427a 100644 --- a/src/print/CallExpression.js +++ b/src/print/CallExpression.js @@ -1,11 +1,12 @@ -const prettier = require("prettier"); -const { group, softline, line, indent, join } = prettier.doc.builders; -const { +import { doc } from "prettier"; +import { Node } from "melody-types"; +import { EXPRESSION_NEEDED, STRING_NEEDS_QUOTES, wrapExpressionIfNeeded -} = require("../util"); -const { Node } = require("melody-types"); +} from "../util/index.js"; + +const { group, softline, line, indent, join } = doc.builders; const p = (node, path, print) => { node[EXPRESSION_NEEDED] = false; @@ -34,6 +35,4 @@ const p = (node, path, print) => { return group(parts); }; -module.exports = { - printCallExpression: p -}; +export { p as printCallExpression }; diff --git a/src/print/ConditionalExpression.js b/src/print/ConditionalExpression.js index e21a3345..5284d075 100644 --- a/src/print/ConditionalExpression.js +++ b/src/print/ConditionalExpression.js @@ -1,10 +1,11 @@ -const prettier = require("prettier"); -const { line, indent, group } = prettier.doc.builders; -const { +import { doc } from "prettier"; +import { EXPRESSION_NEEDED, STRING_NEEDS_QUOTES, wrapExpressionIfNeeded -} = require("../util"); +} from "../util/index.js"; + +const { line, indent, group } = doc.builders; const p = (node, path, print) => { node[EXPRESSION_NEEDED] = false; @@ -23,6 +24,4 @@ const p = (node, path, print) => { return group(parts); }; -module.exports = { - printConditionalExpression: p -}; +export { p as printConditionalExpression }; diff --git a/src/print/Declaration.js b/src/print/Declaration.js index 24569ab7..f8ec1ca1 100644 --- a/src/print/Declaration.js +++ b/src/print/Declaration.js @@ -1,6 +1,7 @@ -const prettier = require("prettier"); -const { fill, join } = prettier.doc.builders; -const { STRING_NEEDS_QUOTES, OVERRIDE_QUOTE_CHAR } = require("../util"); +import { doc } from "prettier"; +import { STRING_NEEDS_QUOTES, OVERRIDE_QUOTE_CHAR } from "../util/index.js"; + +const { fill, join } = doc.builders; const p = (node, path, print) => { node[STRING_NEEDS_QUOTES] = true; @@ -11,6 +12,4 @@ const p = (node, path, print) => { return fill([start, " ", join(" ", printedParts), ">"]); }; -module.exports = { - printDeclaration: p -}; +export { p as printDeclaration }; diff --git a/src/print/DoStatement.js b/src/print/DoStatement.js index e3149814..d2159086 100644 --- a/src/print/DoStatement.js +++ b/src/print/DoStatement.js @@ -7,6 +7,4 @@ const p = (node, path, print) => { ]; }; -module.exports = { - printDoStatement: p -}; +export { p as printDoStatement }; diff --git a/src/print/Element.js b/src/print/Element.js index 22c3c0d5..87fa0e64 100644 --- a/src/print/Element.js +++ b/src/print/Element.js @@ -1,12 +1,13 @@ -const prettier = require("prettier"); -const { group, line, hardline, softline, indent, join } = prettier.doc.builders; -const { +import { doc } from "prettier"; +import { removeSurroundingWhitespace, isInlineElement, printChildGroups, EXPRESSION_NEEDED, STRING_NEEDS_QUOTES -} = require("../util"); +} from "../util/index.js"; + +const { group, line, hardline, softline, indent, join } = doc.builders; const printOpeningTag = (node, path, print) => { const opener = "<" + node.name; @@ -59,6 +60,4 @@ const p = (node, path, print) => { return openingGroup; }; -module.exports = { - printElement: p -}; +export { p as printElement }; diff --git a/src/print/EmbedStatement.js b/src/print/EmbedStatement.js index b9b4cce0..f579651b 100644 --- a/src/print/EmbedStatement.js +++ b/src/print/EmbedStatement.js @@ -1,10 +1,11 @@ -const prettier = require("prettier"); -const { indent, hardline, line, group } = prettier.doc.builders; -const { +import { doc } from "prettier"; +import { EXPRESSION_NEEDED, STRING_NEEDS_QUOTES, printChildBlock -} = require("../util"); +} from "../util/index.js"; + +const { indent, hardline, line, group } = doc.builders; const printOpener = (node, path, print) => { node[EXPRESSION_NEEDED] = false; @@ -34,6 +35,4 @@ const p = (node, path, print) => { return [printedOpener, children, closing]; }; -module.exports = { - printEmbedStatement: p -}; +export { p as printEmbedStatement }; diff --git a/src/print/ExpressionStatement.js b/src/print/ExpressionStatement.js index f13e9379..bcb949cb 100644 --- a/src/print/ExpressionStatement.js +++ b/src/print/ExpressionStatement.js @@ -1,11 +1,12 @@ -const prettier = require("prettier"); -const { group, indent, line } = prettier.doc.builders; -const { +import { doc } from "prettier"; +import { Node } from "melody-types"; +import { EXPRESSION_NEEDED, STRING_NEEDS_QUOTES, isContractableNodeType -} = require("../util"); -const { Node } = require("melody-types"); +} from "../util/index.js"; + +const { group, indent, line } = doc.builders; const p = (node, path, print) => { node[EXPRESSION_NEEDED] = false; @@ -21,6 +22,4 @@ const p = (node, path, print) => { return group([opener, value, padding, closing]); }; -module.exports = { - printExpressionStatement: p -}; +export { p as printExpressionStatement }; diff --git a/src/print/ExtendsStatement.js b/src/print/ExtendsStatement.js index 53e34b26..6204efee 100644 --- a/src/print/ExtendsStatement.js +++ b/src/print/ExtendsStatement.js @@ -1,4 +1,4 @@ -const { STRING_NEEDS_QUOTES } = require("../util"); +import { STRING_NEEDS_QUOTES } from "../util/index.js"; const p = (node, path, print) => { node[STRING_NEEDS_QUOTES] = true; @@ -10,6 +10,4 @@ const p = (node, path, print) => { ]; }; -module.exports = { - printExtendsStatement: p -}; +export { p as printExtendsStatement }; diff --git a/src/print/FilterBlockStatement.js b/src/print/FilterBlockStatement.js index a276883b..295ce938 100644 --- a/src/print/FilterBlockStatement.js +++ b/src/print/FilterBlockStatement.js @@ -1,6 +1,7 @@ -const prettier = require("prettier"); -const { group, line, hardline } = prettier.doc.builders; -const { FILTER_BLOCK, printChildBlock } = require("../util"); +import { doc } from "prettier"; +import { FILTER_BLOCK, printChildBlock } from "../util/index.js"; + +const { group, line, hardline } = doc.builders; const printOpeningGroup = (node, path, print) => { const parts = [node.trimLeft ? "{%- " : "{% "]; @@ -23,6 +24,4 @@ const p = (node, path, print) => { return [openingGroup, body, closingStatement]; }; -module.exports = { - printFilterBlockStatement: p -}; +export { p as printFilterBlockStatement }; diff --git a/src/print/FilterExpression.js b/src/print/FilterExpression.js index aa22b83a..58993346 100644 --- a/src/print/FilterExpression.js +++ b/src/print/FilterExpression.js @@ -1,7 +1,6 @@ -const prettier = require("prettier"); -const { group, indent, line, softline, join } = prettier.doc.builders; -const { Node } = require("melody-types"); -const { +import { doc } from "prettier"; +import { Node } from "melody-types"; +import { EXPRESSION_NEEDED, INSIDE_OF_STRING, STRING_NEEDS_QUOTES, @@ -11,7 +10,9 @@ const { someParentNode, isMultipartExpression, getDeepProperty -} = require("../util"); +} from "../util/index.js"; + +const { group, indent, line, softline, join } = doc.builders; const isInFilterBlock = path => someParentNode(path, node => node[FILTER_BLOCK] === true); @@ -127,6 +128,4 @@ const p = (node, path, print, options) => { return group(parts); }; -module.exports = { - printFilterExpression: p -}; +export { p as printFilterExpression }; diff --git a/src/print/FlushStatement.js b/src/print/FlushStatement.js index 1a9b29a8..66e12ecd 100644 --- a/src/print/FlushStatement.js +++ b/src/print/FlushStatement.js @@ -4,6 +4,4 @@ const p = (node, path, print) => { return `{%${dashLeft} flush ${dashRight}%}`; }; -module.exports = { - printFlushStatement: p -}; +export { p as printFlushStatement }; diff --git a/src/print/ForStatement.js b/src/print/ForStatement.js index aba19a1b..d8c7f022 100644 --- a/src/print/ForStatement.js +++ b/src/print/ForStatement.js @@ -1,10 +1,11 @@ -const prettier = require("prettier"); -const { group, indent, line, hardline } = prettier.doc.builders; -const { +import { doc } from "prettier"; +import { EXPRESSION_NEEDED, isWhitespaceNode, indentWithHardline -} = require("../util"); +} from "../util/index.js"; + +const { group, indent, line, hardline } = doc.builders; const printFor = (node, path, print) => { const parts = [node.trimLeft ? "{%-" : "{%", " for "]; @@ -54,6 +55,4 @@ const p = (node, path, print) => { return parts; }; -module.exports = { - printForStatement: p -}; +export { p as printForStatement }; diff --git a/src/print/FromStatement.js b/src/print/FromStatement.js index f89249d8..369375a9 100644 --- a/src/print/FromStatement.js +++ b/src/print/FromStatement.js @@ -1,6 +1,7 @@ -const prettier = require("prettier"); -const { group, join, line, indent } = prettier.doc.builders; -const { STRING_NEEDS_QUOTES } = require("../util"); +import { doc } from "prettier"; +import { STRING_NEEDS_QUOTES } from "../util/index.js"; + +const { group, join, line, indent } = doc.builders; const printImportDeclaration = node => { const parts = [node.key.name]; @@ -28,6 +29,4 @@ const p = (node, path, print) => { ]); }; -module.exports = { - printFromStatement: p -}; +export { p as printFromStatement }; diff --git a/src/print/GenericToken.js b/src/print/GenericToken.js index 7510d680..98a12197 100644 --- a/src/print/GenericToken.js +++ b/src/print/GenericToken.js @@ -2,6 +2,4 @@ const p = (node, path, print) => { return node.tokenText; }; -module.exports = { - printGenericToken: p -}; +export { p as printGenericToken }; diff --git a/src/print/GenericTwigTag.js b/src/print/GenericTwigTag.js index 7cfb5a62..7a240986 100644 --- a/src/print/GenericTwigTag.js +++ b/src/print/GenericTwigTag.js @@ -1,12 +1,13 @@ -const prettier = require("prettier"); -const { hardline } = prettier.doc.builders; -const { Node } = require("melody-types"); -const { +import { doc } from "prettier"; +import { Node } from "melody-types"; +import { STRING_NEEDS_QUOTES, indentWithHardline, printSingleTwigTag, isEmptySequence -} = require("../util"); +} from "../util/index.js"; + +const { hardline } = doc.builders; const p = (node, path, print) => { node[STRING_NEEDS_QUOTES] = true; @@ -26,6 +27,4 @@ const p = (node, path, print) => { return parts; }; -module.exports = { - printGenericTwigTag: p -}; +export { p as printGenericTwigTag }; diff --git a/src/print/HtmlComment.js b/src/print/HtmlComment.js index ef85dd0a..73f73f44 100644 --- a/src/print/HtmlComment.js +++ b/src/print/HtmlComment.js @@ -1,11 +1,12 @@ -const prettier = require("prettier"); -const { join, indent, hardline } = prettier.doc.builders; -const { +import { doc } from "prettier"; +import { createTextGroups, stripHtmlCommentChars, normalizeHtmlComment, countNewlines -} = require("../util"); +} from "../util/index.js"; + +const { join, indent, hardline } = doc.builders; const p = (node, path, print) => { const commentText = stripHtmlCommentChars(node.value.value || ""); @@ -18,6 +19,4 @@ const p = (node, path, print) => { return [""]; }; -module.exports = { - printHtmlComment: p -}; +export { p as printHtmlComment }; diff --git a/src/print/Identifier.js b/src/print/Identifier.js index 83a5406d..51b90788 100644 --- a/src/print/Identifier.js +++ b/src/print/Identifier.js @@ -1,6 +1,7 @@ -const prettier = require("prettier"); -const { group } = prettier.doc.builders; -const { EXPRESSION_NEEDED, wrapExpressionIfNeeded } = require("../util"); +import { doc } from "prettier"; +import { EXPRESSION_NEEDED, wrapExpressionIfNeeded } from "../util/index.js"; + +const { group } = doc.builders; const p = (node, path) => { node[EXPRESSION_NEEDED] = false; @@ -11,6 +12,4 @@ const p = (node, path) => { return parts.length === 1 ? result : group(result); }; -module.exports = { - printIdentifier: p -}; +export { p as printIdentifier }; diff --git a/src/print/IfStatement.js b/src/print/IfStatement.js index 5c1fda30..fa6383f3 100644 --- a/src/print/IfStatement.js +++ b/src/print/IfStatement.js @@ -1,12 +1,14 @@ -const prettier = require("prettier"); -const { group, indent, line, hardline } = prettier.doc.builders; -const { EXPRESSION_NEEDED, printChildBlock } = require("../util"); -const { Node } = require("melody-types"); -const { +import { doc } from "prettier"; +import { Node } from "melody-types"; +import { + printChildBlock, hasNoNewlines, + EXPRESSION_NEEDED, PRESERVE_LEADING_WHITESPACE, PRESERVE_TRAILING_WHITESPACE -} = require("../util"); +} from "../util/index.js"; + +const { group, indent, line, hardline } = doc.builders; const IS_ELSEIF = Symbol("IS_ELSEIF"); @@ -76,6 +78,4 @@ const p = (node, path, print) => { return parts; }; -module.exports = { - printIfStatement: p -}; +export { p as printIfStatement }; diff --git a/src/print/ImportDeclaration.js b/src/print/ImportDeclaration.js index cf1deb1c..125fbbb5 100644 --- a/src/print/ImportDeclaration.js +++ b/src/print/ImportDeclaration.js @@ -1,6 +1,7 @@ -const prettier = require("prettier"); -const { group, line, indent } = prettier.doc.builders; -const { STRING_NEEDS_QUOTES } = require("../util"); +import { doc } from "prettier"; +import { STRING_NEEDS_QUOTES } from "../util/index.js"; + +const { group, line, indent } = doc.builders; const p = (node, path, print) => { node[STRING_NEEDS_QUOTES] = true; @@ -14,6 +15,4 @@ const p = (node, path, print) => { ]); }; -module.exports = { - printImportDeclaration: p -}; +export { p as printImportDeclaration }; diff --git a/src/print/IncludeStatement.js b/src/print/IncludeStatement.js index 61fbc12d..ee0e730c 100644 --- a/src/print/IncludeStatement.js +++ b/src/print/IncludeStatement.js @@ -1,6 +1,7 @@ -const prettier = require("prettier"); -const { group } = prettier.doc.builders; -const { STRING_NEEDS_QUOTES } = require("../util"); +import { doc } from "prettier"; +import { STRING_NEEDS_QUOTES } from "../util/index.js"; + +const { group } = doc.builders; const p = (node, path, print) => { node[STRING_NEEDS_QUOTES] = true; @@ -22,6 +23,4 @@ const p = (node, path, print) => { return group(parts); }; -module.exports = { - printIncludeStatement: p -}; +export { p as printIncludeStatement }; diff --git a/src/print/MacroDeclarationStatement.js b/src/print/MacroDeclarationStatement.js index 4308d885..6eab0908 100644 --- a/src/print/MacroDeclarationStatement.js +++ b/src/print/MacroDeclarationStatement.js @@ -1,5 +1,6 @@ -const prettier = require("prettier"); -const { group, join, line, softline, hardline, indent } = prettier.doc.builders; +import { doc } from "prettier"; + +const { group, join, line, softline, hardline, indent } = doc.builders; const printOpener = (node, path, print) => { const parts = [ @@ -27,6 +28,4 @@ const p = (node, path, print) => { return parts; }; -module.exports = { - printMacroDeclarationStatement: p -}; +export { p as printMacroDeclarationStatement }; diff --git a/src/print/MemberExpression.js b/src/print/MemberExpression.js index d24b379d..493ef88f 100644 --- a/src/print/MemberExpression.js +++ b/src/print/MemberExpression.js @@ -1,10 +1,11 @@ -const prettier = require("prettier"); -const { group } = prettier.doc.builders; -const { +import { doc } from "prettier"; +import { EXPRESSION_NEEDED, STRING_NEEDS_QUOTES, wrapExpressionIfNeeded -} = require("../util"); +} from "../util/index.js"; + +const { group } = doc.builders; const p = (node, path, print) => { node[EXPRESSION_NEEDED] = false; @@ -19,6 +20,4 @@ const p = (node, path, print) => { return group(parts); }; -module.exports = { - printMemberExpression: p -}; +export { p as printMemberExpression }; diff --git a/src/print/MountStatement.js b/src/print/MountStatement.js index d6a69a9a..b3e7c83a 100644 --- a/src/print/MountStatement.js +++ b/src/print/MountStatement.js @@ -1,6 +1,7 @@ -const prettier = require("prettier"); -const { group, indent, line, hardline } = prettier.doc.builders; -const { EXPRESSION_NEEDED, STRING_NEEDS_QUOTES } = require("../util"); +import { doc } from "prettier"; +import { EXPRESSION_NEEDED, STRING_NEEDS_QUOTES } from "../util/index.js"; + +const { group, indent, line, hardline } = doc.builders; const formatDelay = delay => { return "" + delay / 1000 + "s"; @@ -80,6 +81,4 @@ const p = (node, path, print) => { return parts; }; -module.exports = { - printMountStatement: p -}; +export { p as printMountStatement }; diff --git a/src/print/NamedArgumentExpression.js b/src/print/NamedArgumentExpression.js index c6f038e1..6e97f1f7 100644 --- a/src/print/NamedArgumentExpression.js +++ b/src/print/NamedArgumentExpression.js @@ -1,4 +1,4 @@ -const { STRING_NEEDS_QUOTES } = require("../util"); +import { STRING_NEEDS_QUOTES } from "../util/index.js"; const p = (node, path, print) => { node[STRING_NEEDS_QUOTES] = true; @@ -7,6 +7,4 @@ const p = (node, path, print) => { return [printedName, " = ", printedValue]; }; -module.exports = { - printNamedArgumentExpression: p -}; +export { p as printNamedArgumentExpression }; diff --git a/src/print/ObjectExpression.js b/src/print/ObjectExpression.js index 20eada4d..db8de404 100644 --- a/src/print/ObjectExpression.js +++ b/src/print/ObjectExpression.js @@ -1,6 +1,7 @@ -const prettier = require("prettier"); -const { group, line, hardline, indent, join } = prettier.doc.builders; -const { EXPRESSION_NEEDED, wrapExpressionIfNeeded } = require("../util"); +import { doc } from "prettier"; +import { EXPRESSION_NEEDED, wrapExpressionIfNeeded } from "../util/index.js"; + +const { group, line, hardline, indent, join } = doc.builders; const p = (node, path, print, options) => { if (node.properties.length === 0) { @@ -17,6 +18,4 @@ const p = (node, path, print, options) => { return group(parts); }; -module.exports = { - printObjectExpression: p -}; +export { p as printObjectExpression }; diff --git a/src/print/ObjectProperty.js b/src/print/ObjectProperty.js index 1f4065c0..ca6ba70e 100644 --- a/src/print/ObjectProperty.js +++ b/src/print/ObjectProperty.js @@ -1,5 +1,5 @@ -const { isValidIdentifierName, STRING_NEEDS_QUOTES } = require("../util"); -const { Node } = require("melody-types"); +import { Node } from "melody-types"; +import { isValidIdentifierName, STRING_NEEDS_QUOTES } from "../util/index.js"; const p = (node, path, print, options) => { node[STRING_NEEDS_QUOTES] = @@ -22,6 +22,4 @@ const p = (node, path, print, options) => { return parts; }; -module.exports = { - printObjectProperty: p -}; +export { p as printObjectProperty }; diff --git a/src/print/SequenceExpression.js b/src/print/SequenceExpression.js index 28197970..2f7f614e 100644 --- a/src/print/SequenceExpression.js +++ b/src/print/SequenceExpression.js @@ -1,11 +1,12 @@ -const prettier = require("prettier"); -const { hardline } = prettier.doc.builders; -const { +import { doc } from "prettier"; +import { removeSurroundingWhitespace, printChildGroups, isRootNode, STRING_NEEDS_QUOTES -} = require("../util"); +} from "../util/index.js"; + +const { hardline } = doc.builders; const p = (node, path, print) => { node[STRING_NEEDS_QUOTES] = false; @@ -17,6 +18,4 @@ const p = (node, path, print) => { return items; }; -module.exports = { - printSequenceExpression: p -}; +export { p as printSequenceExpression }; diff --git a/src/print/SetStatement.js b/src/print/SetStatement.js index c4daba16..a169480e 100644 --- a/src/print/SetStatement.js +++ b/src/print/SetStatement.js @@ -1,12 +1,13 @@ -const prettier = require("prettier"); -const { group, line, hardline } = prettier.doc.builders; -const { +import { doc } from "prettier"; +import { Node } from "melody-types"; +import { printChildBlock, isNotExpression, STRING_NEEDS_QUOTES, GROUP_TOP_LEVEL_LOGICAL -} = require("../util"); -const { Node } = require("melody-types"); +} from "../util/index.js"; + +const { group, line, hardline } = doc.builders; const shouldAvoidBreakBeforeClosing = valueNode => Node.isObjectExpression(valueNode) || @@ -87,6 +88,4 @@ const p = (node, path, print) => { return printRegularSet(node, path, print); }; -module.exports = { - printSetStatement: p -}; +export { p as printSetStatement }; diff --git a/src/print/SliceExpression.js b/src/print/SliceExpression.js index 87f483f6..3b66df15 100644 --- a/src/print/SliceExpression.js +++ b/src/print/SliceExpression.js @@ -5,6 +5,4 @@ const p = (node, path, print) => { return [printedTarget, "[", printedStart, ":", printedEnd, "]"]; }; -module.exports = { - printSliceExpression: p -}; +export { p as printSliceExpression }; diff --git a/src/print/SpacelessBlock.js b/src/print/SpacelessBlock.js index 19ac89e8..76625a55 100644 --- a/src/print/SpacelessBlock.js +++ b/src/print/SpacelessBlock.js @@ -1,6 +1,7 @@ -const prettier = require("prettier"); -const { hardline, group } = prettier.doc.builders; -const { printChildBlock } = require("../util"); +import { doc } from "prettier"; +import { printChildBlock } from "../util/index.js"; + +const { hardline, group } = doc.builders; const p = (node, path, print) => { const parts = [ @@ -19,6 +20,4 @@ const p = (node, path, print) => { return result; }; -module.exports = { - printSpacelessBlock: p -}; +export { p as printSpacelessBlock }; diff --git a/src/print/StringLiteral.js b/src/print/StringLiteral.js index d88fc757..7c87dba3 100644 --- a/src/print/StringLiteral.js +++ b/src/print/StringLiteral.js @@ -1,9 +1,9 @@ -const { +import { firstValueInAncestorChain, quoteChar, STRING_NEEDS_QUOTES, OVERRIDE_QUOTE_CHAR -} = require("../util"); +} from "../util/index.js"; const isUnmaskedOccurrence = (s, pos) => { return pos === 0 || s[pos - 1] !== "\\"; @@ -60,6 +60,4 @@ const p = (node, path, print, options) => { return node.value; }; -module.exports = { - printStringLiteral: p -}; +export { p as printStringLiteral }; diff --git a/src/print/TestExpression.js b/src/print/TestExpression.js index b782a3bf..67a781a5 100644 --- a/src/print/TestExpression.js +++ b/src/print/TestExpression.js @@ -1,6 +1,7 @@ -const prettier = require("prettier"); -const { softline, line, group, join, indent } = prettier.doc.builders; -const { findParentNode } = require("../util"); +import { doc } from "prettier"; +import { findParentNode } from "../util/index.js"; + +const { softline, line, group, join, indent } = doc.builders; const textMap = { TestNullExpression: "null", @@ -43,6 +44,4 @@ const p = (node, path, print) => { return parts; }; -module.exports = { - printTestExpression: p -}; +export { p as printTestExpression }; diff --git a/src/print/TextStatement.js b/src/print/TextStatement.js index 0057cf7d..f448f571 100644 --- a/src/print/TextStatement.js +++ b/src/print/TextStatement.js @@ -1,13 +1,14 @@ -const prettier = require("prettier"); -const { line, join, hardline } = prettier.doc.builders; -const { +import { doc } from "prettier"; +import { isWhitespaceOnly, countNewlines, createTextGroups, PRESERVE_LEADING_WHITESPACE, PRESERVE_TRAILING_WHITESPACE, NEWLINES_ONLY -} = require("../util"); +} from "../util/index.js"; + +const { line, join, hardline } = doc.builders; const newlinesOnly = (s, preserveWhitespace = true) => { const numNewlines = countNewlines(s); @@ -41,6 +42,4 @@ const p = (node, path, print) => { return join([hardline, hardline], textGroups); }; -module.exports = { - printTextStatement: p -}; +export { p as printTextStatement }; diff --git a/src/print/TwigComment.js b/src/print/TwigComment.js index 2a770c61..cb2f2bc4 100644 --- a/src/print/TwigComment.js +++ b/src/print/TwigComment.js @@ -1,9 +1,9 @@ -const { +import { createTextGroups, stripTwigCommentChars, normalizeTwigComment, countNewlines -} = require("../util"); +} from "../util/index.js"; const p = node => { const originalText = node.value.value || ""; @@ -20,6 +20,4 @@ const p = node => { return [trimLeft ? "{#-" : "{#", commentText, trimRight ? "-#}" : "#}"]; }; -module.exports = { - printTwigComment: p -}; +export { p as printTwigComment }; diff --git a/src/print/UnaryExpression.js b/src/print/UnaryExpression.js index 1b075483..69ff6001 100644 --- a/src/print/UnaryExpression.js +++ b/src/print/UnaryExpression.js @@ -1,10 +1,11 @@ -const prettier = require("prettier"); -const { group } = prettier.doc.builders; -const { +import { doc } from "prettier"; +import { EXPRESSION_NEEDED, STRING_NEEDS_QUOTES, wrapExpressionIfNeeded -} = require("../util"); +} from "../util/index.js"; + +const { group } = doc.builders; const p = (node, path, print) => { node[EXPRESSION_NEEDED] = false; @@ -14,6 +15,4 @@ const p = (node, path, print) => { return group(parts); }; -module.exports = { - printUnaryExpression: p -}; +export { p as printUnaryExpression }; diff --git a/src/print/UnarySubclass.js b/src/print/UnarySubclass.js index 8a55160e..20d79bbc 100644 --- a/src/print/UnarySubclass.js +++ b/src/print/UnarySubclass.js @@ -1,13 +1,14 @@ -const prettier = require("prettier"); -const { softline, indent, group } = prettier.doc.builders; -const { Node } = require("melody-types"); -const { +import { doc } from "prettier"; +import { Node } from "melody-types"; +import { firstValueInAncestorChain, findParentNode, isMultipartExpression, IS_ROOT_LOGICAL_EXPRESSION, GROUP_TOP_LEVEL_LOGICAL -} = require("../util"); +} from "../util/index.js"; + +const { softline, indent, group } = doc.builders; const argumentNeedsParentheses = node => isMultipartExpression(node); @@ -54,6 +55,4 @@ const p = (node, path, print) => { return parts; }; -module.exports = { - printUnarySubclass: p -}; +export { p as printUnarySubclass }; diff --git a/src/print/UseStatement.js b/src/print/UseStatement.js index 83380e6d..4be251bc 100644 --- a/src/print/UseStatement.js +++ b/src/print/UseStatement.js @@ -1,5 +1,6 @@ -const prettier = require("prettier"); -const { group, indent, join, line } = prettier.doc.builders; +import { doc } from "prettier"; + +const { group, indent, join, line } = doc.builders; const p = (node, path, print) => { const docs = [ @@ -21,6 +22,4 @@ const p = (node, path, print) => { return group(docs); }; -module.exports = { - printUseStatement: p -}; +export { p as printUseStatement }; diff --git a/src/print/VariableDeclarationStatement.js b/src/print/VariableDeclarationStatement.js index 90199394..90ff7526 100644 --- a/src/print/VariableDeclarationStatement.js +++ b/src/print/VariableDeclarationStatement.js @@ -1,6 +1,7 @@ -const prettier = require("prettier"); -const { line, indent } = prettier.doc.builders; -const { STRING_NEEDS_QUOTES, isContractableNodeType } = require("../util"); +import { doc } from "prettier"; +import { STRING_NEEDS_QUOTES, isContractableNodeType } from "../util/index.js"; + +const { line, indent } = doc.builders; const p = (node, path, print) => { const printedName = path.call(print, "name"); @@ -17,6 +18,4 @@ const p = (node, path, print) => { return [printedName, " =", rightHandSide]; }; -module.exports = { - printVariableDeclarationStatement: p -}; +export { p as printVariableDeclarationStatement }; diff --git a/src/printer.js b/src/printer.js index 82deebad..5b3948ea 100644 --- a/src/printer.js +++ b/src/printer.js @@ -1,65 +1,55 @@ -const { printSequenceExpression } = require("./print/SequenceExpression.js"); -const { printBinaryExpression } = require("./print/BinaryExpression.js"); -const { - printConditionalExpression -} = require("./print/ConditionalExpression.js"); -const { printElement } = require("./print/Element.js"); -const { printAttribute } = require("./print/Attribute.js"); -const { printIdentifier } = require("./print/Identifier.js"); -const { printExpressionStatement } = require("./print/ExpressionStatement.js"); -const { printMemberExpression } = require("./print/MemberExpression.js"); -const { printFilterExpression } = require("./print/FilterExpression.js"); -const { printObjectExpression } = require("./print/ObjectExpression.js"); -const { printObjectProperty } = require("./print/ObjectProperty.js"); -const { printCallExpression } = require("./print/CallExpression.js"); -const { printTestExpression } = require("./print/TestExpression.js"); -const { printUnaryExpression } = require("./print/UnaryExpression.js"); -const { printUnarySubclass } = require("./print/UnarySubclass.js"); -const { printTextStatement } = require("./print/TextStatement.js"); -const { printStringLiteral } = require("./print/StringLiteral.js"); -const { printArrayExpression } = require("./print/ArrayExpression.js"); -const { printSliceExpression } = require("./print/SliceExpression.js"); -const { printUseStatement } = require("./print/UseStatement.js"); -const { printAliasExpression } = require("./print/AliasExpression.js"); -const { printBlockStatement } = require("./print/BlockStatement.js"); -const { printSpacelessBlock } = require("./print/SpacelessBlock.js"); -const { printAutoescapeBlock } = require("./print/AutoescapeBlock.js"); -const { printFlushStatement } = require("./print/FlushStatement.js"); -const { printIncludeStatement } = require("./print/IncludeStatement.js"); -const { printIfStatement } = require("./print/IfStatement.js"); -const { printMountStatement } = require("./print/MountStatement.js"); -const { printForStatement } = require("./print/ForStatement.js"); -const { printSetStatement } = require("./print/SetStatement.js"); -const { printDoStatement } = require("./print/DoStatement.js"); -const { printExtendsStatement } = require("./print/ExtendsStatement.js"); -const { printEmbedStatement } = require("./print/EmbedStatement.js"); -const { printImportDeclaration } = require("./print/ImportDeclaration.js"); -const { printFromStatement } = require("./print/FromStatement.js"); -const { printTwigComment } = require("./print/TwigComment.js"); -const { printHtmlComment } = require("./print/HtmlComment.js"); -const { printDeclaration } = require("./print/Declaration.js"); -const { printGenericTwigTag } = require("./print/GenericTwigTag.js"); -const { printGenericToken } = require("./print/GenericToken.js"); -const { - printMacroDeclarationStatement -} = require("./print/MacroDeclarationStatement.js"); -const { - printFilterBlockStatement -} = require("./print/FilterBlockStatement.js"); -const { - printVariableDeclarationStatement -} = require("./print/VariableDeclarationStatement.js"); -const { - printNamedArgumentExpression -} = require("./print/NamedArgumentExpression.js"); -const { +import { printSequenceExpression } from "./print/SequenceExpression.js"; +import { printBinaryExpression } from "./print/BinaryExpression.js"; +import { printConditionalExpression } from "./print/ConditionalExpression.js"; +import { printElement } from "./print/Element.js"; +import { printAttribute } from "./print/Attribute.js"; +import { printIdentifier } from "./print/Identifier.js"; +import { printExpressionStatement } from "./print/ExpressionStatement.js"; +import { printMemberExpression } from "./print/MemberExpression.js"; +import { printFilterExpression } from "./print/FilterExpression.js"; +import { printObjectExpression } from "./print/ObjectExpression.js"; +import { printObjectProperty } from "./print/ObjectProperty.js"; +import { printCallExpression } from "./print/CallExpression.js"; +import { printTestExpression } from "./print/TestExpression.js"; +import { printUnaryExpression } from "./print/UnaryExpression.js"; +import { printUnarySubclass } from "./print/UnarySubclass.js"; +import { printTextStatement } from "./print/TextStatement.js"; +import { printStringLiteral } from "./print/StringLiteral.js"; +import { printArrayExpression } from "./print/ArrayExpression.js"; +import { printSliceExpression } from "./print/SliceExpression.js"; +import { printUseStatement } from "./print/UseStatement.js"; +import { printAliasExpression } from "./print/AliasExpression.js"; +import { printBlockStatement } from "./print/BlockStatement.js"; +import { printSpacelessBlock } from "./print/SpacelessBlock.js"; +import { printAutoescapeBlock } from "./print/AutoescapeBlock.js"; +import { printFlushStatement } from "./print/FlushStatement.js"; +import { printIncludeStatement } from "./print/IncludeStatement.js"; +import { printIfStatement } from "./print/IfStatement.js"; +import { printMountStatement } from "./print/MountStatement.js"; +import { printForStatement } from "./print/ForStatement.js"; +import { printSetStatement } from "./print/SetStatement.js"; +import { printDoStatement } from "./print/DoStatement.js"; +import { printExtendsStatement } from "./print/ExtendsStatement.js"; +import { printEmbedStatement } from "./print/EmbedStatement.js"; +import { printImportDeclaration } from "./print/ImportDeclaration.js"; +import { printFromStatement } from "./print/FromStatement.js"; +import { printTwigComment } from "./print/TwigComment.js"; +import { printHtmlComment } from "./print/HtmlComment.js"; +import { printDeclaration } from "./print/Declaration.js"; +import { printGenericTwigTag } from "./print/GenericTwigTag.js"; +import { printGenericToken } from "./print/GenericToken.js"; +import { printMacroDeclarationStatement } from "./print/MacroDeclarationStatement.js"; +import { printFilterBlockStatement } from "./print/FilterBlockStatement.js"; +import { printVariableDeclarationStatement } from "./print/VariableDeclarationStatement.js"; +import { printNamedArgumentExpression } from "./print/NamedArgumentExpression.js"; +import { isWhitespaceNode, isHtmlCommentEqualTo, isTwigCommentEqualTo, getPluginPathsFromOptions, loadPlugins -} = require("./util"); -const { ORIGINAL_SOURCE } = require("./parser"); +} from "./util/index.js"; +import { ORIGINAL_SOURCE } from "./parser.js"; const printFunctions = {}; @@ -277,6 +267,4 @@ printFunctions["GenericToken"] = printGenericToken; // Fallbacks printFunctions["String"] = s => s; -module.exports = { - print -}; +export { print }; diff --git a/src/util/index.js b/src/util/index.js index 039e1a2b..4328171b 100644 --- a/src/util/index.js +++ b/src/util/index.js @@ -1,14 +1,4 @@ -const pluginUtil = require("./pluginUtil.js"); -const publicSymbols = require("./publicSymbols.js"); -const publicFunctions = require("./publicFunctions.js"); -const printFunctions = require("./printFunctions.js"); - -const combinedExports = Object.assign( - {}, - pluginUtil, - publicSymbols, - publicFunctions, - printFunctions -); - -module.exports = combinedExports; +export * from "./pluginUtil.js"; +export * from "./printFunctions.js"; +export * from "./publicSymbols.js"; +export * from "./publicFunctions.js"; diff --git a/src/util/pluginUtil.js b/src/util/pluginUtil.js index 1f8bb925..b38d4f46 100644 --- a/src/util/pluginUtil.js +++ b/src/util/pluginUtil.js @@ -1,5 +1,5 @@ -const path = require("path"); -const resolve = require("resolve"); +import path from "path"; +import resolve from "resolve"; const getPluginPathsFromOptions = options => { if (options.twigMelodyPlugins && Array.isArray(options.twigMelodyPlugins)) { @@ -68,7 +68,7 @@ const getAdditionalMelodyExtensions = pluginPaths => { return result.filter(elem => !!elem); }; -module.exports = { +export { getPluginPathsFromOptions, tryLoadPlugin, loadPlugins, diff --git a/src/util/printFunctions.js b/src/util/printFunctions.js index 9aff346b..66fd484c 100644 --- a/src/util/printFunctions.js +++ b/src/util/printFunctions.js @@ -1,6 +1,7 @@ -const prettier = require("prettier"); -const { line, indent, group } = prettier.doc.builders; -const { Node } = require("melody-types"); +import { doc } from "prettier"; +import { Node } from "melody-types"; + +const { line, indent, group } = doc.builders; const noSpaceBeforeToken = { ",": true @@ -29,6 +30,4 @@ const printSingleTwigTag = (node, path, print) => { return group(parts); }; -module.exports = { - printSingleTwigTag -}; +export { printSingleTwigTag }; diff --git a/src/util/publicFunctions.js b/src/util/publicFunctions.js index 653dc8c8..41134a7b 100644 --- a/src/util/publicFunctions.js +++ b/src/util/publicFunctions.js @@ -1,13 +1,14 @@ -const { EXPRESSION_NEEDED, INSIDE_OF_STRING } = require("./publicSymbols.js"); -const prettier = require("prettier"); -const { line, indent, fill, group, hardline } = prettier.doc.builders; -const { Node } = require("melody-types"); - -const { +import { doc } from "prettier"; +import { Node } from "melody-types"; +import { + EXPRESSION_NEEDED, + INSIDE_OF_STRING, PRESERVE_LEADING_WHITESPACE, PRESERVE_TRAILING_WHITESPACE, NEWLINES_ONLY -} = require("./publicSymbols.js"); +} from "./publicSymbols.js"; + +const { line, indent, fill, group, hardline } = doc.builders; const INLINE_HTML_ELEMENTS = [ "a", @@ -550,7 +551,7 @@ const printChildGroups = (node, path, print, ...childPath) => { return finishedGroups; }; -module.exports = { +export { shouldExpressionsBeWrapped, wrapExpressionIfNeeded, wrapInStringInterpolation, diff --git a/src/util/publicSymbols.js b/src/util/publicSymbols.js index b8065489..33d70bdd 100644 --- a/src/util/publicSymbols.js +++ b/src/util/publicSymbols.js @@ -74,7 +74,7 @@ const GROUP_TOP_LEVEL_LOGICAL = Symbol("GROUP_TOP_LEVEL_LOGICAL"); */ const IS_ROOT_LOGICAL_EXPRESSION = Symbol("IS_ROOT_LOGICAL_EXPRESSION"); -module.exports = { +export { STRING_NEEDS_QUOTES, OVERRIDE_QUOTE_CHAR, INSIDE_OF_STRING, diff --git a/tests_config/raw-serializer.js b/tests_config/raw-serializer.js index 09e650b4..acb70c3c 100644 --- a/tests_config/raw-serializer.js +++ b/tests_config/raw-serializer.js @@ -1,14 +1,11 @@ const RAW = Symbol.for("raw"); -module.exports = { - print(val) { - return val[RAW]; - }, - test(val) { - return ( - val && - Object.prototype.hasOwnProperty.call(val, RAW) && - typeof val[RAW] === "string" - ); - } +const print = val => val[RAW]; +const test = val => + val && + Object.prototype.hasOwnProperty.call(val, RAW) && + typeof val[RAW] === "string"; +export default { + print, + test }; diff --git a/tests_config/run_spec.js b/tests_config/run_spec.js index b67d2326..be7c2d12 100644 --- a/tests_config/run_spec.js +++ b/tests_config/run_spec.js @@ -1,6 +1,6 @@ -const fs = require("fs"); -const extname = require("path").extname; -const prettier = require("prettier"); +import fs from "fs"; +import prettier from "prettier"; +import { extname } from "path"; import { beforeAll, test, expect } from "vitest"; function run_spec(dirname, parsers, options) {