Skip to content

Commit 5958b77

Browse files
committed
fix: error at compile time on unsupported TypeScript language features
1 parent 448f216 commit 5958b77

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
@@ -60,6 +60,7 @@ import { SvelteSelf } from './visitors/SvelteSelf.js';
6060
import { TaggedTemplateExpression } from './visitors/TaggedTemplateExpression.js';
6161
import { Text } from './visitors/Text.js';
6262
import { TitleElement } from './visitors/TitleElement.js';
63+
import { TSEnumDeclaration } from './visitors/TSEnumDeclaration.js';
6364
import { UpdateExpression } from './visitors/UpdateExpression.js';
6465
import { UseDirective } from './visitors/UseDirective.js';
6566
import { VariableDeclarator } from './visitors/VariableDeclarator.js';
@@ -168,7 +169,10 @@ const visitors = {
168169
TitleElement,
169170
UpdateExpression,
170171
UseDirective,
171-
VariableDeclarator
172+
VariableDeclarator,
173+
174+
// @ts-expect-error
175+
TSEnumDeclaration
172176
};
173177

174178
/**
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)