add comments to ambiguous code
This commit is contained in:
@@ -31,15 +31,17 @@ UMDFormatter.prototype.transform = function (ast) {
|
||||
|
||||
var factory = t.functionExpression(null, args, t.blockStatement(body));
|
||||
|
||||
// runner
|
||||
// amd
|
||||
|
||||
var defineArgs = [t.literal("exports")];
|
||||
if (this.passModuleArg) defineArgs.push(t.literal("module"));
|
||||
defineArgs = defineArgs.concat(names);
|
||||
defineArgs = [t.arrayExpression(defineArgs)];
|
||||
|
||||
// common
|
||||
|
||||
var testExports = util.template("test-exports");
|
||||
var testModule = util.template("test-module");
|
||||
var testModule = util.template("test-module");
|
||||
var commonTests = this.passModuleArg ? t.logicalExpression("&&", testExports, testModule) : testExports;
|
||||
|
||||
var commonArgs = [t.identifier("exports")];
|
||||
@@ -48,6 +50,12 @@ UMDFormatter.prototype.transform = function (ast) {
|
||||
return t.callExpression(t.identifier("require"), [name]);
|
||||
}));
|
||||
|
||||
// globals
|
||||
|
||||
var umdArgs = [];
|
||||
|
||||
//
|
||||
|
||||
var moduleName = this.getModuleName();
|
||||
if (moduleName) defineArgs.unshift(t.literal(moduleName));
|
||||
|
||||
|
||||
25
lib/6to5/transformation/transformers/react.js
vendored
25
lib/6to5/transformation/transformers/react.js
vendored
@@ -42,6 +42,7 @@ var isTag = function(tagName) {
|
||||
|
||||
exports.XJSOpeningElement = {
|
||||
exit: function (node, parent, file) {
|
||||
console.log(node);
|
||||
var reactCompat = file.opts.reactCompat;
|
||||
var tagExpr = node.name;
|
||||
var args = [];
|
||||
@@ -61,11 +62,16 @@ exports.XJSOpeningElement = {
|
||||
}
|
||||
}
|
||||
|
||||
var props = node.attributes;
|
||||
if (props.length) {
|
||||
var attribs = node.attributes;
|
||||
if (attribs.length) {
|
||||
var _props = [];
|
||||
var objs = [];
|
||||
|
||||
// so basically in order to support spread elements we
|
||||
// loop over all the attributes, breaking on spreads
|
||||
// we then push a new object containing all prior attributes
|
||||
// to an array for later processing
|
||||
|
||||
var pushProps = function () {
|
||||
if (!_props.length) return;
|
||||
|
||||
@@ -73,8 +79,8 @@ exports.XJSOpeningElement = {
|
||||
_props = [];
|
||||
};
|
||||
|
||||
while (props.length) {
|
||||
var prop = props.shift();
|
||||
while (attribs.length) {
|
||||
var prop = attribs.shift();
|
||||
if (t.isXJSSpreadAttribute(prop)) {
|
||||
pushProps();
|
||||
objs.push(prop.argument);
|
||||
@@ -86,22 +92,25 @@ exports.XJSOpeningElement = {
|
||||
pushProps();
|
||||
|
||||
if (objs.length === 1) {
|
||||
props = objs[0];
|
||||
// only one object
|
||||
attribs = objs[0];
|
||||
} else {
|
||||
// looks like we have multiple objects
|
||||
if (!t.isObjectExpression(objs[0])) {
|
||||
objs.unshift(t.objectExpression([]));
|
||||
}
|
||||
|
||||
props = t.callExpression(
|
||||
// spread it
|
||||
attribs = t.callExpression(
|
||||
t.memberExpression(t.identifier("React"), t.identifier("__spread")),
|
||||
objs
|
||||
);
|
||||
}
|
||||
} else {
|
||||
props = t.literal(null);
|
||||
attribs = t.literal(null);
|
||||
}
|
||||
|
||||
args.push(props);
|
||||
args.push(attribs);
|
||||
|
||||
if (reactCompat) {
|
||||
if (tagName && isTag(tagName)) {
|
||||
|
||||
Reference in New Issue
Block a user