Skip to content

Commit

Permalink
convert requires/imports and exports to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
rellafella committed May 1, 2024
1 parent 3ab79fb commit 5134d26
Show file tree
Hide file tree
Showing 57 changed files with 325 additions and 412 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
```

Expand Down
20 changes: 9 additions & 11 deletions plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
...
};
```
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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 = [
{
Expand Down Expand Up @@ -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;
13 changes: 5 additions & 8 deletions src/parser.js
Original file line number Diff line number Diff line change
@@ -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");

Expand Down Expand Up @@ -86,7 +86,4 @@ const parse = (text, parsers, options) => {
return ast;
};

module.exports = {
parse,
ORIGINAL_SOURCE
};
export { parse, ORIGINAL_SOURCE };
17 changes: 8 additions & 9 deletions src/plugins/switch-plugin/index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -30,8 +31,6 @@ const printSwitch = (node, path, print) => {
return parts;
};

module.exports = {
printers: {
switchTag: printSwitch
}
export const printers = {
switchTag: printSwitch
};
4 changes: 1 addition & 3 deletions src/print/AliasExpression.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
11 changes: 5 additions & 6 deletions src/print/ArrayExpression.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,6 +11,4 @@ const p = (node, path, print) => {
return group(["[", indent(indentedContent), softline, "]"]);
};

module.exports = {
printArrayExpression: p
};
export { p as printArrayExpression };
8 changes: 3 additions & 5 deletions src/print/Attribute.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -47,6 +47,4 @@ const p = (node, path, print = print) => {
return docs;
};

module.exports = {
printAttribute: p
};
export { p as printAttribute };
11 changes: 5 additions & 6 deletions src/print/AutoescapeBlock.js
Original file line number Diff line number Diff line change
@@ -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 [
Expand All @@ -27,6 +28,4 @@ const p = (node, path, print, options) => {
return parts;
};

module.exports = {
printAutoescapeBlock: p
};
export { p as printAutoescapeBlock };
17 changes: 8 additions & 9 deletions src/print/BinaryExpression.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 = [".."];
Expand Down Expand Up @@ -151,6 +152,4 @@ const p = (node, path, print, options) => {
return printBinaryExpression(node, path, print);
};

module.exports = {
printBinaryExpression: p
};
export { p as printBinaryExpression };
13 changes: 6 additions & 7 deletions src/print/BlockStatement.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -44,6 +45,4 @@ const p = (node, path, print, options) => {
}
};

module.exports = {
printBlockStatement: p
};
export { p as printBlockStatement };
15 changes: 7 additions & 8 deletions src/print/CallExpression.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,6 +35,4 @@ const p = (node, path, print) => {
return group(parts);
};

module.exports = {
printCallExpression: p
};
export { p as printCallExpression };
13 changes: 6 additions & 7 deletions src/print/ConditionalExpression.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,6 +24,4 @@ const p = (node, path, print) => {
return group(parts);
};

module.exports = {
printConditionalExpression: p
};
export { p as printConditionalExpression };
11 changes: 5 additions & 6 deletions src/print/Declaration.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,6 +12,4 @@ const p = (node, path, print) => {
return fill([start, " ", join(" ", printedParts), ">"]);
};

module.exports = {
printDeclaration: p
};
export { p as printDeclaration };
4 changes: 1 addition & 3 deletions src/print/DoStatement.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ const p = (node, path, print) => {
];
};

module.exports = {
printDoStatement: p
};
export { p as printDoStatement };
13 changes: 6 additions & 7 deletions src/print/Element.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -59,6 +60,4 @@ const p = (node, path, print) => {
return openingGroup;
};

module.exports = {
printElement: p
};
export { p as printElement };
13 changes: 6 additions & 7 deletions src/print/EmbedStatement.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,6 +35,4 @@ const p = (node, path, print) => {
return [printedOpener, children, closing];
};

module.exports = {
printEmbedStatement: p
};
export { p as printEmbedStatement };
15 changes: 7 additions & 8 deletions src/print/ExpressionStatement.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,6 +22,4 @@ const p = (node, path, print) => {
return group([opener, value, padding, closing]);
};

module.exports = {
printExpressionStatement: p
};
export { p as printExpressionStatement };
Loading

0 comments on commit 5134d26

Please sign in to comment.