Skip to content

Commit

Permalink
Don't allow JSXNamespacedName to chain (#10366)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jridgewell committed Aug 26, 2019
1 parent a2bf689 commit 1664cce
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/babel-parser/src/plugins/jsx/index.js
Expand Up @@ -250,10 +250,16 @@ export default (superClass: Class<Parser>): Class<Parser> =>
// Parses element name in any form - namespaced, member
// or single identifier.

jsxParseElementName(): N.JSXNamespacedName | N.JSXMemberExpression {
jsxParseElementName():
| N.JSXIdentifier
| N.JSXNamespacedName
| N.JSXMemberExpression {
const startPos = this.state.start;
const startLoc = this.state.startLoc;
let node = this.jsxParseNamespacedName();
if (node.type === "JSXNamespacedName") {
return node;
}
while (this.eat(tt.dot)) {
const newNode = this.startNodeAt(startPos, startLoc);
newNode.object = node;
Expand Down
@@ -0,0 +1 @@
<a.b:c />
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:4)"
}
@@ -0,0 +1 @@
<a:b.c />
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:4)"
}
12 changes: 10 additions & 2 deletions packages/babel-types/src/definitions/jsx.js
Expand Up @@ -30,7 +30,11 @@ defineType("JSXClosingElement", {
aliases: ["JSX", "Immutable"],
fields: {
name: {
validate: assertNodeType("JSXIdentifier", "JSXMemberExpression"),
validate: assertNodeType(
"JSXIdentifier",
"JSXMemberExpression",
"JSXNamespacedName",
),
},
},
});
Expand Down Expand Up @@ -130,7 +134,11 @@ defineType("JSXOpeningElement", {
aliases: ["JSX", "Immutable"],
fields: {
name: {
validate: assertNodeType("JSXIdentifier", "JSXMemberExpression"),
validate: assertNodeType(
"JSXIdentifier",
"JSXMemberExpression",
"JSXNamespacedName",
),
},
selfClosing: {
default: false,
Expand Down

0 comments on commit 1664cce

Please sign in to comment.