Add a 'throwIfNamespace' option for JSX transform (#6563)

* Added tests for ifThrowNamespace flag

* JSX transformator could work with XMLNamespaces (ifThrowNamespace flag)

* Use template literal instead

* Attempt to reword the message

* Added docs

* Reworded docs

* Reworded docs

* Fixed missing space in error message
This commit is contained in:
Jakub Beneš
2017-10-29 02:44:15 +02:00
committed by Henry Zhu
parent 9ac326b075
commit 04d2c030be
10 changed files with 58 additions and 7 deletions

View File

@@ -14,11 +14,13 @@ export default function(opts) {
const visitor = {};
visitor.JSXNamespacedName = function(path) {
throw path.buildCodeFrameError(
"Namespace tags are not supported. ReactJSX is not XML.",
);
if (opts.throwIfNamespace) {
throw path.buildCodeFrameError(
`Namespace tags are not supported by default. React's JSX doesn't support namespace tags. \
You can turn on the 'throwIfNamespace' flag to bypass this warning.`,
);
}
};
visitor.JSXElement = {
exit(path, file) {
const callExpr = buildElementCall(path, file);
@@ -44,6 +46,12 @@ export default function(opts) {
convertJSXIdentifier(node.object, node),
convertJSXIdentifier(node.property, node),
);
} else if (t.isJSXNamespacedName(node)) {
/**
* If there is flag "throwIfNamespace"
* print XMLNamespace like string literal
*/
return t.stringLiteral(`${node.namespace.name}:${node.name.name}`);
}
return node;