@@ -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