Skip to content

Commit 2d0e114

Browse files
committed
Emit warning for double parent selectors
1 parent 9037eda commit 2d0e114

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, bool with_column, ParserState pstate);

src/parser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,9 @@ namespace Sass {
16111611
lex< css_comments >(false);
16121612
if (lex< ampersand >())
16131613
{
1614+
if (match< ampersand >()) {
1615+
warning("In Sass, \"&&\" means two copies of the parent selector. You probably want to use \"and\" instead.", pstate);
1616+
}
16141617
return SASS_MEMORY_NEW(Parent_Selector, pstate); }
16151618

16161619
if (lex< kwd_important >())

src/parser.hpp

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

109109
}
110110

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

0 commit comments

Comments
 (0)