| 10 | } from './scope.js'; |
| 11 | |
| 12 | export const renameBinding = (binding: ScopeEntry, newName: string) => { |
| 13 | binding.references.forEach((node) => { |
| 14 | if (node.type === 'declaration') { |
| 15 | node.identifier.identifier = newName; |
| 16 | } else if (node.type === 'identifier') { |
| 17 | node.identifier = newName; |
| 18 | } else if (node.type === 'parameter_declaration' && node.identifier) { |
| 19 | node.identifier.identifier = newName; |
| 20 | /* Ignore case of: |
| 21 | layout(std140,column_major) uniform; |
| 22 | uniform Material { |
| 23 | uniform vec2 prop; |
| 24 | } |
| 25 | */ |
| 26 | } else if (node.type !== 'interface_declarator') { |
| 27 | console.warn('Unknown binding node', node); |
| 28 | throw new Error(`Binding for type ${node.type} not recognized`); |
| 29 | } |
| 30 | }); |
| 31 | return binding; |
| 32 | }; |
| 33 | |
| 34 | export const renameBindings = ( |
| 35 | bindings: ScopeIndex, |