@@ -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 }
0 commit comments