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

Commit ea4ecf2

Browse files
committed
Implement get-function inheritance
1 parent e6453bc commit ea4ecf2

File tree

3 files changed

+77
-12
lines changed

3 files changed

+77
-12
lines changed

src/extender.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "permutate.hpp"
44
#include "callstack.hpp"
5+
#include "exceptions.hpp"
56
#include "dart_helpers.hpp"
67
#include "ast_selectors.hpp"
78

@@ -70,10 +71,10 @@ namespace Sass {
7071

7172
for (auto complex : targets->elements()) {
7273

73-
// This seems superfluous, check is done before!?
74-
// if (complex->length() != 1) {
75-
// error("complex selectors may not be extended.", complex->pstate(), traces);
76-
// }
74+
if (complex->size() > 1) {
75+
throw Exception::RuntimeException(traces,
76+
"complex selectors may not be extended.");
77+
}
7778

7879
if (const CompoundSelector* compound = complex->first()->isaCompoundSelector()) {
7980

@@ -94,6 +95,11 @@ namespace Sass {
9495
selector = extender.extendList(selector, extensions, {});
9596

9697
}
98+
else {
99+
throw Exception::RuntimeException(traces,
100+
"combinators cannot be extended.");
101+
102+
}
97103

98104
}
99105

src/fn_maps.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ namespace Sass {
211211
void registerFunctions(Compiler& ctx)
212212
{
213213
Module& module(ctx.createModule("map"));
214+
// module.addFunction("get", ctx.registerBuiltInFunction("map-get", "$map, $key", set));
214215
module.addFunction("get", ctx.registerBuiltInFunction("map-get", "$map, $key", get));
215216
module.addFunction("merge", ctx.registerBuiltInFunction("map-merge", "$map1, $map2", merge));
216217
module.addFunction("remove", ctx.registerBuiltInOverloadFns("map-remove", {

src/fn_meta.cpp

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -289,20 +289,78 @@ namespace Sass {
289289

290290
String* name = arguments[0]->assertString(compiler, Sass::Strings::name);
291291
bool css = arguments[1]->isTruthy(); // supports all values
292-
String* plugin = arguments[2]->assertStringOrNull(compiler, Sass::Strings::module);
292+
String* ns = arguments[2]->assertStringOrNull(compiler, Sass::Strings::module);
293293

294-
if (css && plugin != nullptr) {
294+
if (css && ns != nullptr) {
295295
throw Exception::RuntimeException(compiler,
296296
"$css and $module may not both be passed at once.");
297297
}
298298

299-
CallableObj callable = css
300-
? SASS_MEMORY_NEW(PlainCssCallable, pstate, name->value())
301-
: _getFunction(name->value(), compiler);
299+
if (css) {
300+
return SASS_MEMORY_NEW(Function, pstate,
301+
SASS_MEMORY_NEW(PlainCssCallable, pstate,
302+
name->value()));
303+
}
304+
305+
// CallableObj callable = css
306+
// ? SASS_MEMORY_NEW(PlainCssCallable, pstate, name->value())
307+
// : _getFunction(name->value(), compiler);
308+
309+
310+
CallableObj callable;
302311

303-
if (callable == nullptr) throw
304-
Exception::RuntimeException(compiler,
305-
"Function not found: " + name->value());
312+
auto parent = compiler.varStack.back()->getModule();
313+
314+
if (ns != nullptr) {
315+
auto pp = parent->fwdModule33.find(ns->value());
316+
if (pp != parent->fwdModule33.end()) {
317+
VarRefs* module = pp->second.first;
318+
auto it = module->fnIdxs.find(name->value());
319+
if (it != module->fnIdxs.end()) {
320+
VarRef fidx({ module->fnFrame, it->second });
321+
callable = compiler.varRoot.getFunction(fidx);
322+
}
323+
}
324+
else {
325+
throw Exception::RuntimeException(compiler,
326+
"There is no module with the namespace \"" + ns->value() + "\".");
327+
}
328+
}
329+
else {
330+
331+
callable = _getFunction(name->value(), compiler);
332+
333+
if (!callable) {
334+
335+
for (auto asd : parent->fwdGlobal33) {
336+
VarRefs* global = asd.first;
337+
auto it = global->fnIdxs.find(name->value());
338+
if (it != global->fnIdxs.end()) {
339+
if (callable) {
340+
throw Exception::RuntimeException(compiler,
341+
"This function is available from multiple global modules.");
342+
}
343+
VarRef fidx({ global->fnFrame, it->second });
344+
callable = compiler.varRoot.getFunction(fidx);
345+
if (callable) break;
346+
}
347+
}
348+
}
349+
}
350+
351+
352+
if (callable == nullptr) {
353+
if (name->hasQuotes()) {
354+
throw
355+
Exception::RuntimeException(compiler,
356+
"Function not found: \"" + name->value() + "\"");
357+
}
358+
else {
359+
throw
360+
Exception::RuntimeException(compiler,
361+
"Function not found: " + name->value() + "");
362+
}
363+
}
306364

307365
return SASS_MEMORY_NEW(Function, pstate, callable);
308366

0 commit comments

Comments
 (0)