Skip to content

Commit f1c0f50

Browse files
authored
fix object assignments (#123)
1 parent 7ce5f1d commit f1c0f50

4 files changed

Lines changed: 21 additions & 7 deletions

File tree

test/fixtures/plugins-expected.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
-webkit-transform: translate(0, 0);
33
transform: translate(0, 0);
44
}
5+
._75161010 .hello,._75161010 .world {
6+
-webkit-transform: translate(0, 0);
7+
transform: translate(0, 0);
8+
}

test/fixtures/plugins-source.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,12 @@ const prefix = sf`
55
transform: translate(0, 0);
66
}
77
`
8+
9+
var foo = {}
10+
foo.bar = sf`
11+
:host .hello, :host .world {
12+
transform: translate(0, 0);
13+
}
14+
`
15+
816
console.log(prefix)

test/plugins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test('plugins', function (t) {
2828
.transform(function (file) {
2929
return through(function (buf, enc, next) {
3030
const str = buf.toString('utf8')
31-
this.push(str.replace(/sheetify\/insert/, 'insert-css'))
31+
this.push(str.replace(/sheetify\/insert/g, 'insert-css'))
3232
next()
3333
})
3434
})

transform.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,16 @@ function transform (filename, options) {
107107
if (node.type !== 'CallExpression') return
108108
if (!node.callee || node.callee.type !== 'Identifier') return
109109
if (node.callee.name !== mname) return
110+
var pathOpts = { basedir: path.dirname(filename) }
110111
try {
111-
var resolvePath = cssResolve(node.arguments[0].value, {
112-
basedir: path.dirname(filename)
113-
})
114-
self.emit('file', resolvePath)
112+
var resolvePath = cssResolve(node.arguments[0].value, pathOpts)
115113
} catch (err) {
116114
return self.emit('error', err)
117115
}
118116

119-
const iOpts = (node.arguments[1])
117+
self.emit('file', resolvePath)
118+
119+
const iOpts = node.arguments[1]
120120
? xtend(opts, staticEval(node.arguments[1]))
121121
: opts
122122

@@ -149,7 +149,9 @@ function transform (filename, options) {
149149
' || true) && ' + JSON.stringify(prefix) + ')'
150150
].join('')
151151

152-
const lolSemicolon = (val.node.parent.type === 'VariableDeclarator')
152+
const parentNodeType = val.node.parent.type
153+
const lolSemicolon = parentNodeType === 'VariableDeclarator' ||
154+
parentNodeType === 'AssignmentExpression'
153155
? ''
154156
: ';'
155157
val.node.update(lolSemicolon + str)

0 commit comments

Comments
 (0)