1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.getLocation = exports.getFilename = exports.getCodeFromError = exports.CompilerError = void 0;
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | const types_1 = require("../shared/types");
|
11 | class CompilerError extends Error {
|
12 | constructor(code, message, filename, location) {
|
13 | super(message);
|
14 | this.level = types_1.DiagnosticLevel.Error;
|
15 | this.code = code;
|
16 | this.filename = filename;
|
17 | this.location = location;
|
18 | }
|
19 | static from(diagnostic, origin) {
|
20 | const { code, message } = diagnostic;
|
21 | const filename = getFilename(origin, diagnostic);
|
22 | const location = getLocation(origin, diagnostic);
|
23 | const compilerError = new CompilerError(code, message, filename, location);
|
24 |
|
25 |
|
26 | compilerError.stack = undefined;
|
27 | return compilerError;
|
28 | }
|
29 | toDiagnostic() {
|
30 | return {
|
31 | code: this.code,
|
32 | message: this.message,
|
33 | level: this.level,
|
34 | filename: this.filename,
|
35 | location: this.location,
|
36 | };
|
37 | }
|
38 | }
|
39 | exports.CompilerError = CompilerError;
|
40 | function getCodeFromError(error) {
|
41 | if (error.lwcCode && typeof error.lwcCode === 'number') {
|
42 | return error.lwcCode;
|
43 | }
|
44 | else if (error.code && typeof error.code === 'number') {
|
45 | return error.code;
|
46 | }
|
47 | return undefined;
|
48 | }
|
49 | exports.getCodeFromError = getCodeFromError;
|
50 | function getFilename(origin, obj) {
|
51 |
|
52 | if (origin && origin.filename) {
|
53 | return origin.filename;
|
54 | }
|
55 | else if (obj) {
|
56 | return obj.filename || obj.fileName || obj.file;
|
57 | }
|
58 | return undefined;
|
59 | }
|
60 | exports.getFilename = getFilename;
|
61 | function getLocation(origin, obj) {
|
62 |
|
63 | if (origin && origin.location) {
|
64 | return origin.location;
|
65 | }
|
66 | return getLocationFromObject(obj);
|
67 | }
|
68 | exports.getLocation = getLocation;
|
69 | function getLocationFromObject(obj) {
|
70 | if (obj) {
|
71 | if (obj.location) {
|
72 | return obj.location;
|
73 | }
|
74 | else if (obj.loc) {
|
75 | return obj.loc;
|
76 | }
|
77 | else if (Number.isInteger(obj.line) && Number.isInteger(obj.column)) {
|
78 | return { line: obj.line, column: obj.column, start: obj.start, length: obj.length };
|
79 | }
|
80 | }
|
81 | return undefined;
|
82 | }
|
83 |
|
\ | No newline at end of file |