Skip to content

Commit 0ff2474

Browse files
authored
Merge pull request #2220 from mgreter/bugfix/issue-2195
Implement source_map_file_urls option
2 parents 967f297 + bf7d830 commit 0ff2474

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-2
lines changed

docs/api-context-internal.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ struct Sass_Options {
3333
// embed include contents in maps
3434
bool source_map_contents;
3535

36+
// create file urls for sources
37+
bool source_map_file_urls;
38+
3639
// Disable sourceMappingUrl in css output
3740
bool omit_source_map_url;
3841

docs/api-context.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ bool source_map_embed;
3434
bool source_map_contents;
3535
```
3636
```C
37+
// create file urls for sources
38+
bool source_map_file_urls;
39+
```
40+
```C
3741
// Disable sourceMappingUrl in css output
3842
bool omit_source_map_url;
3943
```
@@ -225,6 +229,7 @@ enum Sass_Output_Style sass_option_get_output_style (struct Sass_Options* option
225229
bool sass_option_get_source_comments (struct Sass_Options* options);
226230
bool sass_option_get_source_map_embed (struct Sass_Options* options);
227231
bool sass_option_get_source_map_contents (struct Sass_Options* options);
232+
bool sass_option_get_source_map_file_urls (struct Sass_Options* options);
228233
bool sass_option_get_omit_source_map_url (struct Sass_Options* options);
229234
bool sass_option_get_is_indented_syntax_src (struct Sass_Options* options);
230235
const char* sass_option_get_indent (struct Sass_Options* options);
@@ -244,6 +249,7 @@ void sass_option_set_output_style (struct Sass_Options* options, enum Sass_Outpu
244249
void sass_option_set_source_comments (struct Sass_Options* options, bool source_comments);
245250
void sass_option_set_source_map_embed (struct Sass_Options* options, bool source_map_embed);
246251
void sass_option_set_source_map_contents (struct Sass_Options* options, bool source_map_contents);
252+
void sass_option_set_source_map_file_urls (struct Sass_Options* options, bool source_map_file_urls);
247253
void sass_option_set_omit_source_map_url (struct Sass_Options* options, bool omit_source_map_url);
248254
void sass_option_set_is_indented_syntax_src (struct Sass_Options* options, bool is_indented_syntax_src);
249255
void sass_option_set_indent (struct Sass_Options* options, const char* indent);

include/sass/context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ ADDAPI enum Sass_Output_Style ADDCALL sass_option_get_output_style (struct Sass_
7474
ADDAPI bool ADDCALL sass_option_get_source_comments (struct Sass_Options* options);
7575
ADDAPI bool ADDCALL sass_option_get_source_map_embed (struct Sass_Options* options);
7676
ADDAPI bool ADDCALL sass_option_get_source_map_contents (struct Sass_Options* options);
77+
ADDAPI bool ADDCALL sass_option_get_source_map_file_urls (struct Sass_Options* options);
7778
ADDAPI bool ADDCALL sass_option_get_omit_source_map_url (struct Sass_Options* options);
7879
ADDAPI bool ADDCALL sass_option_get_is_indented_syntax_src (struct Sass_Options* options);
7980
ADDAPI const char* ADDCALL sass_option_get_indent (struct Sass_Options* options);
@@ -94,6 +95,7 @@ ADDAPI void ADDCALL sass_option_set_output_style (struct Sass_Options* options,
9495
ADDAPI void ADDCALL sass_option_set_source_comments (struct Sass_Options* options, bool source_comments);
9596
ADDAPI void ADDCALL sass_option_set_source_map_embed (struct Sass_Options* options, bool source_map_embed);
9697
ADDAPI void ADDCALL sass_option_set_source_map_contents (struct Sass_Options* options, bool source_map_contents);
98+
ADDAPI void ADDCALL sass_option_set_source_map_file_urls (struct Sass_Options* options, bool source_map_file_urls);
9799
ADDAPI void ADDCALL sass_option_set_omit_source_map_url (struct Sass_Options* options, bool omit_source_map_url);
98100
ADDAPI void ADDCALL sass_option_set_is_indented_syntax_src (struct Sass_Options* options, bool is_indented_syntax_src);
99101
ADDAPI void ADDCALL sass_option_set_indent (struct Sass_Options* options, const char* indent);

src/sass_context.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,7 @@ extern "C" {
667667
IMPLEMENT_SASS_OPTION_ACCESSOR(bool, source_comments);
668668
IMPLEMENT_SASS_OPTION_ACCESSOR(bool, source_map_embed);
669669
IMPLEMENT_SASS_OPTION_ACCESSOR(bool, source_map_contents);
670+
IMPLEMENT_SASS_OPTION_ACCESSOR(bool, source_map_file_urls);
670671
IMPLEMENT_SASS_OPTION_ACCESSOR(bool, omit_source_map_url);
671672
IMPLEMENT_SASS_OPTION_ACCESSOR(bool, is_indented_syntax_src);
672673
IMPLEMENT_SASS_OPTION_ACCESSOR(Sass_Function_List, c_functions);

src/sass_context.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ struct Sass_Options : Sass_Output_Options {
1515
// embed include contents in maps
1616
bool source_map_contents;
1717

18+
// create file urls for sources
19+
bool source_map_file_urls;
20+
1821
// Disable sourceMappingUrl in css output
1922
bool omit_source_map_url;
2023

src/source_map.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,20 @@ namespace Sass {
3737

3838
JsonNode *json_includes = json_mkarray();
3939
for (size_t i = 0; i < source_index.size(); ++i) {
40-
const char *include = links[source_index[i]].c_str();
41-
JsonNode *json_include = json_mkstring(include);
40+
std::string include(links[source_index[i]]);
41+
if (ctx.c_options.source_map_file_urls) {
42+
include = File::rel2abs(include);
43+
// check for windows abs path
44+
if (include[0] == '/') {
45+
// ends up with three slashes
46+
include = "file://" + include;
47+
} else {
48+
// needs an additional slash
49+
include = "file:///" + include;
50+
}
51+
}
52+
const char* inc = include.c_str();
53+
JsonNode *json_include = json_mkstring(inc);
4254
json_append_element(json_includes, json_include);
4355
}
4456
json_append_member(json_srcmap, "sources", json_includes);

0 commit comments

Comments
 (0)