babel-plugin-vdux-transform
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -37,2 +37,13 @@ 'use strict'; | ||
function isDefaultExport(path) { | ||
var p = path; | ||
while (p.parentPath) { | ||
if (p.type === 'ExportDefaultDeclaration') return true; | ||
p = p.parentPath; | ||
} | ||
return false; | ||
} | ||
function isFunctionalComponent(path) { | ||
@@ -95,2 +106,10 @@ var node = path.node; | ||
function filenameToComponentName(basename, filename) { | ||
if (basename === 'index') { | ||
return path.basename(path.dirname(filename)); | ||
} | ||
return basename; | ||
} | ||
var wrapperFunctionTemplate = template('\n function WRAPPER_FUNCTION_ID(ID_PARAM) {\n return function(COMPONENT_PARAM) {\n return EXPRESSION\n }\n }\n '); | ||
@@ -121,6 +140,23 @@ | ||
CallExpression: function CallExpression(path) { | ||
if (path.node[VISITED_KEY] || !isHocComponent(path.node, this.options.hoc) && !isVduxLikeComponent(path.node)) { | ||
var isHoc = isHocComponent(path.node, this.options.hoc); | ||
if (path.node[VISITED_KEY] || !isHoc && !isVduxLikeComponent(path.node)) { | ||
return; | ||
} | ||
if (!isHoc && isDefaultExport(path)) { | ||
var name = filenameToComponentName(this.file.opts.basename, this.file.opts.filename); | ||
var props = path.node.arguments[0].properties; | ||
for (var i = 0; i < props.length; i++) { | ||
var prop = props[i]; | ||
var key = t.toComputedKey(prop); | ||
if (t.isLiteral(key, { value: 'name' })) { | ||
return; | ||
} | ||
} | ||
props.unshift(t.objectProperty(t.identifier('name'), t.stringLiteral(name))); | ||
} | ||
path.node[VISITED_KEY] = true; | ||
@@ -228,2 +264,3 @@ | ||
currentlyInFunction: false, | ||
file: this.file, | ||
options: this.options | ||
@@ -230,0 +267,0 @@ }); |
{ | ||
"name": "babel-plugin-vdux-transform", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Babel plugin to instrument vdux components with custom transforms", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
33194
802