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

Commit 5660bfe

Browse files
author
Aaron Leung
committed
getting attribute selectors with interpolated strings to work
1 parent 1122ead commit 5660bfe

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

ast.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,9 +1155,9 @@ namespace Sass {
11551155
class Attribute_Selector : public Simple_Selector {
11561156
ADD_PROPERTY(string, name);
11571157
ADD_PROPERTY(string, matcher);
1158-
ADD_PROPERTY(string, value);
1158+
ADD_PROPERTY(String*, value); // might be interpolated
11591159
public:
1160-
Attribute_Selector(string path, Position position, string n, string m, string v)
1160+
Attribute_Selector(string path, Position position, string n, string m, String* v)
11611161
: Simple_Selector(path, position), name_(n), matcher_(m), value_(v)
11621162
{ }
11631163
ATTACH_OPERATIONS();

contextualize.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,16 @@ namespace Sass {
116116
{ return s; }
117117

118118
Selector* Contextualize::operator()(Attribute_Selector* s)
119-
{ return s; }
119+
{
120+
// the value might be interpolated; evaluate it
121+
String* v = s->value();
122+
if (v) {
123+
v = static_cast<String*>(v->perform(eval->with(env, backtrace)));
124+
}
125+
Attribute_Selector* ss = new (ctx.mem) Attribute_Selector(*s);
126+
ss->value(v);
127+
return ss;
128+
}
120129

121130
Selector* Contextualize::operator()(Selector_Qualifier* s)
122131
{ return s; }

inspect.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,10 @@ namespace Sass {
525525
append_to_buffer(s->name());
526526
if (!s->matcher().empty()) {
527527
append_to_buffer(s->matcher());
528-
append_to_buffer(s->value());
528+
if (s->value()) {
529+
s->value()->perform(this);
530+
}
531+
// append_to_buffer(s->value());
529532
}
530533
append_to_buffer("]");
531534
}

parser.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,14 +539,24 @@ namespace Sass {
539539
Position p = source_position;
540540
if (!lex< attribute_name >()) error("invalid attribute name in attribute selector");
541541
string name(lexed);
542-
if (lex< exactly<']'> >()) return new (ctx.mem) Attribute_Selector(path, p, name, "", "");
542+
if (lex< exactly<']'> >()) return new (ctx.mem) Attribute_Selector(path, p, name, "", 0);
543543
if (!lex< alternatives< exact_match, class_match, dash_match,
544544
prefix_match, suffix_match, substring_match > >()) {
545545
error("invalid operator in attribute selector for " + name);
546546
}
547547
string matcher(lexed);
548-
if (!lex< string_constant >() && !lex< identifier >()) error("expected a string constant or identifier in attribute selector for " + name);
549-
string value(lexed);
548+
549+
String* value = 0;
550+
if (lex< identifier >()) {
551+
value = new (ctx.mem) String_Constant(path, p, lexed, true);
552+
}
553+
else if (lex< string_constant >()) {
554+
value = parse_interpolated_chunk(lexed);
555+
}
556+
else {
557+
error("expected a string constant or identifier in attribute selector for " + name);
558+
}
559+
550560
if (!lex< exactly<']'> >()) error("unterminated attribute selector for " + name);
551561
return new (ctx.mem) Attribute_Selector(path, p, name, matcher, value);
552562
}

0 commit comments

Comments
 (0)