Skip to content

Commit

Permalink
Merge pull request #21 from ShaderFrog/cleanup-20
Browse files Browse the repository at this point in the history
Minor code cleanup and package version bump
  • Loading branch information
AndrewRayCode authored May 5, 2024
2 parents a8e4683 + 79af6ed commit e4d4492
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"engines": {
"node": ">=16"
},
"version": "3.0.4",
"version": "3.1.0",
"type": "module",
"description": "A GLSL ES 1.0 and 3.0 parser and preprocessor that can preserve whitespace and comments",
"scripts": {
Expand Down
10 changes: 8 additions & 2 deletions src/preprocessor/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ const generators: NodePreprocessorGenerators = {
generate(node.wsEnd) +
generate(node.body),
ifdef: (node) =>
generate(node.token) + generate(node.identifier) + generate(node.wsEnd) + generate(node.body),
generate(node.token) +
generate(node.identifier) +
generate(node.wsEnd) +
generate(node.body),
ifndef: (node) =>
generate(node.token) + generate(node.identifier) + generate(node.wsEnd) + generate(node.body),
generate(node.token) +
generate(node.identifier) +
generate(node.wsEnd) +
generate(node.body),
else: (node) =>
generate(node.token) + generate(node.wsEnd) + generate(node.body),
error: (node) =>
Expand Down
41 changes: 19 additions & 22 deletions src/preprocessor/preprocessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,12 @@ function_call line after program`;
// // return identifier === 'A';
// },
preserve: {
conditional: (path) => false,
line: (path) => true,
error: (path) => true,
extension: (path) => true,
pragma: (path) => true,
version: (path) => true,
conditional: () => false,
line: () => true,
error: () => true,
extension: () => true,
pragma: () => true,
version: () => true,
},
});
expect(generate(ast)).toBe(`
Expand All @@ -460,24 +460,21 @@ test('different line breaks character', () => {
});

test('generate #ifdef & #ifndef & #else', () => {
const program = `
#ifdef AA
float a;
#else
float b;
#endif
#ifndef CC
float c;
#endif
expectParsedProgram(`
#ifdef AA
float a;
#else
float b;
#endif
#if AA == 2
float d;
#endif
`;
#ifndef CC
float c;
#endif
const ast = parse(program);
expect(generate(ast)).toBe(program);
#if AA == 2
float d;
#endif
`);
});

/*
Expand Down

0 comments on commit e4d4492

Please sign in to comment.