wesl 0.6.49 → 0.7.1
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/index.d.ts +269 -215
- package/dist/index.js +2911 -1539
- package/package.json +6 -8
- package/src/AbstractElems.ts +81 -81
- package/src/Assertions.ts +5 -5
- package/src/BindIdents.ts +192 -306
- package/src/ClickableError.ts +3 -2
- package/src/Conditions.ts +2 -2
- package/src/LinkedWesl.ts +1 -1
- package/src/Linker.ts +4 -3
- package/src/LinkerUtil.ts +1 -1
- package/src/Logging.ts +165 -0
- package/src/LowerAndEmit.ts +278 -110
- package/src/ModuleResolver.ts +15 -25
- package/src/ParseError.ts +9 -0
- package/src/ParseWESL.ts +30 -94
- package/src/RawEmit.ts +1 -4
- package/src/Reflection.ts +1 -1
- package/src/Scope.ts +3 -0
- package/src/Span.ts +2 -0
- package/src/SrcMap.ts +208 -0
- package/src/Stream.ts +30 -0
- package/src/TransformBindingStructs.ts +2 -2
- package/src/Util.ts +1 -1
- package/src/debug/ASTtoString.ts +84 -135
- package/src/discovery/FindUnboundIdents.ts +14 -5
- package/src/index.ts +4 -0
- package/src/parse/ContentsHelpers.ts +70 -0
- package/src/parse/ExpressionUtil.ts +121 -0
- package/src/parse/Keywords.ts +12 -12
- package/src/parse/OperatorBinding.ts +146 -0
- package/src/parse/ParseAttribute.ts +272 -0
- package/src/parse/ParseCall.ts +77 -0
- package/src/parse/ParseControlFlow.ts +129 -0
- package/src/parse/ParseDirective.ts +105 -0
- package/src/parse/ParseExpression.ts +288 -0
- package/src/parse/ParseFn.ts +151 -0
- package/src/parse/ParseGlobalVar.ts +131 -0
- package/src/parse/ParseIdent.ts +77 -0
- package/src/parse/ParseImport.ts +160 -0
- package/src/parse/ParseLocalVar.ts +69 -0
- package/src/parse/ParseLoop.ts +112 -0
- package/src/parse/ParseModule.ts +116 -0
- package/src/parse/ParseSimpleStatement.ts +162 -0
- package/src/parse/ParseStatement.ts +215 -0
- package/src/parse/ParseStruct.ts +89 -0
- package/src/parse/ParseType.ts +71 -0
- package/src/parse/ParseUtil.ts +174 -0
- package/src/parse/ParseValueDeclaration.ts +130 -0
- package/src/parse/ParseWesl.ts +51 -0
- package/src/parse/ParsingContext.ts +93 -0
- package/src/parse/WeslStream.ts +63 -20
- package/src/parse/stream/CachingStream.ts +48 -0
- package/src/parse/stream/MatchersStream.ts +85 -0
- package/src/parse/stream/RegexHelpers.ts +38 -0
- package/src/test/BevyLink.test.ts +100 -0
- package/src/test/BindStdTypes.test.ts +110 -0
- package/src/test/{BindWESL.test.ts → BindWESLV2.test.ts} +21 -22
- package/src/test/BulkTests.test.ts +11 -12
- package/src/test/ConditionLinking.test.ts +107 -0
- package/src/test/ConditionalElif.test.ts +1 -13
- package/src/test/ConditionalTranslationCases.test.ts +5 -0
- package/src/test/ErrorLogging.test.ts +2 -2
- package/src/test/ImportCasesV2.test.ts +63 -0
- package/src/test/LinkFails.test.ts +69 -0
- package/src/test/LinkPackage.test.ts +1 -1
- package/src/test/Linker.test.ts +75 -2
- package/src/test/LogCatcher.ts +53 -0
- package/src/test/Mangling.test.ts +1 -1
- package/src/test/ParseComments.test.ts +1 -2
- package/src/test/{ParseConditions.test.ts → ParseConditionsV2.test.ts} +57 -49
- package/src/test/ParseErrorV2.test.ts +73 -0
- package/src/test/{ParseWESL.test.ts → ParseWeslV2.test.ts} +288 -370
- package/src/test/{ScopeWESL.test.ts → ScopeWESLV2.test.ts} +205 -176
- package/src/test/TestLink.ts +51 -51
- package/src/test/TestSetup.ts +9 -3
- package/src/test/TestUtil.ts +47 -77
- package/src/test/TrimmedMatch.ts +40 -0
- package/src/test/VirtualModules.test.ts +33 -2
- package/src/test/WeslDevice.test.ts +9 -2
- package/src/test/__snapshots__/ParseWeslV2.test.ts.snap +67 -0
- package/src/test-util.ts +7 -0
- package/src/WESLCollect.ts +0 -656
- package/src/parse/AttributeGrammar.ts +0 -232
- package/src/parse/ImportGrammar.ts +0 -195
- package/src/parse/WeslBaseGrammar.ts +0 -11
- package/src/parse/WeslExpression.ts +0 -231
- package/src/parse/WeslGrammar.ts +0 -739
- package/src/test/Expression.test.ts +0 -22
- package/src/test/ImportSyntaxCases.test.ts +0 -24
- package/src/test/ParseError.test.ts +0 -45
- package/src/test/Reflection.test.ts +0 -176
- package/src/test/TransformBindingStructs.test.ts +0 -238
- /package/src/test/{ParseElif.test.ts → ParseElifV2.test.ts} +0 -0
|
@@ -24,7 +24,6 @@ test("@if(false) enable f16", () => {
|
|
|
24
24
|
"module
|
|
25
25
|
text '
|
|
26
26
|
'
|
|
27
|
-
attribute @if(false)
|
|
28
27
|
directive enable f16 @if
|
|
29
28
|
text '
|
|
30
29
|
'"
|
|
@@ -51,7 +50,7 @@ test("@if(false) const_assert true;", () => {
|
|
|
51
50
|
|
|
52
51
|
test("@if(true) var x = 7", () => {
|
|
53
52
|
const src = `
|
|
54
|
-
@if(true) var x = 7;
|
|
53
|
+
@if(true) var x = 7;
|
|
55
54
|
`;
|
|
56
55
|
const ast = parseTest(src);
|
|
57
56
|
const astString = astToString(ast.moduleElem);
|
|
@@ -65,7 +64,7 @@ test("@if(true) var x = 7", () => {
|
|
|
65
64
|
typeDecl %x
|
|
66
65
|
decl %x
|
|
67
66
|
text ' = 7;'
|
|
68
|
-
text '
|
|
67
|
+
text '
|
|
69
68
|
'"
|
|
70
69
|
`);
|
|
71
70
|
});
|
|
@@ -92,8 +91,8 @@ test("conditional statement", () => {
|
|
|
92
91
|
text 'var '
|
|
93
92
|
typeDecl %x
|
|
94
93
|
decl %x
|
|
95
|
-
text ' = 1'
|
|
96
|
-
text '
|
|
94
|
+
text ' = 1;'
|
|
95
|
+
text '
|
|
97
96
|
'
|
|
98
97
|
statement @if
|
|
99
98
|
attribute @if(true)
|
|
@@ -129,10 +128,13 @@ test("compound statement", () => {
|
|
|
129
128
|
statement @if
|
|
130
129
|
attribute @if(false)
|
|
131
130
|
text ' {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
131
|
+
'
|
|
132
|
+
let %x
|
|
133
|
+
text 'let '
|
|
134
|
+
typeDecl %x
|
|
135
|
+
decl %x
|
|
136
|
+
text ' = 1;'
|
|
137
|
+
text '
|
|
136
138
|
}'
|
|
137
139
|
text '
|
|
138
140
|
}'
|
|
@@ -158,15 +160,12 @@ test("conditional local var", () => {
|
|
|
158
160
|
statement
|
|
159
161
|
text '{
|
|
160
162
|
'
|
|
161
|
-
|
|
163
|
+
var %x @if
|
|
162
164
|
attribute @if(true)
|
|
163
|
-
text ' '
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
decl %x
|
|
168
|
-
text ' = 1'
|
|
169
|
-
text ';'
|
|
165
|
+
text ' var '
|
|
166
|
+
typeDecl %x
|
|
167
|
+
decl %x
|
|
168
|
+
text ' = 1;'
|
|
170
169
|
text '
|
|
171
170
|
}'
|
|
172
171
|
text '
|
|
@@ -240,14 +239,20 @@ test("@else with function", () => {
|
|
|
240
239
|
attribute @if(DEBUG)
|
|
241
240
|
decl %foo
|
|
242
241
|
statement
|
|
243
|
-
text '{
|
|
242
|
+
text '{'
|
|
243
|
+
statement
|
|
244
|
+
text ' return 1;'
|
|
245
|
+
text ' }'
|
|
244
246
|
text '
|
|
245
247
|
'
|
|
246
248
|
fn foo() @else
|
|
247
249
|
attribute @else
|
|
248
250
|
decl %foo
|
|
249
251
|
statement
|
|
250
|
-
text '{
|
|
252
|
+
text '{'
|
|
253
|
+
statement
|
|
254
|
+
text ' return 2;'
|
|
255
|
+
text ' }'
|
|
251
256
|
text '
|
|
252
257
|
'"
|
|
253
258
|
`);
|
|
@@ -271,7 +276,7 @@ test("@else with statement", () => {
|
|
|
271
276
|
statement
|
|
272
277
|
text '{
|
|
273
278
|
'
|
|
274
|
-
|
|
279
|
+
let %x @if
|
|
275
280
|
attribute @if(A)
|
|
276
281
|
text ' let '
|
|
277
282
|
typeDecl %x
|
|
@@ -279,7 +284,7 @@ test("@else with statement", () => {
|
|
|
279
284
|
text ' = 1.0;'
|
|
280
285
|
text '
|
|
281
286
|
'
|
|
282
|
-
|
|
287
|
+
let %x @else
|
|
283
288
|
attribute @else
|
|
284
289
|
text ' let '
|
|
285
290
|
typeDecl %x
|
|
@@ -312,18 +317,24 @@ test("@else compound statement", () => {
|
|
|
312
317
|
'
|
|
313
318
|
statement @if
|
|
314
319
|
attribute @if(MOBILE)
|
|
315
|
-
text ' {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
320
|
+
text ' { '
|
|
321
|
+
let %a
|
|
322
|
+
text 'let '
|
|
323
|
+
typeDecl %a
|
|
324
|
+
decl %a
|
|
325
|
+
text ' = 1;'
|
|
326
|
+
text ' }'
|
|
319
327
|
text '
|
|
320
328
|
'
|
|
321
329
|
statement @else
|
|
322
330
|
attribute @else
|
|
323
|
-
text ' {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
331
|
+
text ' { '
|
|
332
|
+
let %a
|
|
333
|
+
text 'let '
|
|
334
|
+
typeDecl %a
|
|
335
|
+
decl %a
|
|
336
|
+
text ' = 2;'
|
|
337
|
+
text ' }'
|
|
327
338
|
text '
|
|
328
339
|
}'
|
|
329
340
|
text '
|
|
@@ -358,16 +369,15 @@ test("@else with struct member", () => {
|
|
|
358
369
|
ref f32
|
|
359
370
|
text ',
|
|
360
371
|
'
|
|
361
|
-
member @else x: vec3<f32>
|
|
372
|
+
member @else x: vec3<ref f32>
|
|
362
373
|
attribute @else
|
|
363
374
|
text ' '
|
|
364
375
|
name x
|
|
365
376
|
text ': '
|
|
366
|
-
type vec3<f32>
|
|
377
|
+
type vec3<ref f32>
|
|
367
378
|
ref vec3
|
|
368
379
|
text '<'
|
|
369
|
-
|
|
370
|
-
ref f32
|
|
380
|
+
ref f32
|
|
371
381
|
text '>'
|
|
372
382
|
text ',
|
|
373
383
|
}'
|
|
@@ -432,30 +442,28 @@ test("parse @else fn", () => {
|
|
|
432
442
|
attribute @if(FOO)
|
|
433
443
|
decl %testFn
|
|
434
444
|
statement
|
|
435
|
-
text '{
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
445
|
+
text '{ '
|
|
446
|
+
let %a
|
|
447
|
+
text 'let '
|
|
448
|
+
typeDecl %a
|
|
449
|
+
decl %a
|
|
450
|
+
text ' = 0;'
|
|
451
|
+
text ' }'
|
|
439
452
|
text '
|
|
440
453
|
'
|
|
441
454
|
fn testFn() @else
|
|
442
455
|
attribute @else
|
|
443
456
|
decl %testFn
|
|
444
457
|
statement
|
|
445
|
-
text '{
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
458
|
+
text '{ '
|
|
459
|
+
let %a
|
|
460
|
+
text 'let '
|
|
461
|
+
typeDecl %a
|
|
462
|
+
decl %a
|
|
463
|
+
text ' = 1;'
|
|
464
|
+
text ' }'
|
|
449
465
|
text '
|
|
450
466
|
'"
|
|
451
467
|
`,
|
|
452
468
|
);
|
|
453
469
|
});
|
|
454
|
-
|
|
455
|
-
// test("", () => {
|
|
456
|
-
// const src = `
|
|
457
|
-
// `;
|
|
458
|
-
// const ast = parseTest(src);
|
|
459
|
-
// const astString = astToString(ast.moduleElem);
|
|
460
|
-
// expect(astString).toMatchInlineSnapshot('tbd');
|
|
461
|
-
// });
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { errorHighlight } from "../Util.ts";
|
|
3
|
+
import { parseTest } from "./TestUtil.ts";
|
|
4
|
+
|
|
5
|
+
test("parse fn foo() { invalid }", () => {
|
|
6
|
+
const src = "fn foo() { let }";
|
|
7
|
+
expect(() => parseTest(src)).toThrowErrorMatchingInlineSnapshot(`
|
|
8
|
+
[Error: ./test.wesl:1:16 error: Expected identifier after 'let'
|
|
9
|
+
fn foo() { let }
|
|
10
|
+
^]
|
|
11
|
+
`);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("parse invalid if", () => {
|
|
15
|
+
const src = `fn foo() {
|
|
16
|
+
let a = 3;
|
|
17
|
+
if(1<1) { 🐈⬛ } else { }
|
|
18
|
+
}`;
|
|
19
|
+
expect(() => parseTest(src)).toThrowErrorMatchingInlineSnapshot(`
|
|
20
|
+
[Error: ./test.wesl:3:13 error: Invalid token 🐈
|
|
21
|
+
|
|
22
|
+
if(1<1) { 🐈⬛ } else { }
|
|
23
|
+
^^]
|
|
24
|
+
`);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("parse invalid name", () => {
|
|
28
|
+
const src = "var package = 3;";
|
|
29
|
+
expect(() => parseTest(src)).toThrowErrorMatchingInlineSnapshot(`
|
|
30
|
+
[Error: ./test.wesl:1:5 error: Expected identifier after 'var'
|
|
31
|
+
var package = 3;
|
|
32
|
+
^^^^^^^]
|
|
33
|
+
`);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("error highlight", () => {
|
|
37
|
+
expect(errorHighlight("foo", [0, 2]).join("\n")).toBe(`foo
|
|
38
|
+
^^`);
|
|
39
|
+
expect(errorHighlight("foo", [0, 1]).join("\n")).toBe(`foo
|
|
40
|
+
^`);
|
|
41
|
+
expect(errorHighlight("foo", [0, 0]).join("\n")).toBe(`foo
|
|
42
|
+
^`);
|
|
43
|
+
expect(errorHighlight("foo", [1, 2]).join("\n")).toBe(`foo
|
|
44
|
+
^`);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("@must_use with empty parens", () => {
|
|
48
|
+
const src = `@must_use() fn foo() -> u32 { return 0; }`;
|
|
49
|
+
expect(() => parseTest(src)).toThrow();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("semicolon after continuing", () => {
|
|
53
|
+
const src = `fn f() { loop { break; continuing{}; } }`;
|
|
54
|
+
expect(() => parseTest(src)).toThrow();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("package in middle of path", () => {
|
|
58
|
+
const src = `fn f() { foo::package::bar(); }`;
|
|
59
|
+
expect(() => parseTest(src)).toThrowErrorMatchingInlineSnapshot(`
|
|
60
|
+
[Error: ./test.wesl:1:15 error: Expected identifier after '::'
|
|
61
|
+
fn f() { foo::package::bar(); }
|
|
62
|
+
^^^^^^^]
|
|
63
|
+
`);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("super in middle of type path", () => {
|
|
67
|
+
const src = `fn f(a: foo::super::Bar) {}`;
|
|
68
|
+
expect(() => parseTest(src)).toThrowErrorMatchingInlineSnapshot(`
|
|
69
|
+
[Error: ./test.wesl:1:14 error: Expected identifier after '::'
|
|
70
|
+
fn f(a: foo::super::Bar) {}
|
|
71
|
+
^^^^^]
|
|
72
|
+
`);
|
|
73
|
+
});
|