Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit c062aee

Browse files
author
Aaron Leung
committed
Merge branch 'master' into mixin-content
2 parents 5605be0 + 957e472 commit c062aee

File tree

7 files changed

+23
-16
lines changed

7 files changed

+23
-16
lines changed

context.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace Sass {
5151
// }
5252
}
5353

54-
Context::Context(const char* paths_str, const char* img_path_str)
54+
Context::Context(const char* paths_str, const char* img_path_str, bool sc)
5555
: global_env(Environment()),
5656
function_env(map<string, Function>()),
5757
extensions(multimap<Node, Node>()),
@@ -63,7 +63,8 @@ namespace Sass {
6363
new_Node(Node_Factory()),
6464
image_path(0),
6565
ref_count(0),
66-
has_extensions(false)
66+
has_extensions(false),
67+
source_comments(sc)
6768
{
6869
register_functions();
6970
collect_include_paths(paths_str);

context.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ namespace Sass {
3333
// string sass_path;
3434
// string css_path;
3535
bool has_extensions;
36+
bool source_comments;
3637

3738
void collect_include_paths(const char* paths_str);
38-
Context(const char* paths_str = 0, const char* img_path_str = 0);
39+
Context(const char* paths_str = 0, const char* img_path_str = 0, bool sc = false);
3940
~Context();
4041

4142
void register_function(Signature sig, Primitive ip);

document.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ namespace Sass {
146146
root.echo(output);
147147
break;
148148
case nested:
149-
root.emit_nested_css(output, 0, true);
149+
root.emit_nested_css(output, 0, true, false, context.source_comments);
150150
break;
151151
case expanded:
152152
root.emit_expanded_css(output, "");

node.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ namespace Sass {
240240
bool operator>=(Node rhs) const;
241241

242242
string to_string(Type inside_of = none, const string space = " ") const;
243-
void emit_nested_css(stringstream& buf, size_t depth, bool at_toplevel = false, bool in_media_query = false);
243+
void emit_nested_css(stringstream& buf, size_t depth, bool at_toplevel = false, bool in_media_query = false, bool source_comments = false);
244244
void emit_propset(stringstream& buf, size_t depth, const string& prefix, const bool compressed = false);
245245
void echo(stringstream& buf, size_t depth = 0);
246246
void emit_expanded_css(stringstream& buf, const string& prefix);

node_emitters.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,14 @@ namespace Sass {
369369
}
370370
}
371371

372-
void Node::emit_nested_css(stringstream& buf, size_t depth, bool at_toplevel, bool in_media_query)
372+
void Node::emit_nested_css(stringstream& buf, size_t depth, bool at_toplevel, bool in_media_query, bool source_comments)
373373
{
374374
switch (type())
375375
{
376376
case root: {
377377
if (has_expansions()) flatten();
378378
for (size_t i = 0, S = size(); i < S; ++i) {
379-
at(i).emit_nested_css(buf, depth, true);
379+
at(i).emit_nested_css(buf, depth, true, false, source_comments);
380380
}
381381
} break;
382382

@@ -386,6 +386,10 @@ namespace Sass {
386386

387387
if (block.has_expansions()) block.flatten();
388388
if (block.has_statements() || block.has_comments()) {
389+
if (source_comments) {
390+
buf << string(2*depth, ' ');
391+
buf << "/* line " << sel_group.line() << ", " << sel_group.path() << " */" << endl;
392+
}
389393
buf << string(2*depth, ' ');
390394
buf << sel_group.to_string();
391395
buf << " {";
@@ -401,7 +405,7 @@ namespace Sass {
401405
case block_directive:
402406
case blockless_directive:
403407
case warning: {
404-
block[i].emit_nested_css(buf, depth+1);
408+
block[i].emit_nested_css(buf, depth+1, false, false, source_comments);
405409
} break;
406410
default: break;
407411
}
@@ -413,7 +417,7 @@ namespace Sass {
413417
if (block.has_blocks()) {
414418
for (size_t i = 0, S = block.size(); i < S; ++i) {
415419
if (block[i].type() == ruleset || block[i].type() == media_query) {
416-
block[i].emit_nested_css(buf, depth, false, false); // last arg should be in_media_query?
420+
block[i].emit_nested_css(buf, depth, false, false, source_comments); // last arg should be in_media_query?
417421
}
418422
}
419423
}
@@ -435,7 +439,7 @@ namespace Sass {
435439
// just print out the comments without a block
436440
for (size_t i = 0, S = block.size(); i < S; ++i) {
437441
if (block[i].type() == comment)
438-
block[i].emit_nested_css(buf, depth+1);
442+
block[i].emit_nested_css(buf, depth+1, false, false, source_comments);
439443
}
440444
}
441445
if (has_statements) {
@@ -457,7 +461,7 @@ namespace Sass {
457461
case blockless_directive:
458462
case warning: {
459463
// if (stm_type != comment) buf << endl;
460-
block[i].emit_nested_css(buf, depth+1);
464+
block[i].emit_nested_css(buf, depth+1, false, false, source_comments);
461465
} break;
462466

463467
default: break;
@@ -470,15 +474,15 @@ namespace Sass {
470474
Type stm_type = block[i].type();
471475
if (stm_type == comment && !has_statements) {
472476
if (i > 0 && block[i-1].type() == ruleset) buf << endl;
473-
block[i].emit_nested_css(buf, depth+1, false, true);
477+
block[i].emit_nested_css(buf, depth+1, false, true, source_comments);
474478
}
475479
if (stm_type == ruleset || stm_type == media_query) {
476480
buf << endl;
477481
if (i > 0 &&
478482
block[i-1].type() == ruleset &&
479483
!block[i-1][1].has_blocks())
480484
{ buf << endl; }
481-
block[i].emit_nested_css(buf, depth+1, false, true);
485+
block[i].emit_nested_css(buf, depth+1, false, true, source_comments);
482486
}
483487
}
484488
}
@@ -510,7 +514,7 @@ namespace Sass {
510514
default:
511515
break;
512516
}
513-
block[i].emit_nested_css(buf, depth+1, false, in_media_query);
517+
block[i].emit_nested_css(buf, depth+1, false, in_media_query, source_comments);
514518
}
515519
buf << " }" << endl;
516520
if ((depth == 0) && at_toplevel && !in_media_query) buf << endl;

sass_interface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ extern "C" {
6666
{
6767
using namespace Sass;
6868
try {
69-
Context cpp_ctx(c_ctx->options.include_paths, c_ctx->options.image_path);
69+
Context cpp_ctx(c_ctx->options.include_paths, c_ctx->options.image_path, c_ctx->options.source_comments);
7070
// cpp_ctx.image_path = c_ctx->options.image_path;
7171
// Document doc(0, c_ctx->input_string, cpp_ctx);
7272
Document doc(Document::make_from_source_chars(cpp_ctx, c_ctx->source_string));
@@ -102,7 +102,7 @@ extern "C" {
102102
{
103103
using namespace Sass;
104104
try {
105-
Context cpp_ctx(c_ctx->options.include_paths, c_ctx->options.image_path);
105+
Context cpp_ctx(c_ctx->options.include_paths, c_ctx->options.image_path, c_ctx->options.source_comments);
106106
// Document doc(c_ctx->input_path, 0, cpp_ctx);
107107
// string path_string(c_ctx->options.image_path);
108108
// path_string = "'" + path_string + "/";

sass_interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ extern "C" {
1111

1212
struct sass_options {
1313
int output_style;
14+
int source_comments; // really want a bool, but C doesn't have them
1415
char* include_paths;
1516
char* image_path;
1617
};

0 commit comments

Comments
 (0)