@seljs/checker 1.1.0-beta.4 → 1.1.0-beta.5

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.
@@ -14,7 +14,7 @@
14
14
  * We parse the caret offset relative to the code line prefix (`> N | `)
15
15
  * to derive the zero-based character offset within the expression.
16
16
  */
17
- const extractPositionFromMessage = (message) => {
17
+ const extractPositionFromMessage = (message, expression) => {
18
18
  const lines = message.split("\n");
19
19
  const caretLine = lines.find((line) => /^\s*\^+\s*$/.test(line));
20
20
  if (!caretLine) return;
@@ -25,12 +25,22 @@ const extractPositionFromMessage = (message) => {
25
25
  const prefixLength = pipeIndex + 2;
26
26
  const caretStart = caretLine.indexOf("^");
27
27
  const caretEnd = caretLine.lastIndexOf("^");
28
- const from = caretStart - prefixLength;
29
- const to = caretEnd - prefixLength + 1;
30
- if (from < 0) return;
28
+ const column = caretStart - prefixLength;
29
+ const columnEnd = caretEnd - prefixLength + 1;
30
+ if (column < 0) return;
31
+ const lineMatch = codeLine.match(/^>\s+(\d+)\s*\|/);
32
+ const lineNumber = lineMatch ? Number(lineMatch[1]) : 1;
33
+ const expressionLines = expression.split("\n");
34
+ if (lineNumber > expressionLines.length) return;
35
+ let baseOffset = 0;
36
+ for (let i = 0; i < lineNumber - 1; i++) {
37
+ const line = expressionLines[i];
38
+ if (line === void 0) return;
39
+ baseOffset += line.length + 1;
40
+ }
31
41
  return {
32
- from,
33
- to
42
+ from: baseOffset + column,
43
+ to: baseOffset + columnEnd
34
44
  };
35
45
  };
36
46
  /**
@@ -54,7 +64,7 @@ const extractDiagnostics = (expression, error) => {
54
64
  from: 0,
55
65
  to: expression.length
56
66
  }];
57
- const position = extractPositionFromMessage(error.message);
67
+ const position = extractPositionFromMessage(error.message, expression);
58
68
  return [{
59
69
  message: extractPlainMessage(error.message),
60
70
  severity: "error",
@@ -14,7 +14,7 @@
14
14
  * We parse the caret offset relative to the code line prefix (`> N | `)
15
15
  * to derive the zero-based character offset within the expression.
16
16
  */
17
- const extractPositionFromMessage = (message) => {
17
+ const extractPositionFromMessage = (message, expression) => {
18
18
  const lines = message.split("\n");
19
19
  const caretLine = lines.find((line) => /^\s*\^+\s*$/.test(line));
20
20
  if (!caretLine) return;
@@ -25,12 +25,22 @@ const extractPositionFromMessage = (message) => {
25
25
  const prefixLength = pipeIndex + 2;
26
26
  const caretStart = caretLine.indexOf("^");
27
27
  const caretEnd = caretLine.lastIndexOf("^");
28
- const from = caretStart - prefixLength;
29
- const to = caretEnd - prefixLength + 1;
30
- if (from < 0) return;
28
+ const column = caretStart - prefixLength;
29
+ const columnEnd = caretEnd - prefixLength + 1;
30
+ if (column < 0) return;
31
+ const lineMatch = codeLine.match(/^>\s+(\d+)\s*\|/);
32
+ const lineNumber = lineMatch ? Number(lineMatch[1]) : 1;
33
+ const expressionLines = expression.split("\n");
34
+ if (lineNumber > expressionLines.length) return;
35
+ let baseOffset = 0;
36
+ for (let i = 0; i < lineNumber - 1; i++) {
37
+ const line = expressionLines[i];
38
+ if (line === void 0) return;
39
+ baseOffset += line.length + 1;
40
+ }
31
41
  return {
32
- from,
33
- to
42
+ from: baseOffset + column,
43
+ to: baseOffset + columnEnd
34
44
  };
35
45
  };
36
46
  /**
@@ -54,7 +64,7 @@ const extractDiagnostics = (expression, error) => {
54
64
  from: 0,
55
65
  to: expression.length
56
66
  }];
57
- const position = extractPositionFromMessage(error.message);
67
+ const position = extractPositionFromMessage(error.message, expression);
58
68
  return [{
59
69
  message: extractPlainMessage(error.message),
60
70
  severity: "error",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seljs/checker",
3
- "version": "1.1.0-beta.4",
3
+ "version": "1.1.0-beta.5",
4
4
  "repository": {
5
5
  "url": "https://github.com/abinnovision/seljs"
6
6
  },
@@ -50,9 +50,9 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@marcbachmann/cel-js": "^7.5.3",
53
- "@seljs/common": "1.1.0-beta.4",
53
+ "@seljs/common": "1.1.0-beta.5",
54
54
  "@seljs/schema": "1.0.1",
55
- "@seljs/types": "1.1.0-beta.4",
55
+ "@seljs/types": "1.1.0-beta.5",
56
56
  "debug": "^4.4.3"
57
57
  },
58
58
  "devDependencies": {