-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: omit unnecessary nullish coallescing in template expressions (#1…
…5056) * omit unnecessary nullish coallescing in template expressions * add tests
- Loading branch information
Showing
6 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'svelte': patch | ||
--- | ||
|
||
fix: omit unnecessary nullish coallescing in template expressions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
packages/svelte/tests/snapshot/samples/nullish-coallescence-omittance/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { test } from '../../test'; | ||
|
||
export default test({}); |
34 changes: 34 additions & 0 deletions
34
...te/tests/snapshot/samples/nullish-coallescence-omittance/_expected/client/index.svelte.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'svelte/internal/disclose-version'; | ||
import * as $ from 'svelte/internal/client'; | ||
|
||
var on_click = (_, count) => $.update(count); | ||
var root = $.template(`<h1></h1> <b></b> <button> </button> <h1></h1>`, 1); | ||
|
||
export default function Nullish_coallescence_omittance($$anchor) { | ||
let name = 'world'; | ||
let count = $.state(0); | ||
var fragment = root(); | ||
var h1 = $.first_child(fragment); | ||
|
||
h1.textContent = `Hello, ${name ?? ''}!`; | ||
|
||
var b = $.sibling(h1, 2); | ||
|
||
b.textContent = `${1 ?? 'stuff'}${2 ?? 'more stuff'}${3 ?? 'even more stuff'}`; | ||
|
||
var button = $.sibling(b, 2); | ||
|
||
button.__click = [on_click, count]; | ||
|
||
var text = $.child(button); | ||
|
||
$.reset(button); | ||
|
||
var h1_1 = $.sibling(button, 2); | ||
|
||
h1_1.textContent = `Hello, ${name ?? 'earth' ?? ''}`; | ||
$.template_effect(() => $.set_text(text, `Count is ${$.get(count) ?? ''}`)); | ||
$.append($$anchor, fragment); | ||
} | ||
|
||
$.delegate(['click']); |
8 changes: 8 additions & 0 deletions
8
...te/tests/snapshot/samples/nullish-coallescence-omittance/_expected/server/index.svelte.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import * as $ from 'svelte/internal/server'; | ||
|
||
export default function Nullish_coallescence_omittance($$payload) { | ||
let name = 'world'; | ||
let count = 0; | ||
|
||
$$payload.out += `<h1>Hello, ${$.escape(name)}!</h1> <b>${$.escape(1 ?? 'stuff')}${$.escape(2 ?? 'more stuff')}${$.escape(3 ?? 'even more stuff')}</b> <button>Count is ${$.escape(count)}</button> <h1>Hello, ${$.escape(name ?? 'earth' ?? null)}</h1>`; | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/svelte/tests/snapshot/samples/nullish-coallescence-omittance/index.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<script> | ||
let name = 'world'; | ||
let count = $state(0); | ||
</script> | ||
<h1>Hello, {null}{name}!</h1> | ||
<b>{1 ?? 'stuff'}{2 ?? 'more stuff'}{3 ?? 'even more stuff'}</b> | ||
<button onclick={()=>count++}>Count is {count}</button> | ||
<h1>Hello, {name ?? 'earth' ?? null}</h1> |