@shaderfrog/core 2.0.0-beta.0 → 2.0.0-beta.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shaderfrog/core",
3
- "version": "2.0.0-beta.0",
3
+ "version": "2.0.0-beta.2",
4
4
  "description": "Shaderfrog core",
5
5
  "type": "module",
6
6
  "files": [
@@ -34,13 +34,14 @@
34
34
  "@babel/core": "^7.21.8",
35
35
  "@babel/preset-env": "^7.21.5",
36
36
  "@babel/preset-typescript": "^7.21.5",
37
+ "@shaderfrog/glsl-parser": "^5.0.0-beta.4",
37
38
  "@swc/core": "^1.6.7",
38
39
  "@types/lodash.groupby": "^4.6.7",
39
40
  "@types/three": "^0.156.0",
40
41
  "babylonjs": "^6.2.0",
41
42
  "prettier": "^3.3.2",
42
43
  "three": "^0.156.1",
43
- "typescript": "^5.0.4",
44
+ "typescript": "^5.5.3",
44
45
  "vitest": "^1.6.0"
45
46
  },
46
47
  "dependencies": {
@@ -11,5 +11,5 @@ export interface InjectStrategy extends BaseStrategy {
11
11
  * Inject source code into an AST, in a find-and-replace style. This only
12
12
  * operates on statements right now
13
13
  */
14
- export declare const injectStrategy: (config: InjectStrategy['config']) => InjectStrategy;
14
+ export declare const injectStrategy: (config: InjectStrategy["config"]) => InjectStrategy;
15
15
  export declare const applyInjectStrategy: ApplyStrategy<InjectStrategy>;
package/util/ast.d.ts CHANGED
@@ -36,6 +36,7 @@ export declare const makeFnBodyStatementWithScopes: (body: string) => {
36
36
  };
37
37
  export declare const findFn: (name: string) => (ast: Program) => FunctionNode | undefined;
38
38
  export declare const findMain: (ast: Program) => FunctionNode | undefined;
39
+ export declare const findMainOrThrow: (ast: Program) => FunctionNode;
39
40
  export declare const returnGlPosition: (fnName: string, ast: Program) => void;
40
41
  export declare const returnGlPositionHardCoded: (fnName: string, ast: Program, returnType: string, hardCodedReturn: string) => void;
41
42
  export declare const returnGlPositionVec3Right: (fnName: string, ast: Program) => void;
package/util/ast.js CHANGED
@@ -254,6 +254,13 @@ export var findFn = function (name) {
254
254
  };
255
255
  };
256
256
  export var findMain = findFn('main');
257
+ export var findMainOrThrow = function (ast) {
258
+ var main = findMain(ast);
259
+ if (!main) {
260
+ throw new Error('No main function found!');
261
+ }
262
+ return main;
263
+ };
257
264
  export var returnGlPosition = function (fnName, ast) {
258
265
  return convertVertexMain(fnName, ast, 'vec4', function (assign) { return assign.expression.right; });
259
266
  };
@@ -317,10 +324,7 @@ var convertVertexMain = function (fnName, ast, returnType, generateRight) {
317
324
  */
318
325
  export var convert300MainToReturn = function (ast) {
319
326
  // Convert the main function to return a vec4
320
- var main = findMain(ast);
321
- if (!main) {
322
- throw new Error('No main function found!');
323
- }
327
+ var main = findMainOrThrow(ast);
324
328
  main.prototype.header.returnType.specifier.specifier.token =
325
329
  'vec4';
326
330
  // Find the output variable, as in "pc_fragColor" from "out highp vec4 pc_fragColor;"
package/util/ensure.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const ensure: <T>(argument: T, message?: string) => T;
1
+ export declare const ensure: <T>(argument: T | undefined | null, message?: string) => T;
@@ -1,12 +1,12 @@
1
1
  import { expect, it } from 'vitest';
2
2
  import { parser } from '@shaderfrog/glsl-parser';
3
3
  import { generate } from '@shaderfrog/glsl-parser';
4
- import { findMain } from './ast';
5
4
  import { addFnStmtWithIndent } from './whitespace';
5
+ import { findMainOrThrow } from './ast';
6
6
  it("addFnStmtWithIndent", function () {
7
7
  var source = "void main() {\n vec2 y;\n}\n";
8
8
  var ast = parser.parse(source, { quiet: true });
9
- var m = findMain(ast);
9
+ var m = findMainOrThrow(ast);
10
10
  m.body.statements = addFnStmtWithIndent(m, "return x");
11
11
  // Should line up the whitespace properly!
12
12
  expect(generate(m)).toBe("void main() {\n vec2 y;\n return x;\n}\n");