mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 20:28:58 +00:00
fix(codegen): format new expession + import expression with the correct parentheses (#2346)
Similar to #2330
This commit is contained in:
parent
f49ffb2b63
commit
2eb489e996
3 changed files with 23 additions and 34 deletions
|
|
@ -2,8 +2,8 @@ use oxc_syntax::precedence::{GetPrecedence, Precedence};
|
|||
|
||||
use crate::ast::{
|
||||
ArrowExpression, AssignmentExpression, AwaitExpression, BinaryExpression, CallExpression,
|
||||
ConditionalExpression, Expression, LogicalExpression, MemberExpression, NewExpression,
|
||||
SequenceExpression, UnaryExpression, UpdateExpression, YieldExpression,
|
||||
ConditionalExpression, Expression, ImportExpression, LogicalExpression, MemberExpression,
|
||||
NewExpression, SequenceExpression, UnaryExpression, UpdateExpression, YieldExpression,
|
||||
};
|
||||
|
||||
impl<'a> GetPrecedence for Expression<'a> {
|
||||
|
|
@ -97,6 +97,12 @@ impl<'a> GetPrecedence for CallExpression<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> GetPrecedence for ImportExpression<'a> {
|
||||
fn precedence(&self) -> Precedence {
|
||||
Precedence::Call
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GetPrecedence for NewExpression<'a> {
|
||||
fn precedence(&self) -> Precedence {
|
||||
if self.arguments.is_empty() {
|
||||
|
|
|
|||
|
|
@ -886,7 +886,7 @@ impl<'a, const MINIFY: bool> GenExpr<MINIFY> for Expression<'a> {
|
|||
Self::ConditionalExpression(expr) => expr.gen_expr(p, precedence, ctx),
|
||||
Self::AssignmentExpression(expr) => expr.gen_expr(p, precedence, ctx),
|
||||
Self::SequenceExpression(expr) => expr.gen_expr(p, precedence, ctx),
|
||||
Self::ImportExpression(expr) => expr.gen(p, ctx),
|
||||
Self::ImportExpression(expr) => expr.gen_expr(p, precedence, ctx),
|
||||
Self::TemplateLiteral(literal) => literal.gen(p, ctx),
|
||||
Self::TaggedTemplateExpression(expr) => expr.gen(p, ctx),
|
||||
Self::Super(sup) => sup.gen(p, ctx),
|
||||
|
|
@ -1738,15 +1738,19 @@ impl<'a, const MINIFY: bool> GenExpr<MINIFY> for SequenceExpression<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a, const MINIFY: bool> Gen<MINIFY> for ImportExpression<'a> {
|
||||
fn gen(&self, p: &mut Codegen<{ MINIFY }>, _ctx: Context) {
|
||||
p.print_str(b"import(");
|
||||
self.source.gen_expr(p, Precedence::Assign, Context::default());
|
||||
if !self.arguments.is_empty() {
|
||||
p.print_comma();
|
||||
p.print_expressions(&self.arguments, Precedence::Assign, Context::default());
|
||||
}
|
||||
p.print(b')');
|
||||
impl<'a, const MINIFY: bool> GenExpr<MINIFY> for ImportExpression<'a> {
|
||||
fn gen_expr(&self, p: &mut Codegen<{ MINIFY }>, precedence: Precedence, ctx: Context) {
|
||||
let wrap = precedence > self.precedence() || ctx.has_forbid_call();
|
||||
let ctx = ctx.and_forbid_call(false);
|
||||
p.wrap(wrap, |p| {
|
||||
p.print_str(b"import(");
|
||||
self.source.gen_expr(p, Precedence::Assign, ctx);
|
||||
if !self.arguments.is_empty() {
|
||||
p.print_comma();
|
||||
p.print_expressions(&self.arguments, Precedence::Assign, ctx);
|
||||
}
|
||||
p.print(b')');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
codegen_runtime_test262 Summary:
|
||||
AST Parsed : 19407/19407 (100.00%)
|
||||
Positive Passed: 19232/19407 (99.10%)
|
||||
Positive Passed: 19239/19407 (99.13%)
|
||||
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
|
||||
|
||||
|
|
@ -208,24 +208,6 @@ But got a runtime error: TypeError: c[(intermediate value)] is not a function
|
|||
Expect to run correctly: "language/expressions/class/elements/field-definition-accessor-no-line-terminator.js"
|
||||
But got a runtime error: SyntaxError: Unexpected identifier
|
||||
|
||||
Expect to run correctly: "language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-eval-indirect.js"
|
||||
But got a runtime error: TypeError: _eval is not a constructor
|
||||
|
||||
Expect to run correctly: "language/expressions/class/private-getter-brand-check-multiple-evaluations-of-class-eval.js"
|
||||
But got a runtime error: TypeError: eval is not a constructor
|
||||
|
||||
Expect to run correctly: "language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-eval-indirect.js"
|
||||
But got a runtime error: TypeError: _eval is not a constructor
|
||||
|
||||
Expect to run correctly: "language/expressions/class/private-method-brand-check-multiple-evaluations-of-class-eval.js"
|
||||
But got a runtime error: TypeError: eval is not a constructor
|
||||
|
||||
Expect to run correctly: "language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-eval-indirect.js"
|
||||
But got a runtime error: TypeError: _eval is not a constructor
|
||||
|
||||
Expect to run correctly: "language/expressions/class/private-setter-brand-check-multiple-evaluations-of-class-eval.js"
|
||||
But got a runtime error: TypeError: eval is not a constructor
|
||||
|
||||
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
|
||||
|
||||
|
|
@ -313,9 +295,6 @@ But got a runtime error: Test262Error: Expected SameValue(«function then() { [n
|
|||
Expect to run correctly: "language/expressions/dynamic-import/syntax/valid/nested-with-expression-script-code-valid.js"
|
||||
But got a runtime error: Test262Error: Expected SameValue(«function then() { [native code] }», «function then() { [native code] }») to be true
|
||||
|
||||
Expect to run correctly: "language/expressions/dynamic-import/syntax/valid/new-covered-expression-is-valid.js"
|
||||
But got a runtime error: SyntaxError: Cannot use new with import
|
||||
|
||||
Expect to run correctly: "language/expressions/dynamic-import/usage-from-eval.js"
|
||||
But got a runtime error: Test262Error: constructor is %Promise% Expected SameValue(«[object Promise]», «[object Promise]») to be true
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue