update XJS namespaces to JSX

This commit is contained in:
Sebastian McKenzie 2015-01-23 08:08:56 +11:00
parent dacb187f11
commit 36fa887be8
4 changed files with 36 additions and 36 deletions

View File

@ -3,7 +3,7 @@
var t = require("../../types");
var _ = require("lodash");
exports.XJSAttribute = function (node, print) {
exports.JSXAttribute = function (node, print) {
print(node.name);
if (node.value) {
this.push("=");
@ -11,35 +11,35 @@ exports.XJSAttribute = function (node, print) {
}
};
exports.XJSIdentifier = function (node) {
exports.JSXIdentifier = function (node) {
this.push(node.name);
};
exports.XJSNamespacedName = function (node, print) {
exports.JSXNamespacedName = function (node, print) {
print(node.namespace);
this.push(":");
print(node.name);
};
exports.XJSMemberExpression = function (node, print) {
exports.JSXMemberExpression = function (node, print) {
print(node.object);
this.push(".");
print(node.property);
};
exports.XJSSpreadAttribute = function (node, print) {
exports.JSXSpreadAttribute = function (node, print) {
this.push("{...");
print(node.argument);
this.push("}");
};
exports.XJSExpressionContainer = function (node, print) {
exports.JSXExpressionContainer = function (node, print) {
this.push("{");
print(node.expression);
this.push("}");
};
exports.XJSElement = function (node, print) {
exports.JSXElement = function (node, print) {
var self = this;
var open = node.openingElement;
@ -59,7 +59,7 @@ exports.XJSElement = function (node, print) {
print(node.closingElement);
};
exports.XJSOpeningElement = function (node, print) {
exports.JSXOpeningElement = function (node, print) {
this.push("<");
print(node.name);
if (node.attributes.length > 0) {
@ -69,12 +69,12 @@ exports.XJSOpeningElement = function (node, print) {
this.push(node.selfClosing ? " />" : ">");
};
exports.XJSClosingElement = function (node, print) {
exports.JSXClosingElement = function (node, print) {
this.push("</");
print(node.name);
this.push(">");
};
exports.XJSEmptyExpression = function () {
exports.JSXEmptyExpression = function () {
};

View File

@ -9,7 +9,7 @@ var esutils = require("esutils");
var t = require("../../../types");
var _ = require("lodash");
exports.XJSIdentifier = function (node) {
exports.JSXIdentifier = function (node) {
if (esutils.keyword.isIdentifierName(node.name)) {
node.type = "Identifier";
} 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.");
};
exports.XJSMemberExpression = {
exports.JSXMemberExpression = {
exit: function (node) {
node.computed = t.isLiteral(node.property);
node.type = "MemberExpression";
}
};
exports.XJSExpressionContainer = function (node) {
exports.JSXExpressionContainer = function (node) {
return node.expression;
};
exports.XJSAttribute = {
exports.JSXAttribute = {
exit: function (node) {
var value = node.value || t.literal(true);
return t.inherits(t.property("init", node.name, value), node);
@ -43,7 +43,7 @@ var isCompatTag = function (tagName) {
return /^[a-z]|\-/.test(tagName);
};
exports.XJSOpeningElement = {
exports.JSXOpeningElement = {
exit: function (node, parent, scope, context, file) {
var reactCompat = file.opts.reactCompat;
var tagExpr = node.name;
@ -66,7 +66,7 @@ exports.XJSOpeningElement = {
var attribs = node.attributes;
if (attribs.length) {
attribs = buildXJSOpeningElementAttributes(attribs);
attribs = buildJSXOpeningElementAttributes(attribs);
} else {
attribs = t.literal(null);
}
@ -99,7 +99,7 @@ exports.XJSOpeningElement = {
* all prior attributes to an array for later processing.
*/
var buildXJSOpeningElementAttributes = function (attribs) {
var buildJSXOpeningElementAttributes = function (attribs) {
var _props = [];
var objs = [];
@ -112,7 +112,7 @@ var buildXJSOpeningElementAttributes = function (attribs) {
while (attribs.length) {
var prop = attribs.shift();
if (t.isXJSSpreadAttribute(prop)) {
if (t.isJSXSpreadAttribute(prop)) {
pushProps();
objs.push(prop.argument);
} else {
@ -141,7 +141,7 @@ var buildXJSOpeningElementAttributes = function (attribs) {
return attribs;
};
exports.XJSElement = {
exports.JSXElement = {
exit: function (node) {
var callExpr = node.openingElement;
@ -149,9 +149,9 @@ exports.XJSElement = {
var child = node.children[i];
if (t.isLiteral(child) && _.isString(child.value)) {
cleanXJSElementLiteralChild(child, callExpr.arguments);
cleanJSXElementLiteralChild(child, callExpr.arguments);
continue;
} else if (t.isXJSEmptyExpression(child)) {
} else if (t.isJSXEmptyExpression(child)) {
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/);
for (var i = 0; i < lines.length; i++) {

View File

@ -45,7 +45,7 @@
"AssignmentPattern": ["Pattern"],
"Property": ["UserWhitespacable"],
"XJSElement": ["UserWhitespacable", "Expression"],
"JSXElement": ["UserWhitespacable", "Expression"],
"ArrayExpression": ["Expression"],
"AssignmentExpression": ["Expression"],
@ -65,7 +65,7 @@
"ThisExpression": ["Expression"],
"UpdateExpression": ["Expression"],
"VirtualPropertyExpression": ["Expression"],
"XJSEmptyExpression": ["Expression"],
"XJSMemberExpression": ["Expression"],
"JSXEmptyExpression": ["Expression"],
"JSXMemberExpression": ["Expression"],
"YieldExpression": ["Expression"]
}

View File

@ -101,14 +101,14 @@
"UnionTypeAnnotation": [],
"VoidTypeAnnotation": [],
"XJSAttribute": ["name", "value"],
"XJSClosingElement": ["name"],
"XJSElement": ["openingElement", "closingElement", "children"],
"XJSEmptyExpression": [],
"XJSExpressionContainer": ["expression"],
"XJSIdentifier": [],
"XJSMemberExpression": ["object", "property"],
"XJSNamespacedName": ["namespace", "name"],
"XJSOpeningElement": ["name", "attributes"],
"XJSSpreadAttribute": ["argument"]
"JSXAttribute": ["name", "value"],
"JSXClosingElement": ["name"],
"JSXElement": ["openingElement", "closingElement", "children"],
"JSXEmptyExpression": [],
"JSXExpressionContainer": ["expression"],
"JSXIdentifier": [],
"JSXMemberExpression": ["object", "property"],
"JSXNamespacedName": ["namespace", "name"],
"JSXOpeningElement": ["name", "attributes"],
"JSXSpreadAttribute": ["argument"]
}