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
a5973985
Commit
a5973985
authored
Apr 16, 2012
by
Aaron Leung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrapping up type-checking for built-in functions.
parent
2d15ad0c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
17 deletions
+25
-17
exceptional.scss
exceptional.scss
+3
-2
functions.cpp
functions.cpp
+22
-15
No files found.
exceptional.scss
View file @
a5973985
...
@@ -43,6 +43,6 @@ div {
...
@@ -43,6 +43,6 @@ div {
flah
:
unquote
(
"hello"
);
flah
:
unquote
(
"hello"
);
grah
:
quote
(
hello
);
grah
:
quote
(
hello
);
hrah
:
quote
(
mukluk
);
hrah
:
quote
(
mukluk
);
mwah
:
percentage
(
.3
);
mwah
:
join
(()
,
2
,
"comma"
);
a
:
floor
(
10
.8%
);
gwah
:
comparable
(
foo
,
bar
);
}
}
\ No newline at end of file
functions.cpp
View file @
a5973985
...
@@ -356,6 +356,7 @@ namespace Sass {
...
@@ -356,6 +356,7 @@ namespace Sass {
else
if
(
arg
.
type
==
Node
::
nil
)
{
else
if
(
arg
.
type
==
Node
::
nil
)
{
return
Node
(
arg
.
line_number
,
0
);
return
Node
(
arg
.
line_number
,
0
);
}
}
// single objects should be reported as lists of length 1
else
{
else
{
return
Node
(
arg
.
line_number
,
1
);
return
Node
(
arg
.
line_number
,
1
);
}
}
...
@@ -366,36 +367,44 @@ namespace Sass {
...
@@ -366,36 +367,44 @@ namespace Sass {
Node
nth
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
)
{
Node
nth
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
)
{
Node
l
(
bindings
[
parameters
[
0
]]);
Node
l
(
bindings
[
parameters
[
0
]]);
// TO DO: check for empty list
// TO DO: check for empty list
if
(
l
.
type
==
Node
::
nil
)
eval_error
(
"cannot index into an empty list"
,
l
.
line_number
,
l
.
file_name
);
if
(
l
.
type
!=
Node
::
space_list
&&
l
.
type
!=
Node
::
comma_list
)
{
if
(
l
.
type
!=
Node
::
space_list
&&
l
.
type
!=
Node
::
comma_list
)
{
l
=
Node
(
Node
::
space_list
,
l
.
line_number
,
1
)
<<
l
;
l
=
Node
(
Node
::
space_list
,
l
.
line_number
,
1
)
<<
l
;
}
}
Node
n
(
bindings
[
parameters
[
1
]]);
if
(
n
.
type
!=
Node
::
number
)
eval_error
(
"second argument to nth must be a number"
,
n
.
line_number
,
n
.
file_name
);
if
(
n
.
numeric_value
()
<
1
||
n
.
numeric_value
()
>
l
.
size
())
eval_error
(
"out of range index for nth"
,
n
.
line_number
,
n
.
file_name
);
return
l
[
bindings
[
parameters
[
1
]].
content
.
numeric_value
-
1
];
return
l
[
bindings
[
parameters
[
1
]].
content
.
numeric_value
-
1
];
}
}
extern
const
char
separator_kwd
[]
=
"$separator"
;
extern
const
char
separator_kwd
[]
=
"$separator"
;
Node
join_impl
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
,
bool
has_sep
=
false
)
{
Node
join_impl
(
const
vector
<
Token
>&
parameters
,
map
<
Token
,
Node
>&
bindings
,
bool
has_sep
=
false
)
{
// if the args aren't lists, turn them into singleton lists
Node
l1
(
bindings
[
parameters
[
0
]]);
Node
l1
(
bindings
[
parameters
[
0
]]);
if
(
l1
.
type
!=
Node
::
space_list
&&
l1
.
type
!=
Node
::
comma_list
&&
l1
.
type
!=
Node
::
nil
)
{
if
(
l1
.
type
!=
Node
::
space_list
&&
l1
.
type
!=
Node
::
comma_list
&&
l1
.
type
!=
Node
::
nil
)
{
l1
=
Node
(
Node
::
space_list
,
l1
.
line_number
,
1
)
<<
l1
;
l1
=
Node
(
Node
::
space_list
,
l1
.
line_number
,
1
)
<<
l1
;
cerr
<<
"listified singleton"
<<
endl
;
}
}
Node
l2
(
bindings
[
parameters
[
1
]]);
Node
l2
(
bindings
[
parameters
[
1
]]);
if
(
l2
.
type
!=
Node
::
space_list
&&
l2
.
type
!=
Node
::
comma_list
&&
l2
.
type
!=
Node
::
nil
)
{
if
(
l2
.
type
!=
Node
::
space_list
&&
l2
.
type
!=
Node
::
comma_list
&&
l2
.
type
!=
Node
::
nil
)
{
l2
=
Node
(
Node
::
space_list
,
l2
.
line_number
,
1
)
<<
l2
;
l2
=
Node
(
Node
::
space_list
,
l2
.
line_number
,
1
)
<<
l2
;
cerr
<<
"listified singleton"
<<
endl
;
}
}
// nil and nil is nil
if
(
l1
.
type
==
Node
::
nil
&&
l2
.
type
==
Node
::
nil
)
return
Node
(
Node
::
nil
,
l1
.
line_number
);
if
(
l1
.
type
==
Node
::
nil
&&
l2
.
type
==
Node
::
nil
)
return
Node
(
Node
::
nil
,
l1
.
line_number
);
// figure out the combined size in advance
size_t
size
=
0
;
size_t
size
=
0
;
if
(
l1
.
type
!=
Node
::
nil
)
size
+=
l1
.
size
();
if
(
l1
.
type
!=
Node
::
nil
)
size
+=
l1
.
size
();
if
(
l2
.
type
!=
Node
::
nil
)
size
+=
l2
.
size
();
if
(
l2
.
type
!=
Node
::
nil
)
size
+=
l2
.
size
();
Node
lr
(
Node
::
space_list
,
l1
.
line_number
,
size
);
// accumulate the result
Node
lr
(
l1
.
type
,
l1
.
line_number
,
size
);
if
(
has_sep
)
{
if
(
has_sep
)
{
string
sep
(
bindings
[
parameters
[
2
]].
content
.
token
.
unquote
());
string
sep
(
bindings
[
parameters
[
2
]].
content
.
token
.
unquote
());
if
(
sep
==
"comma"
)
lr
.
type
=
Node
::
comma_list
;
if
(
sep
==
"comma"
)
lr
.
type
=
Node
::
comma_list
;
// TO DO: check for "space" or "auto"
else
if
(
sep
==
"space"
)
lr
.
type
=
Node
::
space_list
;
else
if
(
sep
==
"auto"
)
;
// leave it alone
else
{
eval_error
(
"third argument to join must be 'space', 'comma', or 'auto'"
,
l2
.
line_number
,
l2
.
file_name
);
}
}
}
else
if
(
l1
.
type
!=
Node
::
nil
)
lr
.
type
=
l1
.
type
;
else
if
(
l1
.
type
!=
Node
::
nil
)
lr
.
type
=
l1
.
type
;
else
if
(
l2
.
type
!=
Node
::
nil
)
lr
.
type
=
l2
.
type
;
else
if
(
l2
.
type
!=
Node
::
nil
)
lr
.
type
=
l2
.
type
;
...
@@ -477,8 +486,8 @@ namespace Sass {
...
@@ -477,8 +486,8 @@ namespace Sass {
case
Node
:
:
numeric_dimension
:
case
Node
:
:
numeric_dimension
:
u
.
content
.
token
=
Token
::
make
(
val
.
content
.
dimension
.
unit
,
Prelexer
::
identifier
(
val
.
content
.
dimension
.
unit
));
u
.
content
.
token
=
Token
::
make
(
val
.
content
.
dimension
.
unit
,
Prelexer
::
identifier
(
val
.
content
.
dimension
.
unit
));
break
;
break
;
default:
// TO DO: throw an exception
default:
u
.
content
.
token
=
Token
::
make
(
empty_str
);
eval_error
(
"argument to unit must be numeric"
,
val
.
line_number
,
val
.
file_name
);
break
;
break
;
}
}
return
u
;
return
u
;
...
@@ -509,7 +518,7 @@ namespace Sass {
...
@@ -509,7 +518,7 @@ namespace Sass {
return
F
;
return
F
;
}
break
;
}
break
;
default:
default:
// TO DO: throw an exception
;
eval_error
(
"argument to unitless must be numeric"
,
val
.
line_number
,
val
.
file_name
)
;
break
;
break
;
}
}
return
result
;
return
result
;
...
@@ -522,7 +531,8 @@ namespace Sass {
...
@@ -522,7 +531,8 @@ namespace Sass {
Node
n2
(
bindings
[
parameters
[
1
]]);
Node
n2
(
bindings
[
parameters
[
1
]]);
Node
::
Type
t1
=
n1
.
type
;
Node
::
Type
t1
=
n1
.
type
;
Node
::
Type
t2
=
n2
.
type
;
Node
::
Type
t2
=
n2
.
type
;
if
(
t1
==
Node
::
number
||
t2
==
Node
::
number
)
{
if
(
t1
==
Node
::
number
&&
n2
.
is_numeric
()
||
n1
.
is_numeric
()
&&
t2
==
Node
::
number
)
{
Node
T
(
Node
::
boolean
);
Node
T
(
Node
::
boolean
);
T
.
line_number
=
n1
.
line_number
;
T
.
line_number
=
n1
.
line_number
;
T
.
content
.
boolean_value
=
true
;
T
.
content
.
boolean_value
=
true
;
...
@@ -554,11 +564,8 @@ namespace Sass {
...
@@ -554,11 +564,8 @@ namespace Sass {
}
}
}
}
else
{
else
{
Node
F
(
Node
::
boolean
);
eval_error
(
"arguments to comparable must be numeric"
,
n1
.
line_number
,
n1
.
file_name
);
F
.
line_number
=
n1
.
line_number
;
}
F
.
content
.
boolean_value
=
false
;
return
F
;
}
}
}
// Boolean Functions ///////////////////////////////////////////////////
// Boolean Functions ///////////////////////////////////////////////////
...
...
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