Skip to content

Commit

Permalink
fix: inappropriate modification of steps() function arguments (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladislav Shkodin authored and evilebottnawi committed Jan 4, 2019
1 parent 8e9514c commit 8fa1cd7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ function localizeDeclNode(node, context) {
return node;
}

function isWordAFunctionArgument(wordNode, functionNode) {
return functionNode
? functionNode.nodes.some(functionNodeChild => functionNodeChild.sourceIndex === wordNode.sourceIndex)
: false
}

function localizeAnimationShorthandDeclValues(decl, context) {
const validIdent = /^-?[_a-z][_a-z0-9-]*$/i;

Expand Down Expand Up @@ -244,13 +250,19 @@ function localizeAnimationShorthandDeclValues(decl, context) {

const didParseAnimationName = false;
let parsedAnimationKeywords = {};
let stepsFunctionNode = null;
const valueNodes = valueParser(decl.value).walk((node) => {
/* If div-token appeared (represents as comma ','), a possibility of an animation-keywords should be reflesh. */
if (node.type === 'div') {
parsedAnimationKeywords = {};
}
if (node.type === 'function' && node.value.toLowerCase() === 'steps') {
stepsFunctionNode = node;
}
const value =
node.type === 'word' ? node.value.toLowerCase() : null;
node.type === 'word' && !isWordAFunctionArgument(node, stepsFunctionNode)
? node.value.toLowerCase()
: null;

let shouldParseAnimationName = false;

Expand Down
17 changes: 17 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,23 @@ const tests = [
expected:
':local(.foo) { animation: :local(slide-right) 300ms forwards ease-out, :local(fade-in) 300ms forwards ease-out; }'
},
{
should:
'not treat "start" and "end" keywords in steps() function as identifiers',
input: [
'.foo { animation: spin 1s steps(12, end) infinite; }',
'.foo { animation: spin 1s STEPS(12, start) infinite; }',
'.foo { animation: spin 1s steps(12, END) infinite; }',
'.foo { animation: spin 1s steps(12, START) infinite; }',
].join('\n'),
expected:
[
':local(.foo) { animation: :local(spin) 1s steps(12, end) infinite; }',
':local(.foo) { animation: :local(spin) 1s STEPS(12, start) infinite; }',
':local(.foo) { animation: :local(spin) 1s steps(12, END) infinite; }',
':local(.foo) { animation: :local(spin) 1s steps(12, START) infinite; }'
].join('\n'),
},
{
should: 'handle animations with custom timing functions',
input:
Expand Down

0 comments on commit 8fa1cd7

Please sign in to comment.