Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for sourcemap offsets #2208

Closed
wants to merge 7 commits into from
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
30 changes: 28 additions & 2 deletions src/ast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ namespace Sass {
for (size_t i = 0, iL = parents->length(); i < iL; ++i) {
Sequence_Selector* t = (*tails)[n];
Sequence_Selector* parent = (*parents)[i];
Sequence_Selector* s = parent->cloneFully(ctx);
Sequence_Selector* s = parent->cloneFullyInto(ctx, this);
Sequence_Selector* ss = this->clone(ctx);
ss->tail(t ? t->clone(ctx) : 0);
SimpleSequence_Selector* h = head_->clone(ctx);
Expand All @@ -1162,7 +1162,7 @@ namespace Sass {
else {
for (size_t i = 0, iL = parents->length(); i < iL; ++i) {
Sequence_Selector* parent = (*parents)[i];
Sequence_Selector* s = parent->cloneFully(ctx);
Sequence_Selector* s = parent->cloneFullyInto(ctx, this);
Sequence_Selector* ss = this->clone(ctx);
// this is only if valid if the parent has no trailing op
// otherwise we cannot append more simple selectors to head
Expand Down Expand Up @@ -1349,6 +1349,32 @@ namespace Sass {
return cpy;
}

Sequence_Selector* Sequence_Selector::cloneFullyInto(Context& ctx, const Sequence_Selector *s) const
{
// when cloning a parent selector, the scope of the sequence selector must
// be preserved in order for sourcemaps to work, so the sequence selector
// of the current scope is used as an injection vector
Sequence_Selector* cpy = SASS_MEMORY_NEW(ctx.mem, Sequence_Selector, tail() ? *this : *s);
// set properties t the current node and reset tail by default
cpy->combinator(this->combinator());
cpy->reference(this->reference());
cpy->tail(0);
cpy->has_line_feed(this->has_line_feed());
cpy->has_line_break(this->has_line_break());

cpy->is_optional(this->is_optional());
cpy->media_block(this->media_block());
if (head()) {
cpy->head(head()->clone(ctx));
}

if (tail()) {
cpy->tail(tail()->cloneFullyInto(ctx, s));
}

return cpy;
}

SimpleSequence_Selector* SimpleSequence_Selector::clone(Context& ctx) const
{
SimpleSequence_Selector* cpy = SASS_MEMORY_NEW(ctx.mem, SimpleSequence_Selector, *this);
Expand Down
1 change: 1 addition & 0 deletions src/ast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2538,6 +2538,7 @@ namespace Sass {
}
Sequence_Selector* clone(Context&) const; // does not clone SimpleSequence_Selector*s
Sequence_Selector* cloneFully(Context&) const; // clones SimpleSequence_Selector*s
Sequence_Selector* cloneFullyInto(Context&, const Sequence_Selector*) const; // clones SimpleSequence_Selector*s
// std::vector<SimpleSequence_Selector*> to_vector();
ATTACH_OPERATIONS()
};
Expand Down
11 changes: 0 additions & 11 deletions src/emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ namespace Sass {
void Emitter::set_filename(const std::string& str)
{ wbuf.smap.file = str; }

void Emitter::schedule_mapping(const AST_Node* node)
{ scheduled_mapping = node; }
void Emitter::add_open_mapping(const AST_Node* node)
{ wbuf.smap.add_open_mapping(node); }
void Emitter::add_close_mapping(const AST_Node* node)
Expand Down Expand Up @@ -108,7 +106,6 @@ namespace Sass {
// append some text or token to the buffer
void Emitter::append_string(const std::string& text)
{

// write space/lf
flush_schedules();

Expand Down Expand Up @@ -143,12 +140,6 @@ namespace Sass {
{
flush_schedules();
add_open_mapping(node);
// hotfix for browser issues
// this is pretty ugly indeed
if (scheduled_mapping) {
add_open_mapping(scheduled_mapping);
scheduled_mapping = 0;
}
append_string(text);
add_close_mapping(node);
}
Expand Down Expand Up @@ -244,7 +235,6 @@ namespace Sass {
scheduled_linefeed = 0;
append_optional_space();
flush_schedules();
if (node) add_open_mapping(node);
append_string("{");
append_optional_linefeed();
// append_optional_space();
Expand All @@ -263,7 +253,6 @@ namespace Sass {
append_optional_space();
}
append_string("}");
if (node) add_close_mapping(node);
append_optional_linefeed();
if (indentation != 0) return;
if (output_style() != COMPRESSED)
Expand Down
1 change: 0 additions & 1 deletion src/emitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace Sass {
void set_filename(const std::string& str);
void add_open_mapping(const AST_Node* node);
void add_close_mapping(const AST_Node* node);
void schedule_mapping(const AST_Node* node);
std::string render_srcmap(Context &ctx);
ParserState remap(const ParserState& pstate);

Expand Down
Loading