Skip to content

Commit

Permalink
Merge pull request #953 from mgreter/bugfix/issue_947
Browse files Browse the repository at this point in the history
Implement selector contextualization for keyframe rules
  • Loading branch information
mgreter committed Mar 30, 2015
2 parents 4c2a62a + 47dffc5 commit b87f4c7
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,10 @@ namespace Sass {
// Keyframe-rules -- the child blocks of "@keyframes" nodes.
///////////////////////////////////////////////////////////////////////
class Keyframe_Rule : public Has_Block {
ADD_PROPERTY(String*, rules);
ADD_PROPERTY(Selector*, selector);
public:
Keyframe_Rule(ParserState pstate, Block* b)
: Has_Block(pstate, b), rules_(0)
: Has_Block(pstate, b), selector_(0)
{ statement_type(KEYFRAMERULE); }
ATTACH_OPERATIONS();
};
Expand Down
2 changes: 1 addition & 1 deletion cssize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace Sass {

Keyframe_Rule* rr = new (ctx.mem) Keyframe_Rule(r->pstate(),
r->block()->perform(this)->block());
if (r->rules()) rr->rules(r->rules());
if (r->selector()) rr->selector(r->selector());

return debubble(rr->block(), rr)->block();
}
Expand Down
20 changes: 19 additions & 1 deletion debugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
cerr << ind << "Declaration " << block << " " << block->tabs() << endl;
debug_ast(block->property(), ind + " prop: ", env);
debug_ast(block->value(), ind + " value: ", env);
} else if (dynamic_cast<Keyframe_Rule*>(node)) {
Keyframe_Rule* has_block = dynamic_cast<Keyframe_Rule*>(node);
cerr << ind << "Keyframe_Rule " << has_block << " " << has_block->tabs() << endl;
if (has_block->selector()) debug_ast(has_block->selector(), ind + "@");
if (has_block->block()) for(auto i : has_block->block()->elements()) { debug_ast(i, ind + " ", env); }
} else if (dynamic_cast<At_Rule*>(node)) {
At_Rule* block = dynamic_cast<At_Rule*>(node);
cerr << ind << "At_Rule " << block << " [" << block->keyword() << "] " << block->tabs() << endl;
Expand Down Expand Up @@ -348,7 +353,20 @@ inline void debug_ast(AST_Node* node, string ind = "", Env* env = 0)
endl;
} else if (dynamic_cast<Expression*>(node)) {
Expression* expression = dynamic_cast<Expression*>(node);
cerr << ind << "Expression " << expression << " " << expression->concrete_type() << endl;
cerr << ind << "Expression " << expression;
switch (expression->concrete_type()) {
case Expression::Concrete_Type::NONE: cerr << " [NONE]"; break;
case Expression::Concrete_Type::BOOLEAN: cerr << " [BOOLEAN]"; break;
case Expression::Concrete_Type::NUMBER: cerr << " [NUMBER]"; break;
case Expression::Concrete_Type::COLOR: cerr << " [COLOR]"; break;
case Expression::Concrete_Type::STRING: cerr << " [STRING]"; break;
case Expression::Concrete_Type::LIST: cerr << " [LIST]"; break;
case Expression::Concrete_Type::MAP: cerr << " [MAP]"; break;
case Expression::Concrete_Type::SELECTOR: cerr << " [SELECTOR]"; break;
case Expression::Concrete_Type::NULL_VAL: cerr << " [NULL_VAL]"; break;
case Expression::Concrete_Type::NUM_TYPES: cerr << " [NUM_TYPES]"; break;
}
cerr << endl;
} else if (dynamic_cast<Has_Block*>(node)) {
Has_Block* has_block = dynamic_cast<Has_Block*>(node);
cerr << ind << "Has_Block " << has_block << " " << has_block->tabs() << endl;
Expand Down
6 changes: 1 addition & 5 deletions expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ namespace Sass {
if (in_keyframes) {
To_String to_string;
Keyframe_Rule* k = new (ctx.mem) Keyframe_Rule(r->pstate(), r->block()->perform(this)->block());
if (r->selector()) {
string s(r->selector()->perform(eval->with(env, backtrace))->perform(&to_string));
String_Constant* ss = new (ctx.mem) String_Constant(r->selector()->pstate(), s);
k->rules(ss);
}
if (r->selector()) k->selector(r->selector()->perform(contextualize_eval->with(0, env, backtrace)));
in_at_root = old_in_at_root;
old_in_at_root = false;
return k;
Expand Down
5 changes: 2 additions & 3 deletions inspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ namespace Sass {

void Inspect::operator()(Keyframe_Rule* rule)
{
append_indentation();
if (rule->rules()) rule->rules()->perform(this);
rule->block()->perform(this);
if (rule->selector()) rule->selector()->perform(this);
if (rule->block()) rule->block()->perform(this);
}

void Inspect::operator()(Propset* propset)
Expand Down
3 changes: 1 addition & 2 deletions output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,10 @@ namespace Sass {

void Output::operator()(Keyframe_Rule* r)
{
String* v = r->rules();
Block* b = r->block();
Selector* v = r->selector();

if (v) {
append_indentation();
v->perform(this);
}

Expand Down

0 comments on commit b87f4c7

Please sign in to comment.