Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent mutability issue, round 2 #56

Merged
merged 1 commit into from
Jun 19, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,31 @@ function AtImport(options) {
)

return function(styles, result) {
const opts = assign({}, options || {})
// auto add from option if possible
if (
!options.from &&
!opts.from &&
styles &&
styles.nodes &&
styles.nodes[0] &&
styles.nodes[0].source &&
styles.nodes[0].source.input &&
styles.nodes[0].source.input.file
) {
options.from = styles.nodes[0].source.input.file
opts.from = styles.nodes[0].source.input.file
}

// if from available, prepend from directory in the path array
addInputToPath(options)
addInputToPath(opts)

// if we got nothing for the path, just use cwd
if (options.path.length === 0) {
options.path.push(process.cwd())
if (opts.path.length === 0) {
opts.path.push(process.cwd())
}

var importedFiles = {}
if (options.from) {
importedFiles[options.from] = {
if (opts.from) {
importedFiles[opts.from] = {
"": true,
}
}
Expand All @@ -74,7 +75,7 @@ function AtImport(options) {
parseStyles(
result,
styles,
options,
opts,
insertRules,
importedFiles,
ignoredAtRules,
Expand All @@ -83,8 +84,8 @@ function AtImport(options) {
)
addIgnoredAtRulesOnTop(styles, ignoredAtRules)

if (typeof options.onImport === "function") {
options.onImport(Object.keys(importedFiles))
if (typeof opts.onImport === "function") {
opts.onImport(Object.keys(importedFiles))
}
}
}
Expand Down