Skip to content

Commit e695d3d

Browse files
committed
declare keyword
1 parent c1698e6 commit e695d3d

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

packages/svelte/src/compiler/phases/1-parse/remove_typescript_nodes.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,27 @@ const visitors = {
105105
},
106106
FunctionExpression: remove_this_param,
107107
FunctionDeclaration: remove_this_param,
108+
TSDeclareFunction() {
109+
return b.empty;
110+
},
111+
ClassDeclaration(node, context) {
112+
if (node.declare) {
113+
return b.empty;
114+
}
115+
return context.next();
116+
},
117+
VariableDeclaration(node, context) {
118+
if (node.declare) {
119+
return b.empty;
120+
}
121+
return context.next();
122+
},
108123
TSModuleDeclaration(node, context) {
109124
if (!node.body) return b.empty;
110125

111126
// namespaces can contain non-type nodes
112-
const cleaned = context.visit(node.body.body);
113-
if (cleaned.length !== 0) {
127+
const cleaned = /** @type {any[]} */ (node.body.body).map((entry) => context.visit(entry));
128+
if (cleaned.some((entry) => entry !== b.empty)) {
114129
e.typescript_invalid_feature(node, 'namespaces with non-type nodes');
115130
}
116131

packages/svelte/tests/runtime-runes/samples/typescript/main.svelte

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,18 @@
99
}
1010
1111
class Foo {
12-
constructor(public readonly name: string) {}
12+
constructor(readonly name: string) {}
13+
}
14+
15+
declare const declared_const: number;
16+
declare function declared_fn(): void;
17+
declare class declared_class {
18+
foo: number;
19+
}
20+
21+
declare module 'foobar' {}
22+
namespace SomeNamespace {
23+
export type Foo = true
1324
}
1425
1526
export type { Hello };

0 commit comments

Comments
 (0)