Skip to content

fix: unknown functions hang. fixes #112 #114

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

Merged
merged 1 commit into from
Apr 26, 2020
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions lib/nodes/Func.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { registerWalker } = require('../walker');
const Container = require('./Container');
const Punctuation = require('./Punctuation');

const allFunctions = [
const cssFunctions = [
'annotation',
'attr',
'blur',
Expand Down Expand Up @@ -85,7 +85,7 @@ const allFunctions = [
'var'
];
const vendorPrefixes = ['-webkit-', '-moz-', '-ms-', '-o-'];
const reFunctions = new RegExp(`^(${vendorPrefixes.join('|')})?(${allFunctions.join('|')})`, 'i');
const reFunctions = new RegExp(`^(${vendorPrefixes.join('|')})?(${cssFunctions.join('|')})`, 'i');
const rePunctuation = new RegExp(`^(\\${Punctuation.chars.join('|\\')})`);
const reColorFunctions = /^(hsla?|hwb|lab|lch|rgba?)$/i;
const reVar = /^var$/i;
Expand Down Expand Up @@ -122,7 +122,8 @@ class Func extends Container {
let lastToken = brackets;

// fixes #92
if (!reFunctions.test(node.name) && !/^[a-zA-Z]+$/.test(node.name)) {
// eslint-disable-next-line no-useless-escape
if (!reFunctions.test(node.name) && !/^[a-zA-Z\-]+$/.test(node.name)) {
const nameTokens = getTokens(node.name);
tokens.unshift(...nameTokens, brackets);
parser.back(tokens);
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ module.exports = {
'rotate(0.5grad)',
'rotate(0.5turn)',
'1em/var(--line-height)',
'local(foo),local(bar)'
'local(foo),local(bar)',
'bat-man(#000)',
'conic-gradient()'
],

throws: ['url( /gfx/img/bg.jpg ']
Expand Down
114 changes: 114 additions & 0 deletions test/snapshots/func.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,78 @@ Generated by [AVA](https://avajs.dev).
},
]

## bat-man(#000)

> Snapshot 1

'bat-man(#000)'

> Snapshot 2

'bat-man(#000)'

> Snapshot 3

[
Func {
isColor: false,
isVar: false,
name: 'bat-man',
nodes: [
Word {
isColor: true,
isHex: true,
isUrl: false,
isVariable: false,
parent: [Circular],
raws: {
after: '',
before: '',
},
source: {
end: {
column: 1,
line: 1,
},
input: Input {
css: '#000',
hasBOM: false,
id: '<input css 78>',
},
start: {
column: 1,
line: 1,
},
},
type: 'word',
value: '#000',
},
],
params: '(#000)',
raws: {
after: '',
before: '',
semicolon: false,
},
source: {
end: {
column: 8,
line: 1,
},
input: Input {
css: 'bat-man(#000)',
hasBOM: false,
id: '<input css 77>',
},
start: {
column: 1,
line: 1,
},
},
type: 'func',
},
]

## calc(((768px - 100vw) / 2) - 15px)

> Snapshot 1
Expand Down Expand Up @@ -1475,6 +1547,48 @@ Generated by [AVA](https://avajs.dev).
},
]

## conic-gradient()

> Snapshot 1

'conic-gradient()'

> Snapshot 2

'conic-gradient()'

> Snapshot 3

[
Func {
isColor: false,
isVar: false,
name: 'conic-gradient',
nodes: [],
params: '()',
raws: {
after: '',
before: '',
},
source: {
end: {
column: 15,
line: 1,
},
input: Input {
css: 'conic-gradient()',
hasBOM: false,
id: '<input css 79>',
},
start: {
column: 1,
line: 1,
},
},
type: 'func',
},
]

## hwb(90deg 0% 0% / 0.5)

> Snapshot 1
Expand Down
Binary file modified test/snapshots/func.test.js.snap
Binary file not shown.