Skip to content

Commit cef28d7

Browse files
Merge pull request #24 from aaronhuggins/master
Support emitting the end of tag name when newline and tab are used
2 parents 874bf22 + cbcf446 commit cef28d7

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

js/react/jsxLoader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@
666666
}
667667
} else if (nextChar === '>') {
668668
break;
669-
} else if (nextChar === ' ') {
669+
} else if (nextChar === ' ' || nextChar === '\n' || nextChar === '\t') {
670670
foundName = true;
671671
continue;
672672
} else if (nextChar === ')' || nextChar === '&' || nextChar === '|' || nextChar === '?' || nextChar === ';') {

test/js/unit-testing-react.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,24 @@ describe('jsxLoader.js', function() {
648648
expect(js).to.equal('"use strict";\nReact.createElement(Test, {message: "test", value: 123}, "Hello")');
649649
});
650650

651+
it('should compile nested element with newline', function() {
652+
resetIfUsingPreact();
653+
var jsx = '<Test message="test" value={123}><div\ntitle="test">Hello</div></Test>';
654+
var js = jsxLoader.compiler.compile(jsx);
655+
console.log(js);
656+
console.log(JSON.stringify(js));
657+
expect(js).to.equal('"use strict";\nReact.createElement(Test, {message: "test", value: 123}, \n React.createElement("div", {title: "test"}, "Hello"))');
658+
});
659+
660+
it('should compile nested element with tab', function() {
661+
resetIfUsingPreact();
662+
var jsx = '<Test message="test" value={123}><div\ttitle="test">Hello</div></Test>';
663+
var js = jsxLoader.compiler.compile(jsx);
664+
console.log(js);
665+
console.log(JSON.stringify(js));
666+
expect(js).to.equal('"use strict";\nReact.createElement(Test, {message: "test", value: 123}, \n React.createElement("div", {title: "test"}, "Hello"))');
667+
});
668+
651669
it('should have correct child whitespace nodes', function() {
652670
resetIfUsingPreact();
653671
var jsx = '<div><strong className={this.props.cssClass}>Test:</strong> {this.props.name} <section>Test [{this.props.name}] <span className="test">Test2</span></section></div>';
@@ -863,4 +881,4 @@ describe('<JsonData>', function() {
863881
expect(el.style.color).to.equal('rgb(255, 255, 255)');
864882
});
865883
});
866-
});
884+
});

0 commit comments

Comments
 (0)