-
-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) support new const tag (#1072)
- Loading branch information
Showing
32 changed files
with
717 additions
and
56 deletions.
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
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
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
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
120 changes: 120 additions & 0 deletions
120
...uage-server/test/plugins/typescript/features/diagnostics/fixtures/const-tag/expected.json
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,120 @@ | ||
[ | ||
{ | ||
"range": { | ||
"start": { "line": 28, "character": 21 }, | ||
"end": { "line": 28, "character": 27 } | ||
}, | ||
"severity": 4, | ||
"source": "ts", | ||
"message": "'result' is declared but its value is never read.", | ||
"code": 6133, | ||
"tags": [1] | ||
}, | ||
{ | ||
"range": { | ||
"start": { "line": 29, "character": 12 }, | ||
"end": { "line": 29, "character": 18 } | ||
}, | ||
"severity": 4, | ||
"source": "ts", | ||
"message": "'unused' is declared but its value is never read.", | ||
"code": 6133, | ||
"tags": [1] | ||
}, | ||
{ | ||
"range": { "start": { "line": 32, "character": 8 }, "end": { "line": 32, "character": 9 } }, | ||
"severity": 4, | ||
"source": "ts", | ||
"message": "'e' is declared but its value is never read.", | ||
"code": 6133, | ||
"tags": [1] | ||
}, | ||
{ | ||
"range": { | ||
"start": { "line": 33, "character": 12 }, | ||
"end": { "line": 33, "character": 18 } | ||
}, | ||
"severity": 4, | ||
"source": "ts", | ||
"message": "'unused' is declared but its value is never read.", | ||
"code": 6133, | ||
"tags": [1] | ||
}, | ||
{ | ||
"range": { | ||
"start": { "line": 39, "character": 12 }, | ||
"end": { "line": 39, "character": 18 } | ||
}, | ||
"severity": 4, | ||
"source": "ts", | ||
"message": "'unused' is declared but its value is never read.", | ||
"code": 6133, | ||
"tags": [1] | ||
}, | ||
{ | ||
"range": { | ||
"start": { "line": 29, "character": 21 }, | ||
"end": { "line": 29, "character": 32 } | ||
}, | ||
"severity": 1, | ||
"source": "ts", | ||
"message": "Cannot find name 'doesntExist'.", | ||
"code": 2304, | ||
"tags": [] | ||
}, | ||
{ | ||
"range": { | ||
"start": { "line": 31, "character": 5 }, | ||
"end": { "line": 31, "character": 17 } | ||
}, | ||
"severity": 1, | ||
"source": "ts", | ||
"message": "This condition will always return 'false' since the types 'string' and 'boolean' have no overlap.", | ||
"code": 2367, | ||
"tags": [] | ||
}, | ||
{ | ||
"range": { | ||
"start": { "line": 33, "character": 21 }, | ||
"end": { "line": 33, "character": 32 } | ||
}, | ||
"severity": 1, | ||
"source": "ts", | ||
"message": "Cannot find name 'doesntExist'.", | ||
"code": 2304, | ||
"tags": [] | ||
}, | ||
{ | ||
"range": { | ||
"start": { "line": 35, "character": 5 }, | ||
"end": { "line": 35, "character": 17 } | ||
}, | ||
"severity": 1, | ||
"source": "ts", | ||
"message": "This condition will always return 'false' since the types 'string' and 'boolean' have no overlap.", | ||
"code": 2367, | ||
"tags": [] | ||
}, | ||
{ | ||
"range": { | ||
"start": { "line": 39, "character": 21 }, | ||
"end": { "line": 39, "character": 32 } | ||
}, | ||
"severity": 1, | ||
"source": "ts", | ||
"message": "Cannot find name 'doesntExist'.", | ||
"code": 2304, | ||
"tags": [] | ||
}, | ||
{ | ||
"range": { | ||
"start": { "line": 41, "character": 5 }, | ||
"end": { "line": 41, "character": 16 } | ||
}, | ||
"severity": 1, | ||
"source": "ts", | ||
"message": "This condition will always return 'false' since the types 'number' and 'string' have no overlap.", | ||
"code": 2367, | ||
"tags": [] | ||
} | ||
] |
43 changes: 43 additions & 0 deletions
43
...guage-server/test/plugins/typescript/features/diagnostics/fixtures/const-tag/input.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,43 @@ | ||
<script lang="ts"> | ||
const promise = Promise.resolve({foo: true}); | ||
const shadowed = true; | ||
shadowed; | ||
</script> | ||
|
||
<!-- valid --> | ||
{#await promise then result} | ||
{@const bar = result} | ||
{@const str = "hello"} | ||
{@const shadowed = "shadowed"} | ||
{bar === result} | ||
{str === "hello"} | ||
{shadowed === "shadowed"} | ||
{:catch e} | ||
{@const bar = e} | ||
{@const str = "hello"} | ||
{bar} | ||
{str === "hello"} | ||
{/await} | ||
|
||
{#each [1, 2] as item} | ||
{@const x = item * 2} | ||
{@const shadowed = item * 3} | ||
{x === shadowed} | ||
{/each} | ||
|
||
<!-- invalid --> | ||
{#await promise then result} | ||
{@const unused = doesntExist} | ||
{@const str = "hello"} | ||
{str === true} | ||
{:catch e} | ||
{@const unused = doesntExist} | ||
{@const str = "hello"} | ||
{str === true} | ||
{/await} | ||
|
||
{#each [1, 2] as item} | ||
{@const unused = doesntExist} | ||
{@const x = item * 2} | ||
{x === "asd"} | ||
{/each} |
File renamed without changes.
File renamed without changes.
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
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
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
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,25 @@ | ||
import MagicString from 'magic-string'; | ||
import { BaseNode, ConstTag } from '../../interfaces'; | ||
|
||
export function extractConstTags(children: BaseNode[]) { | ||
const tags: Array<(insertionPoint: number, str: MagicString) => void> = []; | ||
for (const child of children) { | ||
if (child.type === 'ConstTag') { | ||
const constTag = child as ConstTag; | ||
|
||
tags.push((insertionPoint: number, str: MagicString) => { | ||
str.appendRight(constTag.expression.left.start, 'const '); | ||
str.move( | ||
constTag.expression.left.start, | ||
constTag.expression.right.end, | ||
insertionPoint | ||
); | ||
str.appendLeft(constTag.expression.right.end, ';'); | ||
str.overwrite(constTag.start + 1, constTag.expression.left.start - 1, '', { | ||
contentOnly: true | ||
}); | ||
}); | ||
} | ||
} | ||
return tags; | ||
} |
Oops, something went wrong.