Skip to content

Commit a41d16a

Browse files
committed
Fixes source mappings for selector schema
1 parent 46f5244 commit a41d16a

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/debugger.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ inline void debug_ast(AST_Node_Ptr node, std::string ind, Env* env)
663663
std::cerr << ind << "String_Schema " << expression;
664664
std::cerr << " (" << pstate_source_position(expression) << ")";
665665
std::cerr << " " << expression->concrete_type();
666+
std::cerr << " (" << pstate_source_position(node) << ")";
666667
if (expression->is_delayed()) std::cerr << " [delayed]";
667668
if (expression->is_interpolant()) std::cerr << " [is interpolant]";
668669
if (expression->has_interpolant()) std::cerr << " [has interpolant]";

src/parser.cpp

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ namespace Sass {
145145
}
146146

147147
// update for end position
148-
block->update_pstate(pstate);
148+
// this seems to be done somewhere else
149+
// but that fixed selector schema issue
150+
// block->update_pstate(pstate);
149151

150152
// parse comments after block
151153
// lex < optional_css_comments >();
@@ -491,6 +493,7 @@ namespace Sass {
491493
stack.pop_back();
492494
// update for end position
493495
ruleset->update_pstate(pstate);
496+
ruleset->block()->update_pstate(pstate);
494497
// inherit is_root from parent block
495498
// need this info for sanity checks
496499
ruleset->is_root(is_root);
@@ -517,30 +520,46 @@ namespace Sass {
517520
// try to parse mutliple interpolants
518521
if (const char* p = find_first_in_interval< exactly<hash_lbrace>, block_comment >(i, end_of_selector)) {
519522
// accumulate the preceding segment if the position has advanced
520-
if (i < p) schema->append(SASS_MEMORY_NEW(String_Constant, pstate, std::string(i, p)));
523+
if (i < p) {
524+
std::string parsed(i, p);
525+
String_Constant_Obj str = SASS_MEMORY_NEW(String_Constant, pstate, parsed);
526+
pstate += Offset(parsed);
527+
str->update_pstate(pstate);
528+
schema->append(&str);
529+
}
530+
521531
// check if the interpolation only contains white-space (error out)
522532
if (peek < sequence < optional_spaces, exactly<rbrace> > >(p+2)) { position = p+2;
523533
css_error("Invalid CSS", " after ", ": expected expression (e.g. 1px, bold), was ");
524534
}
525535
// skip over all nested inner interpolations up to our own delimiter
526536
const char* j = skip_over_scopes< exactly<hash_lbrace>, exactly<rbrace> >(p + 2, end_of_selector);
527537
// pass inner expression to the parser to resolve nested interpolations
538+
pstate.add(p, p+2);
528539
Expression_Obj interpolant = Parser::from_c_str(p+2, j, ctx, pstate).parse_list();
529540
// set status on the list expression
530541
interpolant->is_interpolant(true);
531542
// schema->has_interpolants(true);
532543
// add to the string schema
533544
schema->append(&interpolant);
545+
// advance parser state
546+
pstate.add(p+2, j);
534547
// advance position
535548
i = j;
536549
}
537550
// no more interpolants have been found
538551
// add the last segment if there is one
539552
else {
540553
// make sure to add the last bits of the string up to the end (if any)
541-
if (i < end_of_selector) schema->append(SASS_MEMORY_NEW(String_Constant, pstate, std::string(i, end_of_selector)));
554+
if (i < end_of_selector) {
555+
std::string parsed(i, end_of_selector);
556+
String_Constant_Obj str = SASS_MEMORY_NEW(String_Constant, pstate, parsed);
557+
pstate += Offset(parsed);
558+
str->update_pstate(pstate);
559+
i = end_of_selector;
560+
schema->append(&str);
561+
}
542562
// exit loop
543-
i = end_of_selector;
544563
}
545564
}
546565
// EO until eos
@@ -550,6 +569,9 @@ namespace Sass {
550569

551570
// update for end position
552571
selector_schema->update_pstate(pstate);
572+
schema->update_pstate(pstate);
573+
574+
after_token = before_token = pstate;
553575

554576
// return parsed result
555577
return selector_schema;
@@ -645,6 +667,7 @@ namespace Sass {
645667

646668
String_Ptr reference = 0;
647669
lex < block_comment >();
670+
advanceToNextToken();
648671
Complex_Selector_Obj sel = SASS_MEMORY_NEW(Complex_Selector, pstate);
649672

650673
// parse the left hand side
@@ -974,6 +997,7 @@ namespace Sass {
974997
lex < css_comments >(false);
975998
Declaration_Obj decl = SASS_MEMORY_NEW(Declaration, prop->pstate(), prop, value/*, lex<kwd_important>()*/);
976999
decl->is_indented(is_indented);
1000+
decl->update_pstate(pstate);
9771001
return decl;
9781002
}
9791003
}

0 commit comments

Comments
 (0)