Permalink
Browse files

Improve error message upon an invalid JSX element

Instead of trying to handle it by itself, the special lexer for JSX should
simply defer to the vanilla lexer if it can't understand the upcoming token.

Fix #1815
Closes gh-1820
  • Loading branch information...
ariya committed Apr 3, 2017
1 parent 492eeef commit 4f08020cc3f2678ca21b00931eef365d49defed9
View
@@ -15,8 +15,7 @@ interface MetaJSXElement {
const enum JSXToken {
Identifier = 100,
Text,
Unknown
Text
}
interface RawJSXToken {
@@ -30,7 +29,6 @@ interface RawJSXToken {
TokenName[JSXToken.Identifier] = 'JSXIdentifier';
TokenName[JSXToken.Text] = 'JSXText';
TokenName[JSXToken.Unknown] = 'JSXUnknown';
// Fully qualified element name, e.g. <svg:path> returns "svg:path"
function getQualifiedElementName(elementName: JSXNode.JSXElementName): string {
@@ -261,17 +259,7 @@ export class JSXParser extends Parser {
};
}
return {
type: JSXToken.Unknown,
value: '',
lineNumber: this.scanner.lineNumber,
lineStart: this.scanner.lineStart,
start: this.scanner.index,
end: this.scanner.index
};
// return this.scanner.lex() as RawJSXToken;
// return this.scanner.throwUnexpectedToken();
return this.scanner.lex() as RawJSXToken;
}
nextJSXToken(): RawJSXToken {
@@ -285,10 +273,6 @@ export class JSXParser extends Parser {
this.lastMarker.line = this.scanner.lineNumber;
this.lastMarker.column = this.scanner.index - this.scanner.lineStart;
if (token.type === JSXToken.Unknown) {
this.scanner.throwUnexpectedToken();
}
if (this.config.tokens) {
this.tokens.push(this.convertToken(token as any));
}
@@ -1 +1 @@
{"index":3,"lineNumber":1,"column":4,"message":"Error: Line 1: Unexpected token ILLEGAL","description":"Unexpected token ILLEGAL"}
{"index":3,"lineNumber":1,"column":4,"message":"Error: Line 1: Unexpected token !","description":"Unexpected token !"}
@@ -1 +1 @@
{"index":4,"lineNumber":2,"column":1,"message":"Error: Line 2: Unexpected token ILLEGAL","description":"Unexpected token ILLEGAL"}
{"index":4,"lineNumber":2,"column":1,"message":"Error: Line 2: Unexpected end of input","description":"Unexpected end of input"}

0 comments on commit 4f08020

Please sign in to comment.