Skip to content

Commit 11b91a0

Browse files
committed
fix: comma separated funcs with no spaces. fixes #91
1 parent 3552433 commit 11b91a0

File tree

6 files changed

+160
-2
lines changed

6 files changed

+160
-2
lines changed

lib/nodes/Func.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const { getTokens } = require('../tokenize');
1212
const { registerWalker } = require('../walker');
1313

1414
const Container = require('./Container');
15+
const Punctuation = require('./Punctuation');
1516

1617
const allFunctions = [
1718
'annotation',
@@ -86,6 +87,7 @@ const allFunctions = [
8687
const colorFunctions = ['hsl', 'hsla', 'rgb', 'rgba'];
8788
const vendorPrefixes = ['-webkit-', '-moz-', '-ms-', '-o-'];
8889
const reFunctions = new RegExp(`^(${vendorPrefixes.join('|')})?(${allFunctions.join('|')})`, 'i');
90+
const rePunctuation = new RegExp(`^(\\${Punctuation.chars.join('|\\')})`);
8991
const reVar = /^--[^\s]+$/;
9092

9193
class Func extends Container {
@@ -104,6 +106,8 @@ class Func extends Container {
104106
return (
105107
tokens.length > 1 &&
106108
tokens[0][0] === 'word' &&
109+
// fixes #91
110+
!rePunctuation.test(tokens[0][1]) &&
107111
(tokens[1][0] === 'brackets' || tokens[1][0] === '(')
108112
);
109113
}

lib/nodes/Punctuation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Punctuation extends Node {
2424
}
2525

2626
static get chars() {
27-
return [':', '(', ')', '[', ']', '{', '}'];
27+
return [',', ':', '(', ')', '[', ']', '{', '}'];
2828
}
2929

3030
static fromTokens(tokens, parser) {

test/fixtures/func.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ module.exports = {
4141
'rotate(0.5rad)',
4242
'rotate(0.5grad)',
4343
'rotate(0.5turn)',
44-
'1em/var(--line-height)'
44+
'1em/var(--line-height)',
45+
'local(foo),local(bar)'
4546
],
4647

4748
throws: ['url( /gfx/img/bg.jpg ']

test/func.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ for (const fixture of snapshot) {
2121
delete node.parent; // eslint-disable-line no-param-reassign
2222
return node;
2323
});
24+
// console.log(nodes);
2425
const string = nodeToString(root);
2526

2627
t.is(string, fixture);

test/snapshots/func.test.js.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3481,3 +3481,155 @@ Generated by [AVA](https://ava.li).
34813481
type: 'func',
34823482
},
34833483
]
3484+
3485+
## local(foo),local(bar)
3486+
3487+
> Snapshot 1
3488+
3489+
'local(foo)'
3490+
3491+
> Snapshot 2
3492+
3493+
'local(foo),local(bar)'
3494+
3495+
> Snapshot 3
3496+
3497+
[
3498+
Func {
3499+
isColor: false,
3500+
isVar: false,
3501+
name: 'local',
3502+
nodes: [
3503+
Word {
3504+
isColor: false,
3505+
isHex: false,
3506+
isUrl: false,
3507+
isVariable: false,
3508+
parent: [Circular],
3509+
raws: {
3510+
after: '',
3511+
before: '',
3512+
},
3513+
source: {
3514+
end: {
3515+
column: 1,
3516+
line: 1,
3517+
},
3518+
input: Input {
3519+
css: 'foo',
3520+
hasBOM: false,
3521+
id: '<input css 69>',
3522+
},
3523+
start: {
3524+
column: 1,
3525+
line: 1,
3526+
},
3527+
},
3528+
type: 'word',
3529+
value: 'foo',
3530+
},
3531+
],
3532+
params: '(foo)',
3533+
raws: {
3534+
after: '',
3535+
before: '',
3536+
semicolon: false,
3537+
},
3538+
source: {
3539+
end: {
3540+
column: 6,
3541+
line: 1,
3542+
},
3543+
input: Input {
3544+
css: 'local(foo),local(bar)',
3545+
hasBOM: false,
3546+
id: '<input css 68>',
3547+
},
3548+
start: {
3549+
column: 1,
3550+
line: 1,
3551+
},
3552+
},
3553+
type: 'func',
3554+
},
3555+
Punctuation {
3556+
raws: {
3557+
after: '',
3558+
before: '',
3559+
},
3560+
source: {
3561+
end: {
3562+
column: 11,
3563+
line: 1,
3564+
},
3565+
input: Input {
3566+
css: 'local(foo),local(bar)',
3567+
hasBOM: false,
3568+
id: '<input css 68>',
3569+
},
3570+
start: {
3571+
column: 11,
3572+
line: 1,
3573+
},
3574+
},
3575+
type: 'punctuation',
3576+
value: ',',
3577+
},
3578+
Func {
3579+
isColor: false,
3580+
isVar: false,
3581+
name: 'local',
3582+
nodes: [
3583+
Word {
3584+
isColor: false,
3585+
isHex: false,
3586+
isUrl: false,
3587+
isVariable: false,
3588+
parent: [Circular],
3589+
raws: {
3590+
after: '',
3591+
before: '',
3592+
},
3593+
source: {
3594+
end: {
3595+
column: 1,
3596+
line: 1,
3597+
},
3598+
input: Input {
3599+
css: 'bar',
3600+
hasBOM: false,
3601+
id: '<input css 70>',
3602+
},
3603+
start: {
3604+
column: 1,
3605+
line: 1,
3606+
},
3607+
},
3608+
type: 'word',
3609+
value: 'bar',
3610+
},
3611+
],
3612+
params: '(bar)',
3613+
raws: {
3614+
after: '',
3615+
before: '',
3616+
semicolon: false,
3617+
},
3618+
source: {
3619+
end: {
3620+
column: 17,
3621+
line: 1,
3622+
},
3623+
input: Input {
3624+
css: 'local(foo),local(bar)',
3625+
hasBOM: false,
3626+
id: '<input css 68>',
3627+
},
3628+
start: {
3629+
column: 12,
3630+
line: 1,
3631+
},
3632+
},
3633+
type: 'func',
3634+
},
3635+
]

test/snapshots/func.test.js.snap

709 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)