@keymanapp/common-types 17.0.299-beta → 17.0.301-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/build/src/consts/virtual-key-constants.js +222 -221
  2. package/build/src/consts/virtual-key-constants.js.map +1 -1
  3. package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.js +73 -72
  4. package/build/src/keyman-touch-layout/keyman-touch-layout-file-reader.js.map +1 -1
  5. package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.js +121 -120
  6. package/build/src/keyman-touch-layout/keyman-touch-layout-file-writer.js.map +1 -1
  7. package/build/src/keyman-touch-layout/keyman-touch-layout-file.js +55 -54
  8. package/build/src/keyman-touch-layout/keyman-touch-layout-file.js.map +1 -1
  9. package/build/src/kmx/element-string.js +126 -125
  10. package/build/src/kmx/element-string.js.map +1 -1
  11. package/build/src/kmx/keyman-targets.js +80 -79
  12. package/build/src/kmx/keyman-targets.js.map +1 -1
  13. package/build/src/kmx/kmx-builder.js +190 -189
  14. package/build/src/kmx/kmx-builder.js.map +1 -1
  15. package/build/src/kmx/kmx-file-reader.js +135 -134
  16. package/build/src/kmx/kmx-file-reader.js.map +1 -1
  17. package/build/src/kmx/kmx-plus-builder/build-disp.js +28 -27
  18. package/build/src/kmx/kmx-plus-builder/build-disp.js.map +1 -1
  19. package/build/src/kmx/kmx-plus-builder/build-elem.js +90 -89
  20. package/build/src/kmx/kmx-plus-builder/build-elem.js.map +1 -1
  21. package/build/src/kmx/kmx-plus-builder/build-keys.js +108 -107
  22. package/build/src/kmx/kmx-plus-builder/build-keys.js.map +1 -1
  23. package/build/src/kmx/kmx-plus-builder/build-layr.js +102 -101
  24. package/build/src/kmx/kmx-plus-builder/build-layr.js.map +1 -1
  25. package/build/src/kmx/kmx-plus-builder/build-list.js +67 -66
  26. package/build/src/kmx/kmx-plus-builder/build-list.js.map +1 -1
  27. package/build/src/kmx/kmx-plus-builder/build-loca.js +22 -21
  28. package/build/src/kmx/kmx-plus-builder/build-loca.js.map +1 -1
  29. package/build/src/kmx/kmx-plus-builder/build-meta.js +23 -22
  30. package/build/src/kmx/kmx-plus-builder/build-meta.js.map +1 -1
  31. package/build/src/kmx/kmx-plus-builder/build-sect.js +16 -15
  32. package/build/src/kmx/kmx-plus-builder/build-sect.js.map +1 -1
  33. package/build/src/kmx/kmx-plus-builder/build-strs.js +47 -46
  34. package/build/src/kmx/kmx-plus-builder/build-strs.js.map +1 -1
  35. package/build/src/kmx/kmx-plus-builder/build-tran.js +70 -69
  36. package/build/src/kmx/kmx-plus-builder/build-tran.js.map +1 -1
  37. package/build/src/kmx/kmx-plus-builder/build-uset.js +61 -60
  38. package/build/src/kmx/kmx-plus-builder/build-uset.js.map +1 -1
  39. package/build/src/kmx/kmx-plus-builder/build-vars.js +49 -48
  40. package/build/src/kmx/kmx-plus-builder/build-vars.js.map +1 -1
  41. package/build/src/kmx/kmx-plus-builder/builder-section.js +5 -4
  42. package/build/src/kmx/kmx-plus-builder/builder-section.js.map +1 -1
  43. package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.js +138 -137
  44. package/build/src/kmx/kmx-plus-builder/kmx-plus-builder.js.map +1 -1
  45. package/build/src/kmx/kmx-plus.js +831 -830
  46. package/build/src/kmx/kmx-plus.js.map +1 -1
  47. package/build/src/kmx/kmx.d.ts.map +1 -1
  48. package/build/src/kmx/kmx.js +303 -299
  49. package/build/src/kmx/kmx.js.map +1 -1
  50. package/build/src/kmx/string-list.js +89 -88
  51. package/build/src/kmx/string-list.js.map +1 -1
  52. package/build/src/kpj/keyman-developer-project.js +196 -195
  53. package/build/src/kpj/keyman-developer-project.js.map +1 -1
  54. package/build/src/kpj/kpj-file-reader.js +120 -119
  55. package/build/src/kpj/kpj-file-reader.js.map +1 -1
  56. package/build/src/kpj/kpj-file.js +13 -12
  57. package/build/src/kpj/kpj-file.js.map +1 -1
  58. package/build/src/kvk/kvk-file-reader.js +38 -37
  59. package/build/src/kvk/kvk-file-reader.js.map +1 -1
  60. package/build/src/kvk/kvk-file-writer.js +78 -77
  61. package/build/src/kvk/kvk-file-writer.js.map +1 -1
  62. package/build/src/kvk/kvk-file.js +91 -90
  63. package/build/src/kvk/kvk-file.js.map +1 -1
  64. package/build/src/kvk/kvks-file-reader.js +176 -175
  65. package/build/src/kvk/kvks-file-reader.js.map +1 -1
  66. package/build/src/kvk/kvks-file-writer.js +107 -106
  67. package/build/src/kvk/kvks-file-writer.js.map +1 -1
  68. package/build/src/kvk/kvks-file.js +12 -11
  69. package/build/src/kvk/kvks-file.js.map +1 -1
  70. package/build/src/kvk/visual-keyboard.js +76 -75
  71. package/build/src/kvk/visual-keyboard.js.map +1 -1
  72. package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.js +22 -21
  73. package/build/src/ldml-keyboard/ldml-keyboard-testdata-xml.js.map +1 -1
  74. package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.js +410 -409
  75. package/build/src/ldml-keyboard/ldml-keyboard-xml-reader.js.map +1 -1
  76. package/build/src/ldml-keyboard/ldml-keyboard-xml.js +58 -57
  77. package/build/src/ldml-keyboard/ldml-keyboard-xml.js.map +1 -1
  78. package/build/src/ldml-keyboard/pattern-parser.js +491 -490
  79. package/build/src/ldml-keyboard/pattern-parser.js.map +1 -1
  80. package/build/src/ldml-keyboard/unicodeset-parser-api.js +30 -29
  81. package/build/src/ldml-keyboard/unicodeset-parser-api.js.map +1 -1
  82. package/build/src/main.js +35 -34
  83. package/build/src/main.js.map +1 -1
  84. package/build/src/package/kmp-json-file.js +4 -3
  85. package/build/src/package/kmp-json-file.js.map +1 -1
  86. package/build/src/package/kps-file.js +18 -17
  87. package/build/src/package/kps-file.js.map +1 -1
  88. package/build/src/schema-validators.js +28 -27
  89. package/build/src/schema-validators.js.map +1 -1
  90. package/build/src/schemas/displaymap.schema.js +38 -37
  91. package/build/src/schemas/displaymap.schema.js.map +1 -1
  92. package/build/src/schemas/displaymap.schema.validator.mjs +267 -266
  93. package/build/src/schemas/displaymap.schema.validator.mjs.map +1 -1
  94. package/build/src/schemas/keyboard_info.schema.js +101 -100
  95. package/build/src/schemas/keyboard_info.schema.js.map +1 -1
  96. package/build/src/schemas/keyboard_info.schema.validator.mjs +1161 -1160
  97. package/build/src/schemas/keyboard_info.schema.validator.mjs.map +1 -1
  98. package/build/src/schemas/keyman-touch-layout.clean.spec.js +154 -153
  99. package/build/src/schemas/keyman-touch-layout.clean.spec.js.map +1 -1
  100. package/build/src/schemas/keyman-touch-layout.clean.spec.validator.mjs +1095 -1094
  101. package/build/src/schemas/keyman-touch-layout.clean.spec.validator.mjs.map +1 -1
  102. package/build/src/schemas/keyman-touch-layout.spec.js +143 -142
  103. package/build/src/schemas/keyman-touch-layout.spec.js.map +1 -1
  104. package/build/src/schemas/keyman-touch-layout.spec.validator.mjs +1437 -1436
  105. package/build/src/schemas/keyman-touch-layout.spec.validator.mjs.map +1 -1
  106. package/build/src/schemas/kmp.schema.js +356 -355
  107. package/build/src/schemas/kmp.schema.js.map +1 -1
  108. package/build/src/schemas/kmp.schema.validator.mjs +1628 -1627
  109. package/build/src/schemas/kmp.schema.validator.mjs.map +1 -1
  110. package/build/src/schemas/kpj-9.0.schema.js +134 -133
  111. package/build/src/schemas/kpj-9.0.schema.js.map +1 -1
  112. package/build/src/schemas/kpj-9.0.schema.validator.mjs +656 -655
  113. package/build/src/schemas/kpj-9.0.schema.validator.mjs.map +1 -1
  114. package/build/src/schemas/kpj.schema.js +132 -131
  115. package/build/src/schemas/kpj.schema.js.map +1 -1
  116. package/build/src/schemas/kpj.schema.validator.mjs +516 -515
  117. package/build/src/schemas/kpj.schema.validator.mjs.map +1 -1
  118. package/build/src/schemas/kvks.schema.js +185 -184
  119. package/build/src/schemas/kvks.schema.js.map +1 -1
  120. package/build/src/schemas/kvks.schema.validator.mjs +626 -625
  121. package/build/src/schemas/kvks.schema.validator.mjs.map +1 -1
  122. package/build/src/schemas/ldml-keyboard3.schema.js +699 -698
  123. package/build/src/schemas/ldml-keyboard3.schema.js.map +1 -1
  124. package/build/src/schemas/ldml-keyboard3.schema.validator.mjs +3118 -3117
  125. package/build/src/schemas/ldml-keyboard3.schema.validator.mjs.map +1 -1
  126. package/build/src/schemas/ldml-keyboardtest3.schema.js +228 -227
  127. package/build/src/schemas/ldml-keyboardtest3.schema.js.map +1 -1
  128. package/build/src/schemas/ldml-keyboardtest3.schema.validator.mjs +745 -744
  129. package/build/src/schemas/ldml-keyboardtest3.schema.validator.mjs.map +1 -1
  130. package/build/src/schemas.js +26 -25
  131. package/build/src/schemas.js.map +1 -1
  132. package/build/src/util/common-events.js +29 -28
  133. package/build/src/util/common-events.js.map +1 -1
  134. package/build/src/util/compiler-interfaces.js +381 -380
  135. package/build/src/util/compiler-interfaces.js.map +1 -1
  136. package/build/src/util/errors.js +8 -7
  137. package/build/src/util/errors.js.map +1 -1
  138. package/build/src/util/file-types.js +143 -142
  139. package/build/src/util/file-types.js.map +1 -1
  140. package/build/src/util/util.js +369 -368
  141. package/build/src/util/util.js.map +1 -1
  142. package/package.json +2 -2
@@ -1,381 +1,382 @@
1
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="33becf37-c19a-5e43-8697-389a5157abbd")}catch(e){}}();
2
- ;
3
- export var CompilerErrorSeverity;
4
- (function (CompilerErrorSeverity) {
5
- CompilerErrorSeverity[CompilerErrorSeverity["Info"] = 0] = "Info";
6
- CompilerErrorSeverity[CompilerErrorSeverity["Hint"] = 1048576] = "Hint";
7
- CompilerErrorSeverity[CompilerErrorSeverity["Warn"] = 2097152] = "Warn";
8
- CompilerErrorSeverity[CompilerErrorSeverity["Error"] = 3145728] = "Error";
9
- CompilerErrorSeverity[CompilerErrorSeverity["Fatal"] = 4194304] = "Fatal";
10
- })(CompilerErrorSeverity || (CompilerErrorSeverity = {}));
11
- ;
12
- export const CompilerErrorSeverityValues = [
13
- CompilerErrorSeverity.Info,
14
- CompilerErrorSeverity.Hint,
15
- CompilerErrorSeverity.Warn,
16
- CompilerErrorSeverity.Error,
17
- CompilerErrorSeverity.Fatal,
18
- ];
19
- /**
20
- * Mask values for mapping compiler errors
21
- */
22
- export var CompilerErrorMask;
23
- (function (CompilerErrorMask) {
24
- CompilerErrorMask[CompilerErrorMask["Severity"] = 15728640] = "Severity";
25
- CompilerErrorMask[CompilerErrorMask["Error"] = 1048575] = "Error";
26
- CompilerErrorMask[CompilerErrorMask["Namespace"] = 1044480] = "Namespace";
27
- CompilerErrorMask[CompilerErrorMask["BaseError"] = 4095] = "BaseError";
28
- CompilerErrorMask[CompilerErrorMask["Reserved"] = 4278190080] = "Reserved";
29
- })(CompilerErrorMask || (CompilerErrorMask = {}));
30
- ;
31
- const errorSeverityName = {
32
- [CompilerErrorSeverity.Info]: 'info',
33
- [CompilerErrorSeverity.Hint]: 'hint',
34
- [CompilerErrorSeverity.Warn]: 'warn',
35
- [CompilerErrorSeverity.Error]: 'error',
36
- [CompilerErrorSeverity.Fatal]: 'fatal',
37
- };
38
- export class CompilerError {
39
- static severity(code) {
40
- return code & CompilerErrorMask.Severity;
41
- }
42
- static error(code) {
43
- return code & CompilerErrorMask.Error;
44
- }
45
- static baseError(code) {
46
- return code & CompilerErrorMask.BaseError;
47
- }
48
- static namespace(code) {
49
- return code & CompilerErrorMask.Namespace;
50
- }
51
- static formatSeverity(code) {
52
- return errorSeverityName[CompilerError.severity(code)] ?? 'UNKNOWN';
53
- }
54
- /** true if events has at least one message of the atLeast severity */
55
- static hasSeverity(events, atLeast) {
56
- for (const { code } of events) {
57
- if (CompilerError.severity(code) >= atLeast) {
58
- return true;
59
- }
60
- }
61
- return false;
62
- }
63
- /** true if events has at least one Error or worse */
64
- static hasError(events) {
65
- return CompilerError.hasSeverity(events, CompilerErrorSeverity.Error);
66
- }
67
- /**
68
- * Format an error code number. The error code number does not include
69
- * the severity mask, as this is reported in text form separately; see
70
- * `severityName`.
71
- * @example
72
- *
73
- * The following call returns `KM03004`
74
- * ```
75
- * formatCode(CompilerMessage.ERROR_InvalidDisplayMapFile)
76
- * ```
77
- */
78
- static formatCode(code) {
79
- return Number.isInteger(code) ? 'KM' + CompilerError.error(code).toString(16).toUpperCase().padStart(5, '0') : 'KM?????';
80
- }
81
- /**
82
- * Formats an event filename for an error report,
83
- * stripping off path component
84
- * @param filename
85
- * @returns
86
- */
87
- static formatFilename(filename, options) {
88
- if (!filename) {
89
- return '';
90
- }
91
- if (options?.fullPath) {
92
- return options?.forwardSlashes ?
93
- filename.replaceAll(/\\/g, '/') :
94
- filename.replaceAll(/\//g, '\\');
95
- }
96
- let x = filename.lastIndexOf('/');
97
- if (x < 0) {
98
- x = filename.lastIndexOf('\\');
99
- }
100
- return x >= 0 ? filename.substring(x + 1) : filename;
101
- }
102
- /**
103
- * Formats an event line for an error report
104
- * @param line
105
- * @returns
106
- */
107
- static formatLine(line) {
108
- return line ? line.toString() : '';
109
- }
110
- /**
111
- * Formats an event message for an error report
112
- * @param message
113
- * @returns
114
- */
115
- static formatMessage(message) {
116
- return message ?? '';
117
- }
118
- /**
119
- * Formats a compiler message, without coloring; an ANSI color version is
120
- * implemented in NodeCompilerCallbacks.
121
- * @param event event or array of events
122
- */
123
- static formatEvent(event) {
124
- if (!event) {
125
- return "";
126
- }
127
- if (Array.isArray(event)) {
128
- return event.map(item => CompilerError.formatEvent(item)).join('\n') + '\n';
129
- }
130
- return (event.filename
131
- ? CompilerError.formatFilename(event.filename) +
132
- (event.line ? ':' + CompilerError.formatLine(event.line) : '') + ' - '
133
- : '') +
134
- CompilerError.formatSeverity(event.code) + ' ' +
135
- CompilerError.formatCode(event.code) + ': ' +
136
- CompilerError.formatMessage(event.message);
137
- }
138
- /**
139
- * @param e Error-like
140
- */
141
- static exceptionToString(e) {
142
- return `${(e ?? 'unknown error').toString()}\n\nCall stack:\n${(e instanceof Error ? e.stack : (new Error()).stack)}`;
143
- }
144
- /**
145
- * Returns the corresponding error severity value from a partial name match,
146
- * e.g. 'inf' returns CompilerErrorSeverity.Info, or returns null if not found
147
- * @param name
148
- * @returns
149
- */
150
- static severityNameToValue(name) {
151
- name = name.toLowerCase();
152
- for (let level of CompilerErrorSeverityValues) {
153
- if (errorSeverityName[level].startsWith(name)) {
154
- return level;
155
- }
156
- }
157
- return null;
158
- }
159
- }
160
- ;
161
- /** @deprecated use `CompilerError.severity` instead */
162
- export function compilerErrorSeverity(code) {
163
- return CompilerError.severity(code);
164
- }
165
- /** @deprecated use `CompilerError.formatSeverity` instead */
166
- export function compilerErrorSeverityName(code) {
167
- return CompilerError.formatSeverity(code);
168
- }
169
- /** @deprecated use `CompilerError.formatCode` instead */
170
- export function compilerErrorFormatCode(code) {
171
- return CompilerError.formatCode(code);
172
- }
173
- /** @deprecated use `CompilerError.formatEvent` instead */
174
- export function compilerEventFormat(e) {
175
- return CompilerError.formatEvent(e);
176
- }
177
- /**
178
- * Defines the error code ranges for various compilers. Once defined, these
179
- * ranges must not be changed as external modules may depend on specific error
180
- * codes. Individual errors are defined at a compiler level, for example,
181
- * kmc-ldml/src/compiler/messages.ts.
182
- *
183
- * kmc defines a mapping between each namespace and the corresponding compiler's
184
- * error reporting class in kmc/src/messages/messageNamespaces.ts
185
- */
186
- export var CompilerErrorNamespace;
187
- (function (CompilerErrorNamespace) {
188
- /**
189
- * kmc-ldml errors between 0x0000…0x0FFF
190
- */
191
- CompilerErrorNamespace[CompilerErrorNamespace["LdmlKeyboardCompiler"] = 0] = "LdmlKeyboardCompiler";
192
- /**
193
- * common/web/types errors between 0x1000…0x1FFF
194
- */
195
- CompilerErrorNamespace[CompilerErrorNamespace["CommonTypes"] = 4096] = "CommonTypes";
196
- /**
197
- * kmc-kmn errors between 0x2000…0x2FFF; these map to
198
- * the base codes found in kmn_compiler_errors.h, exclusive severity flags
199
- */
200
- CompilerErrorNamespace[CompilerErrorNamespace["KmnCompiler"] = 8192] = "KmnCompiler";
201
- /**
202
- * kmc-model errors between 0x3000…0x3FFF
203
- */
204
- CompilerErrorNamespace[CompilerErrorNamespace["ModelCompiler"] = 12288] = "ModelCompiler";
205
- /**
206
- * kmc-package errors between 0x4000…0x4FFF
207
- */
208
- CompilerErrorNamespace[CompilerErrorNamespace["PackageCompiler"] = 16384] = "PackageCompiler";
209
- /**
210
- * kmc and related infrastructure errors between 0x5000…0x5FFF
211
- */
212
- CompilerErrorNamespace[CompilerErrorNamespace["Infrastructure"] = 20480] = "Infrastructure";
213
- /**
214
- * kmc-analyze 0x6000…0x6FFF
215
- */
216
- CompilerErrorNamespace[CompilerErrorNamespace["Analyzer"] = 24576] = "Analyzer";
217
- /**
218
- * kmc-kmn/kmw-compiler errors between 0x7000…0x7FFF; note that some errors
219
- * generated by kmc-kmn/kmw-compiler are from kmc-kmn namespace for legacy
220
- * reasons
221
- */
222
- CompilerErrorNamespace[CompilerErrorNamespace["KmwCompiler"] = 28672] = "KmwCompiler";
223
- /**
224
- * kmc-model-info 0x8000…0x8FFF
225
- */
226
- CompilerErrorNamespace[CompilerErrorNamespace["ModelInfoCompiler"] = 32768] = "ModelInfoCompiler";
227
- /**
228
- * kmc-keyboard-info 0x9000…0x9FFF
229
- */
230
- CompilerErrorNamespace[CompilerErrorNamespace["KeyboardInfoCompiler"] = 36864] = "KeyboardInfoCompiler";
231
- })(CompilerErrorNamespace || (CompilerErrorNamespace = {}));
232
- ;
233
- ;
234
- ;
235
- ;
236
- ;
237
- ;
238
- ;
239
- ;
240
- ;
241
- /**
242
- * Wrapper class for CompilerCallbacks for a given input file
243
- */
244
- export class CompilerFileCallbacks {
245
- filename;
246
- options;
247
- parent;
248
- messages = [];
249
- constructor(filename, options, parent) {
250
- this.filename = filename;
251
- this.options = options;
252
- this.parent = parent;
253
- }
254
- /**
255
- * Returns `true` if any message in the `messages` array is a Fatal or Error
256
- * message, and if `compilerWarningsAsErrors` is `true`, then also returns
257
- * `true` if any message is a Warning.
258
- */
259
- static hasFailureMessage(messages, compilerWarningsAsErrors) {
260
- const failureCodes = [
261
- CompilerErrorSeverity.Fatal, CompilerErrorSeverity.Error
262
- ].concat(compilerWarningsAsErrors ? [CompilerErrorSeverity.Warn] : []);
263
- return messages.find(m => failureCodes.includes(CompilerError.severity(m.code))) != undefined;
264
- }
265
- /**
266
- *
267
- * @param event
268
- * @param overrides
269
- * @returns true if event has been suppressed
270
- */
271
- static applyMessageOverridesToEvent(event, overrides) {
272
- // Override event severity from user preference -- this will not override
273
- // fatal or error events
274
- const severity = overrides?.[CompilerError.error(event.code)] ??
275
- CompilerError.severity(event.code);
276
- if (severity == 'disable') {
277
- return true;
278
- }
279
- // Override the default event severity with the command line option
280
- event.code = severity | (event.code & ~CompilerErrorMask.Severity);
281
- return false;
282
- }
283
- /**
284
- * Returns `true` if any message in the `messages` array is a Fatal or Error
285
- * message, and if `compilerWarningsAsErrors` is `true`, then also returns
286
- * `true` if any message is a Warning.
287
- *
288
- * If passed a defined `compilerWarningsAsErrors` value, then uses that,
289
- * otherwise uses `options.compilerWarningsAsErrors`, or `false` if that is
290
- * also `undefined`.
291
- */
292
- hasFailureMessage(compilerWarningsAsErrors) {
293
- return CompilerFileCallbacks.hasFailureMessage(this.messages, compilerWarningsAsErrors ?? this.options.compilerWarningsAsErrors ?? false);
294
- }
295
- clear() {
296
- this.messages = [];
297
- }
298
- loadFile(filename) {
299
- return this.parent.loadFile(filename);
300
- }
301
- fileSize(filename) {
302
- return this.parent.fileSize(filename);
303
- }
304
- get path() {
305
- return this.parent.path;
306
- }
307
- get fs() {
308
- return this.parent.fs;
309
- }
310
- resolveFilename(baseFilename, filename) {
311
- return this.parent.resolveFilename(baseFilename, filename);
312
- }
313
- reportMessage(event) {
314
- const disable = CompilerFileCallbacks.applyMessageOverridesToEvent(event, this.options.messageOverrides);
315
- this.messages.push(event);
316
- if (!disable) {
317
- this.parent.reportMessage({ filename: this.filename, ...event });
318
- }
319
- }
320
- debug(msg) {
321
- return this.parent.debug(msg);
322
- }
323
- }
324
- ;
325
- export const defaultCompilerOptions = {
326
- logLevel: 'info',
327
- logFormat: 'formatted',
328
- // outFile: (undefined)
329
- saveDebug: false,
330
- shouldAddCompilerVersion: true,
331
- compilerWarningsAsErrors: false,
332
- warnDeprecatedCode: true,
333
- checkFilenameConventions: false,
334
- };
335
- /**
336
- * Convenience function for constructing CompilerEvents
337
- * @param code Unique numeric value of the event
338
- * @param message A short description of the error presented to the user
339
- * @param detail Detailed Markdown-formatted description of the error
340
- * including references to documentation, remediation options.
341
- * @returns
342
- */
343
- export const CompilerMessageSpec = (code, message, detail) => ({
344
- code,
345
- message,
346
- detail,
347
- });
348
- export const CompilerMessageDef = (param) => String(param ?? `<param>`);
349
- export const CompilerMessageSpecWithException = (code, message, exceptionVar, detail) => ({
350
- code,
351
- message: exceptionVar
352
- ? (message ?? `Unexpected exception`) + `: ${exceptionVar.toString()}\n\nCall stack:\n${(exceptionVar instanceof Error ? exceptionVar.stack : (new Error()).stack)}` :
353
- message,
354
- detail,
355
- exceptionVar,
356
- });
357
- /**
358
- * Compiler logging level and correspondence to severity
359
- */
360
- export const ALL_COMPILER_LOG_LEVELS = [
361
- 'silent',
362
- 'error',
363
- 'warn',
364
- 'hint',
365
- 'info',
366
- 'debug' /// All messages: errors + warnings + hints + info, plus debug logs
367
- ];
368
- export const compilerLogLevelToSeverity = {
369
- 'silent': CompilerErrorMask.Severity,
370
- 'error': CompilerErrorSeverity.Error,
371
- 'warn': CompilerErrorSeverity.Warn,
372
- 'hint': CompilerErrorSeverity.Hint,
373
- 'info': CompilerErrorSeverity.Info,
374
- 'debug': CompilerErrorSeverity.Info
375
- };
376
- export const ALL_COMPILER_LOG_FORMATS = [
377
- 'tsv',
378
- 'formatted'
379
- ];
380
- //# debugId=33becf37-c19a-5e43-8697-389a5157abbd
1
+
2
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="d8f40277-52ef-5022-98a6-7d35fef5d901")}catch(e){}}();
3
+ ;
4
+ export var CompilerErrorSeverity;
5
+ (function (CompilerErrorSeverity) {
6
+ CompilerErrorSeverity[CompilerErrorSeverity["Info"] = 0] = "Info";
7
+ CompilerErrorSeverity[CompilerErrorSeverity["Hint"] = 1048576] = "Hint";
8
+ CompilerErrorSeverity[CompilerErrorSeverity["Warn"] = 2097152] = "Warn";
9
+ CompilerErrorSeverity[CompilerErrorSeverity["Error"] = 3145728] = "Error";
10
+ CompilerErrorSeverity[CompilerErrorSeverity["Fatal"] = 4194304] = "Fatal";
11
+ })(CompilerErrorSeverity || (CompilerErrorSeverity = {}));
12
+ ;
13
+ export const CompilerErrorSeverityValues = [
14
+ CompilerErrorSeverity.Info,
15
+ CompilerErrorSeverity.Hint,
16
+ CompilerErrorSeverity.Warn,
17
+ CompilerErrorSeverity.Error,
18
+ CompilerErrorSeverity.Fatal,
19
+ ];
20
+ /**
21
+ * Mask values for mapping compiler errors
22
+ */
23
+ export var CompilerErrorMask;
24
+ (function (CompilerErrorMask) {
25
+ CompilerErrorMask[CompilerErrorMask["Severity"] = 15728640] = "Severity";
26
+ CompilerErrorMask[CompilerErrorMask["Error"] = 1048575] = "Error";
27
+ CompilerErrorMask[CompilerErrorMask["Namespace"] = 1044480] = "Namespace";
28
+ CompilerErrorMask[CompilerErrorMask["BaseError"] = 4095] = "BaseError";
29
+ CompilerErrorMask[CompilerErrorMask["Reserved"] = 4278190080] = "Reserved";
30
+ })(CompilerErrorMask || (CompilerErrorMask = {}));
31
+ ;
32
+ const errorSeverityName = {
33
+ [CompilerErrorSeverity.Info]: 'info',
34
+ [CompilerErrorSeverity.Hint]: 'hint',
35
+ [CompilerErrorSeverity.Warn]: 'warn',
36
+ [CompilerErrorSeverity.Error]: 'error',
37
+ [CompilerErrorSeverity.Fatal]: 'fatal',
38
+ };
39
+ export class CompilerError {
40
+ static severity(code) {
41
+ return code & CompilerErrorMask.Severity;
42
+ }
43
+ static error(code) {
44
+ return code & CompilerErrorMask.Error;
45
+ }
46
+ static baseError(code) {
47
+ return code & CompilerErrorMask.BaseError;
48
+ }
49
+ static namespace(code) {
50
+ return code & CompilerErrorMask.Namespace;
51
+ }
52
+ static formatSeverity(code) {
53
+ return errorSeverityName[CompilerError.severity(code)] ?? 'UNKNOWN';
54
+ }
55
+ /** true if events has at least one message of the atLeast severity */
56
+ static hasSeverity(events, atLeast) {
57
+ for (const { code } of events) {
58
+ if (CompilerError.severity(code) >= atLeast) {
59
+ return true;
60
+ }
61
+ }
62
+ return false;
63
+ }
64
+ /** true if events has at least one Error or worse */
65
+ static hasError(events) {
66
+ return CompilerError.hasSeverity(events, CompilerErrorSeverity.Error);
67
+ }
68
+ /**
69
+ * Format an error code number. The error code number does not include
70
+ * the severity mask, as this is reported in text form separately; see
71
+ * `severityName`.
72
+ * @example
73
+ *
74
+ * The following call returns `KM03004`
75
+ * ```
76
+ * formatCode(CompilerMessage.ERROR_InvalidDisplayMapFile)
77
+ * ```
78
+ */
79
+ static formatCode(code) {
80
+ return Number.isInteger(code) ? 'KM' + CompilerError.error(code).toString(16).toUpperCase().padStart(5, '0') : 'KM?????';
81
+ }
82
+ /**
83
+ * Formats an event filename for an error report,
84
+ * stripping off path component
85
+ * @param filename
86
+ * @returns
87
+ */
88
+ static formatFilename(filename, options) {
89
+ if (!filename) {
90
+ return '';
91
+ }
92
+ if (options?.fullPath) {
93
+ return options?.forwardSlashes ?
94
+ filename.replaceAll(/\\/g, '/') :
95
+ filename.replaceAll(/\//g, '\\');
96
+ }
97
+ let x = filename.lastIndexOf('/');
98
+ if (x < 0) {
99
+ x = filename.lastIndexOf('\\');
100
+ }
101
+ return x >= 0 ? filename.substring(x + 1) : filename;
102
+ }
103
+ /**
104
+ * Formats an event line for an error report
105
+ * @param line
106
+ * @returns
107
+ */
108
+ static formatLine(line) {
109
+ return line ? line.toString() : '';
110
+ }
111
+ /**
112
+ * Formats an event message for an error report
113
+ * @param message
114
+ * @returns
115
+ */
116
+ static formatMessage(message) {
117
+ return message ?? '';
118
+ }
119
+ /**
120
+ * Formats a compiler message, without coloring; an ANSI color version is
121
+ * implemented in NodeCompilerCallbacks.
122
+ * @param event event or array of events
123
+ */
124
+ static formatEvent(event) {
125
+ if (!event) {
126
+ return "";
127
+ }
128
+ if (Array.isArray(event)) {
129
+ return event.map(item => CompilerError.formatEvent(item)).join('\n') + '\n';
130
+ }
131
+ return (event.filename
132
+ ? CompilerError.formatFilename(event.filename) +
133
+ (event.line ? ':' + CompilerError.formatLine(event.line) : '') + ' - '
134
+ : '') +
135
+ CompilerError.formatSeverity(event.code) + ' ' +
136
+ CompilerError.formatCode(event.code) + ': ' +
137
+ CompilerError.formatMessage(event.message);
138
+ }
139
+ /**
140
+ * @param e Error-like
141
+ */
142
+ static exceptionToString(e) {
143
+ return `${(e ?? 'unknown error').toString()}\n\nCall stack:\n${(e instanceof Error ? e.stack : (new Error()).stack)}`;
144
+ }
145
+ /**
146
+ * Returns the corresponding error severity value from a partial name match,
147
+ * e.g. 'inf' returns CompilerErrorSeverity.Info, or returns null if not found
148
+ * @param name
149
+ * @returns
150
+ */
151
+ static severityNameToValue(name) {
152
+ name = name.toLowerCase();
153
+ for (let level of CompilerErrorSeverityValues) {
154
+ if (errorSeverityName[level].startsWith(name)) {
155
+ return level;
156
+ }
157
+ }
158
+ return null;
159
+ }
160
+ }
161
+ ;
162
+ /** @deprecated use `CompilerError.severity` instead */
163
+ export function compilerErrorSeverity(code) {
164
+ return CompilerError.severity(code);
165
+ }
166
+ /** @deprecated use `CompilerError.formatSeverity` instead */
167
+ export function compilerErrorSeverityName(code) {
168
+ return CompilerError.formatSeverity(code);
169
+ }
170
+ /** @deprecated use `CompilerError.formatCode` instead */
171
+ export function compilerErrorFormatCode(code) {
172
+ return CompilerError.formatCode(code);
173
+ }
174
+ /** @deprecated use `CompilerError.formatEvent` instead */
175
+ export function compilerEventFormat(e) {
176
+ return CompilerError.formatEvent(e);
177
+ }
178
+ /**
179
+ * Defines the error code ranges for various compilers. Once defined, these
180
+ * ranges must not be changed as external modules may depend on specific error
181
+ * codes. Individual errors are defined at a compiler level, for example,
182
+ * kmc-ldml/src/compiler/messages.ts.
183
+ *
184
+ * kmc defines a mapping between each namespace and the corresponding compiler's
185
+ * error reporting class in kmc/src/messages/messageNamespaces.ts
186
+ */
187
+ export var CompilerErrorNamespace;
188
+ (function (CompilerErrorNamespace) {
189
+ /**
190
+ * kmc-ldml errors between 0x0000…0x0FFF
191
+ */
192
+ CompilerErrorNamespace[CompilerErrorNamespace["LdmlKeyboardCompiler"] = 0] = "LdmlKeyboardCompiler";
193
+ /**
194
+ * common/web/types errors between 0x1000…0x1FFF
195
+ */
196
+ CompilerErrorNamespace[CompilerErrorNamespace["CommonTypes"] = 4096] = "CommonTypes";
197
+ /**
198
+ * kmc-kmn errors between 0x2000…0x2FFF; these map to
199
+ * the base codes found in kmn_compiler_errors.h, exclusive severity flags
200
+ */
201
+ CompilerErrorNamespace[CompilerErrorNamespace["KmnCompiler"] = 8192] = "KmnCompiler";
202
+ /**
203
+ * kmc-model errors between 0x3000…0x3FFF
204
+ */
205
+ CompilerErrorNamespace[CompilerErrorNamespace["ModelCompiler"] = 12288] = "ModelCompiler";
206
+ /**
207
+ * kmc-package errors between 0x4000…0x4FFF
208
+ */
209
+ CompilerErrorNamespace[CompilerErrorNamespace["PackageCompiler"] = 16384] = "PackageCompiler";
210
+ /**
211
+ * kmc and related infrastructure errors between 0x5000…0x5FFF
212
+ */
213
+ CompilerErrorNamespace[CompilerErrorNamespace["Infrastructure"] = 20480] = "Infrastructure";
214
+ /**
215
+ * kmc-analyze 0x6000…0x6FFF
216
+ */
217
+ CompilerErrorNamespace[CompilerErrorNamespace["Analyzer"] = 24576] = "Analyzer";
218
+ /**
219
+ * kmc-kmn/kmw-compiler errors between 0x7000…0x7FFF; note that some errors
220
+ * generated by kmc-kmn/kmw-compiler are from kmc-kmn namespace for legacy
221
+ * reasons
222
+ */
223
+ CompilerErrorNamespace[CompilerErrorNamespace["KmwCompiler"] = 28672] = "KmwCompiler";
224
+ /**
225
+ * kmc-model-info 0x8000…0x8FFF
226
+ */
227
+ CompilerErrorNamespace[CompilerErrorNamespace["ModelInfoCompiler"] = 32768] = "ModelInfoCompiler";
228
+ /**
229
+ * kmc-keyboard-info 0x9000…0x9FFF
230
+ */
231
+ CompilerErrorNamespace[CompilerErrorNamespace["KeyboardInfoCompiler"] = 36864] = "KeyboardInfoCompiler";
232
+ })(CompilerErrorNamespace || (CompilerErrorNamespace = {}));
233
+ ;
234
+ ;
235
+ ;
236
+ ;
237
+ ;
238
+ ;
239
+ ;
240
+ ;
241
+ ;
242
+ /**
243
+ * Wrapper class for CompilerCallbacks for a given input file
244
+ */
245
+ export class CompilerFileCallbacks {
246
+ filename;
247
+ options;
248
+ parent;
249
+ messages = [];
250
+ constructor(filename, options, parent) {
251
+ this.filename = filename;
252
+ this.options = options;
253
+ this.parent = parent;
254
+ }
255
+ /**
256
+ * Returns `true` if any message in the `messages` array is a Fatal or Error
257
+ * message, and if `compilerWarningsAsErrors` is `true`, then also returns
258
+ * `true` if any message is a Warning.
259
+ */
260
+ static hasFailureMessage(messages, compilerWarningsAsErrors) {
261
+ const failureCodes = [
262
+ CompilerErrorSeverity.Fatal, CompilerErrorSeverity.Error
263
+ ].concat(compilerWarningsAsErrors ? [CompilerErrorSeverity.Warn] : []);
264
+ return messages.find(m => failureCodes.includes(CompilerError.severity(m.code))) != undefined;
265
+ }
266
+ /**
267
+ *
268
+ * @param event
269
+ * @param overrides
270
+ * @returns true if event has been suppressed
271
+ */
272
+ static applyMessageOverridesToEvent(event, overrides) {
273
+ // Override event severity from user preference -- this will not override
274
+ // fatal or error events
275
+ const severity = overrides?.[CompilerError.error(event.code)] ??
276
+ CompilerError.severity(event.code);
277
+ if (severity == 'disable') {
278
+ return true;
279
+ }
280
+ // Override the default event severity with the command line option
281
+ event.code = severity | (event.code & ~CompilerErrorMask.Severity);
282
+ return false;
283
+ }
284
+ /**
285
+ * Returns `true` if any message in the `messages` array is a Fatal or Error
286
+ * message, and if `compilerWarningsAsErrors` is `true`, then also returns
287
+ * `true` if any message is a Warning.
288
+ *
289
+ * If passed a defined `compilerWarningsAsErrors` value, then uses that,
290
+ * otherwise uses `options.compilerWarningsAsErrors`, or `false` if that is
291
+ * also `undefined`.
292
+ */
293
+ hasFailureMessage(compilerWarningsAsErrors) {
294
+ return CompilerFileCallbacks.hasFailureMessage(this.messages, compilerWarningsAsErrors ?? this.options.compilerWarningsAsErrors ?? false);
295
+ }
296
+ clear() {
297
+ this.messages = [];
298
+ }
299
+ loadFile(filename) {
300
+ return this.parent.loadFile(filename);
301
+ }
302
+ fileSize(filename) {
303
+ return this.parent.fileSize(filename);
304
+ }
305
+ get path() {
306
+ return this.parent.path;
307
+ }
308
+ get fs() {
309
+ return this.parent.fs;
310
+ }
311
+ resolveFilename(baseFilename, filename) {
312
+ return this.parent.resolveFilename(baseFilename, filename);
313
+ }
314
+ reportMessage(event) {
315
+ const disable = CompilerFileCallbacks.applyMessageOverridesToEvent(event, this.options.messageOverrides);
316
+ this.messages.push(event);
317
+ if (!disable) {
318
+ this.parent.reportMessage({ filename: this.filename, ...event });
319
+ }
320
+ }
321
+ debug(msg) {
322
+ return this.parent.debug(msg);
323
+ }
324
+ }
325
+ ;
326
+ export const defaultCompilerOptions = {
327
+ logLevel: 'info',
328
+ logFormat: 'formatted',
329
+ // outFile: (undefined)
330
+ saveDebug: false,
331
+ shouldAddCompilerVersion: true,
332
+ compilerWarningsAsErrors: false,
333
+ warnDeprecatedCode: true,
334
+ checkFilenameConventions: false,
335
+ };
336
+ /**
337
+ * Convenience function for constructing CompilerEvents
338
+ * @param code Unique numeric value of the event
339
+ * @param message A short description of the error presented to the user
340
+ * @param detail Detailed Markdown-formatted description of the error
341
+ * including references to documentation, remediation options.
342
+ * @returns
343
+ */
344
+ export const CompilerMessageSpec = (code, message, detail) => ({
345
+ code,
346
+ message,
347
+ detail,
348
+ });
349
+ export const CompilerMessageDef = (param) => String(param ?? `<param>`);
350
+ export const CompilerMessageSpecWithException = (code, message, exceptionVar, detail) => ({
351
+ code,
352
+ message: exceptionVar
353
+ ? (message ?? `Unexpected exception`) + `: ${exceptionVar.toString()}\n\nCall stack:\n${(exceptionVar instanceof Error ? exceptionVar.stack : (new Error()).stack)}` :
354
+ message,
355
+ detail,
356
+ exceptionVar,
357
+ });
358
+ /**
359
+ * Compiler logging level and correspondence to severity
360
+ */
361
+ export const ALL_COMPILER_LOG_LEVELS = [
362
+ 'silent',
363
+ 'error',
364
+ 'warn',
365
+ 'hint',
366
+ 'info',
367
+ 'debug' /// All messages: errors + warnings + hints + info, plus debug logs
368
+ ];
369
+ export const compilerLogLevelToSeverity = {
370
+ 'silent': CompilerErrorMask.Severity,
371
+ 'error': CompilerErrorSeverity.Error,
372
+ 'warn': CompilerErrorSeverity.Warn,
373
+ 'hint': CompilerErrorSeverity.Hint,
374
+ 'info': CompilerErrorSeverity.Info,
375
+ 'debug': CompilerErrorSeverity.Info
376
+ };
377
+ export const ALL_COMPILER_LOG_FORMATS = [
378
+ 'tsv',
379
+ 'formatted'
380
+ ];
381
381
  //# sourceMappingURL=compiler-interfaces.js.map
382
+ //# debugId=d8f40277-52ef-5022-98a6-7d35fef5d901