1 | "use strict";
|
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3 | if (k2 === undefined) k2 = k;
|
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5 | }) : (function(o, m, k, k2) {
|
6 | if (k2 === undefined) k2 = k;
|
7 | o[k2] = m[k];
|
8 | }));
|
9 | var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
10 | for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
11 | };
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | exports.normalizeToDiagnostic = exports.normalizeToCompilerError = exports.invariant = exports.generateCompilerError = exports.generateCompilerDiagnostic = exports.generateErrorMessage = exports.CompilerError = void 0;
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | const utils_1 = require("../shared/utils");
|
21 | const utils_2 = require("./utils");
|
22 | var utils_3 = require("./utils");
|
23 | Object.defineProperty(exports, "CompilerError", { enumerable: true, get: function () { return utils_3.CompilerError; } });
|
24 | __exportStar(require("./error-info"), exports);
|
25 | function generateErrorMessage(errorInfo, args) {
|
26 | const message = Array.isArray(args)
|
27 | ? utils_1.templateString(errorInfo.message, args)
|
28 | : errorInfo.message;
|
29 | if (errorInfo.url && errorInfo.url !== '') {
|
30 |
|
31 | }
|
32 | return `LWC${errorInfo.code}: ${message}`;
|
33 | }
|
34 | exports.generateErrorMessage = generateErrorMessage;
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | function generateCompilerDiagnostic(errorInfo, config) {
|
45 | const message = generateErrorMessage(errorInfo, config && config.messageArgs);
|
46 | const diagnostic = {
|
47 | code: errorInfo.code,
|
48 | message,
|
49 | level: errorInfo.level,
|
50 | };
|
51 | if (config && config.origin) {
|
52 | diagnostic.filename = utils_2.getFilename(config.origin);
|
53 | diagnostic.location = utils_2.getLocation(config.origin);
|
54 | }
|
55 | return diagnostic;
|
56 | }
|
57 | exports.generateCompilerDiagnostic = generateCompilerDiagnostic;
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 | function generateCompilerError(errorInfo, config) {
|
68 | const message = generateErrorMessage(errorInfo, config && config.messageArgs);
|
69 | const error = new utils_2.CompilerError(errorInfo.code, message);
|
70 | if (config) {
|
71 | error.filename = utils_2.getFilename(config.origin);
|
72 | error.location = utils_2.getLocation(config.origin);
|
73 | }
|
74 | return error;
|
75 | }
|
76 | exports.generateCompilerError = generateCompilerError;
|
77 | function invariant(condition, errorInfo, args) {
|
78 | if (!condition) {
|
79 | throw generateCompilerError(errorInfo, {
|
80 | messageArgs: args,
|
81 | });
|
82 | }
|
83 | }
|
84 | exports.invariant = invariant;
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | function normalizeToCompilerError(errorInfo, error, origin) {
|
94 | if (error instanceof utils_2.CompilerError) {
|
95 | if (origin) {
|
96 | error.filename = utils_2.getFilename(origin);
|
97 | error.location = utils_2.getLocation(origin);
|
98 | }
|
99 | return error;
|
100 | }
|
101 | const { code, message, filename, location } = convertErrorToDiagnostic(error, errorInfo, origin);
|
102 | const compilerError = new utils_2.CompilerError(code, `${error.name}: ${message}`, filename, location);
|
103 | compilerError.stack = error.stack;
|
104 | return compilerError;
|
105 | }
|
106 | exports.normalizeToCompilerError = normalizeToCompilerError;
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | function normalizeToDiagnostic(errorInfo, error, origin) {
|
115 | if (error instanceof utils_2.CompilerError) {
|
116 | const diagnostic = error.toDiagnostic();
|
117 | if (origin) {
|
118 | diagnostic.filename = utils_2.getFilename(origin);
|
119 | diagnostic.location = utils_2.getLocation(origin);
|
120 | }
|
121 | return diagnostic;
|
122 | }
|
123 | return convertErrorToDiagnostic(error, errorInfo, origin);
|
124 | }
|
125 | exports.normalizeToDiagnostic = normalizeToDiagnostic;
|
126 | function convertErrorToDiagnostic(error, fallbackErrorInfo, origin) {
|
127 | const code = utils_2.getCodeFromError(error) || fallbackErrorInfo.code;
|
128 | const message = error.lwcCode
|
129 | ? error.message
|
130 | : generateErrorMessage(fallbackErrorInfo, [error.message]);
|
131 | const level = error.level || fallbackErrorInfo.level;
|
132 | const filename = utils_2.getFilename(origin, error);
|
133 | const location = utils_2.getLocation(origin, error);
|
134 |
|
135 | return { code, message, level, filename, location };
|
136 | }
|
137 |
|
\ | No newline at end of file |