mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
feat(codegen): improve codegen formatting (#3731)
This commit is contained in:
parent
ee627c355c
commit
bf9b38a197
5 changed files with 744 additions and 620 deletions
|
|
@ -122,9 +122,18 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for Statement<'a> {
|
|||
decl.gen(p, ctx);
|
||||
p.print_soft_newline();
|
||||
}
|
||||
Self::ClassDeclaration(decl) => decl.gen(p, ctx),
|
||||
Self::UsingDeclaration(declaration) => declaration.gen(p, ctx),
|
||||
Self::ClassDeclaration(decl) => {
|
||||
p.print_indent();
|
||||
decl.gen(p, ctx);
|
||||
p.print_soft_newline();
|
||||
}
|
||||
Self::UsingDeclaration(declaration) => {
|
||||
p.print_indent();
|
||||
declaration.gen(p, ctx);
|
||||
p.print_semicolon_after_statement();
|
||||
}
|
||||
Self::TSModuleDeclaration(decl) => {
|
||||
p.print_indent();
|
||||
decl.gen(p, ctx);
|
||||
p.print_soft_newline();
|
||||
}
|
||||
|
|
@ -133,8 +142,16 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for Statement<'a> {
|
|||
decl.gen(p, ctx);
|
||||
p.print_semicolon_after_statement();
|
||||
}
|
||||
Self::TSInterfaceDeclaration(decl) => decl.gen(p, ctx),
|
||||
Self::TSEnumDeclaration(decl) => decl.gen(p, ctx),
|
||||
Self::TSInterfaceDeclaration(decl) => {
|
||||
p.print_indent();
|
||||
decl.gen(p, ctx);
|
||||
p.print_soft_newline();
|
||||
}
|
||||
Self::TSEnumDeclaration(decl) => {
|
||||
p.print_indent();
|
||||
decl.gen(p, ctx);
|
||||
p.print_soft_newline();
|
||||
}
|
||||
Self::TSImportEqualsDeclaration(decl) => {
|
||||
p.print_indent();
|
||||
decl.gen(p, ctx);
|
||||
|
|
@ -565,7 +582,6 @@ 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.needs_semicolon = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -858,6 +874,7 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for ExportNamedDeclaration<'a> {
|
|||
if matches!(
|
||||
decl,
|
||||
Declaration::VariableDeclaration(_)
|
||||
| Declaration::UsingDeclaration(_)
|
||||
| Declaration::TSTypeAliasDeclaration(_)
|
||||
| Declaration::TSImportEqualsDeclaration(_)
|
||||
) {
|
||||
|
|
@ -1460,14 +1477,17 @@ impl<'a, const MINIFY: bool> GenExpr<MINIFY> for ObjectExpression<'a> {
|
|||
fn gen_expr(&self, p: &mut Codegen<{ MINIFY }>, _precedence: Precedence, ctx: Context) {
|
||||
let n = p.code_len();
|
||||
p.wrap(p.start_of_stmt == n || p.start_of_arrow_expr == n, |p| {
|
||||
p.print_curly_braces(self.span, self.properties.is_empty(), |p| {
|
||||
let single_line = self.properties.is_empty();
|
||||
p.print_curly_braces(self.span, single_line, |p| {
|
||||
for (index, item) in self.properties.iter().enumerate() {
|
||||
if index != 0 {
|
||||
p.print_comma();
|
||||
p.print_soft_space();
|
||||
p.print_soft_newline();
|
||||
}
|
||||
p.print_indent();
|
||||
item.gen(p, ctx);
|
||||
}
|
||||
if !single_line {
|
||||
p.print_soft_newline();
|
||||
}
|
||||
});
|
||||
|
|
@ -3155,7 +3175,6 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for TSNamedTupleMember<'a> {
|
|||
|
||||
impl<'a, const MINIFY: bool> Gen<MINIFY> for TSModuleDeclaration<'a> {
|
||||
fn gen(&self, p: &mut Codegen<{ MINIFY }>, ctx: Context) {
|
||||
p.print_indent();
|
||||
if self.modifiers.contains(ModifierKind::Export) {
|
||||
p.print_str(b"export ");
|
||||
}
|
||||
|
|
@ -3255,11 +3274,6 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for TSInterfaceDeclaration<'a> {
|
|||
p.print_soft_newline();
|
||||
}
|
||||
});
|
||||
if MINIFY {
|
||||
p.print_hard_space();
|
||||
}
|
||||
p.print_soft_newline();
|
||||
p.needs_semicolon = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3296,11 +3310,6 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for TSEnumDeclaration<'a> {
|
|||
p.print_soft_newline();
|
||||
}
|
||||
});
|
||||
if MINIFY {
|
||||
p.print_hard_space();
|
||||
}
|
||||
p.print_soft_newline();
|
||||
p.needs_semicolon = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
commit: 17ba9aea
|
||||
commit: a1587416
|
||||
|
||||
codegen_runtime_test262 Summary:
|
||||
AST Parsed : 18685/18685 (100.00%)
|
||||
Positive Passed: 18586/18685 (99.47%)
|
||||
AST Parsed : 18687/18687 (100.00%)
|
||||
Positive Passed: 18615/18687 (99.61%)
|
||||
Expect to run correctly: "annexB/built-ins/String/prototype/substr/surrogate-pairs.js"
|
||||
But got a runtime error: Test262Error: start: 1 Expected SameValue(«<>», «\udf06») to be true
|
||||
|
||||
|
|
@ -33,42 +33,6 @@ But got a runtime error: Test262Error: descriptor should be enumerable
|
|||
Expect to run correctly: "language/expressions/assignment/fn-name-lhs-cover.js"
|
||||
But got a runtime error: Test262Error: descriptor value should be ; object value should be
|
||||
|
||||
Expect to run correctly: "language/expressions/class/cpn-class-expr-accessors-computed-property-name-from-arrow-function-expression.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«undefined», «1») to be true
|
||||
|
||||
Expect to run correctly: "language/expressions/class/cpn-class-expr-accessors-computed-property-name-from-async-arrow-function-expression.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«undefined», «1») to be true
|
||||
|
||||
Expect to run correctly: "language/expressions/class/cpn-class-expr-accessors-computed-property-name-from-function-expression.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«undefined», «1») to be true
|
||||
|
||||
Expect to run correctly: "language/expressions/class/cpn-class-expr-computed-property-name-from-arrow-function-expression.js"
|
||||
But got a runtime error: TypeError: c[(intermediate value)] is not a function
|
||||
|
||||
Expect to run correctly: "language/expressions/class/cpn-class-expr-computed-property-name-from-async-arrow-function-expression.js"
|
||||
But got a runtime error: TypeError: c[(intermediate value)] is not a function
|
||||
|
||||
Expect to run correctly: "language/expressions/class/cpn-class-expr-computed-property-name-from-function-expression.js"
|
||||
But got a runtime error: TypeError: c[(intermediate value)] is not a function
|
||||
|
||||
Expect to run correctly: "language/expressions/class/cpn-class-expr-fields-computed-property-name-from-arrow-function-expression.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«undefined», «1») to be true
|
||||
|
||||
Expect to run correctly: "language/expressions/class/cpn-class-expr-fields-computed-property-name-from-async-arrow-function-expression.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«undefined», «1») to be true
|
||||
|
||||
Expect to run correctly: "language/expressions/class/cpn-class-expr-fields-computed-property-name-from-function-expression.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«undefined», «1») to be true
|
||||
|
||||
Expect to run correctly: "language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-arrow-function-expression.js"
|
||||
But got a runtime error: TypeError: c[(intermediate value)] is not a function
|
||||
|
||||
Expect to run correctly: "language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-async-arrow-function-expression.js"
|
||||
But got a runtime error: TypeError: c[(intermediate value)] is not a function
|
||||
|
||||
Expect to run correctly: "language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-function-expression.js"
|
||||
But got a runtime error: TypeError: c[(intermediate value)] is not a function
|
||||
|
||||
Expect to run correctly: "language/expressions/compound-assignment/compound-assignment-operator-calls-putvalue-lref--v--1.js"
|
||||
But got a runtime error: Test262Error: Expected a ReferenceError but got a TypeError
|
||||
|
||||
|
|
@ -144,15 +108,6 @@ But got a runtime error: Test262Error: constructor is %Promise% Expected SameVal
|
|||
Expect to run correctly: "language/expressions/object/__proto__-permitted-dup-shorthand.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«[object Object]», «2») to be true
|
||||
|
||||
Expect to run correctly: "language/expressions/object/cpn-obj-lit-computed-property-name-from-arrow-function-expression.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«undefined», «1») to be true
|
||||
|
||||
Expect to run correctly: "language/expressions/object/cpn-obj-lit-computed-property-name-from-async-arrow-function-expression.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«undefined», «1») to be true
|
||||
|
||||
Expect to run correctly: "language/expressions/object/cpn-obj-lit-computed-property-name-from-function-expression.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«undefined», «1») to be true
|
||||
|
||||
Expect to run correctly: "language/expressions/postfix-decrement/operator-x-postfix-decrement-calls-putvalue-lhs-newvalue--1.js"
|
||||
But got a runtime error: Test262Error: Expected a ReferenceError but got a TypeError
|
||||
|
||||
|
|
@ -243,42 +198,6 @@ But got a runtime error: Test262Error: Expected a ReferenceError to be thrown bu
|
|||
Expect to run correctly: "language/module-code/verify-dfs.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«B», «A») to be true
|
||||
|
||||
Expect to run correctly: "language/statements/class/cpn-class-decl-accessors-computed-property-name-from-arrow-function-expression.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«undefined», «1») to be true
|
||||
|
||||
Expect to run correctly: "language/statements/class/cpn-class-decl-accessors-computed-property-name-from-async-arrow-function-expression.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«undefined», «1») to be true
|
||||
|
||||
Expect to run correctly: "language/statements/class/cpn-class-decl-accessors-computed-property-name-from-function-expression.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«undefined», «1») to be true
|
||||
|
||||
Expect to run correctly: "language/statements/class/cpn-class-decl-computed-property-name-from-arrow-function-expression.js"
|
||||
But got a runtime error: TypeError: c[(intermediate value)] is not a function
|
||||
|
||||
Expect to run correctly: "language/statements/class/cpn-class-decl-computed-property-name-from-async-arrow-function-expression.js"
|
||||
But got a runtime error: TypeError: c[(intermediate value)] is not a function
|
||||
|
||||
Expect to run correctly: "language/statements/class/cpn-class-decl-computed-property-name-from-function-expression.js"
|
||||
But got a runtime error: TypeError: c[(intermediate value)] is not a function
|
||||
|
||||
Expect to run correctly: "language/statements/class/cpn-class-decl-fields-computed-property-name-from-arrow-function-expression.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«undefined», «1») to be true
|
||||
|
||||
Expect to run correctly: "language/statements/class/cpn-class-decl-fields-computed-property-name-from-async-arrow-function-expression.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«undefined», «1») to be true
|
||||
|
||||
Expect to run correctly: "language/statements/class/cpn-class-decl-fields-computed-property-name-from-function-expression.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«undefined», «1») to be true
|
||||
|
||||
Expect to run correctly: "language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-arrow-function-expression.js"
|
||||
But got a runtime error: TypeError: c[(intermediate value)] is not a function
|
||||
|
||||
Expect to run correctly: "language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-async-arrow-function-expression.js"
|
||||
But got a runtime error: TypeError: c[(intermediate value)] is not a function
|
||||
|
||||
Expect to run correctly: "language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-function-expression.js"
|
||||
But got a runtime error: TypeError: c[(intermediate value)] is not a function
|
||||
|
||||
Expect to run correctly: "language/statements/class/subclass/default-constructor-spread-override.js"
|
||||
But got a runtime error: Test262Error: @@iterator invoked
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -153,7 +153,6 @@ export const c: number = 1;
|
|||
export interface A {
|
||||
x: number;
|
||||
}
|
||||
|
||||
let expr: {
|
||||
x: number;
|
||||
};
|
||||
|
|
@ -167,7 +166,6 @@ export declare const c: number;
|
|||
export interface A {
|
||||
x: number;
|
||||
}
|
||||
|
||||
declare let expr: {
|
||||
x: number;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue