Skip to content

Commit bc5e2b8

Browse files
committed
stop using nodes key for created object
1 parent 7d0bafe commit bc5e2b8

File tree

2 files changed

+48
-39
lines changed

2 files changed

+48
-39
lines changed

lib/index.js

+27-21
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var createImportedName = options && options.createImportedName || function (impo
2525
return 'i__const_' + importName.replace(/\W/g, '_') + '_' + importIndex++;
2626
};
2727

28-
exports['default'] = function (css) {
28+
exports['default'] = function (css, result) {
2929
var importAliases = [];
3030
var definitions = {};
3131

@@ -81,18 +81,21 @@ exports['default'] = function (css) {
8181
if (matchImports.exec(atRule.params)) {
8282
addImport(atRule);
8383
} else {
84+
if (atRule.params.indexOf('@value') !== -1) {
85+
result.warn('Invalid value definition: ' + atRule.params);
86+
}
87+
8488
addDefinition(atRule);
8589
}
8690
});
8791

8892
/* We want to export anything defined by now, but don't add it to the CSS yet or
89-
it well get picked up by the replacement stuff */
93+
it well get picked up by the replacement stuff */
9094
var exportDeclarations = Object.keys(definitions).map(function (key) {
9195
return _postcss2['default'].decl({
9296
value: definitions[key],
9397
prop: key,
94-
raws: { before: "\n " },
95-
_autoprefixerDisabled: true
98+
raws: { before: "\n " }
9699
});
97100
});
98101

@@ -104,32 +107,35 @@ exports['default'] = function (css) {
104107

105108
/* Add export rules if any */
106109
if (exportDeclarations.length > 0) {
107-
css.prepend(_postcss2['default'].rule({
110+
var exportRule = _postcss2['default'].rule({
108111
selector: ':export',
109-
raws: { after: "\n" },
110-
nodes: exportDeclarations
111-
}));
112+
raws: { after: "\n" }
113+
});
114+
exportRule.append(exportDeclarations);
115+
css.prepend(exportRule);
112116
}
113117

114118
/* Add import rules */
115119
importAliases.reverse().forEach(function (_ref) {
116120
var path = _ref.path;
117121
var imports = _ref.imports;
118122

119-
css.prepend(_postcss2['default'].rule({
123+
var importRule = _postcss2['default'].rule({
120124
selector: ':import(' + path + ')',
121-
raws: { after: "\n" },
122-
nodes: imports.map(function (_ref2) {
123-
var theirName = _ref2.theirName;
124-
var importedName = _ref2.importedName;
125-
return _postcss2['default'].decl({
126-
value: theirName,
127-
prop: importedName,
128-
raws: { before: "\n " },
129-
_autoprefixerDisabled: true
130-
});
131-
})
132-
}));
125+
raws: { after: "\n" }
126+
});
127+
imports.forEach(function (_ref2) {
128+
var theirName = _ref2.theirName;
129+
var importedName = _ref2.importedName;
130+
131+
importRule.append({
132+
value: theirName,
133+
prop: importedName,
134+
raws: { before: "\n " }
135+
});
136+
});
137+
138+
css.prepend(importRule);
133139
});
134140
};
135141

src/index.js

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import postcss from 'postcss'
2-
import replaceSymbols, { replaceAll } from 'icss-replace-symbols'
2+
import replaceSymbols, {replaceAll} from 'icss-replace-symbols'
33

44
const matchImports = /^(.+?)\s+from\s+("[^"]*"|'[^']*'|[\w-]+)$/
55
const matchValueDefinition = /(?:,\s+|^)([\w-]+):?\s+("[^"]*"|'[^']*'|\w+\([^\)]+\)|[^,]+)\s?/g
@@ -34,12 +34,12 @@ export default (css, result) => {
3434
let [/*match*/, theirName, myName = theirName] = tokens
3535
let importedName = createImportedName(myName)
3636
definitions[myName] = importedName
37-
return {theirName, importedName}
37+
return { theirName, importedName }
3838
} else {
3939
throw new Error(`@import statement "${alias}" is invalid!`)
4040
}
4141
})
42-
importAliases.push({path, imports})
42+
importAliases.push({ path, imports })
4343
atRule.remove()
4444
}
4545
}
@@ -58,12 +58,11 @@ export default (css, result) => {
5858
})
5959

6060
/* We want to export anything defined by now, but don't add it to the CSS yet or
61-
it well get picked up by the replacement stuff */
61+
it well get picked up by the replacement stuff */
6262
let exportDeclarations = Object.keys(definitions).map(key => postcss.decl({
6363
value: definitions[key],
6464
prop: key,
65-
raws: { before: "\n " },
66-
_autoprefixerDisabled: true
65+
raws: { before: "\n " }
6766
}))
6867

6968
/* If we have no definitions, don't continue */
@@ -74,24 +73,28 @@ export default (css, result) => {
7473

7574
/* Add export rules if any */
7675
if (exportDeclarations.length > 0) {
77-
css.prepend(postcss.rule({
76+
let exportRule = postcss.rule({
7877
selector: `:export`,
79-
raws: { after: "\n" },
80-
nodes: exportDeclarations
81-
}))
78+
raws: { after: "\n" }
79+
})
80+
exportRule.append(exportDeclarations)
81+
css.prepend(exportRule)
8282
}
8383

8484
/* Add import rules */
85-
importAliases.reverse().forEach(({path, imports}) => {
86-
css.prepend(postcss.rule({
85+
importAliases.reverse().forEach(({ path, imports }) => {
86+
let importRule = postcss.rule({
8787
selector: `:import(${path})`,
88-
raws: { after: "\n" },
89-
nodes: imports.map(({theirName, importedName}) => postcss.decl({
88+
raws: { after: "\n" }
89+
})
90+
imports.forEach(({ theirName, importedName }) => {
91+
importRule.append({
9092
value: theirName,
9193
prop: importedName,
92-
raws: { before: "\n " },
93-
_autoprefixerDisabled: true
94-
}))
95-
}))
94+
raws: { before: "\n " }
95+
})
96+
})
97+
98+
css.prepend(importRule)
9699
})
97100
}

0 commit comments

Comments
 (0)