aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordenisanisimov <denis@vaadin.com>2014-01-27 13:20:31 +0200
committerDenis Anisimov <denis@vaadin.com>2014-02-13 11:45:13 +0200
commit6f5b334247e024143b82c1c9e0c84b41d9bd2abb (patch)
treeeffbb89bbdf74f2e18b9ea8f80b50d80977a4bd0
parent3a9327925b2d987430866a6ec1806a4b35ff2697 (diff)
downloadvaadin-framework-6f5b334247e024143b82c1c9e0c84b41d9bd2abb.tar.gz
vaadin-framework-6f5b334247e024143b82c1c9e0c84b41d9bd2abb.zip
Avoid error in rgb() function if variables are used (#12752).
Change-Id: Id51ffef257c193900026a4644eb99dbd3926c668
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java41
-rw-r--r--theme-compiler/src/com/vaadin/sass/internal/parser/Parser.jj17
-rw-r--r--theme-compiler/tests/resources/css/functions.css1
-rw-r--r--theme-compiler/tests/resources/scss/functions.scss4
-rw-r--r--theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Functions.java6
5 files changed, 46 insertions, 23 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java b/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java
index e68b24355b..06a413649e 100644
--- a/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java
+++ b/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.java
@@ -5857,12 +5857,15 @@ LexicalUnitImpl result = null;
if ("rgb(".equals(f)) {
// this is a RGB declaration (e.g. rgb(255, 50%, 0) )
int i = 0;
+ boolean hasVariables = false;
while (loop && l != null && i < 5) {
switch (i) {
case 0:
case 2:
case 4:
- if ((l.getLexicalUnitType() != LexicalUnit.SAC_INTEGER)
+ if (l.getLexicalUnitType() == SCSSLexicalUnit.SCSS_VARIABLE) {
+ hasVariables = true;
+ } else if ((l.getLexicalUnitType() != LexicalUnit.SAC_INTEGER)
&& (l.getLexicalUnitType() != LexicalUnit.SAC_PERCENTAGE)) {
loop = false;
}
@@ -5882,9 +5885,15 @@ LexicalUnitImpl result = null;
}
}
if ((i == 5) && loop && (l == null)) {
- {if (true) return LexicalUnitImpl.createRGBColor(n.beginLine,
- n.beginColumn,
- prev, params);}
+ if (hasVariables) {
+ {if (true) return LexicalUnitImpl.createFunction(n.beginLine,
+ n.beginColumn, prev,
+ f.substring(0, f.length() - 1), params);}
+ } else {
+ {if (true) return LexicalUnitImpl.createRGBColor(n.beginLine,
+ n.beginColumn,
+ prev, params);}
+ }
} else {
if (errorHandler != null) {
String errorText;
@@ -7221,6 +7230,11 @@ LexicalUnitImpl result = null;
return false;
}
+ private boolean jj_3R_256() {
+ if (jj_scan_token(HASH)) return true;
+ return false;
+ }
+
private boolean jj_3R_216() {
if (jj_scan_token(NUMBER)) return true;
return false;
@@ -7314,8 +7328,8 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_256() {
- if (jj_scan_token(HASH)) return true;
+ private boolean jj_3R_257() {
+ if (jj_scan_token(URL)) return true;
return false;
}
@@ -7324,11 +7338,6 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_257() {
- if (jj_scan_token(URL)) return true;
- return false;
- }
-
private boolean jj_3_2() {
if (jj_3R_177()) return true;
if (jj_3R_178()) return true;
@@ -7371,6 +7380,11 @@ LexicalUnitImpl result = null;
return false;
}
+ private boolean jj_3R_258() {
+ if (jj_scan_token(UNICODERANGE)) return true;
+ return false;
+ }
+
private boolean jj_3R_197() {
Token xsp;
xsp = jj_scanpos;
@@ -7409,11 +7423,6 @@ LexicalUnitImpl result = null;
return false;
}
- private boolean jj_3R_258() {
- if (jj_scan_token(UNICODERANGE)) return true;
- return false;
- }
-
private boolean jj_3_8() {
Token xsp;
xsp = jj_scanpos;
diff --git a/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.jj b/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.jj
index f8b6a86af7..9be5236bc3 100644
--- a/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.jj
+++ b/theme-compiler/src/com/vaadin/sass/internal/parser/Parser.jj
@@ -2575,12 +2575,15 @@ LexicalUnitImpl function(char operator, LexicalUnitImpl prev) :
if ("rgb(".equals(f)) {
// this is a RGB declaration (e.g. rgb(255, 50%, 0) )
int i = 0;
+ boolean hasVariables = false;
while (loop && l != null && i < 5) {
switch (i) {
case 0:
case 2:
case 4:
- if ((l.getLexicalUnitType() != LexicalUnit.SAC_INTEGER)
+ if (l.getLexicalUnitType() == SCSSLexicalUnit.SCSS_VARIABLE) {
+ hasVariables = true;
+ } else if ((l.getLexicalUnitType() != LexicalUnit.SAC_INTEGER)
&& (l.getLexicalUnitType() != LexicalUnit.SAC_PERCENTAGE)) {
loop = false;
}
@@ -2600,9 +2603,15 @@ LexicalUnitImpl function(char operator, LexicalUnitImpl prev) :
}
}
if ((i == 5) && loop && (l == null)) {
- return LexicalUnitImpl.createRGBColor(n.beginLine,
- n.beginColumn,
- prev, params);
+ if (hasVariables) {
+ return LexicalUnitImpl.createFunction(n.beginLine,
+ n.beginColumn, prev,
+ f.substring(0, f.length() - 1), params);
+ } else {
+ return LexicalUnitImpl.createRGBColor(n.beginLine,
+ n.beginColumn,
+ prev, params);
+ }
} else {
if (errorHandler != null) {
String errorText;
diff --git a/theme-compiler/tests/resources/css/functions.css b/theme-compiler/tests/resources/css/functions.css
index 3f6c2bd810..45d42b34de 100644
--- a/theme-compiler/tests/resources/css/functions.css
+++ b/theme-compiler/tests/resources/css/functions.css
@@ -13,4 +13,5 @@
color: #f00;
color: hsl(33, 7%, 89%);
color: hsl(33, 7%, 95%);
+ color: rgb(1, 2, 3);
} \ No newline at end of file
diff --git a/theme-compiler/tests/resources/scss/functions.scss b/theme-compiler/tests/resources/scss/functions.scss
index 93c1a6a64a..4230850b2a 100644
--- a/theme-compiler/tests/resources/scss/functions.scss
+++ b/theme-compiler/tests/resources/scss/functions.scss
@@ -1,5 +1,8 @@
$base-color : hsl(33, 7%, 89%);
$app-bg-color : lighten($base-color, 6%);
+$red:1;
+$green:2;
+$blue:3;
.main {
margin: abs(-2px);
border: ceil(10.4px);
@@ -15,4 +18,5 @@ $app-bg-color : lighten($base-color, 6%);
color: lighten(#800, 20%);
color : $base-color;
color : $app-bg-color;
+ color: rgb($red, $green, $blue);
} \ No newline at end of file
diff --git a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Functions.java b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Functions.java
index 5c41494ac6..b50172ac2f 100644
--- a/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Functions.java
+++ b/theme-compiler/tests/src/com/vaadin/sass/testcases/scss/Functions.java
@@ -41,9 +41,9 @@ public class Functions extends AbstractTestBase {
parser.setDocumentHandler(handler);
parser.parseStyleSheet(getClass().getResource(scss).getPath());
ScssStylesheet root = handler.getStyleSheet();
- Assert.assertEquals(3, root.getChildren().size());
- BlockNode blockNode = (BlockNode) root.getChildren().get(2);
- Assert.assertEquals(14, blockNode.getChildren().size());
+ Assert.assertEquals(6, root.getChildren().size());
+ BlockNode blockNode = (BlockNode) root.getChildren().get(5);
+ Assert.assertEquals(15, blockNode.getChildren().size());
}
@Test