diff --git a/package.json b/package.json index 9f616dc..f7ecb69 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/parser/scope.test.ts b/src/parser/scope.test.ts index 6499050..030ddbe 100644 --- a/src/parser/scope.test.ts +++ b/src/parser/scope.test.ts @@ -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) {}`); +}); diff --git a/src/parser/utils.ts b/src/parser/utils.ts index 86a9c62..63705cc 100644 --- a/src/parser/utils.ts +++ b/src/parser/utils.ts @@ -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`);