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.
Files changed (141) hide show
  1. package/README.md +31 -0
  2. package/dist/index.js +4468 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/minified.js +3426 -0
  5. package/dist/minified.js.map +1 -0
  6. package/dist/tools/packages/wesl/src/AbstractElems.d.ts +322 -0
  7. package/dist/tools/packages/wesl/src/Assertions.d.ts +27 -0
  8. package/dist/tools/packages/wesl/src/BindIdents.d.ts +70 -0
  9. package/dist/tools/packages/wesl/src/Conditions.d.ts +6 -0
  10. package/dist/tools/packages/wesl/src/FlattenTreeImport.d.ts +11 -0
  11. package/dist/tools/packages/wesl/src/LinkedWesl.d.ts +50 -0
  12. package/dist/tools/packages/wesl/src/Linker.d.ts +87 -0
  13. package/dist/tools/packages/wesl/src/LinkerUtil.d.ts +3 -0
  14. package/dist/tools/packages/wesl/src/LiveDeclarations.d.ts +12 -0
  15. package/dist/tools/packages/wesl/src/LowerAndEmit.d.ts +31 -0
  16. package/dist/tools/packages/wesl/src/Mangler.d.ts +39 -0
  17. package/dist/tools/packages/wesl/src/ParseWESL.d.ts +60 -0
  18. package/dist/tools/packages/wesl/src/ParsedRegistry.d.ts +29 -0
  19. package/dist/tools/packages/wesl/src/PathUtil.d.ts +6 -0
  20. package/dist/tools/packages/wesl/src/RawEmit.d.ts +6 -0
  21. package/dist/tools/packages/wesl/src/Reflection.d.ts +45 -0
  22. package/dist/tools/packages/wesl/src/Scope.d.ts +81 -0
  23. package/dist/tools/packages/wesl/src/StandardTypes.d.ts +13 -0
  24. package/dist/tools/packages/wesl/src/TransformBindingStructs.d.ts +52 -0
  25. package/dist/tools/packages/wesl/src/Util.d.ts +43 -0
  26. package/dist/tools/packages/wesl/src/WESLCollect.d.ts +94 -0
  27. package/dist/tools/packages/wesl/src/WeslBundle.d.ts +13 -0
  28. package/dist/tools/packages/wesl/src/WeslDevice.d.ts +25 -0
  29. package/dist/tools/packages/wesl/src/debug/ASTtoString.d.ts +5 -0
  30. package/dist/tools/packages/wesl/src/debug/ImportToString.d.ts +2 -0
  31. package/dist/tools/packages/wesl/src/debug/LineWrapper.d.ts +21 -0
  32. package/dist/tools/packages/wesl/src/debug/ScopeToString.d.ts +6 -0
  33. package/dist/tools/packages/wesl/src/index.d.ts +11 -0
  34. package/dist/tools/packages/wesl/src/parse/ImportGrammar.d.ts +5 -0
  35. package/dist/tools/packages/wesl/src/parse/Keywords.d.ts +4 -0
  36. package/dist/tools/packages/wesl/src/parse/WeslBaseGrammar.d.ts +5 -0
  37. package/dist/tools/packages/wesl/src/parse/WeslExpression.d.ts +13 -0
  38. package/dist/tools/packages/wesl/src/parse/WeslGrammar.d.ts +80 -0
  39. package/dist/tools/packages/wesl/src/parse/WeslStream.d.ts +44 -0
  40. package/dist/tools/packages/wesl/src/test/BindWESL.test.d.ts +1 -0
  41. package/dist/tools/packages/wesl/src/test/ConditionLinking.test.d.ts +1 -0
  42. package/dist/tools/packages/wesl/src/test/ConditionalTranslationCases.test.d.ts +1 -0
  43. package/dist/tools/packages/wesl/src/test/ErrorLogging.test.d.ts +1 -0
  44. package/dist/tools/packages/wesl/src/test/Expression.test.d.ts +1 -0
  45. package/dist/tools/packages/wesl/src/test/FlattenTreeImport.test.d.ts +1 -0
  46. package/dist/tools/packages/wesl/src/test/ImportCases.test.d.ts +1 -0
  47. package/dist/tools/packages/wesl/src/test/ImportSyntaxCases.test.d.ts +1 -0
  48. package/dist/tools/packages/wesl/src/test/LinkGlob.test.d.ts +1 -0
  49. package/dist/tools/packages/wesl/src/test/LinkPackage.test.d.ts +1 -0
  50. package/dist/tools/packages/wesl/src/test/Linker.test.d.ts +1 -0
  51. package/dist/tools/packages/wesl/src/test/Mangling.test.d.ts +1 -0
  52. package/dist/tools/packages/wesl/src/test/ParseComments.test.d.ts +1 -0
  53. package/dist/tools/packages/wesl/src/test/ParseConditions.test.d.ts +1 -0
  54. package/dist/tools/packages/wesl/src/test/ParseError.test.d.ts +1 -0
  55. package/dist/tools/packages/wesl/src/test/ParseWESL.test.d.ts +1 -0
  56. package/dist/tools/packages/wesl/src/test/PathUtil.test.d.ts +1 -0
  57. package/dist/tools/packages/wesl/src/test/PrettyGrammar.test.d.ts +1 -0
  58. package/dist/tools/packages/wesl/src/test/Reflection.test.d.ts +1 -0
  59. package/dist/tools/packages/wesl/src/test/ScopeWESL.test.d.ts +1 -0
  60. package/dist/tools/packages/wesl/src/test/TestLink.d.ts +21 -0
  61. package/dist/tools/packages/wesl/src/test/TestSetup.d.ts +1 -0
  62. package/dist/tools/packages/wesl/src/test/TestUtil.d.ts +40 -0
  63. package/dist/tools/packages/wesl/src/test/Tokenizer.test.d.ts +1 -0
  64. package/dist/tools/packages/wesl/src/test/TransformBindingStructs.test.d.ts +1 -0
  65. package/dist/tools/packages/wesl/src/test/Util.test.d.ts +1 -0
  66. package/dist/tools/packages/wesl/src/test/VirtualModules.test.d.ts +1 -0
  67. package/dist/tools/packages/wesl/src/test/WeslDevice.test.d.ts +1 -0
  68. package/dist/tools/packages/wesl/src/test/WgslTests.d.ts +0 -0
  69. package/dist/tools/packages/wesl/src/vlq/vlq.d.ts +11 -0
  70. package/package.json +46 -0
  71. package/src/AbstractElems.ts +446 -0
  72. package/src/Assertions.ts +51 -0
  73. package/src/BindIdents.ts +523 -0
  74. package/src/Conditions.ts +74 -0
  75. package/src/FlattenTreeImport.ts +55 -0
  76. package/src/LinkedWesl.ts +184 -0
  77. package/src/Linker.ts +284 -0
  78. package/src/LinkerUtil.ts +29 -0
  79. package/src/LiveDeclarations.ts +31 -0
  80. package/src/LowerAndEmit.ts +413 -0
  81. package/src/Mangler.ts +94 -0
  82. package/src/ParseWESL.ts +157 -0
  83. package/src/ParsedRegistry.ts +120 -0
  84. package/src/PathUtil.ts +31 -0
  85. package/src/RawEmit.ts +102 -0
  86. package/src/Reflection.ts +334 -0
  87. package/src/Scope.ts +162 -0
  88. package/src/StandardTypes.ts +97 -0
  89. package/src/TransformBindingStructs.ts +319 -0
  90. package/src/Util.ts +194 -0
  91. package/src/WESLCollect.ts +614 -0
  92. package/src/WeslBundle.ts +16 -0
  93. package/src/WeslDevice.ts +209 -0
  94. package/src/debug/ASTtoString.ts +290 -0
  95. package/src/debug/ImportToString.ts +29 -0
  96. package/src/debug/LineWrapper.ts +70 -0
  97. package/src/debug/ScopeToString.ts +79 -0
  98. package/src/index.ts +11 -0
  99. package/src/parse/ImportGrammar.ts +157 -0
  100. package/src/parse/Keywords.ts +26 -0
  101. package/src/parse/WeslBaseGrammar.ts +8 -0
  102. package/src/parse/WeslExpression.ts +207 -0
  103. package/src/parse/WeslGrammar.ts +856 -0
  104. package/src/parse/WeslStream.ts +279 -0
  105. package/src/test/BindWESL.test.ts +57 -0
  106. package/src/test/ConditionLinking.test.ts +91 -0
  107. package/src/test/ConditionalTranslationCases.test.ts +56 -0
  108. package/src/test/ErrorLogging.test.ts +30 -0
  109. package/src/test/Expression.test.ts +22 -0
  110. package/src/test/FlattenTreeImport.test.ts +74 -0
  111. package/src/test/ImportCases.test.ts +56 -0
  112. package/src/test/ImportSyntaxCases.test.ts +24 -0
  113. package/src/test/LinkGlob.test.ts +25 -0
  114. package/src/test/LinkPackage.test.ts +26 -0
  115. package/src/test/Linker.test.ts +125 -0
  116. package/src/test/Mangling.test.ts +45 -0
  117. package/src/test/ParseComments.test.ts +36 -0
  118. package/src/test/ParseConditions.test.ts +183 -0
  119. package/src/test/ParseError.test.ts +36 -0
  120. package/src/test/ParseWESL.test.ts +1572 -0
  121. package/src/test/PathUtil.test.ts +34 -0
  122. package/src/test/PrettyGrammar.test.ts +20 -0
  123. package/src/test/Reflection.test.ts +172 -0
  124. package/src/test/ScopeWESL.test.ts +462 -0
  125. package/src/test/TestLink.ts +82 -0
  126. package/src/test/TestSetup.ts +4 -0
  127. package/src/test/TestUtil.ts +126 -0
  128. package/src/test/Tokenizer.test.ts +135 -0
  129. package/src/test/TransformBindingStructs.test.ts +230 -0
  130. package/src/test/Util.test.ts +22 -0
  131. package/src/test/VirtualModules.test.ts +37 -0
  132. package/src/test/WeslDevice.test.ts +265 -0
  133. package/src/test/WgslTests.ts +0 -0
  134. package/src/test/__snapshots__/ParseDirectives.test.ts.snap +25 -0
  135. package/src/test/__snapshots__/ParseWESL.test.ts.snap +119 -0
  136. package/src/test/__snapshots__/RustDirective.test.ts.snap +359 -0
  137. package/src/test/wgsl_1/main.wgsl +3 -0
  138. package/src/test/wgsl_1/util.wgsl +1 -0
  139. package/src/test/wgsl_2/main2.wgsl +3 -0
  140. package/src/test/wgsl_2/util2.wgsl +1 -0
  141. package/src/vlq/vlq.ts +94 -0
@@ -0,0 +1,44 @@
1
+ import { Stream, TypedToken } from '../../../mini-parse/src';
2
+ export type WeslTokenKind = "word" | "keyword" | "number" | "symbol";
3
+ export type WeslToken<Kind extends WeslTokenKind = WeslTokenKind> = TypedToken<Kind>;
4
+ /** Checks if a word is a valid WGSL ident, and not a keyword */
5
+ export declare function isIdent(text: string): boolean;
6
+ /** To mark parts of the grammar implementation that are WESL specific extensions */
7
+ export declare function weslExtension<T>(combinator: T): T;
8
+ export declare class WeslStream implements Stream<WeslToken> {
9
+ src: string;
10
+ private stream;
11
+ /** New line */
12
+ private eolPattern;
13
+ /** Block comments */
14
+ private blockCommentPattern;
15
+ constructor(src: string);
16
+ checkpoint(): number;
17
+ reset(position: number): void;
18
+ nextToken(): WeslToken | null;
19
+ private skipToEol;
20
+ private skipBlockComment;
21
+ /**
22
+ * Only matches the `<` token if it is a template
23
+ * Precondition: An ident was parsed right before this.
24
+ * Runs the [template list discovery algorithm](https://www.w3.org/TR/WGSL/#template-list-discovery).
25
+ */
26
+ nextTemplateStartToken(): (WeslToken & {
27
+ kind: "symbol";
28
+ }) | null;
29
+ nextTemplateEndToken(): (WeslToken & {
30
+ kind: "symbol";
31
+ }) | null;
32
+ isTemplateStart(afterToken: number): boolean;
33
+ /**
34
+ * Call this after consuming an opening bracket.
35
+ * Skips until a closing bracket. This also consumes the closing bracket.
36
+ */
37
+ skipBracketsTo(closingBracket: string): void;
38
+ }
39
+ export declare const templateOpen: import('../../../mini-parse/src').Parser<import('../../../mini-parse/src').ParserStream, WeslToken<WeslTokenKind> & {
40
+ kind: "symbol";
41
+ }>;
42
+ export declare const templateClose: import('../../../mini-parse/src').Parser<import('../../../mini-parse/src').ParserStream, WeslToken<WeslTokenKind> & {
43
+ kind: "symbol";
44
+ }>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ import { RunnerTestSuite } from 'vitest';
2
+ import { WgslTestSrc } from '../../../../../wesl-testsuite/src';
3
+ import { ManglerFn } from '../Mangler.ts';
4
+ /**
5
+ * Link wesl sources and compare the linked wgsl vs expectations.
6
+ * Ignores blank lines and initial blank columns.
7
+ *
8
+ * (for tests)
9
+ */
10
+ export declare function testLink(weslSrc: Record<string, string>, rootModuleName: string, expectedWgsl: string, mangler?: ManglerFn): Promise<void>;
11
+ type TestCaseMap = Map<string, WgslTestSrc>;
12
+ /**
13
+ * Test link one test case from one a shared test suite
14
+ * (ImportCases, ConditionalTranslationCases, etc.)
15
+ */
16
+ export declare function testFromCase(name: string, cases: TestCaseMap): Promise<void>;
17
+ /**
18
+ * for afterAll(), to verify that all cases are covered from one of the shared test suites
19
+ */
20
+ export declare function verifyCaseCoverage(caseList: WgslTestSrc[]): (suite: RunnerTestSuite) => void;
21
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,40 @@
1
+ import { Parser, Stream } from '../../../mini-parse/src';
2
+ import { TestParseResult } from '../../../mini-parse/src/test-util';
3
+ import { BoundAndTransformed, ParsedRegistry } from '..';
4
+ import { LinkParams } from '../Linker.js';
5
+ import { WeslToken } from '../parse/WeslStream.js';
6
+ import { WeslAST } from '../ParseWESL.js';
7
+ export declare function testAppParse<T>(parser: Parser<Stream<WeslToken>, T>, src: string): TestParseResult<T, WeslAST>;
8
+ /** Convenience wrapper to link wgsl for tests.
9
+ * The first module is named "./test.wesl",
10
+ * subsequent modules are named "./file1.wesl", "./file2.wesl", etc.
11
+ */
12
+ export declare function linkTest(...rawWgsl: string[]): Promise<string>;
13
+ export type LinkTestOpts = Pick<LinkParams, "conditions" | "libs" | "config" | "virtualLibs" | "constants" | "mangler">;
14
+ export declare function linkTestOpts(opts: LinkTestOpts, ...rawWgsl: string[]): Promise<string>;
15
+ /** Link wesl for tests, and return the console log as well */
16
+ export declare function linkWithLog(...rawWgsl: string[]): Promise<{
17
+ log: string;
18
+ result: string;
19
+ }>;
20
+ /** Link wesl for tests, and return the console log as well.
21
+ * Quietly swallow any exceptions thrown */
22
+ export declare function linkWithLogQuietly(...rawWgsl: string[]): Promise<{
23
+ log: string;
24
+ result: string;
25
+ }>;
26
+ /** parse wesl for testing, and return the AST */
27
+ export declare function parseTest(src: string): WeslAST;
28
+ /** test w/o any log collection, to not confuse debugging */
29
+ export declare function parseTestRaw(src: string): WeslAST;
30
+ interface BindTestResult {
31
+ bound: BoundAndTransformed;
32
+ registry: ParsedRegistry;
33
+ }
34
+ /**
35
+ * Test parsing and binding some wesl src.
36
+ * @return both the bound result and the internal registry.
37
+ * (since binding mutates the AST, it's useful for tests to review)
38
+ */
39
+ export declare function bindTest(...rawWesl: string[]): BindTestResult;
40
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,11 @@
1
+ /*!
2
+ Copyright (c) 2017-2021 [these people](https://github.com/Rich-Harris/vlq/graphs/contributors)
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+ */
10
+ export declare function decodeVlq(string: string): number[];
11
+ export declare function encodeVlq(value: number | number[]): string;
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "wesl",
3
+ "version": "0.6.0-pre10",
4
+ "files": [
5
+ "dist",
6
+ "src"
7
+ ],
8
+ "type": "module",
9
+ "repository": "github:wgsl-tooling-wg/wesl-js",
10
+ "main": "dist/index.js",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/tools/packages/wesl/src/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ },
16
+ "./minified": {
17
+ "types": "./dist/tools/packages/wesl/src/index.d.ts",
18
+ "import": "./dist/minified.js"
19
+ }
20
+ },
21
+ "dependencies": {
22
+ "mini-parse": "0.6.0-pre10"
23
+ },
24
+ "devDependencies": {
25
+ "ncp": "^2.0.0",
26
+ "rollup-plugin-visualizer": "^5.14.0",
27
+ "terser": "^5.38.1",
28
+ "vite-plugin-dts": "^4.5.0",
29
+ "random_wgsl": "0.6.0-pre10"
30
+ },
31
+ "scripts": {
32
+ "echo": "echo",
33
+ "build": "run-s build:main build:minified",
34
+ "build:main": "vite build",
35
+ "build:minified": "vite build --config minified.vite.config.js",
36
+ "build:sizetest": "vite build --config sizetest.vite.config.js",
37
+ "build:brotli-size": "tsx ./scripts/brotli.ts dist/sized.cjs",
38
+ "build:size": "run-s build:sizetest build:brotli-size",
39
+ "typecheck": "tsc",
40
+ "format": "prettier . --write",
41
+ "lint": "eslint src",
42
+ "organize": "organize-imports-cli tsconfig.json",
43
+ "test": "vitest",
44
+ "test:once": "vitest run"
45
+ }
46
+ }