Skip to content

Commit

Permalink
Merge pull request #41 from ShaderFrog/proto-rename
Browse files Browse the repository at this point in the history
Fixing rename case for function prototypes
  • Loading branch information
AndrewRayCode authored Jan 18, 2025
2 parents 85c4012 + 7ff3a37 commit 4f9ef9a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"engines": {
"node": ">=16"
},
"version": "5.4.0",
"version": "5.4.1",
"type": "module",
"description": "A GLSL ES 1.0 and 3.0 parser and preprocessor that can preserve whitespace and comments",
"scripts": {
Expand Down
15 changes: 15 additions & 0 deletions src/parser/scope.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,3 +572,18 @@ void main() {
const a = Object.values(ast.scopes[0].functions.a)[0];
expect(a.references).toHaveLength(3);
});

test('rename function prototypes', () => {
const ast = c.parseSrc(
`vec3 hash3(vec3 p3);
vec3 hash3(vec3 p3) {}`
);

ast.scopes[0].functions = renameFunctions(
ast.scopes[0].functions,
(name) => `${name}_FUNCTION`
);

expect(generate(ast)).toBe(`vec3 hash3_FUNCTION(vec3 p3);
vec3 hash3_FUNCTION(vec3 p3) {}`);
});
2 changes: 2 additions & 0 deletions src/parser/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ export const renameFunction = (
node.identifier.type === 'identifier'
) {
node.identifier.identifier = newName;
} else if (node.type === 'function_prototype') {
node.header.name.identifier = newName;
} else {
console.warn('Unknown function node to rename', node);
throw new Error(`Function for type ${node.type} not recognized`);
Expand Down

0 comments on commit 4f9ef9a

Please sign in to comment.