https://github.com/stackgl/glsl-min-stream
through stream that transforms glsl-parser AST nodes and rewrites variables into shorter forms
https://github.com/stackgl/glsl-min-stream
Last synced: about 1 year ago
JSON representation
through stream that transforms glsl-parser AST nodes and rewrites variables into shorter forms
- Host: GitHub
- URL: https://github.com/stackgl/glsl-min-stream
- Owner: stackgl
- Created: 2012-11-24T22:40:53.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2019-06-12T01:06:23.000Z (about 7 years ago)
- Last Synced: 2024-05-04T21:02:25.751Z (about 2 years ago)
- Language: JavaScript
- Size: 58.6 KB
- Stars: 14
- Watchers: 8
- Forks: 6
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
   [](https://travis-ci.org/stackgl/glsl-min-stream) [](https://coveralls.io/github/stackgl/glsl-min-stream?branch=master)
# glsl-min-stream
Transform [glsl-parser](https://github.com/chrisdickinson/glsl-parser.git) AST nodes
on-the-fly by renaming variables into shorter forms.
```javascript
var tokenizer = require('glsl-tokenizer/stream')
, parser = require('glsl-parser')
, deparser = require('glsl-deparser')
, minify = require('./index')
process.stdin
.pipe(tokenizer())
.pipe(parser())
.pipe(minify()) // <-- the minifier
.pipe(deparser(false)) // <-- "false" == no unnecessary whitespace, please.
.pipe(process.stdout)
process.stdin.resume()
```
# API
### minifier = require('glsl-minifier')([safe_word_list], should_mutate_storages) -> minifier stream
Create a [through stream](https://github.com/dominictarr/stream-spec#through-sync-writable-and-readable-aka-filter) that rewrites incoming declared variables.
* `safe_word_list` defaults to `["main"]` so that the main function is not overridden.
* `should_mutate_storages`, a boolean defaulted to `false`, determines whether the minifier should attempt to rewrite variables declared as `varying`, `attribute`, or `uniform` (usually you do not want to do this, as the client program is expecting specific variable names).
# Testing
Run `npm test` to run tests
---
When adding a code change that differs the output, make sure to run tap with snapshots by running `npm run test -- --snapshot`. This will regenerate the tap-snapshot files. Make sure to commit those along with other code and test changes.
# License
MIT