mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(codegen): using declaration in for statement (#3285)
Fixes conformance tests for `using` declarations in for statements, e.g.
```ts
for (using x = 1;;) {}
```
This commit is contained in:
parent
5b2fc391bc
commit
a12ed0fd26
4 changed files with 36 additions and 31 deletions
|
|
@ -234,20 +234,21 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for ForStatement<'a> {
|
|||
}
|
||||
|
||||
p.print_semicolon();
|
||||
p.print_soft_space();
|
||||
|
||||
if let Some(test) = self.test.as_ref() {
|
||||
p.print_soft_space();
|
||||
p.print_expression(test);
|
||||
}
|
||||
|
||||
p.print_semicolon();
|
||||
p.print_soft_space();
|
||||
|
||||
if let Some(update) = self.update.as_ref() {
|
||||
p.print_soft_space();
|
||||
p.print_expression(update);
|
||||
}
|
||||
|
||||
p.print(b')');
|
||||
p.print_soft_space();
|
||||
self.body.gen(p, ctx);
|
||||
}
|
||||
}
|
||||
|
|
@ -600,7 +601,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for UsingDeclaration<'a> {
|
|||
p.print_str(b"using");
|
||||
p.print_soft_space();
|
||||
p.print_list(&self.declarations, ctx);
|
||||
p.print_semicolon_after_statement();
|
||||
p.needs_semicolon = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -129,6 +129,17 @@ fn new_expr() {
|
|||
test("new (foo()).bar();", "new (foo()).bar();\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn for_stmt() {
|
||||
test("for (let x = 0; x < 10; x++) {}", "for (let x = 0; x < 10; x++) {\n}\n");
|
||||
test("for (;;) {}", "for (;;) {\n}\n");
|
||||
test("for (let x = 1;;) {}", "for (let x = 1;;) {\n}\n");
|
||||
test("for (;true;) {}", "for (; true;) {\n}\n");
|
||||
test("for (;;i++) {}", "for (;; i++) {\n}\n");
|
||||
|
||||
test("for (using x = 1;;) {}", "for (using x = 1;;) {\n}\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typescript() {
|
||||
test_ts("let x: string = `\\x01`;", "let x: string = `\\x01`;\n", false);
|
||||
|
|
|
|||
|
|
@ -752,8 +752,8 @@ Invalid Character `[`
|
|||
(182:88-182:91) " 1;" --> (111:88-111:91) " 1;"
|
||||
(182:91-182:98) " _key <" --> (111:91-111:98) " _key <"
|
||||
(182:98-182:104) " _len;" --> (111:98-111:104) " _len;"
|
||||
(182:104-182:112) " _key++)" --> (111:104-111:115) " _key++)\t\t\t"
|
||||
(182:112-183:6) " {\n " --> (111:115-112:0) "\t{"
|
||||
(182:104-182:112) " _key++)" --> (111:104-111:116) " _key++) \t\t\t"
|
||||
(182:112-183:6) " {\n " --> (111:116-112:0) "\t{"
|
||||
(183:6-183:11) " args" --> (112:0-112:10) "\n\t\t\t\t\targs"
|
||||
(183:11-183:18) "[_key -" --> (112:10-112:17) "[_key -"
|
||||
(183:18-183:23) " 1] =" --> (112:17-112:22) " 1] ="
|
||||
|
|
@ -789,8 +789,8 @@ Invalid Character `[`
|
|||
(191:92-191:95) " 1;" --> (119:92-119:95) " 1;"
|
||||
(191:95-191:103) " _key2 <" --> (119:95-119:103) " _key2 <"
|
||||
(191:103-191:110) " _len2;" --> (119:103-119:110) " _len2;"
|
||||
(191:110-191:119) " _key2++)" --> (119:110-119:122) " _key2++)\t\t\t"
|
||||
(191:119-192:6) " {\n " --> (119:122-120:0) "\t{"
|
||||
(191:110-191:119) " _key2++)" --> (119:110-119:123) " _key2++) \t\t\t"
|
||||
(191:119-192:6) " {\n " --> (119:123-120:0) "\t{"
|
||||
(192:6-192:11) " args" --> (120:0-120:10) "\n\t\t\t\t\targs"
|
||||
(192:11-192:19) "[_key2 -" --> (120:10-120:18) "[_key2 -"
|
||||
(192:19-192:24) " 1] =" --> (120:18-120:23) " 1] ="
|
||||
|
|
@ -1786,8 +1786,8 @@ Invalid Character `[`
|
|||
(747:17-747:20) " 0;" --> (434:17-434:20) " 0;"
|
||||
(747:20-747:24) " i <" --> (434:20-434:24) " i <"
|
||||
(747:24-747:40) " childrenLength;" --> (434:24-434:40) " childrenLength;"
|
||||
(747:40-747:45) " i++)" --> (434:40-434:48) " i++)\t\t\t"
|
||||
(747:45-748:6) " {\n " --> (434:48-435:0) "\t{"
|
||||
(747:40-747:45) " i++)" --> (434:40-434:49) " i++) \t\t\t"
|
||||
(747:45-748:6) " {\n " --> (434:49-435:0) "\t{"
|
||||
(748:6-748:17) " childArray" --> (435:0-435:16) "\n\t\t\t\t\tchildArray"
|
||||
(748:17-748:22) "[i] =" --> (435:16-435:21) "[i] ="
|
||||
(748:22-748:32) " arguments" --> (435:21-435:31) " arguments"
|
||||
|
|
@ -2058,8 +2058,8 @@ Invalid Character `[`
|
|||
(858:17-858:20) " 0;" --> (509:17-509:20) " 0;"
|
||||
(858:20-858:24) " i <" --> (509:20-509:24) " i <"
|
||||
(858:24-858:40) " childrenLength;" --> (509:24-509:40) " childrenLength;"
|
||||
(858:40-858:45) " i++)" --> (509:40-509:48) " i++)\t\t\t"
|
||||
(858:45-859:6) " {\n " --> (509:48-510:0) "\t{"
|
||||
(858:40-858:45) " i++)" --> (509:40-509:49) " i++) \t\t\t"
|
||||
(858:45-859:6) " {\n " --> (509:49-510:0) "\t{"
|
||||
(859:6-859:17) " childArray" --> (510:0-510:16) "\n\t\t\t\t\tchildArray"
|
||||
(859:17-859:22) "[i] =" --> (510:16-510:21) "[i] ="
|
||||
(859:22-859:32) " arguments" --> (510:21-510:31) " arguments"
|
||||
|
|
@ -2348,8 +2348,8 @@ Invalid Character `[`
|
|||
(1000:20-1000:24) " i <" --> (590:20-590:24) " i <"
|
||||
(1000:24-1000:33) " children" --> (590:24-590:33) " children"
|
||||
(1000:33-1000:41) ".length;" --> (590:33-590:41) ".length;"
|
||||
(1000:41-1000:46) " i++)" --> (590:41-590:49) " i++)\t\t\t"
|
||||
(1000:46-1001:6) " {\n " --> (590:49-591:0) "\t{"
|
||||
(1000:41-1000:46) " i++)" --> (590:41-590:50) " i++) \t\t\t"
|
||||
(1000:46-1001:6) " {\n " --> (590:50-591:0) "\t{"
|
||||
(1001:6-1001:14) " child =" --> (591:0-591:13) "\n\t\t\t\t\tchild ="
|
||||
(1001:14-1001:23) " children" --> (591:13-591:22) " children"
|
||||
(1001:23-1002:6) "[i];\n " --> (591:22-592:0) "[i];"
|
||||
|
|
@ -3975,8 +3975,8 @@ Invalid Character `[`
|
|||
(1758:23-1758:28) " c >=" --> (1145:22-1145:27) " c >="
|
||||
(1758:28-1758:31) " 0;" --> (1145:27-1145:30) " 0;"
|
||||
(1758:31-1758:36) " s--," --> (1145:30-1145:34) " s--"
|
||||
(1758:36-1758:41) " c--)" --> (1145:34-1145:43) ",c--)\t\t\t\t"
|
||||
(1758:41-1761:8) " {\n // Next we find the first one that isn't the same which should be the\n // frame that called our sample function and the control.\n " --> (1145:43-1146:0) "\t{"
|
||||
(1758:36-1758:41) " c--)" --> (1145:34-1145:44) ",c--) \t\t\t\t"
|
||||
(1758:41-1761:8) " {\n // Next we find the first one that isn't the same which should be the\n // frame that called our sample function and the control.\n " --> (1145:44-1146:0) "\t{"
|
||||
(1761:8-1761:12) " if " --> (1146:0-1146:10) "\n\t\t\t\t\t\tif "
|
||||
(1761:12-1761:24) "(sampleLines" --> (1146:10-1146:22) "(sampleLines"
|
||||
(1761:24-1761:31) "[s] !==" --> (1146:22-1146:29) "[s] !=="
|
||||
|
|
@ -4645,8 +4645,8 @@ Invalid Character `[`
|
|||
(2073:20-2073:24) " i <" --> (1347:20-1347:24) " i <"
|
||||
(2073:24-2073:29) " node" --> (1347:24-1347:29) " node"
|
||||
(2073:29-2073:37) ".length;" --> (1347:29-1347:37) ".length;"
|
||||
(2073:37-2073:42) " i++)" --> (1347:37-1347:45) " i++)\t\t\t"
|
||||
(2073:42-2074:6) " {\n " --> (1347:45-1348:5) "\t{\n\t\t\t\t"
|
||||
(2073:37-2073:42) " i++)" --> (1347:37-1347:46) " i++) \t\t\t"
|
||||
(2073:42-2074:6) " {\n " --> (1347:46-1348:5) "\t{\n\t\t\t\t"
|
||||
(2074:6-2074:10) " var" --> (1348:5-1348:9) "\tvar"
|
||||
(2074:10-2074:18) " child =" --> (1348:9-1348:17) " child ="
|
||||
(2074:18-2074:23) " node" --> (1348:17-1348:22) " node"
|
||||
|
|
@ -4839,8 +4839,8 @@ Invalid Character `[`
|
|||
(2159:20-2159:24) " i <" --> (1402:20-1402:24) " i <"
|
||||
(2159:24-2159:29) " keys" --> (1402:24-1402:29) " keys"
|
||||
(2159:29-2159:37) ".length;" --> (1402:29-1402:37) ".length;"
|
||||
(2159:37-2159:42) " i++)" --> (1402:37-1402:45) " i++)\t\t\t"
|
||||
(2159:42-2160:6) " {\n " --> (1402:45-1403:5) "\t{\n\t\t\t\t"
|
||||
(2159:37-2159:42) " i++)" --> (1402:37-1402:46) " i++) \t\t\t"
|
||||
(2159:42-2160:6) " {\n " --> (1402:46-1403:5) "\t{\n\t\t\t\t"
|
||||
(2160:6-2160:10) " var" --> (1403:5-1403:9) "\tvar"
|
||||
(2160:10-2160:16) " key =" --> (1403:9-1403:15) " key ="
|
||||
(2160:16-2160:21) " keys" --> (1403:15-1403:20) " keys"
|
||||
|
|
@ -5005,8 +5005,8 @@ Invalid Character `[`
|
|||
(2231:20-2231:24) " i <" --> (1451:20-1451:24) " i <"
|
||||
(2231:24-2231:34) " arguments" --> (1451:24-1451:34) " arguments"
|
||||
(2231:34-2231:42) ".length;" --> (1451:34-1451:42) ".length;"
|
||||
(2231:42-2231:47) " i++)" --> (1451:42-1451:50) " i++)\t\t\t"
|
||||
(2231:47-2232:6) " {\n " --> (1451:50-1452:0) "\t{"
|
||||
(2231:42-2231:47) " i++)" --> (1451:42-1451:51) " i++) \t\t\t"
|
||||
(2231:47-2232:6) " {\n " --> (1451:51-1452:0) "\t{"
|
||||
(2232:6-2232:24) " validateChildKeys" --> (1452:0-1452:23) "\n\t\t\t\t\tvalidateChildKeys"
|
||||
(2232:24-2232:34) "(arguments" --> (1452:23-1452:33) "(arguments"
|
||||
(2232:34-2232:38) "[i]," --> (1452:33-1452:37) "[i],"
|
||||
|
|
@ -5112,8 +5112,8 @@ Invalid Character `[`
|
|||
(2275:18-2275:22) " i <" --> (1486:19-1486:23) " i <"
|
||||
(2275:22-2275:32) " arguments" --> (1486:23-1486:33) " arguments"
|
||||
(2275:32-2275:40) ".length;" --> (1486:33-1486:41) ".length;"
|
||||
(2275:40-2275:45) " i++)" --> (1486:41-1486:48) " i++)\t\t"
|
||||
(2275:45-2276:4) " {\n " --> (1486:48-1487:0) "\t{"
|
||||
(2275:40-2275:45) " i++)" --> (1486:41-1486:49) " i++) \t\t"
|
||||
(2275:45-2276:4) " {\n " --> (1486:49-1487:0) "\t{"
|
||||
(2276:4-2276:22) " validateChildKeys" --> (1487:0-1487:22) "\n\t\t\t\tvalidateChildKeys"
|
||||
(2276:22-2276:32) "(arguments" --> (1487:22-1487:32) "(arguments"
|
||||
(2276:32-2276:36) "[i]," --> (1487:32-1487:36) "[i],"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ commit: 64d2eeea
|
|||
|
||||
codegen_typescript Summary:
|
||||
AST Parsed : 5243/5243 (100.00%)
|
||||
Positive Passed: 5228/5243 (99.71%)
|
||||
Positive Passed: 5235/5243 (99.85%)
|
||||
Typescript failed: "compiler/castExpressionParentheses.ts"
|
||||
Default failed: "compiler/elidedEmbeddedStatementsReplacedWithSemicolon.ts"
|
||||
Typescript failed: "compiler/genericTypeAssertions3.ts"
|
||||
|
|
@ -11,10 +11,3 @@ Default failed: "compiler/jsxMultilineAttributeValuesReact.tsx"
|
|||
Default failed: "compiler/typeAliasDeclarationEmit3.ts"
|
||||
Default failed: "conformance/constEnums/constEnum4.ts"
|
||||
Default failed: "conformance/jsx/tsxReactEmitEntities.tsx"
|
||||
Default failed: "conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarationsInFor.ts"
|
||||
Default failed: "conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarationsInForAwaitOf.ts"
|
||||
Default failed: "conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarationsInForOf.1.ts"
|
||||
Default failed: "conformance/statements/VariableStatements/usingDeclarations/awaitUsingDeclarationsInForOf.2.ts"
|
||||
Default failed: "conformance/statements/VariableStatements/usingDeclarations/usingDeclarationsInFor.ts"
|
||||
Default failed: "conformance/statements/VariableStatements/usingDeclarations/usingDeclarationsInForAwaitOf.ts"
|
||||
Default failed: "conformance/statements/VariableStatements/usingDeclarations/usingDeclarationsInForOf.1.ts"
|
||||
|
|
|
|||
Loading…
Reference in a new issue