prettier-plugin-solidity 1.1.2 → 1.1.4-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/README.md +48 -9
  2. package/dist/standalone.cjs +3 -0
  3. package/dist/standalone.cjs.map +1 -0
  4. package/package.json +42 -33
  5. package/src/binary-operator-printers/arithmetic.js +12 -14
  6. package/src/binary-operator-printers/assignment.js +4 -6
  7. package/src/binary-operator-printers/bit.js +2 -2
  8. package/src/binary-operator-printers/comparison.js +11 -13
  9. package/src/binary-operator-printers/exponentiation.js +4 -6
  10. package/src/binary-operator-printers/index.js +7 -13
  11. package/src/binary-operator-printers/logical.js +12 -14
  12. package/src/binary-operator-printers/shift.js +2 -2
  13. package/src/clean.js +1 -1
  14. package/src/comments/handler.js +7 -15
  15. package/src/comments/handlers/handleContractDefinitionComments.js +9 -11
  16. package/src/comments/handlers/handleModifierInvocationComments.js +9 -11
  17. package/src/comments/handlers/index.js +5 -3
  18. package/src/comments/ignore.js +1 -1
  19. package/src/comments/index.js +2 -4
  20. package/src/comments/printer.js +5 -10
  21. package/src/common/printer-helpers.js +15 -28
  22. package/src/common/util.js +30 -20
  23. package/src/index.js +14 -12
  24. package/src/loc.js +1 -1
  25. package/src/nodes/ArrayTypeName.js +1 -3
  26. package/src/nodes/AssemblyAssignment.js +4 -8
  27. package/src/nodes/AssemblyBlock.js +6 -11
  28. package/src/nodes/AssemblyCall.js +2 -4
  29. package/src/nodes/AssemblyCase.js +1 -3
  30. package/src/nodes/AssemblyFor.js +4 -8
  31. package/src/nodes/AssemblyFunctionDefinition.js +6 -11
  32. package/src/nodes/AssemblyIf.js +1 -3
  33. package/src/nodes/AssemblyLocalDefinition.js +4 -9
  34. package/src/nodes/AssemblyMemberAccess.js +1 -3
  35. package/src/nodes/AssemblyStackAssignment.js +1 -3
  36. package/src/nodes/AssemblySwitch.js +4 -8
  37. package/src/nodes/BinaryOperation.js +2 -5
  38. package/src/nodes/Block.js +6 -11
  39. package/src/nodes/BooleanLiteral.js +1 -3
  40. package/src/nodes/Break.js +1 -3
  41. package/src/nodes/BreakStatement.js +1 -3
  42. package/src/nodes/CatchClause.js +2 -4
  43. package/src/nodes/Conditional.js +4 -8
  44. package/src/nodes/Continue.js +1 -3
  45. package/src/nodes/ContinueStatement.js +1 -3
  46. package/src/nodes/ContractDefinition.js +11 -17
  47. package/src/nodes/CustomErrorDefinition.js +2 -4
  48. package/src/nodes/DecimalNumber.js +1 -3
  49. package/src/nodes/DoWhileStatement.js +4 -9
  50. package/src/nodes/ElementaryTypeName.js +1 -3
  51. package/src/nodes/EmitStatement.js +1 -3
  52. package/src/nodes/EnumDefinition.js +4 -9
  53. package/src/nodes/EnumValue.js +1 -3
  54. package/src/nodes/EventDefinition.js +2 -4
  55. package/src/nodes/ExpressionStatement.js +4 -9
  56. package/src/nodes/FileLevelConstant.js +1 -3
  57. package/src/nodes/ForStatement.js +4 -9
  58. package/src/nodes/FunctionCall.js +4 -9
  59. package/src/nodes/FunctionDefinition.js +11 -18
  60. package/src/nodes/FunctionTypeName.js +4 -9
  61. package/src/nodes/HexLiteral.js +4 -9
  62. package/src/nodes/HexNumber.js +1 -3
  63. package/src/nodes/Identifier.js +1 -3
  64. package/src/nodes/IfStatement.js +6 -11
  65. package/src/nodes/ImportDirective.js +12 -17
  66. package/src/nodes/IndexAccess.js +4 -8
  67. package/src/nodes/IndexRangeAccess.js +1 -3
  68. package/src/nodes/InheritanceSpecifier.js +2 -4
  69. package/src/nodes/InlineAssemblyStatement.js +3 -4
  70. package/src/nodes/LabelDefinition.js +4 -8
  71. package/src/nodes/Mapping.js +17 -18
  72. package/src/nodes/MemberAccess.js +6 -10
  73. package/src/nodes/ModifierDefinition.js +4 -9
  74. package/src/nodes/ModifierInvocation.js +3 -5
  75. package/src/nodes/NameValueExpression.js +1 -3
  76. package/src/nodes/NameValueList.js +4 -9
  77. package/src/nodes/NewExpression.js +1 -3
  78. package/src/nodes/NumberLiteral.js +1 -3
  79. package/src/nodes/PragmaDirective.js +1 -3
  80. package/src/nodes/ReturnStatement.js +4 -8
  81. package/src/nodes/RevertStatement.js +1 -3
  82. package/src/nodes/SourceUnit.js +4 -9
  83. package/src/nodes/StateVariableDeclaration.js +4 -8
  84. package/src/nodes/StringLiteral.js +5 -9
  85. package/src/nodes/StructDefinition.js +11 -14
  86. package/src/nodes/ThrowStatement.js +1 -3
  87. package/src/nodes/TryStatement.js +6 -11
  88. package/src/nodes/TupleExpression.js +4 -9
  89. package/src/nodes/TypeDefinition.js +1 -3
  90. package/src/nodes/UnaryOperation.js +1 -3
  91. package/src/nodes/UncheckedStatement.js +4 -8
  92. package/src/nodes/UserDefinedTypeName.js +1 -3
  93. package/src/nodes/UsingForDeclaration.js +14 -12
  94. package/src/nodes/VariableDeclaration.js +4 -9
  95. package/src/nodes/VariableDeclarationStatement.js +6 -11
  96. package/src/nodes/WhileStatement.js +4 -9
  97. package/src/nodes/index.js +72 -78
  98. package/src/options.js +1 -1
  99. package/src/parser.js +5 -12
  100. package/src/prettier-comments/language-js/comments.js +13 -23
  101. package/src/printer.js +6 -6
  102. package/dist/standalone.js +0 -3
  103. package/dist/standalone.js.map +0 -1
  104. package/src/prettier-comments/index.js +0 -3
  105. /package/dist/{standalone.js.LICENSE.txt → standalone.cjs.LICENSE.txt} +0 -0
package/package.json CHANGED
@@ -1,28 +1,36 @@
1
1
  {
2
2
  "name": "prettier-plugin-solidity",
3
- "version": "1.1.2",
3
+ "version": "1.1.4-dev",
4
4
  "description": "A Prettier Plugin for automatically formatting your Solidity code.",
5
+ "type": "module",
5
6
  "main": "./src/index.js",
6
- "browser": "./dist/standalone.js",
7
- "unpkg": "./dist/standalone.js",
7
+ "browser": "./dist/standalone.cjs",
8
+ "unpkg": "./dist/standalone.cjs",
9
+ "exports": {
10
+ ".": {
11
+ "import": "./src/index.js",
12
+ "require": "./dist/standalone.cjs"
13
+ },
14
+ "./standalone": {
15
+ "default": "./dist/standalone.cjs"
16
+ }
17
+ },
8
18
  "scripts": {
9
19
  "build": "webpack --env production",
10
20
  "build:dev": "webpack --env development",
11
- "eslint": "eslint 'scripts/**' 'src/**' 'tests/**'",
12
- "generateindexes": "cross-env SCRIPT=true node scripts/generateIndexes.js",
21
+ "build:test": "webpack --config test.config.js",
22
+ "eslint": "eslint 'src/**' 'tests/**'",
13
23
  "lint": "npm run eslint && npm run prettier -- --list-different",
14
24
  "lint:fix": "npm run eslint -- --fix && npm run prettier -- --write",
15
25
  "prepublishOnly": "npm run build",
16
- "prettier": "prettier './*.{js,json,md,yml}' '{scripts,src,tests}/**/*.js'",
17
- "test": "jest",
18
- "test:all": "cross-env FULL_TEST=1 c8 jest",
26
+ "prettier": "prettier './*.{js,json,md,yml}' '{src,tests}/**/*.js'",
27
+ "test": "NODE_OPTIONS=--loader=esmock jest",
28
+ "test:all": "cross-env FULL_TEST=1 NODE_OPTIONS=--loader=esmock c8 jest",
19
29
  "test:standalone": "cross-env TEST_STANDALONE=1 FULL_TEST=1 jest"
20
30
  },
21
31
  "files": [
22
32
  "src",
23
- "dist/standalone.js",
24
- "dist/standalone.js.LICENSE.txt",
25
- "dist/standalone.js.map",
33
+ "dist/**/*",
26
34
  "LICENSE",
27
35
  "README.md"
28
36
  ],
@@ -76,43 +84,44 @@
76
84
  },
77
85
  "homepage": "https://github.com/prettier-solidity/prettier-plugin-solidity#readme",
78
86
  "engines": {
79
- "node": ">=12"
87
+ "node": ">=16"
80
88
  },
81
89
  "devDependencies": {
82
- "@babel/code-frame": "^7.18.6",
83
- "c8": "^7.12.0",
90
+ "@babel/code-frame": "^7.22.10",
91
+ "c8": "^8.0.1",
84
92
  "cross-env": "^7.0.3",
85
- "dir-to-object": "^2.0.0",
86
- "eslint": "^8.31.0",
93
+ "eslint": "^8.47.0",
87
94
  "eslint-config-airbnb-base": "^15.0.0",
88
- "eslint-config-prettier": "^8.5.0",
89
- "eslint-plugin-import": "^2.26.0",
95
+ "eslint-config-prettier": "^9.0.0",
96
+ "eslint-plugin-import": "^2.28.1",
97
+ "esm-utils": "^4.1.2",
98
+ "esmock": "^2.3.8",
90
99
  "exports-loader": "^4.0.0",
91
- "jest": "^29.3.1",
92
- "jest-light-runner": "^0.4.1",
93
- "jest-mock-now": "^1.3.0",
94
- "jest-snapshot-serializer-ansi": "^1.0.0",
95
- "jest-snapshot-serializer-raw": "^1.2.0",
96
- "jest-watch-typeahead": "^2.2.1",
100
+ "jest": "^29.6.3",
101
+ "jest-light-runner": "^0.5.0",
102
+ "jest-snapshot-serializer-ansi": "^2.1.0",
103
+ "jest-snapshot-serializer-raw": "^2.0.0",
104
+ "jest-watch-typeahead": "^2.2.2",
97
105
  "lines-and-columns": "^2.0.3",
98
- "prettier": "^2.8.1",
106
+ "prettier": "^3.0.2",
99
107
  "proxyquire": "^2.1.3",
100
- "solc": "^0.8.17",
101
- "webpack": "^5.75.0",
102
- "webpack-cli": "^5.0.1"
108
+ "solc": "^0.8.21",
109
+ "webpack": "^5.88.2",
110
+ "webpack-cli": "^5.1.4"
103
111
  },
104
112
  "dependencies": {
105
- "@solidity-parser/parser": "^0.15.0",
106
- "semver": "^7.3.8",
113
+ "@solidity-parser/parser": "^0.16.1",
114
+ "semver": "^7.5.4",
107
115
  "solidity-comments-extractor": "^0.0.7"
108
116
  },
109
117
  "peerDependencies": {
110
- "prettier": ">=2.3.0 || >=3.0.0-alpha.0"
118
+ "prettier": ">=2.3.0"
111
119
  },
112
120
  "browserslist": {
113
121
  "production": [
114
- ">0.2%",
115
- "not dead",
122
+ ">0.5%",
123
+ "not ie 11",
124
+ "not safari 5.1",
116
125
  "not op_mini all"
117
126
  ],
118
127
  "development": [
@@ -1,38 +1,36 @@
1
- const {
2
- doc: {
3
- builders: { group, line, indent }
4
- }
5
- } = require('prettier');
6
- const comparison = require('./comparison');
1
+ import { doc } from 'prettier';
2
+ import { comparison } from './comparison.js';
3
+
4
+ const { group, line, indent } = doc.builders;
7
5
 
8
- const groupIfNecessaryBuilder = (path) => (doc) => {
6
+ const groupIfNecessaryBuilder = (path) => (document) => {
9
7
  const parentNode = path.getParentNode();
10
8
  if (
11
9
  parentNode.type === 'BinaryOperation' &&
12
10
  !comparison.match(parentNode.operator)
13
11
  ) {
14
- return doc;
12
+ return document;
15
13
  }
16
- return group(doc);
14
+ return group(document);
17
15
  };
18
16
 
19
- const indentIfNecessaryBuilder = (path) => (doc) => {
17
+ const indentIfNecessaryBuilder = (path) => (document) => {
20
18
  let node = path.getNode();
21
19
  for (let i = 0; ; i += 1) {
22
20
  const parentNode = path.getParentNode(i);
23
- if (parentNode.type === 'ReturnStatement') return doc;
21
+ if (parentNode.type === 'ReturnStatement') return document;
24
22
  if (
25
23
  parentNode.type !== 'BinaryOperation' ||
26
24
  comparison.match(parentNode.operator)
27
25
  ) {
28
- return indent(doc);
26
+ return indent(document);
29
27
  }
30
- if (node === parentNode.right) return doc;
28
+ if (node === parentNode.right) return document;
31
29
  node = parentNode;
32
30
  }
33
31
  };
34
32
 
35
- module.exports = {
33
+ export const arithmetic = {
36
34
  match: (op) => ['+', '-', '*', '/', '%'].includes(op),
37
35
  print: (node, path, print) => {
38
36
  const groupIfNecessary = groupIfNecessaryBuilder(path);
@@ -1,10 +1,8 @@
1
- const {
2
- doc: {
3
- builders: { group, line, indent }
4
- }
5
- } = require('prettier');
1
+ import { doc } from 'prettier';
6
2
 
7
- module.exports = {
3
+ const { group, line, indent } = doc.builders;
4
+
5
+ export const assignment = {
8
6
  match: (op) =>
9
7
  [
10
8
  '=',
@@ -1,6 +1,6 @@
1
- const arithmetic = require('./arithmetic');
1
+ import { arithmetic } from './arithmetic.js';
2
2
 
3
- module.exports = {
3
+ export const bit = {
4
4
  match: (op) => ['&', '|', '^'].includes(op),
5
5
  print: arithmetic.print
6
6
  };
@@ -1,24 +1,22 @@
1
- const {
2
- doc: {
3
- builders: { group, line, indent }
4
- }
5
- } = require('prettier');
1
+ import { doc } from 'prettier';
2
+
3
+ const { group, indent, line } = doc.builders;
6
4
 
7
- const indentIfNecessaryBuilder = (path) => (doc) => {
5
+ const indentIfNecessaryBuilder = (path) => (document) => {
8
6
  let node = path.getNode();
9
7
  for (let i = 0; ; i += 1) {
10
8
  const parentNode = path.getParentNode(i);
11
- if (parentNode.type === 'ReturnStatement') return doc;
12
- if (parentNode.type === 'IfStatement') return doc;
13
- if (parentNode.type === 'ForStatement') return doc;
14
- if (parentNode.type === 'WhileStatement') return doc;
15
- if (parentNode.type !== 'BinaryOperation') return indent(doc);
16
- if (node === parentNode.right) return doc;
9
+ if (parentNode.type === 'ReturnStatement') return document;
10
+ if (parentNode.type === 'IfStatement') return document;
11
+ if (parentNode.type === 'ForStatement') return document;
12
+ if (parentNode.type === 'WhileStatement') return document;
13
+ if (parentNode.type !== 'BinaryOperation') return indent(document);
14
+ if (node === parentNode.right) return document;
17
15
  node = parentNode;
18
16
  }
19
17
  };
20
18
 
21
- module.exports = {
19
+ export const comparison = {
22
20
  match: (op) => ['<', '>', '<=', '>=', '==', '!='].includes(op),
23
21
  print: (node, path, print) => {
24
22
  const indentIfNecessary = indentIfNecessaryBuilder(path);
@@ -1,10 +1,8 @@
1
- const {
2
- doc: {
3
- builders: { group, indent, line }
4
- }
5
- } = require('prettier');
1
+ import { doc } from 'prettier';
2
+
3
+ const { group, indent, line } = doc.builders;
6
4
 
7
- module.exports = {
5
+ export const exponentiation = {
8
6
  match: (op) => op === '**',
9
7
  print: (node, path, print) => {
10
8
  const right = [' ', node.operator, line, path.call(print, 'right')];
@@ -1,13 +1,7 @@
1
- /* This file was automatically generated on 1666691919.933 */
2
-
3
- /* eslint-disable global-require */
4
-
5
- module.exports = {
6
- arithmetic: require('./arithmetic'),
7
- assignment: require('./assignment'),
8
- bit: require('./bit'),
9
- comparison: require('./comparison'),
10
- exponentiation: require('./exponentiation'),
11
- logical: require('./logical'),
12
- shift: require('./shift')
13
- };
1
+ export * from './arithmetic.js';
2
+ export * from './assignment.js';
3
+ export * from './bit.js';
4
+ export * from './comparison.js';
5
+ export * from './exponentiation.js';
6
+ export * from './logical.js';
7
+ export * from './shift.js';
@@ -1,26 +1,24 @@
1
- const {
2
- doc: {
3
- builders: { group, line, indent }
4
- }
5
- } = require('prettier');
1
+ import { doc } from 'prettier';
2
+
3
+ const { group, line, indent } = doc.builders;
6
4
 
7
- const groupIfNecessaryBuilder = (path) => (doc) =>
8
- path.getParentNode().type === 'BinaryOperation' ? doc : group(doc);
5
+ const groupIfNecessaryBuilder = (path) => (document) =>
6
+ path.getParentNode().type === 'BinaryOperation' ? document : group(document);
9
7
 
10
- const indentIfNecessaryBuilder = (path) => (doc) => {
8
+ const indentIfNecessaryBuilder = (path) => (document) => {
11
9
  let node = path.getNode();
12
10
  for (let i = 0; ; i += 1) {
13
11
  const parentNode = path.getParentNode(i);
14
- if (parentNode.type === 'ReturnStatement') return doc;
15
- if (parentNode.type === 'IfStatement') return doc;
16
- if (parentNode.type === 'WhileStatement') return doc;
17
- if (parentNode.type !== 'BinaryOperation') return indent(doc);
18
- if (node === parentNode.right) return doc;
12
+ if (parentNode.type === 'ReturnStatement') return document;
13
+ if (parentNode.type === 'IfStatement') return document;
14
+ if (parentNode.type === 'WhileStatement') return document;
15
+ if (parentNode.type !== 'BinaryOperation') return indent(document);
16
+ if (node === parentNode.right) return document;
19
17
  node = parentNode;
20
18
  }
21
19
  };
22
20
 
23
- module.exports = {
21
+ export const logical = {
24
22
  match: (op) => ['&&', '||'].includes(op),
25
23
  print: (node, path, print) => {
26
24
  const groupIfNecessary = groupIfNecessaryBuilder(path);
@@ -1,6 +1,6 @@
1
- const arithmetic = require('./arithmetic');
1
+ import { arithmetic } from './arithmetic.js';
2
2
 
3
- module.exports = {
3
+ export const shift = {
4
4
  match: (op) => ['<<', '>>'].includes(op),
5
5
  print: arithmetic.print
6
6
  };
package/src/clean.js CHANGED
@@ -3,4 +3,4 @@ const ignoredProperties = new Set(['loc', 'range', 'comments']);
3
3
  function clean(/* ast, newObj, parent */) {}
4
4
  clean.ignoredProperties = ignoredProperties;
5
5
 
6
- module.exports = clean;
6
+ export default clean;
@@ -1,12 +1,11 @@
1
- const {
1
+ import {
2
2
  handleOwnLineComment,
3
3
  handleEndOfLineComment,
4
4
  handleRemainingComment
5
- } = require('../prettier-comments/language-js/comments');
5
+ } from '../prettier-comments/language-js/comments.js';
6
+ import handlers from './handlers/index.js';
6
7
 
7
- const handlers = require('./handlers');
8
-
9
- function solidityHandleOwnLineComment(
8
+ export function solidityHandleOwnLineComment(
10
9
  comment,
11
10
  text,
12
11
  options,
@@ -32,7 +31,7 @@ function solidityHandleOwnLineComment(
32
31
  return false;
33
32
  }
34
33
 
35
- function solidityHandleEndOfLineComment(
34
+ export function solidityHandleEndOfLineComment(
36
35
  comment,
37
36
  text,
38
37
  options,
@@ -58,7 +57,7 @@ function solidityHandleEndOfLineComment(
58
57
  return false;
59
58
  }
60
59
 
61
- function solidityHandleRemainingComment(
60
+ export function solidityHandleRemainingComment(
62
61
  comment,
63
62
  text,
64
63
  options,
@@ -84,13 +83,6 @@ function solidityHandleRemainingComment(
84
83
  return false;
85
84
  }
86
85
 
87
- function isBlockComment(comment) {
86
+ export function isBlockComment(comment) {
88
87
  return comment.type === 'BlockComment';
89
88
  }
90
-
91
- module.exports = {
92
- handleOwnLineComment: solidityHandleOwnLineComment,
93
- handleEndOfLineComment: solidityHandleEndOfLineComment,
94
- handleRemainingComment: solidityHandleRemainingComment,
95
- isBlockComment
96
- };
@@ -1,11 +1,7 @@
1
- const {
2
- util: {
3
- addLeadingComment,
4
- addTrailingComment,
5
- addDanglingComment,
6
- getNextNonSpaceNonCommentCharacterIndex
7
- }
8
- } = require('prettier');
1
+ import { util } from 'prettier';
2
+ import { getNextNonSpaceNonCommentCharacter } from '../../common/util.js';
3
+
4
+ const { addLeadingComment, addTrailingComment, addDanglingComment } = util;
9
5
 
10
6
  function handleContractDefinitionComments({
11
7
  text,
@@ -24,8 +20,10 @@ function handleContractDefinitionComments({
24
20
  // contract a is abc /* comment */ {}
25
21
  // The only workaround I found is to look at the next character to see if
26
22
  // it is a {}.
27
- const nextCharacter = text.charAt(
28
- getNextNonSpaceNonCommentCharacterIndex(text, comment, options.locEnd)
23
+ const nextCharacter = getNextNonSpaceNonCommentCharacter(
24
+ text,
25
+ comment,
26
+ options.locEnd
29
27
  );
30
28
 
31
29
  // The comment is behind the start of the Block `{}` or behind a base contract
@@ -57,4 +55,4 @@ function handleContractDefinitionComments({
57
55
  return false;
58
56
  }
59
57
 
60
- module.exports = handleContractDefinitionComments;
58
+ export default handleContractDefinitionComments;
@@ -1,11 +1,7 @@
1
- const {
2
- util: {
3
- addLeadingComment,
4
- addTrailingComment,
5
- addDanglingComment,
6
- getNextNonSpaceNonCommentCharacterIndex
7
- }
8
- } = require('prettier');
1
+ import { util } from 'prettier';
2
+ import { getNextNonSpaceNonCommentCharacter } from '../../common/util.js';
3
+
4
+ const { addLeadingComment, addTrailingComment, addDanglingComment } = util;
9
5
 
10
6
  function handleModifierInvocationComments({
11
7
  text,
@@ -23,8 +19,10 @@ function handleModifierInvocationComments({
23
19
  // function a() public modifier /* comment 1 */ ( /* comment 2 */ ) /* comment 3 */
24
20
  // The only workaround I found is to look at the next character to see if
25
21
  // it is a ().
26
- const nextCharacter = text.charAt(
27
- getNextNonSpaceNonCommentCharacterIndex(text, comment, options.locEnd)
22
+ const nextCharacter = getNextNonSpaceNonCommentCharacter(
23
+ text,
24
+ comment,
25
+ options.locEnd
28
26
  );
29
27
 
30
28
  // The comment is behind the start of the Parentheses `()`
@@ -66,4 +64,4 @@ function handleModifierInvocationComments({
66
64
  return false;
67
65
  }
68
66
 
69
- module.exports = handleModifierInvocationComments;
67
+ export default handleModifierInvocationComments;
@@ -1,6 +1,8 @@
1
1
  /* eslint-disable global-require */
2
+ import handleContractDefinitionComments from './handleContractDefinitionComments.js';
3
+ import handleModifierInvocationComments from './handleModifierInvocationComments.js';
2
4
 
3
- module.exports = [
4
- require('./handleContractDefinitionComments'),
5
- require('./handleModifierInvocationComments')
5
+ export default [
6
+ handleContractDefinitionComments,
7
+ handleModifierInvocationComments
6
8
  ];
@@ -30,4 +30,4 @@ function ignoreComments(path) {
30
30
  });
31
31
  }
32
32
 
33
- module.exports = ignoreComments;
33
+ export default ignoreComments;
@@ -1,4 +1,2 @@
1
- const handler = require('./handler');
2
- const printer = require('./printer');
3
-
4
- module.exports = { handleComments: handler, printComment: printer };
1
+ export * from './handler.js';
2
+ export * from './printer.js';
@@ -1,9 +1,6 @@
1
- const {
2
- doc: {
3
- builders: { hardline, join }
4
- },
5
- util: { hasNewline }
6
- } = require('prettier');
1
+ import { doc, util } from 'prettier';
2
+
3
+ const { hardline, join } = doc.builders;
7
4
 
8
5
  function isIndentableBlockComment(comment) {
9
6
  // If the comment has multiple lines and every line starts with a star
@@ -31,7 +28,7 @@ function printIndentableBlockComment(comment) {
31
28
  ];
32
29
  }
33
30
 
34
- function printComment(commentPath, options) {
31
+ export function printComment(commentPath, options) {
35
32
  const comment = commentPath.getValue();
36
33
 
37
34
  switch (comment.type) {
@@ -43,7 +40,7 @@ function printComment(commentPath, options) {
43
40
  // interleaved. See https://github.com/prettier/prettier/issues/4412
44
41
  if (
45
42
  comment.trailing &&
46
- !hasNewline(options.originalText, options.locStart(comment), {
43
+ !util.hasNewline(options.originalText, options.locStart(comment), {
47
44
  backwards: true
48
45
  })
49
46
  ) {
@@ -60,5 +57,3 @@ function printComment(commentPath, options) {
60
57
  throw new Error(`Not a comment: ${JSON.stringify(comment)}`);
61
58
  }
62
59
  }
63
-
64
- module.exports = printComment;
@@ -1,14 +1,11 @@
1
- const {
2
- doc: {
3
- builders: { group, indent, join, line, softline, hardline }
4
- },
5
- util: { isNextLineEmptyAfterIndex }
6
- } = require('prettier');
7
- const { prettierVersionSatisfies } = require('./util');
1
+ import { doc } from 'prettier';
2
+ import { isNextLineEmpty, isPrettier2 } from './util.js';
8
3
 
9
- const printComments = (node, path, options, filter = () => true) => {
4
+ const { group, indent, join, line, softline, hardline } = doc.builders;
5
+
6
+ export const printComments = (node, path, options, filter = () => true) => {
10
7
  if (!node.comments) return '';
11
- const doc = join(
8
+ const document = join(
12
9
  line,
13
10
  path
14
11
  .map((commentPath) => {
@@ -29,13 +26,13 @@ const printComments = (node, path, options, filter = () => true) => {
29
26
  // since it depends on the version of Prettier being used.
30
27
  // Mocking the behaviour will introduce a lot of maintenance in the tests.
31
28
  /* c8 ignore start */
32
- return prettierVersionSatisfies('^2.3.0')
33
- ? doc.parts // Prettier V2
34
- : doc; // Prettier V3
29
+ return isPrettier2()
30
+ ? document.parts // Prettier V2
31
+ : document; // Prettier V3
35
32
  /* c8 ignore stop */
36
33
  };
37
34
 
38
- function printPreservingEmptyLines(path, key, options, print) {
35
+ export function printPreservingEmptyLines(path, key, options, print) {
39
36
  const parts = [];
40
37
  path.each((childPath, index) => {
41
38
  const node = childPath.getValue();
@@ -63,10 +60,7 @@ function printPreservingEmptyLines(path, key, options, print) {
63
60
  parts.push(print(childPath));
64
61
 
65
62
  if (
66
- isNextLineEmptyAfterIndex(
67
- options.originalText,
68
- options.locEnd(node) + 1
69
- ) ||
63
+ isNextLineEmpty(options.originalText, options.locEnd(node) + 1) ||
70
64
  nodeType === 'FunctionDefinition'
71
65
  ) {
72
66
  parts.push(hardline);
@@ -82,7 +76,7 @@ function printPreservingEmptyLines(path, key, options, print) {
82
76
 
83
77
  // This function will add an indentation to the `item` and separate it from the
84
78
  // rest of the `doc` in most cases by a `softline`.
85
- const printSeparatedItem = (
79
+ export const printSeparatedItem = (
86
80
  item,
87
81
  {
88
82
  firstSeparator = softline,
@@ -90,15 +84,15 @@ const printSeparatedItem = (
90
84
  grouped = true
91
85
  } = {}
92
86
  ) => {
93
- const doc = [indent([firstSeparator, item]), lastSeparator];
94
- return grouped ? group(doc) : doc;
87
+ const document = [indent([firstSeparator, item]), lastSeparator];
88
+ return grouped ? group(document) : document;
95
89
  };
96
90
 
97
91
  // This function will add an indentation to the `list` and separate it from the
98
92
  // rest of the `doc` in most cases by a `softline`.
99
93
  // the list itself will be printed with a separator that in most cases is a
100
94
  // comma (,) and a `line`
101
- const printSeparatedList = (
95
+ export const printSeparatedList = (
102
96
  list,
103
97
  { firstSeparator, separator = [',', line], lastSeparator, grouped } = {}
104
98
  ) =>
@@ -107,10 +101,3 @@ const printSeparatedList = (
107
101
  lastSeparator,
108
102
  grouped
109
103
  });
110
-
111
- module.exports = {
112
- printComments,
113
- printPreservingEmptyLines,
114
- printSeparatedList,
115
- printSeparatedItem
116
- };