Skip to content

Commit 7c1af00

Browse files
committed
Update for latest specs
1 parent cade3f4 commit 7c1af00

15 files changed

+296
-61
lines changed

src/ast_fwd_decl.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ namespace Sass {
158158
class String;
159159

160160
class SupportsCondition;
161+
class SupportsFunction;
162+
class SupportsAnything;
161163
class SupportsOperation;
162164
class SupportsNegation;
163165
class SupportsDeclaration;
@@ -289,6 +291,8 @@ namespace Sass {
289291
IMPL_MEM_OBJ(ItplString);
290292
IMPL_MEM_OBJ(StringExpression);
291293
IMPL_MEM_OBJ(SupportsCondition);
294+
IMPL_MEM_OBJ(SupportsFunction);
295+
IMPL_MEM_OBJ(SupportsAnything);
292296
IMPL_MEM_OBJ(SupportsOperation);
293297
IMPL_MEM_OBJ(SupportsNegation);
294298
IMPL_MEM_OBJ(SupportsDeclaration);

src/ast_supports.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,39 @@ namespace Sass {
2020

2121
SupportsOperation::SupportsOperation(
2222
const SourceSpan& pstate,
23-
SupportsConditionObj lhs,
24-
SupportsConditionObj rhs,
23+
SupportsCondition* lhs,
24+
SupportsCondition* rhs,
2525
Operand operand) :
2626
SupportsCondition(pstate),
2727
left_(lhs),
2828
right_(rhs),
2929
operand_(operand)
3030
{}
3131

32+
/////////////////////////////////////////////////////////////////////////
33+
// A supports function
34+
/////////////////////////////////////////////////////////////////////////
35+
36+
SupportsFunction::SupportsFunction(
37+
const SourceSpan& pstate,
38+
Interpolation* name,
39+
Interpolation* args) :
40+
SupportsCondition(pstate),
41+
name_(name),
42+
args_(args)
43+
{}
44+
45+
/////////////////////////////////////////////////////////////////////////
46+
// A supports anything
47+
/////////////////////////////////////////////////////////////////////////
48+
49+
SupportsAnything::SupportsAnything(
50+
const SourceSpan& pstate,
51+
Interpolation* contents) :
52+
SupportsCondition(pstate),
53+
contents_(contents)
54+
{}
55+
3256
/////////////////////////////////////////////////////////////////////////
3357
// A negation condition (`not CONDITION`).
3458
/////////////////////////////////////////////////////////////////////////

src/ast_supports.hpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ namespace Sass {
2323
const SourceSpan& pstate);
2424
// Declare up-casting methods
2525
DECLARE_ISA_CASTER(SupportsOperation);
26+
DECLARE_ISA_CASTER(SupportsFunction);
27+
DECLARE_ISA_CASTER(SupportsAnything);
2628
DECLARE_ISA_CASTER(SupportsNegation);
2729
DECLARE_ISA_CASTER(SupportsDeclaration);
2830
DECLARE_ISA_CASTER(SupportsInterpolation);
@@ -43,13 +45,47 @@ namespace Sass {
4345
// Value constructor
4446
SupportsOperation(
4547
const SourceSpan& pstate,
46-
SupportsConditionObj lhs,
47-
SupportsConditionObj rhs,
48+
SupportsCondition* lhs,
49+
SupportsCondition* rhs,
4850
Operand operand);
4951
// Implement final up-casting method
5052
IMPLEMENT_ISA_CASTER(SupportsOperation);
5153
};
5254

55+
/////////////////////////////////////////////////////////////////////////
56+
// A supports function
57+
/////////////////////////////////////////////////////////////////////////
58+
class SupportsFunction final : public SupportsCondition
59+
{
60+
private:
61+
ADD_CONSTREF(InterpolationObj, name);
62+
ADD_CONSTREF(InterpolationObj, args);
63+
public:
64+
// Value constructor
65+
SupportsFunction(
66+
const SourceSpan& pstate,
67+
Interpolation* name,
68+
Interpolation* args);
69+
// Implement final up-casting method
70+
IMPLEMENT_ISA_CASTER(SupportsFunction);
71+
};
72+
73+
/////////////////////////////////////////////////////////////////////////
74+
// A supports anything
75+
/////////////////////////////////////////////////////////////////////////
76+
class SupportsAnything final : public SupportsCondition
77+
{
78+
private:
79+
ADD_CONSTREF(InterpolationObj, contents);
80+
public:
81+
// Value constructor
82+
SupportsAnything(
83+
const SourceSpan& pstate,
84+
Interpolation* contents);
85+
// Implement final up-casting method
86+
IMPLEMENT_ISA_CASTER(SupportsAnything);
87+
};
88+
5389
/////////////////////////////////////////////////////////////////////////
5490
// A negation condition (`not CONDITION`).
5591
/////////////////////////////////////////////////////////////////////////

src/ast_values.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,17 @@ namespace Sass {
10851085
return value_;
10861086
}
10871087

1088+
const Number* Number::checkPercent(Logger& logger, const sass::string& name) const
1089+
{
1090+
if (!hasUnit("%")) {
1091+
sass::sstream msg;
1092+
msg << "$" << name << ": Passing a number without unit % (" << inspect() << ") is deprecated." << STRMLF;
1093+
msg << "To preserve current behavior: $" << name << " * 1%" << STRMLF;
1094+
logger.addDeprecation(msg.str(), pstate());
1095+
}
1096+
return this;
1097+
}
1098+
10881099
/////////////////////////////////////////////////////////////////////////
10891100
// Implement delayed value fetcher
10901101
/////////////////////////////////////////////////////////////////////////

src/ast_values.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ namespace Sass {
433433
Number* assertHasUnits(Logger& logger, const sass::string& unit, const sass::string& name = Strings::empty);
434434
double assertRange(double min, double max, Logger& logger, const sass::string& name = Strings::empty) const;
435435

436+
const Number* checkPercent(Logger& logger, const sass::string& name) const;
437+
436438
// Implement equality comparators for base value class
437439
bool operator== (const Value& rhs) const override final;
438440
// Implement same class compare operator

src/debugger.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,20 @@ inline void debug_ast(AstNode* node, std::string ind)
730730
debug_ast(block->left(), ind + " left) ");
731731
debug_ast(block->right(), ind + " right) ");
732732
}
733+
else if (Cast<SupportsFunction>(node)) {
734+
SupportsFunction* block = Cast<SupportsFunction>(node);
735+
std::cerr << ind << "SupportsFunction " << block;
736+
std::cerr << " (" << pstate_source_position(node) << ")"
737+
<< std::endl;
738+
// debug_ast(block->condition(), ind + " condition) ");
739+
}
740+
else if (Cast<SupportsAnything>(node)) {
741+
SupportsAnything* block = Cast<SupportsAnything>(node);
742+
std::cerr << ind << "SupportsAnything " << block;
743+
std::cerr << " (" << pstate_source_position(node) << ")"
744+
<< std::endl;
745+
// debug_ast(block->condition(), ind + " condition) ");
746+
}
733747
else if (Cast<SupportsNegation>(node)) {
734748
SupportsNegation* block = Cast<SupportsNegation>(node);
735749
std::cerr << ind << "SupportsNegation " << block;

src/emitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ namespace Sass {
271271
if ((output_style() != SASS_STYLE_COMPRESSED) && wbuf.buffer.size()) {
272272
unsigned char lst = buffer().at(buffer().length() - 1);
273273
if (!isspace(lst) || scheduled_delimiter) {
274-
if (last_char() != '(') {
274+
// if (last_char() != '(') {
275275
append_mandatory_space();
276-
}
276+
// }
277277
}
278278
}
279279
}

src/environment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ namespace Sass {
372372
}
373373

374374
sass::string fname(StringUtils::unvendor(name));
375-
if (fname == "calc" || fname == "element" || fname == "expression" ||
375+
if (fname == "calc" || fname == "element" || fname == "expression" || fname == "clamp" ||
376376
fname == "url" || fname == "and" || fname == "or" || fname == "not") {
377377
error("Invalid function name.",
378378
scanner.relevantSpanFrom(start));

src/eval.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,8 @@ namespace Sass {
17951795
sass::string Eval::_parenthesize(SupportsCondition* condition) {
17961796
SupportsNegation* negation = condition->isaSupportsNegation();
17971797
SupportsOperation* operation = condition->isaSupportsOperation();
1798-
if (negation != nullptr || operation != nullptr) {
1798+
SupportsAnything* anything = condition->isaSupportsAnything();
1799+
if (negation != nullptr || operation != nullptr || anything != nullptr) {
17991800
return "(" + _visitSupportsCondition(condition) + ")";
18001801
}
18011802
else {
@@ -1837,6 +1838,12 @@ namespace Sass {
18371838
strm += toCss(declaration->value()); strm += ")";
18381839
return strm;
18391840
}
1841+
else if (auto declaration = condition->isaSupportsFunction()) {
1842+
return "SupportsFunction";
1843+
}
1844+
else if (auto anything = condition->isaSupportsAnything()) {
1845+
return acceptInterpolation(anything->contents(), false);
1846+
}
18401847
else {
18411848
return Strings::empty;
18421849
}

src/fn_colors.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace Sass {
2121
/////////////////////////////////////////////////////////////////////////
2222
/////////////////////////////////////////////////////////////////////////
2323

24-
// Create typedef for value function callback
24+
// Create typedef for color function callback
2525
typedef Value* (*colFn)(
2626
const sass::string& name,
2727
const ValueVector& arguments,
@@ -71,7 +71,8 @@ namespace Sass {
7171
|| startsWith(str->value(), "var(", 4)
7272
|| startsWith(str->value(), "env(", 4)
7373
|| startsWith(str->value(), "min(", 4)
74-
|| startsWith(str->value(), "max(", 4);
74+
|| startsWith(str->value(), "max(", 4)
75+
|| startsWith(str->value(), "clamp(", 6);
7576
}
7677
// EO isSpecialNumber
7778

@@ -1251,8 +1252,8 @@ namespace Sass {
12511252
double r = nr_r ? nr_r->assertRange(0.0, 255.0, compiler, Strings::red) : 0.0;
12521253
double g = nr_g ? nr_g->assertRange(0.0, 255.0, compiler, Strings::green) : 0.0;
12531254
double b = nr_b ? nr_b->assertRange(0.0, 255.0, compiler, Strings::blue) : 0.0;
1254-
double s = nr_s ? nr_s->assertRange(0.0, 100.0, compiler, Strings::saturation) : 0.0;
1255-
double l = nr_l ? nr_l->assertRange(0.0, 100.0, compiler, Strings::lightness) : 0.0;
1255+
double s = nr_s ? nr_s->checkPercent(compiler, Strings::saturation)->assertRange(0.0, 100.0, compiler, Strings::saturation) : 0.0;
1256+
double l = nr_l ? nr_l->checkPercent(compiler, Strings::lightness)->assertRange(0.0, 100.0, compiler, Strings::lightness) : 0.0;
12561257
double a = nr_a ? nr_a->assertRange(0.0, 1.0, compiler, Strings::alpha) : 0.0;
12571258
double wn = nr_wn ? nr_wn->assertHasUnits(compiler, Strings::percent, Strings::whiteness)->assertRange(0.0, 100.0, compiler, Strings::whiteness) : 0.0;
12581259
double bn = nr_bn ? nr_bn->assertHasUnits(compiler, Strings::percent, Strings::blackness)->assertRange( 0.0, 100.0, compiler, Strings::blackness) : 0.0;
@@ -1680,10 +1681,10 @@ namespace Sass {
16801681
return SASS_MEMORY_NEW(String, pstate, fncall.str());
16811682
}
16821683

1683-
Number* h = _h->assertNumber(logger, Strings::hue);
1684-
Number* s = _s->assertNumber(logger, Strings::saturation);
1685-
Number* l = _l->assertNumber(logger, Strings::lightness);
1686-
Number* a = _a ? _a->assertNumber(logger, Strings::alpha) : nullptr;
1684+
const Number* h = _h->assertNumber(logger, Strings::hue);
1685+
const Number* s = _s->assertNumber(logger, Strings::saturation)->checkPercent(logger, Strings::saturation);
1686+
const Number* l = _l->assertNumber(logger, Strings::lightness)->checkPercent(logger, Strings::lightness);
1687+
const Number* a = _a ? _a->assertNumber(logger, Strings::alpha) : nullptr;
16871688

16881689
return SASS_MEMORY_NEW(ColorHsla, pstate,
16891690
h->value(),

0 commit comments

Comments
 (0)