-
Notifications
You must be signed in to change notification settings - Fork 149
Better Typescript transpilation #392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
12c1157
feat: pass source markup to transformers (if provided)
SomaticIT e5a73db
feat: allow typescript to know used variables in template
SomaticIT 8c97341
fix: handle sourcemaps in typescript transformer
SomaticIT 18c3d13
Merge remote-tracking branch 'somaticit/@feature/typescript-imports' …
31f6a50
bump svelte for passing tests, handle empty code/map case
d588307
move new transpilation into a flag for backwards compatibility
81f9aec
lint, make build work
e8f1e07
Adjust failing tests
e6f7b22
docs
2b0ea9e
rename option, more docs
ca73a4e
Remove dynamic imports of source-map and sorcery, make them "real" deps
856a98e
make handling mixed imports the default
78db9eb
adjust docs
d349c64
Ignore possible errors in $$vars$$
dummdidumm cec5391
undo ts-ignore as it's not needed
dummdidumm ee2c11d
fix: handle store subscription in template
e720117
handle store subscription in script
ca66810
handle imports in instance script that are only used in module script
b041847
remove unused code
23c24f6
fix comment regression + add test for it
de8e077
lint
3d561aa
filter out reserved keywords to prevent syntax errors
fe37ccb
cleanup
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: allow typescript to know used variables in template
- inject vars from markup to typescript - do not use importTransform when markup is available - inject component script to context=module script - refactor modules/markup to reuse common functions - test injection behavior
- Loading branch information
commit e5a73db6a5af29bc585f6210467370992ef45bb9
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,109 @@ | ||
<script lang="ts"> | ||
kaisermann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { fly } from "svelte/transition"; | ||
import { flip } from "svelte/animate"; | ||
import Nested from "./Nested.svelte"; | ||
import { hello } from "./script"; | ||
import { AValue, AType } from "./types"; | ||
const ui = { MyNested: Nested }; | ||
const val: AType = "test1"; | ||
const prom: Promise<AType> = Promise.resolve("test2"); | ||
const arr: AType[] = ["test1", "test2"]; | ||
const isTest1 = (v: AType) => v === "test1"; | ||
const obj = { | ||
fn: () => "test", | ||
val: "test1" as const | ||
}; | ||
let inputVal: string; | ||
const action = (node: Element, options: { id: string; }) => { node.id = options.id; }; | ||
const action2 = (node: Element) => { node.classList.add("test"); }; | ||
let nested: Nested; | ||
|
||
let scrollY = 500; | ||
let innerWidth = 500; | ||
|
||
const duration = 200; | ||
function onKeyDown(e: KeyboardEvent): void { | ||
e.preventDefault(); | ||
} | ||
</script> | ||
|
||
<style> | ||
.value { color: #ccc; } | ||
</style> | ||
|
||
<svelte:window on:keydown={onKeyDown} {scrollY} bind:innerWidth /> | ||
<svelte:body on:keydown={onKeyDown} /> | ||
|
||
<svelte:head> | ||
<title>Title: {val}</title> | ||
</svelte:head> | ||
|
||
<div> | ||
<Nested let:var1 let:var2={var3}> | ||
<Nested bind:this={nested} /> | ||
<Nested {...obj} /> | ||
<Nested {...{ var1, var3 }} /> | ||
|
||
<svelte:fragment slot="slot1" let:var4={var5}> | ||
<Nested {...{ var5 }} /> | ||
</svelte:fragment> | ||
|
||
<div slot="slot2" let:var6={var7}> | ||
<Nested {...{ var7 }} /> | ||
</div> | ||
|
||
<div slot="slot3"> | ||
<Nested {...{ val }} /> | ||
</div> | ||
</Nested> | ||
|
||
<svelte:component this={ui.MyNested} {val} on:keydown={onKeyDown} bind:inputVal /> | ||
|
||
<p class:value={!!inputVal}>{hello}</p> | ||
<input bind:value={inputVal} use:action={{ id: val }} use:action2 /> | ||
|
||
{#if AValue && val} | ||
<p class="value" transition:fly={{ duration }}>There is a value: {AValue}</p> | ||
{/if} | ||
|
||
{#if val && isTest1(val) && AValue && true && "test"} | ||
<p class="value">There is a value: {AValue}</p> | ||
{:else if obj.val && obj.fn() && isTest1(obj.val)} | ||
<p class="value">There is a value: {AValue}</p> | ||
{:else} | ||
Else | ||
{/if} | ||
|
||
{#each arr as item (item)} | ||
<p animate:flip={{ duration }}>{item}</p> | ||
{/each} | ||
|
||
{#each arr as item} | ||
<p>{item}</p> | ||
{:else} | ||
<p>No items</p> | ||
{/each} | ||
|
||
{#await prom} | ||
Loading... | ||
{:then value} | ||
<input type={val} {value} on:input={e => inputVal = e.currentTarget.value} /> | ||
{:catch err} | ||
<p>Error: {err}</p> | ||
{/await} | ||
|
||
{#await prom then value} | ||
<p>{value}</p> | ||
{/await} | ||
|
||
{#key val} | ||
<p>Keyed {val}</p> | ||
{/key} | ||
|
||
<slot name="slot0" {inputVal}> | ||
<p>{inputVal}</p> | ||
</slot> | ||
|
||
{@html val} | ||
{@debug val, inputVal} | ||
</div> |
This file contains hidden or 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,10 @@ | ||
<script lang="ts" context="module"> | ||
import { AValue, AType } from "./types"; | ||
</script> | ||
|
||
<script lang="ts"> | ||
const val: AType = "test1"; | ||
const aValue = AValue; | ||
</script> | ||
|
||
{val} {aValue} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.