Skip to content

Commit 57e4543

Browse files
committed
only add ignore code in dev
2 parents f85d491 + 4b1b886 commit 57e4543

File tree

12 files changed

+72
-71
lines changed

12 files changed

+72
-71
lines changed

packages/svelte/src/compiler/phases/3-transform/client/transform-client.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { javascript_visitors_runes } from './visitors/javascript-runes.js';
1212
import { javascript_visitors_legacy } from './visitors/javascript-legacy.js';
1313
import { serialize_get_binding } from './utils.js';
1414
import { render_stylesheet } from '../css/index.js';
15-
import { filename } from '../../../state.js';
15+
import { dev, filename } from '../../../state.js';
1616

1717
/**
1818
* This function ensures visitor sets don't accidentally clobber each other
@@ -164,7 +164,7 @@ export function client_component(source, analysis, options) {
164164
store_setup.push(
165165
b.const(
166166
binding.node,
167-
options.dev
167+
dev
168168
? b.thunk(
169169
b.sequence([
170170
b.call('$.validate_store', store_reference, b.literal(name.slice(1))),
@@ -210,7 +210,7 @@ export function client_component(source, analysis, options) {
210210
getter,
211211
b.set(alias ?? name, [b.stmt(b.assignment('=', expression, b.id('$$value')))])
212212
];
213-
} else if (!options.dev) {
213+
} else if (!dev) {
214214
return b.init(alias ?? name, expression);
215215
}
216216
}
@@ -238,7 +238,7 @@ export function client_component(source, analysis, options) {
238238
(binding.kind === 'prop' || binding.kind === 'bindable_prop') && !name.startsWith('$$')
239239
);
240240

241-
if (analysis.runes && options.dev) {
241+
if (dev && analysis.runes) {
242242
const exports = analysis.exports.map(({ name, alias }) => b.literal(alias ?? name));
243243
/** @type {ESTree.Literal[]} */
244244
const bindable = [];
@@ -300,12 +300,12 @@ export function client_component(source, analysis, options) {
300300
)
301301
)
302302
);
303-
} else if (options.dev) {
303+
} else if (dev) {
304304
component_returned_object.push(b.spread(b.call(b.id('$.legacy_api'))));
305305
}
306306

307307
const push_args = [b.id('$$props'), b.literal(analysis.runes)];
308-
if (options.dev) push_args.push(b.id(analysis.name));
308+
if (dev) push_args.push(b.id(analysis.name));
309309

310310
const component_block = b.block([
311311
...store_setup,
@@ -345,10 +345,10 @@ export function client_component(source, analysis, options) {
345345
}
346346

347347
const should_inject_context =
348+
dev ||
348349
analysis.needs_context ||
349350
analysis.reactive_statements.size > 0 ||
350-
component_returned_object.length > 0 ||
351-
options.dev;
351+
component_returned_object.length > 0;
352352

353353
if (should_inject_context) {
354354
component_block.body.unshift(b.stmt(b.call('$.push', ...push_args)));
@@ -462,7 +462,7 @@ export function client_component(source, analysis, options) {
462462
body.push(b.export_default(component));
463463
}
464464

465-
if (options.dev) {
465+
if (dev) {
466466
if (filename) {
467467
// add `App[$.FILENAME] = 'App.svelte'` so that we can print useful messages later
468468
body.unshift(
@@ -498,7 +498,7 @@ export function client_component(source, analysis, options) {
498498
)
499499
)
500500
);
501-
} else if (options.dev) {
501+
} else if (dev) {
502502
component_block.body.unshift(b.stmt(b.call('$.check_target', b.id('new.target'))));
503503
}
504504

packages/svelte/src/compiler/phases/3-transform/client/utils.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
PROPS_IS_RUNES,
1717
PROPS_IS_UPDATED
1818
} from '../../../../constants.js';
19-
import { is_ignored } from '../../../state.js';
19+
import { is_ignored, dev } from '../../../state.js';
2020

2121
/**
2222
* @template {ClientTransformState} State
@@ -213,7 +213,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
213213
assignment.right =
214214
private_state.kind === 'frozen_state'
215215
? b.call('$.freeze', value)
216-
: serialize_proxy_reassignment(value, private_state.id, state);
216+
: serialize_proxy_reassignment(value, private_state.id);
217217
return assignment;
218218
}
219219
}
@@ -226,7 +226,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
226226
should_proxy_or_freeze(value, context.state.scope)
227227
? private_state.kind === 'frozen_state'
228228
? b.call('$.freeze', value)
229-
: serialize_proxy_reassignment(value, private_state.id, state)
229+
: serialize_proxy_reassignment(value, private_state.id)
230230
: value
231231
);
232232
}
@@ -250,7 +250,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
250250
assignment.right =
251251
public_state.kind === 'frozen_state'
252252
? b.call('$.freeze', value)
253-
: serialize_proxy_reassignment(value, public_state.id, state);
253+
: serialize_proxy_reassignment(value, public_state.id);
254254
return assignment;
255255
}
256256
}
@@ -287,7 +287,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
287287
* @returns
288288
*/
289289
function maybe_skip_ownership_validation(serialized) {
290-
if (context.state.options.dev && is_ignored(node, 'ownership_invalid_mutation')) {
290+
if (is_ignored(node, 'ownership_invalid_mutation')) {
291291
return b.call('$.skip_ownership_validation', b.thunk(serialized));
292292
}
293293

@@ -334,7 +334,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
334334
context.state.analysis.runes &&
335335
!options?.skip_proxy_and_freeze &&
336336
should_proxy_or_freeze(value, context.state.scope)
337-
? serialize_proxy_reassignment(value, left_name, state)
337+
? serialize_proxy_reassignment(value, left_name)
338338
: value
339339
);
340340
} else if (binding.kind === 'frozen_state') {
@@ -357,7 +357,7 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
357357
!options?.skip_proxy_and_freeze &&
358358
should_proxy_or_freeze(value, context.state.scope) &&
359359
binding.kind === 'bindable_prop'
360-
? serialize_proxy_reassignment(value, left_name, state)
360+
? serialize_proxy_reassignment(value, left_name)
361361
: value
362362
);
363363
} else {
@@ -462,10 +462,9 @@ export function serialize_set_binding(node, context, fallback, prefix, options)
462462
/**
463463
* @param {Expression} value
464464
* @param {PrivateIdentifier | string} proxy_reference
465-
* @param {ClientTransformState} state
466465
*/
467-
export function serialize_proxy_reassignment(value, proxy_reference, state) {
468-
return state.options.dev
466+
export function serialize_proxy_reassignment(value, proxy_reference) {
467+
return dev
469468
? b.call(
470469
'$.proxy',
471470
value,

packages/svelte/src/compiler/phases/3-transform/client/visitors/global.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export const global_visitors = {
118118
} else {
119119
/** @param {any} serialized */
120120
function maybe_skip_ownership_validation(serialized) {
121-
if (context.state.options.dev && is_ignored(node, 'ownership_invalid_mutation')) {
121+
if (is_ignored(node, 'ownership_invalid_mutation')) {
122122
return b.call('$.skip_ownership_validation', b.thunk(serialized));
123123
}
124124

packages/svelte/src/compiler/phases/3-transform/client/visitors/javascript-runes.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
serialize_proxy_reassignment,
1616
should_proxy_or_freeze
1717
} from '../utils.js';
18+
import { dev } from '../../../../state.js';
1819

1920
/** @type {ComponentVisitors} */
2021
export const javascript_visitors_runes = {
@@ -149,11 +150,7 @@ export const javascript_visitors_runes = {
149150
'set',
150151
definition.key,
151152
[value],
152-
[
153-
b.stmt(
154-
b.call('$.set', member, serialize_proxy_reassignment(value, field.id, state))
155-
)
156-
]
153+
[b.stmt(b.call('$.set', member, serialize_proxy_reassignment(value, field.id)))]
157154
)
158155
);
159156
}
@@ -171,7 +168,7 @@ export const javascript_visitors_runes = {
171168
);
172169
}
173170

174-
if ((field.kind === 'derived' || field.kind === 'derived_call') && state.options.dev) {
171+
if (dev && (field.kind === 'derived' || field.kind === 'derived_call')) {
175172
body.push(
176173
b.method(
177174
'set',
@@ -189,7 +186,7 @@ export const javascript_visitors_runes = {
189186
body.push(/** @type {MethodDefinition} **/ (visit(definition, child_state)));
190187
}
191188

192-
if (state.options.dev && public_state.size > 0) {
189+
if (dev && public_state.size > 0) {
193190
// add an `[$.ADD_OWNER]` method so that a class with state fields can widen ownership
194191
body.push(
195192
b.method(
@@ -251,7 +248,7 @@ export const javascript_visitors_runes = {
251248
/** @type {Expression[]} */
252249
const args = [b.id('$$props'), b.array(seen.map((name) => b.literal(name)))];
253250

254-
if (state.options.dev) {
251+
if (dev) {
255252
// include rest name, so we can provide informative error messages
256253
args.push(b.literal(declarator.id.name));
257254
}
@@ -290,7 +287,7 @@ export const javascript_visitors_runes = {
290287
/** @type {Expression[]} */
291288
const args = [b.id('$$props'), b.array(seen.map((name) => b.literal(name)))];
292289

293-
if (state.options.dev) {
290+
if (dev) {
294291
// include rest name, so we can provide informative error messages
295292
args.push(b.literal(/** @type {Identifier} */ (property.argument).name));
296293
}
@@ -481,7 +478,7 @@ export const javascript_visitors_runes = {
481478
BinaryExpression(node, { state, visit, next }) {
482479
const operator = node.operator;
483480

484-
if (state.options.dev) {
481+
if (dev) {
485482
if (operator === '===' || operator === '!==') {
486483
return b.call(
487484
'$.strict_equals',

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
TRANSITION_OUT
2323
} from '../../../../../constants.js';
2424
import { escape_html } from '../../../../../escaping.js';
25-
import { is_ignored, locator } from '../../../../state.js';
25+
import { dev, is_ignored, locator } from '../../../../state.js';
2626
import {
2727
extract_identifiers,
2828
extract_paths,
@@ -798,8 +798,8 @@ function serialize_inline_component(node, component_name, context, anchor = cont
798798
const expression = /** @type {Expression} */ (context.visit(attribute.expression));
799799

800800
if (
801+
dev &&
801802
expression.type === 'MemberExpression' &&
802-
context.state.options.dev &&
803803
context.state.analysis.runes &&
804804
!is_ignored(node, 'binding_property_non_reactive')
805805
) {
@@ -809,7 +809,7 @@ function serialize_inline_component(node, component_name, context, anchor = cont
809809
if (attribute.name === 'this') {
810810
bind_this = attribute.expression;
811811
} else {
812-
if (context.state.options.dev) {
812+
if (dev) {
813813
binding_initializers.push(
814814
b.stmt(
815815
b.call(
@@ -919,9 +919,7 @@ function serialize_inline_component(node, component_name, context, anchor = cont
919919
push_prop(
920920
b.init(
921921
'children',
922-
context.state.options.dev
923-
? b.call('$.wrap_snippet', b.id(context.state.analysis.name), slot_fn)
924-
: slot_fn
922+
dev ? b.call('$.wrap_snippet', b.id(context.state.analysis.name), slot_fn) : slot_fn
925923
)
926924
);
927925

@@ -993,7 +991,7 @@ function serialize_inline_component(node, component_name, context, anchor = cont
993991
b.block([
994992
...binding_initializers,
995993
b.stmt(
996-
context.state.options.dev
994+
dev
997995
? b.call('$.validate_dynamic_component', b.thunk(prev(b.id('$$anchor'))))
998996
: prev(b.id('$$anchor'))
999997
)
@@ -1721,7 +1719,7 @@ export const template_visitors = {
17211719
*/
17221720
const add_template = (template_name, args) => {
17231721
let call = b.call(get_template_function(namespace, state), ...args);
1724-
if (context.state.options.dev) {
1722+
if (dev) {
17251723
call = b.call(
17261724
'$.add_locations',
17271725
call,
@@ -1863,7 +1861,7 @@ export const template_visitors = {
18631861

18641862
// we need to eagerly evaluate the expression in order to hit any
18651863
// 'Cannot access x before initialization' errors
1866-
if (state.options.dev) {
1864+
if (dev) {
18671865
state.init.push(b.stmt(b.call('$.get', declaration.id)));
18681866
}
18691867
} else {
@@ -1897,7 +1895,7 @@ export const template_visitors = {
18971895

18981896
// we need to eagerly evaluate the expression in order to hit any
18991897
// 'Cannot access x before initialization' errors
1900-
if (state.options.dev) {
1898+
if (dev) {
19011899
state.init.push(b.stmt(b.call('$.get', tmp)));
19021900
}
19031901

@@ -2013,7 +2011,7 @@ export const template_visitors = {
20132011
/** @type {SourceLocation} */
20142012
let location = [-1, -1];
20152013

2016-
if (context.state.options.dev) {
2014+
if (dev) {
20172015
const loc = locator(node.start);
20182016
if (loc) {
20192017
location[0] = loc.line;
@@ -2396,7 +2394,7 @@ export const template_visitors = {
23962394

23972395
const get_tag = b.thunk(/** @type {Expression} */ (context.visit(node.tag)));
23982396

2399-
if (context.state.options.dev && context.state.metadata.namespace !== 'foreign') {
2397+
if (dev && context.state.metadata.namespace !== 'foreign') {
24002398
if (node.fragment.nodes.length > 0) {
24012399
context.state.init.push(b.stmt(b.call('$.validate_void_dynamic_element', get_tag)));
24022400
}
@@ -2421,7 +2419,7 @@ export const template_visitors = {
24212419
).body
24222420
);
24232421

2424-
const location = context.state.options.dev && locator(node.start);
2422+
const location = dev && locator(node.start);
24252423

24262424
context.state.init.push(
24272425
b.stmt(
@@ -2640,7 +2638,7 @@ export const template_visitors = {
26402638

26412639
// we need to eagerly evaluate the expression in order to hit any
26422640
// 'Cannot access x before initialization' errors
2643-
if (context.state.options.dev) {
2641+
if (dev) {
26442642
declarations.push(b.stmt(getter));
26452643
}
26462644

@@ -2667,7 +2665,7 @@ export const template_visitors = {
26672665
declarations.push(b.let(node.index, index));
26682666
}
26692667

2670-
if (context.state.options.dev && (flags & EACH_KEYED) !== 0) {
2668+
if (dev && (flags & EACH_KEYED) !== 0) {
26712669
context.state.init.push(
26722670
b.stmt(b.call('$.validate_each_keys', b.thunk(collection), key_function))
26732671
);
@@ -2860,7 +2858,7 @@ export const template_visitors = {
28602858

28612859
// we need to eagerly evaluate the expression in order to hit any
28622860
// 'Cannot access x before initialization' errors
2863-
if (context.state.options.dev) {
2861+
if (dev) {
28642862
declarations.push(b.stmt(getters[name]));
28652863
}
28662864
}
@@ -2874,7 +2872,7 @@ export const template_visitors = {
28742872
/** @type {Expression} */
28752873
let snippet = b.arrow(args, body);
28762874

2877-
if (context.state.options.dev) {
2875+
if (dev) {
28782876
snippet = b.call('$.wrap_snippet', b.id(context.state.analysis.name), snippet);
28792877
}
28802878

@@ -2934,7 +2932,7 @@ export const template_visitors = {
29342932
type === 'AwaitBlock' ||
29352933
type === 'KeyBlock'
29362934
)) &&
2937-
context.state.options.dev &&
2935+
dev &&
29382936
context.state.analysis.runes &&
29392937
!is_ignored(node, 'binding_property_non_reactive')
29402938
) {

0 commit comments

Comments
 (0)