bimba-cli 0.4.5 → 0.4.6

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 (3) hide show
  1. package/package.json +1 -1
  2. package/plugin.js +15 -5
  3. package/serve.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bimba-cli",
3
- "version": "0.4.5",
3
+ "version": "0.4.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/HeapVoid/bimba.git"
package/plugin.js CHANGED
@@ -89,18 +89,28 @@ plugin(imbaPlugin);
89
89
 
90
90
  // print an error generated by the imba compiler
91
91
  export function printerr(err) {
92
-
92
+
93
93
  // halper function to produce empty strings
94
94
  const fill = (len = 0) => {return new Array(len + 1).join(' ')}
95
-
96
- // gather the needed information from the compiler error
95
+
96
+ // gather the needed information from the compiler error
97
97
  const snippet = err.toSnippet().split("\n");
98
+ const errs = snippet[2] ? snippet[2].indexOf('^') : -1;
99
+
100
+ // no source context available — print compact fallback
101
+ if (!snippet[1] || errs === -1) {
102
+ console.log('');
103
+ console.log(fill(10) + theme.error(" " + err.message + " "));
104
+ console.log('');
105
+ return;
106
+ }
107
+
98
108
  const display = {
99
109
  error: " " + err.message + " ",
100
110
  outdent: fill(10),
101
111
  source: snippet[1] + " ",
102
- margin: " line " + err.range.start.line + " ",
103
- errs: snippet[2].indexOf('^'),
112
+ margin: " line " + (err.range.start.line + 1) + " ",
113
+ errs: errs,
104
114
  erre: snippet[2].lastIndexOf('^') + 1,
105
115
  };
106
116
 
package/serve.js CHANGED
@@ -266,7 +266,7 @@ export function serve(entrypoint, flags) {
266
266
  if (out.errors?.length) {
267
267
  if (!out.cached) {
268
268
  printStatus(file, 'fail', out.errors)
269
- const payload = JSON.stringify({ type: 'error', file, errors: out.errors.map(e => ({ message: e.message, line: e.range?.start?.line, snippet: e.toSnippet() })) })
269
+ const payload = JSON.stringify({ type: 'error', file, errors: out.errors.map(e => ({ message: e.message, line: e.range?.start?.line, snippet: e.toSnippet().split('\n').slice(1).join('\n').trim() })) })
270
270
  for (const socket of sockets) socket.send(payload)
271
271
  }
272
272
  return new Response(out.errors.map(e => e.message).join('\n'), { status: 500 })