Skip to content

Commit 0a81092

Browse files
authored
(fix) regression with boolean literal props type inference (#1390)
* (fix) regression with boolean props type inference Revert changes with it. Misread the condition. * lint * v2 expected
1 parent ec51f91 commit 0a81092

File tree

7 files changed

+25
-7
lines changed

7 files changed

+25
-7
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<script lang="ts">
2+
export let flag = false;
3+
</script>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script lang="ts">
2+
import Component from './Component.svelte'
3+
</script>
4+
5+
<Component flag />

packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,15 @@ export class ExportedNames {
111111
const jsDocType = ts.getJSDocType(declaration);
112112
const type = tsType || jsDocType;
113113

114-
if (!ts.isIdentifier(identifier) || !type) {
114+
if (
115+
!ts.isIdentifier(identifier) ||
116+
(!type &&
117+
// Edge case: TS infers `export let bla = false` to type `false`.
118+
// prevent that by adding the any-wrap in this case, too.
119+
![ts.SyntaxKind.FalseKeyword, ts.SyntaxKind.TrueKeyword].includes(
120+
declaration.initializer?.kind
121+
))
122+
) {
115123
return;
116124
}
117125
const name = identifier.getText();

packages/svelte2tsx/test/svelte2tsx/samples/ts-export-boolean/expected.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
///<reference types="svelte" />
22
<></>;function render() {
33

4-
let bla = false;
5-
let blubb = true;
4+
let bla = false/*Ωignore_startΩ*/;bla = __sveltets_1_any(bla);/*Ωignore_endΩ*/;
5+
let blubb = true/*Ωignore_startΩ*/;blubb = __sveltets_1_any(blubb);/*Ωignore_endΩ*/;
66
let bla1: boolean = false/*Ωignore_startΩ*/;bla1 = __sveltets_1_any(bla1);/*Ωignore_endΩ*/;
77
let blubb1: boolean = true/*Ωignore_startΩ*/;blubb1 = __sveltets_1_any(blubb1);/*Ωignore_endΩ*/;
8-
let a1 = true;let a2 = false;let b1: boolean = true/*Ωignore_startΩ*/;b1 = __sveltets_1_any(b1);/*Ωignore_endΩ*/;let b2: boolean = false/*Ωignore_startΩ*/;b2 = __sveltets_1_any(b2);/*Ωignore_endΩ*/;
8+
let a1 = true/*Ωignore_startΩ*/;a1 = __sveltets_1_any(a1);/*Ωignore_endΩ*/;let a2 = false/*Ωignore_startΩ*/;a2 = __sveltets_1_any(a2);/*Ωignore_endΩ*/;let b1: boolean = true/*Ωignore_startΩ*/;b1 = __sveltets_1_any(b1);/*Ωignore_endΩ*/;let b2: boolean = false/*Ωignore_startΩ*/;b2 = __sveltets_1_any(b2);/*Ωignore_endΩ*/;
99
;
1010
() => (<></>);
1111
return { props: {bla: bla , blubb: blubb , bla1: bla1 , blubb1: blubb1 , a1: a1 , a2: a2 , b1: b1 , b2: b2} as {bla?: typeof bla, blubb?: typeof blubb, bla1?: boolean, blubb1?: boolean, a1?: typeof a1, a2?: typeof a2, b1?: boolean, b2?: boolean}, slots: {}, getters: {}, events: {} }}

packages/svelte2tsx/test/svelte2tsx/samples/ts-export-boolean/expectedv2.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
///<reference types="svelte" />
22
;function render() {
33

4-
let bla = false;
5-
let blubb = true;
4+
let bla = false/*Ωignore_startΩ*/;bla = __sveltets_1_any(bla);/*Ωignore_endΩ*/;
5+
let blubb = true/*Ωignore_startΩ*/;blubb = __sveltets_1_any(blubb);/*Ωignore_endΩ*/;
66
let bla1: boolean = false/*Ωignore_startΩ*/;bla1 = __sveltets_1_any(bla1);/*Ωignore_endΩ*/;
77
let blubb1: boolean = true/*Ωignore_startΩ*/;blubb1 = __sveltets_1_any(blubb1);/*Ωignore_endΩ*/;
8-
let a1 = true;let a2 = false;let b1: boolean = true/*Ωignore_startΩ*/;b1 = __sveltets_1_any(b1);/*Ωignore_endΩ*/;let b2: boolean = false/*Ωignore_startΩ*/;b2 = __sveltets_1_any(b2);/*Ωignore_endΩ*/;
8+
let a1 = true/*Ωignore_startΩ*/;a1 = __sveltets_1_any(a1);/*Ωignore_endΩ*/;let a2 = false/*Ωignore_startΩ*/;a2 = __sveltets_1_any(a2);/*Ωignore_endΩ*/;let b1: boolean = true/*Ωignore_startΩ*/;b1 = __sveltets_1_any(b1);/*Ωignore_endΩ*/;let b2: boolean = false/*Ωignore_startΩ*/;b2 = __sveltets_1_any(b2);/*Ωignore_endΩ*/;
99
;
1010
async () => {};
1111
return { props: {bla: bla , blubb: blubb , bla1: bla1 , blubb1: blubb1 , a1: a1 , a2: a2 , b1: b1 , b2: b2} as {bla?: typeof bla, blubb?: typeof blubb, bla1?: boolean, blubb1?: boolean, a1?: typeof a1, a2?: typeof a2, b1?: boolean, b2?: boolean}, slots: {}, getters: {}, events: {} }}

0 commit comments

Comments
 (0)