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

Commit 55d8267

Browse files
author
Aaron Leung
committed
Cloning values fetched from variables in order to set their paths and line-numbers to the point of reference. (Using the original values would result in paths and line-numbers being reported as the point of assignment, which is not helpful for debugging.)
1 parent d935b77 commit 55d8267

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

eval_apply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ namespace Sass {
286286

287287
case Node::variable: {
288288
if (!env.query(expr.token())) throw_eval_error("reference to unbound variable " + expr.token().to_string(), expr.path(), expr.line());
289-
return env[expr.token()];
289+
return new_Node(expr.path(), expr.line(), env[expr.token()]);
290290
} break;
291291

292292
case Node::image_url: {

node_factory.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,37 @@ namespace Sass {
2727
return ip_cpy;
2828
}
2929

30+
// returns a deep-copy of its argument, but uses the path and line that are passed in
31+
Node_Impl* Node_Factory::alloc_Node_Impl(string& path, size_t line, Node_Impl* ip)
32+
{
33+
Node_Impl* ip_cpy = new Node_Impl(*ip);
34+
pool_.push_back(ip_cpy);
35+
if (ip_cpy->has_children) {
36+
for (size_t i = 0, S = ip_cpy->size(); i < S; ++i) {
37+
Node n(ip_cpy->at(i));
38+
ip_cpy->at(i) = (*this)(path, line, n);
39+
}
40+
}
41+
return ip_cpy;
42+
}
43+
44+
3045
// for cloning nodes
3146
Node Node_Factory::operator()(const Node& n1)
3247
{
3348
Node_Impl* ip_cpy = alloc_Node_Impl(n1.ip_); // deep-copy the implementation object
3449
return Node(ip_cpy);
3550
}
3651

52+
// for cloning nodes and resetting their path and line-number fields
53+
Node Node_Factory::operator()(string& path, size_t line, const Node& n1)
54+
{
55+
Node_Impl* ip_cpy = alloc_Node_Impl(path, line, n1.ip_); // deep-copy the implementation object
56+
ip_cpy->path = path;
57+
ip_cpy->line = line;
58+
return Node(ip_cpy);
59+
}
60+
3761
// for making leaf nodes out of terminals/tokens
3862
Node Node_Factory::operator()(Node::Type type, string path, size_t line, Token t)
3963
{

node_factory.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ namespace Sass {
1717
Node_Impl* alloc_Node_Impl(Node::Type type, string file, size_t line);
1818
// returns a deep-copy of its argument
1919
Node_Impl* alloc_Node_Impl(Node_Impl* ip);
20+
Node_Impl* alloc_Node_Impl(string& path, size_t line, Node_Impl* ip);
2021
public:
2122
// for cloning nodes
2223
Node operator()(const Node& n1);
24+
Node operator()(string& path, size_t line, const Node& n1);
2325
// for making leaf nodes out of terminals/tokens
2426
Node operator()(Node::Type type, string file, size_t line, Token t);
2527
// for making boolean values or interior nodes that have children

0 commit comments

Comments
 (0)