Skip to content

Commit fdac3c4

Browse files
committed
Emit warning for double parent selectors
1 parent 16e48a8 commit fdac3c4

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

src/error_handling.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ namespace Sass {
165165
std::cerr << "Warning: " << msg<< std::endl;
166166
}
167167

168+
void warning(std::string msg, ParserState pstate)
169+
{
170+
std::string cwd(Sass::File::get_cwd());
171+
std::string abs_path(Sass::File::rel2abs(pstate.path, cwd, cwd));
172+
std::string rel_path(Sass::File::abs2rel(pstate.path, cwd, cwd));
173+
std::string output_path(Sass::File::path_for_console(rel_path, abs_path, pstate.path));
174+
175+
std::cerr << "WARNING on line " << pstate.line+1 << ", column " << pstate.column+1 << " of " << output_path << std::endl;
176+
std::cerr << msg << std::endl << std::endl;
177+
}
178+
168179
void warn(std::string msg, ParserState pstate, Backtrace* bt)
169180
{
170181
Backtrace top(bt, pstate, "");

src/error_handling.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ namespace Sass {
200200

201201
void warn(std::string msg, ParserState pstate);
202202
void warn(std::string msg, ParserState pstate, Backtrace* bt);
203+
void warning(std::string msg, ParserState pstate);
203204

204205
void deprecated_function(std::string msg, ParserState pstate);
205206
void deprecated(std::string msg, std::string msg2, ParserState pstate);

src/parser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,9 @@ namespace Sass {
15921592
lex< css_comments >(false);
15931593
if (lex< ampersand >())
15941594
{
1595+
if (match< ampersand >()) {
1596+
warning("In Sass, \"&&\" means two copies of the parent selector. You probably want to use \"and\" instead.", pstate);
1597+
}
15951598
return SASS_MEMORY_NEW(Parent_Selector, pstate); }
15961599

15971600
if (lex< kwd_important >())

src/parser.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ namespace Sass {
109109

110110
}
111111

112-
// peek will only skip over space, tabs and line comment
112+
// match will not skip over space, tabs and line comment
113113
// return the position where the lexer match will occur
114114
template <Prelexer::prelexer mx>
115115
const char* match(const char* start = 0)

0 commit comments

Comments
 (0)