prettier-plugin-solidity 1.1.3 → 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.
- package/README.md +48 -9
- package/dist/standalone.cjs +3 -0
- package/dist/standalone.cjs.map +1 -0
- package/package.json +42 -33
- package/src/binary-operator-printers/arithmetic.js +12 -14
- package/src/binary-operator-printers/assignment.js +4 -6
- package/src/binary-operator-printers/bit.js +2 -2
- package/src/binary-operator-printers/comparison.js +11 -13
- package/src/binary-operator-printers/exponentiation.js +4 -6
- package/src/binary-operator-printers/index.js +7 -13
- package/src/binary-operator-printers/logical.js +12 -14
- package/src/binary-operator-printers/shift.js +2 -2
- package/src/clean.js +1 -1
- package/src/comments/handler.js +7 -15
- package/src/comments/handlers/handleContractDefinitionComments.js +9 -11
- package/src/comments/handlers/handleModifierInvocationComments.js +9 -11
- package/src/comments/handlers/index.js +5 -3
- package/src/comments/ignore.js +1 -1
- package/src/comments/index.js +2 -4
- package/src/comments/printer.js +5 -10
- package/src/common/printer-helpers.js +15 -28
- package/src/common/util.js +30 -20
- package/src/index.js +14 -12
- package/src/loc.js +1 -1
- package/src/nodes/ArrayTypeName.js +1 -3
- package/src/nodes/AssemblyAssignment.js +4 -8
- package/src/nodes/AssemblyBlock.js +6 -11
- package/src/nodes/AssemblyCall.js +2 -4
- package/src/nodes/AssemblyCase.js +1 -3
- package/src/nodes/AssemblyFor.js +4 -8
- package/src/nodes/AssemblyFunctionDefinition.js +6 -11
- package/src/nodes/AssemblyIf.js +1 -3
- package/src/nodes/AssemblyLocalDefinition.js +4 -9
- package/src/nodes/AssemblyMemberAccess.js +1 -3
- package/src/nodes/AssemblyStackAssignment.js +1 -3
- package/src/nodes/AssemblySwitch.js +4 -8
- package/src/nodes/BinaryOperation.js +2 -5
- package/src/nodes/Block.js +6 -11
- package/src/nodes/BooleanLiteral.js +1 -3
- package/src/nodes/Break.js +1 -3
- package/src/nodes/BreakStatement.js +1 -3
- package/src/nodes/CatchClause.js +2 -4
- package/src/nodes/Conditional.js +4 -8
- package/src/nodes/Continue.js +1 -3
- package/src/nodes/ContinueStatement.js +1 -3
- package/src/nodes/ContractDefinition.js +11 -17
- package/src/nodes/CustomErrorDefinition.js +2 -4
- package/src/nodes/DecimalNumber.js +1 -3
- package/src/nodes/DoWhileStatement.js +4 -9
- package/src/nodes/ElementaryTypeName.js +1 -3
- package/src/nodes/EmitStatement.js +1 -3
- package/src/nodes/EnumDefinition.js +4 -9
- package/src/nodes/EnumValue.js +1 -3
- package/src/nodes/EventDefinition.js +2 -4
- package/src/nodes/ExpressionStatement.js +4 -9
- package/src/nodes/FileLevelConstant.js +1 -3
- package/src/nodes/ForStatement.js +4 -9
- package/src/nodes/FunctionCall.js +4 -9
- package/src/nodes/FunctionDefinition.js +11 -18
- package/src/nodes/FunctionTypeName.js +4 -9
- package/src/nodes/HexLiteral.js +4 -9
- package/src/nodes/HexNumber.js +1 -3
- package/src/nodes/Identifier.js +1 -3
- package/src/nodes/IfStatement.js +6 -11
- package/src/nodes/ImportDirective.js +12 -17
- package/src/nodes/IndexAccess.js +4 -8
- package/src/nodes/IndexRangeAccess.js +1 -3
- package/src/nodes/InheritanceSpecifier.js +2 -4
- package/src/nodes/InlineAssemblyStatement.js +3 -4
- package/src/nodes/LabelDefinition.js +4 -8
- package/src/nodes/Mapping.js +17 -18
- package/src/nodes/MemberAccess.js +6 -10
- package/src/nodes/ModifierDefinition.js +4 -9
- package/src/nodes/ModifierInvocation.js +3 -5
- package/src/nodes/NameValueExpression.js +1 -3
- package/src/nodes/NameValueList.js +4 -9
- package/src/nodes/NewExpression.js +1 -3
- package/src/nodes/NumberLiteral.js +1 -3
- package/src/nodes/PragmaDirective.js +1 -3
- package/src/nodes/ReturnStatement.js +4 -8
- package/src/nodes/RevertStatement.js +1 -3
- package/src/nodes/SourceUnit.js +4 -9
- package/src/nodes/StateVariableDeclaration.js +4 -8
- package/src/nodes/StringLiteral.js +5 -9
- package/src/nodes/StructDefinition.js +13 -22
- package/src/nodes/ThrowStatement.js +1 -3
- package/src/nodes/TryStatement.js +6 -11
- package/src/nodes/TupleExpression.js +4 -9
- package/src/nodes/TypeDefinition.js +1 -3
- package/src/nodes/UnaryOperation.js +1 -3
- package/src/nodes/UncheckedStatement.js +4 -8
- package/src/nodes/UserDefinedTypeName.js +1 -3
- package/src/nodes/UsingForDeclaration.js +28 -44
- package/src/nodes/VariableDeclaration.js +4 -9
- package/src/nodes/VariableDeclarationStatement.js +6 -11
- package/src/nodes/WhileStatement.js +4 -9
- package/src/nodes/index.js +72 -78
- package/src/options.js +1 -1
- package/src/parser.js +5 -12
- package/src/prettier-comments/language-js/comments.js +13 -23
- package/src/printer.js +6 -6
- package/dist/standalone.js +0 -3
- package/dist/standalone.js.map +0 -1
- package/src/prettier-comments/index.js +0 -3
- /package/dist/{standalone.js.LICENSE.txt → standalone.cjs.LICENSE.txt} +0 -0
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { hardline }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printComments } from '../common/printer-helpers.js';
|
|
6
3
|
|
|
7
|
-
const {
|
|
4
|
+
const { hardline } = doc.builders;
|
|
8
5
|
|
|
9
|
-
const ExpressionStatement = {
|
|
6
|
+
export const ExpressionStatement = {
|
|
10
7
|
print: ({ node, options, path, print }) => {
|
|
11
8
|
const parts = [];
|
|
12
9
|
|
|
@@ -28,5 +25,3 @@ const ExpressionStatement = {
|
|
|
28
25
|
return parts;
|
|
29
26
|
}
|
|
30
27
|
};
|
|
31
|
-
|
|
32
|
-
module.exports = ExpressionStatement;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { group, indent, line }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
6
3
|
|
|
7
|
-
const {
|
|
4
|
+
const { group, indent, line } = doc.builders;
|
|
8
5
|
|
|
9
6
|
const initExpression = (node, path, print) =>
|
|
10
7
|
node.initExpression ? path.call(print, 'initExpression') : '';
|
|
@@ -20,7 +17,7 @@ const printBody = (node, path, print) =>
|
|
|
20
17
|
? [' ', path.call(print, 'body')]
|
|
21
18
|
: group(indent([line, path.call(print, 'body')]));
|
|
22
19
|
|
|
23
|
-
const ForStatement = {
|
|
20
|
+
export const ForStatement = {
|
|
24
21
|
print: ({ node, path, print }) => [
|
|
25
22
|
'for (',
|
|
26
23
|
printSeparatedList(
|
|
@@ -42,5 +39,3 @@ const ForStatement = {
|
|
|
42
39
|
printBody(node, path, print)
|
|
43
40
|
]
|
|
44
41
|
};
|
|
45
|
-
|
|
46
|
-
module.exports = ForStatement;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { group, indentIfBreak, label, line, softline }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
6
3
|
|
|
7
|
-
const {
|
|
4
|
+
const { group, indentIfBreak, label, line, softline } = doc.builders;
|
|
8
5
|
|
|
9
6
|
const printObject = (path, print, options) => {
|
|
10
7
|
const identifiers = path.map(print, 'identifiers');
|
|
@@ -28,7 +25,7 @@ const printArguments = (path, print) =>
|
|
|
28
25
|
});
|
|
29
26
|
|
|
30
27
|
let groupIndex = 0;
|
|
31
|
-
const FunctionCall = {
|
|
28
|
+
export const FunctionCall = {
|
|
32
29
|
print: ({ node, path, print, options }) => {
|
|
33
30
|
let expressionDoc = path.call(print, 'expression');
|
|
34
31
|
let argumentsDoc = ')';
|
|
@@ -61,5 +58,3 @@ const FunctionCall = {
|
|
|
61
58
|
return [expressionDoc, '(', argumentsDoc];
|
|
62
59
|
}
|
|
63
60
|
};
|
|
64
|
-
|
|
65
|
-
module.exports = FunctionCall;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
},
|
|
5
|
-
util: { getNextNonSpaceNonCommentCharacterIndex }
|
|
6
|
-
} = require('prettier');
|
|
7
|
-
|
|
8
|
-
const {
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { getNextNonSpaceNonCommentCharacter } from '../common/util.js';
|
|
3
|
+
import {
|
|
9
4
|
printComments,
|
|
10
5
|
printSeparatedItem,
|
|
11
6
|
printSeparatedList
|
|
12
|
-
}
|
|
7
|
+
} from '../common/printer-helpers.js';
|
|
8
|
+
|
|
9
|
+
const { dedent, group, indent, join, line } = doc.builders;
|
|
13
10
|
|
|
14
11
|
const functionName = (node, options) => {
|
|
15
12
|
if (node.isConstructor && !node.name) return 'constructor';
|
|
@@ -41,12 +38,10 @@ const parameters = (parametersType, node, path, print, options) => {
|
|
|
41
38
|
path,
|
|
42
39
|
options,
|
|
43
40
|
(comment) =>
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
options.locEnd
|
|
49
|
-
)
|
|
41
|
+
getNextNonSpaceNonCommentCharacter(
|
|
42
|
+
options.originalText,
|
|
43
|
+
comment,
|
|
44
|
+
options.locEnd
|
|
50
45
|
) === ')'
|
|
51
46
|
);
|
|
52
47
|
return parameterComments.length > 0
|
|
@@ -96,7 +91,7 @@ const signatureEnd = (node) => (node.body ? dedent(line) : ';');
|
|
|
96
91
|
|
|
97
92
|
const body = (node, path, print) => (node.body ? path.call(print, 'body') : '');
|
|
98
93
|
|
|
99
|
-
const FunctionDefinition = {
|
|
94
|
+
export const FunctionDefinition = {
|
|
100
95
|
print: ({ node, path, print, options }) => [
|
|
101
96
|
group([
|
|
102
97
|
functionName(node, options),
|
|
@@ -120,5 +115,3 @@ const FunctionDefinition = {
|
|
|
120
115
|
body(node, path, print)
|
|
121
116
|
]
|
|
122
117
|
};
|
|
123
|
-
|
|
124
|
-
module.exports = FunctionDefinition;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { group, indent, line }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
6
3
|
|
|
7
|
-
const {
|
|
4
|
+
const { group, indent, line } = doc.builders;
|
|
8
5
|
|
|
9
6
|
const returnTypes = (node, path, print) =>
|
|
10
7
|
node.returnTypes.length > 0
|
|
@@ -26,7 +23,7 @@ const stateMutability = (node) =>
|
|
|
26
23
|
? [line, node.stateMutability]
|
|
27
24
|
: '';
|
|
28
25
|
|
|
29
|
-
const FunctionTypeName = {
|
|
26
|
+
export const FunctionTypeName = {
|
|
30
27
|
print: ({ node, path, print }) => [
|
|
31
28
|
'function(',
|
|
32
29
|
printSeparatedList(path.map(print, 'parameterTypes')),
|
|
@@ -40,5 +37,3 @@ const FunctionTypeName = {
|
|
|
40
37
|
)
|
|
41
38
|
]
|
|
42
39
|
};
|
|
43
|
-
|
|
44
|
-
module.exports = FunctionTypeName;
|
package/src/nodes/HexLiteral.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { join, line }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printString } from '../common/util.js';
|
|
6
3
|
|
|
7
|
-
const {
|
|
4
|
+
const { join, line } = doc.builders;
|
|
8
5
|
|
|
9
|
-
const HexLiteral = {
|
|
6
|
+
export const HexLiteral = {
|
|
10
7
|
print: ({ node, options }) => {
|
|
11
8
|
const list = node.parts.map((part) => `hex${printString(part, options)}`);
|
|
12
9
|
return join(line, list);
|
|
13
10
|
}
|
|
14
11
|
};
|
|
15
|
-
|
|
16
|
-
module.exports = HexLiteral;
|
package/src/nodes/HexNumber.js
CHANGED
package/src/nodes/Identifier.js
CHANGED
package/src/nodes/IfStatement.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { group, hardline, indent, line }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
6
|
-
|
|
7
|
-
const {
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import {
|
|
8
3
|
printComments,
|
|
9
4
|
printSeparatedItem
|
|
10
|
-
}
|
|
5
|
+
} from '../common/printer-helpers.js';
|
|
6
|
+
|
|
7
|
+
const { group, hardline, indent, line } = doc.builders;
|
|
11
8
|
|
|
12
9
|
const printTrueBody = (node, path, print) => {
|
|
13
10
|
if (node.trueBody.type === 'Block') {
|
|
@@ -38,7 +35,7 @@ const printElse = (node, path, print, commentsBetweenIfAndElse) => {
|
|
|
38
35
|
return '';
|
|
39
36
|
};
|
|
40
37
|
|
|
41
|
-
const IfStatement = {
|
|
38
|
+
export const IfStatement = {
|
|
42
39
|
print: ({ node, options, path, print }) => {
|
|
43
40
|
const comments = node.comments || [];
|
|
44
41
|
const commentsBetweenIfAndElse = comments.filter(
|
|
@@ -58,5 +55,3 @@ const IfStatement = {
|
|
|
58
55
|
return parts;
|
|
59
56
|
}
|
|
60
57
|
};
|
|
61
|
-
|
|
62
|
-
module.exports = IfStatement;
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
const coerce = require('semver/functions/coerce');
|
|
7
|
-
const satisfies = require('semver/functions/satisfies');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import coerce from 'semver/functions/coerce.js';
|
|
3
|
+
import satisfies from 'semver/functions/satisfies.js';
|
|
4
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
5
|
+
import { printString } from '../common/util.js';
|
|
8
6
|
|
|
9
|
-
const {
|
|
10
|
-
const { printString } = require('../common/util');
|
|
7
|
+
const { group, line, softline } = doc.builders;
|
|
11
8
|
|
|
12
|
-
const ImportDirective = {
|
|
9
|
+
export const ImportDirective = {
|
|
13
10
|
print: ({ node, options }) => {
|
|
14
11
|
const importPath = printString(node.path, options);
|
|
15
|
-
let
|
|
12
|
+
let document;
|
|
16
13
|
|
|
17
14
|
if (node.unitAlias) {
|
|
18
15
|
// import "./Foo.sol" as Foo;
|
|
19
|
-
|
|
16
|
+
document = [importPath, ' as ', node.unitAlias];
|
|
20
17
|
} else if (node.symbolAliases) {
|
|
21
18
|
// import { Foo, Bar as Qux } from "./Foo.sol";
|
|
22
19
|
const compiler = coerce(options.compiler);
|
|
@@ -38,7 +35,7 @@ const ImportDirective = {
|
|
|
38
35
|
separator = ', ';
|
|
39
36
|
}
|
|
40
37
|
|
|
41
|
-
|
|
38
|
+
document = [
|
|
42
39
|
'{',
|
|
43
40
|
printSeparatedList(symbolAliases, { firstSeparator, separator }),
|
|
44
41
|
'} from ',
|
|
@@ -46,10 +43,8 @@ const ImportDirective = {
|
|
|
46
43
|
];
|
|
47
44
|
} else {
|
|
48
45
|
// import "./Foo.sol";
|
|
49
|
-
|
|
46
|
+
document = importPath;
|
|
50
47
|
}
|
|
51
|
-
return group(['import ',
|
|
48
|
+
return group(['import ', document, ';']);
|
|
52
49
|
}
|
|
53
50
|
};
|
|
54
|
-
|
|
55
|
-
module.exports = ImportDirective;
|
package/src/nodes/IndexAccess.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
|
|
3
|
+
const { group, indent, indentIfBreak, label, softline } = doc.builders;
|
|
6
4
|
|
|
7
5
|
let groupIndex = 0;
|
|
8
|
-
const IndexAccess = {
|
|
6
|
+
export const IndexAccess = {
|
|
9
7
|
print: ({ path, print }) => {
|
|
10
8
|
let baseDoc = path.call(print, 'base');
|
|
11
9
|
let indexDoc = group([
|
|
@@ -34,5 +32,3 @@ const IndexAccess = {
|
|
|
34
32
|
return [baseDoc, '[', indexDoc];
|
|
35
33
|
}
|
|
36
34
|
};
|
|
37
|
-
|
|
38
|
-
module.exports = IndexAccess;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
2
2
|
|
|
3
3
|
const printArguments = (node, path, print) =>
|
|
4
4
|
node.arguments && node.arguments.length
|
|
5
5
|
? ['(', printSeparatedList(path.map(print, 'arguments')), ')']
|
|
6
6
|
: '';
|
|
7
7
|
|
|
8
|
-
const InheritanceSpecifier = {
|
|
8
|
+
export const InheritanceSpecifier = {
|
|
9
9
|
print: ({ node, path, print }) => [
|
|
10
10
|
path.call(print, 'baseName'),
|
|
11
11
|
printArguments(node, path, print)
|
|
12
12
|
]
|
|
13
13
|
};
|
|
14
|
-
|
|
15
|
-
module.exports = InheritanceSpecifier;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// @TODO: add support for assembly language specifier
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { printString } from '../common/util.js';
|
|
3
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
4
4
|
|
|
5
|
-
const InlineAssemblyStatement = {
|
|
5
|
+
export const InlineAssemblyStatement = {
|
|
6
6
|
print: ({ node, path, print, options }) => [
|
|
7
7
|
'assembly ',
|
|
8
8
|
node.language ? `${printString(node.language, options)} ` : '',
|
|
@@ -18,4 +18,3 @@ const InlineAssemblyStatement = {
|
|
|
18
18
|
path.call(print, 'body')
|
|
19
19
|
]
|
|
20
20
|
};
|
|
21
|
-
module.exports = InlineAssemblyStatement;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
doc: {
|
|
3
|
-
builders: { dedent, line }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
6
2
|
|
|
7
|
-
const
|
|
3
|
+
const { dedent, line } = doc.builders;
|
|
4
|
+
|
|
5
|
+
export const LabelDefinition = {
|
|
8
6
|
print: ({ node }) => [dedent(line), node.name, ':']
|
|
9
7
|
};
|
|
10
|
-
|
|
11
|
-
module.exports = LabelDefinition;
|
package/src/nodes/Mapping.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
keyType,
|
|
10
|
-
keyName ? ` ${keyName}` : '',
|
|
11
|
-
' => ',
|
|
12
|
-
valueType,
|
|
13
|
-
valueName ? ` ${valueName}` : '',
|
|
14
|
-
')'
|
|
15
|
-
];
|
|
16
|
-
}
|
|
17
|
-
};
|
|
1
|
+
const namedParameter = (prefix, node, path, print) =>
|
|
2
|
+
node[`${prefix}Name`]
|
|
3
|
+
? [
|
|
4
|
+
path.call(print, `${prefix}Type`),
|
|
5
|
+
' ',
|
|
6
|
+
path.call(print, `${prefix}Name`)
|
|
7
|
+
]
|
|
8
|
+
: path.call(print, `${prefix}Type`);
|
|
18
9
|
|
|
19
|
-
|
|
10
|
+
export const Mapping = {
|
|
11
|
+
print: ({ node, path, print }) => [
|
|
12
|
+
'mapping(',
|
|
13
|
+
namedParameter('key', node, path, print),
|
|
14
|
+
' => ',
|
|
15
|
+
namedParameter('value', node, path, print),
|
|
16
|
+
')'
|
|
17
|
+
]
|
|
18
|
+
};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
|
|
3
|
+
const { group, indent, label, softline } = doc.builders;
|
|
6
4
|
|
|
7
5
|
const isEndOfChain = (node, path) => {
|
|
8
6
|
let i = 0;
|
|
@@ -107,21 +105,19 @@ const processChain = (chain) => {
|
|
|
107
105
|
return label('MemberAccessChain', group([firstExpression, restOfChain]));
|
|
108
106
|
};
|
|
109
107
|
|
|
110
|
-
const MemberAccess = {
|
|
108
|
+
export const MemberAccess = {
|
|
111
109
|
print: ({ node, path, print }) => {
|
|
112
110
|
let expressionDoc = path.call(print, 'expression');
|
|
113
111
|
if (Array.isArray(expressionDoc)) {
|
|
114
112
|
expressionDoc = expressionDoc.flat();
|
|
115
113
|
}
|
|
116
114
|
|
|
117
|
-
const
|
|
115
|
+
const document = [
|
|
118
116
|
expressionDoc,
|
|
119
117
|
label('separator', [softline, '.']),
|
|
120
118
|
node.memberName
|
|
121
119
|
].flat();
|
|
122
120
|
|
|
123
|
-
return isEndOfChain(node, path) ? processChain(
|
|
121
|
+
return isEndOfChain(node, path) ? processChain(document) : document;
|
|
124
122
|
}
|
|
125
123
|
};
|
|
126
|
-
|
|
127
|
-
module.exports = MemberAccess;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { group, hardline, indent, line }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
6
3
|
|
|
7
|
-
const {
|
|
4
|
+
const { group, hardline, indent, line } = doc.builders;
|
|
8
5
|
|
|
9
6
|
const modifierParameters = (node, path, print) => {
|
|
10
7
|
if (node.parameters && node.parameters.length > 0) {
|
|
@@ -45,7 +42,7 @@ const body = (node, path, print) => {
|
|
|
45
42
|
return [' ', path.call(print, 'body')];
|
|
46
43
|
};
|
|
47
44
|
|
|
48
|
-
const ModifierDefinition = {
|
|
45
|
+
export const ModifierDefinition = {
|
|
49
46
|
print: ({ node, path, print }) => [
|
|
50
47
|
'modifier ',
|
|
51
48
|
node.name,
|
|
@@ -54,5 +51,3 @@ const ModifierDefinition = {
|
|
|
54
51
|
body(node, path, print)
|
|
55
52
|
]
|
|
56
53
|
};
|
|
57
|
-
|
|
58
|
-
module.exports = ModifierDefinition;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
2
|
printComments,
|
|
3
3
|
printSeparatedList
|
|
4
|
-
}
|
|
4
|
+
} from '../common/printer-helpers.js';
|
|
5
5
|
|
|
6
6
|
const modifierArguments = (node, path, print, options) => {
|
|
7
7
|
if (node.arguments) {
|
|
@@ -27,11 +27,9 @@ const modifierArguments = (node, path, print, options) => {
|
|
|
27
27
|
return '';
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
const ModifierInvocation = {
|
|
30
|
+
export const ModifierInvocation = {
|
|
31
31
|
print: ({ node, path, print, options }) => [
|
|
32
32
|
node.name,
|
|
33
33
|
modifierArguments(node, path, print, options)
|
|
34
34
|
]
|
|
35
35
|
};
|
|
36
|
-
|
|
37
|
-
module.exports = ModifierInvocation;
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { line, softline }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
6
3
|
|
|
7
|
-
const {
|
|
4
|
+
const { line, softline } = doc.builders;
|
|
8
5
|
|
|
9
|
-
const NameValueList = {
|
|
6
|
+
export const NameValueList = {
|
|
10
7
|
print: ({ node, path, print, options }) =>
|
|
11
8
|
printSeparatedList(
|
|
12
9
|
path
|
|
@@ -17,5 +14,3 @@ const NameValueList = {
|
|
|
17
14
|
}
|
|
18
15
|
)
|
|
19
16
|
};
|
|
20
|
-
|
|
21
|
-
module.exports = NameValueList;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
|
|
3
|
+
const { group, indent, line } = doc.builders;
|
|
6
4
|
|
|
7
5
|
const expression = (node, path, print) => {
|
|
8
6
|
if (node.expression) {
|
|
@@ -13,12 +11,10 @@ const expression = (node, path, print) => {
|
|
|
13
11
|
return '';
|
|
14
12
|
};
|
|
15
13
|
|
|
16
|
-
const ReturnStatement = {
|
|
14
|
+
export const ReturnStatement = {
|
|
17
15
|
print: ({ node, path, print }) => [
|
|
18
16
|
'return',
|
|
19
17
|
expression(node, path, print),
|
|
20
18
|
';'
|
|
21
19
|
]
|
|
22
20
|
};
|
|
23
|
-
|
|
24
|
-
module.exports = ReturnStatement;
|
package/src/nodes/SourceUnit.js
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { line }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printPreservingEmptyLines } from '../common/printer-helpers.js';
|
|
6
3
|
|
|
7
|
-
const {
|
|
4
|
+
const { line } = doc.builders;
|
|
8
5
|
|
|
9
|
-
const SourceUnit = {
|
|
6
|
+
export const SourceUnit = {
|
|
10
7
|
print: ({ options, path, print }) => [
|
|
11
8
|
printPreservingEmptyLines(path, 'children', options, print),
|
|
12
9
|
options.parentParser ? '' : line
|
|
13
10
|
]
|
|
14
11
|
};
|
|
15
|
-
|
|
16
|
-
module.exports = SourceUnit;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
|
|
3
|
+
const { group, indent, line } = doc.builders;
|
|
6
4
|
|
|
7
5
|
const initialValue = (node, path, print) => {
|
|
8
6
|
if (!node.initialValue) {
|
|
@@ -16,12 +14,10 @@ const initialValue = (node, path, print) => {
|
|
|
16
14
|
return group([' =', indent([line, path.call(print, 'initialValue')])]);
|
|
17
15
|
};
|
|
18
16
|
|
|
19
|
-
const StateVariableDeclaration = {
|
|
17
|
+
export const StateVariableDeclaration = {
|
|
20
18
|
print: ({ node, path, print }) => [
|
|
21
19
|
...path.map(print, 'variables'),
|
|
22
20
|
initialValue(node, path, print),
|
|
23
21
|
';'
|
|
24
22
|
]
|
|
25
23
|
};
|
|
26
|
-
|
|
27
|
-
module.exports = StateVariableDeclaration;
|