Commit d293b634 by Adeel

sourceComment: Changes behavior (BREAKING change).

parent 15c0912f
......@@ -25,7 +25,7 @@ function init(args) {
' -x, --omit-source-map-url Omit source map URL comment from output',
' -i, --indented-syntax Treat data from stdin as sass code (versus scss)',
' --output-style CSS output style (nested|expanded|compact|compressed)',
' --source-comments Include debug info in output (none|normal|map)',
' --source-comments Include debug info in output',
' --source-map Emit source map',
' --include-path Path to look for imported files',
' --image-path Path to prepend when using the `image-url()` helper',
......@@ -38,28 +38,28 @@ function init(args) {
'indented-syntax',
'omit-source-map-url',
'stdout',
'watch'
'watch',
'source-comments'
],
string: [
'image-path',
'include-path',
'output',
'output-style',
'precision',
'source-comments'
'precision'
],
alias: {
i: 'indented-syntax',
o: 'output',
w: 'watch',
x: 'omit-source-map-url'
x: 'omit-source-map-url',
c: 'source-comments'
},
default: {
'image-path': '',
'include-path': cwd,
'output-style': 'nested',
precision: 5,
'source-comments': 'none'
precision: 5
}
});
}
......
......@@ -31,13 +31,6 @@ var SASS_OUTPUT_STYLE = {
compressed: 3
};
var SASS_SOURCE_COMMENTS = {
none: false,
normal: true,
default: false,
map: true
};
var prepareOptions = function (options) {
var success;
var error;
......@@ -50,11 +43,7 @@ var prepareOptions = function (options) {
error = options.error;
stats = options.stats || {};
sourceComments = options.source_comments || options.sourceComments;
if (options.sourceMap && !sourceComments) {
sourceComments = 'map';
}
sourceComments = options.source_comments || options.sourceComments || false;
if (typeof options.outFile === 'string' && typeof options.file === 'string' && path.resolve(options.outFile) === path.normalize(options.outFile).replace(new RegExp(path.sep + '$'), '' )) {
options.outFile = path.resolve(path.dirname(options.file), options.outFile);
......@@ -62,10 +51,12 @@ var prepareOptions = function (options) {
sourceMap = options.sourceMap;
if ((typeof sourceMap !== 'string' || !sourceMap.trim()) && sourceComments === 'map') {
sourceMap = options.outFile !== null ? options.outFile + '.map' : '';
} else if (options.outFile && sourceMap) {
sourceMap = path.resolve(path.dirname(options.file), sourceMap);
if (sourceMap) {
if (typeof sourceMap !== 'string' || !sourceMap.trim()) {
sourceMap = options.outFile !== null ? options.outFile + '.map' : '';
} else if (options.outFile) {
sourceMap = path.resolve(path.dirname(options.file), sourceMap);
}
}
prepareStats(options, stats);
......@@ -81,7 +72,7 @@ var prepareOptions = function (options) {
paths: (options.include_paths || options.includePaths || []).join(path.delimiter),
imagePath: options.image_path || options.imagePath || '',
style: SASS_OUTPUT_STYLE[options.output_style || options.outputStyle] || 0,
comments: SASS_SOURCE_COMMENTS[sourceComments] || false,
comments: sourceComments,
omitSourceMapUrl: options.omitSourceMapUrl,
indentedSyntax: options.indentedSyntax,
stats: stats,
......
......@@ -25,6 +25,24 @@ var expectedSampleNoComments = '#navbar {\n\
#navbar li a {\n\
font-weight: bold; }\n';
var sampleFilenameFwdSlashes = sampleFilename.replace(/\\/g, '/');
var expectedSampleComments = '/* line 1, ' + sampleFilenameFwdSlashes + ' */\n\
#navbar {\n\
width: 80%;\n\
height: 23px; }\n\
\n\
/* line 5, ' + sampleFilenameFwdSlashes + ' */\n\
#navbar ul {\n\
list-style-type: none; }\n\
\n\
/* line 8, ' + sampleFilenameFwdSlashes + ' */\n\
#navbar li {\n\
float: left; }\n\
/* line 10, ' + sampleFilenameFwdSlashes + ' */\n\
#navbar li a {\n\
font-weight: bold; }\n';
var expectedSampleCustomImagePath = 'body {\n\
background-image: url("/path/to/images/image.png"); }\n';
......@@ -143,10 +161,10 @@ describe('cli', function() {
});
it('should compile with the --source-comments option', function(done) {
var emitter = cli(['--source-comments', 'none', sampleScssPath]);
var emitter = cli(['--source-comments', sampleScssPath]);
emitter.on('error', done);
emitter.on('write', function(err, file, css) {
assert.equal(css, expectedSampleNoComments);
assert.equal(css, expectedSampleComments);
fs.unlink(file, done);
});
});
......@@ -252,8 +270,8 @@ describe('cli', function() {
});
});
it('should compile a sourceMap if --source-comments="map", but the --source-map option is excluded', function(done) {
var emitter = cli([sampleScssPath, '--source-comments', 'map']);
it('should not compile a sourceMap if --source-map option is excluded', function(done) {
var emitter = cli([sampleScssPath, '--source-comments']);
emitter.on('error', done);
emitter.on('write-source-map', function(err, file) {
assert.equal(file, sampleCssMapOutputPath);
......
......@@ -23,7 +23,7 @@ describe('compile file with source comments', function() {
it('should compile with render and comment outputs', function(done) {
sass.render({
file: sampleFilename,
source_comments: 'normal',
source_comments: 'map',
success: function (css) {
done(assert.equal(css, expectedCommentsScssStr));
},
......
......@@ -318,7 +318,6 @@ describe('compile with stats', function() {
sass.renderSync({
file: sampleFilename,
stats: stats,
sourceComments: 'map',
sourceMap: true
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment