Skip to content

Commit ea02b0f

Browse files
authored
Merge pull request #7355 from QwikDev/fix-wrap
fix(core): non-wrapped expressions aren't const
2 parents f1fef6f + 63a6512 commit ea02b0f

File tree

4 files changed

+136
-31
lines changed

4 files changed

+136
-31
lines changed
+4-30
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,7 @@
1-
# qwik-core
1+
# Qwik Optimizer
22

3-
## 1. Install rust
3+
See the contributing guide for more install information. If you want to updat the tests, run `pnpm run test.rust.update`. If you want to run a single test with dbg output:
44

5-
https://www.rust-lang.org/tools/install
6-
7-
```
8-
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
9-
```
10-
11-
## 2. Build library
12-
13-
```
14-
make build
15-
```
16-
17-
or
18-
19-
```
20-
cargo build
21-
```
22-
23-
## 3. Run tests
24-
25-
```
26-
make test
27-
```
28-
29-
or
30-
31-
```
32-
cargo test
5+
```shell
6+
cargo test --manifest-path packages/qwik/src/optimizer/core/Cargo.toml PARTIAL_NAME_OF_TEST -- --nocapture
337
```

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ pub fn convert_inlined_fn(
6161

6262
let rendered_expr = render_expr(&expr);
6363
if rendered_expr.len() > 150 {
64-
return (None, is_const);
64+
// It isn't guaranteed const if we don't wrap it
65+
// TODO make this be a wrapped computedsignal?
66+
return (None, false);
6567
}
6668

6769
if scoped_idents.is_empty() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
source: packages/qwik/src/optimizer/core/src/test.rs
3+
assertion_line: 4299
4+
expression: output
5+
snapshot_kind: text
6+
---
7+
==INPUT==
8+
9+
10+
import { component$, useStore } from '@qwik.dev/core';
11+
12+
export default component$(() => {
13+
const panelStore = useStore(() => ({
14+
active: 'Input',
15+
list: PANELS,
16+
}));
17+
18+
return (
19+
<div
20+
stuff={panelStore.active ? 'yes' : 'no'}
21+
class={{
22+
'too-long-to-wrap': true,
23+
'examples-panel-input': panelStore.active === 'Input',
24+
'examples-panel-output': panelStore.active === 'Output',
25+
'examples-panel-console': panelStore.active === 'Console',
26+
}}
27+
/>
28+
);
29+
});
30+
export const PANELS: ActivePanel[] = ['Examples', 'Input', 'Output', 'Console'];
31+
32+
============================= test.js ==
33+
34+
import { componentQrl } from "@qwik.dev/core";
35+
import { qrl } from "@qwik.dev/core";
36+
export default /*#__PURE__*/ componentQrl(/*#__PURE__*/ qrl(()=>import("./test.tsx_test_component_LUXeXe0DQrg"), "test_component_LUXeXe0DQrg"));
37+
export const PANELS = [
38+
'Examples',
39+
'Input',
40+
'Output',
41+
'Console'
42+
];
43+
44+
45+
Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\";;AAGE,6BAAe,mHAiBZ;AACH,OAAO,MAAM,SAAwB;IAAC;IAAY;IAAS;IAAU;CAAU,CAAC\"}")
46+
============================= test.tsx_test_component_LUXeXe0DQrg.js (ENTRY POINT)==
47+
48+
import { PANELS } from "./test";
49+
import { _fnSignal } from "@qwik.dev/core";
50+
import { _jsxSorted } from "@qwik.dev/core";
51+
import { useStore } from "@qwik.dev/core";
52+
export const test_component_LUXeXe0DQrg = ()=>{
53+
const panelStore = useStore(()=>({
54+
active: 'Input',
55+
list: PANELS
56+
}));
57+
return /*#__PURE__*/ _jsxSorted("div", {
58+
class: {
59+
'too-long-to-wrap': true,
60+
'examples-panel-input': panelStore.active === 'Input',
61+
'examples-panel-output': panelStore.active === 'Output',
62+
'examples-panel-console': panelStore.active === 'Console'
63+
}
64+
}, {
65+
stuff: _fnSignal((p0)=>p0.active ? 'yes' : 'no', [
66+
panelStore
67+
], 'p0.active?"yes":"no"')
68+
}, null, 3, "u6_0");
69+
};
70+
71+
72+
Some("{\"version\":3,\"sources\":[\"/user/qwik/src/test.tsx\"],\"names\":[],\"mappings\":\";;;;0CAG4B;IACzB,MAAM,aAAa,SAAS,IAAM,CAAC;YAClC,QAAQ;YACR,MAAM;QACP,CAAC;IAED,qBACC,WAAC;QAEA,OAAO;YACN,oBAAoB;YACpB,wBAAwB,WAAW,MAAM,KAAK;YAC9C,yBAAyB,WAAW,MAAM,KAAK;YAC/C,0BAA0B,WAAW,MAAM,KAAK;QACjD;;QANA,KAAK,kBAAE,GAAW,MAAM,GAAG,QAAQ;;;;AAStC\"}")
73+
/*
74+
{
75+
"origin": "test.tsx",
76+
"name": "test_component_LUXeXe0DQrg",
77+
"entry": null,
78+
"displayName": "test.tsx_test_component",
79+
"hash": "LUXeXe0DQrg",
80+
"canonicalFilename": "test.tsx_test_component_LUXeXe0DQrg",
81+
"path": "",
82+
"extension": "js",
83+
"parent": null,
84+
"ctxKind": "function",
85+
"ctxName": "component$",
86+
"captures": false,
87+
"loc": [
88+
88,
89+
510
90+
]
91+
}
92+
*/
93+
== DIAGNOSTICS ==
94+
95+
[]

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

+34
Original file line numberDiff line numberDiff line change
@@ -4293,6 +4293,40 @@ export default component$((props) => {
42934293
..TestInput::default()
42944294
});
42954295
}
4296+
4297+
#[test]
4298+
fn should_wrap_store_expression() {
4299+
test_input!(TestInput {
4300+
code: r#"
4301+
import { component$, useStore } from '@qwik.dev/core';
4302+
4303+
export default component$(() => {
4304+
const panelStore = useStore(() => ({
4305+
active: 'Input',
4306+
list: PANELS,
4307+
}));
4308+
4309+
return (
4310+
<div
4311+
stuff={panelStore.active ? 'yes' : 'no'}
4312+
class={{
4313+
'too-long-to-wrap': true,
4314+
'examples-panel-input': panelStore.active === 'Input',
4315+
'examples-panel-output': panelStore.active === 'Output',
4316+
'examples-panel-console': panelStore.active === 'Console',
4317+
}}
4318+
/>
4319+
);
4320+
});
4321+
export const PANELS: ActivePanel[] = ['Examples', 'Input', 'Output', 'Console'];
4322+
"#
4323+
.to_string(),
4324+
transpile_ts: true,
4325+
transpile_jsx: true,
4326+
..TestInput::default()
4327+
});
4328+
}
4329+
42964330
// TODO(misko): Make this test work by implementing strict serialization.
42974331
// #[test]
42984332
// fn example_of_synchronous_qrl_that_cant_be_serialized() {

0 commit comments

Comments
 (0)