babel-plugin-react-originjs
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -23,3 +23,7 @@ 'use strict'; | ||
} | ||
if (types.isImportDefaultSpecifier(spec)) { | ||
methodName = value + '/' + spec.local.name; | ||
} | ||
}); | ||
methodName = methodName || 'noname'; | ||
} | ||
@@ -38,8 +42,30 @@ }, | ||
if (!types.isIdentifier(node.callee)) { | ||
if (object && object.name.toLowerCase() === 'reactdom') { | ||
var fn = 'function(render, name, argus){ render.apply(this, argus); }'; | ||
var argus = t.arrayExpression(node.arguments); | ||
var icatReact = "window['ICAT']? window['ICAT'].react : "; | ||
if (object && (object.name || '').toLowerCase() === 'reactdom') { | ||
(function () { | ||
var fn = 'function(){\n var argus = Array.prototype.slice.call(arguments),\n rcDom = argus[1], el = argus[4], vdom = argus[5]; \n rcDom.render(vdom, el);\n }'; | ||
var argus = t.arrayExpression(node.arguments); | ||
var icatReact = "window['ICAT']? window['ICAT'].react : "; | ||
var arr = [t.stringLiteral(methodName), node.callee.object]; | ||
node.arguments.map(function (arg) { | ||
if (t.isJSXElement(arg)) { | ||
arr.push(arg.openingElement.name); | ||
if (arg.openingElement.attributes.length) { | ||
(function () { | ||
var attrs = []; | ||
arg.openingElement.attributes.map(function (item) { | ||
attrs.push(t.objectProperty(t.stringLiteral(item.name.name), item.value)); | ||
}); | ||
arr.push(t.objectExpression(attrs)); | ||
})(); | ||
} else { | ||
arr.push(t.identifier('null')); | ||
} | ||
} else { | ||
arr.push(arg); | ||
} | ||
}); | ||
path.replaceWith(t.callExpression(t.identifier("(" + icatReact + fn + ")"), [node.callee, t.stringLiteral(methodName), argus])); | ||
arr.push(node.arguments[0]); | ||
path.replaceWith(t.callExpression(t.identifier("(" + icatReact + fn + ")"), arr)); | ||
})(); | ||
} | ||
@@ -46,0 +72,0 @@ } |
{ | ||
"name": "babel-plugin-react-originjs", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Make react-components into original js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -15,3 +15,7 @@ export default function({ types }) { | ||
} | ||
}); | ||
if (types.isImportDefaultSpecifier(spec)) { | ||
methodName = value + '/' + spec.local.name; | ||
} | ||
}); | ||
methodName = methodName || 'noname'; | ||
} | ||
@@ -27,11 +31,31 @@ }, | ||
if (!types.isIdentifier(node.callee)) { | ||
if(object && object.name.toLowerCase()==='reactdom'){ | ||
let fn = 'function(render, name, argus){ render.apply(this, argus); }'; | ||
if(object && (object.name||'').toLowerCase()==='reactdom'){ | ||
let fn = `function(){ | ||
var argus = Array.prototype.slice.call(arguments), | ||
rcDom = argus[1], el = argus[4], vdom = argus[5]; | ||
rcDom.render(vdom, el); | ||
}`; | ||
let argus = t.arrayExpression(node.arguments); | ||
let icatReact = "window['ICAT']? window['ICAT'].react : "; | ||
let arr = [t.stringLiteral(methodName), node.callee.object]; | ||
node.arguments.map(arg => { | ||
if(t.isJSXElement(arg)) { | ||
arr.push(arg.openingElement.name); | ||
if(arg.openingElement.attributes.length){ | ||
let attrs = []; | ||
arg.openingElement.attributes.map(item=>{ | ||
attrs.push(t.objectProperty(t.stringLiteral(item.name.name), item.value)); | ||
}); | ||
arr.push(t.objectExpression(attrs)); | ||
} else { | ||
arr.push(t.identifier('null')); | ||
} | ||
} else { | ||
arr.push(arg); | ||
} | ||
}); | ||
arr.push(node.arguments[0]); | ||
path.replaceWith( | ||
t.callExpression( | ||
t.identifier("(" + icatReact + fn + ")"), | ||
[node.callee, t.stringLiteral(methodName), argus]) | ||
t.callExpression(t.identifier("(" + icatReact + fn + ")"), arr) | ||
) | ||
@@ -38,0 +62,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5782
124
0