Commit graph

338 commits

Author SHA1 Message Date
magic-akari
577d7ab72f
feat(prettier): Support TSImportEqualsDeclaration (#2321) 2024-02-05 20:37:26 +08:00
magic-akari
c6273732f6
feat(prettier): Support TSExportAssignment (#2320) 2024-02-05 20:33:03 +08:00
underfin
989ab88bc6
fix(codegen): print Directive original string (#2157)
> A Use Strict Directive may not contain an EscapeSequence or
LineContinuation.

It is `Use Strict Directive` spec, but the `expression` of `Directive`
isn't original string value, it has error if using it to codegen, so
here using `directive` of `Directive` to codegen and not to escape it.
Here is crashed test cases.

``` js
'use str\
ict';
```
The babel will print the original string, I follow it and avoid using
`print_str` because it will escape string.

I also changed some code using the `expression` of `Directive` to check
`Use Strict Directive` .
2024-01-25 15:24:05 +08:00
Dunqing
766ca63aa0
refactor(ast): rename RestElement to BindingRestElement (#2116)
close: #2115
2024-01-22 14:28:35 +08:00
Boshen
a9e2158362
Update README 2024-01-19 18:39:07 +08:00
magic-akari
9b77d0e6e6
fix(prettier): Correctly print export declaration (#2014)
Before this PR:
<img width="912" alt="image"
src="https://github.com/oxc-project/oxc/assets/7829098/78605f25-3320-4bed-8a31-3ffa7604cdc7">

https://oxc-project.github.io/oxc/playground/?code=3YCAAICUgICAgICAgICyHorESipoTXBToMuz4zZHvH%2B4MPS3Y6F%2FfvvogA%3D%3D
2024-01-13 21:26:33 +08:00
magic-akari
869643b03b
fix(prettier): Correctly format call expression arguments (#2018) 2024-01-13 21:25:26 +08:00
Deivid Almeida
c1cfd1759e
feat(linter): no-irregular-whitespace rule (#1835)
Parser, trivias and trivias_builder were edited to get all whitespaces.
Now Trivias struct store comments and whitespaces Vec. After that, i
will implement the no-irregular-whitespace rule.

P.S.: There isn't a way to implement this feature without lose a little
bit of performance, comparing with my last PR #1819 to minimax this
trouble instead of store the irregular whitespace as Span it was stored
as u32, i removed a map iterator and removed too a unused function. If
you have a suggestion about it pls give me a feedback.
2023-12-31 12:05:38 +08:00
IWANABETHATGUY
4bbc977971
chore: upgrade rustc toolchain to stable 1.75.0 (#1853)
ref: 
https://blog.rust-lang.org/2023/12/28/Rust-1.75.0.html
2023-12-29 12:20:51 +08:00
Cameron
29a4a35fd8
fix(prettier) add missing closing brace for dock debug (#1786) 2023-12-23 10:59:13 +08:00
Wenzhe Wang
c49a1f6b32
feat(prettier): add print_binaryish_expressions (#1664) 2023-12-13 22:52:53 +08:00
Dunqing
0c19991471
feat(prettier): print CallExpression arguments correctly (#1631) 2023-12-10 15:59:13 +08:00
Dunqing
6e5aad2639
feat(prettier): add ConditionalGroup command (#1635) 2023-12-07 20:12:45 +08:00
Wenzhe Wang
0dec110790
refactor(prettier): move the format of Function's key to PropertyKey (#1639) 2023-12-07 17:30:48 +08:00
Wenzhe Wang
286644714f
feat(prettier): wrap parameters in indent (#1633) 2023-12-06 10:20:31 +08:00
Wenzhe Wang
633455aba6
refactor(prettier): add print_method_value (#1632) 2023-12-06 10:16:09 +08:00
Wenzhe Wang
2aa5f7db91
feat(prettier): finish should_hug_the_only_function_parameter (#1626) 2023-12-05 22:55:12 +08:00
Cameron
b7b3073f3f
feat(prettier) port should_break_after_operator (#1606) 2023-12-02 20:40:25 +08:00
Cameron
502d61dc9f
fix(prettier) fix use chain formatting (#1605) 2023-12-02 15:44:25 +08:00
Boshen
811b219b27
feat(prettier): add parens to new class {} (#1604) 2023-12-01 21:36:01 +08:00
Boshen
bb61f10399
feat(prettier): handle parens for (x % y) % z (#1603) 2023-12-01 21:29:56 +08:00
Cameron
b4e90a723a
feat(prettier): implement has_comment, improve blank lines when printing arrays (#1601) 2023-12-01 20:52:26 +08:00
Cameron
deac95e274
feat(prettier): print blank lines when printing array concisely (#1600) 2023-12-01 20:48:10 +08:00
Boshen
f4f392e19f
feat(prettier): add parens to left of instanceof (#1602) 2023-12-01 19:08:45 +08:00
Cameron
66452c95f5
fix(prettier) print computed object property key correctly (#1599) 2023-12-01 18:36:38 +08:00
Cameron
0134211b6f
fix(prettier) use print_assignment for ObjectProperty (#1598) 2023-12-01 18:32:03 +08:00
Boshen
da87b9b29e
feat(prettier): binaryish expressions with parens (#1597) 2023-12-01 13:52:22 +08:00
Boshen
e3c54b92c9
fix(prettier): object pattern in function parameters (#1595) 2023-11-30 23:49:24 +08:00
Wenzhe Wang
9f38072002
feat(tasks): add visualize_end_of_line (#1593) 2023-11-30 23:42:57 +08:00
Dunqing
39188d00e1
feat(prettier): support arrowParens option (#1592) 2023-11-30 17:41:34 +08:00
Boshen
6ec257ba2d
feat(prettier): add --no-semi to prettier example (#1588) 2023-11-29 23:33:35 +08:00
Boshen
fd6a3ed918
feat(prettier): format for((async) of and for((let) of (#1586) 2023-11-29 22:55:42 +08:00
Boshen
1bd1c5b51b
feat(prettier): check parens for (let)[a] = 1 (#1585) 2023-11-29 21:57:59 +08:00
Boshen
c50fcececa
feat(prettier): wrap return statements with parentheses (#1583) 2023-11-29 19:31:55 +08:00
Boshen
b8ce6266ad
feat(prettier): handle parens for sequence expression (#1582) 2023-11-29 19:15:57 +08:00
Boshen
405d1228a0
feat(prettier): wrap BindingIdentifier (#1581) 2023-11-29 19:08:29 +08:00
Dunqing
f19032e102
feat(prettier): support quoteProps option in PropertyKey (#1578) 2023-11-29 18:32:30 +08:00
Dunqing
93d5b0f879
pref(prettier): using allocator String to avoid reallocation (#1577) 2023-11-29 18:27:27 +08:00
Dunqing
3a4261ff5d
fix(prettier): keep EmptyStatement in Program (#1576) 2023-11-29 18:22:40 +08:00
Boshen
7236368d5a
feat(prettier): implement is_next_line_empty_after_index (#1575) 2023-11-29 14:37:33 +08:00
Boshen
a9f0206805
feat(prettier): print es5 comma for object expression (#1574) 2023-11-29 13:36:28 +08:00
Boshen
c5b138f006
refactor(prettier): clean up object::print_object_properties (#1573) 2023-11-29 12:30:06 +08:00
Cameron
9a0a6f5004
feat(prettier) further improve class printing (#1566) 2023-11-28 10:59:37 +08:00
Cameron
522cf29489
feat(prettier) improve class printing (#1565) 2023-11-28 10:54:33 +08:00
Cameron
2bfd28e6f5
fix(prettier) remove unmatched brace when displaying doc (#1564) 2023-11-28 10:50:25 +08:00
Cameron
83f25fc9b3
fix(prettier) fix printing of call args when in break mode (#1563)
To test, format:
```ts
foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar();
```

Previously:
```ts
foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar(
  ,
);
```

Now:
```ts
foobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobarfoobar();
```
2023-11-28 10:45:27 +08:00
Cameron
cc25f7897d
fix(prettier) Fix printing of array expressions (#1562) 2023-11-28 10:39:37 +08:00
Cameron
fe7f6efff2
fix(prettier) Fix debug printing if IfBreak` doc (#1561) 2023-11-28 10:34:28 +08:00
Cameron
cda0b97ade
feat(prettier) use groupId in fluid assignments (#1560) 2023-11-28 10:29:32 +08:00
Boshen
7d9d04c569
refactor(prettier): align line with prettier (#1559)
This PR alines all the line types with prettier

```
const hardlineWithoutBreakParent = { type: DOC_TYPE_LINE, hard: true };
const literallineWithoutBreakParent = {
  type: DOC_TYPE_LINE,
  hard: true,
  literal: true,
};


const line = { type: DOC_TYPE_LINE };
const softline = { type: DOC_TYPE_LINE, soft: true };
const hardline = [hardlineWithoutBreakParent, breakParent];
const literalline = [literallineWithoutBreakParent, breakParent];
```

101598f94f/src/document/builders.js (L165-L175)
2023-11-27 23:11:53 +08:00
Wenzhe Wang
21dffec8be
feat(prettier): add id on IfBreak and Group (#1551) 2023-11-27 22:53:32 +08:00
Dunqing
0e1abae757
feat(prettier): filter out EmptyStatement in BlockStatement (#1546) 2023-11-27 22:45:45 +08:00
Boshen
6e7892fcf0
refactor(prettier): move comment printing to its own directory (#1556) 2023-11-27 14:22:15 +08:00
Boshen
cc382835ef
feat(prettier): trailing comment (wip) (#1538) 2023-11-27 14:08:39 +08:00
Dunqing
85e8c8bad5
fix(prettier): incorrect order of print in AssignmentTargetPropertyProperty (#1545) 2023-11-27 12:18:32 +08:00
Cameron
d5b636b197
feat(prettier) Improve assignment compatibility (#1547) 2023-11-27 10:01:01 +08:00
Cameron
08b659455b
refactor(prettier) move assignment printing into seperate file (#1544) 2023-11-26 14:09:57 +08:00
Wenzhe Wang
46d1086c3e
feat(prettier): add LineSuffix Doc (#1542) 2023-11-25 13:46:02 +08:00
Wenzhe Wang
924d99e8d7
feat(prettier): init command of Fill (#1460) 2023-11-25 12:03:26 +08:00
Boshen
13cac62402
feat(prettier): print leading comments for all ast nodes (#1537) 2023-11-25 00:35:51 +08:00
Dunqing
3ca2f50773
feat(prettier): align ObjectProerty with prettier (#1536) 2023-11-24 20:20:07 +08:00
Dunqing
ac8a5ce574
feat(prettier): support handling of BlockStatement within consequent in SwitchCase (#1533) 2023-11-24 17:15:29 +08:00
Dunqing
ec0ee5cd07
feat(prettier): keep empty lines in SwitchStatement (#1532) 2023-11-24 17:10:27 +08:00
Boshen
4a0d18048b
feat(prettier): format () => ({} ? 1 : 2); to () => ({}) ? 1 : 2; (#1534) 2023-11-24 17:07:19 +08:00
Dunqing
75c75887e3
feat(prettier): trim spaces when printing hardline (#1531) 2023-11-24 17:05:20 +08:00
Boshen
e55fdc6452
feat(prettier): add parens to conditional and arrow expr (#1530) 2023-11-24 15:07:29 +08:00
Boshen
6e81b3d41a
fix(prettier): pop the stack in should_wrap_function_for_export_default (#1529) 2023-11-24 14:57:06 +08:00
Boshen
78c6fcd1d0
feat(prettier): improve format of ExportDefaultDeclaration (#1520) 2023-11-23 21:52:56 +08:00
Wenzhe Wang
f4c89ce5a6
feat(prettier): implement DocBuidler trait for Printer and Prettier (#1519) 2023-11-23 21:48:13 +08:00
Dunqing
3758e6f6a5
feat(prettier): handle the logic inside the parentheses in BinaryExpression and LogicalExpression (#1516) 2023-11-23 18:32:25 +08:00
Dunqing
490a589ded
feat(prettier): print binarylish correctly in SwitchStatement (#1515) 2023-11-23 18:29:00 +08:00
Dunqing
635008a408
feat(prettier): support print empty switch (#1514) 2023-11-23 16:19:42 +08:00
Boshen
ef59f544b4
feat(prettier): handle binary in in for statement init (#1512) 2023-11-23 12:50:30 +08:00
Dunqing
bec365e1b6
feat(prettier): support propagate breaks (#1511)
regression tests are the expected result
2023-11-23 10:44:41 +08:00
Boshen
2d5e0d5d07
feat(prettier): handle parens for member expression inside new expression (#1505) 2023-11-22 16:22:49 +00:00
Boshen
6410502cc6
refactor(prettier): rename file need_parens -> needs_parens (#1504) 2023-11-23 00:04:00 +08:00
Boshen
d3b7629b46
feat(prettier): handle parens for logical assignment expression (#1503) 2023-11-22 23:58:43 +08:00
Boshen
93c461a5b9
feat(prettier): format number in member expression (#1499) 2023-11-22 21:52:06 +08:00
Boshen
567c6ed757
feat(prettier): print directives (#1497) 2023-11-22 19:39:25 +08:00
Boshen
cf803d379a
feat(prettier): add parens to ExportDefaultDeclaration (#1494) 2023-11-22 19:34:37 +08:00
Dunqing
79c67d15c0
perf(prettier): check commandjs or amd in CallExpression only (#1491) 2023-11-22 10:57:31 +08:00
Boshen
064353c97e
feat(prettier): turn off preserve_parens and start working on need-parens (#1487) 2023-11-21 16:26:56 +00:00
Shannon Rothe
8934ddb590
feat(prettier): basic TaggedTemplateExpression printing (#1486) 2023-11-21 22:15:29 +08:00
Dunqing
347b5721c0
feat(prettier): print multiple variable declarator correctly in VariableDeclaration (#1485) 2023-11-21 18:54:26 +08:00
Dunqing
f1874c7955
feat(prettier): should be newline if break in AssigmentExpression (#1484) 2023-11-21 18:50:26 +08:00
Dunqing
c762a85fcc
feat(prettier): print inner comment in PropertyKey (#1479) 2023-11-21 17:26:36 +08:00
Dunqing
79c2bac6b1
feat(prettier): support longer source in ImportExpression (#1478) 2023-11-21 17:21:23 +08:00
Dunqing
51a78e2223
feat(prettier): support print inner comment in CallExpression (#1475) 2023-11-21 12:28:46 +08:00
Dunqing
d64ed0a953
feat(prettier): support format commonjs and amd call (#1473) 2023-11-21 10:05:39 +08:00
magic-akari
f81f15ff71
fix(prettier): Private Field Expression (#1459) 2023-11-20 23:32:16 +08:00
Wenzhe Wang
5aca375a94
feat(prettier): add should_break for array (#1454) 2023-11-20 22:58:52 +08:00
magic-akari
4c213a1c14
fix(prettier): async arrow expression (#1457) 2023-11-20 22:58:37 +08:00
magic-akari
59b8fdfaa5
fix(prettier): class extends clause (#1456) 2023-11-20 21:45:28 +08:00
magic-akari
18d8be0353
fix(prettier): class without name (#1455) 2023-11-20 21:41:14 +08:00
magic-akari
eecf8d3dc6
fix(prettier): print_method (#1453) 2023-11-20 12:41:36 +00:00
Shannon Rothe
712505bfce
chore(prettier): fix typo in function name (#1451)
Small typo on the function name cloned from the Prettier repo
2023-11-20 18:51:45 +08:00
Boshen
0bf3dbfde4
feat(prettier): add infra for need_parens (#1450) 2023-11-20 17:18:39 +08:00
Dunqing
719ed744e0
feat(prettier): implement should_break in CallExpression and Object (#1448) 2023-11-20 17:07:32 +08:00
Dunqing
aabed6bee8
feat(prettier): when calculating the remaining width, the docs of the remaining commands should be included (#1441) 2023-11-20 16:59:06 +08:00
Dunqing
ca06126d50
feat(prettier): support format function for ImportNamespaceSpecifier (#1443) 2023-11-20 07:24:15 +00:00
Boshen
6892a298cf
feat(prettier): add spacing before empty bracket in ImportDeclaration (#1447)
Co-authored-by: Dunqing <dengqing0821@gmail.com>
2023-11-20 15:14:38 +08:00
Boshen
1a576f60a8
refactor(rust): move to workspace lint table (#1444) 2023-11-20 14:38:10 +08:00
Cameron
d02b7470d9
feat(prettier) print ?. when a printing an optional call expression (#1440) 2023-11-20 09:40:28 +08:00
Cameron
a53c5e9bab
feat(prettier) check original state for new lines when formatting properties (#1439) 2023-11-20 09:36:26 +08:00
Cameron
008eb0d178
feat(prettier) Support should_break option for group doc (#1438) 2023-11-20 09:32:05 +08:00
Boshen
18f19ee164
refactor(prettier): improve comment handling API (#1435) 2023-11-19 23:08:23 +08:00
Boshen
0218ae8641
feat(prettier): print leading comments with newlines (#1434) 2023-11-19 22:46:55 +08:00
Boshen
6ee072aafd
refactor(prettier): comment flags should be bigflags (#1433) 2023-11-19 21:24:22 +08:00
Boshen
cf388ae79e
feat(prettier): format empty try catch (#1430) 2023-11-19 18:01:49 +08:00
Boshen
18fa8e45a4
feat(prettier): format for((let) of .. (#1429) 2023-11-19 17:48:09 +08:00
Boshen
cc8b8719f7
feat(prettier): format for loop and update expression (#1427) 2023-11-19 14:04:47 +08:00
Wenzhe Wang
c1450d8e90
feat(prettier): basic print of TemplateLiteral (#1426) 2023-11-19 13:51:47 +08:00
Boshen
902d4d0bab
feat(prettier): format with and if statements (#1425) 2023-11-19 11:47:31 +08:00
Cameron
08ce4474e1
feat(prettier) Add IndentIfBreak support (#1420) 2023-11-19 03:11:52 +00:00
Dunqing
b945307ab3
feat(prettier): support format function for ImportDefaultSpecifier (#1424) 2023-11-19 11:10:08 +08:00
Wenzhe Wang
d6b913e46a
feat(prettier): add trailing comma (#1422) 2023-11-19 11:08:25 +08:00
Cameron
91ee3e8bfc
fix(prettier) Print intend in doc debug view (#1419) 2023-11-19 11:07:32 +08:00
Boshen
1dacb645d0
feat(prettier): start adding parent stack (#1415) 2023-11-18 16:39:24 +00:00
Boshen
abaa8c37a5
refactor(prettier): clean up some code (#1414) 2023-11-18 14:46:11 +00:00
Boshen
d0a70d0626
feat(prettier): print class method and read tab width (#1413) 2023-11-18 22:42:53 +08:00
Dunqing
b0248acb7b
refactor(prettier): refactor binaryish expression formatting (#1412) 2023-11-18 22:03:26 +08:00
Dunqing
f6ecd96e69
feat(prettier): print getter/setter function in PropertyKey (#1411) 2023-11-18 21:59:22 +08:00
Boshen
bc3069ec76
feat(prettier): print empty object properties (#1409) 2023-11-18 16:52:54 +08:00
Wenzhe Wang
70b80ba542
feat(prettier): print TSTupleType (#1408) 2023-11-18 16:44:27 +08:00
Wenzhe Wang
97fee26e25
feat(prettier): print empty array (#1407) 2023-11-18 16:40:39 +08:00
Boshen
481af5040d
feat(prettier): format hashbang (#1406) 2023-11-18 16:00:52 +08:00
Boshen
c9f7f1308f
chore(prettier): allow trailing comma in some macros (#1405) 2023-11-18 15:42:39 +08:00
Boshen
323f2f9789
feat(prettier): format more import and export declarations (#1404) 2023-11-18 15:37:56 +08:00
Dunqing
b251c10b09
feat(prettier): print parameters in ArrowExpression (#1400) 2023-11-18 05:37:55 +00:00
Dunqing
7951849ec1
feat(prettier): support format function for ImportExpression (#1399) 2023-11-18 13:34:14 +08:00
magic-akari
f5894b636b
perf(regexp): remove unnecessary sort (#1402) 2023-11-18 13:28:55 +08:00
Dunqing
75eb708526
feat(prettier): transform expression to identifier in PropertyKey (#1398) 2023-11-18 11:20:43 +08:00
Boshen
fb7cdc6687
refactor(prettier): impl Display for Doc (#1401) 2023-11-18 11:17:03 +08:00
Boshen
8cb0795796
feat(prettier): format SequenceExpression and ParenthesizedExpression (#1397) 2023-11-18 10:19:12 +08:00
Cameron
08f00cbd82
fix(prettier) if statement closing bracket indentation (#1396) 2023-11-18 09:51:25 +08:00
Cameron
39341e4688
feat(prettier) Print function args correctly (#1395) 2023-11-18 09:47:27 +08:00
Cameron
cff04ed09c
feat(prettier) print do while loop (#1394) 2023-11-18 09:41:27 +08:00
Cameron
db71974655
feat(prettier) Print labeled statement (#1393) 2023-11-18 09:36:28 +08:00
Cameron
ecbe0a4b98
feat(prettier) object assignments (#1392) 2023-11-18 09:31:26 +08:00
Cameron
6bb40a8f86
feat(prettier) array assignments (#1391) 2023-11-18 09:27:26 +08:00
Cameron
ba57544b6e
feat(prettier) TSInferType, TSIndexAccessType (#1390) 2023-11-18 09:22:37 +08:00
Boshen
7ed067ec28
feat(prettier): print NumberLiteral (#1389)
feat(prettier): print NumberLiteral

feat(prettier): format `NumberLiteral`
2023-11-18 02:06:09 +08:00
Cameron
b025213795
feat(prettier) port adjust clause (#1388) 2023-11-18 01:58:27 +08:00
Cameron
5cb6ff2895
feat(prettier) print while statement (#1387) 2023-11-18 01:52:27 +08:00
Cameron
0195affb5a
feat(prettier) print for in statements (#1386) 2023-11-18 01:46:27 +08:00
Cameron
b613eab2f0
feat(prettier) print for of statements (#1385) 2023-11-18 01:41:27 +08:00
Cameron
788e9b3807
feat(prettier) print for statement (#1384) 2023-11-18 01:36:14 +08:00
Boshen
f8b9679d74
feat(prettier): print module specifiers (#1383) 2023-11-17 22:03:28 +08:00
Cameron
001a8d8fe9
feat(prettier) print array pattern (#1382) 2023-11-17 21:56:41 +08:00
Cameron
6d0e647c13
feat(prettier) print TS literals (#1380) 2023-11-17 21:23:27 +08:00