Skip to content

Commit 1bb4a66

Browse files
committed
Merge pull request #31 from nzakas/issue28
Ensure empty expression tokens ranges are correct.
2 parents 67d0c78 + f1c3ddb commit 1bb4a66

File tree

2 files changed

+68
-9
lines changed

2 files changed

+68
-9
lines changed

inject.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,8 @@ module.exports = function(acorn) {
244244
// at the beginning of the next one (right brace).
245245

246246
pp.jsx_parseEmptyExpression = function() {
247-
var tmp = this.start;
248-
this.start = this.lastTokEnd;
249-
this.lastTokEnd = tmp;
250-
251-
tmp = this.startLoc;
252-
this.startLoc = this.lastTokEndLoc;
253-
this.lastTokEndLoc = tmp;
254-
255-
return this.finishNode(this.startNode(), 'JSXEmptyExpression');
247+
var node = this.startNodeAt(this.lastTokEnd, this.lastTokEndLoc);
248+
return this.finishNodeAt(node, 'JSXEmptyExpression', this.start, this.startLoc);
256249
};
257250

258251
// Parses JSX expression enclosed into curly brackets.

test/tests-jsx.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3634,10 +3634,76 @@ var fbTestFixture = {
36343634
if (typeof exports !== "undefined") {
36353635
var test = require("./driver.js").test;
36363636
var testFail = require("./driver.js").testFail;
3637+
var tokTypes = require("../").tokTypes;
36373638
}
36383639

36393640
testFail("var x = <div>one</div><div>two</div>;", "Adjacent JSX elements must be wrapped in an enclosing tag (1:22)");
36403641

3642+
test('<a>{/* foo */}</a>', {}, {
3643+
onToken: [
3644+
{
3645+
type: tokTypes.jsxTagStart,
3646+
value: undefined,
3647+
start: 0,
3648+
end: 1
3649+
},
3650+
{
3651+
type: tokTypes.jsxName,
3652+
value: 'a',
3653+
start: 1,
3654+
end: 2
3655+
},
3656+
{
3657+
type: tokTypes.jsxTagEnd,
3658+
value: undefined,
3659+
start: 2,
3660+
end: 3
3661+
},
3662+
{
3663+
type: tokTypes.braceL,
3664+
value: undefined,
3665+
start: 3,
3666+
end: 4
3667+
},
3668+
{
3669+
type: tokTypes.braceR,
3670+
value: undefined,
3671+
start: 13,
3672+
end: 14
3673+
},
3674+
{
3675+
type: tokTypes.jsxTagStart,
3676+
value: undefined,
3677+
start: 14,
3678+
end: 15
3679+
},
3680+
{
3681+
type: tokTypes.slash,
3682+
value: '/',
3683+
start: 15,
3684+
end: 16
3685+
},
3686+
{
3687+
type: tokTypes.jsxName,
3688+
value: 'a',
3689+
start: 16,
3690+
end: 17
3691+
},
3692+
{
3693+
type: tokTypes.jsxTagEnd,
3694+
value: undefined,
3695+
start: 17,
3696+
end: 18
3697+
},
3698+
{
3699+
type: tokTypes.eof,
3700+
value: undefined,
3701+
start: 18,
3702+
end: 18
3703+
}
3704+
]
3705+
});
3706+
36413707
for (var ns in fbTestFixture) {
36423708
ns = fbTestFixture[ns];
36433709
for (var code in ns) {

0 commit comments

Comments
 (0)