Skip to content

Commit

Permalink
fix: a bug QwikDev#7216, that const prop was putted in the var
Browse files Browse the repository at this point in the history
  • Loading branch information
wuls committed Feb 6, 2025
1 parent aed94db commit 83e76bc
Show file tree
Hide file tree
Showing 4 changed files with 294 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
---
source: packages/qwik/src/optimizer/core/src/test.rs
assertion_line: 4275
expression: output
snapshot_kind: text
---
==INPUT==


import { component$ } from '@builder.io/qwik';
export default component$((props) => {
return (<p
onHi$={() => 'hi'}
{...props.foo}
onHello$={props.helloHandler$}
{...props.rest}
onVar$={props.onVarHandler$}
onConst$={() => 'const'}
asd={"1"}
/>);
});

============================= test.js ==

import { componentQrl } from "@qwik.dev/core";
import { qrl } from "@qwik.dev/core";
export default /*#__PURE__*/ componentQrl(/*#__PURE__*/ qrl(()=>import("./test.tsx_test_component_LUXeXe0DQrg"), "test_component_LUXeXe0DQrg"));


Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\";;AAEA,6BAAe,mHAUZ\"}")
============================= test.tsx_test_component_p_onHi_MzKNRhr770k.js (ENTRY POINT)==

export const test_component_p_onHi_MzKNRhr770k = ()=>'hi';


Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\"iDAIS,IAAM\"}")
/*
{
"origin": "test.tsx",
"name": "test_component_p_onHi_MzKNRhr770k",
"entry": null,
"displayName": "test.tsx_test_component_p_onHi",
"hash": "MzKNRhr770k",
"canonicalFilename": "test.tsx_test_component_p_onHi_MzKNRhr770k",
"path": "",
"extension": "js",
"parent": "test_component_LUXeXe0DQrg",
"ctxKind": "eventHandler",
"ctxName": "onHi$",
"captures": false,
"loc": [
111,
121
]
}
*/
============================= test.tsx_test_component_p_onConst_WVa6OMq4yIM.js (ENTRY POINT)==

export const test_component_p_onConst_WVa6OMq4yIM = ()=>'const';


Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\"oDASY,IAAM\"}")
/*
{
"origin": "test.tsx",
"name": "test_component_p_onConst_WVa6OMq4yIM",
"entry": null,
"displayName": "test.tsx_test_component_p_onConst",
"hash": "WVa6OMq4yIM",
"canonicalFilename": "test.tsx_test_component_p_onConst_WVa6OMq4yIM",
"path": "",
"extension": "js",
"parent": "test_component_LUXeXe0DQrg",
"ctxKind": "eventHandler",
"ctxName": "onConst$",
"captures": false,
"loc": [
239,
252
]
}
*/
============================= test.tsx_test_component_LUXeXe0DQrg.js (ENTRY POINT)==

import { _jsxSplit } from "@qwik.dev/core";
import { qrl } from "@qwik.dev/core";
export const test_component_LUXeXe0DQrg = (props)=>{
return /*#__PURE__*/ _jsxSplit("p", {
onHi$: /*#__PURE__*/ qrl(()=>import("./test.tsx_test_component_p_onHi_MzKNRhr770k"), "test_component_p_onHi_MzKNRhr770k"),
...props.foo,
onHello$: props.helloHandler$,
...props.rest,
onVar$: props.onVarHandler$
}, {
onConst$: /*#__PURE__*/ qrl(()=>import("./test.tsx_test_component_p_onConst_WVa6OMq4yIM"), "test_component_p_onConst_WVa6OMq4yIM"),
asd: "1"
}, null, 0, "u6_0");
};


Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\";;0CAE0B,CAAC;IACzB,qBAAQ,UAAC;QACT,KAAK;QACJ,GAAG,MAAM,GAAG;QACb,UAAU,MAAM,aAAa;QAC5B,GAAG,MAAM,IAAI;QACd,QAAQ,MAAM,aAAa;;QAC3B,QAAQ;QACR,KAAK;;AAEP\"}")
/*
{
"origin": "test.tsx",
"name": "test_component_LUXeXe0DQrg",
"entry": null,
"displayName": "test.tsx_test_component",
"hash": "LUXeXe0DQrg",
"canonicalFilename": "test.tsx_test_component_LUXeXe0DQrg",
"path": "",
"extension": "js",
"parent": null,
"ctxKind": "function",
"ctxName": "component$",
"captures": false,
"loc": [
75,
274
]
}
*/
== DIAGNOSTICS ==

[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
source: packages/qwik/src/optimizer/core/src/test.rs
assertion_line: 3877
expression: output
snapshot_kind: text
---
==INPUT==


import { component$, $, useSignal } from '@qwik.dev/core';
export const Cmp = component$(() => {
const toggleSig = useSignal(false);

const handleClick$ = $(() => {
toggleSig.value = !toggleSig.value;
});

return (
<button onClick$={handleClick$} data-open={toggleSig.value ? true : undefined}>
Removing data-open re-renders
</button>
);
});

============================= test.tsx_Cmp_component_handleClick_WawHV3HwS1A.ts (ENTRY POINT)==

import { useLexicalScope } from "@qwik.dev/core";
export const Cmp_component_handleClick_WawHV3HwS1A = ()=>{
const [toggleSig] = useLexicalScope();
toggleSig.value = !toggleSig.value;
};
export { _hW } from "@qwik.dev/core";


Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\";qDAK0B;;IACtB,UAAU,KAAK,GAAG,CAAC,UAAU,KAAK\"}")
/*
{
"origin": "test.tsx",
"name": "Cmp_component_handleClick_WawHV3HwS1A",
"entry": null,
"displayName": "test.tsx_Cmp_component_handleClick",
"hash": "WawHV3HwS1A",
"canonicalFilename": "test.tsx_Cmp_component_handleClick_WawHV3HwS1A",
"path": "",
"extension": "ts",
"parent": "Cmp_component_4ryKJTOKjWE",
"ctxKind": "function",
"ctxName": "$",
"captures": true,
"loc": [
169,
221
]
}
*/
============================= test.tsx_Cmp_component_4ryKJTOKjWE.ts (ENTRY POINT)==

import { _fnSignal } from "@qwik.dev/core";
import { _jsxSorted } from "@qwik.dev/core";
import { qrl } from "@qwik.dev/core";
import { useSignal } from "@qwik.dev/core";
export const Cmp_component_4ryKJTOKjWE = ()=>{
const toggleSig = useSignal(false);
const handleClick$ = /*#__PURE__*/ qrl(()=>import("./test.tsx_Cmp_component_handleClick_WawHV3HwS1A"), "Cmp_component_handleClick_WawHV3HwS1A", [
toggleSig
]);
return /*#__PURE__*/ _jsxSorted("button", null, {
onClick$: handleClick$,
"data-open": _fnSignal((p0)=>p0.value ? true : undefined, [
toggleSig
], "p0.value?true:undefined")
}, "Removing data-open re-renders", 3, "u6_0");
};


Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\";;;;yCAEgC;IAC7B,MAAM,YAAY,UAAU;IAE5B,MAAM;;;IAIN,qBACC,WAAC;QAAO,UAAU;QAAc,WAAS,kBAAE,GAAU,KAAK,GAAG,OAAO;;;OAAW;AAIjF\"}")
/*
{
"origin": "test.tsx",
"name": "Cmp_component_4ryKJTOKjWE",
"entry": null,
"displayName": "test.tsx_Cmp_component",
"hash": "4ryKJTOKjWE",
"canonicalFilename": "test.tsx_Cmp_component_4ryKJTOKjWE",
"path": "",
"extension": "ts",
"parent": null,
"ctxKind": "function",
"ctxName": "component$",
"captures": false,
"loc": [
95,
379
]
}
*/
============================= test.ts ==

import { componentQrl } from "@qwik.dev/core";
import { qrl } from "@qwik.dev/core";
export const Cmp = /*#__PURE__*/ componentQrl(/*#__PURE__*/ qrl(()=>import("./test.tsx_Cmp_component_4ryKJTOKjWE"), "Cmp_component_4ryKJTOKjWE"));


Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\";;AAEE,OAAO,MAAM,oBAAM,iHAYhB\"}")
== DIAGNOSTICS ==

[]
24 changes: 24 additions & 0 deletions packages/qwik/src/optimizer/core/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4269,6 +4269,30 @@ export const Cmp = component$(() => {
..TestInput::default()
});
}

#[test]
fn issue_7216_add_test() {
test_input!(TestInput {
code: r#"
import { component$ } from '@builder.io/qwik';
export default component$((props) => {
return (<p
onHi$={() => 'hi'}
{...props.foo}
onHello$={props.helloHandler$}
{...props.rest}
onVar$={props.onVarHandler$}
onConst$={() => 'const'}
asd={"1"}
/>);
});
"#
.to_string(),
transpile_ts: true,
transpile_jsx: true,
..TestInput::default()
});
}
// TODO(misko): Make this test work by implementing strict serialization.
// #[test]
// fn example_of_synchronous_qrl_that_cant_be_serialized() {
Expand Down
Loading

0 comments on commit 83e76bc

Please sign in to comment.