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

Commit e6453bc

Browse files
committed
Implement inheritance in runtime getters
1 parent 92ddfa8 commit e6453bc

File tree

2 files changed

+94
-10
lines changed

2 files changed

+94
-10
lines changed

src/fn_meta.cpp

Lines changed: 90 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,33 @@ namespace Sass {
8585
{
8686
String* variable = arguments[0]->assertString(compiler, Sass::Strings::name);
8787
String* plugin = arguments[1]->assertStringOrNull(compiler, Sass::Strings::module);
88+
auto parent = compiler.varStack.back()->getModule();
8889
if (plugin != nullptr) {
89-
throw Exception::RuntimeException(compiler,
90-
"Modules are not supported yet");
90+
auto pp = parent->fwdModule33.find(plugin->value());
91+
if (pp != parent->fwdModule33.end()) {
92+
VarRefs* module = pp->second.first;
93+
auto it = module->varIdxs.find(variable->value());
94+
return SASS_MEMORY_NEW(Boolean, pstate,
95+
it != module->varIdxs.end());
96+
}
97+
else {
98+
throw Exception::RuntimeException(compiler,
99+
"There is no module with the namespace \"" + plugin->value() + "\".");
100+
}
101+
return SASS_MEMORY_NEW(Boolean, pstate, false);
102+
}
103+
bool hasVar = false;
104+
for (auto asd : parent->fwdGlobal33) {
105+
VarRefs* global = asd.first;
106+
if (global->varIdxs.count(variable->value()) != 0) {
107+
if (hasVar) {
108+
throw Exception::RuntimeException(compiler,
109+
"This variable is available from multiple global modules.");
110+
}
111+
hasVar = true;
112+
}
91113
}
114+
if (hasVar) return SASS_MEMORY_NEW(Boolean, pstate, true);
92115
return SASS_MEMORY_NEW(Boolean, pstate,
93116
compiler.getVariable(variable->value(), true));
94117

@@ -100,17 +123,53 @@ namespace Sass {
100123
{
101124
String* variable = arguments[0]->assertString(compiler, Sass::Strings::name);
102125
ValueObj ex = compiler.getVariable(variable->value());
126+
bool hasVar = false;
127+
auto parent = compiler.varStack.back()->getModule();
128+
for (auto asd : parent->fwdGlobal33) {
129+
VarRefs* global = asd.first;
130+
if (global->varIdxs.count(variable->value()) != 0) {
131+
if (hasVar) {
132+
throw Exception::RuntimeException(compiler,
133+
"This variable is available from multiple global modules.");
134+
}
135+
hasVar = true;
136+
}
137+
}
138+
if (hasVar) return SASS_MEMORY_NEW(Boolean, pstate, true);
103139
return SASS_MEMORY_NEW(Boolean, pstate, !ex.isNull());
104140
}
105141

106142
BUILT_IN_FN(functionExists)
107143
{
108144
String* variable = arguments[0]->assertString(compiler, Sass::Strings::name);
109145
String* plugin = arguments[1]->assertStringOrNull(compiler, Sass::Strings::module);
146+
auto parent = compiler.varStack.back()->getModule();
110147
if (plugin != nullptr) {
111-
throw Exception::RuntimeException(compiler,
112-
"Modules are not supported yet");
148+
auto pp = parent->fwdModule33.find(plugin->value());
149+
if (pp != parent->fwdModule33.end()) {
150+
VarRefs* module = pp->second.first;
151+
auto it = module->fnIdxs.find(variable->value());
152+
return SASS_MEMORY_NEW(Boolean, pstate,
153+
it != module->fnIdxs.end());
154+
}
155+
else {
156+
throw Exception::RuntimeException(compiler,
157+
"There is no module with the namespace \"" + plugin->value() + "\".");
158+
}
159+
return SASS_MEMORY_NEW(Boolean, pstate, false);
160+
}
161+
bool hasFn = false;
162+
for (auto asd : parent->fwdGlobal33) {
163+
VarRefs* global = asd.first;
164+
if (global->fnIdxs.count(variable->value()) != 0) {
165+
if (hasFn) {
166+
throw Exception::RuntimeException(compiler,
167+
"This function is available from multiple global modules.");
168+
}
169+
hasFn = true;
170+
}
113171
}
172+
if (hasFn) return SASS_MEMORY_NEW(Boolean, pstate, true);
114173
CallableObj fn = compiler.getFunction(variable->value());
115174
return SASS_MEMORY_NEW(Boolean, pstate, !fn.isNull());
116175
}
@@ -119,10 +178,35 @@ namespace Sass {
119178
{
120179
String* variable = arguments[0]->assertString(compiler, Sass::Strings::name);
121180
String* plugin = arguments[1]->assertStringOrNull(compiler, Sass::Strings::module);
181+
182+
auto parent = compiler.varStack.back()->getModule();
122183
if (plugin != nullptr) {
123-
throw Exception::RuntimeException(compiler,
124-
"Modules are not supported yet");
184+
auto pp = parent->fwdModule33.find(plugin->value());
185+
if (pp != parent->fwdModule33.end()) {
186+
VarRefs* module = pp->second.first;
187+
auto it = module->mixIdxs.find(variable->value());
188+
return SASS_MEMORY_NEW(Boolean, pstate,
189+
it != module->mixIdxs.end());
190+
}
191+
else {
192+
throw Exception::RuntimeException(compiler,
193+
"There is no module with the namespace \"" + plugin->value() + "\".");
194+
}
195+
return SASS_MEMORY_NEW(Boolean, pstate, false);
125196
}
197+
bool hasFn = false;
198+
for (auto asd : parent->fwdGlobal33) {
199+
VarRefs* global = asd.first;
200+
if (global->mixIdxs.count(variable->value()) != 0) {
201+
if (hasFn) {
202+
throw Exception::RuntimeException(compiler,
203+
"This function is available from multiple global modules.");
204+
}
205+
hasFn = true;
206+
}
207+
}
208+
if (hasFn) return SASS_MEMORY_NEW(Boolean, pstate, true);
209+
126210
CallableObj fn = compiler.getMixin(variable->value());
127211
return SASS_MEMORY_NEW(Boolean, pstate, !fn.isNull());
128212
}

src/parser_stylesheet.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ namespace Sass {
14241424
if (var != fwd.first->mixIdxs.end()) {
14251425
if (sameMixFrame && it.second == var->second) continue;
14261426
throw Exception::ParserException(context,
1427-
"Mixin " + it.first.norm() + " is "
1427+
"Mixin \"" + it.first.norm() + "(...)\" is "
14281428
"available from multiple global modules.");
14291429
}
14301430
}
@@ -1433,7 +1433,7 @@ namespace Sass {
14331433
if (var != fwd.first->fnIdxs.end()) {
14341434
if (sameFnFrame && it.second == var->second) continue;
14351435
throw Exception::ParserException(context,
1436-
"Function " + it.first.norm() + " is "
1436+
"Function \"" + it.first.norm() + "(...)\" is "
14371437
"available from multiple global modules.");
14381438
}
14391439
}
@@ -1640,7 +1640,7 @@ namespace Sass {
16401640
if (var != fwd.first->mixIdxs.end()) {
16411641
if (sameMixFrame && it.second == var->second) continue;
16421642
throw Exception::ParserException(context,
1643-
"Mixin " + it.first.norm() + " is "
1643+
"Mixin \"" + it.first.norm() + "(...)\" is "
16441644
"available from multiple global modules.");
16451645
}
16461646
}
@@ -1649,7 +1649,7 @@ namespace Sass {
16491649
if (var != fwd.first->fnIdxs.end()) {
16501650
if (sameFnFrame && it.second == var->second) continue;
16511651
throw Exception::ParserException(context,
1652-
"Function " + it.first.norm() + " is "
1652+
"Function \"" + it.first.norm() + "(...)\" is "
16531653
"available from multiple global modules.");
16541654
}
16551655
}

0 commit comments

Comments
 (0)