Commit d293b634 by Adeel

sourceComment: Changes behavior (BREAKING change).

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