@haneullabs/prettier-plugin-move 0.3.3
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/CHANGELOG.md +67 -0
- package/CONTRIBUTING.md +31 -0
- package/README.md +96 -0
- package/bin/prettier-move.js +29 -0
- package/out/cst/annotation.js +64 -0
- package/out/cst/annotation.js.map +1 -0
- package/out/cst/common.js +376 -0
- package/out/cst/common.js.map +1 -0
- package/out/cst/constant.js +92 -0
- package/out/cst/constant.js.map +1 -0
- package/out/cst/enum_definition.js +69 -0
- package/out/cst/enum_definition.js.map +1 -0
- package/out/cst/expression/abort_expression.js +32 -0
- package/out/cst/expression/abort_expression.js.map +1 -0
- package/out/cst/expression/annotation_expression.js +35 -0
- package/out/cst/expression/annotation_expression.js.map +1 -0
- package/out/cst/expression/assign_expression.js +51 -0
- package/out/cst/expression/assign_expression.js.map +1 -0
- package/out/cst/expression/binary_expression.js +70 -0
- package/out/cst/expression/binary_expression.js.map +1 -0
- package/out/cst/expression/block.js +58 -0
- package/out/cst/expression/block.js.map +1 -0
- package/out/cst/expression/block_item.js +25 -0
- package/out/cst/expression/block_item.js.map +1 -0
- package/out/cst/expression/borrow_expression.js +26 -0
- package/out/cst/expression/borrow_expression.js.map +1 -0
- package/out/cst/expression/break_expression.js +27 -0
- package/out/cst/expression/break_expression.js.map +1 -0
- package/out/cst/expression/call_expression.js +25 -0
- package/out/cst/expression/call_expression.js.map +1 -0
- package/out/cst/expression/cast_expression.js +31 -0
- package/out/cst/expression/cast_expression.js.map +1 -0
- package/out/cst/expression/continue_expression.js +26 -0
- package/out/cst/expression/continue_expression.js.map +1 -0
- package/out/cst/expression/dereference_expression.js +27 -0
- package/out/cst/expression/dereference_expression.js.map +1 -0
- package/out/cst/expression/dot_expression.js +66 -0
- package/out/cst/expression/dot_expression.js.map +1 -0
- package/out/cst/expression/expression_list.js +26 -0
- package/out/cst/expression/expression_list.js.map +1 -0
- package/out/cst/expression/identified_expression.js +28 -0
- package/out/cst/expression/identified_expression.js.map +1 -0
- package/out/cst/expression/if_expression.js +133 -0
- package/out/cst/expression/if_expression.js.map +1 -0
- package/out/cst/expression/index.js +74 -0
- package/out/cst/expression/index.js.map +1 -0
- package/out/cst/expression/index_expression.js +28 -0
- package/out/cst/expression/index_expression.js.map +1 -0
- package/out/cst/expression/lambda_expression.js +72 -0
- package/out/cst/expression/lambda_expression.js.map +1 -0
- package/out/cst/expression/let_statement.js +59 -0
- package/out/cst/expression/let_statement.js.map +1 -0
- package/out/cst/expression/loop_expression.js +27 -0
- package/out/cst/expression/loop_expression.js.map +1 -0
- package/out/cst/expression/macro_call_expression.js +66 -0
- package/out/cst/expression/macro_call_expression.js.map +1 -0
- package/out/cst/expression/match_expression.js +86 -0
- package/out/cst/expression/match_expression.js.map +1 -0
- package/out/cst/expression/move_or_copy_expression.js +27 -0
- package/out/cst/expression/move_or_copy_expression.js.map +1 -0
- package/out/cst/expression/name_expression.js +26 -0
- package/out/cst/expression/name_expression.js.map +1 -0
- package/out/cst/expression/pack_expression.js +27 -0
- package/out/cst/expression/pack_expression.js.map +1 -0
- package/out/cst/expression/return_expression.js +44 -0
- package/out/cst/expression/return_expression.js.map +1 -0
- package/out/cst/expression/unary_expression.js +26 -0
- package/out/cst/expression/unary_expression.js.map +1 -0
- package/out/cst/expression/unit_expression.js +17 -0
- package/out/cst/expression/unit_expression.js.map +1 -0
- package/out/cst/expression/vector_expression.js +80 -0
- package/out/cst/expression/vector_expression.js.map +1 -0
- package/out/cst/expression/while_expression.js +42 -0
- package/out/cst/expression/while_expression.js.map +1 -0
- package/out/cst/formatting.js +100 -0
- package/out/cst/formatting.js.map +1 -0
- package/out/cst/function_definition.js +248 -0
- package/out/cst/function_definition.js.map +1 -0
- package/out/cst/literal.js +68 -0
- package/out/cst/literal.js.map +1 -0
- package/out/cst/module.js +158 -0
- package/out/cst/module.js.map +1 -0
- package/out/cst/source_file.js +38 -0
- package/out/cst/source_file.js.map +1 -0
- package/out/cst/struct_definition.js +209 -0
- package/out/cst/struct_definition.js.map +1 -0
- package/out/cst/use_declaration.js +212 -0
- package/out/cst/use_declaration.js.map +1 -0
- package/out/imports-grouping.js +259 -0
- package/out/imports-grouping.js.map +1 -0
- package/out/index.js +97 -0
- package/out/index.js.map +1 -0
- package/out/printer.js +69 -0
- package/out/printer.js.map +1 -0
- package/out/tree.js +371 -0
- package/out/tree.js.map +1 -0
- package/out/utilities.js +251 -0
- package/out/utilities.js.map +1 -0
- package/package.json +34 -0
- package/prettier.config.js +12 -0
- package/src/cst/annotation.ts +71 -0
- package/src/cst/common.ts +430 -0
- package/src/cst/constant.ts +110 -0
- package/src/cst/enum_definition.ts +73 -0
- package/src/cst/expression/abort_expression.ts +35 -0
- package/src/cst/expression/annotation_expression.ts +38 -0
- package/src/cst/expression/assign_expression.ts +66 -0
- package/src/cst/expression/binary_expression.ts +75 -0
- package/src/cst/expression/block.ts +72 -0
- package/src/cst/expression/block_item.ts +29 -0
- package/src/cst/expression/borrow_expression.ts +28 -0
- package/src/cst/expression/break_expression.ts +33 -0
- package/src/cst/expression/call_expression.ts +28 -0
- package/src/cst/expression/cast_expression.ts +35 -0
- package/src/cst/expression/continue_expression.ts +29 -0
- package/src/cst/expression/dereference_expression.ts +33 -0
- package/src/cst/expression/dot_expression.ts +89 -0
- package/src/cst/expression/expression_list.ts +28 -0
- package/src/cst/expression/identified_expression.ts +30 -0
- package/src/cst/expression/if_expression.ts +177 -0
- package/src/cst/expression/index.ts +85 -0
- package/src/cst/expression/index_expression.ts +37 -0
- package/src/cst/expression/lambda_expression.ts +84 -0
- package/src/cst/expression/let_statement.ts +73 -0
- package/src/cst/expression/loop_expression.ts +29 -0
- package/src/cst/expression/macro_call_expression.ts +79 -0
- package/src/cst/expression/match_expression.ts +102 -0
- package/src/cst/expression/move_or_copy_expression.ts +29 -0
- package/src/cst/expression/name_expression.ts +28 -0
- package/src/cst/expression/pack_expression.ts +29 -0
- package/src/cst/expression/return_expression.ts +50 -0
- package/src/cst/expression/unary_expression.ts +28 -0
- package/src/cst/expression/unit_expression.ts +18 -0
- package/src/cst/expression/vector_expression.ts +97 -0
- package/src/cst/expression/while_expression.ts +45 -0
- package/src/cst/formatting.ts +100 -0
- package/src/cst/function_definition.ts +300 -0
- package/src/cst/literal.ts +69 -0
- package/src/cst/module.ts +191 -0
- package/src/cst/source_file.ts +38 -0
- package/src/cst/struct_definition.ts +267 -0
- package/src/cst/use_declaration.ts +238 -0
- package/src/imports-grouping.ts +300 -0
- package/src/index.ts +119 -0
- package/src/printer.ts +93 -0
- package/src/tree.ts +438 -0
- package/src/utilities.ts +387 -0
- package/tree-sitter-move.wasm +0 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) The Move Contributors
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.printImports = printImports;
|
|
6
|
+
exports.collectImports = collectImports;
|
|
7
|
+
/**
|
|
8
|
+
* This module contains the logic for grouping imports in a file.
|
|
9
|
+
*
|
|
10
|
+
* @module imports-grouping
|
|
11
|
+
*/
|
|
12
|
+
const prettier_1 = require("prettier");
|
|
13
|
+
const use_declaration_1 = require("./cst/use_declaration");
|
|
14
|
+
const { join, softline, indent, line, group } = prettier_1.doc.builders;
|
|
15
|
+
/**
|
|
16
|
+
* Special function to print imports if import grouping is turned on.
|
|
17
|
+
* Important note: we don't use the `print` function for imports, as they're already
|
|
18
|
+
* parsed. We just need to print them in the correct order and format.
|
|
19
|
+
*
|
|
20
|
+
* We sort and avoid duplicates in the imports. To do so, we keep track of the
|
|
21
|
+
* printed keys (including alias!), and only print the import if it hasn't been
|
|
22
|
+
* printed before.
|
|
23
|
+
*/
|
|
24
|
+
function printImports(imports, option) {
|
|
25
|
+
const pkgs = [...imports.keys()].sort();
|
|
26
|
+
const result = [];
|
|
27
|
+
for (const pkg of pkgs) {
|
|
28
|
+
const modules = imports.get(pkg);
|
|
29
|
+
// typescript wants this
|
|
30
|
+
if (modules == undefined) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const keys = [...modules.keys()].sort();
|
|
34
|
+
// if grouped by module
|
|
35
|
+
if (option === 'module') {
|
|
36
|
+
for (const mod of keys) {
|
|
37
|
+
if (!modules.get(mod))
|
|
38
|
+
continue;
|
|
39
|
+
result.push(['use ', pkg, '::', printModule(mod, modules.get(mod)), ';']);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// if grouped by package
|
|
44
|
+
const modulesDoc = [];
|
|
45
|
+
for (const mod of keys) {
|
|
46
|
+
if (!modules.has(mod))
|
|
47
|
+
continue;
|
|
48
|
+
modulesDoc.push(printModule(mod, modules.get(mod)));
|
|
49
|
+
}
|
|
50
|
+
modulesDoc.length === 1
|
|
51
|
+
? result.push(['use ', pkg, '::', modulesDoc[0], ';'])
|
|
52
|
+
: result.push([
|
|
53
|
+
'use ',
|
|
54
|
+
pkg,
|
|
55
|
+
'::',
|
|
56
|
+
group([
|
|
57
|
+
'{',
|
|
58
|
+
indent(softline),
|
|
59
|
+
indent(join([',', line], modulesDoc)),
|
|
60
|
+
softline,
|
|
61
|
+
'}',
|
|
62
|
+
]),
|
|
63
|
+
';',
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
function printModule(mod, members) {
|
|
70
|
+
const printedKeys = [];
|
|
71
|
+
// perform deduplication of imports
|
|
72
|
+
members = members.filter((m) => {
|
|
73
|
+
const key = [mod, m.name, m.alias || '-'].join('');
|
|
74
|
+
if (printedKeys.includes(key))
|
|
75
|
+
return false;
|
|
76
|
+
printedKeys.push(key);
|
|
77
|
+
return true;
|
|
78
|
+
});
|
|
79
|
+
if (members.length === 1) {
|
|
80
|
+
const member = members[0];
|
|
81
|
+
if (member.name === 'Self') {
|
|
82
|
+
const alias = member.alias ? ` as ${member.alias}` : '';
|
|
83
|
+
return `${mod}${alias}`;
|
|
84
|
+
}
|
|
85
|
+
return [mod, '::', printMember(member)];
|
|
86
|
+
}
|
|
87
|
+
const selfIdx = members.findIndex((m) => m.name === 'Self');
|
|
88
|
+
if (selfIdx !== -1) {
|
|
89
|
+
const self = members.splice(selfIdx, 1);
|
|
90
|
+
members = [...self, ...members];
|
|
91
|
+
}
|
|
92
|
+
return members.length === 0
|
|
93
|
+
? [mod]
|
|
94
|
+
: [
|
|
95
|
+
mod,
|
|
96
|
+
'::',
|
|
97
|
+
group([
|
|
98
|
+
'{',
|
|
99
|
+
indent(softline),
|
|
100
|
+
indent(join([',', line], members.map(printMember))),
|
|
101
|
+
softline,
|
|
102
|
+
'}',
|
|
103
|
+
]),
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Print a single member of a module with an optional alias.
|
|
108
|
+
*/
|
|
109
|
+
function printMember({ name, alias }) {
|
|
110
|
+
const a = alias ? ` as ${alias}` : '';
|
|
111
|
+
return `${name}${a}`;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Special function which walks the current node and collects all `use` imports.
|
|
115
|
+
* Returns a tree of all imports in this file to be used for grouping.
|
|
116
|
+
*
|
|
117
|
+
* There are 3 main types of imports:
|
|
118
|
+
* - `use_module` - `module_access` <as `alias`>;
|
|
119
|
+
* - `use_module_member` - `<module_identity>::<use_member>`;
|
|
120
|
+
* - `use_module_members` - `package::<use_member>, <use_member>, ...`
|
|
121
|
+
*
|
|
122
|
+
* @param node
|
|
123
|
+
* @returns
|
|
124
|
+
*/
|
|
125
|
+
function collectImports(node) {
|
|
126
|
+
const grouped = new Map();
|
|
127
|
+
const imports = node.nonFormattingChildren
|
|
128
|
+
.filter((n) => n.isGroupedImport)
|
|
129
|
+
.map((n) => n.nonFormattingChildren[0]);
|
|
130
|
+
for (let import_ of imports) {
|
|
131
|
+
switch (import_.type) {
|
|
132
|
+
// `module_access` <as `alias`>;
|
|
133
|
+
case use_declaration_1.UseDeclaration.UseModule: {
|
|
134
|
+
const moduleIdentity = import_.nonFormattingChildren[0];
|
|
135
|
+
const alias = import_.nonFormattingChildren[1];
|
|
136
|
+
const [pkg, mod] = parseModuleIdentity(moduleIdentity);
|
|
137
|
+
// we use `Self` in the tree to represent the current module
|
|
138
|
+
const rec = { name: 'Self', alias: alias?.text };
|
|
139
|
+
// if there hasn't been a registered package yet, add it
|
|
140
|
+
if (!grouped.has(pkg))
|
|
141
|
+
grouped.set(pkg, new Map());
|
|
142
|
+
const pkgMap = grouped.get(pkg);
|
|
143
|
+
// if there hasn't been a registered module yet, add it
|
|
144
|
+
if (!pkgMap.has(mod))
|
|
145
|
+
pkgMap.set(mod, []);
|
|
146
|
+
pkgMap.set(mod, pkgMap.get(mod));
|
|
147
|
+
pkgMap.get(mod).push(rec);
|
|
148
|
+
break;
|
|
149
|
+
}
|
|
150
|
+
// `<module_identity>::<use_member>`
|
|
151
|
+
case use_declaration_1.UseDeclaration.UseModuleMember: {
|
|
152
|
+
const moduleIdentity = import_.nonFormattingChildren[0];
|
|
153
|
+
const [pkg, mod] = parseModuleIdentity(moduleIdentity);
|
|
154
|
+
const useMember = import_.nonFormattingChildren[1];
|
|
155
|
+
const [name, alias] = parseUseMember(useMember);
|
|
156
|
+
if (!grouped.has(pkg))
|
|
157
|
+
grouped.set(pkg, new Map());
|
|
158
|
+
const pkgMap = grouped.get(pkg);
|
|
159
|
+
if (!pkgMap.has(mod))
|
|
160
|
+
pkgMap.set(mod, []);
|
|
161
|
+
const modMap = pkgMap.get(mod);
|
|
162
|
+
modMap.push({ name, alias });
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
// The only tricky node in this scheme. `use_module_members` can be
|
|
166
|
+
// both for grouped by package and for grouped by module, so we have
|
|
167
|
+
// to detect which version it is and then dance off of that.
|
|
168
|
+
case use_declaration_1.UseDeclaration.UseModuleMembers: {
|
|
169
|
+
const children = import_.nonFormattingChildren;
|
|
170
|
+
const isGroupedByPackage = children[0].type === 'module_identifier';
|
|
171
|
+
if (!isGroupedByPackage && children[0].type !== use_declaration_1.UseDeclaration.ModuleIdentity) {
|
|
172
|
+
throw new Error('Expected `module_identity` or `module_identifier`');
|
|
173
|
+
}
|
|
174
|
+
// simple scenario: the first node is `module_identity`
|
|
175
|
+
if (!isGroupedByPackage) {
|
|
176
|
+
const moduleIdentity = children[0];
|
|
177
|
+
const [pkg, mod] = parseModuleIdentity(moduleIdentity);
|
|
178
|
+
const members = children.slice(1).map((n) => parseUseMember(n));
|
|
179
|
+
if (!grouped.has(pkg))
|
|
180
|
+
grouped.set(pkg, new Map());
|
|
181
|
+
const pkgMap = grouped.get(pkg);
|
|
182
|
+
if (!pkgMap.has(mod))
|
|
183
|
+
pkgMap.set(mod, []);
|
|
184
|
+
const modMap = pkgMap.get(mod);
|
|
185
|
+
modMap.push(...members.map(([name, alias]) => ({ name, alias })));
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
// complex scenario: the first node is `module_identifier`
|
|
189
|
+
// `use_member` can be recursive in this scenario with 1 level of nesting
|
|
190
|
+
const pkg = children[0].text;
|
|
191
|
+
if (!grouped.has(pkg))
|
|
192
|
+
grouped.set(pkg, new Map());
|
|
193
|
+
const pkgMap = grouped.get(pkg);
|
|
194
|
+
children.slice(1).forEach((node) => {
|
|
195
|
+
if (!node)
|
|
196
|
+
return;
|
|
197
|
+
if (node.type !== use_declaration_1.UseDeclaration.UseMember)
|
|
198
|
+
throw new Error('Expected `use_member` node got `' + node.type + '`');
|
|
199
|
+
const [first, ...rest] = node.nonFormattingChildren;
|
|
200
|
+
if (!first || first.type !== 'identifier')
|
|
201
|
+
throw new Error('Expected `identifier` node in `use_module_members`');
|
|
202
|
+
const mod = first.text;
|
|
203
|
+
if (!pkgMap.has(mod))
|
|
204
|
+
pkgMap.set(mod, []);
|
|
205
|
+
// if there's only one member and it's the module.
|
|
206
|
+
if (!rest.length) {
|
|
207
|
+
pkgMap.get(mod).push({ name: 'Self', alias: undefined });
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
// ident + ident is an alias
|
|
211
|
+
if (rest.length == 1 && rest[0]?.type === 'identifier') {
|
|
212
|
+
if (rest[0].previousSibling?.type !== 'as') {
|
|
213
|
+
pkgMap.get(mod).push({ name: rest[0].text, alias: undefined });
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
pkgMap.get(mod).push({ name: 'Self', alias: rest[0].text });
|
|
217
|
+
}
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
// special case, no use member, but already expanded pair of identifiers.
|
|
221
|
+
if (rest.length == 2 &&
|
|
222
|
+
rest[0]?.type === 'identifier' &&
|
|
223
|
+
rest[1]?.type === 'identifier') {
|
|
224
|
+
if (rest[1].previousSibling?.type !== 'as') {
|
|
225
|
+
throw new Error('Expected `as` keyword after module name');
|
|
226
|
+
}
|
|
227
|
+
pkgMap.get(mod).push({ name: rest[0].text, alias: rest[1].text });
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
// the rest are `use_member` nodes
|
|
231
|
+
const members = rest.map(parseUseMember);
|
|
232
|
+
pkgMap.get(mod).push(...members.map(([name, alias]) => ({ name, alias })));
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return grouped;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Parse a `module_identity` node returning a tuple of package and module.
|
|
241
|
+
*/
|
|
242
|
+
function parseModuleIdentity(node) {
|
|
243
|
+
if (node.type !== use_declaration_1.UseDeclaration.ModuleIdentity) {
|
|
244
|
+
throw new Error('Expected `module_identity` node');
|
|
245
|
+
}
|
|
246
|
+
const [pkg, mod] = node.nonFormattingChildren.map((n) => n.text);
|
|
247
|
+
return [pkg, mod];
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Parse a simple `use_member` node returning a tuple of member and alias.
|
|
251
|
+
*/
|
|
252
|
+
function parseUseMember(node) {
|
|
253
|
+
if (node.type !== use_declaration_1.UseDeclaration.UseMember) {
|
|
254
|
+
throw new Error('Expected `use_member` node, got `' + node.type + '`');
|
|
255
|
+
}
|
|
256
|
+
const [member, alias] = node.nonFormattingChildren.map((n) => n.text);
|
|
257
|
+
return [member, alias];
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=imports-grouping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imports-grouping.js","sourceRoot":"","sources":["../src/imports-grouping.ts"],"names":[],"mappings":";AAAA,sCAAsC;AACtC,sCAAsC;;AAkCtC,oCAgDC;AAgED,wCAgIC;AAhRD;;;;GAIG;AAEH,uCAAoC;AAEpC,2DAAuD;AACvD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,cAAG,CAAC,QAAQ,CAAC;AAc7D;;;;;;;;GAQG;AACH,SAAgB,YAAY,CAAC,OAAuB,EAAE,MAA4B;IAC9E,MAAM,IAAI,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACxC,MAAM,MAAM,GAAG,EAAW,CAAC;IAE3B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACrB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAEjC,wBAAwB;QACxB,IAAI,OAAO,IAAI,SAAS,EAAE,CAAC;YACvB,SAAS;QACb,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAExC,uBAAuB;QACvB,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;YACtB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;gBACrB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAA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
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) The Move Contributors
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.defaultOptions = exports.options = exports.printers = exports.parsers = exports.languages = void 0;
|
|
6
|
+
/**
|
|
7
|
+
* Contains the Prettier Plugin definition for the Move language.
|
|
8
|
+
* For more information on Prettier plugins, see https://prettier.io/docs/en/plugins.html
|
|
9
|
+
*
|
|
10
|
+
* The printing logic is implemented in the `printer` module, which is routing the
|
|
11
|
+
* specific node types defined in the `cst/*` modules.
|
|
12
|
+
*
|
|
13
|
+
* Additionally, `utilities` module contains helper functions for the printer.
|
|
14
|
+
*
|
|
15
|
+
* @module prettier-move
|
|
16
|
+
*/
|
|
17
|
+
const path = require("path");
|
|
18
|
+
const Parser = require("web-tree-sitter");
|
|
19
|
+
const printer_1 = require("./printer");
|
|
20
|
+
const tree_1 = require("./tree");
|
|
21
|
+
exports.languages = [
|
|
22
|
+
{
|
|
23
|
+
name: 'move',
|
|
24
|
+
extensions: ['.move'],
|
|
25
|
+
parsers: ['move'],
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
exports.parsers = {
|
|
29
|
+
move: {
|
|
30
|
+
parse: (text) => {
|
|
31
|
+
return (async () => {
|
|
32
|
+
await Parser.init();
|
|
33
|
+
const parser = new Parser();
|
|
34
|
+
const Lang = await Parser.Language.load(path.join(__dirname, '..', 'tree-sitter-move.wasm'));
|
|
35
|
+
parser.setLanguage(Lang);
|
|
36
|
+
return new tree_1.Tree(parser.parse(text).rootNode);
|
|
37
|
+
})();
|
|
38
|
+
},
|
|
39
|
+
astFormat: 'move',
|
|
40
|
+
locStart: () => -1,
|
|
41
|
+
locEnd: () => -1,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
exports.printers = {
|
|
45
|
+
move: { print: printer_1.print },
|
|
46
|
+
};
|
|
47
|
+
exports.options = {
|
|
48
|
+
autoGroupImports: {
|
|
49
|
+
type: 'choice',
|
|
50
|
+
category: 'Global',
|
|
51
|
+
default: 'package',
|
|
52
|
+
description: "Group all use imports by 'package', 'module' or 'none'.",
|
|
53
|
+
choices: [
|
|
54
|
+
{
|
|
55
|
+
value: 'package',
|
|
56
|
+
description: 'Group imports by package, eg `use sui::{balance::Balance, coin::Coin}',
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
value: 'module',
|
|
60
|
+
description: 'Group imports by module eg\n`use sui::balance::Balance;\nuse sui::coin::Coin`',
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
wrapComments: {
|
|
65
|
+
type: 'boolean',
|
|
66
|
+
category: 'Global',
|
|
67
|
+
default: false,
|
|
68
|
+
description: 'Wrap comments to the next line if the line is too long.',
|
|
69
|
+
},
|
|
70
|
+
useModuleLabel: {
|
|
71
|
+
type: 'boolean',
|
|
72
|
+
category: 'Global',
|
|
73
|
+
default: true,
|
|
74
|
+
description: 'Enable module labels instead of module with braces. This option will be ignored if there is more than one module in the file.',
|
|
75
|
+
},
|
|
76
|
+
enableErrorDebug: {
|
|
77
|
+
type: 'boolean',
|
|
78
|
+
category: 'Global',
|
|
79
|
+
default: false,
|
|
80
|
+
description: 'Print ERROR nodes instead of throwing an error.',
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
exports.defaultOptions = {
|
|
84
|
+
tabWidth: 4,
|
|
85
|
+
useTabs: false,
|
|
86
|
+
printWidth: 100,
|
|
87
|
+
useModuleLabel: false,
|
|
88
|
+
groupImports: 'module',
|
|
89
|
+
};
|
|
90
|
+
exports.default = {
|
|
91
|
+
languages: exports.languages,
|
|
92
|
+
parsers: exports.parsers,
|
|
93
|
+
printers: exports.printers,
|
|
94
|
+
options: exports.options,
|
|
95
|
+
defaultOptions: exports.defaultOptions,
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=index.js.map
|
package/out/index.js.map
AD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AE,SAAS;QAClB,WAAW,EAAE,yDAAyD;QACtE,OAAO,EAAE;YACL;gBACI,KAAK,EAAE,SAAS;gBAChB,WAAW,EACP,uEAAuE;aAC9E;YACD;gBACI,KAAK,EAAE,QAAQ;gBACf,WAAW,EACP,+EAA+E;aACtF;SACJ;KACJ;IACD,YAAY,EAAE;QACV,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,QAAQ;QAClB,OAAO,EAAE,KAAK;QACd,WAAW,EAAE,yDAAyD;KACzE;IACD,cAAc,EAAE;QACZ,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,QAAQ;QAClB,OAAO,EAAE,IAAI;QACb,WAAW,EACP,+HAA+H;KACtI;IACD,gBAAgB,EAAE;QACd,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,QAAQ;QAClB,OAAO,EAAE,KAAK;QACd,WAAW,EAAE,iDAAiD;KACjE;CACJ,CAAC;AAEW,QAAA,cAAc,GAAG;IAC1B,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,KAAK;IACd,UAAU,EAAE,GAAG;IACf,cAAc,EAAE,KAAK;IACrB,YAAY,EAAE,QAAQ;CACzB,CAAC;AAEF,kBAAe;IACX,SAAS,EAAT,iBAAS;IACT,OAAO,EAAP,eAAO;IACP,QAAQ,EAAR,gBAAQ;IACR,OAAO,EAAP,eAAO;IACP,cAAc,EAAd,sBAAc;CACP,CAAC"}
|
package/out/printer.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) The Move Contributors
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.print = print;
|
|
6
|
+
const common_1 = require("./cst/common");
|
|
7
|
+
const formatting_1 = require("./cst/formatting");
|
|
8
|
+
const module_1 = require("./cst/module");
|
|
9
|
+
const use_declaration_1 = require("./cst/use_declaration");
|
|
10
|
+
const constant_1 = require("./cst/constant");
|
|
11
|
+
const struct_definition_1 = require("./cst/struct_definition");
|
|
12
|
+
const function_definition_1 = require("./cst/function_definition");
|
|
13
|
+
const source_file_1 = require("./cst/source_file");
|
|
14
|
+
const expression_1 = require("./cst/expression");
|
|
15
|
+
const literal_1 = require("./cst/literal");
|
|
16
|
+
const utilities_1 = require("./utilities");
|
|
17
|
+
const enum_definition_1 = require("./cst/enum_definition");
|
|
18
|
+
const annotation_1 = require("./cst/annotation");
|
|
19
|
+
/**
|
|
20
|
+
* Print the AST node at the given path.
|
|
21
|
+
*/
|
|
22
|
+
function print(path, options, print) {
|
|
23
|
+
// check if the node has an error child, if so, we throw an error or return the error text
|
|
24
|
+
const checkErrorsCb = (path) => {
|
|
25
|
+
if (path.node.children.some((n) => n.type === 'ERROR')) {
|
|
26
|
+
if (options.enableErrorDebug) {
|
|
27
|
+
return ((path, options, print) => ['/* ERROR: */', path.node.text]);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
throw new Error('tree-sitter failure on \n```\n' + path.node.text + '\n```');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (path.node.children.some((n) => n.type === 'MISSING')) {
|
|
34
|
+
if (options.enableErrorDebug) {
|
|
35
|
+
return ((path, options, print) => ['/* MISSING: */', path.node.text]);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
throw new Error('tree-sitter failure on \n```\n' + path.node.text + '\n```');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
};
|
|
43
|
+
// for unimplemented / not yet implemented nodes, we just return the node type
|
|
44
|
+
const defautCb = (path, options, print) => {
|
|
45
|
+
return path.node.type;
|
|
46
|
+
};
|
|
47
|
+
const fn = checkErrorsCb(path) ||
|
|
48
|
+
(0, source_file_1.default)(path) ||
|
|
49
|
+
(0, annotation_1.default)(path) ||
|
|
50
|
+
(0, formatting_1.default)(path) ||
|
|
51
|
+
(0, common_1.default)(path) ||
|
|
52
|
+
(0, module_1.default)(path) ||
|
|
53
|
+
(0, use_declaration_1.default)(path) ||
|
|
54
|
+
(0, constant_1.default)(path) ||
|
|
55
|
+
(0, enum_definition_1.default)(path) ||
|
|
56
|
+
(0, struct_definition_1.default)(path) ||
|
|
57
|
+
(0, function_definition_1.default)(path) ||
|
|
58
|
+
(0, expression_1.default)(path) ||
|
|
59
|
+
(0, literal_1.default)(path) ||
|
|
60
|
+
defautCb;
|
|
61
|
+
return [
|
|
62
|
+
(0, utilities_1.printLeadingComment)(path, options),
|
|
63
|
+
// if the node has a `skipFormattingNode` property, we just return
|
|
64
|
+
// the text without formatting it
|
|
65
|
+
path.node.skipFormattingNode ? path.node.text : fn(path, options, print),
|
|
66
|
+
(0, utilities_1.printTrailingComment)(path),
|
|
67
|
+
];
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=printer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printer.js","sourceRoot":"","sources":["../src/printer.ts"],"names":[],"mappings":";AAAA,sCAAsC;AACtC,sCAAsC;;AAyCtC,sBAkDC;AA/ED,yCAAkC;AAClC,iDAA0C;AAC1C,yCAAkC;AAClC,2DAAmD;AACnD,6CAAsC;AACtC,+DAAuD;AACvD,mEAA2D;AAC3D,mDAA2C;AAC3C,iDAA0C;AAC1C,2CAAoC;AACpC,2CAAwE;AACxE,2DAAmD;AACnD,iDAA0C;AAc1C;;GAEG;AACH,SAAgB,KAAK,CAAC,IAAmB,EAAE,OAAoB,EAAE,KAAc;IAC3E,0FAA0F;IAC1F,MAAM,aAAa,GAAG,CAAC,IAAmB,EAAE,EAAE;QAC1C,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,EAAE,CAAC;YACrD,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;gBAC3B,OAAO,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,KAA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