@shaderfrog/core 2.0.0-beta.0 → 2.0.0-beta.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/package.json +2 -2
- package/strategy/inject.d.ts +1 -1
- package/util/ast.d.ts +1 -0
- package/util/ast.js +8 -4
- package/util/ensure.d.ts +1 -1
- package/util/whitespace.test.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shaderfrog/core",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
4
|
"description": "Shaderfrog core",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"babylonjs": "^6.2.0",
|
|
41
41
|
"prettier": "^3.3.2",
|
|
42
42
|
"three": "^0.156.1",
|
|
43
|
-
"typescript": "^5.
|
|
43
|
+
"typescript": "^5.5.3",
|
|
44
44
|
"vitest": "^1.6.0"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
package/strategy/inject.d.ts
CHANGED
|
@@ -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[
|
|
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 =
|
|
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;
|
package/util/whitespace.test.js
CHANGED
|
@@ -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 =
|
|
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");
|