From eabbcd31ad34d27875acdd188ee1589fcfc2bc7a Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 13 Jan 2015 01:50:10 +1100 Subject: [PATCH] add comments to ambiguous code --- lib/6to5/transformation/modules/umd.js | 12 +++++++-- lib/6to5/transformation/transformers/react.js | 25 +++++++++++++------ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/6to5/transformation/modules/umd.js b/lib/6to5/transformation/modules/umd.js index 32dde9759a..f3933da7ce 100644 --- a/lib/6to5/transformation/modules/umd.js +++ b/lib/6to5/transformation/modules/umd.js @@ -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)); diff --git a/lib/6to5/transformation/transformers/react.js b/lib/6to5/transformation/transformers/react.js index fd0d7140ac..1e03298253 100644 --- a/lib/6to5/transformation/transformers/react.js +++ b/lib/6to5/transformation/transformers/react.js @@ -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)) {