Skip to content

Commit

Permalink
simpler still - no function call necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jun 7, 2024
1 parent 01bf904 commit 2971e00
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ function serialize_template_literal(values, visit, state) {
);
expressions.push(b.call('$.get', id));
} else {
expressions.push(b.call('$.normalize', visit(node.expression, state)));
expressions.push(b.logical('??', visit(node.expression, state), b.literal('')));
}
quasis.push(b.quasi('', i + 1 === values.length));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { DEV } from 'esm-env';
import { render_effect, effect, teardown } from '../../../reactivity/effects.js';
import { normalize } from '../../../render.js';
import { listen_to_event_and_reset_event } from './shared.js';
import * as e from '../../../errors.js';
import { get_proxied_value, is } from '../../../proxy.js';
Expand Down Expand Up @@ -44,7 +43,7 @@ export function bind_value(input, get_value, update) {
}

// @ts-expect-error the value is coerced on assignment
input.value = normalize(value);
input.value = value ?? '';
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export {
update_pre_store,
update_store
} from './reactivity/store.js';
export { append_styles, sanitize_slots, set_text, slot, normalize } from './render.js';
export { append_styles, sanitize_slots, set_text, slot } from './render.js';
export {
get,
invalidate_inner_signals,
Expand Down
9 changes: 0 additions & 9 deletions packages/svelte/src/internal/client/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ export function slot(anchor, slot_fn, slot_props, fallback_fn) {
}
}

/**
* Replaces `null` or `undefined` with an empty string, but otherwise does
* no coercion since it will happen automatically in all the places it's used
* @param {unknown} value
*/
export function normalize(value) {
return value ?? '';
}

/**
* Mounts a component to the given target and returns the exports and potentially the props (if compiled with `accessors: true`) of the component
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ export default function Bind_component_snippet($$anchor) {

var text = $.sibling(node, true);

$.template_effect(() => $.set_text(text, ` value: ${$.normalize($.get(value))}`));
$.template_effect(() => $.set_text(text, ` value: ${$.get(value) ?? ""}`));
$.append($$anchor, fragment_1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function Each_string_template($$anchor) {
$.each(node, 1, () => ['foo', 'bar', 'baz'], $.index, ($$anchor, thing, $$index) => {
var text = $.text($$anchor);

$.template_effect(() => $.set_text(text, `${$.normalize($.unwrap(thing))}, `));
$.template_effect(() => $.set_text(text, `${$.unwrap(thing) ?? ""}, `));
$.append($$anchor, text);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function Function_prop_no_getter($$anchor) {
children: ($$anchor, $$slotProps) => {
var text = $.text($$anchor);

$.template_effect(() => $.set_text(text, `clicks: ${$.normalize($.get(count))}`));
$.template_effect(() => $.set_text(text, `clicks: ${$.get(count) ?? ""}`));
$.append($$anchor, text);
},
$$slots: { default: true }
Expand Down

0 comments on commit 2971e00

Please sign in to comment.