babel-plugin-jss-simple
Advanced tools
Comparing version
@@ -13,9 +13,24 @@ 'use strict'; | ||
var CallVisitor = { | ||
CallExpression: function CallExpression(path, _ref2) { | ||
var name = _ref2.name; | ||
var node = path.node; | ||
if (node.callee.name === name && node.arguments.length === 1) { | ||
path.replaceWith(t.callExpression(t.identifier(name), [node.arguments[0], t.identifier('__filename')])); | ||
} | ||
} | ||
}; | ||
return { | ||
visitor: { | ||
ImportDeclaration: function ImportDeclaration(node, parent, scope) { | ||
ImportDeclaration: function ImportDeclaration(path) { | ||
var node = path.node; | ||
node.parent; | ||
if (node.source.value === 'jss-simple') { | ||
var identifier = undefined; | ||
node.specifiers.forEach(function (spec) { | ||
if (t.isDefaultImportSpecifier(spec)) { | ||
console.log('default import', spec); | ||
if (t.isImportDefaultSpecifier(spec)) { | ||
path.parentPath.traverse(CallVisitor, { name: spec.local.name }); | ||
} | ||
@@ -22,0 +37,0 @@ }); |
@@ -5,3 +5,3 @@ { | ||
"repository": "git://github.com/ashaffer/babel-plugin-jss-simple.git", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
@@ -8,0 +8,0 @@ "main": "lib/index.js", |
@@ -12,4 +12,38 @@ | ||
## What it does | ||
It transforms this: | ||
```javascript | ||
import css from 'jss-simple' | ||
const style = css({ | ||
primary: { | ||
color: 'green' | ||
} | ||
}) | ||
``` | ||
into this: | ||
```javascript | ||
import css from 'jss-simple' | ||
const style = css({ | ||
primary: { | ||
color: 'green' | ||
} | ||
}) | ||
``` | ||
## Why do I want this? | ||
If you are using hot module replacement on the client, you won't be able to tell which styles are the new styles. This provides a key (the filename) to jss-simple so that it can replace the previous style with the new style, and your stylesheet doesn't grow huge. | ||
## Do I have to call it 'css'? | ||
No. It will track whatever you've called your default import and rewrite it appropriately. | ||
## License | ||
MIT |
3082
57.49%47
34.29%49
226.67%