Skip to content

Commit 978126b

Browse files
committed
1 parent 8ea3cc5 commit 978126b

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/ast.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ var binOperatorsPrecedence = [
131131
['or'],
132132
['xor'],
133133
['and'],
134-
// TODO: assignment / not sure that PHP allows this with expressions
134+
['='],
135135
['?'],
136136
['??'],
137137
['||'],
@@ -210,6 +210,19 @@ AST.prototype.resolvePrecedence = function(result) {
210210
buffer.test = this.resolvePrecedence(result);
211211
result = buffer;
212212
}
213+
} else if (result.kind === 'assign') {
214+
// https://github.com/glayzzle/php-parser/issues/81
215+
if (result.right && result.right.kind === 'bin') {
216+
var lLevel = AST.precedence['='];
217+
var rLevel = AST.precedence[result.right.type];
218+
// only shifts with and, xor, or
219+
if (lLevel && rLevel && rLevel < lLevel) {
220+
buffer = result.right;
221+
result.right = result.right.left;
222+
buffer.left = result;
223+
result = buffer;
224+
}
225+
}
213226
}
214227
return result;
215228
};

0 commit comments

Comments
 (0)