Skip to content

Commit 870a90a

Browse files
authored
Merge pull request #7880 from QwikDev/v2-rest-props-conflicting-name
fix: avoid conflicting restprops and props names
2 parents 0a414c0 + 569b4a6 commit 870a90a

21 files changed

+353
-113
lines changed

.changeset/easy-geese-watch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@qwik.dev/core': patch
3+
---
4+
5+
fix: convert any destructured props to restProps helper

.changeset/many-forks-ring.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@qwik.dev/core': patch
3+
---
4+
5+
fix: avoid potential name conflicts with rest props

packages/qwik/src/core/qwik.core.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ export interface ResourceResolved<T> {
902902
export type ResourceReturn<T> = ResourcePending<T> | ResourceResolved<T> | ResourceRejected<T>;
903903

904904
// @internal (undocumented)
905-
export const _restProps: (props: PropsProxy, omit: string[], target?: Props) => Props;
905+
export const _restProps: (props: PropsProxy, omit?: string[], target?: Props) => Props;
906906

907907
// @internal
908908
export const _run: (...args: unknown[]) => ValueOrPromise<unknown>;

packages/qwik/src/core/shared/utils/prop.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export function isSlotProp(prop: string): boolean {
77
}
88

99
/** @internal */
10-
export const _restProps = (props: PropsProxy, omit: string[], target: Props = {}) => {
10+
export const _restProps = (props: PropsProxy, omit: string[] = [], target: Props = {}) => {
1111
let constPropsTarget: Props | null = null;
1212
const constProps = props[_CONST_PROPS];
1313
if (constProps) {

packages/qwik/src/optimizer/core/src/props_destructuring.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ enum TransformInit {
5656
impl<'a> PropsDestructuring<'a> {
5757
fn transform_component_props(&mut self, arrow: &mut ast::ArrowExpr) {
5858
if let Some(ast::Pat::Object(obj)) = arrow.params.first() {
59-
let new_ident = private_ident!("props");
60-
if let Some((rest_id, local)) =
59+
let new_ident = private_ident!("_rawProps");
60+
if let Some((rest_id_opt, local)) =
6161
transform_pat(ast::Expr::Ident(new_ident.clone()), obj, self)
6262
{
63-
if let Some(rest_id) = rest_id {
63+
if let Some(rest_id) = rest_id_opt {
6464
let omit_fn = self.global_collect.import(&_REST_PROPS, self.core_module);
65-
let omit = local.iter().map(|(_, id, _)| id.clone()).collect();
65+
let omit: Vec<JsWord> = local.iter().map(|(_, id, _)| id.clone()).collect();
6666
transform_rest(
6767
arrow,
6868
&omit_fn,
@@ -413,9 +413,10 @@ fn transform_pat(
413413
}
414414
}
415415
}
416-
if skip || local.is_empty() {
416+
if skip {
417417
return None;
418418
}
419+
// Allow case with only rest binding (no local fields)
419420
Some((rest_id, local))
420421
}
421422

@@ -426,7 +427,30 @@ fn transform_rest(
426427
props_expr: ast::Expr,
427428
omit: Vec<JsWord>,
428429
) {
429-
let new_stmt = create_omit_props(omit_fn, rest_id, props_expr, omit);
430+
let new_stmt = if omit.is_empty() {
431+
// const rest = _restProps(rawProps);
432+
ast::Stmt::Decl(ast::Decl::Var(Box::new(ast::VarDecl {
433+
kind: ast::VarDeclKind::Const,
434+
decls: vec![ast::VarDeclarator {
435+
definite: false,
436+
span: DUMMY_SP,
437+
init: Some(Box::new(ast::Expr::Call(ast::CallExpr {
438+
callee: ast::Callee::Expr(Box::new(ast::Expr::Ident(new_ident_from_id(
439+
omit_fn,
440+
)))),
441+
args: vec![ast::ExprOrSpread {
442+
spread: None,
443+
expr: Box::new(props_expr),
444+
}],
445+
..Default::default()
446+
}))),
447+
name: ast::Pat::Ident(ast::BindingIdent::from(new_ident_from_id(rest_id))),
448+
}],
449+
..Default::default()
450+
})))
451+
} else {
452+
create_omit_props(omit_fn, rest_id, props_expr, omit)
453+
};
430454
match &mut arrow.body {
431455
box ast::BlockStmtOrExpr::BlockStmt(block) => {
432456
block.stmts.insert(0, new_stmt);

packages/qwik/src/optimizer/core/src/snapshots/qwik_core__test__destructure_args_inline_cmp_block_stmt.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import { _fnSignal } from "@qwik.dev/core";
2424
import { qrl } from "@qwik.dev/core";
2525
import { _jsxSorted } from "@qwik.dev/core";
2626
const i_GbMO6TGQv9M = ()=>import("./test.tsx_test_div_onClick_GbMO6TGQv9M");
27-
export default ((props)=>{
27+
export default ((_rawProps)=>{
2828
return /*#__PURE__*/ _jsxSorted("div", {
2929
"data-is-active": _fnSignal((p0)=>p0.data.selectedOutputDetail === 'options', [
30-
props
30+
_rawProps
3131
], 'p0.data.selectedOutputDetail==="options"'),
3232
onClick$: /*#__PURE__*/ qrl(i_GbMO6TGQv9M, "test_div_onClick_GbMO6TGQv9M", [
33-
props
33+
_rawProps
3434
])
3535
}, null, null, 2, "u6_0");
3636
});
@@ -41,12 +41,12 @@ Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"ma
4141

4242
import { useLexicalScope } from "@qwik.dev/core";
4343
export const test_div_onClick_GbMO6TGQv9M = ()=>{
44-
const [props] = useLexicalScope();
45-
props.data.selectedOutputDetail = 'options';
44+
const [_rawProps] = useLexicalScope();
45+
_rawProps.data.selectedOutputDetail = 'options';
4646
};
4747

4848

49-
Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\";4CAKwB;;IACR,MALI,KAKC,oBAAoB,GAAG\"}")
49+
Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\";4CAKwB;;IACR,UALI,KAKC,oBAAoB,GAAG\"}")
5050
/*
5151
{
5252
"origin": "test.tsx",
@@ -66,7 +66,7 @@ Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"ma
6666
259
6767
],
6868
"captureNames": [
69-
"props"
69+
"_rawProps"
7070
]
7171
}
7272
*/

packages/qwik/src/optimizer/core/src/snapshots/qwik_core__test__destructure_args_inline_cmp_expr_stmt.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,27 @@ import { _fnSignal } from "@qwik.dev/core";
2121
import { qrl } from "@qwik.dev/core";
2222
import { _jsxSorted } from "@qwik.dev/core";
2323
const i_GbMO6TGQv9M = ()=>import("./test.tsx_test_div_onClick_GbMO6TGQv9M");
24-
export default ((props)=>/*#__PURE__*/ _jsxSorted("div", {
24+
export default ((_rawProps)=>/*#__PURE__*/ _jsxSorted("div", {
2525
"data-is-active": _fnSignal((p0)=>p0.data.selectedOutputDetail === 'options', [
26-
props
26+
_rawProps
2727
], 'p0.data.selectedOutputDetail==="options"'),
2828
onClick$: /*#__PURE__*/ qrl(i_GbMO6TGQv9M, "test_div_onClick_GbMO6TGQv9M", [
29-
props
29+
_rawProps
3030
])
3131
}, null, null, 2, "u6_0"));
3232

3333

34-
Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\";;;;AACE,eAAe,CAAA,uBACL,WAAC;QACC,gBAAc,kBAAE,GAFV,KAEe,oBAAoB,KAAK;;;QAC9C,QAAQ;;;6BAGT,EAAE\"}")
34+
Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\";;;;AACE,eAAe,CAAA,2BACL,WAAC;QACC,gBAAc,kBAAE,GAFV,KAEe,oBAAoB,KAAK;;;QAC9C,QAAQ;;;6BAGT,EAAE\"}")
3535
============================= test.tsx_test_div_onClick_GbMO6TGQv9M.js (ENTRY POINT)==
3636

3737
import { useLexicalScope } from "@qwik.dev/core";
3838
export const test_div_onClick_GbMO6TGQv9M = ()=>{
39-
const [props] = useLexicalScope();
40-
props.data.selectedOutputDetail = 'options';
39+
const [_rawProps] = useLexicalScope();
40+
_rawProps.data.selectedOutputDetail = 'options';
4141
};
4242

4343

44-
Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\";4CAIwB;;IACR,MAJI,KAIC,oBAAoB,GAAG\"}")
44+
Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\";4CAIwB;;IACR,UAJI,KAIC,oBAAoB,GAAG\"}")
4545
/*
4646
{
4747
"origin": "test.tsx",
@@ -61,7 +61,7 @@ Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"ma
6161
238
6262
],
6363
"captureNames": [
64-
"props"
64+
"_rawProps"
6565
]
6666
}
6767
*/

packages/qwik/src/optimizer/core/src/snapshots/qwik_core__test__example_dead_code.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const Foo = component$(({foo}) => {
2323

2424
============================= test.tsx_Foo_component_HTDRsvUbLiE.tsx (ENTRY POINT)==
2525

26-
export const Foo_component_HTDRsvUbLiE = (props)=>{
26+
export const Foo_component_HTDRsvUbLiE = (_rawProps)=>{
2727
useMount$(()=>{});
2828
return <div/>;
2929
};
@@ -49,7 +49,7 @@ Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"ma
4949
199
5050
],
5151
"paramNames": [
52-
"props"
52+
"_rawProps"
5353
]
5454
}
5555
*/

packages/qwik/src/optimizer/core/src/snapshots/qwik_core__test__example_invalid_references.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ import { _auto_I8 as I8 } from "./test";
6161
import { _auto_I9 as I9 } from "./test";
6262
import { qrl } from "@qwik.dev/core";
6363
const i_w0t0o3QMovU = ()=>import("./test.tsx_App_component_1_w0t0o3QMovU");
64-
export const App_component_ckEPmXZlub0 = (props)=>{
64+
export const App_component_ckEPmXZlub0 = (_rawProps)=>{
6565
console.log(I1, I2, I3, I4, I5, I6, I7, I8, I9);
6666
console.log(itsok, v1, v2, v3, obj);
6767
return /*#__PURE__*/ qrl(i_w0t0o3QMovU, "App_component_1_w0t0o3QMovU");
@@ -88,7 +88,7 @@ Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"ma
8888
346
8989
],
9090
"paramNames": [
91-
"props"
91+
"_rawProps"
9292
]
9393
}
9494
*/

packages/qwik/src/optimizer/core/src/snapshots/qwik_core__test__example_issue_33443.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ const Issue3742_component_div_button_onClick_a504K2BCEXg = ()=>{
3535
const [counter] = useLexicalScope();
3636
return counter.value++;
3737
};
38-
const Issue3742_component_svSy0PlWTAw = (props)=>{
38+
const Issue3742_component_svSy0PlWTAw = (_rawProps)=>{
3939
const counter = useSignal(0);
4040
return /*#__PURE__*/ _jsxSorted("div", {
41-
title: _fnSignal((p0, p1)=>(p1.description ?? '') && 'description' in p1.other ? `Hello ${p0.value}` : `Bye ${p0.value}`, [
42-
counter,
43-
props
44-
], '(p1.description??"")&&"description"in p1.other?`Hello ${p0.value}`:`Bye ${p0.value}`')
41+
title: _fnSignal((p0, p1)=>(p0.description ?? '') && 'description' in p0.other ? `Hello ${p1.value}` : `Bye ${p1.value}`, [
42+
_rawProps,
43+
counter
44+
], '(p0.description??"")&&"description"in p0.other?`Hello ${p1.value}`:`Bye ${p1.value}`')
4545
}, null, [
4646
"Issue3742",
4747
/*#__PURE__*/ _jsxSorted("button", null, {

0 commit comments

Comments
 (0)