Skip to content

Commit d886ffc

Browse files
author
Kai Cataldo
authored
Throw unexpected token error for } and > in JSXText nodes (#108)
1 parent e57398c commit d886ffc

File tree

2 files changed

+968
-284
lines changed

2 files changed

+968
-284
lines changed

index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ function plugin(options, Parser) {
136136
chunkStart = this.pos;
137137
break;
138138

139+
case 62: // '>'
140+
case 125: // '}'
141+
this.raise(
142+
this.pos,
143+
"Unexpected token `" + this.input[this.pos] + "`. Did you mean `" +
144+
(ch === 62 ? ">" : "}") + "` or " + "`{\"" + this.input[this.pos] + "\"}" + "`?"
145+
);
146+
139147
default:
140148
if (isNewLine(ch)) {
141149
out += this.input.slice(chunkStart, this.pos);
@@ -414,8 +422,8 @@ function plugin(options, Parser) {
414422

415423
// Parse JSX text
416424

417-
jsx_parseText(value) {
418-
let node = this.parseLiteral(value);
425+
jsx_parseText() {
426+
let node = this.parseLiteral(this.value);
419427
node.type = "JSXText";
420428
return node;
421429
}
@@ -430,7 +438,7 @@ function plugin(options, Parser) {
430438

431439
parseExprAtom(refShortHandDefaultPos) {
432440
if (this.type === tok.jsxText)
433-
return this.jsx_parseText(this.value);
441+
return this.jsx_parseText();
434442
else if (this.type === tok.jsxTagStart)
435443
return this.jsx_parseElement();
436444
else

0 commit comments

Comments
 (0)