glsl-transpiler
Advanced tools
Comparing version
@@ -47,3 +47,22 @@ 'use strict' | ||
/** | ||
* Check if expression is protected by parentheses | ||
*/ | ||
function isBraced (exp) { | ||
if (/\s/.test(exp)) { | ||
// a + b | ||
if (exp[0] !== '(') return false; | ||
var level = 1; | ||
var len = exp.length; | ||
for (let i = 1; i < len - 1; i++) { | ||
if (exp[i] === '(') level++; | ||
else if (exp[i] === ')') level--; | ||
// (a + b) * c + d | ||
if (level === 0) return false; | ||
} | ||
} | ||
return true; | ||
} | ||
/** | ||
@@ -291,3 +310,3 @@ * Return rendered operation | ||
if (operator != '+' && operator != '-') { | ||
if (/\s/.test(left) && left[0] != '(' && left[left.length - 1] != ')') opResult += '(' + left + ')' | ||
if (!isBraced(left)) opResult += '(' + left + ')' | ||
else opResult += left | ||
@@ -300,3 +319,3 @@ } | ||
if (operator != '+' && operator != '-') { | ||
if (/\s/.test(right) && right[0] != '(' && right[right.length - 1] != ')') opResult += '(' + right + ')' | ||
if (!isBraced(right)) opResult += '(' + right + ')' | ||
else opResult += right | ||
@@ -303,0 +322,0 @@ } |
{ | ||
"name": "glsl-transpiler", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "Transpile GLSL to JS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
99354
0.3%3006
0.6%