Skip to content

Commit a792ae0

Browse files
committed
Fix incorrect validation of mixin definition
Removed the duplicate validation check from the parser. The validation in the check nesting visitor was being skipped. Looks like there is a bunch of left of AST validation in the parser, which now belongs in the check nesting visitor. With the current approach the parser should only ever error when it encounters invalid tokens. It cannot accurately validate the AST because things like `at-root` change the structure in important ways. Closes #2269 Fixes #2095 Spec sass/sass-spec#1031
1 parent 380a85b commit a792ae0

File tree

3 files changed

+8
-17
lines changed

3 files changed

+8
-17
lines changed

src/check_nesting.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,8 @@ namespace Sass {
1111
current_mixin_definition(0)
1212
{ }
1313

14-
Statement_Ptr CheckNesting::before(Statement_Ptr s) {
15-
if (this->should_visit(s)) return s;
16-
return NULL;
17-
}
18-
19-
Statement_Ptr CheckNesting::visit_children(Statement_Ptr parent) {
20-
14+
Statement_Ptr CheckNesting::visit_children(Statement_Ptr parent)
15+
{
2116
Statement_Ptr old_parent = this->parent;
2217

2318
if (At_Root_Block_Ptr root = SASS_MEMORY_CAST_PTR(At_Root_Block, parent)) {
@@ -86,6 +81,7 @@ namespace Sass {
8681

8782
Statement_Ptr CheckNesting::operator()(Definition_Ptr n)
8883
{
84+
if (!this->should_visit(n)) return NULL;
8985
if (!is_mixin(n)) return n;
9086

9187
Definition_Ptr old_mixin_definition = this->current_mixin_definition;

src/check_nesting.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ namespace Sass {
2727

2828
template <typename U>
2929
Statement_Ptr fallback(U x) {
30-
return fallback_impl(this->before(SASS_MEMORY_CAST_PTR(Statement, x)));
30+
Statement_Ptr n = SASS_MEMORY_CAST_PTR(Statement, x);
31+
if (this->should_visit(n)) {
32+
return fallback_impl(n);
33+
}
34+
return NULL;
3135
}
3236

3337
private:

src/parser.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -363,15 +363,6 @@ namespace Sass {
363363

364364
Definition_Obj Parser::parse_definition(Definition::Type which_type)
365365
{
366-
Scope parent = stack.empty() ? Scope::Rules : stack.back();
367-
if (parent != Scope::Root && parent != Scope::Rules && parent != Scope::Function) {
368-
if (which_type == Definition::FUNCTION) {
369-
error("Functions may not be defined within control directives or other mixins.", pstate);
370-
} else {
371-
error("Mixins may not be defined within control directives or other mixins.", pstate);
372-
}
373-
374-
}
375366
std::string which_str(lexed);
376367
if (!lex< identifier >()) error("invalid name in " + which_str + " definition", pstate);
377368
std::string name(Util::normalize_underscores(lexed));

0 commit comments

Comments
 (0)