Skip to content

Commit d763513

Browse files
authored
Merge pull request #2268 from mgreter/bugfix/srcmap-selector-schema
Fix source mappings for selector schema
2 parents b667cac + a41d16a commit d763513

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
@@ -144,7 +144,9 @@ namespace Sass {
144144
}
145145

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

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

550569
// update for end position
551570
selector_schema->update_pstate(pstate);
571+
schema->update_pstate(pstate);
572+
573+
after_token = before_token = pstate;
552574

553575
// return parsed result
554576
return selector_schema;
@@ -644,6 +666,7 @@ namespace Sass {
644666

645667
String_Ptr reference = 0;
646668
lex < block_comment >();
669+
advanceToNextToken();
647670
Complex_Selector_Obj sel = SASS_MEMORY_NEW(Complex_Selector, pstate);
648671

649672
// parse the left hand side
@@ -973,6 +996,7 @@ namespace Sass {
973996
lex < css_comments >(false);
974997
Declaration_Obj decl = SASS_MEMORY_NEW(Declaration, prop->pstate(), prop, value/*, lex<kwd_important>()*/);
975998
decl->is_indented(is_indented);
999+
decl->update_pstate(pstate);
9761000
return decl;
9771001
}
9781002
}

0 commit comments

Comments
 (0)