babel-plugin-react-cssmoduleify
Advanced tools
Comparing version 0.9.1 to 0.9.2
35
index.js
@@ -101,5 +101,10 @@ /** | ||
const convertStringKeysToComputedProperties = (node) => { | ||
// return node; | ||
node.properties.forEach(p => { | ||
// ensure we're idempotent | ||
if ( | ||
p.key.type === 'MemberExpression' && | ||
p.object === cssModuleId | ||
) { | ||
return; | ||
} | ||
p.key = t.memberExpression( | ||
@@ -118,3 +123,7 @@ cssModuleId, | ||
if (v.type === 'Identifier') { | ||
const bindings = scope.bindings[v.name]; | ||
let bindings; | ||
while (!(bindings = scope.bindings[v.name]) && scope.parent) { | ||
scope = scope.parent; | ||
} | ||
if (!bindings) { | ||
@@ -330,4 +339,20 @@ return t.memberExpression( | ||
const {properties} = node.arguments[1]; | ||
if (!properties) return; | ||
node.arguments[1].properties = properties.map(prop => handleProp(prop, node, scope, file)); | ||
if (properties) { | ||
node.arguments[1].properties = properties.map(prop => handleProp(prop, node, scope, file)); | ||
return; | ||
} else { | ||
// an ObjectSpreadProperty was used in the source | ||
if ( | ||
node.arguments[1].type === 'CallExpression' && | ||
node.arguments[1].callee.name.indexOf('extends') !== -1 | ||
) { | ||
node.arguments[1].arguments = node.arguments[1].arguments.map(prop => { | ||
if (prop.type === 'ObjectExpression') { | ||
prop.properties = prop.properties.map(prop => handleProp(prop, node, scope, file)); | ||
} | ||
return prop; | ||
}); | ||
} | ||
} | ||
}, | ||
@@ -334,0 +359,0 @@ |
@@ -96,5 +96,7 @@ /** | ||
var convertStringKeysToComputedProperties = function convertStringKeysToComputedProperties(node) { | ||
// return node; | ||
node.properties.forEach(function (p) { | ||
// ensure we're idempotent | ||
if (p.key.type === 'MemberExpression' && p.object === cssModuleId) { | ||
return; | ||
} | ||
p.key = t.memberExpression(cssModuleId, t.literal(p.key.value), true); | ||
@@ -109,3 +111,7 @@ p.computed = true; | ||
if (v.type === 'Identifier') { | ||
var bindings = scope.bindings[v.name]; | ||
var bindings = undefined; | ||
while (!(bindings = scope.bindings[v.name]) && scope.parent) { | ||
scope = scope.parent; | ||
} | ||
if (!bindings) { | ||
@@ -256,6 +262,21 @@ return t.memberExpression(cssModuleId, t.literal(v.name), true); | ||
if (!properties) return; | ||
node.arguments[1].properties = properties.map(function (prop) { | ||
return handleProp(prop, node, scope, file); | ||
}); | ||
if (properties) { | ||
node.arguments[1].properties = properties.map(function (prop) { | ||
return handleProp(prop, node, scope, file); | ||
}); | ||
return; | ||
} else { | ||
// an ObjectSpreadProperty was used in the source | ||
if (node.arguments[1].type === 'CallExpression' && node.arguments[1].callee.name.indexOf('extends') !== -1) { | ||
node.arguments[1].arguments = node.arguments[1].arguments.map(function (prop) { | ||
if (prop.type === 'ObjectExpression') { | ||
prop.properties = prop.properties.map(function (prop) { | ||
return handleProp(prop, node, scope, file); | ||
}); | ||
} | ||
return prop; | ||
}); | ||
} | ||
} | ||
}, | ||
@@ -262,0 +283,0 @@ |
{ | ||
"name": "babel-plugin-react-cssmoduleify", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"description": "Babel plugin to transform traditional classNames to CSS Modules", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"prepublish": "babel index.js -o lib/index.js", | ||
"build": "babel index.js -o lib/index.js", | ||
"prepublish": "npm run build", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
@@ -9,0 +10,0 @@ }, |
@@ -9,2 +9,9 @@ # babel-plugin-react-cssmoduleify | ||
Please note this is a work in progress and does not account for all JavaScript | ||
constructs yet. It is undergoing the “trial-by-fire” support methodology. If we | ||
detect a currently-unsupported construct we will print a warning to the console | ||
with a link to report it at our issue tracker. Please include as much code as | ||
possible to make it easier for us to add support. | ||
## Usage | ||
@@ -37,2 +44,6 @@ | ||
This works on both post-babel compiled JavaScript as well as the original | ||
source. The following example demonstrates the modifications on the babel output | ||
of a React component. | ||
### Before | ||
@@ -39,0 +50,0 @@ |
28935
592
229