@vesk/compiler 0.2.37 → 0.2.38

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.
package/dist/parser.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as acorn from 'acorn';
2
2
  import { tsPlugin } from './acorn-ts-plugin/index.js';
3
3
  import { VeskParserPlugin } from '@vesk/compiler/src/vesk-plugin';
4
- import { blankLeadingLineComments, containsForOfIn } from '@vesk/compiler/src/scan';
4
+ import { blankComments, containsForOfIn } from '@vesk/compiler/src/scan';
5
5
  import { VeskError, codeFrame } from '@vesk/compiler/src/errors';
6
6
  function isIdentChar(code) {
7
7
  return ((code >= 97 && code <= 122) || (code >= 65 && code <= 90) || (code >= 48 && code <= 57) || code === 95 || code === 36);
@@ -257,7 +257,7 @@ export function createBaseParser() {
257
257
  }
258
258
  export function parse(source, options = {}) {
259
259
  const ParserClass = createBaseParser();
260
- const { code, annotations } = preprocessForClauses(blankLeadingLineComments(source));
260
+ const { code, annotations } = preprocessForClauses(blankComments(source));
261
261
  try {
262
262
  const ast = ParserClass.parse(code, {
263
263
  ecmaVersion: 'latest',
package/dist/scan.d.ts CHANGED
@@ -44,22 +44,28 @@ export declare function skipString(text: string, i: number): number;
44
44
  */
45
45
  export declare function skipComment(text: string, i: number): number;
46
46
  /**
47
- * Blanks out `//` line comments that begin a line, overwriting the comment
48
- * characters with spaces so every source offset (and therefore every
49
- * diagnostic line/column) is preserved.
47
+ * Blanks comments in the source, overwriting the comment characters with
48
+ * spaces so every source offset (and therefore every diagnostic line/column)
49
+ * is preserved. Newlines inside a comment are kept so line numbers hold.
50
50
  *
51
- * In JSX-children position acorn reads `//` as JSXText rather than a
52
- * comment, so `//<span>old</span>` inside a component still rendered the
53
- * element and `//{count + 1}` still emitted a live binding. Blanking a
54
- * line-leading `//` before the parse makes a commented-out line behave like
51
+ * In JSX-children position acorn reads both `//` and `/* ... *​/` as JSXText
52
+ * rather than a comment, so commented-out code still ran: `//<span>old</span>`
53
+ * inside a component rendered the element, `//{count + 1}` emitted a live
54
+ * binding, and `/* <span>old</span> *​/` leaked the markup as visible text.
55
+ * Blanking comments before the parse makes a commented-out line behave like
55
56
  * a comment in every position of a `.vsk` file.
56
57
  *
57
- * Only line-leading `//` is blanked: a trailing `// note` after code is a
58
- * real comment acorn already ignores, and blanking a mid-line `//` would
59
- * corrupt regex literals (`/https:\/\//`) and intentional JSX text. Strings
60
- * and template literals are skipped, so a `//` inside them is never touched.
58
+ * `/* ... *​/` is blanked wherever it appears (outside a string) because a
59
+ * block comment is inert everywhere in JS — and an unescaped `/*` cannot occur
60
+ * inside a regex literal, since it would terminate the regex there.
61
+ *
62
+ * `//` is blanked only when it is the first non-whitespace token on its line: a
63
+ * trailing `// note` after code is a real comment acorn already ignores, and
64
+ * blanking a mid-line `//` would corrupt regex literals (`/https:\/\//`) and
65
+ * intentional JSX text such as `ratio 1//2`. Strings and template literals are
66
+ * skipped throughout, so a comment marker inside them is never touched.
61
67
  */
62
- export declare function blankLeadingLineComments(text: string): string;
68
+ export declare function blankComments(text: string): string;
63
69
  /**
64
70
  * Given the index of an opening `(`, `[` or `{`, returns the index of its
65
71
  * matching closing delimiter. Strings, `//` and `/* ... *​/` comments are
@@ -1 +1 @@
1
- {"version":3,"file":"scan.d.ts","sourceRoot":"","sources":["../src/scan.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEpD;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAItD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,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165
  }
166
166
  /**
167
- * Blanks out `//` line comments that begin a line, overwriting the comment
168
- * characters with spaces so every source offset (and therefore every
169
- * diagnostic line/column) is preserved.
167
+ * Blanks comments in the source, overwriting the comment characters with
168
+ * spaces so every source offset (and therefore every diagnostic line/column)
169
+ * is preserved. Newlines inside a comment are kept so line numbers hold.
170
170
  *
171
- * In JSX-children position acorn reads `//` as JSXText rather than a
172
- * comment, so `//<span>old</span>` inside a component still rendered the
173
- * element and `//{count + 1}` still emitted a live binding. Blanking a
174
- * line-leading `//` before the parse makes a commented-out line behave like
171
+ * In JSX-children position acorn reads both `//` and `/* ... *​/` as JSXText
172
+ * rather than a comment, so commented-out code still ran: `//<span>old</span>`
173
+ * inside a component rendered the element, `//{count + 1}` emitted a live
174
+ * binding, and `/* <span>old</span> *​/` leaked the markup as visible text.
175
+ * Blanking comments before the parse makes a commented-out line behave like
175
176
  * a comment in every position of a `.vsk` file.
176
177
  *
177
- * Only line-leading `//` is blanked: a trailing `// note` after code is a
178
- * real comment acorn already ignores, and blanking a mid-line `//` would
179
- * corrupt regex literals (`/https:\/\//`) and intentional JSX text. Strings
180
- * and template literals are skipped, so a `//` inside them is never touched.
178
+ * `/* ... *​/` is blanked wherever it appears (outside a string) because a
179
+ * block comment is inert everywhere in JS — and an unescaped `/*` cannot occur
180
+ * inside a regex literal, since it would terminate the regex there.
181
+ *
182
+ * `//` is blanked only when it is the first non-whitespace token on its line: a
183
+ * trailing `// note` after code is a real comment acorn already ignores, and
184
+ * blanking a mid-line `//` would corrupt regex literals (`/https:\/\//`) and
185
+ * intentional JSX text such as `ratio 1//2`. Strings and template literals are
186
+ * skipped throughout, so a comment marker inside them is never touched.
181
187
  */
182
- export function blankLeadingLineComments(text) {
188
+ export function blankComments(text) {
183
189
  const chars = text.split('');
184
190
  const n = text.length;
185
191
  let lineStart = true;
@@ -207,7 +213,11 @@ export function blankLeadingLineComments(text) {
207
213
  i = end;
208
214
  continue;
209
215
  }
210
- if (ch === '/' && text[i + 1] === '/' && lineStart) {
216
+ if (ch === '/' && text[i + 1] === '/') {
217
+ if (!lineStart) {
218
+ i += 2;
219
+ continue;
220
+ }
211
221
  let j = i;
212
222
  while (j < n && text[j] !== '\n') {
213
223
  chars[j] = ' ';
@@ -216,6 +226,18 @@ export function blankLeadingLineComments(text) {
216
226
  i = j;
217
227
  continue;
218
228
  }
229
+ if (ch === '/' && text[i + 1] === '*') {
230
+ let j = i;
231
+ while (j < n && !(text[j] === '*' && text[j + 1] === '/'))
232
+ j++;
233
+ const end = Math.min(j + 2, n);
234
+ for (let k = i; k < end; k++)
235
+ if (text[k] !== '\n')
236
+ chars[k] = ' ';
237
+ lineStart = false;
238
+ i = end;
239
+ continue;
240
+ }
219
241
  lineStart = false;
220
242
  i++;
221
243
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vesk/compiler",
3
- "version": "0.2.37",
3
+ "version": "0.2.38",
4
4
  "type": "module",
5
5
  "description": "Vesk compiler — lexer, parser, semantic analysis, IR, codegen",
6
6
  "main": "./dist/index.js",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@sveltejs/acorn-typescript": "^1.0.0",
23
- "@vesk/types": "^0.2.37",
23
+ "@vesk/types": "^0.2.38",
24
24
  "acorn": "^8.15.0",
25
25
  "esrap": "^2.3.0",
26
26
  "is-reference": "^3.0.0",