Skip to content

Commit dd67dd0

Browse files
committed
Merge pull request #1498 from mgreter/bugfix/err-mixin-wo-content
Add error for mixins without `@content` statement
2 parents f61a3b6 + 9e43ec7 commit dd67dd0

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/ast.hpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ namespace Sass {
305305
SUPPORTS,
306306
ATROOT,
307307
BUBBLE,
308+
CONTENT,
308309
KEYFRAMERULE,
309310
DECLARATION,
310311
ASSIGNMENT,
@@ -336,6 +337,10 @@ namespace Sass {
336337
virtual bool is_invisible() const { return false; }
337338
virtual bool bubbles() { return false; }
338339
virtual Block* block() { return 0; }
340+
virtual bool has_content()
341+
{
342+
return statement_type_ == CONTENT;
343+
}
339344
};
340345
inline Statement::~Statement() { }
341346

@@ -358,8 +363,18 @@ namespace Sass {
358363
Block(ParserState pstate, size_t s = 0, bool r = false)
359364
: Statement(pstate),
360365
Vectorized<Statement*>(s),
361-
is_root_(r), is_at_root_(false), has_hoistable_(false), has_non_hoistable_(false)
366+
is_root_(r),
367+
is_at_root_(false),
368+
has_hoistable_(false),
369+
has_non_hoistable_(false)
362370
{ }
371+
virtual bool has_content()
372+
{
373+
for (size_t i = 0, L = elements().size(); i < L; ++i) {
374+
if (elements()[i]->has_content()) return true;
375+
}
376+
return Statement::has_content();
377+
}
363378
Block* block() { return this; }
364379
ATTACH_OPERATIONS()
365380
};
@@ -373,6 +388,10 @@ namespace Sass {
373388
Has_Block(ParserState pstate, Block* b)
374389
: Statement(pstate), block_(b)
375390
{ }
391+
virtual bool has_content()
392+
{
393+
return block_->has_content() || Statement::has_content();
394+
}
376395
virtual ~Has_Block() = 0;
377396
};
378397
inline Has_Block::~Has_Block() { }
@@ -765,7 +784,8 @@ namespace Sass {
765784
///////////////////////////////////////////////////
766785
class Content : public Statement {
767786
public:
768-
Content(ParserState pstate) : Statement(pstate) { }
787+
Content(ParserState pstate) : Statement(pstate)
788+
{ statement_type(CONTENT); }
769789
ATTACH_OPERATIONS()
770790
};
771791

src/expand.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,9 @@ namespace Sass {
558558
Block* body = def->block();
559559
Parameters* params = def->parameters();
560560

561+
if (c->block() && c->name() != "@content" && !body->has_content()) {
562+
error("Mixin \"" + c->name() + "\" does not accept a content block.", c->pstate(), backtrace());
563+
}
561564
Arguments* args = static_cast<Arguments*>(c->arguments()
562565
->perform(&eval));
563566
Backtrace new_bt(backtrace(), c->pstate(), ", in mixin `" + c->name() + "`");

0 commit comments

Comments
 (0)