Skip to content

Commit 17a6645

Browse files
author
Vlad Yelahin
committed
Allow processign container at-rule, add tests for it
1 parent 82ff87f commit 17a6645

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

index.js

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,21 @@ const factory = ({
166166
let preprocessPlugins = [];
167167
if (preprocessValues) {
168168
const rootPlugins = rootResult.processor.plugins;
169-
const oursPluginIndex = rootPlugins
170-
.findIndex((plugin) => plugin.postcssPlugin === PLUGIN);
169+
const oursPluginIndex = rootPlugins.findIndex(
170+
(plugin) => plugin.postcssPlugin === PLUGIN
171+
);
171172
preprocessPlugins = rootPlugins.slice(0, oursPluginIndex);
172173
}
173174

174175
const definitionCache = new Map();
175176
async function walkFile(from, dir, requiredDefinitions) {
176177
const request = importsAsModuleRequests ? urlToRequest(from) : from;
177-
const resolvedFrom = await resolve(concordContext, dir, request, resolveContext);
178+
const resolvedFrom = await resolve(
179+
concordContext,
180+
dir,
181+
request,
182+
resolveContext
183+
);
178184

179185
const cached = definitionCache.get(resolvedFrom);
180186
if (cached) {
@@ -186,8 +192,9 @@ const factory = ({
186192
...preprocessPlugins,
187193
walkerPlugin(walk, requiredDefinitions, walkFile),
188194
];
189-
const result = await postcss(plugins)
190-
.process(content, { from: resolvedFrom });
195+
const result = await postcss(plugins).process(content, {
196+
from: resolvedFrom,
197+
});
191198

192199
definitionCache.set(resolvedFrom, result.messages[0].value);
193200

@@ -197,7 +204,7 @@ const factory = ({
197204
definitions = await walk(null, walkFile, root, rootResult);
198205
rootResult.messages.push({
199206
plugin: PLUGIN,
200-
type: 'values',
207+
type: "values",
201208
values: definitions,
202209
});
203210
},
@@ -210,6 +217,10 @@ const factory = ({
210217
// eslint-disable-next-line no-param-reassign
211218
node.params = replaceValueSymbols(node.params, definitions);
212219
},
220+
container(node) {
221+
// eslint-disable-next-line no-param-reassign
222+
node.params = replaceValueSymbols(node.params, definitions);
223+
},
213224
value(node) {
214225
if (noEmitExports) {
215226
node.remove();
@@ -219,7 +230,10 @@ const factory = ({
219230
Rule(node) {
220231
if (replaceInSelectors) {
221232
// eslint-disable-next-line no-param-reassign
222-
node.selector = ICSSUtils.replaceValueSymbols(node.selector, definitions);
233+
node.selector = ICSSUtils.replaceValueSymbols(
234+
node.selector,
235+
definitions
236+
);
223237
}
224238
},
225239
};

index.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,22 @@ test('should replace inside media queries', async (t) => {
271271
);
272272
});
273273

274+
test('should replace inside container queries', async (t) => {
275+
await run(
276+
t,
277+
'@value base: 10px;\n@container (min-width: calc(base * 200)) {}',
278+
'@value base: 10px;\n@container (min-width: calc(10px * 200)) {}',
279+
);
280+
});
281+
282+
test('should replace inside named container queries', async (t) => {
283+
await run(
284+
t,
285+
'@value base: 10px;\n@container header (min-width: calc(base * 200)) {}',
286+
'@value base: 10px;\n@container header (min-width: calc(10px * 200)) {}',
287+
);
288+
});
289+
274290
test('should allow custom-property-style names', async (t) => {
275291
await run(
276292
t,

0 commit comments

Comments
 (0)