CodyJasonBennett / shaderkit

Tools and IntelliSense for GLSL and WGSL.
https://npmjs.com/shaderkit
MIT License
117 stars 3 forks source link

WGSL variable is ignored by the mangler #12

Closed ooflorent closed 1 year ago

ooflorent commented 1 year ago

The minifier is unable to identify some variables in WSGL.

The issue can already be observed by looking at the current snapshots where output is not mangled.

Reproduction

it('mangle WGSL variables', () => {
  const mangleMap = new Map()
  const shader = /* wgsl */ `@vertex fn main() -> void { var test: f32; }`
  expect(minify(shader, { mangle: true, mangleMap })).toMatchSnapshot()
  expect(mangleMap).toContain('test')
  //                ^^^^^^^^^ AssertionError: expected Map{} to include 'test'
})
CodyJasonBennett commented 1 year ago

This looks to be skipped since void is not a valid keyword in WGSL and treated as an identifier. The behavior is still very wrong until I implement a proper AST (#14), but this should work with valid WGSL fn main() { var test: f32; }.

CodyJasonBennett commented 1 year ago

I've harden surrounding cases in the latest release. Let me know if this was somehow missed.