Skip to content

Commit

Permalink
Some debugging and tests. #186
Browse files Browse the repository at this point in the history
  • Loading branch information
jurcovicovam committed Jun 23, 2014
1 parent 6d74ad6 commit b5b709d
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ public BodyCompilationResult run() {

});
}

private BodyCompilationResult resolveReferencedBody(final IScope callerScope, final BodyOwner<?> mixin, final IScope mixinWorkingScope) {
final ExpressionEvaluator expressionEvaluator = new ExpressionEvaluator(mixinWorkingScope, problemsHandler, configuration);


final IScope referencedMixinScope = mixinWorkingScope;
// ... and I'm starting to see the point of closures ...
return InScopeSnapshotRunner.runInOriginalDataSnapshot(referencedMixinScope, new IFunction<BodyCompilationResult>() {
Expand All @@ -84,20 +83,25 @@ public BodyCompilationResult run() {
// compile referenced mixin - keep the original copy unchanged
List<ASTCssNode> replacement = compileBody(mixin.getBody(), referencedMixinScope);

// collect variables and mixins to be imported
// IScope returnValues = expressionEvaluator.evaluateValues(referencedMixinScope);

// collect variables and mixins to be imported
IScope returnValues = ScopeFactory.createDummyScope();
returnValues.addFilteredVariables(new ImportedScopeFilter(expressionEvaluator, callerScope), referencedMixinScope);
List<FullMixinDefinition> unmodifiedMixinsToImport = referencedMixinScope.getAllMixins();

List<FullMixinDefinition> allMixinsToImport = mixinsToImport(callerScope, referencedMixinScope, unmodifiedMixinsToImport);
returnValues.addAllMixins(allMixinsToImport);

//FIXME: !!!!!!!!!! clean up
return new BodyCompilationResult((ASTCssNode) mixin, replacement, returnValues);


}

});
}


private List<ASTCssNode> compileBody(Body body, IScope scopeSnapshot) {
semiCompiledNodes.push(body.getParent());
try {
Expand All @@ -109,7 +113,6 @@ private List<ASTCssNode> compileBody(Body body, IScope scopeSnapshot) {
}
}


private List<FullMixinDefinition> mixinsToImport(IScope referenceScope, IScope referencedMixinScope, List<FullMixinDefinition> unmodifiedMixinsToImport) {
List<FullMixinDefinition> result = new ArrayList<FullMixinDefinition>();
for (FullMixinDefinition mixinToImport : unmodifiedMixinsToImport) {
Expand Down Expand Up @@ -168,7 +171,7 @@ public void run() {
MixinsGuardsValidator guardsValidator = new MixinsGuardsValidator(mixinWorkingScope, problemsHandler, configuration);
GuardValue guardValue = guardsValidator.evaluateGuards(mixin);

if (guardValue!=GuardValue.DO_NOT_USE) {
if (guardValue != GuardValue.DO_NOT_USE) {
//OPTIMIZATION POSSIBLE: there is no need to compile mixins at this point, some of them are not going to be
//used and create snapshot operation is cheap now. It should be done later on.
BodyCompilationResult compiled = resolveMixinReference(callerScope, fullMixin, mixinWorkingScope);
Expand All @@ -183,7 +186,7 @@ public void run() {

// filter out mixins we do not want to use
List<BodyCompilationResult> mixinsToBeUsed = defaultGuardHelper.chooseMixinsToBeUsed(compiledMixins, reference);

// update mixin replacements and update scope with imported variables and mixins
for (BodyCompilationResult compiled : mixinsToBeUsed) {
result.addMembers(compiled.getReplacement());
Expand Down Expand Up @@ -232,7 +235,8 @@ private void declarationsAreImportant(Body result) {
}
}

@Deprecated //FIXME: !!! evaluate need for this
@Deprecated
//FIXME: !!! evaluate need for this
private static IScope calculateMixinsWorkingScope(IScope callerScope, IScope arguments, IScope mixinScope) {
// add arguments
IScope mixinDeclarationScope = mixinScope.getParent();
Expand Down Expand Up @@ -261,11 +265,12 @@ private static IScope calculateBodyWorkingScope(IScope callerScope, IScope argum
// locally defined mixin does not require any other action
boolean isLocallyDefined = bodyScope.seesLocalDataOf(callerScope);
IScope parent = callerScope.getParent();
while (isLocallyDefined && parent!=null) {
isLocallyDefined = bodyScope.seesLocalDataOf(parent);;
while (isLocallyDefined && parent != null) {
isLocallyDefined = bodyScope.seesLocalDataOf(parent);
;
parent = parent.getParent();
}

if (isLocallyDefined) {
return bodyScope;
}
Expand All @@ -274,10 +279,10 @@ private static IScope calculateBodyWorkingScope(IScope callerScope, IScope argum
IScope result = ScopeFactory.createJoinedScopesView(callerScope, bodyScope);
return result;
}

//FIXME !!!! refactor and clean, unify with references
class ImportedScopeFilter implements ExpressionFilter {

private final ExpressionEvaluator expressionEvaluator;
private final IScope importTargetScope;

Expand All @@ -296,9 +301,9 @@ public Expression apply(Expression input) {
}

private IScope apply(IScope input) {
if (input==null)
if (input == null)
return importTargetScope;

return constructImportedBodyScope(importTargetScope, input);

}
Expand All @@ -311,8 +316,9 @@ private ScopeView constructImportedBodyScope(IScope importTargetScope, IScope bo
//FIXME !!!! unify with the above scope joiners
// locally defined mixin does not require any other action
IScope parent = importTargetScope.getParent();
while (isLocalImport && parent!=null) {
isLocalImport = bodyToBeImportedScope.seesLocalDataOf(parent);;
while (isLocalImport && parent != null) {
isLocalImport = bodyToBeImportedScope.seesLocalDataOf(parent);
;
parent = parent.getParent();
}

Expand All @@ -333,4 +339,3 @@ private ScopeView constructImportedBodyScope(IScope importTargetScope, IScope bo
}

}

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
.mixin(@parameter: {default: default;}) {
@parameter();
}

.default-mixin-argument {
.mixin();
}

.custom-mixin-argument {
.mixin({custom: custom;});
.mixin(@parameter: {default: default;}) {
@parameter();
}

.default-mixin-argument {
.mixin();
}

.custom-mixin-argument {
.mixin({custom: custom;});
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.selector-direct {
color: #008000;
color: green;
}
.selector-indirect {
color: #ff0000;
color: red;
}
.multiple-imports .selector {
scope: yes;
Expand Down
27 changes: 25 additions & 2 deletions src/test/resources/minitests/debug1.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
.wrap-selector {
visible-one: visible;
@media (orientation: portrait) {
}
@media (orientation: portrait) and (min-size: 256) {
.my-selector {
background-color: black;
}
}
@media (orientation: portrait) and (max-size: 1028) {
}
@media (orientation: portrait) and (max-size: 1028) and (blah: 22) {
}
@media (orientation: portrait) and (max-size: 1028) and (blah: 22) and (min-size: 256) {
.triple-wrapped-mq {
triple: true;
}
}
@media (orientation: portrait) and (max-size: 1028) and (min-size: 256) {
.triple-wrapped-mq {
triple: true;
}
}
@media (orientation: portrait) and (min-size: 256) {
.triple-wrapped-mq {
triple: true;
}
}
31 changes: 25 additions & 6 deletions src/test/resources/minitests/debug1.less
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
@detached: {
property: mixin;
};

.img-responsive {
@detached();
@my-ruleset: {
.my-selector {
@media (min-size:256) { //tv
background-color: black;
}
}
};
@media (orientation:portrait) {
@my-ruleset();
.wrap-media-mixin({
@media (min-size:256) { //tv
.triple-wrapped-mq {
triple: true;
}
}
});
}
.wrap-media-mixin(@ruleset) {
@media (max-size:1028) { //widescreen
@media (blah: 22) { //print
@ruleset();
}
@ruleset();
}
@ruleset();
}

0 comments on commit b5b709d

Please sign in to comment.