Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script lang="ts">
import Component from './untyped-ts.svelte'
</script>

<Component typedAsAny={undefined} untyped={undefined} />
<Component typedAsAny={null} untyped={null} />
<Component typedAsAny={true} untyped={true} />
<Component typedAsAny={123} untyped={123} />
<Component typedAsAny='string' untyped='string' />
<Component typedAsAny={{some: 'object'}} untyped={{some: 'object'}} />
<Component typedAsAny={['string', 'array']} untyped={['string', 'array']} />
<Component typedAsAny={['array', 123, false]} untyped={['array', 123, false]} />
<Component typedAsAny={['array', 123, false]} untyped={['array', 123, false]} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script lang="ts">
export let untyped;
export let typedAsAny: any;
</script>
32 changes: 18 additions & 14 deletions packages/svelte2tsx/src/svelte2tsx/nodes/ExportedNames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,28 @@ export class ExportedNames {
const type = tsType || jsDocType;

if (
!ts.isIdentifier(identifier) ||
(!type &&
ts.isIdentifier(identifier) &&
// Ensure initialization for proper control flow and to avoid "possibly undefined" type errors.
// Also ensure prop is typed as any with a type annotation in TS strict mode
(!declaration.initializer ||
// Widen the type, else it's narrowed to the initializer
type ||
// Edge case: TS infers `export let bla = false` to type `false`.
// prevent that by adding the any-wrap in this case, too.
![ts.SyntaxKind.FalseKeyword, ts.SyntaxKind.TrueKeyword].includes(
declaration.initializer?.kind
))
(!type &&
[ts.SyntaxKind.FalseKeyword, ts.SyntaxKind.TrueKeyword].includes(
declaration.initializer.kind
)))
) {
return;
const name = identifier.getText();
const end = declaration.end + this.astOffset;

preprendStr(
this.str,
end,
surroundWithIgnoreComments(`;${name} = __sveltets_1_any(${name});`)
);
}
const name = identifier.getText();
const end = declaration.end + this.astOffset;

preprendStr(
this.str,
end,
surroundWithIgnoreComments(`;${name} = __sveltets_1_any(${name});`)
);
};

const findComma = (target: ts.Node) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,17 @@ s
------------------------------------------------------------------------------------------------------------------------------------------------------ */}
{/**
------------------------------------------------------------------------------------------------------------------------------------------------------ */}
let slug; {/**
╚•let•slug;↲ [generated] line 35
let slug/*Ωignore_startΩ*/;slug = __sveltets_1_any(slug);/*Ωignore_endΩ*/; {/**
╚•let•slug/*Ωignore_startΩ*/;slug•=•__sveltets_1_any(slug);/*Ωignore_endΩ*/;↲ [generated] line 35
╚•let•slug; ↲
╚ •let•slug;↲
╚export•let•slug;↲ [original] line 29
╚export•let•slug;↲ [original] line 29
------------------------------------------------------------------------------------------------------------------------------------------------------ */}
let chapter; {/**
╚•let•chapter;↲ [generated] line 36
let chapter/*Ωignore_startΩ*/;chapter = __sveltets_1_any(chapter);/*Ωignore_endΩ*/; {/**
╚•let•chapter/*Ωignore_startΩ*/;chapter•=•__sveltets_1_any(chapter);/*Ωignore_endΩ*/;↲ [generated] line 36
╚•let•chapter; ↲
╚ •let•chapter;↲
╚export•let•chapter;↲ [original] line 30
╚export•let•chapter;↲ [original] line 30
------------------------------------------------------------------------------------------------------------------------------------------------------ */}

const { sections } = getContext('tutorial');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<script>↲ [original] line 1 (rest generated at line 2)
------------------------------------------------------------------------------------------------------------------------------------------------------ */}
let prop/*Ωignore_startΩ*/;let $prop = __sveltets_1_store_get(prop);/*Ωignore_endΩ*/ {/**
╚•let•prop/*Ωignore_startΩ*/;let•$prop•=•__sveltets_1_store_get(prop);/*Ωignore_endΩ*/↲ [generated] line 4
╚•let•prop ↲
╚ •let•prop↲
╚export•let•prop↲ [original] line 2
------------------------------------------------------------------------------------------------------------------------------------------------------ */}
let prop/*Ωignore_startΩ*/;let $prop = __sveltets_1_store_get(prop);/*Ωignore_endΩ*//*Ωignore_startΩ*/;prop = __sveltets_1_any(prop);/*Ωignore_endΩ*/
╚•let•prop/*Ωignore_startΩ*/;let•$prop•=•__sveltets_1_store_get(prop);/*Ωignore_endΩ*//*Ωignore_startΩ*/;prop•=•__sveltets_1_any(prop);/*Ωignore_endΩ*/↲ [generated] line 4
╚•let•prop ↲
╚ •let•prop↲
╚export•let•prop↲ [original] line 2
//----------------------------------------------------------------------------------------------------------------------------------------------------
let foo = __sveltets_1_invalidate(() => prop); {/**
╚let••foo•=•__sveltets_1_invalidate(()•=>•prop);↲ [generated] line 5
╚ •foo•=• prop; ↲
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
/**
* DOCS!
*/
let a;
let a/*Ωignore_startΩ*/;a = __sveltets_1_any(a);/*Ωignore_endΩ*/;
/**
* not this
*/
/**
* MORE DOCS!
*/
let b;
let c;
let b/*Ωignore_startΩ*/;b = __sveltets_1_any(b);/*Ωignore_endΩ*/;
let c/*Ωignore_startΩ*/;c = __sveltets_1_any(c);/*Ωignore_endΩ*/;
/**
* d
*/
let d;let
let d/*Ωignore_startΩ*/;d = __sveltets_1_any(d);/*Ωignore_endΩ*/;let
/**
* e
*/
e;
e/*Ωignore_startΩ*/;e = __sveltets_1_any(e);/*Ωignore_endΩ*/;
;
() => (<></>);
return { props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@
/**
* DOCS!
*/
let a;
let a/*Ωignore_startΩ*/;a = __sveltets_1_any(a);/*Ωignore_endΩ*/;
/**
* not this
*/
/**
* MORE DOCS!
*/
let b;
let c;
let b/*Ωignore_startΩ*/;b = __sveltets_1_any(b);/*Ωignore_endΩ*/;
let c/*Ωignore_startΩ*/;c = __sveltets_1_any(c);/*Ωignore_endΩ*/;
/**
* d
*/
let d;let
let d/*Ωignore_startΩ*/;d = __sveltets_1_any(d);/*Ωignore_endΩ*/;let
/**
* e
*/
e;
e/*Ωignore_startΩ*/;e = __sveltets_1_any(e);/*Ωignore_endΩ*/;
;
async () => {};
return { props: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
///<reference types="svelte" />
<></>;function render() {

let a;
let b;
let a/*Ωignore_startΩ*/;a = __sveltets_1_any(a);/*Ωignore_endΩ*/;
let b/*Ωignore_startΩ*/;b = __sveltets_1_any(b);/*Ωignore_endΩ*/;
let c = 123;
;
() => (<></>);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
///<reference types="svelte" />
;function render() {

let a;
let b;
let a/*Ωignore_startΩ*/;a = __sveltets_1_any(a);/*Ωignore_endΩ*/;
let b/*Ωignore_startΩ*/;b = __sveltets_1_any(b);/*Ωignore_endΩ*/;
let c = 123;
;
async () => {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<></>;function render() {

let name1 = "world"
let name2
let name2/*Ωignore_startΩ*/;name2 = __sveltets_1_any(name2);/*Ωignore_endΩ*/

let rename1 = '';
let rename2;
let rename2/*Ωignore_startΩ*/;rename2 = __sveltets_1_any(rename2);/*Ωignore_endΩ*/;

class Foo {}
function bar() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
;function render() {

let name1 = "world"
let name2
let name2/*Ωignore_startΩ*/;name2 = __sveltets_1_any(name2);/*Ωignore_endΩ*/

let rename1 = '';
let rename2;
let rename2/*Ωignore_startΩ*/;rename2 = __sveltets_1_any(rename2);/*Ωignore_endΩ*/;

class Foo {}
function bar() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* DOCS!
* @typedef {'ABC'} ABC
*/
let a;
let a/*Ωignore_startΩ*/;a = __sveltets_1_any(a);/*Ωignore_endΩ*/;
;
() => (<></>);
return { props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* DOCS!
* @typedef {'ABC'} ABC
*/
let a;
let a/*Ωignore_startΩ*/;a = __sveltets_1_any(a);/*Ωignore_endΩ*/;
;
async () => {};
return { props: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* MORE DOCS!
*/
let b = 1;
let c;
let c/*Ωignore_startΩ*/;c = __sveltets_1_any(c);/*Ωignore_endΩ*/;

// not this one
let d;
let d/*Ωignore_startΩ*/;d = __sveltets_1_any(d);/*Ωignore_endΩ*/;
;
() => (<></>);
return { props: {a: a , b: b , c: c , d: d} as {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* MORE DOCS!
*/
let b = 1;
let c;
let c/*Ωignore_startΩ*/;c = __sveltets_1_any(c);/*Ωignore_endΩ*/;

// not this one
let d;
let d/*Ωignore_startΩ*/;d = __sveltets_1_any(d);/*Ωignore_endΩ*/;
;
async () => {};
return { props: {a: a , b: b , c: c , d: d} as {
Expand Down