Skip to content

Commit e0dcff2

Browse files
fix: include version header
1 parent 1cc035f commit e0dcff2

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

src/generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,5 @@ export interface GenerateOptions {
118118
* Generates a string of GLSL (WGSL WIP) code from an [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree).
119119
*/
120120
export function generate(program: Program, options: GenerateOptions): string {
121-
return '#version 300 es\n' + format(program).replaceAll('\n\n', '\n')
121+
return format(program).replaceAll('\n\n', '\n').trim()
122122
}

src/parser.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,10 @@ function parsePreprocessor(tokens: Token[]): PreprocessorStatement {
579579
value = [{ type: 'Identifier', name: consume(tokens).value }]
580580
consume(tokens, '>')
581581
} else if (name !== 'else' && name !== 'endif') {
582-
value = [parseExpression(tokens)]
582+
value = []
583+
while (tokens.length && tokens[0].value !== '\\') {
584+
value.push(parseExpression(tokens))
585+
}
583586
}
584587
}
585588

@@ -641,9 +644,6 @@ const DIRECTIVE_REGEX = /(^\s*#[^\\]*?)(\n|\/[\/\*])/gm
641644
* Parses a string of GLSL (WGSL WIP) code into an [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree).
642645
*/
643646
export function parse(code: string): Program {
644-
// Remove (implicit) version header
645-
code = code.replace('#version 300 es', '')
646-
647647
// Fold newlines
648648
code = code.replace(NEWLINE_REGEX, '')
649649

tests/generator.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ const glsl = /* glsl */ `#version 300 es
4040
float one, two;
4141
} globals;
4242
43-
4443
// struct X {
4544
// #if !defined(BLA)
4645
// int y;

0 commit comments

Comments
 (0)