Skip to content

Commit 263610d

Browse files
committed
fix lint
1 parent a4b5d50 commit 263610d

File tree

7 files changed

+47
-71
lines changed

7 files changed

+47
-71
lines changed

packages/svelte/scripts/process-messages/templates/compile-errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function e(node, code, message) {
2828
throw new InternalCompileError(
2929
code,
3030
message,
31-
start !== undefined && end !== undefined ? [start, end] : undefined
31+
start !== undefined ? [start, end ?? start] : undefined
3232
);
3333
}
3434

packages/svelte/scripts/process-messages/templates/compile-warnings.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ function w(node, code, message) {
2929
if (stack && stack.at(-1)?.has(code)) return;
3030

3131
warnings.push(
32-
new InternalCompileWarning(code, message, node ? [node.start, node.end] : undefined)
32+
new InternalCompileWarning(
33+
code,
34+
message,
35+
node && node.start !== undefined ? [node.start, node.end ?? node.start] : undefined
36+
)
3337
);
3438
}
3539

packages/svelte/src/compiler/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function e(node, code, message) {
2626
const start = typeof node === 'number' ? node : node?.start;
2727
const end = typeof node === 'number' ? node : node?.end;
2828

29-
throw new InternalCompileError(code, message, start !== undefined && end !== undefined ? [start, end] : undefined);
29+
throw new InternalCompileError(code, message, start !== undefined ? [start, end ?? start] : undefined);
3030
}
3131

3232
/**

packages/svelte/src/compiler/types/index.d.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import type { Context } from 'zimmerframe';
1111
import type { Scope } from '../phases/scope.js';
1212
import type { Css } from './css.js';
1313
import type { EachBlock, Namespace, SvelteNode, SvelteOptions } from './template.js';
14-
import type { InternalCompileError } from '../errors.js';
15-
import type { InternalCompileWarning } from '../warnings.js';
14+
import type { ICompileDiagnostic } from '../utils/compile_diagnostic.js';
1615

1716
/** The return value of `compile` from `svelte/compiler` */
1817
export interface CompileResult {
@@ -51,9 +50,9 @@ export interface CompileResult {
5150
ast: any;
5251
}
5352

54-
export interface Warning extends InternalCompileWarning {}
53+
export interface Warning extends ICompileDiagnostic {}
5554

56-
export interface CompileError extends InternalCompileError {}
55+
export interface CompileError extends ICompileDiagnostic {}
5756

5857
export type CssHashGetter = (args: {
5958
name: string;

packages/svelte/src/compiler/utils/compile_diagnostic.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,20 @@ function get_code_frame(source, line, column) {
3535
.join('\n');
3636
}
3737

38+
/**
39+
* @typedef {{
40+
* code: string;
41+
* message: string;
42+
* filename?: string;
43+
* start?: Location;
44+
* end?: Location;
45+
* position?: [number, number];
46+
* frame?: string;
47+
* }} ICompileDiagnostic */
48+
49+
/** @implements {ICompileDiagnostic} */
3850
export class CompileDiagnostic extends Error {
3951
name = 'CompileDiagnostic';
40-
filename = state.filename;
41-
/** @type {[number, number] | undefined} */
42-
position = undefined;
43-
/** @type {Location | undefined} */
44-
start = undefined;
45-
/** @type {Location | undefined} */
46-
end = undefined;
47-
/** @type {string | undefined} */
48-
frame = undefined;
4952

5053
/**
5154
* @param {string} code
@@ -55,9 +58,13 @@ export class CompileDiagnostic extends Error {
5558
constructor(code, message, position) {
5659
super(message);
5760
this.code = code;
58-
this.position = position;
61+
62+
if (state.filename) {
63+
this.filename = state.filename;
64+
}
5965

6066
if (position) {
67+
this.position = position;
6168
this.start = state.locator(position[0]);
6269
this.end = state.locator(position[1]);
6370
if (this.start && this.end) {

packages/svelte/src/compiler/warnings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function w(node, code, message) {
3030
}
3131

3232
if (stack && stack.at(-1)?.has(code)) return;
33-
warnings.push(new InternalCompileWarning(code, message, node ? [node.start, node.end] : undefined));
33+
warnings.push(new InternalCompileWarning(code, message, node && node.start !== undefined ? [node.start, node.end ?? node.start] : undefined));
3434
}
3535

3636
export const codes = [

packages/svelte/types/index.d.ts

Lines changed: 19 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,9 @@ declare module 'svelte/compiler' {
714714
ast: any;
715715
}
716716

717-
export interface Warning extends InternalCompileWarning {}
717+
export interface Warning extends ICompileDiagnostic {}
718718

719-
export interface CompileError extends InternalCompileError {}
719+
export interface CompileError extends ICompileDiagnostic {}
720720

721721
type CssHashGetter = (args: {
722722
name: string;
@@ -1875,33 +1875,15 @@ declare module 'svelte/compiler' {
18751875
content: Program;
18761876
attributes: Attribute[];
18771877
}
1878-
class InternalCompileError extends CompileDiagnostic {
1879-
}
1880-
class InternalCompileWarning extends CompileDiagnostic {
1881-
}
1882-
class CompileDiagnostic extends Error {
1883-
1884-
constructor(code: string, message: string, position: [number, number] | undefined);
1885-
filename: string | undefined;
1886-
1887-
position: [number, number] | undefined;
1888-
1889-
start: Location | undefined;
1890-
1891-
end: Location | undefined;
1892-
1893-
frame: string | undefined;
1878+
type ICompileDiagnostic = {
18941879
code: string;
1895-
toJSON(): {
1896-
code: string;
1897-
message: string;
1898-
filename: string | undefined;
1899-
start: import("locate-character").Location_1 | undefined;
1900-
end: import("locate-character").Location_1 | undefined;
1901-
position: [number, number] | undefined;
1902-
frame: string | undefined;
1903-
};
1904-
}
1880+
message: string;
1881+
filename?: string;
1882+
start?: Location;
1883+
end?: Location;
1884+
position?: [number, number];
1885+
frame?: string;
1886+
};
19051887

19061888
export {};
19071889
}
@@ -2547,7 +2529,7 @@ declare module 'svelte/types/compiler/interfaces' {
25472529
export type CompileOptions = CompileOptions_1;
25482530
/** @deprecated import this from 'svelte' instead */
25492531
export type Warning = Warning_1;
2550-
interface Warning_1 extends InternalCompileWarning {}
2532+
interface Warning_1 extends ICompileDiagnostic {}
25512533

25522534
type CssHashGetter = (args: {
25532535
name: string;
@@ -2710,31 +2692,15 @@ declare module 'svelte/types/compiler/interfaces' {
27102692
* (also see https://github.com/sveltejs/svelte/pull/5652)
27112693
*/
27122694
type Namespace = 'html' | 'svg' | 'mathml' | 'foreign';
2713-
class InternalCompileWarning extends CompileDiagnostic {
2714-
}
2715-
class CompileDiagnostic extends Error {
2716-
2717-
constructor(code: string, message: string, position: [number, number] | undefined);
2718-
filename: string | undefined;
2719-
2720-
position: [number, number] | undefined;
2721-
2722-
start: Location | undefined;
2723-
2724-
end: Location | undefined;
2725-
2726-
frame: string | undefined;
2695+
type ICompileDiagnostic = {
27272696
code: string;
2728-
toJSON(): {
2729-
code: string;
2730-
message: string;
2731-
filename: string | undefined;
2732-
start: import("locate-character").Location_1 | undefined;
2733-
end: import("locate-character").Location_1 | undefined;
2734-
position: [number, number] | undefined;
2735-
frame: string | undefined;
2736-
};
2737-
}
2697+
message: string;
2698+
filename?: string;
2699+
start?: Location;
2700+
end?: Location;
2701+
position?: [number, number];
2702+
frame?: string;
2703+
};
27382704

27392705
export {};
27402706
}declare module '*.svelte' {

0 commit comments

Comments
 (0)