-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Line/column location is wrong with JSX #90
Comments
Obviously an bug! cc/ @3cp Do you have any idea for an quick solution? |
Not just |
It looks like scanJSXToken is called twice to scan the same source location (index 3). The duplicated scan is probably a bug. The first scan picked up two new lines correctly, the second scan missed the first new line, it strangely thinks the char at index 3 is a export function scanJSXToken(parser: ParserState): Token {
parser.startPos = parser.tokenPos = parser.index;
parser.startColumn = parser.colPos = parser.column;
parser.startLine = parser.linePos = parser.line;
if (parser.index >= parser.end) return (parser.token = Token.EOF);
const token = TokenLookup[parser.source.charCodeAt(parser.index)];
console.log('index: ' + parser.index);
switch (token) {
// '<'
case Token.LessThan: {
advanceChar(parser);
if (parser.currentChar === Chars.Slash) {
advanceChar(parser);
parser.token = Token.JSXClose;
} else {
parser.token = Token.LessThan;
}
break;
}
// '{'
case Token.LeftBrace: {
advanceChar(parser);
parser.token = Token.LeftBrace;
break;
}
default:
let state = LexerState.None;
while (parser.index < parser.end) {
const type = CharTypes[parser.currentChar];
console.log('char ' + JSON.stringify(String.fromCharCode(parser.currentChar)));
if (type & CharFlags.CarriageReturn) {
state |= LexerState.NewLine | LexerState.LastIsCR;
scanNewLine(parser);
console.log('scanNewLine');
} else if (type & CharFlags.LineFeed) {
console.log('consumeLineFeed');
consumeLineFeed(parser, state);
state = (state & ~LexerState.LastIsCR) | LexerState.NewLine;
} else {
advanceChar(parser);
}
if (CharTypes[parser.currentChar] & CharFlags.JSXToken) break;
}
parser.tokenValue = parser.source.slice(parser.tokenPos, parser.index);
parser.token = Token.JSXText;
console.log('tokenValue: ' + JSON.stringify(parser.tokenValue));
}
return parser.token;
}
|
Any ideas on how to solve it? |
No idea now. The |
Far as I know jsx is separated from rest of the code in parser.ts. So I guess only 5 methods related to jsx. Everyone have jsx in the func name |
I will debug it when I got more time. |
I didn't fix the duplicated scan, but figured out how to bypass the wrong currentChar. |
Trying to parse the following code using
loc: true, jsx: true
:gives an unexpected location for
<Text>
:I expect it to start on line 4.
Am I missing something?
The text was updated successfully, but these errors were encountered: