Skip to content

Commit 5fbf419

Browse files
committed
Merge pull request #130 from asottile/remove_comments_with_sourcemap
Remove comments with sourcemap
2 parents c84f25c + 793bc16 commit 5fbf419

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed

pysass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ PySass_compile_filename(PyObject *self, PyObject *args) {
575575
context = sass_make_file_context(filename);
576576
options = sass_file_context_get_options(context);
577577

578-
if (source_comments && PySass_Bytes_Check(source_map_filename)) {
578+
if (PySass_Bytes_Check(source_map_filename)) {
579579
size_t source_map_file_len = PySass_Bytes_GET_SIZE(source_map_filename);
580580
if (source_map_file_len) {
581581
char *source_map_file = (char *) malloc(source_map_file_len + 1);

sass.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,6 @@ def compile(**kwargs):
308308
:param source_map_filename: use source maps and indicate the source map
309309
output filename. :const:`None` means not
310310
using source maps. :const:`None` by default.
311-
note that it implies ``source_comments``
312-
is also :const:`True`
313311
:type source_map_filename: :class:`str`
314312
:param include_paths: an optional list of paths to find ``@import``\ ed
315313
SASS/CSS source files
@@ -327,7 +325,7 @@ def compile(**kwargs):
327325
<importer-callbacks>`_ description
328326
:type importers: :class:`collections.Callable`
329327
:returns: the compiled CSS string, or a pair of the compiled CSS string
330-
and the source map string if ``source_comments='map'``
328+
and the source map string if ``source_map_filename`` is set
331329
:rtype: :class:`str`, :class:`tuple`
332330
:raises sass.CompileError: when it fails for any reason
333331
(for example the given SASS has broken syntax)
@@ -480,6 +478,9 @@ def my_importer(path):
480478
.. versionadded:: 0.7.0
481479
Added ``custom_functions`` parameter.
482480
481+
.. versionadded:: 0.11.0
482+
``source_map_filename`` no longer implies ``source_comments``.
483+
483484
"""
484485
modes = set()
485486
for mode_name in MODES:
@@ -537,8 +538,6 @@ def my_importer(path):
537538
raise CompileError('source_map_filename is only available with '
538539
'filename= keyword argument since it has to be '
539540
'aware of it')
540-
if source_map_filename is not None:
541-
source_comments = True
542541
try:
543542
include_paths = kwargs.pop('include_paths') or b''
544543
except KeyError:

sassc.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
4949
.. versionadded:: 0.7.0
5050
51+
.. option:: --source-comments
52+
53+
Include debug info in output.
54+
55+
.. versionadded:: 0.11.0
56+
5157
.. option:: -v, --version
5258
5359
Prints the program version.
@@ -101,6 +107,10 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
101107
'-p', '--precision', action='store', type='int', default=5,
102108
help='Set the precision for numbers. [default: %default]'
103109
)
110+
parser.add_option(
111+
'--source-comments', action='store_true', default=False,
112+
help='Include debug info in output',
113+
)
104114
options, args = parser.parse_args(argv[1:])
105115
error = functools.partial(print,
106116
parser.get_prog_name() + ': error:',
@@ -134,6 +144,7 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
134144
css, source_map = compile(
135145
filename=filename,
136146
output_style=options.style,
147+
source_comments=options.source_comments,
137148
source_map_filename=source_map_filename,
138149
include_paths=options.include_paths,
139150
precision=options.precision
@@ -144,6 +155,7 @@ def main(argv=sys.argv, stdout=sys.stdout, stderr=sys.stderr):
144155
css = compile(
145156
filename=filename,
146157
output_style=options.style,
158+
source_comments=options.source_comments,
147159
include_paths=options.include_paths,
148160
precision=options.precision
149161
)

sasstests.py

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ def normalize_path(path):
4545
'''
4646

4747
A_EXPECTED_CSS_WITH_MAP = '''\
48-
/* line 6, SOURCE */
4948
body {
5049
background-color: green; }
51-
/* line 8, SOURCE */
5250
body a {
5351
color: blue; }
5452
@@ -60,8 +58,8 @@ def normalize_path(path):
6058
'sources': ['test/a.scss'],
6159
'names': [],
6260
'mappings': (
63-
';AAKA,AAAA,IAAI,CAAC;EAHH,gBAAgB,EAAE,KAAM,GAQzB;;EALD,AAEE,IAFE,'
64-
'CAEF,CAAC,CAAC;IACA,KAAK,EAAE,IAAK,GACb'
61+
'AAKA,AAAA,IAAI,CAAC;EAHH,gBAAgB,EAAE,KAAM,GAQzB;EALD,AAEE,'
62+
'IAFE,CAEF,CAAC,CAAC;IACA,KAAK,EAAE,IAAK,GACb'
6563
),
6664
}
6765

@@ -71,7 +69,6 @@ def normalize_path(path):
7169
'''
7270

7371
B_EXPECTED_CSS_WITH_MAP = '''\
74-
/* line 2, SOURCE */
7572
b i {
7673
font-size: 20px; }
7774
@@ -97,10 +94,8 @@ def normalize_path(path):
9794

9895
D_EXPECTED_CSS_WITH_MAP = '''\
9996
@charset "UTF-8";
100-
/* line 6, SOURCE */
10197
body {
10298
background-color: green; }
103-
/* line 8, SOURCE */
10499
body a {
105100
font: '나눔고딕', sans-serif; }
106101
@@ -446,10 +441,7 @@ def test_compile_source_map(self):
446441
source_map_filename='a.scss.css.map'
447442
)
448443
self.assertEqual(
449-
A_EXPECTED_CSS_WITH_MAP.replace(
450-
'SOURCE',
451-
normalize_path(os.path.abspath(filename))
452-
),
444+
A_EXPECTED_CSS_WITH_MAP,
453445
actual
454446
)
455447
self.assert_source_map_equal(A_EXPECTED_MAP, source_map)
@@ -612,7 +604,7 @@ def replace_source_path(s, name):
612604
'sources': ['../test/b.scss'],
613605
'names': [],
614606
'mappings': (
615-
';AAAA,AACE,CADD,CACC,CAAC,CAAC;EACA,SAAS,EAAE,IAAK,'
607+
'AAAA,AACE,CADD,CACC,CAAC,CAAC;EACA,SAAS,EAAE,IAAK,'
616608
'GACjB'
617609
),
618610
},
@@ -632,7 +624,7 @@ def replace_source_path(s, name):
632624
'sources': ['../test/d.scss'],
633625
'names': [],
634626
'mappings': (
635-
';;AAKA,AAAA,IAAI,CAAC;EAHH,gBAAgB,EAAE,KAAM,GAQzB;;'
627+
';AAKA,AAAA,IAAI,CAAC;EAHH,gBAAgB,EAAE,KAAM,GAQzB;'
636628
'EALD,AAEE,IAFE,CAEF,CAAC,CAAC;IACA,IAAI,EAAE,0BAA2B,'
637629
'GAClC'
638630
),
@@ -665,9 +657,8 @@ def test_wsgi_sass_middleware(self):
665657
self.assertEqual('text/plain', r.mimetype)
666658
r = client.get('/static/a.scss.css')
667659
self.assertEqual(200, r.status_code)
668-
src_path = normalize_path(os.path.join(src_dir, 'a.scss'))
669660
self.assert_bytes_equal(
670-
b(A_EXPECTED_CSS_WITH_MAP.replace('SOURCE', src_path)),
661+
b(A_EXPECTED_CSS_WITH_MAP),
671662
r.data
672663
)
673664
self.assertEqual('text/css', r.mimetype)
@@ -737,7 +728,7 @@ def setUp(self):
737728
self.err = StringIO()
738729

739730
def test_no_args(self):
740-
exit_code = sassc.main(['sassc', ], self.out, self.err)
731+
exit_code = sassc.main(['sassc'], self.out, self.err)
741732
self.assertEqual(2, exit_code)
742733
err = self.err.getvalue()
743734
assert err.strip().endswith('error: too few arguments'), \
@@ -803,12 +794,11 @@ def test_sassc_source_map_without_css_filename(self):
803794
self.assertEqual('', self.out.getvalue())
804795

805796
def test_sassc_sourcemap(self):
806-
tmp_dir = tempfile.mkdtemp()
807-
src_dir = os.path.join(tmp_dir, 'test')
808-
shutil.copytree('test', src_dir)
809-
src_filename = os.path.join(src_dir, 'a.scss')
810-
out_filename = os.path.join(tmp_dir, 'a.scss.css')
811-
try:
797+
with tempdir() as tmp_dir:
798+
src_dir = os.path.join(tmp_dir, 'test')
799+
shutil.copytree('test', src_dir)
800+
src_filename = os.path.join(src_dir, 'a.scss')
801+
out_filename = os.path.join(tmp_dir, 'a.scss.css')
812802
exit_code = sassc.main(
813803
['sassc', '-m', src_filename, out_filename],
814804
self.out, self.err
@@ -818,18 +808,14 @@ def test_sassc_sourcemap(self):
818808
self.assertEqual('', self.out.getvalue())
819809
with open(out_filename) as f:
820810
self.assertEqual(
821-
A_EXPECTED_CSS_WITH_MAP.replace(
822-
'SOURCE', normalize_path(src_filename)
823-
),
811+
A_EXPECTED_CSS_WITH_MAP,
824812
f.read().strip()
825813
)
826814
with open(out_filename + '.map') as f:
827815
self.assert_source_map_equal(
828816
dict(A_EXPECTED_MAP, sources=None),
829817
dict(json.load(f), sources=None)
830818
)
831-
finally:
832-
shutil.rmtree(tmp_dir)
833819

834820

835821
@contextlib.contextmanager
@@ -1432,3 +1418,8 @@ def test_stack_trace_formatting():
14321418
'>> a{☃\n'
14331419
' --^\n\n'
14341420
)
1421+
1422+
1423+
def test_source_comments():
1424+
out = sass.compile(string='a{color: red}', source_comments=True)
1425+
assert out == '/* line 1, stdin */\na {\n color: red; }\n'

0 commit comments

Comments
 (0)