Skip to content
Browse files

Add tests for the grouping operator.

These tests highlight the problem with syntax node location when the
expression contains parentheses.

http://code.google.com/p/esprima/issues/detail?id=345
  • Loading branch information...
1 parent 536b743 commit 392c4bd20e25a9c023896acbd91d8b846047d3b6 @ariya committed Oct 3, 2012
Showing with 118 additions and 0 deletions.
  1. +118 −0 test/test.js
View
118 test/test.js
@@ -197,6 +197,124 @@ var testFixture = {
},
+ 'Grouping Operator': {
+
+ '(1) + (2 ) + 3': {
+ type: 'ExpressionStatement',
+ expression: {
+ type: 'BinaryExpression',
+ operator: '+',
+ left: {
+ type: 'BinaryExpression',
+ operator: '+',
+ left: {
+ type: 'Literal',
+ value: 1,
+ raw: '1',
+ range: [1, 2],
+ loc: {
+ start: { line: 1, column: 1 },
+ end: { line: 1, column: 2 }
+ }
+ },
+ right: {
+ type: 'Literal',
+ value: 2,
+ raw: '2',
+ range: [7, 8],
+ loc: {
+ start: { line: 1, column: 7 },
+ end: { line: 1, column: 8 }
+ }
+ },
+ range: [0, 11],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 11 }
+ }
+ },
+ right: {
+ type: 'Literal',
+ value: 3,
+ raw: '3',
+ range: [14, 15],
+ loc: {
+ start: { line: 1, column: 14 },
+ end: { line: 1, column: 15 }
+ }
+ },
+ range: [0, 15],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 15 }
+ }
+ },
+ range: [0, 15],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 15 }
+ }
+ },
+
+ '4 + 5 << (6)': {
+ type: 'ExpressionStatement',
+ expression: {
+ type: 'BinaryExpression',
+ operator: '<<',
+ left: {
+ type: 'BinaryExpression',
+ operator: '+',
+ left: {
+ type: 'Literal',
+ value: 4,
+ raw: '4',
+ range: [0, 1],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 1 }
+ }
+ },
+ right: {
+ type: 'Literal',
+ value: 5,
+ raw: '5',
+ range: [4, 5],
+ loc: {
+ start: { line: 1, column: 4 },
+ end: { line: 1, column: 5 }
+ }
+ },
+ range: [0, 5],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 5 }
+ }
+ },
+ right: {
+ type: 'Literal',
+ value: 6,
+ raw: '6',
+ range: [10, 11],
+ loc: {
+ start: { line: 1, column: 10 },
+ end: { line: 1, column: 11 }
+ }
+ },
+ range: [0, 12],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 12 }
+ }
+ },
+ range: [0, 12],
+ loc: {
+ start: { line: 1, column: 0 },
+ end: { line: 1, column: 12 }
+ }
+ }
+
+ },
+
'Array Initializer': {
'x = []': {

0 comments on commit 392c4bd

Please sign in to comment.
Something went wrong with that request. Please try again.