Skip to content

Commit 76dc597

Browse files
committed
no ?? '' on some expressions
1 parent afae274 commit 76dc597

File tree

1 file changed

+14
-5
lines changed
  • packages/svelte/src/compiler/phases/3-transform/client/visitors/shared

1 file changed

+14
-5
lines changed

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,21 @@ export function build_template_chunk(
130130
value = { ...value, right: b.literal('') };
131131
}
132132
} else if (
133-
state.analysis.props_id &&
134-
value.type === 'Identifier' &&
135-
value.name === state.analysis.props_id.name
133+
// $props.id() is never null/undefined
134+
!(
135+
state.analysis.props_id &&
136+
value.type === 'Identifier' &&
137+
value.name === state.analysis.props_id.name
138+
) &&
139+
// Binary expressions are never null/undefined
140+
value.type !== 'BinaryExpression' &&
141+
// Unary expressions are never null/undefined (except for void/delete)
142+
!(
143+
value.type === 'UnaryExpression' &&
144+
value.operator !== 'void' &&
145+
value.operator !== 'delete'
146+
)
136147
) {
137-
// do nothing ($props.id() is never null/undefined)
138-
} else {
139148
value = b.logical('??', value, b.literal(''));
140149
}
141150

0 commit comments

Comments
 (0)