@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 +2 -2
- package/dist/scan.d.ts +18 -12
- package/dist/scan.d.ts.map +1 -1
- package/dist/scan.js +35 -13
- package/package.json +2 -2
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 {
|
|
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(
|
|
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
|
|
48
|
-
*
|
|
49
|
-
*
|
|
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 `//`
|
|
52
|
-
* comment, so `//<span>old</span>`
|
|
53
|
-
* element
|
|
54
|
-
*
|
|
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
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
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
|
|
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
|
package/dist/scan.d.ts.map
CHANGED
|
@@ -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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,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAcnE;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAqB9D;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAY3D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAexD"}
|
package/dist/scan.js
CHANGED
|
@@ -164,22 +164,28 @@ export function skipComment(text, i) {
|
|
|
164
164
|
return i;
|
|
165
165
|
}
|
|
166
166
|
/**
|
|
167
|
-
* Blanks
|
|
168
|
-
*
|
|
169
|
-
*
|
|
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 `//`
|
|
172
|
-
* comment, so `//<span>old</span>`
|
|
173
|
-
* element
|
|
174
|
-
*
|
|
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
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
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
|
|
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] === '/'
|
|
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.
|
|
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.
|
|
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",
|