Skip to content

Commit 20621b2

Browse files
committed
arrow function expressions w/ object patterns
1 parent 96d8d21 commit 20621b2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/es_tree/tools/generator.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ defmodule ESTree.Tools.Generator do
231231
do_generate(body, opts)
232232
end
233233

234-
if not opts.beauty and length(ast.params) == 1 do
234+
if not opts.beauty and length(ast.params) == 1 and hd(ast.params).__struct__ != ObjectPattern do
235235
[async, params, generator, wh_sep, "=>", wh_sep, body]
236236
else
237237
[async, "(", params, ")", generator, wh_sep, "=>", wh_sep, body]

test/tools/generator/arrow_function_expression_test.exs

+13
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ defmodule ESTree.Tools.Generator.ArrowFunctionExpression.Test do
3030
assert_gen ast, "()=>({})", beauty: false
3131
end
3232

33+
should "convert basic arrow function object pattern has parens" do
34+
ast = Builder.arrow_function_expression(
35+
[Builder.object_pattern([Builder.identifier(:one)])],
36+
[],
37+
Builder.block_statement([]),
38+
false,
39+
false
40+
)
41+
42+
assert_gen ast, "({one}) => {}"
43+
assert_gen ast, "({one})=>{}", beauty: false
44+
end
45+
3346
should "convert basic arrow function expression generator" do
3447
ast = Builder.arrow_function_expression(
3548
[],

0 commit comments

Comments
 (0)