Skip to content

Commit b8281a2

Browse files
authored
Merge pull request #216 from mgreter/feature/sourcemap-options
Implement inline and auto sourcemap options
2 parents eb83991 + 780cd67 commit b8281a2

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

sassc.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ void print_usage(char* argv0) {
212212
printf(" --line-comments\n");
213213
printf(" -I, --load-path PATH Set Sass import path.\n");
214214
printf(" -P, --plugin-path PATH Set path to autoload plugins.\n");
215-
printf(" -m, --sourcemap Emit source map.\n");
215+
printf(" -m, --sourcemap[=TYPE] Emit source map (auto or inline).\n");
216216
printf(" -M, --omit-map-comment Omits the source map url comment.\n");
217217
printf(" -p, --precision Set the precision for numbers.\n");
218218
printf(" -a, --sass Treat input as indented syntax.\n");
@@ -246,6 +246,7 @@ int main(int argc, char** argv) {
246246

247247
char *outfile = 0;
248248
int from_stdin = 0;
249+
bool auto_source_map = false;
249250
bool generate_source_map = false;
250251
struct Sass_Options* options = sass_make_options();
251252
sass_option_set_output_style(options, SASS_STYLE_NESTED);
@@ -262,15 +263,15 @@ int main(int argc, char** argv) {
262263
{ "style", required_argument, 0, 't' },
263264
{ "line-numbers", no_argument, 0, 'l' },
264265
{ "line-comments", no_argument, 0, 'l' },
265-
{ "sourcemap", no_argument, 0, 'm' },
266+
{ "sourcemap", optional_argument, 0, 'm' },
266267
{ "omit-map-comment", no_argument, 0, 'M' },
267268
{ "precision", required_argument, 0, 'p' },
268269
{ "version", no_argument, 0, 'v' },
269270
{ "sass", no_argument, 0, 'a' },
270271
{ "help", no_argument, 0, 'h' },
271272
{ NULL, 0, NULL, 0}
272273
};
273-
while ((c = getopt_long(argc, argv, "vhslmMap:t:I:P:", long_options, &long_index)) != -1) {
274+
while ((c = getopt_long(argc, argv, "vhsl:mMap:t:I:P:", long_options, &long_index)) != -1) {
274275
switch (c) {
275276
case 's':
276277
from_stdin = 1;
@@ -301,6 +302,20 @@ int main(int argc, char** argv) {
301302
sass_option_set_source_comments(options, true);
302303
break;
303304
case 'm':
305+
if (optarg) { // optional argument
306+
if (strcmp(optarg, "auto") == 0) {
307+
auto_source_map = true;
308+
} else if (strcmp(optarg, "inline") == 0) {
309+
sass_option_set_source_map_embed(options, true);
310+
} else {
311+
fprintf(stderr, "Invalid argument for -m flag: '%s'. Allowed arguments are:", optarg);
312+
fprintf(stderr, " %s", "auto inline");
313+
fprintf(stderr, "\n");
314+
invalid_usage(argv[0]);
315+
}
316+
} else {
317+
auto_source_map = true;
318+
}
304319
generate_source_map = true;
305320
break;
306321
case 'M':
@@ -349,6 +364,8 @@ int main(int argc, char** argv) {
349364
strcpy(source_map_file, outfile);
350365
strcat(source_map_file, extension);
351366
sass_option_set_source_map_file(options, source_map_file);
367+
} else if (auto_source_map) {
368+
sass_option_set_source_map_embed(options, true);
352369
}
353370
result = compile_file(options, argv[optind], outfile);
354371
} else {

0 commit comments

Comments
 (0)