From 095bbac8dfa12b83a4431662ecd91497faa62287 Mon Sep 17 00:00:00 2001 From: Vladislav Shkodin Date: Thu, 3 Jan 2019 14:23:59 +0200 Subject: [PATCH] Fix inappropriate modification of steps() function arguments --- index.js | 14 +++++++++++++- test.js | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e2e2791..e772160 100644 --- a/index.js +++ b/index.js @@ -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; @@ -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; diff --git a/test.js b/test.js index 9ec62ff..d83090d 100644 --- a/test.js +++ b/test.js @@ -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: