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
615097b4
Commit
615097b4
authored
Jan 02, 2014
by
Nick Schonning
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #200 from arian/source-maps
Initial support for the new source map feature of libsass
parents
ce2df81d
aa10b5e9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
86 additions
and
5 deletions
+86
-5
binding.cpp
binding.cpp
+15
-2
cli.js
lib/cli.js
+13
-0
render.js
lib/render.js
+20
-1
sass.js
sass.js
+1
-2
cli.js
test/cli.js
+37
-0
No files found.
binding.cpp
View file @
615097b4
...
...
@@ -191,9 +191,17 @@ void MakeFileCallback(uv_work_t* req) {
if
(
ctx
->
error_status
==
0
)
{
// if no error, do callback(null, result)
const
unsigned
argc
=
1
;
Handle
<
Value
>
source_map
;
if
(
ctx
->
options
.
source_comments
==
SASS_SOURCE_COMMENTS_MAP
)
{
source_map
=
String
::
New
(
ctx
->
source_map_string
);
}
else
{
source_map
=
Null
();
}
const
unsigned
argc
=
2
;
Local
<
Value
>
argv
[
argc
]
=
{
NanNewLocal
(
String
::
New
(
ctx
->
output_string
))
NanNewLocal
(
String
::
New
(
ctx
->
output_string
)),
NanNewLocal
(
source_map
)
};
ctx_w
->
callback
->
Call
(
argc
,
argv
);
...
...
@@ -222,6 +230,7 @@ NAN_METHOD(RenderFile) {
Local
<
Function
>
callback
=
Local
<
Function
>::
Cast
(
args
[
1
]);
Local
<
Function
>
errorCallback
=
Local
<
Function
>::
Cast
(
args
[
2
]);
String
::
AsciiValue
bstr
(
args
[
3
]);
String
::
AsciiValue
cstr
(
args
[
6
]);
filename
=
new
char
[
strlen
(
*
astr
)
+
1
];
strcpy
(
filename
,
*
astr
);
...
...
@@ -232,6 +241,10 @@ NAN_METHOD(RenderFile) {
ctx
->
options
.
output_style
=
args
[
4
]
->
Int32Value
();
ctx
->
options
.
image_path
=
new
char
[
0
];
ctx
->
options
.
source_comments
=
args
[
5
]
->
Int32Value
();
if
(
ctx
->
options
.
source_comments
==
SASS_SOURCE_COMMENTS_MAP
)
{
ctx
->
source_map_file
=
new
char
[
strlen
(
*
cstr
)
+
1
];
strcpy
(
ctx
->
source_map_file
,
*
cstr
);
}
ctx_w
->
ctx
=
ctx
;
ctx_w
->
callback
=
new
NanCallback
(
callback
);
ctx_w
->
errorCallback
=
new
NanCallback
(
errorCallback
);
...
...
lib/cli.js
View file @
615097b4
...
...
@@ -14,6 +14,9 @@ var optimist = require('optimist')
describe
:
'Include debug info in output (none|normal|map)'
,
'default'
:
'none'
})
.
options
(
'source-map'
,
{
describe
:
'Emit source map'
})
.
options
(
'include-path'
,
{
describe
:
'Path to look for @import-ed files'
,
'default'
:
cwd
...
...
@@ -99,6 +102,16 @@ exports = module.exports = function(args) {
options
.
sourceComments
=
options
.
sourceComments
[
0
];
}
// set source map file and set sourceComments to 'map'
if
(
argv
[
'source-map'
])
{
options
.
sourceComments
=
'map'
;
if
(
argv
[
'source-map'
]
===
true
)
{
options
.
sourceMap
=
outFile
+
'.map'
;
}
else
{
options
.
sourceMap
=
path
.
resolve
(
cwd
,
argv
[
'source-map'
]);
}
}
if
(
argv
.
w
)
{
var
watchDir
=
argv
.
w
;
...
...
lib/render.js
View file @
615097b4
...
...
@@ -9,7 +9,15 @@ function render(options, emitter) {
includePaths
:
options
.
includePaths
,
outputStyle
:
options
.
outputStyle
,
sourceComments
:
options
.
sourceComments
,
success
:
function
(
css
)
{
sourceMap
:
options
.
sourceMap
,
success
:
function
(
css
,
sourceMap
)
{
var
todo
=
1
;
var
done
=
function
()
{
if
(
--
todo
<=
0
)
{
emitter
.
emit
(
'done'
);
}
};
emitter
.
emit
(
'warn'
,
chalk
.
green
(
'Rendering Complete, saving .css file...'
));
...
...
@@ -17,8 +25,19 @@ function render(options, emitter) {
if
(
err
)
{
return
emitter
.
emit
(
'error'
,
chalk
.
red
(
'Error: '
+
err
));
}
emitter
.
emit
(
'warn'
,
chalk
.
green
(
'Wrote CSS to '
+
options
.
outFile
));
emitter
.
emit
(
'write'
,
err
,
options
.
outFile
,
css
);
done
();
});
if
(
options
.
sourceMap
)
{
todo
++
;
fs
.
writeFile
(
options
.
sourceMap
,
sourceMap
,
function
(
err
)
{
if
(
err
)
{
return
emitter
.
emit
(
'error'
,
chalk
.
red
(
'Error'
+
err
));
}
emitter
.
emit
(
'warn'
,
chalk
.
green
(
'Wrote Source Map to '
+
options
.
sourceMap
));
emitter
.
emit
(
'write-source-map'
,
err
,
options
.
sourceMap
,
sourceMap
);
done
();
});
}
if
(
options
.
stdout
)
{
emitter
.
emit
(
'log'
,
css
);
}
...
...
sass.js
View file @
615097b4
...
...
@@ -68,9 +68,8 @@ exports.render = function(options) {
options
.
error
=
options
.
error
||
function
(){};
if
(
options
.
file
!==
undefined
&&
options
.
file
!==
null
)
{
return
binding
.
renderFile
(
options
.
file
,
options
.
success
,
options
.
error
,
newOptions
.
paths
.
join
(
path
.
delimiter
),
newOptions
.
style
,
newOptions
.
comments
);
return
binding
.
renderFile
(
options
.
file
,
options
.
success
,
options
.
error
,
newOptions
.
paths
.
join
(
path
.
delimiter
),
newOptions
.
style
,
newOptions
.
comments
,
options
.
sourceMap
);
}
//Assume data is present if file is not. binding/libsass will tell the user otherwise!
return
binding
.
render
(
options
.
data
,
options
.
success
,
options
.
error
,
newOptions
.
paths
.
join
(
path
.
delimiter
),
newOptions
.
style
);
};
...
...
test/cli.js
View file @
615097b4
...
...
@@ -103,4 +103,41 @@ describe('cli', function() {
});
});
it
(
'should compile with the --source-map option'
,
function
(
done
){
var
emitter
=
cli
([
path
.
join
(
__dirname
,
'sample.scss'
),
'--source-map'
]);
emitter
.
on
(
'error'
,
done
);
emitter
.
on
(
'write-source-map'
,
function
(
err
,
file
)
{
assert
.
equal
(
file
,
path
.
join
(
__dirname
,
'../sample.css.map'
));
fs
.
exists
(
file
,
function
(
exists
)
{
assert
(
exists
);
});
});
emitter
.
on
(
'done'
,
function
()
{
fs
.
unlink
(
path
.
join
(
__dirname
,
'../sample.css.map'
),
function
()
{
fs
.
unlink
(
path
.
join
(
__dirname
,
'../sample.css'
),
function
()
{
done
();
});
});
});
});
it
(
'should compile with the --source-map option with specific filename'
,
function
(
done
){
var
emitter
=
cli
([
path
.
join
(
__dirname
,
'sample.scss'
),
'--source-map'
,
path
.
join
(
__dirname
,
'../sample.map'
)]);
emitter
.
on
(
'error'
,
done
);
emitter
.
on
(
'write-source-map'
,
function
(
err
,
file
)
{
assert
.
equal
(
file
,
path
.
join
(
__dirname
,
'../sample.map'
));
fs
.
exists
(
file
,
function
(
exists
)
{
assert
(
exists
);
});
});
emitter
.
on
(
'done'
,
function
()
{
fs
.
unlink
(
path
.
join
(
__dirname
,
'../sample.map'
),
function
()
{
fs
.
unlink
(
path
.
join
(
__dirname
,
'../sample.css'
),
function
()
{
done
();
});
});
});
});
});
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