Skip to content

Commit bc53fb4

Browse files
committed
fix(glsl): fix console handling
1 parent e739021 commit bc53fb4

File tree

2 files changed

+10
-17
lines changed

2 files changed

+10
-17
lines changed

src/glsl/index.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -246,25 +246,16 @@ function arrFun(node) {
246246

247247
function calExp(node) {
248248
// console.log('calExp()', node.name, node);
249-
const { arguments: args, callee: { name } } = node;
249+
const { arguments: args, callee: { name, object } } = node;
250+
if (object && object.name === 'console') {
251+
return '/* console statement */';
252+
}
250253
if (name === 'discard') {
251254
return 'discard';
252255
}
253256
if (name === 'calc') {
254257
return `(${handleNode(args[0].body)})`;
255258
}
256-
if (name === 'debug') {
257-
return '/* debug statement */';
258-
}
259-
if (name === 'log') {
260-
return '/* log statement */';
261-
}
262-
if (name === 'warn') {
263-
return '/* warn statement */';
264-
}
265-
if (name === 'error') {
266-
return '/* error statement */';
267-
}
268259
return `${name}(${args.map(handleNode).join(', ')})`;
269260
}
270261

test/glsl/sim.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,22 +324,24 @@ float action(vec2 one, vec2 two) {
324324
it('works fine even with debug statements', () => {
325325

326326
let warnRes;
327-
const warn = (arg) => warnRes = arg;
327+
const console = {
328+
warn: (arg) => warnRes = arg
329+
};
328330

329331
const shader = ({ vec4, vec2 }) => {
330332
let bar = vec4((x = vec2()) => {
331-
warn(`warning: ${x.x.toPrecision(8)}`);
333+
console.warn(`warning: ${x.x.toPrecision(8)}`);
332334
return vec4(x, 1.0, 1.0);
333335
});
334336
return { bar };
335337
};
336-
const { js, glsl } = buildGLSL(shader, { js: true });
338+
const { js, glsl } = buildGLSL(shader, { js: true, ast: true });
337339

338340
const { bar } = js;
339341

340342
const expected = `
341343
vec4 bar(vec2 x) {
342-
\t/* warn statement */
344+
\t/* console statement */
343345
\treturn vec4(x, 1.0, 1.0);
344346
}
345347
`;

0 commit comments

Comments
 (0)