Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/api-context-internal.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ struct Sass_Options : Sass_Output_Options {
// Treat source_string as sass (as opposed to scss)
bool is_indented_syntax_src;

// If this options is set, nothing will be printed to stderr anymore
// The aggregated output on stderr can be fetched via stderr_string
bool suppress_stderr;

// The input path is used for source map
// generation. It can be used to define
// something with string compilation or to
Expand Down Expand Up @@ -105,6 +109,9 @@ struct Sass_Context : Sass_Options
// generated output data
char* output_string;

// messages on stderr
char* stderr_string;

// generated source map json
char* source_map_string;

Expand Down
11 changes: 11 additions & 0 deletions docs/api-context.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ bool omit_source_map_url;
bool is_indented_syntax_src;
```
```C
// If this options is set, nothing will be printed to stderr anymore
// The aggregated output on stderr can be fetched via stderr_string
bool suppress_stderr;
```
```C
// The input path is used for source map
// generating. It can be used to define
// something with string compilation or to
Expand Down Expand Up @@ -111,6 +116,10 @@ enum Sass_Input_Style type;
char* output_string;
```
```C
// messages on stderr
char* stderr_string;
```
```C
// generated source map json
char* source_map_string;
```
Expand Down Expand Up @@ -197,6 +206,7 @@ void sass_data_context_set_options (struct Sass_Data_Context* data_ctx, struct S

// Getters for Sass_Context values
const char* sass_context_get_output_string (struct Sass_Context* ctx);
const char* sass_context_get_stderr_string (struct Sass_Context* ctx);
int sass_context_get_error_status (struct Sass_Context* ctx);
const char* sass_context_get_error_json (struct Sass_Context* ctx);
const char* sass_context_get_error_text (struct Sass_Context* ctx);
Expand Down Expand Up @@ -262,6 +272,7 @@ void sass_option_set_source_map_contents (struct Sass_Options* options, bool sou
void sass_option_set_source_map_file_urls (struct Sass_Options* options, bool source_map_file_urls);
void sass_option_set_omit_source_map_url (struct Sass_Options* options, bool omit_source_map_url);
void sass_option_set_is_indented_syntax_src (struct Sass_Options* options, bool is_indented_syntax_src);
void sass_option_set_suppress_stderr (struct Sass_Options* options, bool suppress_stderr);
void sass_option_set_indent (struct Sass_Options* options, const char* indent);
void sass_option_set_linefeed (struct Sass_Options* options, const char* linefeed);
void sass_option_set_input_path (struct Sass_Options* options, const char* input_path);
Expand Down
2 changes: 2 additions & 0 deletions include/sass/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ ADDAPI void ADDCALL sass_option_set_source_map_contents (struct Sass_Options* op
ADDAPI void ADDCALL sass_option_set_source_map_file_urls (struct Sass_Options* options, bool source_map_file_urls);
ADDAPI void ADDCALL sass_option_set_omit_source_map_url (struct Sass_Options* options, bool omit_source_map_url);
ADDAPI void ADDCALL sass_option_set_is_indented_syntax_src (struct Sass_Options* options, bool is_indented_syntax_src);
ADDAPI void ADDCALL sass_option_set_suppress_stderr (struct Sass_Options* options, bool suppress_stderr);
ADDAPI void ADDCALL sass_option_set_indent (struct Sass_Options* options, const char* indent);
ADDAPI void ADDCALL sass_option_set_linefeed (struct Sass_Options* options, const char* linefeed);
ADDAPI void ADDCALL sass_option_set_input_path (struct Sass_Options* options, const char* input_path);
Expand All @@ -111,6 +112,7 @@ ADDAPI void ADDCALL sass_option_set_c_functions (struct Sass_Options* options, S

// Getters for Sass_Context values
ADDAPI const char* ADDCALL sass_context_get_output_string (struct Sass_Context* ctx);
ADDAPI const char* ADDCALL sass_context_get_stderr_string (struct Sass_Context* ctx);
ADDAPI int ADDCALL sass_context_get_error_status (struct Sass_Context* ctx);
ADDAPI const char* ADDCALL sass_context_get_error_json (struct Sass_Context* ctx);
ADDAPI const char* ADDCALL sass_context_get_error_text (struct Sass_Context* ctx);
Expand Down
6 changes: 4 additions & 2 deletions src/bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Sass {

void bind(std::string type, std::string name, Parameters_Obj ps, Arguments_Obj as, Env* env, Eval* eval, Backtraces& traces)
void bind(std::string type, std::string name, Parameters_Obj ps, Arguments_Obj as, Context* ctx, Env* env, Eval* eval, Backtraces& traces)
{
std::string callee(type + " " + name);

Expand Down Expand Up @@ -194,7 +194,9 @@ namespace Sass {
msg << (LP == 1 ? " argument" : " arguments");
msg << " but " << arg_count;
msg << (arg_count == 1 ? " was passed" : " were passed.");
deprecated_bind(msg.str(), as->pstate());
// ToDo: we only need ctx here to capture the message on stderr
// ToDo: once deprecation is gone, remove it from method args
ctx->c_options.print_stderr(deprecated_bind(msg.str(), as->pstate()));

while (arglist->length() > LP - ip) {
arglist->elements().erase(arglist->elements().end() - 1);
Expand Down
2 changes: 1 addition & 1 deletion src/bind.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Sass {

void bind(std::string type, std::string name, Parameters_Obj, Arguments_Obj, Env*, Eval*, Backtraces& traces);
void bind(std::string type, std::string name, Parameters_Obj, Arguments_Obj, Context* ctx, Env*, Eval*, Backtraces& traces);

}

Expand Down
1 change: 1 addition & 0 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace Sass {
head_imports(0),
plugins(),
emitter(c_options),
CERR(std::cerr),

ast_gc(),
strings(),
Expand Down
3 changes: 3 additions & 0 deletions src/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define SASS_CONTEXT_H

#include <string>
#include <sstream>
#include <vector>
#include <map>

Expand Down Expand Up @@ -44,6 +45,8 @@ namespace Sass {
Plugins plugins;
Output emitter;

std::ostream& CERR;

// generic ast node garbage container
// used to avoid possible circular refs
CallStack ast_gc;
Expand Down
60 changes: 36 additions & 24 deletions src/error_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,66 +134,78 @@ namespace Sass {

}


void warn(std::string msg, ParserState pstate)
std::string warn(std::string msg, ParserState pstate)
{
std::cerr << "Warning: " << msg << std::endl;
std::ostringstream sstrm;
sstrm << "Warning: " << msg << std::endl;
return sstrm.str();
}

void warning(std::string msg, ParserState pstate)
std::string warning(std::string msg, ParserState pstate)
{
std::string cwd(Sass::File::get_cwd());
std::string abs_path(Sass::File::rel2abs(pstate.path, cwd, cwd));
std::string rel_path(Sass::File::abs2rel(pstate.path, cwd, cwd));
std::string output_path(Sass::File::path_for_console(rel_path, abs_path, pstate.path));

std::cerr << "WARNING on line " << pstate.line+1 << ", column " << pstate.column+1 << " of " << output_path << ":" << std::endl;
std::cerr << msg << std::endl << std::endl;
std::ostringstream sstrm;
sstrm << "WARNING on line " << pstate.line + 1;
sstrm << ", column " << pstate.column + 1;
sstrm << " of " << output_path << std::endl;
sstrm << msg << std::endl;
sstrm << std::endl;
return sstrm.str();
}

void warn(std::string msg, ParserState pstate, Backtrace* bt)
std::string warn(std::string msg, ParserState pstate, Backtrace* bt)
{
warn(msg, pstate);
return warn(msg, pstate);
}

void deprecated_function(std::string msg, ParserState pstate)
std::string deprecated_function(std::string msg, ParserState pstate)
{
std::string cwd(Sass::File::get_cwd());
std::string abs_path(Sass::File::rel2abs(pstate.path, cwd, cwd));
std::string rel_path(Sass::File::abs2rel(pstate.path, cwd, cwd));
std::string output_path(Sass::File::path_for_console(rel_path, abs_path, pstate.path));

std::cerr << "DEPRECATION WARNING: " << msg << std::endl;
std::cerr << "will be an error in future versions of Sass." << std::endl;
std::cerr << " on line " << pstate.line+1 << " of " << output_path << std::endl;
std::ostringstream sstrm;
sstrm << "DEPRECATION WARNING: " << msg << std::endl;
sstrm << "will be an error in future versions of Sass." << std::endl;
sstrm << " on line " << pstate.line+1 << " of " << output_path << std::endl;
return sstrm.str();
}

void deprecated(std::string msg, std::string msg2, bool with_column, ParserState pstate)
std::string deprecated(std::string msg, std::string msg2, bool with_column, ParserState pstate)
{
std::string cwd(Sass::File::get_cwd());
std::string abs_path(Sass::File::rel2abs(pstate.path, cwd, cwd));
std::string rel_path(Sass::File::abs2rel(pstate.path, cwd, cwd));
std::string output_path(Sass::File::path_for_console(rel_path, pstate.path, pstate.path));

std::cerr << "DEPRECATION WARNING on line " << pstate.line + 1;
if (with_column) std::cerr << ", column " << pstate.column + pstate.offset.column + 1;
if (output_path.length()) std::cerr << " of " << output_path;
std::cerr << ":" << std::endl;
std::cerr << msg << std::endl;
if (msg2.length()) std::cerr << msg2 << std::endl;
std::cerr << std::endl;
std::ostringstream sstrm;
sstrm << "DEPRECATION WARNING on line " << pstate.line + 1;
if (with_column) sstrm << ", column " << pstate.column + pstate.offset.column + 1;
if (output_path.length()) sstrm << " of " << output_path;
sstrm << ":" << std::endl;
sstrm << msg << std::endl;
if (msg2.length()) sstrm << msg2 << std::endl;
sstrm << std::endl;
return sstrm.str();
}

void deprecated_bind(std::string msg, ParserState pstate)
std::string deprecated_bind(std::string msg, ParserState pstate)
{
std::string cwd(Sass::File::get_cwd());
std::string abs_path(Sass::File::rel2abs(pstate.path, cwd, cwd));
std::string rel_path(Sass::File::abs2rel(pstate.path, cwd, cwd));
std::string output_path(Sass::File::path_for_console(rel_path, abs_path, pstate.path));

std::cerr << "WARNING: " << msg << std::endl;
std::cerr << " on line " << pstate.line+1 << " of " << output_path << std::endl;
std::cerr << "This will be an error in future versions of Sass." << std::endl;
std::ostringstream sstrm;
sstrm << "WARNING: " << msg << std::endl;
sstrm << " on line " << pstate.line+1 << " of " << output_path << std::endl;
sstrm << "This will be an error in future versions of Sass." << std::endl;
return sstrm.str();
}

// should be replaced with error with backtraces
Expand Down
15 changes: 7 additions & 8 deletions src/error_handling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,13 @@ namespace Sass {

}

void warn(std::string msg, ParserState pstate);
void warn(std::string msg, ParserState pstate, Backtrace* bt);
void warning(std::string msg, ParserState pstate);

void deprecated_function(std::string msg, ParserState pstate);
void deprecated(std::string msg, std::string msg2, bool with_column, ParserState pstate);
void deprecated_bind(std::string msg, ParserState pstate);
// void deprecated(std::string msg, ParserState pstate, Backtrace* bt);
std::string warn(std::string msg, ParserState pstate);
std::string warn(std::string msg, ParserState pstate, Backtrace* bt);
std::string warning(std::string msg, ParserState pstate);

std::string deprecated_function(std::string msg, ParserState pstate);
std::string deprecated(std::string msg, std::string msg2, bool with_column, ParserState pstate);
std::string deprecated_bind(std::string msg, ParserState pstate);

void coreError(std::string msg, ParserState pstate);
void error(std::string msg, ParserState pstate, Backtraces& traces);
Expand Down
17 changes: 11 additions & 6 deletions src/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,11 @@ namespace Sass {

std::string result(unquote(message->to_sass()));
std::cerr << "WARNING: " << result << std::endl;
std::ostringstream sstrm;
traces.push_back(Backtrace(w->pstate()));
std::cerr << traces_to_string(traces, " ");
std::cerr << std::endl;
sstrm << traces_to_string(traces, " ");
sstrm << std::endl;
ctx.c_options.print_stderr(sstrm.str());
options().output_style = outstyle;
traces.pop_back();
return 0;
Expand Down Expand Up @@ -485,8 +487,11 @@ namespace Sass {
std::string output_path(Sass::File::path_for_console(rel_path, abs_path, d->pstate().path));
options().output_style = outstyle;

std::cerr << output_path << ":" << d->pstate().line+1 << " DEBUG: " << result;
std::cerr << std::endl;
std::ostringstream sstrm;
sstrm << output_path << ":" << d->pstate().line+1 << " DEBUG: " << result;
sstrm << std::endl;
ctx.c_options.print_stderr(sstrm.str());

return 0;
}

Expand Down Expand Up @@ -1048,7 +1053,7 @@ namespace Sass {
env_stack().push_back(&fn_env);

if (func || body) {
bind(std::string("Function"), c->name(), params, args, &fn_env, this, traces);
bind(std::string("Function"), c->name(), params, args, &ctx, &fn_env, this, traces);
std::string msg(", in function `" + c->name() + "`");
traces.push_back(Backtrace(c->pstate(), msg));
callee_stack().push_back({
Expand Down Expand Up @@ -1088,7 +1093,7 @@ namespace Sass {

// populates env with default values for params
std::string ff(c->name());
bind(std::string("Function"), c->name(), params, args, &fn_env, this, traces);
bind(std::string("Function"), c->name(), params, args, &ctx, &fn_env, this, traces);
std::string msg(", in function `" + c->name() + "`");
traces.push_back(Backtrace(c->pstate(), msg));
callee_stack().push_back({
Expand Down
6 changes: 3 additions & 3 deletions src/expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,11 +685,11 @@ namespace Sass {
d->name() == "expression" ||
d->name() == "url"
)) {
deprecated(
ctx.c_options.print_stderr(deprecated(
"Naming a function \"" + d->name() + "\" is disallowed and will be an error in future versions of Sass.",
"This name conflicts with an existing CSS function with special parse rules.",
false, d->pstate()
);
));
}

// set the static link so we can have lexical scoping
Expand Down Expand Up @@ -746,7 +746,7 @@ namespace Sass {
new_env.local_frame()["@content[m]"] = thunk;
}

bind(std::string("Mixin"), c->name(), params, args, &new_env, &eval, traces);
bind(std::string("Mixin"), c->name(), params, args, &ctx, &new_env, &eval, traces);

Block_Obj trace_block = SASS_MEMORY_NEW(Block, c->pstate());
Trace_Obj trace = SASS_MEMORY_NEW(Trace, c->pstate(), c->name(), trace_block);
Expand Down
2 changes: 1 addition & 1 deletion src/fn_strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace Sass {
val = Cast<Null>(arg) ? "null" : val;
ctx.c_options.output_style = oldstyle;

deprecated_function("Passing " + val + ", a non-string value, to unquote()", pstate);
ctx.c_options.print_stderr(deprecated_function("Passing " + val + ", a non-string value, to unquote()", pstate));
return ex;
}
throw std::runtime_error("Invalid Data Type for unquote");
Expand Down
14 changes: 7 additions & 7 deletions src/operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ namespace Sass {
bool gte(Expression_Obj lhs, Expression_Obj rhs) { return !cmp(lhs, rhs, Sass_OP::GTE) || eq(lhs, rhs); }

/* colour math deprecation warning */
void op_color_deprecation(enum Sass_OP op, std::string lsh, std::string rhs, const ParserState& pstate)
void op_color_deprecation(enum Sass_OP op, std::string lsh, std::string rhs, struct Sass_Inspect_Options opt, const ParserState& pstate)
{
deprecated(
opt.print_stderr(deprecated(
"The operation `" + lsh + " " + sass_op_to_name(op) + " " + rhs +
"` is deprecated and will be an error in future versions.",
"Consider using Sass's color functions instead.\n"
"https://sass-lang.com/documentation/Sass/Script/Functions.html#other_color_functions",
/*with_column=*/false, pstate);
/*with_column=*/false, pstate));
}

/* static function, throws OperationError, has no traces but optional pstate for returned value */
Expand Down Expand Up @@ -130,7 +130,7 @@ namespace Sass {
throw Exception::ZeroDivisionError(lhs, rhs);
}

op_color_deprecation(op, lhs.to_string(), rhs.to_string(), pstate);
op_color_deprecation(op, lhs.to_string(), rhs.to_string(), opt, pstate);

return SASS_MEMORY_NEW(Color_RGBA,
pstate,
Expand Down Expand Up @@ -218,7 +218,7 @@ namespace Sass {
switch (op) {
case Sass_OP::ADD:
case Sass_OP::MUL: {
op_color_deprecation(op, lhs.to_string(), rhs.to_string(opt), pstate);
op_color_deprecation(op, lhs.to_string(), rhs.to_string(opt), opt, pstate);
return SASS_MEMORY_NEW(Color_RGBA,
pstate,
ops[op](lval, rhs.r()),
Expand All @@ -229,7 +229,7 @@ namespace Sass {
case Sass_OP::SUB:
case Sass_OP::DIV: {
std::string color(rhs.to_string(opt));
op_color_deprecation(op, lhs.to_string(), color, pstate);
op_color_deprecation(op, lhs.to_string(), color, opt, pstate);
return SASS_MEMORY_NEW(String_Quoted,
pstate,
lhs.to_string(opt)
Expand All @@ -251,7 +251,7 @@ namespace Sass {
throw Exception::ZeroDivisionError(lhs, rhs);
}

op_color_deprecation(op, lhs.to_string(), rhs.to_string(), pstate);
op_color_deprecation(op, lhs.to_string(), rhs.to_string(), opt, pstate);

return SASS_MEMORY_NEW(Color_RGBA,
pstate,
Expand Down
3 changes: 2 additions & 1 deletion src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,8 @@ namespace Sass {
if (lex< ampersand >())
{
if (match< ampersand >()) {
warning("In Sass, \"&&\" means two copies of the parent selector. You probably want to use \"and\" instead.", pstate);
ctx.c_options.print_stderr(warning("In Sass, \"&&\" means two copies of the parent"
" selector. You probably want to use \"and\" instead.", pstate));
}
return SASS_MEMORY_NEW(Parent_Reference, pstate); }

Expand Down
Loading