Skip to content

Commit 90ef6ac

Browse files
committed
fix: error at compile time on unsupported TypeScript language features
1 parent 81b32d8 commit 90ef6ac

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

.changeset/perfect-cooks-shop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: error at compile time on unsupported TypeScript language features

packages/svelte/messages/compile-errors/script.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,7 @@
159159
> Cannot reference store value outside a `.svelte` file
160160
161161
Using a `$` prefix to refer to the value of a store is only possible inside `.svelte` files, where Svelte can automatically create subscriptions when a component is mounted and unsubscribe when the component is unmounted. Consider migrating to runes instead.
162+
163+
## typescript_invalid_feature
164+
165+
> TypeScript language feature like %feature% 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

packages/svelte/src/compiler/errors.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,16 @@ export function store_invalid_subscription_module(node) {
434434
e(node, "store_invalid_subscription_module", "Cannot reference store value outside a `.svelte` file");
435435
}
436436

437+
/**
438+
* TypeScript language feature like %feature% 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
439+
* @param {null | number | NodeLike} node
440+
* @param {string} feature
441+
* @returns {never}
442+
*/
443+
export function typescript_invalid_feature(node, feature) {
444+
e(node, "typescript_invalid_feature", `TypeScript language feature like ${feature} 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`);
445+
}
446+
437447
/**
438448
* Declaration cannot be empty
439449
* @param {null | number | NodeLike} node

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import { SvelteWindow } from './visitors/SvelteWindow.js';
6363
import { TaggedTemplateExpression } from './visitors/TaggedTemplateExpression.js';
6464
import { Text } from './visitors/Text.js';
6565
import { TitleElement } from './visitors/TitleElement.js';
66+
import { TSEnumDeclaration } from './visitors/TSEnumDeclaration.js';
6667
import { UpdateExpression } from './visitors/UpdateExpression.js';
6768
import { UseDirective } from './visitors/UseDirective.js';
6869
import { VariableDeclarator } from './visitors/VariableDeclarator.js';
@@ -174,7 +175,10 @@ const visitors = {
174175
TitleElement,
175176
UpdateExpression,
176177
UseDirective,
177-
VariableDeclarator
178+
VariableDeclarator,
179+
180+
// @ts-expect-error
181+
TSEnumDeclaration
178182
};
179183

180184
/**
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/** @import { Context } from '../types' */
2+
import * as e from '../../../errors.js';
3+
4+
/**
5+
* @param {any} node
6+
* @param {Context} context
7+
*/
8+
export function TSEnumDeclaration(node, context) {
9+
e.typescript_invalid_feature(node, 'enums');
10+
}

0 commit comments

Comments
 (0)