Skip to content

Commit

Permalink
Merge pull request facebook#108 from jenseng/newlines-in-empty-expres…
Browse files Browse the repository at this point in the history
…sions

fix loc.end for JSXEmptyExpression
  • Loading branch information
zpao committed Apr 2, 2015
2 parents 6035077 + 1e7e673 commit 9b0451e
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 4 deletions.
16 changes: 13 additions & 3 deletions esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -7008,9 +7008,19 @@
}

function parseJSXEmptyExpression() {
var marker = markerCreatePreserveWhitespace();
while (source.charAt(index) !== '}') {
index++;
var ch, marker = markerCreatePreserveWhitespace();
while (index < length) {
ch = source.charCodeAt(index);
if (ch === 125) {
break;
} else if (isLineTerminator(ch)) {
if (ch === 13 && source.charCodeAt(index + 1) === 10) {
++index;
}
++lineNumber;
lineStart = index;
}
++index;
}
return markerApply(marker, delegate.createJSXEmptyExpression());
}
Expand Down
2 changes: 2 additions & 0 deletions test/fbtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ module.exports = {
'<AbC-def\n test="&#x0026;&#38;">\nbar\nbaz\r\n</AbC-def>',
'<a b={x ? <c /> : <d />} />',
'<a>{}</a>',
'<a>{\r\n}</a>',
'<a>{/* this is a comment */}</a>',
'<a>{/* this\nis\na\nmulti-line\ncomment */}</a>',
'<div>@test content</div>',
'<div><br />7x invalid-js-identifier</div>',
'<LeftRight left=<a /> right=<b>monkeys</b> />',
Expand Down
138 changes: 137 additions & 1 deletion test/fbtest.rec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* tests/fbtest.js and run tools/generate-fbtest.js
*/

var numTests = 221
var numTests = 223
var testFixture;

var fbTestFixture = {
Expand Down Expand Up @@ -1008,6 +1008,74 @@ var fbTestFixture = {
end: { line: 1, column: 9 }
}
},
'<a>{\r\n}</a>': {
type: 'ExpressionStatement',
expression: {
type: 'JSXElement',
openingElement: {
type: 'JSXOpeningElement',
name: {
type: 'JSXIdentifier',
name: 'a',
range: [1, 2],
loc: {
start: { line: 1, column: 1 },
end: { line: 1, column: 2 }
}
},
selfClosing: false,
attributes: [],
range: [0, 3],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 3 }
}
},
closingElement: {
type: 'JSXClosingElement',
name: {
type: 'JSXIdentifier',
name: 'a',
range: [9, 10],
loc: {
start: { line: 2, column: 3 },
end: { line: 2, column: 4 }
}
},
range: [7, 11],
loc: {
start: { line: 2, column: 1 },
end: { line: 2, column: 5 }
}
},
children: [{
type: 'JSXExpressionContainer',
expression: {
type: 'JSXEmptyExpression',
range: [4, 6],
loc: {
start: { line: 1, column: 4 },
end: { line: 2, column: 1 }
}
},
range: [3, 7],
loc: {
start: { line: 1, column: 3 },
end: { line: 2, column: 1 }
}
}],
range: [0, 11],
loc: {
start: { line: 1, column: 0 },
end: { line: 2, column: 5 }
}
},
range: [0, 11],
loc: {
start: { line: 1, column: 0 },
end: { line: 2, column: 5 }
}
},
'<a>{/* this is a comment */}</a>': {
type: 'ExpressionStatement',
expression: {
Expand Down Expand Up @@ -1076,6 +1144,74 @@ var fbTestFixture = {
end: { line: 1, column: 32 }
}
},
'<a>{/* this\nis\na\nmulti-line\ncomment */}</a>': {
type: 'ExpressionStatement',
expression: {
type: 'JSXElement',
openingElement: {
type: 'JSXOpeningElement',
name: {
type: 'JSXIdentifier',
name: 'a',
range: [1, 2],
loc: {
start: { line: 1, column: 1 },
end: { line: 1, column: 2 }
}
},
selfClosing: false,
attributes: [],
range: [0, 3],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 3 }
}
},
closingElement: {
type: 'JSXClosingElement',
name: {
type: 'JSXIdentifier',
name: 'a',
range: [41, 42],
loc: {
start: { line: 5, column: 13 },
end: { line: 5, column: 14 }
}
},
range: [39, 43],
loc: {
start: { line: 5, column: 11 },
end: { line: 5, column: 15 }
}
},
children: [{
type: 'JSXExpressionContainer',
expression: {
type: 'JSXEmptyExpression',
range: [4, 38],
loc: {
start: { line: 1, column: 4 },
end: { line: 5, column: 11 }
}
},
range: [3, 39],
loc: {
start: { line: 1, column: 3 },
end: { line: 5, column: 11 }
}
}],
range: [0, 43],
loc: {
start: { line: 1, column: 0 },
end: { line: 5, column: 15 }
}
},
range: [0, 43],
loc: {
start: { line: 1, column: 0 },
end: { line: 5, column: 15 }
}
},
'<div>@test content</div>': {
type: 'ExpressionStatement',
expression: {
Expand Down

0 comments on commit 9b0451e

Please sign in to comment.