From 82f88c459d1f522383bb73430e2d4dc09607d31d Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Sat, 15 Nov 2014 02:30:12 +0200 Subject: [PATCH] Fix ignored whitespaces before children elements. Similar to 790afe (template literals). Fixes #4. --- acorn.js | 3 ++ package.json | 2 +- test/tests-jsx.js | 126 ++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 121 insertions(+), 10 deletions(-) diff --git a/acorn.js b/acorn.js index 13052a1218..419afd10ae 100644 --- a/acorn.js +++ b/acorn.js @@ -3272,6 +3272,9 @@ inXJSChild = origInXJSChild; inXJSTag = origInXJSTag; tokRegexpAllowed = false; + if (inXJSChild) { + tokPos = tokEnd; + } expect(_gt); return finishNode(node, "XJSClosingElement"); } diff --git a/package.json b/package.json index 13bdd52350..e8cc1b2784 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "acorn-jsx", "description": "Alternative React JSX parser", "main": "acorn.js", - "version": "0.9.1-2", + "version": "0.9.1-3", "maintainers": [ { "name": "Marijn Haverbeke", diff --git a/test/tests-jsx.js b/test/tests-jsx.js index 5f61b9edf5..d7b58acb94 100644 --- a/test/tests-jsx.js +++ b/test/tests-jsx.js @@ -3199,6 +3199,111 @@ var fbTestFixture = { ] } } + }, + 'Regression': { + '

foo bar baz

;': { + type: "ExpressionStatement", + start: 0, + end: 40, + expression: { + type: "XJSElement", + start: 0, + end: 38, + openingElement: { + type: "XJSOpeningElement", + start: 0, + end: 3, + attributes: [], + name: { + type: "XJSIdentifier", + start: 1, + end: 2, + name: "p" + }, + selfClosing: false + }, + closingElement: { + type: "XJSClosingElement", + start: 34, + end: 38, + name: { + type: "XJSIdentifier", + start: 36, + end: 37, + name: "p" + } + }, + children: [ + { + type: "Literal", + start: 3, + end: 7, + value: "foo ", + raw: "foo " + }, + { + type: "XJSElement", + start: 7, + end: 30, + openingElement: { + type: "XJSOpeningElement", + start: 7, + end: 22, + attributes: [{ + type: "XJSAttribute", + start: 10, + end: 21, + name: { + type: "XJSIdentifier", + start: 10, + end: 14, + name: "href" + }, + value: { + type: "Literal", + start: 15, + end: 21, + value: "test", + raw: "\"test\"" + } + }], + name: { + type: "XJSIdentifier", + start: 8, + end: 9, + name: "a" + }, + selfClosing: false + }, + closingElement: { + type: "XJSClosingElement", + start: 26, + end: 30, + name: { + type: "XJSIdentifier", + start: 28, + end: 29, + name: "a" + } + }, + children: [{ + type: "Literal", + start: 22, + end: 26, + value: " bar", + raw: " bar" + }] + }, + { + type: "Literal", + start: 30, + end: 34, + value: " baz", + raw: " baz" + } + ] + } + } } }; @@ -3206,13 +3311,16 @@ if (typeof exports !== "undefined") { var test = require("./driver.js").test; } -for (var code in fbTestFixture.XJS) { - test(code, { - type: 'Program', - body: [fbTestFixture.XJS[code]] - }, { - ecmaVersion: 6, - locations: true, - ranges: true - }); +for (var ns in fbTestFixture) { + ns = fbTestFixture[ns]; + for (var code in ns) { + test(code, { + type: 'Program', + body: [ns[code]] + }, { + ecmaVersion: 6, + locations: true, + ranges: true + }); + } }