diff --git a/src/main/java/com/github/sommeri/less4j/EmbeddedScripting.java b/src/main/java/com/github/sommeri/less4j/EmbeddedScripting.java new file mode 100644 index 00000000..d87938f6 --- /dev/null +++ b/src/main/java/com/github/sommeri/less4j/EmbeddedScripting.java @@ -0,0 +1,9 @@ +package com.github.sommeri.less4j; + +import com.github.sommeri.less4j.core.ast.Expression; + +public interface EmbeddedScripting { + + String toScriptExpression(Expression value, LessProblems problemsHandler); + +} diff --git a/src/main/java/com/github/sommeri/less4j/LessCompiler.java b/src/main/java/com/github/sommeri/less4j/LessCompiler.java index 8f119e64..5269aca5 100644 --- a/src/main/java/com/github/sommeri/less4j/LessCompiler.java +++ b/src/main/java/com/github/sommeri/less4j/LessCompiler.java @@ -31,7 +31,8 @@ public class Configuration { private LessSource cssResultLocation; private boolean linkSourceMap = true; - private List functionPackages = new ArrayList(); + private List functionPackages = new ArrayList(); + private EmbeddedScripting embeddedScripting; /** * This is needed in for source map. @@ -69,6 +70,14 @@ public void addCustomFunction(LessFunction functionPackage) { this.functionPackages.add(functionPackage); } + public EmbeddedScripting getEmbeddedScripting() { + return embeddedScripting; + } + + public void setEmbeddedScripting(EmbeddedScripting embeddedScripting) { + this.embeddedScripting = embeddedScripting; + } + } public class CompilationResult { diff --git a/src/main/java/com/github/sommeri/less4j/LessStringsEvaluator.java b/src/main/java/com/github/sommeri/less4j/LessStringsEvaluator.java new file mode 100644 index 00000000..607d53c3 --- /dev/null +++ b/src/main/java/com/github/sommeri/less4j/LessStringsEvaluator.java @@ -0,0 +1,20 @@ +package com.github.sommeri.less4j; + +import com.github.sommeri.less4j.core.ast.Expression; +import com.github.sommeri.less4j.utils.InStringCssPrinter; + +public class LessStringsEvaluator implements EmbeddedScripting { + + public LessStringsEvaluator() { + super(); + } + + @Override + public String toScriptExpression(Expression value, LessProblems problemsHandler) { + InStringCssPrinter builder = new InStringCssPrinter(); + builder.append(value); + String replacement = builder.toString(); + return replacement; + } + +} diff --git a/src/main/java/com/github/sommeri/less4j/core/ast/ASTCssNodeType.java b/src/main/java/com/github/sommeri/less4j/core/ast/ASTCssNodeType.java index 8a77fb17..65d7ce44 100644 --- a/src/main/java/com/github/sommeri/less4j/core/ast/ASTCssNodeType.java +++ b/src/main/java/com/github/sommeri/less4j/core/ast/ASTCssNodeType.java @@ -1,5 +1,5 @@ package com.github.sommeri.less4j.core.ast; public enum ASTCssNodeType { - UNKNOWN, CSS_CLASS, DECLARATION, STYLE_SHEET, RULE_SET, SELECTOR, SIMPLE_SELECTOR, PSEUDO_CLASS, PSEUDO_ELEMENT, SELECTOR_ATTRIBUTE, ID_SELECTOR, CHARSET_DECLARATION, FONT_FACE, IDENTIFIER_EXPRESSION, COMPOSED_EXPRESSION, STRING_EXPRESSION, NUMBER, COLOR_EXPRESSION, FUNCTION, MEDIA, COMMENT, SELECTOR_OPERATOR, SELECTOR_COMBINATOR, EXPRESSION_OPERATOR, NTH, NAMED_EXPRESSION, MEDIA_QUERY, FIXED_MEDIA_EXPRESSION, MEDIUM, MEDIUM_MODIFIER, MEDIUM_TYPE, MEDIUM_EX_FEATURE, VARIABLE_DECLARATION, VARIABLE, INDIRECT_VARIABLE, PARENTHESES_EXPRESSION, SIGNED_EXPRESSION, ARGUMENT_DECLARATION, MIXIN_REFERENCE, GUARD_CONDITION, COMPARISON_EXPRESSION, GUARD, NESTED_SELECTOR_APPENDER, REUSABLE_STRUCTURE, FAULTY_EXPRESSION, ESCAPED_SELECTOR, ESCAPED_VALUE, INTERPOLABLE_NAME, FIXED_NAME_PART, VARIABLE_NAME_PART, KEYFRAMES, KEYFRAMES_NAME, REUSABLE_STRUCTURE_NAME, VIEWPORT, GENERAL_BODY, PAGE, NAME, PAGE_MARGIN_BOX, IMPORT, FAULTY_NODE, ANONYMOUS, EMPTY_EXPRESSION, SYNTAX_ONLY_ELEMENT, UNICODE_RANGE_EXPRESSION, INTERPOLATED_MEDIA_EXPRESSION, DOCUMENT, SUPPORTS, SUPPORTS_QUERY, SUPPORTS_CONDITION_NEGATION, SUPPORTS_CONDITION_PARENTHESES, SUPPORTS_CONDITION_LOGICAL, SUPPORTS_LOGICAL_OPERATOR, EXTEND, INLINE_CONTENT + UNKNOWN, CSS_CLASS, DECLARATION, STYLE_SHEET, RULE_SET, SELECTOR, SIMPLE_SELECTOR, PSEUDO_CLASS, PSEUDO_ELEMENT, SELECTOR_ATTRIBUTE, ID_SELECTOR, CHARSET_DECLARATION, FONT_FACE, IDENTIFIER_EXPRESSION, COMPOSED_EXPRESSION, STRING_EXPRESSION, NUMBER, COLOR_EXPRESSION, FUNCTION, MEDIA, COMMENT, SELECTOR_OPERATOR, SELECTOR_COMBINATOR, EXPRESSION_OPERATOR, NTH, NAMED_EXPRESSION, MEDIA_QUERY, FIXED_MEDIA_EXPRESSION, MEDIUM, MEDIUM_MODIFIER, MEDIUM_TYPE, MEDIUM_EX_FEATURE, VARIABLE_DECLARATION, VARIABLE, INDIRECT_VARIABLE, PARENTHESES_EXPRESSION, SIGNED_EXPRESSION, ARGUMENT_DECLARATION, MIXIN_REFERENCE, GUARD_CONDITION, COMPARISON_EXPRESSION, GUARD, NESTED_SELECTOR_APPENDER, REUSABLE_STRUCTURE, FAULTY_EXPRESSION, ESCAPED_SELECTOR, ESCAPED_VALUE, INTERPOLABLE_NAME, FIXED_NAME_PART, VARIABLE_NAME_PART, KEYFRAMES, KEYFRAMES_NAME, REUSABLE_STRUCTURE_NAME, VIEWPORT, GENERAL_BODY, PAGE, NAME, PAGE_MARGIN_BOX, IMPORT, FAULTY_NODE, ANONYMOUS, EMPTY_EXPRESSION, SYNTAX_ONLY_ELEMENT, UNICODE_RANGE_EXPRESSION, INTERPOLATED_MEDIA_EXPRESSION, DOCUMENT, SUPPORTS, SUPPORTS_QUERY, SUPPORTS_CONDITION_NEGATION, SUPPORTS_CONDITION_PARENTHESES, SUPPORTS_CONDITION_LOGICAL, SUPPORTS_LOGICAL_OPERATOR, EXTEND, INLINE_CONTENT, EMBEDDED_SCRIPT } diff --git a/src/main/java/com/github/sommeri/less4j/core/ast/ComposedExpression.java b/src/main/java/com/github/sommeri/less4j/core/ast/ComposedExpression.java index 7abc33cd..bb02cf35 100644 --- a/src/main/java/com/github/sommeri/less4j/core/ast/ComposedExpression.java +++ b/src/main/java/com/github/sommeri/less4j/core/ast/ComposedExpression.java @@ -50,22 +50,30 @@ public void setRight(Expression right) { this.right = right; } + public List splitList() { + LinkedList byComma = doSplitByListOperator(Operator.COMMA); + if (byComma.size()==1) + return doSplitByListOperator(Operator.EMPTY_OPERATOR); + + return byComma; + } + @Override public List splitByComma() { - return doSplitByComma(); + return doSplitByListOperator(Operator.COMMA); } - private LinkedList doSplitByComma() { + private LinkedList doSplitByListOperator(Operator splitOper) { LinkedList result = new LinkedList(); if (operator.getOperator()!=Operator.COMMA && operator.getOperator()!=Operator.EMPTY_OPERATOR) { result.add(this); return result; } - LinkedList left = splitByComma(getLeft()); - LinkedList right = splitByComma(getRight()); + LinkedList left = splitByComma(getLeft(), splitOper); + LinkedList right = splitByComma(getRight(), splitOper); - if (operator.getOperator()!=Operator.EMPTY_OPERATOR) { + if (operator.getOperator()==splitOper) { result.addAll(left); result.addAll(right); return result; @@ -80,10 +88,10 @@ private LinkedList doSplitByComma() { return result; } - private LinkedList splitByComma(Expression expression) { + private LinkedList splitByComma(Expression expression, Operator splitOper) { if (expression.getType()==ASTCssNodeType.COMPOSED_EXPRESSION) { ComposedExpression composed = (ComposedExpression) expression; - return composed.doSplitByComma(); + return composed.doSplitByListOperator(splitOper); } else { LinkedList result = new LinkedList(); result.add(expression); diff --git a/src/main/java/com/github/sommeri/less4j/core/ast/EmbeddedScript.java b/src/main/java/com/github/sommeri/less4j/core/ast/EmbeddedScript.java new file mode 100644 index 00000000..09255f7f --- /dev/null +++ b/src/main/java/com/github/sommeri/less4j/core/ast/EmbeddedScript.java @@ -0,0 +1,46 @@ +package com.github.sommeri.less4j.core.ast; + +import java.util.Collections; +import java.util.List; + +import com.github.sommeri.less4j.core.ast.annotations.NotAstProperty; +import com.github.sommeri.less4j.core.parser.HiddenTokenAwareTree; + +public class EmbeddedScript extends Expression { + + private String value; + + public EmbeddedScript(HiddenTokenAwareTree token, String value) { + super(token); + this.value = value; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public ASTCssNodeType getType() { + return ASTCssNodeType.EMBEDDED_SCRIPT; + } + + @Override + @NotAstProperty + public List getChilds() { + return Collections.emptyList(); + } + + @Override + public String toString() { + return value; + } + + @Override + public EmbeddedScript clone() { + return (EmbeddedScript) super.clone(); + } +} diff --git a/src/main/java/com/github/sommeri/less4j/core/compiler/expressions/EmbeddedScriptFunctions.java b/src/main/java/com/github/sommeri/less4j/core/compiler/expressions/EmbeddedScriptFunctions.java index e4c4ee0d..9e6a5dd4 100644 --- a/src/main/java/com/github/sommeri/less4j/core/compiler/expressions/EmbeddedScriptFunctions.java +++ b/src/main/java/com/github/sommeri/less4j/core/compiler/expressions/EmbeddedScriptFunctions.java @@ -6,7 +6,9 @@ import com.github.sommeri.less4j.core.ast.ASTCssNodeType; import com.github.sommeri.less4j.core.ast.CssString; +import com.github.sommeri.less4j.core.ast.EmbeddedScript; import com.github.sommeri.less4j.core.ast.Expression; +import com.github.sommeri.less4j.core.ast.FaultyExpression; import com.github.sommeri.less4j.core.ast.FunctionExpression; import com.github.sommeri.less4j.core.problems.ProblemsHandler; @@ -48,20 +50,19 @@ public Expression evaluate(List parameters, ProblemsHandler problems problemsHandler.wrongNumberOfArgumentsToFunction(call.getParameter(), call.getName(), 1); Expression parameter = parameters.get(0); - if (!(parameter instanceof CssString)) { - problemsHandler.wrongArgumentTypeToFunction(parameter, name+"...`", parameter.getType(),ASTCssNodeType.STRING_EXPRESSION); + if (!(parameter instanceof EmbeddedScript)) { + problemsHandler.wrongArgumentTypeToFunction(parameter, name+"...`", parameter.getType(),ASTCssNodeType.EMBEDDED_SCRIPT); + return new FaultyExpression(call); } warn(call, problemsHandler); - CssString parameterAsStr = (CssString) parameter; + EmbeddedScript parameterAsStr = (EmbeddedScript) parameter; String value = name+parameterAsStr.getValue()+"`"; return new CssString(call.getUnderlyingStructure(), value, ""); } private void warn(FunctionExpression call, ProblemsHandler problemsHandler) { -// ALTERNATIVE_NAMES_FOR_ERROR_REPORTING.put("EMBEDDED_SCRIPT", "embedded script `...`"); -// ALTERNATIVE_NAMES_FOR_ERROR_REPORTING.put("ESCAPED_SCRIPT", "escaped script ~`...`"); problemsHandler.warnScriptingNotSupported(call, errorName); } diff --git a/src/main/java/com/github/sommeri/less4j/core/compiler/expressions/ExpressionEvaluator.java b/src/main/java/com/github/sommeri/less4j/core/compiler/expressions/ExpressionEvaluator.java index cfcb5465..605acd68 100644 --- a/src/main/java/com/github/sommeri/less4j/core/compiler/expressions/ExpressionEvaluator.java +++ b/src/main/java/com/github/sommeri/less4j/core/compiler/expressions/ExpressionEvaluator.java @@ -6,7 +6,9 @@ import java.util.Iterator; import java.util.List; +import com.github.sommeri.less4j.EmbeddedScripting; import com.github.sommeri.less4j.LessCompiler.Configuration; +import com.github.sommeri.less4j.LessStringsEvaluator; import com.github.sommeri.less4j.core.ast.ASTCssNode; import com.github.sommeri.less4j.core.ast.ASTCssNodeType; import com.github.sommeri.less4j.core.ast.AbstractVariableDeclaration; @@ -14,6 +16,7 @@ import com.github.sommeri.less4j.core.ast.ComparisonExpressionOperator; import com.github.sommeri.less4j.core.ast.ComposedExpression; import com.github.sommeri.less4j.core.ast.CssString; +import com.github.sommeri.less4j.core.ast.EmbeddedScript; import com.github.sommeri.less4j.core.ast.EscapedValue; import com.github.sommeri.less4j.core.ast.Expression; import com.github.sommeri.less4j.core.ast.ExpressionOperator; @@ -54,7 +57,9 @@ public class ExpressionEvaluator { private ColorsCalculator colorsCalculator; private ExpressionComparator comparator = new GuardsComparator(); private List functions = new ArrayList(); - private StringInterpolator stringInterpolator = new StringInterpolator(); + private StringInterpolator stringInterpolator; + private StringInterpolator embeddedScriptInterpolator; + private EmbeddedScripting embeddedScripting; public ExpressionEvaluator(ProblemsHandler problemsHandler, Configuration configuration) { this(new NullScope(), problemsHandler, configuration); @@ -66,6 +71,9 @@ public ExpressionEvaluator(IScope scope, ProblemsHandler problemsHandler, Config this.problemsHandler = problemsHandler; arithmeticCalculator = new ArithmeticCalculator(problemsHandler); colorsCalculator = new ColorsCalculator(problemsHandler); + embeddedScripting = configuration.getEmbeddedScripting() == null ? new LessStringsEvaluator() : configuration.getEmbeddedScripting(); + stringInterpolator = new StringInterpolator(problemsHandler); + embeddedScriptInterpolator = new StringInterpolator(embeddedScripting, problemsHandler); functions.add(new CustomFunctions(problemsHandler, configuration.getCustomFunctions())); functions.add(new MathFunctions(problemsHandler)); @@ -128,6 +136,11 @@ public Expression evaluate(EscapedValue input) { return new EscapedValue(input.getUnderlyingStructure(), value); } + public Expression evaluate(EmbeddedScript input) { + String value = embeddedScriptInterpolator.replaceIn(input.getValue(), this, input.getUnderlyingStructure()); + return new EmbeddedScript(input.getUnderlyingStructure(), value); + } + public Expression evaluate(Variable input) { if (cycleDetector.wouldCycle(input)) { problemsHandler.variablesCycle(cycleDetector.getCycleFor(input)); @@ -201,6 +214,9 @@ public Expression evaluate(Expression input) { case ESCAPED_VALUE: return evaluate((EscapedValue) input); + case EMBEDDED_SCRIPT: + return evaluate((EmbeddedScript) input); + //the value is already there, nothing to evaluate case IDENTIFIER_EXPRESSION: case COLOR_EXPRESSION: diff --git a/src/main/java/com/github/sommeri/less4j/core/compiler/expressions/strings/StringInterpolator.java b/src/main/java/com/github/sommeri/less4j/core/compiler/expressions/strings/StringInterpolator.java index 744dc2a5..9f275b05 100644 --- a/src/main/java/com/github/sommeri/less4j/core/compiler/expressions/strings/StringInterpolator.java +++ b/src/main/java/com/github/sommeri/less4j/core/compiler/expressions/strings/StringInterpolator.java @@ -2,16 +2,28 @@ import java.util.regex.Pattern; -import com.github.sommeri.less4j.core.ast.CssString; +import com.github.sommeri.less4j.EmbeddedScripting; +import com.github.sommeri.less4j.LessStringsEvaluator; import com.github.sommeri.less4j.core.ast.Expression; import com.github.sommeri.less4j.core.ast.Variable; import com.github.sommeri.less4j.core.compiler.expressions.ExpressionEvaluator; import com.github.sommeri.less4j.core.parser.HiddenTokenAwareTree; -import com.github.sommeri.less4j.utils.InStringCssPrinter; +import com.github.sommeri.less4j.core.problems.ProblemsHandler; public class StringInterpolator extends AbstractStringReplacer { private static final Pattern STR_INTERPOLATION = Pattern.compile("@\\{([^\\{\\}@])*\\}"); + private final EmbeddedScripting embeddedScriptEvaluator; + private final ProblemsHandler problemsHandler; + + public StringInterpolator(ProblemsHandler problemsHandler) { + this(new LessStringsEvaluator(), problemsHandler); + } + + public StringInterpolator(EmbeddedScripting embeddedScriptEvaluator, ProblemsHandler problemsHandler) { + this.embeddedScriptEvaluator = embeddedScriptEvaluator; + this.problemsHandler = problemsHandler; + } @Override protected Pattern getPattern() { @@ -20,23 +32,17 @@ protected Pattern getPattern() { @Override protected String extractMatchName(String group) { - return "@"+group.substring(2, group.length()-1); + return "@" + group.substring(2, group.length() - 1); } @Override protected String replacementValue(ExpressionEvaluator expressionEvaluator, HiddenTokenAwareTree technicalUnderlying, MatchRange matchRange) { Expression value = expressionEvaluator.evaluateIfPresent(new Variable(technicalUnderlying, matchRange.getName())); - if (value!=null && (value instanceof CssString)) { - CssString string = (CssString) value; - return replaceIn(string.getValue(), expressionEvaluator, technicalUnderlying); - } else if (value==null) { + if (value == null) { return matchRange.getFullMatch(); - } else { - InStringCssPrinter builder = new InStringCssPrinter(); - builder.append(value); - String replacement = builder.toString(); - return replacement; } + + return embeddedScriptEvaluator.toScriptExpression(value, problemsHandler); } } diff --git a/src/main/java/com/github/sommeri/less4j/core/compiler/stages/ReferencesSolver.java b/src/main/java/com/github/sommeri/less4j/core/compiler/stages/ReferencesSolver.java index 5101c95a..4816718c 100644 --- a/src/main/java/com/github/sommeri/less4j/core/compiler/stages/ReferencesSolver.java +++ b/src/main/java/com/github/sommeri/less4j/core/compiler/stages/ReferencesSolver.java @@ -10,6 +10,7 @@ import com.github.sommeri.less4j.core.ast.ASTCssNode; import com.github.sommeri.less4j.core.ast.ASTCssNodeType; import com.github.sommeri.less4j.core.ast.CssString; +import com.github.sommeri.less4j.core.ast.EmbeddedScript; import com.github.sommeri.less4j.core.ast.EscapedSelector; import com.github.sommeri.less4j.core.ast.EscapedValue; import com.github.sommeri.less4j.core.ast.Expression; @@ -42,11 +43,12 @@ public class ReferencesSolver { private final ProblemsHandler problemsHandler; private final Configuration configuration; private final AstNodesStack semiCompiledNodes = new AstNodesStack(); - private StringInterpolator stringInterpolator = new StringInterpolator(); + private final StringInterpolator stringInterpolator; public ReferencesSolver(ProblemsHandler problemsHandler, Configuration configuration) { this.problemsHandler = problemsHandler; this.configuration = configuration; + this.stringInterpolator = new StringInterpolator(problemsHandler); this.mixinsSolver = new MixinsSolver(this, semiCompiledNodes, problemsHandler, configuration); } @@ -212,6 +214,11 @@ private boolean solveIfVariableReference(ASTCssNode node, IScope scope) { manipulator.replaceAndSynchronizeSilentness(node, replacement); return true; } + case EMBEDDED_SCRIPT: { + Expression replacement = expressionEvaluator.evaluate((EmbeddedScript) node); + manipulator.replaceAndSynchronizeSilentness(node, replacement); + return true; + } case ESCAPED_SELECTOR: { SimpleSelector replacement = interpolateEscapedSelector((EscapedSelector) node, expressionEvaluator); manipulator.replaceAndSynchronizeSilentness(node, replacement); diff --git a/src/main/java/com/github/sommeri/less4j/core/parser/TermBuilder.java b/src/main/java/com/github/sommeri/less4j/core/parser/TermBuilder.java index 04a9c2ba..79adc3bf 100644 --- a/src/main/java/com/github/sommeri/less4j/core/parser/TermBuilder.java +++ b/src/main/java/com/github/sommeri/less4j/core/parser/TermBuilder.java @@ -4,6 +4,7 @@ import com.github.sommeri.less4j.core.ast.ColorExpression; import com.github.sommeri.less4j.core.ast.CssString; +import com.github.sommeri.less4j.core.ast.EmbeddedScript; import com.github.sommeri.less4j.core.ast.EmptyExpression; import com.github.sommeri.less4j.core.ast.EscapedValue; import com.github.sommeri.less4j.core.ast.Expression; @@ -215,13 +216,13 @@ public CssString createCssString(HiddenTokenAwareTree token, String quotedText) private Expression buildFromEscapedScript(HiddenTokenAwareTree token, HiddenTokenAwareTree first) { String text = first.getText(); text = text.substring(2, text.length() - 1); - return new FunctionExpression(token, "~`", new CssString(token, text, "")); + return new FunctionExpression(token, "~`", new EmbeddedScript(token, text)); } private Expression buildFromEmbeddedScript(HiddenTokenAwareTree token, HiddenTokenAwareTree first) { String text = first.getText(); text = text.substring(1, text.length() - 1); - return new FunctionExpression(token, "`", new CssString(token, text, "")); + return new FunctionExpression(token, "`", new EmbeddedScript(token, text)); } private Expression buildFromIdentifier(HiddenTokenAwareTree parent, HiddenTokenAwareTree first) { diff --git a/src/main/java/com/github/sommeri/less4j/core/problems/ProblemsHandler.java b/src/main/java/com/github/sommeri/less4j/core/problems/ProblemsHandler.java index 3700bee5..8c2ed7ce 100644 --- a/src/main/java/com/github/sommeri/less4j/core/problems/ProblemsHandler.java +++ b/src/main/java/com/github/sommeri/less4j/core/problems/ProblemsHandler.java @@ -124,7 +124,7 @@ public void wrongArgumentTypeToFunction(Expression param, String function, ASTCs collector.addError(new CompilationError(param, "Wrong argument type to function '" + function + "', expected " + PrintUtils.toTypeNames(expected) + " saw " + PrintUtils.toTypeName(received) + ".")); } - public void warnScriptingNotSupported(FunctionExpression call, String errorName) { + public void warnScriptingNotSupported(ASTCssNode call, String errorName) { collector.addError(new CompilationError(call, errorName + "are not supported. The problem can be solved using custom functions. Compilation resulted in incorrect CSS.")); } diff --git a/src/main/java/com/github/sommeri/less4j/utils/CssPrinter.java b/src/main/java/com/github/sommeri/less4j/utils/CssPrinter.java index 6d103993..7bb5410b 100644 --- a/src/main/java/com/github/sommeri/less4j/utils/CssPrinter.java +++ b/src/main/java/com/github/sommeri/less4j/utils/CssPrinter.java @@ -19,6 +19,7 @@ import com.github.sommeri.less4j.core.ast.Declaration; import com.github.sommeri.less4j.core.ast.Document; import com.github.sommeri.less4j.core.ast.ElementSubsequent; +import com.github.sommeri.less4j.core.ast.EmbeddedScript; import com.github.sommeri.less4j.core.ast.EmptyExpression; import com.github.sommeri.less4j.core.ast.EscapedValue; import com.github.sommeri.less4j.core.ast.ExpressionOperator; @@ -229,6 +230,9 @@ public boolean switchOnType(ASTCssNode node) { case ESCAPED_VALUE: return appendEscapedValue((EscapedValue) node); // TODOsm: source map + case EMBEDDED_SCRIPT: + return appendEmbeddedScript((EmbeddedScript) node); // TODOsm: source map + case KEYFRAMES: return appendKeyframes((Keyframes) node); // TODOsm: source map @@ -811,6 +815,12 @@ public boolean appendEscapedValue(EscapedValue escaped) { return true; } + public boolean appendEmbeddedScript(EmbeddedScript escaped) { + cssOnly.append(escaped.getValue()); + + return true; + } + public boolean appendIdentifierExpression(IdentifierExpression expression) { cssOnly.append(expression.getValue()); diff --git a/src/test/java/com/github/sommeri/less4j/SimpleCssTest.java b/src/test/java/com/github/sommeri/less4j/SimpleCssTest.java index 359ca848..6589bc03 100644 --- a/src/test/java/com/github/sommeri/less4j/SimpleCssTest.java +++ b/src/test/java/com/github/sommeri/less4j/SimpleCssTest.java @@ -23,8 +23,8 @@ @RunWith(Parameterized.class) public class SimpleCssTest extends AbstractFileBasedTest { - //private static final String inputLess = "src/test/resources/minitests/debug1.less"; - private static final String inputLess = "src/test/resources/minitests/javascript.less"; + private static final String inputLess = "src/test/resources/minitests/debug1.less"; + //private static final String inputLess = "src/test/resources/minitests/javascript.less"; private static final String outputCss = "src/test/resources/minitests/debug1.css"; private static final String mapdata = "src/test/resources/minitests/debug1.mapdata"; diff --git a/src/test/resources/minitests/debug1.less b/src/test/resources/minitests/debug1.less index e6300802..841cdac8 100644 --- a/src/test/resources/minitests/debug1.less +++ b/src/test/resources/minitests/debug1.less @@ -1,3 +1,5 @@ -.eval { - escaped: ~``; -} \ No newline at end of file +.escape-interpol { + @world: "world"; + width: ~'"hello" + " " + @{world}'; + width: ~`"hello" + " " + @{world}`; +}