|
1 | 1 | const { |
2 | 2 | doc: { |
3 | | - builders: { group, line, softline } |
| 3 | + builders: { join } |
4 | 4 | } |
5 | 5 | } = require('prettier/standalone'); |
6 | 6 |
|
7 | | -const printSeparatedList = require('./print-separated-list'); |
8 | 7 | const { printString } = require('../prettier-comments/common/util'); |
9 | 8 |
|
10 | 9 | const ImportDirective = { |
11 | 10 | print: ({ node, options }) => { |
12 | | - let doc = printString(node.path, options); |
| 11 | + const importPath = printString(node.path, options); |
| 12 | + |
| 13 | + let doc; |
13 | 14 |
|
14 | 15 | if (node.unitAlias) { |
15 | | - doc = [doc, ' as ', node.unitAlias]; |
| 16 | + // import "./Foo.sol" as Foo; |
| 17 | + doc = [importPath, ' as ', node.unitAlias]; |
16 | 18 | } else if (node.symbolAliases) { |
17 | | - doc = [ |
18 | | - '{', |
19 | | - printSeparatedList( |
20 | | - node.symbolAliases.map(([a, b]) => (b ? `${a} as ${b}` : a)), |
21 | | - { firstSeparator: options.bracketSpacing ? line : softline } |
22 | | - ), |
23 | | - '} from ', |
24 | | - doc |
25 | | - ]; |
| 19 | + // import { Foo, Bar as Qux } from "./Foo.sol"; |
| 20 | + doc = ['{']; |
| 21 | + |
| 22 | + if (options.bracketSpacing) { |
| 23 | + doc.push(' '); |
| 24 | + } |
| 25 | + |
| 26 | + const symbolAliases = node.symbolAliases.map(([a, b]) => |
| 27 | + b ? `${a} as ${b}` : a |
| 28 | + ); |
| 29 | + doc.push(join(', ', symbolAliases)); |
| 30 | + |
| 31 | + if (options.bracketSpacing) { |
| 32 | + doc.push(' '); |
| 33 | + } |
| 34 | + |
| 35 | + doc.push('} from ', importPath); |
| 36 | + } else { |
| 37 | + // import "./Foo.sol"; |
| 38 | + doc = importPath; |
26 | 39 | } |
27 | | - return group(['import ', doc, ';']); |
| 40 | + |
| 41 | + return ['import ', doc, ';']; |
28 | 42 | } |
29 | 43 | }; |
30 | 44 |
|
|
0 commit comments