diff options
Diffstat (limited to 'test/bun.js/solid-dom-fixtures/conditionalExpressions')
3 files changed, 534 insertions, 0 deletions
diff --git a/test/bun.js/solid-dom-fixtures/conditionalExpressions/code.js b/test/bun.js/solid-dom-fixtures/conditionalExpressions/code.js new file mode 100644 index 000000000..80f1a6a4f --- /dev/null +++ b/test/bun.js/solid-dom-fixtures/conditionalExpressions/code.js @@ -0,0 +1,71 @@ +const template1 = <div>{simple}</div>; + +const template2 = <div>{state.dynamic}</div>; + +const template3 = <div>{simple ? good : bad}</div>; + +const template4 = <div>{simple ? good() : bad}</div>; + +const template5 = <div>{state.dynamic ? good() : bad}</div>; + +const template6 = <div>{state.dynamic && good()}</div>; + +const template7 = ( + <div>{state.count > 5 ? (state.dynamic ? best : good()) : bad}</div> +); + +const template8 = <div>{state.dynamic && state.something && good()}</div>; + +const template9 = <div>{(state.dynamic && good()) || bad}</div>; + +const template10 = ( + <div>{state.a ? "a" : state.b ? "b" : state.c ? "c" : "fallback"}</div> +); + +const template11 = ( + <div>{state.a ? a() : state.b ? b() : state.c ? "c" : "fallback"}</div> +); + +const template12 = <Comp render={state.dynamic ? good() : bad} />; + +// no dynamic predicate +const template13 = <Comp render={state.dynamic ? good : bad} />; + +const template14 = <Comp render={state.dynamic && good()} />; + +// no dynamic predicate +const template15 = <Comp render={state.dynamic && good} />; + +const template16 = <Comp render={state.dynamic || good()} />; + +const template17 = <Comp render={state.dynamic ? <Comp /> : <Comp />} />; + +const template18 = <Comp>{state.dynamic ? <Comp /> : <Comp />}</Comp>; + +const template19 = <div innerHTML={state.dynamic ? <Comp /> : <Comp />} />; + +const template20 = <div>{state.dynamic ? <Comp /> : <Comp />}</div>; + +const template21 = <Comp render={state?.dynamic ? "a" : "b"} />; + +const template22 = <Comp>{state?.dynamic ? "a" : "b"}</Comp>; + +const template23 = <div innerHTML={state?.dynamic ? "a" : "b"} />; + +const template24 = <div>{state?.dynamic ? "a" : "b"}</div>; + +const template25 = <Comp render={state.dynamic ?? <Comp />} />; + +const template26 = <Comp>{state.dynamic ?? <Comp />}</Comp>; + +const template27 = <div innerHTML={state.dynamic ?? <Comp />} />; + +const template28 = <div>{state.dynamic ?? <Comp />}</div>; + +const template29 = <div>{(thing() && thing1()) ?? thing2() ?? thing3()}</div>; + +const template30 = <div>{thing() || thing1() || thing2()}</div>; + +const template31 = ( + <Comp value={count() ? (count() ? count() : count()) : count()} /> +); diff --git a/test/bun.js/solid-dom-fixtures/conditionalExpressions/output.bun.js b/test/bun.js/solid-dom-fixtures/conditionalExpressions/output.bun.js new file mode 100644 index 000000000..36c3f649b --- /dev/null +++ b/test/bun.js/solid-dom-fixtures/conditionalExpressions/output.bun.js @@ -0,0 +1,144 @@ +var _tmpl = template("<div</div>", 2), _tmpl$1 = template("<div/>", 0); +const template1 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, simple, null); + return _tmpl; +}; +const template2 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, state.dynamic, null); + return _tmpl; +}; +const template3 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, simple ? good : bad, null); + return _tmpl; +}; +const template4 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, simple ? good() : bad, null); + return _tmpl; +}; +const template5 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, state.dynamic ? good() : bad, null); + return _tmpl; +}; +const template6 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, state.dynamic && good(), null); + return _tmpl; +}; +const template7 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, state.count > 5 ? state.dynamic ? best : good() : bad, null); + return _tmpl; +}; +const template8 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, state.dynamic && state.something && good(), null); + return _tmpl; +}; +const template9 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, state.dynamic && good() || bad, null); + return _tmpl; +}; +const template10 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, state.a ? "a" : state.b ? "b" : state.c ? "c" : "fallback", null); + return _tmpl; +}; +const template11 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, state.a ? a() : state.b ? b() : state.c ? "c" : "fallback", null); + return _tmpl; +}; +const template12 = createComponent(Comp, { + render: state.dynamic ? good() : bad +}); +const template13 = createComponent(Comp, { + render: state.dynamic ? good : bad +}); +const template14 = createComponent(Comp, { + render: state.dynamic && good() +}); +const template15 = createComponent(Comp, { + render: state.dynamic && good +}); +const template16 = createComponent(Comp, { + render: state.dynamic || good() +}); +const template17 = createComponent(Comp, { + render: state.dynamic ? createComponent(Comp, {}) : createComponent(Comp, {}) +}); +const template18 = createComponent(Comp, { + get children: [ + state.dynamic ? createComponent(Comp, {}) : createComponent(Comp, {}) + ] +}); +const template19 = () => { + var _el = _tmpl$1.cloneNode(true); + effect(() => { + return setAttribute(_el, "innerHTML", state.dynamic ? createComponent(Comp, {}) : createComponent(Comp, {})); + }); + return _el; +}; +const template20 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, state.dynamic ? createComponent(Comp, {}) : createComponent(Comp, {}), null); + return _tmpl; +}; +const template21 = createComponent(Comp, { + render: state?.dynamic ? "a" : "b" +}); +const template22 = createComponent(Comp, { + get children: [ + state?.dynamic ? "a" : "b" + ] +}); +const template23 = () => { + var _el = _tmpl$1.cloneNode(true); + effect(() => { + return setAttribute(_el, "innerHTML", state?.dynamic ? "a" : "b"); + }); + return _el; +}; +const template24 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, state?.dynamic ? "a" : "b", null); + return _tmpl; +}; +const template25 = createComponent(Comp, { + render: state.dynamic ?? createComponent(Comp, {}) +}); +const template26 = createComponent(Comp, { + get children: [ + state.dynamic ?? createComponent(Comp, {}) + ] +}); +const template27 = () => { + var _el = _tmpl$1.cloneNode(true); + effect(() => { + return setAttribute(_el, "innerHTML", state.dynamic ?? createComponent(Comp, {})); + }); + return _el; +}; +const template28 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, state.dynamic ?? createComponent(Comp, {}), null); + return _tmpl; +}; +const template29 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, (thing() && thing1()) ?? thing2() ?? thing3(), null); + return _tmpl; +}; +const template30 = () => { + var _tmpl = _tmpl.cloneNode(true); + insert(_tmpl, thing() || thing1() || thing2(), null); + return _tmpl; +}; +const template31 = createComponent(Comp, { + value: count() ? count() ? count() : count() : count() +}); diff --git a/test/bun.js/solid-dom-fixtures/conditionalExpressions/output.js b/test/bun.js/solid-dom-fixtures/conditionalExpressions/output.js new file mode 100644 index 000000000..1511f4222 --- /dev/null +++ b/test/bun.js/solid-dom-fixtures/conditionalExpressions/output.js @@ -0,0 +1,319 @@ +import { template as _$template } from "r-dom"; +import { effect as _$effect } from "r-dom"; +import { createComponent as _$createComponent } from "r-dom"; +import { memo as _$memo } from "r-dom"; +import { insert as _$insert } from "r-dom"; + +const _tmpl$ = /*#__PURE__*/ _$template(`<div></div>`, 2); + +const template1 = (() => { + const _el$ = _tmpl$.cloneNode(true); + + _$insert(_el$, simple); + + return _el$; +})(); + +const template2 = (() => { + const _el$2 = _tmpl$.cloneNode(true); + + _$insert(_el$2, () => state.dynamic); + + return _el$2; +})(); + +const template3 = (() => { + const _el$3 = _tmpl$.cloneNode(true); + + _$insert(_el$3, simple ? good : bad); + + return _el$3; +})(); + +const template4 = (() => { + const _el$4 = _tmpl$.cloneNode(true); + + _$insert(_el$4, () => (simple ? good() : bad)); + + return _el$4; +})(); + +const template5 = (() => { + const _el$5 = _tmpl$.cloneNode(true); + + _$insert( + _el$5, + (() => { + const _c$ = _$memo(() => !!state.dynamic, true); + + return () => (_c$() ? good() : bad); + })() + ); + + return _el$5; +})(); + +const template6 = (() => { + const _el$6 = _tmpl$.cloneNode(true); + + _$insert( + _el$6, + (() => { + const _c$2 = _$memo(() => !!state.dynamic, true); + + return () => _c$2() && good(); + })() + ); + + return _el$6; +})(); + +const template7 = (() => { + const _el$7 = _tmpl$.cloneNode(true); + + _$insert( + _el$7, + (() => { + const _c$3 = _$memo(() => state.count > 5, true); + + return () => + _c$3() + ? (() => { + const _c$4 = _$memo(() => !!state.dynamic, true); + + return () => (_c$4() ? best : good()); + })() + : bad; + })() + ); + + return _el$7; +})(); + +const template8 = (() => { + const _el$8 = _tmpl$.cloneNode(true); + + _$insert( + _el$8, + (() => { + const _c$5 = _$memo(() => !!(state.dynamic && state.something), true); + + return () => _c$5() && good(); + })() + ); + + return _el$8; +})(); + +const template9 = (() => { + const _el$9 = _tmpl$.cloneNode(true); + + _$insert( + _el$9, + (() => { + const _c$6 = _$memo(() => !!state.dynamic, true); + + return () => (_c$6() && good()) || bad; + })() + ); + + return _el$9; +})(); + +const template10 = (() => { + const _el$10 = _tmpl$.cloneNode(true); + + _$insert(_el$10, () => + state.a ? "a" : state.b ? "b" : state.c ? "c" : "fallback" + ); + + return _el$10; +})(); + +const template11 = (() => { + const _el$11 = _tmpl$.cloneNode(true); + + _$insert( + _el$11, + (() => { + const _c$7 = _$memo(() => !!state.a, true); + + return () => + _c$7() + ? a() + : (() => { + const _c$8 = _$memo(() => !!state.b, true); + + return () => (_c$8() ? b() : state.c ? "c" : "fallback"); + })(); + })() + ); + + return _el$11; +})(); + +const template12 = _$createComponent(Comp, { + get render() { + return _$memo(() => !!state.dynamic, true)() ? good() : bad; + }, +}); // no dynamic predicate + +const template13 = _$createComponent(Comp, { + get render() { + return state.dynamic ? good : bad; + }, +}); + +const template14 = _$createComponent(Comp, { + get render() { + return _$memo(() => !!state.dynamic, true)() && good(); + }, +}); // no dynamic predicate + +const template15 = _$createComponent(Comp, { + get render() { + return state.dynamic && good; + }, +}); + +const template16 = _$createComponent(Comp, { + get render() { + return state.dynamic || good(); + }, +}); + +const template17 = _$createComponent(Comp, { + get render() { + return _$memo(() => !!state.dynamic, true)() + ? _$createComponent(Comp, {}) + : _$createComponent(Comp, {}); + }, +}); + +const template18 = _$createComponent(Comp, { + get children() { + return _$memo(() => !!state.dynamic, true)() + ? _$createComponent(Comp, {}) + : _$createComponent(Comp, {}); + }, +}); + +const template19 = (() => { + const _el$12 = _tmpl$.cloneNode(true); + + _$effect( + () => + (_el$12.innerHTML = state.dynamic + ? _$createComponent(Comp, {}) + : _$createComponent(Comp, {})) + ); + + return _el$12; +})(); + +const template20 = (() => { + const _el$13 = _tmpl$.cloneNode(true); + + _$insert( + _el$13, + (() => { + const _c$9 = _$memo(() => !!state.dynamic, true); + + return () => + _c$9() ? _$createComponent(Comp, {}) : _$createComponent(Comp, {}); + })() + ); + + return _el$13; +})(); + +const template21 = _$createComponent(Comp, { + get render() { + return state?.dynamic ? "a" : "b"; + }, +}); + +const template22 = _$createComponent(Comp, { + get children() { + return state?.dynamic ? "a" : "b"; + }, +}); + +const template23 = (() => { + const _el$14 = _tmpl$.cloneNode(true); + + _$effect(() => (_el$14.innerHTML = state?.dynamic ? "a" : "b")); + + return _el$14; +})(); + +const template24 = (() => { + const _el$15 = _tmpl$.cloneNode(true); + + _$insert(_el$15, () => (state?.dynamic ? "a" : "b")); + + return _el$15; +})(); + +const template25 = _$createComponent(Comp, { + get render() { + return state.dynamic ?? _$createComponent(Comp, {}); + }, +}); + +const template26 = _$createComponent(Comp, { + get children() { + return state.dynamic ?? _$createComponent(Comp, {}); + }, +}); + +const template27 = (() => { + const _el$16 = _tmpl$.cloneNode(true); + + _$effect( + () => (_el$16.innerHTML = state.dynamic ?? _$createComponent(Comp, {})) + ); + + return _el$16; +})(); + +const template28 = (() => { + const _el$17 = _tmpl$.cloneNode(true); + + _$insert(_el$17, () => state.dynamic ?? _$createComponent(Comp, {})); + + return _el$17; +})(); + +const template29 = (() => { + const _el$18 = _tmpl$.cloneNode(true); + + _$insert( + _el$18, + (() => { + const _c$10 = _$memo(() => !!thing(), true); + + return () => (_c$10() && thing1()) ?? thing2() ?? thing3(); + })() + ); + + return _el$18; +})(); + +const template30 = (() => { + const _el$19 = _tmpl$.cloneNode(true); + + _$insert(_el$19, () => thing() || thing1() || thing2()); + + return _el$19; +})(); + +const template31 = _$createComponent(Comp, { + get value() { + return _$memo(() => !!count(), true)() + ? _$memo(() => !!count(), true)() + ? count() + : count() + : count(); + }, +}); |