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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user