pull/9988/head
Rich Harris 3 years ago
parent e55d8d100a
commit 1390466d86

@ -2481,14 +2481,15 @@ export const template_visitors = {
if (!argument) continue; if (!argument) continue;
if (argument.type === 'Identifier') { if (argument.type === 'Identifier') {
args.push(argument); args.push({
type: 'AssignmentPattern',
left: argument,
right: b.id('$.noop')
});
const binding = /** @type {import('#compiler').Binding} */ ( const binding = /** @type {import('#compiler').Binding} */ (
context.state.scope.get(argument.name) context.state.scope.get(argument.name)
); );
// we can't use `b.maybe_call` because it can result in invalid javascript if binding.expression = b.call(argument);
// this expression appears on the left side of an assignment somewhere. For example:
// `$.maybe_call(myArg).value = 1` is valid JavaScript, but `$.myArg?.().value = 1` is not
binding.expression = b.call('$.maybe_call', argument);
continue; continue;
} }
@ -2505,7 +2506,7 @@ export const template_visitors = {
path.node, path.node,
b.thunk( b.thunk(
/** @type {import('estree').Expression} */ ( /** @type {import('estree').Expression} */ (
context.visit(path.expression?.(b.call('$.maybe_call', b.id(arg_alias)))) context.visit(path.expression?.(b.maybe_call(b.id(arg_alias))))
) )
) )
) )

@ -1,6 +1,6 @@
import { DEV } from 'esm-env'; import { DEV } from 'esm-env';
import { subscribe_to_store } from '../../store/utils.js'; import { subscribe_to_store } from '../../store/utils.js';
import { EMPTY_FUNC, run_all } from '../common.js'; import { noop, run_all } from '../common.js';
import { import {
array_prototype, array_prototype,
get_descriptor, get_descriptor,
@ -860,7 +860,7 @@ export function store_get(store, store_name, stores) {
store: null, store: null,
last_value: null, last_value: null,
value: mutable_source(UNINITIALIZED), value: mutable_source(UNINITIALIZED),
unsubscribe: EMPTY_FUNC unsubscribe: noop
}; };
// TODO: can we remove this code? it was refactored out when we split up source/comptued signals // TODO: can we remove this code? it was refactored out when we split up source/comptued signals
// push_destroy_fn(entry.value, () => { // push_destroy_fn(entry.value, () => {
@ -890,7 +890,7 @@ export function store_get(store, store_name, stores) {
function connect_store_to_signal(store, source) { function connect_store_to_signal(store, source) {
if (store == null) { if (store == null) {
set(source, undefined); set(source, undefined);
return EMPTY_FUNC; return noop;
} }
/** @param {V} v */ /** @param {V} v */
@ -2109,18 +2109,6 @@ if (DEV) {
throw_rune_error('$props'); throw_rune_error('$props');
} }
/**
* @template {Function | undefined} T
* @param {T} fn
* @returns {ReturnType<T> | undefined}
*/
export function maybe_call(fn) {
if (fn === undefined) {
return undefined;
}
return fn();
}
/** /**
* Expects a value that was wrapped with `freeze` and makes it frozen. * Expects a value that was wrapped with `freeze` and makes it frozen.
* @template T * @template T

@ -1,5 +1,5 @@
// eslint-disable-next-line @typescript-eslint/no-empty-function // eslint-disable-next-line @typescript-eslint/no-empty-function
export const EMPTY_FUNC = () => {}; export const noop = () => {};
// Adapted from https://github.com/then/is-promise/blob/master/index.js // Adapted from https://github.com/then/is-promise/blob/master/index.js
// Distributed under MIT License https://github.com/then/is-promise/blob/master/LICENSE // Distributed under MIT License https://github.com/then/is-promise/blob/master/LICENSE

@ -38,7 +38,6 @@ export {
user_root_effect, user_root_effect,
inspect, inspect,
unwrap, unwrap,
maybe_call,
freeze freeze
} from './client/runtime.js'; } from './client/runtime.js';
export * from './client/each.js'; export * from './client/each.js';
@ -54,3 +53,4 @@ export {
$window as window, $window as window,
$document as document $document as document
} from './client/operations.js'; } from './client/operations.js';
export { noop } from './common.js';

@ -1,6 +1,6 @@
import * as $ from '../client/runtime.js'; import * as $ from '../client/runtime.js';
import { set_is_ssr } from '../client/runtime.js'; import { set_is_ssr } from '../client/runtime.js';
import { is_promise } from '../common.js'; import { is_promise, noop } from '../common.js';
import { subscribe_to_store } from '../../store/utils.js'; import { subscribe_to_store } from '../../store/utils.js';
import { DOMBooleanAttributes } from '../../constants.js'; import { DOMBooleanAttributes } from '../../constants.js';
@ -523,10 +523,6 @@ export function bind_props(props_parent, props_now) {
} }
} }
function noop() {
// noop
}
/** /**
* @template V * @template V
* @param {Promise<V>} promise * @param {Promise<V>} promise

@ -1,3 +1,4 @@
import { noop } from '../internal/common.js';
import { subscribe_to_store } from './utils.js'; import { subscribe_to_store } from './utils.js';
/** /**
@ -5,10 +6,6 @@ import { subscribe_to_store } from './utils.js';
*/ */
const subscriber_queue = []; const subscriber_queue = [];
/** @returns {void} */
// eslint-disable-next-line @typescript-eslint/no-empty-function
function noop() {}
/** /**
* Creates a `Readable` store that allows reading by subscription. * Creates a `Readable` store that allows reading by subscription.
* *

@ -1,4 +1,4 @@
import { EMPTY_FUNC } from '../internal/common.js'; import { noop } from '../internal/common.js';
/** /**
* @template T * @template T
@ -15,7 +15,7 @@ export function subscribe_to_store(store, run, invalidate) {
// @ts-expect-error // @ts-expect-error
if (invalidate) invalidate(undefined); if (invalidate) invalidate(undefined);
return EMPTY_FUNC; return noop;
} }
// Svelte store takes a private second argument // Svelte store takes a private second argument

Loading…
Cancel
Save