Skip to content

Commit 0b673c2

Browse files
committed
Relax closing tag map rule in JSX parsing
1 parent 0b85364 commit 0b673c2

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/compiler/parser.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -3131,12 +3131,22 @@ module ts {
31313131
// if it's a self closing tag it's a JSXElement and not a type assertion
31323132
speculative = false;
31333133
}
3134-
else if (speculative && !hasClosingTagAfterPos(tagName, scanner.getStartPos())) {
3135-
// we are in speculative parsing and we were not able to find a corresponding closing tag
3136-
// farther in the source text
3137-
return null;
3138-
}
31393134
else {
3135+
if (speculative && !hasClosingTagAfterPos(tagName, scanner.getStartPos())) {
3136+
// we are in speculative parsing and we were not able to find a corresponding closing tag
3137+
// farther in the source text, we try to determine if the following tokens look like normal
3138+
// part of jsx children to decide if we continue parsing the JSXElement children
3139+
let shouldContinueJSXParsing = lookAhead(() => {
3140+
const t = token;
3141+
const next = nextToken();
3142+
return t === SyntaxKind.LessThanToken ||// <foo><...
3143+
(t >= SyntaxKind.Identifier && next === SyntaxKind.OpenBraceToken) || // '<foo> bar {...
3144+
(t >= SyntaxKind.Identifier && next >= SyntaxKind.Identifier) // '<foo> foo bar ...
3145+
});
3146+
if (!shouldContinueJSXParsing) {
3147+
return null;
3148+
}
3149+
}
31403150
//we can't use parseList we need to intercept '}‘ token in speculative mode
31413151
let savedStrictModeContext = inStrictModeContext();
31423152

0 commit comments

Comments
 (0)