Skip to content

Fix inappropriate modification of steps() function arguments #6

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
Jan 4, 2019
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
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