Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sass
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
楚学文
node-sass
Commits
f7c3321b
Commit
f7c3321b
authored
Oct 01, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring the apply functions a bit.
parent
d3795e66
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
37 deletions
+44
-37
eval_apply.cpp
eval_apply.cpp
+44
-37
No files found.
eval_apply.cpp
View file @
f7c3321b
...
...
@@ -673,11 +673,11 @@ namespace Sass {
// Apply a mixin -- bind the arguments in a new environment, link the new
// environment to the current one, then copy the body and eval in the new
// environment.
Node
apply_mixin
(
Node
mixin
,
const
Node
args
,
Node
prefix
,
Environment
&
env
,
map
<
string
,
Function
>&
f_env
,
Node_Factory
&
new_Node
,
Context
&
ctx
,
bool
dynamic_scope
)
Node
apply_mixin
(
Node
mixin
,
const
Node
a
a
rgs
,
Node
prefix
,
Environment
&
env
,
map
<
string
,
Function
>&
f_env
,
Node_Factory
&
new_Node
,
Context
&
ctx
,
bool
dynamic_scope
)
{
Node
params
(
mixin
[
1
]);
Node
body
(
new_Node
(
mixin
[
2
]));
// clone the body
Node
args
=
new_Node
(
aargs
);
// evaluate arguments in the current environment
for
(
size_t
i
=
0
,
S
=
args
.
size
();
i
<
S
;
++
i
)
{
if
(
args
[
i
].
type
()
!=
Node
::
assignment
)
{
...
...
@@ -687,6 +687,17 @@ namespace Sass {
args
[
i
][
1
]
=
eval
(
args
[
i
][
1
],
prefix
,
env
,
f_env
,
new_Node
,
ctx
);
}
}
// need to eval twice because some expressions get delayed
// for (size_t i = 0, S = args.size(); i < S; ++i) {
// if (args[i].type() != Node::assignment) {
// args[i].should_eval() = true;
// args[i] = eval(args[i], prefix, env, f_env, new_Node, ctx);
// }
// else {
// args[i][1].should_eval() = true;
// args[i][1] = eval(args[i][1], prefix, env, f_env, new_Node, ctx);
// }
// }
// Create a new environment for the mixin and link it to the appropriate parent
Environment
bindings
;
...
...
@@ -713,46 +724,42 @@ namespace Sass {
// Apply a function -- bind the arguments and pass them to the underlying
// primitive function implementation, then return its value.
Node
apply_function
(
const
Function
&
f
,
const
Node
args
,
Node
prefix
,
Environment
&
env
,
map
<
string
,
Function
>&
f_env
,
Node_Factory
&
new_Node
,
Context
&
ctx
,
string
&
path
,
size_t
line
)
Node
apply_function
(
const
Function
&
f
,
const
Node
a
a
rgs
,
Node
prefix
,
Environment
&
env
,
map
<
string
,
Function
>&
f_env
,
Node_Factory
&
new_Node
,
Context
&
ctx
,
string
&
path
,
size_t
line
)
{
if
(
f
.
primitive
)
{
// evaluate arguments in the current environment
for
(
size_t
i
=
0
,
S
=
args
.
size
();
i
<
S
;
++
i
)
{
if
(
args
[
i
].
type
()
!=
Node
::
assignment
)
{
args
[
i
]
=
eval
(
args
[
i
],
prefix
,
env
,
f_env
,
new_Node
,
ctx
);
}
else
{
args
[
i
][
1
]
=
eval
(
args
[
i
][
1
],
prefix
,
env
,
f_env
,
new_Node
,
ctx
);
}
Node
args
=
new_Node
(
aargs
);
// evaluate arguments in the current environment
for
(
size_t
i
=
0
,
S
=
args
.
size
();
i
<
S
;
++
i
)
{
if
(
args
[
i
].
type
()
!=
Node
::
assignment
)
{
args
[
i
]
=
eval
(
args
[
i
],
prefix
,
env
,
f_env
,
new_Node
,
ctx
);
}
else
{
args
[
i
][
1
]
=
eval
(
args
[
i
][
1
],
prefix
,
env
,
f_env
,
new_Node
,
ctx
);
}
// bind arguments
Environment
bindings
;
bindings
.
link
(
env
.
global
?
*
env
.
global
:
env
);
bind_arguments
(
"function "
+
f
.
name
,
f
.
parameters
,
args
,
prefix
,
bindings
,
f_env
,
new_Node
,
ctx
);
return
f
.
primitive
(
f
.
parameter_names
,
bindings
,
new_Node
,
path
,
line
);
}
else
{
Node
params
(
f
.
definition
[
1
]);
Node
body
(
new_Node
(
f
.
definition
[
2
]));
// need to eval twice because some expressions get delayed
// for (size_t i = 0, S = args.size(); i < S; ++i) {
// if (args[i].type() != Node::assignment) {
// args[i].should_eval() = true;
// args[i] = eval(args[i], prefix, env, f_env, new_Node, ctx);
// }
// else {
// args[i][1].should_eval() = true;
// args[i][1] = eval(args[i][1], prefix, env, f_env, new_Node, ctx);
// }
// }
// evaluate arguments in the current environment
for
(
size_t
i
=
0
,
S
=
args
.
size
();
i
<
S
;
++
i
)
{
if
(
args
[
i
].
type
()
!=
Node
::
assignment
)
{
args
[
i
]
=
eval
(
args
[
i
],
prefix
,
env
,
f_env
,
new_Node
,
ctx
);
}
else
{
args
[
i
][
1
]
=
eval
(
args
[
i
][
1
],
prefix
,
env
,
f_env
,
new_Node
,
ctx
);
}
}
// bind arguments
Environment
bindings
;
Node
params
(
f
.
primitive
?
f
.
parameters
:
f
.
definition
[
1
]);
bindings
.
link
(
env
.
global
?
*
env
.
global
:
env
);
bind_arguments
(
"function "
+
f
.
name
,
params
,
args
,
prefix
,
bindings
,
f_env
,
new_Node
,
ctx
);
// create a new environment for the function and link it to the global env
// (C-style scope -- no full-blown lexical scope yet)
Environment
bindings
;
bindings
.
link
(
env
.
global
?
*
env
.
global
:
env
);
// bind the arguments
bind_arguments
(
"function "
+
f
.
name
,
params
,
args
,
prefix
,
bindings
,
f_env
,
new_Node
,
ctx
);
// TO DO: consider cloning the function body
return
function_eval
(
f
.
name
,
body
,
bindings
,
new_Node
,
ctx
,
true
);
if
(
f
.
primitive
)
{
return
f
.
primitive
(
f
.
parameter_names
,
bindings
,
new_Node
,
path
,
line
);
}
else
{
// TO DO: consider cloning the function body?
return
function_eval
(
f
.
name
,
f
.
definition
[
2
],
bindings
,
new_Node
,
ctx
,
true
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment