Skip to content

Commit

Permalink
feat(shader-ast): update & export gensym()
Browse files Browse the repository at this point in the history
- add opt prefix arg for better re-use
  • Loading branch information
postspectacular committed Oct 4, 2021
1 parent a9abcfe commit 8a3f1ff
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/shader-ast/src/ast/idgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ let symID = 0;
export const resetSymID = () => (symID = 0);

/**
* Generates a new symbol name, e.g. `_sa2`. Uses base36 for counter to
* keep names short.
* Generates a new symbol name with optional given `prefix` (default: "_s"),
* e.g. `_s123`. Uses base36 for internal counter to keep names short.
*
* @param prefix
*/
export const gensym = () => `_s${(symID++).toString(36)}`;
export const gensym = (prefix = "_s") => `${prefix}${(symID++).toString(36)}`;
1 change: 1 addition & 0 deletions packages/shader-ast/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export * from "./ast/assign";
export * from "./ast/checks";
export * from "./ast/controlflow";
export * from "./ast/function";
export * from "./ast/idgen";
export * from "./ast/indexed";
export * from "./ast/item";
export * from "./ast/lit";
Expand Down

0 comments on commit 8a3f1ff

Please sign in to comment.