handle module declarations and namespaces

pull/12982/head
Simon Holthausen 2 years ago
parent 90ef6ac79b
commit 08471dcc90

@ -162,4 +162,4 @@ Using a `$` prefix to refer to the value of a store is only possible inside `.sv
## 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
> TypeScript language features 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

@ -435,13 +435,13 @@ export function store_invalid_subscription_module(node) {
}
/**
* 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
* TypeScript language features 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
* @param {null | number | NodeLike} node
* @param {string} feature
* @returns {never}
*/
export function typescript_invalid_feature(node, feature) {
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`);
e(node, "typescript_invalid_feature", `TypeScript language features 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`);
}
/**

@ -89,7 +89,13 @@ const visitors = {
return node;
},
FunctionExpression: remove_this_param,
FunctionDeclaration: remove_this_param
FunctionDeclaration: remove_this_param,
TSModuleDeclaration(node, context) {
if (!node.body) return b.empty;
// namespaces can contain non-type nodes
const cleaned = context.visit(node.body.body);
if (cleaned.length === 0) return b.empty;
}
};
/**

@ -0,0 +1,10 @@
/** @import { Context } from '../types' */
import * as e from '../../../errors.js';
/**
* @param {any} node
* @param {Context} context
*/
export function TSModuleDeclaration(node, context) {
e.typescript_invalid_feature(node, 'namespaces with non-type nodes');
}
Loading…
Cancel
Save