aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/errors.ts
blob: c5968e4228e35a764cf43cf318126bdc5fbba9a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// @ts-nocheck
var __BuildLog;
var __ResolveLog;
var __ImportKind;
{
  enum ImportKind {
    entry_point = 0,
    stmt = 1,
    require = 2,
    dynamic = 3,
    require_resolve = 4,
    at = 5,
    at_conditional = 6,
    url = 7,
  }

  type ErrorPosition = {
    file: string;
    namespace: string;
    line: number; // 1-based
    column: number; // 0-based, byte offset relative to lineText
    length: number; // in bytes
    /** line of text, possibly empty */
    lineText: string;
    /** byte offset relative to the start of the file */
    offset: number;
  };

  interface BuildErrorImplementation {
    position: ErrorPosition;
    name: string;
    message: string;
  }

  interface ResolveErrorImplementation extends BuildErrorImplementation {
    specifier: string;
    importKind: ImportKind;
  }

  class BuildMessage extends Error {
    constructor(data: BuildErrorImplementation) {
      super(data.message);
      this.name = data.name;
      this.data = data;
    }
    data: BuildLogImplementation;

    get position() {
      return this.data.position;
    }

    get [Symbol.toStringTag]() {
      return `${this.name}: ${this.message}`;
    }
  }

  class ResolveMessage extends BuildMessage {
    constructor(data: ResolveErrorImplementation) {
      super(data);
      this.name = data.name;
      this.data = data;
    }
    data: ResolveErrorImplementation;

    get importKind() {
      return this.data.importKind;
    }

    get specifier() {
      return this.data.specifier || "";
    }
  }

  __ResolveLog = ResolveMessage;
  __BuildLog = BuildMessage;
  __ImportKind = ImportKind;
}

export { __ResolveLog as ResolveMessage, __BuildLog as BuildMessage, __ImportKind as ImportKind };