Skip to content

Commit 180b332

Browse files
feat: minor type improvements (#9989)
1 parent c0a357c commit 180b332

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

packages/svelte/src/compiler/index.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getLocator } from 'locate-character';
66
import { walk } from 'zimmerframe';
77
import { validate_component_options, validate_module_options } from './validate-options.js';
88
import { convert } from './legacy.js';
9+
import { CompileError } from './errors.js';
910
export { default as preprocess } from './preprocess/index.js';
1011

1112
/**
@@ -30,12 +31,8 @@ export function compile(source, options) {
3031
const result = transform_component(analysis, source, combined_options);
3132
return result;
3233
} catch (e) {
33-
if (/** @type {any} */ (e).name === 'CompileError') {
34-
handle_compile_error(
35-
/** @type {import('#compiler').CompileError} */ (e),
36-
options.filename,
37-
source
38-
);
34+
if (e instanceof CompileError) {
35+
handle_compile_error(e, options.filename, source);
3936
}
4037

4138
throw e;
@@ -56,12 +53,8 @@ export function compileModule(source, options) {
5653
const analysis = analyze_module(parse_acorn(source, false), validated);
5754
return transform_module(analysis, source, validated);
5855
} catch (e) {
59-
if (/** @type {any} */ (e).name === 'CompileError') {
60-
handle_compile_error(
61-
/** @type {import('#compiler').CompileError} */ (e),
62-
options.filename,
63-
source
64-
);
56+
if (e instanceof CompileError) {
57+
handle_compile_error(e, options.filename, source);
6558
}
6659

6760
throw e;
@@ -106,12 +99,8 @@ export function parse(source, options = {}) {
10699
try {
107100
ast = _parse(source);
108101
} catch (e) {
109-
if (/** @type {any} */ (e).name === 'CompileError') {
110-
handle_compile_error(
111-
/** @type {import('#compiler').CompileError} */ (e),
112-
options.filename,
113-
source
114-
);
102+
if (e instanceof CompileError) {
103+
handle_compile_error(e, options.filename, source);
115104
}
116105

117106
throw e;

packages/svelte/src/compiler/phases/scope.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,5 +712,5 @@ export function get_rune(node, scope) {
712712
const binding = scope.get(n.name);
713713
if (binding !== null) return null; // rune name, but references a variable or store
714714

715-
return /** @type {Runes[number] | null} */ (joined);
715+
return /** @type {typeof Runes[number] | null} */ (joined);
716716
}

0 commit comments

Comments
 (0)