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

Commit 6b470ff

Browse files
committed
Fix import stack and relative meta.load-css resolving
1 parent a2fadba commit 6b470ff

File tree

6 files changed

+28
-6
lines changed

6 files changed

+28
-6
lines changed

src/ast_css.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,8 @@ namespace Sass {
553553

554554
CssParentNodeObj loaded = nullptr;
555555

556+
ImportObj import;
557+
556558
bool isActive = false;
557559
bool isLoading = false;
558560

src/ast_statements.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,18 +505,22 @@ namespace Sass {
505505

506506
UseRule::UseRule(
507507
const SourceSpan& pstate,
508-
const sass::string& url) :
508+
const sass::string& url,
509+
Import* import) :
509510
Statement(pstate),
511+
import_(import),
510512
url_(url)
511513
{}
512514

513515
ForwardRule::ForwardRule(
514516
const SourceSpan& pstate,
515517
const sass::string& url,
518+
Import* import,
516519
std::set<sass::string>&& toggledVariables,
517520
std::set<sass::string>&& toggledCallables,
518521
bool isShown) :
519522
Statement(pstate),
523+
import_(import),
520524
url_(url),
521525
isShown_(isShown),
522526
toggledVariables_(std::move(toggledVariables)),

src/ast_statements.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "ast_statements.hpp"
1616
#include "ast_css.hpp"
1717
#include "environment_stack.hpp"
18+
#include "file.hpp"
1819

1920
namespace Sass {
2021

@@ -568,6 +569,7 @@ namespace Sass {
568569
class UseRule final : public Statement
569570
{
570571
private:
572+
ADD_CONSTREF(ImportObj, import);
571573
ADD_CONSTREF(sass::string, url);
572574
// ADD_REF(sass::vector<WithConfigVar>, config);
573575
ADD_CONSTREF(RootObj, root);
@@ -577,7 +579,8 @@ namespace Sass {
577579
// Value constructor
578580
UseRule(
579581
const SourceSpan& pstate,
580-
const sass::string& url);
582+
const sass::string& url,
583+
Import* import);
581584
// Statement visitor to sass values entry function
582585
Value* accept(StatementVisitor<Value*>* visitor) override final {
583586
return visitor->visitUseRule(this);
@@ -590,6 +593,7 @@ namespace Sass {
590593
class ForwardRule final : public Statement
591594
{
592595
private:
596+
ADD_CONSTREF(ImportObj, import);
593597
ADD_CONSTREF(sass::string, url);
594598
ADD_PROPERTY(bool, isShown);
595599
ADD_PROPERTY(bool, hasWithConfig);
@@ -601,6 +605,7 @@ namespace Sass {
601605
ForwardRule(
602606
const SourceSpan& pstate,
603607
const sass::string& url,
608+
Import* import,
604609
std::set<sass::string>&& toggledVariables,
605610
std::set<sass::string>&& toggledCallables,
606611
bool isShown);

src/eval.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,9 +1436,11 @@ namespace Sass {
14361436
root->pstate(), nullptr, selectorStack.back());
14371437
auto oldCurrent = current;
14381438
current = root->loaded;
1439+
compiler.import_stack.push_back(root->import);
14391440
for (auto child : root->elements()) {
14401441
child->accept(this);
14411442
}
1443+
compiler.import_stack.pop_back();
14421444
current = oldCurrent;
14431445

14441446
for (auto child : root->loaded->elements()) {
@@ -1475,9 +1477,11 @@ namespace Sass {
14751477

14761478
node->root()->isActive = true;
14771479
node->root()->isLoading = true;
1480+
compiler.import_stack.push_back(root->import);
14781481
for (auto child : node->root()->elements()) {
14791482
child->accept(this);
14801483
}
1484+
compiler.import_stack.pop_back();
14811485
node->root()->isLoading = false;
14821486
node->root()->loaded = current;
14831487
}

src/fn_meta.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,10 @@ namespace Sass {
463463
return SASS_MEMORY_NEW(Null, pstate);
464464
}
465465

466-
sass::string previous(".");
467-
const ImportRequest import(url->value(), previous);
466+
Import* loaded = compiler.import_stack.back();
467+
468+
// Loading relative to where the function was included
469+
const ImportRequest import(url->value(), pstate.getAbsPath());
468470
// Search for valid imports (e.g. partials) on the file-system
469471
// Returns multiple valid results for ambiguous import path
470472
const sass::vector<ResolvedImport> resolved(compiler.findIncludes(import));
@@ -504,6 +506,7 @@ namespace Sass {
504506
sheet = compiler.registerImport(loaded); // @use
505507
// eval.selectorStack.pop_back();
506508
sheet->root2->idxs = local.idxs;
509+
sheet->root2->import = loaded;
507510
}
508511
else if (sheet->root2->isActive) {
509512
if (withMap) {
@@ -557,9 +560,11 @@ namespace Sass {
557560
eval.current = root->loaded;
558561
EnvScope scoped(compiler.varRoot, root->idxs);
559562
eval.selectorStack.push_back(nullptr);
563+
compiler.import_stack.push_back(root->import);
560564
for (auto child : root->elements()) {
561565
child->accept(&eval);
562566
}
567+
compiler.import_stack.pop_back();
563568
eval.selectorStack.pop_back();
564569
eval.current = oldCurrent;
565570
root->isLoading = false;

src/parser_stylesheet.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ namespace Sass {
13791379

13801380
UseRuleObj rule = SASS_MEMORY_NEW(UseRule,
13811381
scanner.relevantSpanFrom(start),
1382-
url);
1382+
url, {});
13831383

13841384
rule->hasWithConfig(hasWith);
13851385

@@ -1531,6 +1531,7 @@ namespace Sass {
15311531
local.idxs->fnFrame = 0xFFFFFFFF;
15321532
sheet = context.registerImport(loaded);
15331533
sheet->root2->idxs = local.idxs;
1534+
sheet->root2->import = loaded;
15341535
// sheet->root2->con context->node
15351536
}
15361537

@@ -1748,7 +1749,7 @@ namespace Sass {
17481749

17491750
ForwardRuleObj rule = SASS_MEMORY_NEW(ForwardRule,
17501751
scanner.relevantSpanFrom(start),
1751-
url,
1752+
url, {},
17521753
std::move(toggledVariables2),
17531754
std::move(toggledCallables2),
17541755
isShown);
@@ -1995,6 +1996,7 @@ namespace Sass {
19951996
local.idxs->fnFrame = 0xFFFFFFFF;
19961997
sheet = context.registerImport(loaded);
19971998
sheet->root2->idxs = local.idxs;
1999+
sheet->root2->import = loaded;
19982000
}
19992001

20002002
Root* root = sheet->root2;

0 commit comments

Comments
 (0)