update XJS namespaces to JSX
This commit is contained in:
parent
dacb187f11
commit
36fa887be8
@ -3,7 +3,7 @@
|
|||||||
var t = require("../../types");
|
var t = require("../../types");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
exports.XJSAttribute = function (node, print) {
|
exports.JSXAttribute = function (node, print) {
|
||||||
print(node.name);
|
print(node.name);
|
||||||
if (node.value) {
|
if (node.value) {
|
||||||
this.push("=");
|
this.push("=");
|
||||||
@ -11,35 +11,35 @@ exports.XJSAttribute = function (node, print) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.XJSIdentifier = function (node) {
|
exports.JSXIdentifier = function (node) {
|
||||||
this.push(node.name);
|
this.push(node.name);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.XJSNamespacedName = function (node, print) {
|
exports.JSXNamespacedName = function (node, print) {
|
||||||
print(node.namespace);
|
print(node.namespace);
|
||||||
this.push(":");
|
this.push(":");
|
||||||
print(node.name);
|
print(node.name);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.XJSMemberExpression = function (node, print) {
|
exports.JSXMemberExpression = function (node, print) {
|
||||||
print(node.object);
|
print(node.object);
|
||||||
this.push(".");
|
this.push(".");
|
||||||
print(node.property);
|
print(node.property);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.XJSSpreadAttribute = function (node, print) {
|
exports.JSXSpreadAttribute = function (node, print) {
|
||||||
this.push("{...");
|
this.push("{...");
|
||||||
print(node.argument);
|
print(node.argument);
|
||||||
this.push("}");
|
this.push("}");
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.XJSExpressionContainer = function (node, print) {
|
exports.JSXExpressionContainer = function (node, print) {
|
||||||
this.push("{");
|
this.push("{");
|
||||||
print(node.expression);
|
print(node.expression);
|
||||||
this.push("}");
|
this.push("}");
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.XJSElement = function (node, print) {
|
exports.JSXElement = function (node, print) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
var open = node.openingElement;
|
var open = node.openingElement;
|
||||||
@ -59,7 +59,7 @@ exports.XJSElement = function (node, print) {
|
|||||||
print(node.closingElement);
|
print(node.closingElement);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.XJSOpeningElement = function (node, print) {
|
exports.JSXOpeningElement = function (node, print) {
|
||||||
this.push("<");
|
this.push("<");
|
||||||
print(node.name);
|
print(node.name);
|
||||||
if (node.attributes.length > 0) {
|
if (node.attributes.length > 0) {
|
||||||
@ -69,12 +69,12 @@ exports.XJSOpeningElement = function (node, print) {
|
|||||||
this.push(node.selfClosing ? " />" : ">");
|
this.push(node.selfClosing ? " />" : ">");
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.XJSClosingElement = function (node, print) {
|
exports.JSXClosingElement = function (node, print) {
|
||||||
this.push("</");
|
this.push("</");
|
||||||
print(node.name);
|
print(node.name);
|
||||||
this.push(">");
|
this.push(">");
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.XJSEmptyExpression = function () {
|
exports.JSXEmptyExpression = function () {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -9,7 +9,7 @@ var esutils = require("esutils");
|
|||||||
var t = require("../../../types");
|
var t = require("../../../types");
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
exports.XJSIdentifier = function (node) {
|
exports.JSXIdentifier = function (node) {
|
||||||
if (esutils.keyword.isIdentifierName(node.name)) {
|
if (esutils.keyword.isIdentifierName(node.name)) {
|
||||||
node.type = "Identifier";
|
node.type = "Identifier";
|
||||||
} else {
|
} else {
|
||||||
@ -17,22 +17,22 @@ exports.XJSIdentifier = function (node) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.XJSNamespacedName = function (node, parent, scope, context, file) {
|
exports.JSXNamespacedName = function (node, parent, scope, context, file) {
|
||||||
throw file.errorWithNode(node, "Namespace tags are not supported. ReactJSX is not XML.");
|
throw file.errorWithNode(node, "Namespace tags are not supported. ReactJSX is not XML.");
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.XJSMemberExpression = {
|
exports.JSXMemberExpression = {
|
||||||
exit: function (node) {
|
exit: function (node) {
|
||||||
node.computed = t.isLiteral(node.property);
|
node.computed = t.isLiteral(node.property);
|
||||||
node.type = "MemberExpression";
|
node.type = "MemberExpression";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.XJSExpressionContainer = function (node) {
|
exports.JSXExpressionContainer = function (node) {
|
||||||
return node.expression;
|
return node.expression;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.XJSAttribute = {
|
exports.JSXAttribute = {
|
||||||
exit: function (node) {
|
exit: function (node) {
|
||||||
var value = node.value || t.literal(true);
|
var value = node.value || t.literal(true);
|
||||||
return t.inherits(t.property("init", node.name, value), node);
|
return t.inherits(t.property("init", node.name, value), node);
|
||||||
@ -43,7 +43,7 @@ var isCompatTag = function (tagName) {
|
|||||||
return /^[a-z]|\-/.test(tagName);
|
return /^[a-z]|\-/.test(tagName);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.XJSOpeningElement = {
|
exports.JSXOpeningElement = {
|
||||||
exit: function (node, parent, scope, context, file) {
|
exit: function (node, parent, scope, context, file) {
|
||||||
var reactCompat = file.opts.reactCompat;
|
var reactCompat = file.opts.reactCompat;
|
||||||
var tagExpr = node.name;
|
var tagExpr = node.name;
|
||||||
@ -66,7 +66,7 @@ exports.XJSOpeningElement = {
|
|||||||
|
|
||||||
var attribs = node.attributes;
|
var attribs = node.attributes;
|
||||||
if (attribs.length) {
|
if (attribs.length) {
|
||||||
attribs = buildXJSOpeningElementAttributes(attribs);
|
attribs = buildJSXOpeningElementAttributes(attribs);
|
||||||
} else {
|
} else {
|
||||||
attribs = t.literal(null);
|
attribs = t.literal(null);
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ exports.XJSOpeningElement = {
|
|||||||
* all prior attributes to an array for later processing.
|
* all prior attributes to an array for later processing.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var buildXJSOpeningElementAttributes = function (attribs) {
|
var buildJSXOpeningElementAttributes = function (attribs) {
|
||||||
var _props = [];
|
var _props = [];
|
||||||
var objs = [];
|
var objs = [];
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ var buildXJSOpeningElementAttributes = function (attribs) {
|
|||||||
|
|
||||||
while (attribs.length) {
|
while (attribs.length) {
|
||||||
var prop = attribs.shift();
|
var prop = attribs.shift();
|
||||||
if (t.isXJSSpreadAttribute(prop)) {
|
if (t.isJSXSpreadAttribute(prop)) {
|
||||||
pushProps();
|
pushProps();
|
||||||
objs.push(prop.argument);
|
objs.push(prop.argument);
|
||||||
} else {
|
} else {
|
||||||
@ -141,7 +141,7 @@ var buildXJSOpeningElementAttributes = function (attribs) {
|
|||||||
return attribs;
|
return attribs;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.XJSElement = {
|
exports.JSXElement = {
|
||||||
exit: function (node) {
|
exit: function (node) {
|
||||||
var callExpr = node.openingElement;
|
var callExpr = node.openingElement;
|
||||||
|
|
||||||
@ -149,9 +149,9 @@ exports.XJSElement = {
|
|||||||
var child = node.children[i];
|
var child = node.children[i];
|
||||||
|
|
||||||
if (t.isLiteral(child) && _.isString(child.value)) {
|
if (t.isLiteral(child) && _.isString(child.value)) {
|
||||||
cleanXJSElementLiteralChild(child, callExpr.arguments);
|
cleanJSXElementLiteralChild(child, callExpr.arguments);
|
||||||
continue;
|
continue;
|
||||||
} else if (t.isXJSEmptyExpression(child)) {
|
} else if (t.isJSXEmptyExpression(child)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ exports.XJSElement = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var cleanXJSElementLiteralChild = function (child, args) {
|
var cleanJSXElementLiteralChild = function (child, args) {
|
||||||
var lines = child.value.split(/\r\n|\n|\r/);
|
var lines = child.value.split(/\r\n|\n|\r/);
|
||||||
|
|
||||||
for (var i = 0; i < lines.length; i++) {
|
for (var i = 0; i < lines.length; i++) {
|
||||||
|
|||||||
@ -45,7 +45,7 @@
|
|||||||
"AssignmentPattern": ["Pattern"],
|
"AssignmentPattern": ["Pattern"],
|
||||||
|
|
||||||
"Property": ["UserWhitespacable"],
|
"Property": ["UserWhitespacable"],
|
||||||
"XJSElement": ["UserWhitespacable", "Expression"],
|
"JSXElement": ["UserWhitespacable", "Expression"],
|
||||||
|
|
||||||
"ArrayExpression": ["Expression"],
|
"ArrayExpression": ["Expression"],
|
||||||
"AssignmentExpression": ["Expression"],
|
"AssignmentExpression": ["Expression"],
|
||||||
@ -65,7 +65,7 @@
|
|||||||
"ThisExpression": ["Expression"],
|
"ThisExpression": ["Expression"],
|
||||||
"UpdateExpression": ["Expression"],
|
"UpdateExpression": ["Expression"],
|
||||||
"VirtualPropertyExpression": ["Expression"],
|
"VirtualPropertyExpression": ["Expression"],
|
||||||
"XJSEmptyExpression": ["Expression"],
|
"JSXEmptyExpression": ["Expression"],
|
||||||
"XJSMemberExpression": ["Expression"],
|
"JSXMemberExpression": ["Expression"],
|
||||||
"YieldExpression": ["Expression"]
|
"YieldExpression": ["Expression"]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -101,14 +101,14 @@
|
|||||||
"UnionTypeAnnotation": [],
|
"UnionTypeAnnotation": [],
|
||||||
"VoidTypeAnnotation": [],
|
"VoidTypeAnnotation": [],
|
||||||
|
|
||||||
"XJSAttribute": ["name", "value"],
|
"JSXAttribute": ["name", "value"],
|
||||||
"XJSClosingElement": ["name"],
|
"JSXClosingElement": ["name"],
|
||||||
"XJSElement": ["openingElement", "closingElement", "children"],
|
"JSXElement": ["openingElement", "closingElement", "children"],
|
||||||
"XJSEmptyExpression": [],
|
"JSXEmptyExpression": [],
|
||||||
"XJSExpressionContainer": ["expression"],
|
"JSXExpressionContainer": ["expression"],
|
||||||
"XJSIdentifier": [],
|
"JSXIdentifier": [],
|
||||||
"XJSMemberExpression": ["object", "property"],
|
"JSXMemberExpression": ["object", "property"],
|
||||||
"XJSNamespacedName": ["namespace", "name"],
|
"JSXNamespacedName": ["namespace", "name"],
|
||||||
"XJSOpeningElement": ["name", "attributes"],
|
"JSXOpeningElement": ["name", "attributes"],
|
||||||
"XJSSpreadAttribute": ["argument"]
|
"JSXSpreadAttribute": ["argument"]
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user