Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/compat): Fix handling of deep array pattern of object rest pass #6035

Merged
merged 8 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/swc/tests/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ fn create_matrix(entry: &Path) -> Vec<Options> {
jsc: JscConfig {
syntax: Some(syntax),
transform: None.into(),
external_helpers: external_helpers.into(),
// true, false
external_helpers: (!external_helpers).into(),
target: Some(target),
minify: if minify {
Some(JsMinifyOptions {
Expand Down
8 changes: 8 additions & 0 deletions crates/swc/tests/exec/issues-6xxx/6029/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


function thing({ queryKey: [{ url, ...query }] }) {
console.log(url);
console.log(query);
}

thing({ queryKey: [{ url: 'https://www.google.com', id: '1' }] })
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ impl ObjectRest {
// TODO: fix this. this is wrong
obj.clone(),
use_expr_for_assign,
use_member_for_array,
true,
);
ObjectPatProp::Rest(RestPat {
dot3_token,
Expand Down Expand Up @@ -873,7 +873,7 @@ impl ObjectRest {
.into(),
),
use_expr_for_assign,
use_member_for_array,
true,
),
);
ObjectPatProp::KeyValue(KeyValuePatProp { key, value })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use swc_common::chain;
use swc_common::{chain, Mark};
use swc_ecma_parser::Syntax;
use swc_ecma_transforms_base::resolver;
use swc_ecma_transforms_compat::{
es2015::spread,
es2015::{self, spread},
es2018::{object_rest_spread, object_rest_spread::Config},
};
use swc_ecma_transforms_testing::{test, test_exec};
Expand Down Expand Up @@ -3101,3 +3102,44 @@ a.c;a.c;
expect(counter).toEqual(2);
"#
);

test_exec!(
syntax(),
|_| tr(Default::default()),
issue_6029_1,
r#"
function thing({ queryKey: [{ url, ...query }] }) {
expect(url).toEqual('https://www.google.com')
expect(query).toEqual({ id: '1' })
}

thing({ queryKey: [{ url: 'https://www.google.com', id: '1' }] })
"#
);

test_exec!(
syntax(),
|t| {
//
let unresolved_mark = Mark::new();
let top_level_mark = Mark::new();
chain!(
resolver(unresolved_mark, top_level_mark, false),
tr(Default::default()),
es2015::es2015(
unresolved_mark,
Some(t.comments.clone()),
Default::default()
),
)
},
issue_6029_2,
r#"
function thing({ queryKey: [{ url, ...query }] }) {
expect(url).toEqual('https://www.google.com')
expect(query).toEqual({ id: '1' })
}

thing({ queryKey: [{ url: 'https://www.google.com', id: '1' }] })
"#
);