wesl 0.6.0-pre10
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/README.md +31 -0
- package/dist/index.js +4468 -0
- package/dist/index.js.map +1 -0
- package/dist/minified.js +3426 -0
- package/dist/minified.js.map +1 -0
- package/dist/tools/packages/wesl/src/AbstractElems.d.ts +322 -0
- package/dist/tools/packages/wesl/src/Assertions.d.ts +27 -0
- package/dist/tools/packages/wesl/src/BindIdents.d.ts +70 -0
- package/dist/tools/packages/wesl/src/Conditions.d.ts +6 -0
- package/dist/tools/packages/wesl/src/FlattenTreeImport.d.ts +11 -0
- package/dist/tools/packages/wesl/src/LinkedWesl.d.ts +50 -0
- package/dist/tools/packages/wesl/src/Linker.d.ts +87 -0
- package/dist/tools/packages/wesl/src/LinkerUtil.d.ts +3 -0
- package/dist/tools/packages/wesl/src/LiveDeclarations.d.ts +12 -0
- package/dist/tools/packages/wesl/src/LowerAndEmit.d.ts +31 -0
- package/dist/tools/packages/wesl/src/Mangler.d.ts +39 -0
- package/dist/tools/packages/wesl/src/ParseWESL.d.ts +60 -0
- package/dist/tools/packages/wesl/src/ParsedRegistry.d.ts +29 -0
- package/dist/tools/packages/wesl/src/PathUtil.d.ts +6 -0
- package/dist/tools/packages/wesl/src/RawEmit.d.ts +6 -0
- package/dist/tools/packages/wesl/src/Reflection.d.ts +45 -0
- package/dist/tools/packages/wesl/src/Scope.d.ts +81 -0
- package/dist/tools/packages/wesl/src/StandardTypes.d.ts +13 -0
- package/dist/tools/packages/wesl/src/TransformBindingStructs.d.ts +52 -0
- package/dist/tools/packages/wesl/src/Util.d.ts +43 -0
- package/dist/tools/packages/wesl/src/WESLCollect.d.ts +94 -0
- package/dist/tools/packages/wesl/src/WeslBundle.d.ts +13 -0
- package/dist/tools/packages/wesl/src/WeslDevice.d.ts +25 -0
- package/dist/tools/packages/wesl/src/debug/ASTtoString.d.ts +5 -0
- package/dist/tools/packages/wesl/src/debug/ImportToString.d.ts +2 -0
- package/dist/tools/packages/wesl/src/debug/LineWrapper.d.ts +21 -0
- package/dist/tools/packages/wesl/src/debug/ScopeToString.d.ts +6 -0
- package/dist/tools/packages/wesl/src/index.d.ts +11 -0
- package/dist/tools/packages/wesl/src/parse/ImportGrammar.d.ts +5 -0
- package/dist/tools/packages/wesl/src/parse/Keywords.d.ts +4 -0
- package/dist/tools/packages/wesl/src/parse/WeslBaseGrammar.d.ts +5 -0
- package/dist/tools/packages/wesl/src/parse/WeslExpression.d.ts +13 -0
- package/dist/tools/packages/wesl/src/parse/WeslGrammar.d.ts +80 -0
- package/dist/tools/packages/wesl/src/parse/WeslStream.d.ts +44 -0
- package/dist/tools/packages/wesl/src/test/BindWESL.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ConditionLinking.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ConditionalTranslationCases.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ErrorLogging.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/Expression.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/FlattenTreeImport.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ImportCases.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ImportSyntaxCases.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/LinkGlob.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/LinkPackage.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/Linker.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/Mangling.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ParseComments.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ParseConditions.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ParseError.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ParseWESL.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/PathUtil.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/PrettyGrammar.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/Reflection.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/ScopeWESL.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/TestLink.d.ts +21 -0
- package/dist/tools/packages/wesl/src/test/TestSetup.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/TestUtil.d.ts +40 -0
- package/dist/tools/packages/wesl/src/test/Tokenizer.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/TransformBindingStructs.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/Util.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/VirtualModules.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/WeslDevice.test.d.ts +1 -0
- package/dist/tools/packages/wesl/src/test/WgslTests.d.ts +0 -0
- package/dist/tools/packages/wesl/src/vlq/vlq.d.ts +11 -0
- package/package.json +46 -0
- package/src/AbstractElems.ts +446 -0
- package/src/Assertions.ts +51 -0
- package/src/BindIdents.ts +523 -0
- package/src/Conditions.ts +74 -0
- package/src/FlattenTreeImport.ts +55 -0
- package/src/LinkedWesl.ts +184 -0
- package/src/Linker.ts +284 -0
- package/src/LinkerUtil.ts +29 -0
- package/src/LiveDeclarations.ts +31 -0
- package/src/LowerAndEmit.ts +413 -0
- package/src/Mangler.ts +94 -0
- package/src/ParseWESL.ts +157 -0
- package/src/ParsedRegistry.ts +120 -0
- package/src/PathUtil.ts +31 -0
- package/src/RawEmit.ts +102 -0
- package/src/Reflection.ts +334 -0
- package/src/Scope.ts +162 -0
- package/src/StandardTypes.ts +97 -0
- package/src/TransformBindingStructs.ts +319 -0
- package/src/Util.ts +194 -0
- package/src/WESLCollect.ts +614 -0
- package/src/WeslBundle.ts +16 -0
- package/src/WeslDevice.ts +209 -0
- package/src/debug/ASTtoString.ts +290 -0
- package/src/debug/ImportToString.ts +29 -0
- package/src/debug/LineWrapper.ts +70 -0
- package/src/debug/ScopeToString.ts +79 -0
- package/src/index.ts +11 -0
- package/src/parse/ImportGrammar.ts +157 -0
- package/src/parse/Keywords.ts +26 -0
- package/src/parse/WeslBaseGrammar.ts +8 -0
- package/src/parse/WeslExpression.ts +207 -0
- package/src/parse/WeslGrammar.ts +856 -0
- package/src/parse/WeslStream.ts +279 -0
- package/src/test/BindWESL.test.ts +57 -0
- package/src/test/ConditionLinking.test.ts +91 -0
- package/src/test/ConditionalTranslationCases.test.ts +56 -0
- package/src/test/ErrorLogging.test.ts +30 -0
- package/src/test/Expression.test.ts +22 -0
- package/src/test/FlattenTreeImport.test.ts +74 -0
- package/src/test/ImportCases.test.ts +56 -0
- package/src/test/ImportSyntaxCases.test.ts +24 -0
- package/src/test/LinkGlob.test.ts +25 -0
- package/src/test/LinkPackage.test.ts +26 -0
- package/src/test/Linker.test.ts +125 -0
- package/src/test/Mangling.test.ts +45 -0
- package/src/test/ParseComments.test.ts +36 -0
- package/src/test/ParseConditions.test.ts +183 -0
- package/src/test/ParseError.test.ts +36 -0
- package/src/test/ParseWESL.test.ts +1572 -0
- package/src/test/PathUtil.test.ts +34 -0
- package/src/test/PrettyGrammar.test.ts +20 -0
- package/src/test/Reflection.test.ts +172 -0
- package/src/test/ScopeWESL.test.ts +462 -0
- package/src/test/TestLink.ts +82 -0
- package/src/test/TestSetup.ts +4 -0
- package/src/test/TestUtil.ts +126 -0
- package/src/test/Tokenizer.test.ts +135 -0
- package/src/test/TransformBindingStructs.test.ts +230 -0
- package/src/test/Util.test.ts +22 -0
- package/src/test/VirtualModules.test.ts +37 -0
- package/src/test/WeslDevice.test.ts +265 -0
- package/src/test/WgslTests.ts +0 -0
- package/src/test/__snapshots__/ParseDirectives.test.ts.snap +25 -0
- package/src/test/__snapshots__/ParseWESL.test.ts.snap +119 -0
- package/src/test/__snapshots__/RustDirective.test.ts.snap +359 -0
- package/src/test/wgsl_1/main.wgsl +3 -0
- package/src/test/wgsl_1/util.wgsl +1 -0
- package/src/test/wgsl_2/main2.wgsl +3 -0
- package/src/test/wgsl_2/util2.wgsl +1 -0
- package/src/vlq/vlq.ts +94 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
import { expect, test } from "vitest";
|
|
3
|
+
import { link } from "../Linker.js";
|
|
4
|
+
|
|
5
|
+
const wgsl1: Record<string, string> = import.meta.glob("./wgsl_1/*.wgsl", {
|
|
6
|
+
query: "?raw",
|
|
7
|
+
eager: true,
|
|
8
|
+
import: "default",
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const wgsl2: Record<string, string> = import.meta.glob("./wgsl_2/*.wgsl", {
|
|
12
|
+
query: "?raw",
|
|
13
|
+
eager: true,
|
|
14
|
+
import: "default",
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("basic import glob", async () => {
|
|
18
|
+
const linked = await link({ weslSrc: wgsl1, rootModuleName: "wgsl_1/main" });
|
|
19
|
+
expect(linked.dest).toContain("fn bar()");
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("#import from path ./util", async () => {
|
|
23
|
+
const linked = await link({ weslSrc: wgsl2, rootModuleName: "wgsl_2/main2" });
|
|
24
|
+
expect(linked.dest).toContain("fn bar()");
|
|
25
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { expectNoLogAsync } from "mini-parse/test-util";
|
|
2
|
+
import lib from "random_wgsl";
|
|
3
|
+
import { expect, test } from "vitest";
|
|
4
|
+
import { link } from "../Linker.ts";
|
|
5
|
+
|
|
6
|
+
test("import rand() from a package", async () => {
|
|
7
|
+
const src = `
|
|
8
|
+
import random_wgsl::pcg_2u_3f;
|
|
9
|
+
|
|
10
|
+
struct Uniforms { frame: u32 }
|
|
11
|
+
@binding(0) @group(0) var<uniform> u: Uniforms;
|
|
12
|
+
|
|
13
|
+
@fragment
|
|
14
|
+
fn fragmentMain(@builtin(position) pos: vec4f) -> @location(0) vec4f {
|
|
15
|
+
let rand = pcg_2u_3f(vec2u(pos.xy) + u.frame);
|
|
16
|
+
return vec4(rand, 1f);
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
|
|
20
|
+
const weslSrc = { "./main.wesl": src };
|
|
21
|
+
const result = await expectNoLogAsync(async () =>
|
|
22
|
+
link({ weslSrc, rootModuleName: "./main.wesl", libs: [lib] }),
|
|
23
|
+
);
|
|
24
|
+
expect(result.dest).toContain("fn pcg_2u_3f");
|
|
25
|
+
expect(result.dest).not.toContain("sinRand");
|
|
26
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { expectTrimmedMatch } from "mini-parse/vitest-util";
|
|
2
|
+
import { test } from "vitest";
|
|
3
|
+
import { linkTest } from "./TestUtil.js";
|
|
4
|
+
|
|
5
|
+
test("link global var", async () => {
|
|
6
|
+
const src = `var x: i32 = 1;`;
|
|
7
|
+
const result = await linkTest(src);
|
|
8
|
+
expectTrimmedMatch(result, src);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test("link an alias", async () => {
|
|
12
|
+
const src = `
|
|
13
|
+
alias Num = f32;
|
|
14
|
+
|
|
15
|
+
fn main() { Num(1.0); }
|
|
16
|
+
`;
|
|
17
|
+
const result = await linkTest(src);
|
|
18
|
+
expectTrimmedMatch(result, src);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("link a const_assert", async () => {
|
|
22
|
+
const src = `
|
|
23
|
+
var x = 1;
|
|
24
|
+
var y = 2;
|
|
25
|
+
const_assert x < y;
|
|
26
|
+
`;
|
|
27
|
+
const result = await linkTest(src);
|
|
28
|
+
expectTrimmedMatch(result, src);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("link a struct", async () => {
|
|
32
|
+
const src = `
|
|
33
|
+
struct Point {
|
|
34
|
+
x: i32,
|
|
35
|
+
y: i32,
|
|
36
|
+
}
|
|
37
|
+
`;
|
|
38
|
+
const result = await linkTest(src);
|
|
39
|
+
expectTrimmedMatch(result, src);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("link a fn", async () => {
|
|
43
|
+
const src = `
|
|
44
|
+
fn foo(x: i32, y: u32) -> f32 {
|
|
45
|
+
return 1.0;
|
|
46
|
+
}`;
|
|
47
|
+
const result = await linkTest(src);
|
|
48
|
+
expectTrimmedMatch(result, src);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("handle a ptr type", async () => {
|
|
52
|
+
const src = `
|
|
53
|
+
fn uint_bitfieldExtract_u1_i1_i1_(value: ptr<function, u32>, bits: ptr<function, i32>) -> u32 { }
|
|
54
|
+
`;
|
|
55
|
+
const result = await linkTest(src);
|
|
56
|
+
expectTrimmedMatch(result, src);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("struct after var", async () => {
|
|
60
|
+
const src = `
|
|
61
|
+
var config: TwoPassConfig;
|
|
62
|
+
|
|
63
|
+
struct TwoPassConfig { x: u32 }
|
|
64
|
+
`;
|
|
65
|
+
const result = await linkTest(src);
|
|
66
|
+
expectTrimmedMatch(result, src);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("type inside fn with same name as fn", async () => {
|
|
70
|
+
// illegal but shouldn't hang
|
|
71
|
+
const src = `
|
|
72
|
+
fn foo() {
|
|
73
|
+
var a:foo;
|
|
74
|
+
}
|
|
75
|
+
fn bar() {}
|
|
76
|
+
`;
|
|
77
|
+
const result = await linkTest(src);
|
|
78
|
+
expectTrimmedMatch(result, src);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("call cross reference", async () => {
|
|
82
|
+
const src = `
|
|
83
|
+
fn foo() {
|
|
84
|
+
bar();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
fn bar() {
|
|
88
|
+
foo();
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
const result = await linkTest(src);
|
|
93
|
+
expectTrimmedMatch(result, src);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("struct self reference", async () => {
|
|
97
|
+
const src = `
|
|
98
|
+
struct A {
|
|
99
|
+
a: A,
|
|
100
|
+
b: B,
|
|
101
|
+
}
|
|
102
|
+
struct B { f: f32 }
|
|
103
|
+
`;
|
|
104
|
+
|
|
105
|
+
const result = await linkTest(src);
|
|
106
|
+
expectTrimmedMatch(result, src);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test("parse texture_storage_2d with texture format in typical type position", async () => {
|
|
110
|
+
const src = `var t: texture_storage_2d<rgba8unorm, write>;`;
|
|
111
|
+
const result = await linkTest(src);
|
|
112
|
+
expectTrimmedMatch(result, src);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("struct member ref with extra component_or_swizzle", async () => {
|
|
116
|
+
const src = `
|
|
117
|
+
struct C { p: P }
|
|
118
|
+
struct P { x: u32 }
|
|
119
|
+
fn foo(c: C) {
|
|
120
|
+
let a = c.p.x;
|
|
121
|
+
}
|
|
122
|
+
`;
|
|
123
|
+
const result = await linkTest(src);
|
|
124
|
+
expectTrimmedMatch(result, src);
|
|
125
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { expectTrimmedMatch } from "mini-parse/vitest-util";
|
|
2
|
+
import { test } from "vitest";
|
|
3
|
+
import { link } from "../Linker.ts";
|
|
4
|
+
import { underscoreMangle } from "../Mangler.ts";
|
|
5
|
+
import { linkTestOpts } from "./TestUtil.ts";
|
|
6
|
+
|
|
7
|
+
test("underscoreMangle", async () => {
|
|
8
|
+
const main = `
|
|
9
|
+
import package::file1::bar;
|
|
10
|
+
fn main() { bar(); }
|
|
11
|
+
`;
|
|
12
|
+
const file1 = `
|
|
13
|
+
fn bar() {};
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
const linked = await linkTestOpts({ mangler: underscoreMangle }, main, file1);
|
|
17
|
+
const expected = `
|
|
18
|
+
fn main() { package_file1_bar(); }
|
|
19
|
+
fn package_file1_bar() {}
|
|
20
|
+
`;
|
|
21
|
+
expectTrimmedMatch(linked, expected);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("underscoreMangle longer ident", async () => {
|
|
25
|
+
const main = `
|
|
26
|
+
import package::container::file1::bar;
|
|
27
|
+
fn main() { bar(); }
|
|
28
|
+
`;
|
|
29
|
+
const file1 = `
|
|
30
|
+
fn bar() {};
|
|
31
|
+
`;
|
|
32
|
+
const weslSrc = { "./main.wesl": main, "./container/file1.wesl": file1 };
|
|
33
|
+
|
|
34
|
+
const linked = await link({
|
|
35
|
+
mangler: underscoreMangle,
|
|
36
|
+
weslSrc,
|
|
37
|
+
debugWeslRoot: "main",
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const expected = `
|
|
41
|
+
fn main() { package_container_file1_bar(); }
|
|
42
|
+
fn package_container_file1_bar() {}
|
|
43
|
+
`;
|
|
44
|
+
expectTrimmedMatch(linked.dest, expected);
|
|
45
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { expectNoLog } from "mini-parse/test-util";
|
|
2
|
+
|
|
3
|
+
import { expect, test } from "vitest";
|
|
4
|
+
import { astToString } from "../debug/ASTtoString.js";
|
|
5
|
+
import { parseWESL } from "../ParseWESL.js";
|
|
6
|
+
|
|
7
|
+
test("parse fn with line comment", () => {
|
|
8
|
+
const src = `
|
|
9
|
+
fn binaryOp() { // binOpImpl
|
|
10
|
+
}`;
|
|
11
|
+
const parsed = parseWESL(src);
|
|
12
|
+
expect(astToString(parsed.moduleElem)).toMatchInlineSnapshot(`
|
|
13
|
+
"module
|
|
14
|
+
text '
|
|
15
|
+
'
|
|
16
|
+
fn binaryOp()
|
|
17
|
+
decl %binaryOp
|
|
18
|
+
statement
|
|
19
|
+
text '{ // binOpImpl
|
|
20
|
+
}'"
|
|
21
|
+
`);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("parse empty line comment", () => {
|
|
25
|
+
const src = `
|
|
26
|
+
var workgroupThreads= 4; //
|
|
27
|
+
`;
|
|
28
|
+
expectNoLog(() => parseWESL(src));
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("parse line comment with #replace", () => {
|
|
32
|
+
const src = `
|
|
33
|
+
const workgroupThreads= 4; // #replace 4=workgroupThreads
|
|
34
|
+
`;
|
|
35
|
+
expectNoLog(() => parseWESL(src));
|
|
36
|
+
});
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { astToString } from "../debug/ASTtoString.ts";
|
|
3
|
+
import { parseTest } from "./TestUtil.ts";
|
|
4
|
+
|
|
5
|
+
test("parse complex condition", () => {
|
|
6
|
+
const ast = parseTest("@if(true || (!foo&&!!false) )\nfn a() {}");
|
|
7
|
+
expect(astToString(ast.moduleElem)).toMatchInlineSnapshot(`
|
|
8
|
+
"module
|
|
9
|
+
fn a() @if
|
|
10
|
+
attribute @if(true || (!foo && !!false))
|
|
11
|
+
decl %a
|
|
12
|
+
statement
|
|
13
|
+
text '{}'"
|
|
14
|
+
`);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test("@if(false) enable f16", () => {
|
|
18
|
+
const src = `
|
|
19
|
+
@if(false) enable f16;
|
|
20
|
+
`;
|
|
21
|
+
const ast = parseTest(src);
|
|
22
|
+
const astString = astToString(ast.moduleElem);
|
|
23
|
+
expect(astString).toMatchInlineSnapshot(`
|
|
24
|
+
"module
|
|
25
|
+
text '
|
|
26
|
+
'
|
|
27
|
+
attribute @if(false)
|
|
28
|
+
directive enable f16 @if
|
|
29
|
+
text '
|
|
30
|
+
'"
|
|
31
|
+
`);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("@if(false) const_assert true;", () => {
|
|
35
|
+
const src = `
|
|
36
|
+
@if(false) const_assert true;
|
|
37
|
+
`;
|
|
38
|
+
const ast = parseTest(src);
|
|
39
|
+
const astString = astToString(ast.moduleElem);
|
|
40
|
+
expect(astString).toMatchInlineSnapshot(`
|
|
41
|
+
"module
|
|
42
|
+
text '
|
|
43
|
+
'
|
|
44
|
+
assert
|
|
45
|
+
attribute @if(false)
|
|
46
|
+
text ' const_assert true;'
|
|
47
|
+
text '
|
|
48
|
+
'"
|
|
49
|
+
`);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("@if(true) var x = 7", () => {
|
|
53
|
+
const src = `
|
|
54
|
+
@if(true) var x = 7;
|
|
55
|
+
`;
|
|
56
|
+
const ast = parseTest(src);
|
|
57
|
+
const astString = astToString(ast.moduleElem);
|
|
58
|
+
expect(astString).toMatchInlineSnapshot(`
|
|
59
|
+
"module
|
|
60
|
+
text '
|
|
61
|
+
'
|
|
62
|
+
gvar %x @if
|
|
63
|
+
attribute @if(true)
|
|
64
|
+
text ' var '
|
|
65
|
+
typeDecl %x
|
|
66
|
+
decl %x
|
|
67
|
+
text ' = 7;'
|
|
68
|
+
text '
|
|
69
|
+
'"
|
|
70
|
+
`);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("conditional statement", () => {
|
|
74
|
+
const src = `
|
|
75
|
+
fn main() {
|
|
76
|
+
var x = 1;
|
|
77
|
+
@if(true) x = 2 ;
|
|
78
|
+
}
|
|
79
|
+
`;
|
|
80
|
+
const ast = parseTest(src);
|
|
81
|
+
const astString = astToString(ast.moduleElem);
|
|
82
|
+
expect(astString).toMatchInlineSnapshot(`
|
|
83
|
+
"module
|
|
84
|
+
text '
|
|
85
|
+
'
|
|
86
|
+
fn main()
|
|
87
|
+
decl %main
|
|
88
|
+
statement
|
|
89
|
+
text '{
|
|
90
|
+
'
|
|
91
|
+
var %x
|
|
92
|
+
text 'var '
|
|
93
|
+
typeDecl %x
|
|
94
|
+
decl %x
|
|
95
|
+
text ' = 1'
|
|
96
|
+
text ';
|
|
97
|
+
'
|
|
98
|
+
statement @if
|
|
99
|
+
attribute @if(true)
|
|
100
|
+
text ' '
|
|
101
|
+
ref x
|
|
102
|
+
text ' = 2 ;'
|
|
103
|
+
text '
|
|
104
|
+
}'
|
|
105
|
+
text '
|
|
106
|
+
'"
|
|
107
|
+
`);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("compound statement", () => {
|
|
111
|
+
const src = `
|
|
112
|
+
fn main() {
|
|
113
|
+
@if(false) {
|
|
114
|
+
let x = 1;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
`;
|
|
118
|
+
const ast = parseTest(src);
|
|
119
|
+
const astString = astToString(ast.moduleElem);
|
|
120
|
+
expect(astString).toMatchInlineSnapshot(`
|
|
121
|
+
"module
|
|
122
|
+
text '
|
|
123
|
+
'
|
|
124
|
+
fn main()
|
|
125
|
+
decl %main
|
|
126
|
+
statement
|
|
127
|
+
text '{
|
|
128
|
+
'
|
|
129
|
+
statement @if
|
|
130
|
+
attribute @if(false)
|
|
131
|
+
text ' {
|
|
132
|
+
let '
|
|
133
|
+
typeDecl %x
|
|
134
|
+
decl %x
|
|
135
|
+
text ' = 1;
|
|
136
|
+
}'
|
|
137
|
+
text '
|
|
138
|
+
}'
|
|
139
|
+
text '
|
|
140
|
+
'"
|
|
141
|
+
`);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test("conditional local var", () => {
|
|
145
|
+
const src = `
|
|
146
|
+
fn main() {
|
|
147
|
+
@if(true) var x = 1;
|
|
148
|
+
}
|
|
149
|
+
`;
|
|
150
|
+
const ast = parseTest(src);
|
|
151
|
+
const astString = astToString(ast.moduleElem);
|
|
152
|
+
expect(astString).toMatchInlineSnapshot(`
|
|
153
|
+
"module
|
|
154
|
+
text '
|
|
155
|
+
'
|
|
156
|
+
fn main()
|
|
157
|
+
decl %main
|
|
158
|
+
statement
|
|
159
|
+
text '{
|
|
160
|
+
'
|
|
161
|
+
statement @if
|
|
162
|
+
attribute @if(true)
|
|
163
|
+
text ' '
|
|
164
|
+
var %x
|
|
165
|
+
text 'var '
|
|
166
|
+
typeDecl %x
|
|
167
|
+
decl %x
|
|
168
|
+
text ' = 1'
|
|
169
|
+
text ';'
|
|
170
|
+
text '
|
|
171
|
+
}'
|
|
172
|
+
text '
|
|
173
|
+
'"
|
|
174
|
+
`);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
// test("", () => {
|
|
178
|
+
// const src = `
|
|
179
|
+
// `;
|
|
180
|
+
// const ast = parseTest(src);
|
|
181
|
+
// const astString = astToString(ast.moduleElem);
|
|
182
|
+
// expect(astString).toMatchInlineSnapshot('tbd');
|
|
183
|
+
// });
|
|
@@ -0,0 +1,36 @@
|
|
|
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:15 error: invalid ident
|
|
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:15 error: Invalid token 🐈
|
|
21
|
+
|
|
22
|
+
if(1<1) { 🐈⬛ } else { }
|
|
23
|
+
^]
|
|
24
|
+
`);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("error highlight", () => {
|
|
28
|
+
expect(errorHighlight("foo", [0, 2]).join("\n")).toBe(`foo
|
|
29
|
+
^^`);
|
|
30
|
+
expect(errorHighlight("foo", [0, 1]).join("\n")).toBe(`foo
|
|
31
|
+
^`);
|
|
32
|
+
expect(errorHighlight("foo", [0, 0]).join("\n")).toBe(`foo
|
|
33
|
+
^`);
|
|
34
|
+
expect(errorHighlight("foo", [1, 2]).join("\n")).toBe(`foo
|
|
35
|
+
^`);
|
|
36
|
+
});
|