Skip to content

Commit e66c914

Browse files
fiskerCopilot
andauthored
Support mixin name like a hex color or number (#228)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
1 parent 09f6beb commit e66c914

3 files changed

Lines changed: 33 additions & 25 deletions

File tree

‎lib/less-parser.js‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import Comment from 'postcss/lib/comment';
22
import Parser from 'postcss/lib/parser';
33

44
import tokenize from './less-tokenize.js';
5-
import { isMixinToken } from './nodes/mixin.js';
65
import { convertImport } from './nodes/import.js';
76

87
const importantPattern = /(!\s*important)$/i;
@@ -260,13 +259,12 @@ class LessParser extends Parser {
260259

261260
const [firstToken] = tokens;
262261

263-
// TODO: move this into a util function/file
264-
if (isMixinToken(firstToken)) {
265-
this.mixin(tokens);
266-
return;
267-
}
268-
269262
if (firstToken[0] === 'word') {
263+
if (firstToken[1].startsWith('.') || firstToken[1].startsWith('#')) {
264+
this.mixin(tokens);
265+
return;
266+
}
267+
270268
const secondToken = tokens[1];
271269
if (
272270
secondToken &&

‎lib/nodes/mixin.js‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

‎test/parser/mixins.test.js‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from 'ava';
2-
2+
import { outdent } from 'outdent';
33
import { parse, nodeToString } from '../../lib/index.js';
44

55
test('basic', (t) => {
@@ -305,6 +305,7 @@ test('mixin parameters with functions (#122)', (t) => {
305305
const { first } = root;
306306

307307
t.is(first.name, 'mixin');
308+
t.is(first.mixin, true);
308309
t.is(nodeToString(root), less);
309310
});
310311

@@ -321,6 +322,7 @@ test('mixin parameters with multiple parens', (t) => {
321322
const { first, last } = root;
322323

323324
t.is(first.name, 'mixin');
325+
t.is(first.mixin, true);
324326
t.is(last.selector, '.two');
325327
t.is(nodeToString(root), less);
326328
});
@@ -335,6 +337,7 @@ test('support mixin starts with a digit', (t) => {
335337
const { first, last } = root;
336338

337339
t.is(first.name, '3D');
340+
t.is(first.mixin, true);
338341
t.is(last.selector, '.3D(...)');
339342
t.is(nodeToString(root), less);
340343
});
@@ -349,6 +352,30 @@ test('support mixin starts with a backslash', (t) => {
349352
const { first, last } = root;
350353

351354
t.is(first.name, '\\123');
355+
t.is(first.mixin, true);
352356
t.is(last.name, '\\x');
353357
t.is(nodeToString(root), less);
354358
});
359+
360+
test('support mixin looks like a color or number', (t) => {
361+
const less = outdent`
362+
#eee,
363+
.3{
364+
color: red;
365+
}
366+
367+
a {
368+
#eee();
369+
.3()
370+
}
371+
`;
372+
373+
const root = parse(less);
374+
const node = root.nodes[1].nodes;
375+
376+
t.is(node[0].name, 'eee');
377+
t.is(node[0].mixin, true);
378+
t.is(node[1].name, '3');
379+
t.is(node[1].mixin, true);
380+
t.is(nodeToString(root), less);
381+
});

0 commit comments

Comments
 (0)