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,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} = require('prettier');
|
|
6
|
-
const { printString } = require('../common/util');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printString } from '../common/util.js';
|
|
3
|
+
|
|
4
|
+
const { join, hardline } = doc.builders;
|
|
7
5
|
|
|
8
|
-
const StringLiteral = {
|
|
6
|
+
export const StringLiteral = {
|
|
9
7
|
print: ({ node, options }) => {
|
|
10
8
|
const list = node.parts.map(
|
|
11
9
|
(part, index) =>
|
|
@@ -17,5 +15,3 @@ const StringLiteral = {
|
|
|
17
15
|
return join(hardline, list);
|
|
18
16
|
}
|
|
19
17
|
};
|
|
20
|
-
|
|
21
|
-
module.exports = StringLiteral;
|
|
@@ -1,29 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { hardline }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
6
3
|
|
|
7
|
-
const {
|
|
4
|
+
const { hardline } = doc.builders;
|
|
8
5
|
|
|
9
|
-
const StructDefinition = {
|
|
10
|
-
print: ({ node, path, print }) =>
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
export const StructDefinition = {
|
|
7
|
+
print: ({ node, path, print }) => [
|
|
8
|
+
'struct ',
|
|
9
|
+
node.name,
|
|
10
|
+
' {',
|
|
11
|
+
node.members.length > 0
|
|
12
|
+
? printSeparatedList(path.map(print, 'members'), {
|
|
16
13
|
firstSeparator: hardline,
|
|
17
14
|
separator: [';', hardline],
|
|
18
15
|
lastSeparator: [';', hardline]
|
|
19
16
|
})
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
parts.push('}');
|
|
24
|
-
|
|
25
|
-
return parts;
|
|
26
|
-
}
|
|
17
|
+
: '',
|
|
18
|
+
'}'
|
|
19
|
+
]
|
|
27
20
|
};
|
|
28
|
-
|
|
29
|
-
module.exports = StructDefinition;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { join, line }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
6
|
-
|
|
7
|
-
const {
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import {
|
|
8
3
|
printSeparatedItem,
|
|
9
4
|
printSeparatedList
|
|
10
|
-
}
|
|
5
|
+
} from '../common/printer-helpers.js';
|
|
6
|
+
|
|
7
|
+
const { join, line } = doc.builders;
|
|
11
8
|
|
|
12
9
|
const returnParameters = (node, path, print) =>
|
|
13
10
|
node.returnParameters
|
|
@@ -18,7 +15,7 @@ const returnParameters = (node, path, print) =>
|
|
|
18
15
|
]
|
|
19
16
|
: '';
|
|
20
17
|
|
|
21
|
-
const TryStatement = {
|
|
18
|
+
export const TryStatement = {
|
|
22
19
|
print: ({ node, path, print }) => {
|
|
23
20
|
let parts = [
|
|
24
21
|
'try',
|
|
@@ -41,5 +38,3 @@ const TryStatement = {
|
|
|
41
38
|
return parts;
|
|
42
39
|
}
|
|
43
40
|
};
|
|
44
|
-
|
|
45
|
-
module.exports = TryStatement;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { group }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
6
3
|
|
|
7
|
-
const {
|
|
4
|
+
const { group } = doc.builders;
|
|
8
5
|
|
|
9
6
|
const contents = (node, path, print) =>
|
|
10
7
|
node.components &&
|
|
@@ -13,7 +10,7 @@ const contents = (node, path, print) =>
|
|
|
13
10
|
? path.map(print, 'components')
|
|
14
11
|
: [printSeparatedList(path.map(print, 'components'))];
|
|
15
12
|
|
|
16
|
-
const TupleExpression = {
|
|
13
|
+
export const TupleExpression = {
|
|
17
14
|
print: ({ node, path, print }) =>
|
|
18
15
|
group([
|
|
19
16
|
node.isArray ? '[' : '(',
|
|
@@ -21,5 +18,3 @@ const TupleExpression = {
|
|
|
21
18
|
node.isArray ? ']' : ')'
|
|
22
19
|
])
|
|
23
20
|
};
|
|
24
|
-
|
|
25
|
-
module.exports = TupleExpression;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const UnaryOperation = {
|
|
1
|
+
export const UnaryOperation = {
|
|
2
2
|
print: ({ node, path, print }) =>
|
|
3
3
|
node.isPrefix
|
|
4
4
|
? [
|
|
@@ -8,5 +8,3 @@ const UnaryOperation = {
|
|
|
8
8
|
]
|
|
9
9
|
: [path.call(print, 'subExpression'), node.operator]
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
module.exports = UnaryOperation;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
doc: {
|
|
3
|
-
builders: { group }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
6
2
|
|
|
7
|
-
const
|
|
3
|
+
const { group } = doc.builders;
|
|
4
|
+
|
|
5
|
+
export const UncheckedStatement = {
|
|
8
6
|
print: ({ path, print }) => group(['unchecked ', path.call(print, 'block')])
|
|
9
7
|
};
|
|
10
|
-
|
|
11
|
-
module.exports = UncheckedStatement;
|
|
@@ -1,45 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
firstSeparator: options.bracketSpacing ? line : softline
|
|
30
|
-
})
|
|
31
|
-
);
|
|
32
|
-
parts.push('}');
|
|
33
|
-
} else {
|
|
34
|
-
parts.push(node.libraryName);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
parts.push(' for ');
|
|
38
|
-
parts.push(node.typeName ? path.call(print, 'typeName') : '*');
|
|
39
|
-
parts.push(node.isGlobal ? ' global;' : ';');
|
|
40
|
-
|
|
41
|
-
return parts;
|
|
42
|
-
}
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printSeparatedList } from '../common/printer-helpers.js';
|
|
3
|
+
|
|
4
|
+
const { line, softline } = doc.builders;
|
|
5
|
+
|
|
6
|
+
export const UsingForDeclaration = {
|
|
7
|
+
print: ({ node, path, print, options }) => [
|
|
8
|
+
'using ',
|
|
9
|
+
node.functions && node.functions.length
|
|
10
|
+
? [
|
|
11
|
+
'{',
|
|
12
|
+
printSeparatedList(
|
|
13
|
+
node.functions.map((functionName, i) =>
|
|
14
|
+
node.operators[i]
|
|
15
|
+
? [functionName, ' as ', node.operators[i]]
|
|
16
|
+
: functionName
|
|
17
|
+
),
|
|
18
|
+
{
|
|
19
|
+
firstSeparator: options.bracketSpacing ? line : softline
|
|
20
|
+
}
|
|
21
|
+
),
|
|
22
|
+
'}'
|
|
23
|
+
]
|
|
24
|
+
: node.libraryName,
|
|
25
|
+
' for ',
|
|
26
|
+
node.typeName ? path.call(print, 'typeName') : '*',
|
|
27
|
+
node.isGlobal ? ' global;' : ';'
|
|
28
|
+
]
|
|
43
29
|
};
|
|
44
|
-
|
|
45
|
-
module.exports = UsingForDeclaration;
|
|
@@ -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 indexed = (node) => (node.isIndexed ? ' indexed' : '');
|
|
10
7
|
|
|
@@ -35,7 +32,7 @@ const override = (node, path, print) => {
|
|
|
35
32
|
|
|
36
33
|
const name = (node) => (node.name ? [' ', node.name] : '');
|
|
37
34
|
|
|
38
|
-
const VariableDeclaration = {
|
|
35
|
+
export const VariableDeclaration = {
|
|
39
36
|
print: ({ node, path, print }) =>
|
|
40
37
|
node.typeName
|
|
41
38
|
? group([
|
|
@@ -52,5 +49,3 @@ const VariableDeclaration = {
|
|
|
52
49
|
])
|
|
53
50
|
: node.name
|
|
54
51
|
};
|
|
55
|
-
|
|
56
|
-
module.exports = VariableDeclaration;
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { group, indentIfBreak }
|
|
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 } = doc.builders;
|
|
8
5
|
|
|
9
|
-
const embraceVariables = (
|
|
10
|
-
embrace ? ['(', printSeparatedList(
|
|
6
|
+
const embraceVariables = (document, embrace) =>
|
|
7
|
+
embrace ? ['(', printSeparatedList(document), ')'] : document;
|
|
11
8
|
|
|
12
9
|
const initialValue = (node, path, print) =>
|
|
13
10
|
node.initialValue ? [' = ', path.call(print, 'initialValue')] : '';
|
|
14
11
|
|
|
15
12
|
let groupIndex = 0;
|
|
16
|
-
const VariableDeclarationStatement = {
|
|
13
|
+
export const VariableDeclarationStatement = {
|
|
17
14
|
print: ({ node, path, print }) => {
|
|
18
15
|
const startsWithVar =
|
|
19
16
|
node.variables.filter((x) => x && x.typeName).length === 0;
|
|
@@ -40,5 +37,3 @@ const VariableDeclarationStatement = {
|
|
|
40
37
|
]);
|
|
41
38
|
}
|
|
42
39
|
};
|
|
43
|
-
|
|
44
|
-
module.exports = VariableDeclarationStatement;
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
builders: { group, indent, line }
|
|
4
|
-
}
|
|
5
|
-
} = require('prettier');
|
|
1
|
+
import { doc } from 'prettier';
|
|
2
|
+
import { printSeparatedItem } from '../common/printer-helpers.js';
|
|
6
3
|
|
|
7
|
-
const {
|
|
4
|
+
const { group, indent, line } = doc.builders;
|
|
8
5
|
|
|
9
6
|
const printBody = (node, path, print) =>
|
|
10
7
|
node.body.type === 'Block'
|
|
11
8
|
? [' ', path.call(print, 'body')]
|
|
12
9
|
: group(indent([line, path.call(print, 'body')]));
|
|
13
10
|
|
|
14
|
-
const WhileStatement = {
|
|
11
|
+
export const WhileStatement = {
|
|
15
12
|
print: ({ node, path, print }) => [
|
|
16
13
|
'while (',
|
|
17
14
|
printSeparatedItem(path.call(print, 'condition')),
|
|
@@ -19,5 +16,3 @@ const WhileStatement = {
|
|
|
19
16
|
printBody(node, path, print)
|
|
20
17
|
]
|
|
21
18
|
};
|
|
22
|
-
|
|
23
|
-
module.exports = WhileStatement;
|
package/src/nodes/index.js
CHANGED
|
@@ -1,78 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
UserDefinedTypeName: require('./UserDefinedTypeName'),
|
|
74
|
-
UsingForDeclaration: require('./UsingForDeclaration'),
|
|
75
|
-
VariableDeclaration: require('./VariableDeclaration'),
|
|
76
|
-
VariableDeclarationStatement: require('./VariableDeclarationStatement'),
|
|
77
|
-
WhileStatement: require('./WhileStatement')
|
|
78
|
-
};
|
|
1
|
+
export * from './ArrayTypeName.js';
|
|
2
|
+
export * from './AssemblyAssignment.js';
|
|
3
|
+
export * from './AssemblyBlock.js';
|
|
4
|
+
export * from './AssemblyCall.js';
|
|
5
|
+
export * from './AssemblyCase.js';
|
|
6
|
+
export * from './AssemblyFor.js';
|
|
7
|
+
export * from './AssemblyFunctionDefinition.js';
|
|
8
|
+
export * from './AssemblyIf.js';
|
|
9
|
+
export * from './AssemblyLocalDefinition.js';
|
|
10
|
+
export * from './AssemblyMemberAccess.js';
|
|
11
|
+
export * from './AssemblyStackAssignment.js';
|
|
12
|
+
export * from './AssemblySwitch.js';
|
|
13
|
+
export * from './BinaryOperation.js';
|
|
14
|
+
export * from './Block.js';
|
|
15
|
+
export * from './BooleanLiteral.js';
|
|
16
|
+
export * from './Break.js';
|
|
17
|
+
export * from './BreakStatement.js';
|
|
18
|
+
export * from './CatchClause.js';
|
|
19
|
+
export * from './Conditional.js';
|
|
20
|
+
export * from './Continue.js';
|
|
21
|
+
export * from './ContinueStatement.js';
|
|
22
|
+
export * from './ContractDefinition.js';
|
|
23
|
+
export * from './CustomErrorDefinition.js';
|
|
24
|
+
export * from './DecimalNumber.js';
|
|
25
|
+
export * from './DoWhileStatement.js';
|
|
26
|
+
export * from './ElementaryTypeName.js';
|
|
27
|
+
export * from './EmitStatement.js';
|
|
28
|
+
export * from './EnumDefinition.js';
|
|
29
|
+
export * from './EnumValue.js';
|
|
30
|
+
export * from './EventDefinition.js';
|
|
31
|
+
export * from './ExpressionStatement.js';
|
|
32
|
+
export * from './FileLevelConstant.js';
|
|
33
|
+
export * from './ForStatement.js';
|
|
34
|
+
export * from './FunctionCall.js';
|
|
35
|
+
export * from './FunctionDefinition.js';
|
|
36
|
+
export * from './FunctionTypeName.js';
|
|
37
|
+
export * from './HexLiteral.js';
|
|
38
|
+
export * from './HexNumber.js';
|
|
39
|
+
export * from './Identifier.js';
|
|
40
|
+
export * from './IfStatement.js';
|
|
41
|
+
export * from './ImportDirective.js';
|
|
42
|
+
export * from './IndexAccess.js';
|
|
43
|
+
export * from './IndexRangeAccess.js';
|
|
44
|
+
export * from './InheritanceSpecifier.js';
|
|
45
|
+
export * from './InlineAssemblyStatement.js';
|
|
46
|
+
export * from './LabelDefinition.js';
|
|
47
|
+
export * from './Mapping.js';
|
|
48
|
+
export * from './MemberAccess.js';
|
|
49
|
+
export * from './ModifierDefinition.js';
|
|
50
|
+
export * from './ModifierInvocation.js';
|
|
51
|
+
export * from './NameValueExpression.js';
|
|
52
|
+
export * from './NameValueList.js';
|
|
53
|
+
export * from './NewExpression.js';
|
|
54
|
+
export * from './NumberLiteral.js';
|
|
55
|
+
export * from './PragmaDirective.js';
|
|
56
|
+
export * from './ReturnStatement.js';
|
|
57
|
+
export * from './RevertStatement.js';
|
|
58
|
+
export * from './SourceUnit.js';
|
|
59
|
+
export * from './StateVariableDeclaration.js';
|
|
60
|
+
export * from './StringLiteral.js';
|
|
61
|
+
export * from './StructDefinition.js';
|
|
62
|
+
export * from './ThrowStatement.js';
|
|
63
|
+
export * from './TryStatement.js';
|
|
64
|
+
export * from './TupleExpression.js';
|
|
65
|
+
export * from './TypeDefinition.js';
|
|
66
|
+
export * from './UnaryOperation.js';
|
|
67
|
+
export * from './UncheckedStatement.js';
|
|
68
|
+
export * from './UserDefinedTypeName.js';
|
|
69
|
+
export * from './UsingForDeclaration.js';
|
|
70
|
+
export * from './VariableDeclaration.js';
|
|
71
|
+
export * from './VariableDeclarationStatement.js';
|
|
72
|
+
export * from './WhileStatement.js';
|
package/src/options.js
CHANGED
package/src/parser.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import extractComments from 'solidity-comments-extractor';
|
|
2
2
|
// https://prettier.io/docs/en/plugins.html#parsers
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import parser from '@solidity-parser/parser';
|
|
4
|
+
import coerce from 'semver/functions/coerce.js';
|
|
5
|
+
import satisfies from 'semver/functions/satisfies.js';
|
|
6
6
|
|
|
7
7
|
const tryHug = (node, operators) => {
|
|
8
8
|
if (node.type === 'BinaryOperation' && operators.includes(node.operator))
|
|
@@ -61,13 +61,6 @@ function parse(text, _parsers, options = _parsers) {
|
|
|
61
61
|
? `hex'${ctx.value.slice(4, -1)}'`
|
|
62
62
|
: `hex"${ctx.value.slice(4, -1)}"`;
|
|
63
63
|
},
|
|
64
|
-
ElementaryTypeName(ctx) {
|
|
65
|
-
// if the compiler is below 0.8.0 we will recognize the type 'byte' as an
|
|
66
|
-
// alias of 'bytes1'. Otherwise we will ignore this and enforce always
|
|
67
|
-
// 'bytes1'.
|
|
68
|
-
const pre080 = compiler && satisfies(compiler, '<0.8.0');
|
|
69
|
-
if (!pre080 && ctx.name === 'byte') ctx.name = 'bytes1';
|
|
70
|
-
},
|
|
71
64
|
BinaryOperation(ctx) {
|
|
72
65
|
switch (ctx.operator) {
|
|
73
66
|
case '+':
|
|
@@ -184,4 +177,4 @@ function parse(text, _parsers, options = _parsers) {
|
|
|
184
177
|
return parsed;
|
|
185
178
|
}
|
|
186
179
|
|
|
187
|
-
|
|
180
|
+
export default parse;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { util } from "prettier";
|
|
2
|
+
import { getNextNonSpaceNonCommentCharacter } from "../../common/util.js";
|
|
2
3
|
|
|
3
4
|
const {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} = require('prettier');
|
|
13
|
-
const { getNextNonSpaceNonCommentCharacter } = require("../../common/util");
|
|
14
|
-
|
|
15
|
-
function handleOwnLineComment(comment, text, options, ast, isLastComment) {
|
|
5
|
+
addLeadingComment,
|
|
6
|
+
addTrailingComment,
|
|
7
|
+
addDanglingComment,
|
|
8
|
+
hasNewline,
|
|
9
|
+
hasNewlineInRange
|
|
10
|
+
} = util
|
|
11
|
+
|
|
12
|
+
export function handleOwnLineComment(comment, text, options, ast, isLastComment) {
|
|
16
13
|
const { precedingNode, enclosingNode, followingNode } = comment;
|
|
17
14
|
if (
|
|
18
15
|
handleLastFunctionArgComments(
|
|
@@ -77,7 +74,7 @@ function handleOwnLineComment(comment, text, options, ast, isLastComment) {
|
|
|
77
74
|
return false;
|
|
78
75
|
}
|
|
79
76
|
|
|
80
|
-
function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
|
|
77
|
+
export function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
|
|
81
78
|
const { precedingNode, enclosingNode, followingNode } = comment;
|
|
82
79
|
if (
|
|
83
80
|
handleLastFunctionArgComments(
|
|
@@ -132,7 +129,7 @@ function handleEndOfLineComment(comment, text, options, ast, isLastComment) {
|
|
|
132
129
|
return false;
|
|
133
130
|
}
|
|
134
131
|
|
|
135
|
-
function handleRemainingComment(comment, text, options, ast, isLastComment) {
|
|
132
|
+
export function handleRemainingComment(comment, text, options, ast, isLastComment) {
|
|
136
133
|
const { precedingNode, enclosingNode, followingNode } = comment;
|
|
137
134
|
|
|
138
135
|
if (
|
|
@@ -834,13 +831,6 @@ function handleTSMappedTypeComments(
|
|
|
834
831
|
return false;
|
|
835
832
|
}
|
|
836
833
|
|
|
837
|
-
function isBlockComment(comment) {
|
|
834
|
+
export function isBlockComment(comment) {
|
|
838
835
|
return comment.type === "Block" || comment.type === "CommentBlock";
|
|
839
836
|
}
|
|
840
|
-
|
|
841
|
-
module.exports = {
|
|
842
|
-
handleOwnLineComment,
|
|
843
|
-
handleEndOfLineComment,
|
|
844
|
-
handleRemainingComment,
|
|
845
|
-
isBlockComment
|
|
846
|
-
};
|
package/src/printer.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as nodes from './nodes/index.js';
|
|
2
|
+
import {
|
|
3
3
|
hasNodeIgnoreComment,
|
|
4
4
|
prettierVersionSatisfies
|
|
5
|
-
}
|
|
6
|
-
|
|
5
|
+
} from './common/util.js';
|
|
6
|
+
import ignoreComments from './comments/ignore.js';
|
|
7
7
|
|
|
8
8
|
let checked = false;
|
|
9
9
|
|
|
10
10
|
function prettierVersionCheck() {
|
|
11
11
|
if (checked) return;
|
|
12
|
-
if (!prettierVersionSatisfies('>=2.3.0
|
|
12
|
+
if (!prettierVersionSatisfies('>=2.3.0')) {
|
|
13
13
|
throw new Error(
|
|
14
14
|
'The version of prettier in your node-modules does not satisfy the required ">=2.3.0" constraint. Please update the version of Prettier.'
|
|
15
15
|
);
|
|
@@ -41,4 +41,4 @@ function genericPrint(path, options, print) {
|
|
|
41
41
|
return nodes[node.type].print({ node, options, path, print });
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
export default genericPrint;
|