@danielx/civet 0.11.9 → 0.11.11

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.
@@ -22,11 +22,22 @@ try {
22
22
  }
23
23
  return parentPort.postMessage({ id, result, errors: args[1]?.errors });
24
24
  } catch (error) {
25
- return parentPort.postMessage({ id, error: {
26
- type: error.constructor.name,
27
- name: error.name,
28
- message: error.message
29
- } });
25
+ if (error instanceof Error) {
26
+ return parentPort.postMessage({ id, error: {
27
+ type: error.constructor.name,
28
+ name: error.name,
29
+ message: error.message
30
+ } });
31
+ } else {
32
+ return parentPort.postMessage({
33
+ id,
34
+ error: {
35
+ type: typeof error,
36
+ name: "Error",
37
+ message: String(error)
38
+ }
39
+ });
40
+ }
30
41
  }
31
42
  });
32
43
  }
@@ -21,14 +21,22 @@ __export(ts_diagnostic_exports, {
21
21
  flattenDiagnosticMessageText: () => flattenDiagnosticMessageText,
22
22
  forwardMap: () => forwardMap,
23
23
  remapPosition: () => remapPosition,
24
+ remapPositionStrict: () => remapPositionStrict,
24
25
  remapRange: () => remapRange
25
26
  });
26
27
  module.exports = __toCommonJS(ts_diagnostic_exports);
27
28
  function remapPosition(position, sourcemapLines) {
28
- if (!sourcemapLines) return position;
29
+ if (!sourcemapLines) {
30
+ return position;
31
+ }
32
+ return remapPositionStrict(position, sourcemapLines) ?? walkBack(position, sourcemapLines) ?? position;
33
+ }
34
+ function remapPositionStrict(position, sourcemapLines) {
29
35
  const { line, character } = position;
30
36
  const textLine = sourcemapLines[line];
31
- if (!textLine?.length) return position;
37
+ if (!textLine?.length) {
38
+ return void 0;
39
+ }
32
40
  let i = 0, p = 0, l = textLine.length, lastMapping, lastMappingPosition = 0;
33
41
  while (i < l) {
34
42
  const mapping = textLine[i];
@@ -42,18 +50,42 @@ function remapPosition(position, sourcemapLines) {
42
50
  }
43
51
  i++;
44
52
  }
45
- if (lastMapping) {
46
- const srcLine = lastMapping[2];
47
- const srcChar = lastMapping[3];
48
- const newChar = srcChar + character - lastMappingPosition;
49
- return {
50
- line: srcLine,
51
- character: Math.max(0, newChar)
52
- };
53
- } else {
54
- return position;
53
+ if (!lastMapping) {
54
+ return void 0;
55
55
  }
56
+ const srcLine = lastMapping[2];
57
+ const srcChar = lastMapping[3];
58
+ const newChar = srcChar + character - lastMappingPosition;
59
+ return {
60
+ line: srcLine,
61
+ character: Math.max(0, newChar)
62
+ };
56
63
  }
64
+ const walkBack = function(position, sourcemapLines) {
65
+ for (let i1 = Math.min(position.line, sourcemapLines.length) + -1; i1 >= 0; --i1) {
66
+ const l = i1;
67
+ const prevLine = sourcemapLines[l];
68
+ if (!prevLine?.length) {
69
+ continue;
70
+ }
71
+ let results = void 0;
72
+ for (let i2 = prevLine.length + -1; i2 >= 0; --i2) {
73
+ const i = i2;
74
+ if (!(prevLine[i].length === 4)) continue;
75
+ results = prevLine[i];
76
+ break;
77
+ }
78
+ ;
79
+ const lastMapping = results;
80
+ if (lastMapping) {
81
+ return {
82
+ line: lastMapping[2],
83
+ character: Math.max(0, lastMapping[3])
84
+ };
85
+ }
86
+ }
87
+ return void 0;
88
+ };
57
89
  function remapRange(range, sourcemapLines) {
58
90
  return {
59
91
  start: remapPosition(range.start, sourcemapLines),
@@ -126,5 +158,6 @@ function flattenDiagnosticMessageText(diag, indent = 0) {
126
158
  flattenDiagnosticMessageText,
127
159
  forwardMap,
128
160
  remapPosition,
161
+ remapPositionStrict,
129
162
  remapRange
130
163
  });
@@ -1,8 +1,15 @@
1
1
  function remapPosition(position, sourcemapLines) {
2
- if (!sourcemapLines) return position;
2
+ if (!sourcemapLines) {
3
+ return position;
4
+ }
5
+ return remapPositionStrict(position, sourcemapLines) ?? walkBack(position, sourcemapLines) ?? position;
6
+ }
7
+ function remapPositionStrict(position, sourcemapLines) {
3
8
  const { line, character } = position;
4
9
  const textLine = sourcemapLines[line];
5
- if (!textLine?.length) return position;
10
+ if (!textLine?.length) {
11
+ return void 0;
12
+ }
6
13
  let i = 0, p = 0, l = textLine.length, lastMapping, lastMappingPosition = 0;
7
14
  while (i < l) {
8
15
  const mapping = textLine[i];
@@ -16,18 +23,42 @@ function remapPosition(position, sourcemapLines) {
16
23
  }
17
24
  i++;
18
25
  }
19
- if (lastMapping) {
20
- const srcLine = lastMapping[2];
21
- const srcChar = lastMapping[3];
22
- const newChar = srcChar + character - lastMappingPosition;
23
- return {
24
- line: srcLine,
25
- character: Math.max(0, newChar)
26
- };
27
- } else {
28
- return position;
26
+ if (!lastMapping) {
27
+ return void 0;
29
28
  }
29
+ const srcLine = lastMapping[2];
30
+ const srcChar = lastMapping[3];
31
+ const newChar = srcChar + character - lastMappingPosition;
32
+ return {
33
+ line: srcLine,
34
+ character: Math.max(0, newChar)
35
+ };
30
36
  }
37
+ const walkBack = function(position, sourcemapLines) {
38
+ for (let i1 = Math.min(position.line, sourcemapLines.length) + -1; i1 >= 0; --i1) {
39
+ const l = i1;
40
+ const prevLine = sourcemapLines[l];
41
+ if (!prevLine?.length) {
42
+ continue;
43
+ }
44
+ let results = void 0;
45
+ for (let i2 = prevLine.length + -1; i2 >= 0; --i2) {
46
+ const i = i2;
47
+ if (!(prevLine[i].length === 4)) continue;
48
+ results = prevLine[i];
49
+ break;
50
+ }
51
+ ;
52
+ const lastMapping = results;
53
+ if (lastMapping) {
54
+ return {
55
+ line: lastMapping[2],
56
+ character: Math.max(0, lastMapping[3])
57
+ };
58
+ }
59
+ }
60
+ return void 0;
61
+ };
31
62
  function remapRange(range, sourcemapLines) {
32
63
  return {
33
64
  start: remapPosition(range.start, sourcemapLines),
@@ -99,5 +130,6 @@ export {
99
130
  flattenDiagnosticMessageText,
100
131
  forwardMap,
101
132
  remapPosition,
133
+ remapPositionStrict,
102
134
  remapRange
103
135
  };
@@ -223,7 +223,26 @@ function parseTsConfigForCivet(projectPath, transpilers, options = {}) {
223
223
  } else ref2 = system;
224
224
  const configSys = ref2;
225
225
  const tsConfigPath = import_node_path2.default.join(projectPath, "tsconfig.json");
226
- const config = options.tsConfig ?? import_typescript4.default.readConfigFile(tsConfigPath, system.readFile).config;
226
+ let config;
227
+ let configFound;
228
+ if (options.tsConfig != null) {
229
+ config = options.tsConfig;
230
+ configFound = true;
231
+ } else {
232
+ configFound = system.fileExists(tsConfigPath);
233
+ let ref3;
234
+ if (configFound) {
235
+ ref3 = import_typescript4.default.readConfigFile(tsConfigPath, system.readFile).config;
236
+ } else {
237
+ if (extraExtensions.length > 0) {
238
+ ref3 = { include: extraExtensions.map((ext) => `**/*${ext}`) };
239
+ } else {
240
+ ref3 = {};
241
+ }
242
+ }
243
+ ;
244
+ config = ref3;
245
+ }
227
246
  const parsed = import_typescript4.default.parseJsonConfigFileContent(
228
247
  config,
229
248
  configSys,
@@ -235,6 +254,7 @@ function parseTsConfigForCivet(projectPath, transpilers, options = {}) {
235
254
  parsed.options.allowNonTsExtensions ??= true;
236
255
  parsed.options.jsx ??= import_typescript4.default.JsxEmit.Preserve;
237
256
  parsed.options.rootDir ??= projectPath;
257
+ parsed.configFound = configFound;
238
258
  return parsed;
239
259
  }
240
260
 
@@ -695,6 +715,7 @@ function TSService(projectPath, options) {
695
715
  };
696
716
  return Object.assign({}, service, {
697
717
  host,
718
+ configFound: parsedConfig.configFound,
698
719
  /** `foo.civet.tsx` → `foo.civet`; passthrough for non-transpiled files. */
699
720
  getSourceFileName(fileName) {
700
721
  return getCanonicalFileName(remapFileName(fileName, transpilers));