Don't allow JSXNamespacedName to chain (#10366)

Eg, `namespace:foo.bar` used to parse but is invalid in the [spec](https://facebook.github.io/jsx/).

Also, allow `JSXNamespacedName` in the `JSXOpeningElement`/`JSXClosingElement` builders.
This commit is contained in:
Justin Ridgewell 2019-08-26 13:16:22 -04:00 committed by GitHub
parent a2bf68981f
commit 1664cce681
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 3 deletions

View File

@ -250,10 +250,16 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// Parses element name in any form - namespaced, member // Parses element name in any form - namespaced, member
// or single identifier. // or single identifier.
jsxParseElementName(): N.JSXNamespacedName | N.JSXMemberExpression { jsxParseElementName():
| N.JSXIdentifier
| N.JSXNamespacedName
| N.JSXMemberExpression {
const startPos = this.state.start; const startPos = this.state.start;
const startLoc = this.state.startLoc; const startLoc = this.state.startLoc;
let node = this.jsxParseNamespacedName(); let node = this.jsxParseNamespacedName();
if (node.type === "JSXNamespacedName") {
return node;
}
while (this.eat(tt.dot)) { while (this.eat(tt.dot)) {
const newNode = this.startNodeAt(startPos, startLoc); const newNode = this.startNodeAt(startPos, startLoc);
newNode.object = node; newNode.object = node;

View File

@ -0,0 +1 @@
<a.b:c />

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:4)"
}

View File

@ -0,0 +1 @@
<a:b.c />

View File

@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:4)"
}

View File

@ -30,7 +30,11 @@ defineType("JSXClosingElement", {
aliases: ["JSX", "Immutable"], aliases: ["JSX", "Immutable"],
fields: { fields: {
name: { name: {
validate: assertNodeType("JSXIdentifier", "JSXMemberExpression"), validate: assertNodeType(
"JSXIdentifier",
"JSXMemberExpression",
"JSXNamespacedName",
),
}, },
}, },
}); });
@ -130,7 +134,11 @@ defineType("JSXOpeningElement", {
aliases: ["JSX", "Immutable"], aliases: ["JSX", "Immutable"],
fields: { fields: {
name: { name: {
validate: assertNodeType("JSXIdentifier", "JSXMemberExpression"), validate: assertNodeType(
"JSXIdentifier",
"JSXMemberExpression",
"JSXNamespacedName",
),
}, },
selfClosing: { selfClosing: {
default: false, default: false,