Skip to content

fix: error at compile time on unsupported TypeScript language features #12982

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 8 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
tests
  • Loading branch information
dummdidumm committed Sep 3, 2024
commit 255f1ed473875f7b3d2bc49e0ea9b1630a9bd332
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"code": "typescript_invalid_feature",
"message": "TypeScript language features like accessor fields (related TSC proposal is not stage 4 yet) are not natively supported, and their use is generally discouraged. You will need to use a preprocessor to convert it to JavaScript before it gets passed to the Svelte compiler",
"start": {
"line": 3,
"column": 2
},
"end": {
"line": 3,
"column": 17
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script lang="ts">
class Foo {
accessor y = 1;
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"code": "typescript_invalid_feature",
"message": "TypeScript language features like decorators (related TSC proposal is not stage 4 yet) are not natively supported, and their use is generally discouraged. You will need to use a preprocessor to convert it to JavaScript before it gets passed to the Svelte compiler",
"start": {
"line": 2,
"column": 4
},
"end": {
"line": 2,
"column": 10
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<script lang="ts">
@foo()
class Foo {}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"code": "typescript_invalid_feature",
"message": "TypeScript language features like enums are not natively supported, and their use is generally discouraged. You will need to use a preprocessor to convert it to JavaScript before it gets passed to the Svelte compiler",
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 4,
"column": 2
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script lang="ts">
enum Foo {
bar = 1
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"code": "typescript_invalid_feature",
"message": "TypeScript language features like accessibility modifiers on constructor parameters are not natively supported, and their use is generally discouraged. You will need to use a preprocessor to convert it to JavaScript before it gets passed to the Svelte compiler",
"start": {
"line": 3,
"column": 14
},
"end": {
"line": 3,
"column": 31
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script lang="ts">
class Foo {
constructor(private x: number) {}
}
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"code": "typescript_invalid_feature",
"message": "TypeScript language features like namespaces with non-type nodes are not natively supported, and their use is generally discouraged. You will need to use a preprocessor to convert it to JavaScript before it gets passed to the Svelte compiler",
"start": {
"line": 2,
"column": 1
},
"end": {
"line": 4,
"column": 2
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script module lang="ts">
namespace SomeNamespace {
export const foo = true;
}
</script>
18 changes: 14 additions & 4 deletions packages/svelte/tests/validator/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,20 @@ const { test, run } = suite<ValidatorTest>(async (config, cwd) => {
const expected = expected_errors && expected_errors[0];

if (error && expected) {
assert.equal(error.code, expected.code);
assert.equal(error.message, expected.message);
assert.deepEqual({ line: error.start?.line, column: error.start?.column }, expected.start);
assert.deepEqual({ line: error.end?.line, column: error.end?.column }, expected.end);
assert.deepEqual(
{
code: error.code,
message: error.message,
start: { line: error.start?.line, column: error.start?.column },
end: { line: error.end?.line, column: error.end?.column }
},
{
code: expected.code,
message: expected.message,
start: expected.start,
end: expected.end
}
);
} else if (expected) {
throw new Error(`Expected an error: ${expected.message}`);
} else if (error) {
Expand Down