diff options
author | Henri Sara <hesara@vaadin.com> | 2012-12-14 14:13:22 +0200 |
---|---|---|
committer | Henri Sara <hesara@vaadin.com> | 2012-12-14 14:13:22 +0200 |
commit | aff0802d4b22e3d6f1e97c503aa8c5f3dfedd53b (patch) | |
tree | f8a13e6bba10ae93df427e2623975045853891e5 /theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java | |
parent | eced3091e368bb6a4bb36c3df0d2567668ba6c72 (diff) | |
download | vaadin-framework-aff0802d4b22e3d6f1e97c503aa8c5f3dfedd53b.tar.gz vaadin-framework-aff0802d4b22e3d6f1e97c503aa8c5f3dfedd53b.zip |
Use separate scope for variables within a mixin (#10453)
Also contains another fix related to how variable values are replaced in
mixins.
Change-Id: I7a53e0a62041da6557eea10e124e64a55c7823f4
Diffstat (limited to 'theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java')
-rw-r--r-- | theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java b/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java index 2a5d617a6b..6c759167c7 100644 --- a/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java +++ b/theme-compiler/src/com/vaadin/sass/internal/ScssStylesheet.java @@ -20,6 +20,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -217,9 +218,7 @@ public class ScssStylesheet extends Node { node.traverse(); - @SuppressWarnings("unchecked") - HashMap<String, VariableNode> variableScope = (HashMap<String, VariableNode>) variables - .clone(); + Map<String, VariableNode> variableScope = openVariableScope(); // the size of the child list may change on each iteration: current node // may get deleted and possibly other nodes have been inserted where it @@ -232,8 +231,7 @@ public class ScssStylesheet extends Node { } } - variables.clear(); - variables.putAll(variableScope); + closeVariableScope(variableScope); // clean up insert point so that processing of the next block will // insert after that block @@ -248,6 +246,34 @@ public class ScssStylesheet extends Node { } } + /** + * Start a new scope for variables. Any variables set or modified after + * opening a new scope are only valid until the scope is closed, at which + * time they are replaced with their old values. + * + * @return old scope to give to a paired {@link #closeVariableScope(Map)} + * call at the end of the scope (unmodifiable map). + */ + public static Map<String, VariableNode> openVariableScope() { + @SuppressWarnings("unchecked") + HashMap<String, VariableNode> variableScope = (HashMap<String, VariableNode>) variables + .clone(); + return Collections.unmodifiableMap(variableScope); + } + + /** + * End a scope for variables, replacing all active variables with those from + * the original scope (obtained from {@link #openVariableScope()}). + * + * @param originalScope + * original scope + */ + public static void closeVariableScope( + Map<String, VariableNode> originalScope) { + variables.clear(); + variables.putAll(originalScope); + } + public void removeEmptyBlocks(Node node) { // depth first for avoiding re-checking parents of removed nodes for (Node child : new ArrayList<Node>(node.getChildren())) { |