Skip to content

Commit 12e36dc

Browse files
committed
Re-order the sourcemap writing to match spec
The spec https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6f AH0KY0k/edit?pli=1# outlines the order of the elements as: Line 1: The entire file is a single JSON object Line 2: File version (always the first entry in the object) and must be a positive integer. Line 3: An optional name of the generated code that this source map is associated with. Line 4: An optional source root, useful for relocating source files on a server or removing repeated values in the “sources” entry. This value is prepended to the individual entries in the “source” field. Line 5: A list of original sources used by the “mappings” entry. Line 6: An optional list of source content, useful when the “source” can’t be hosted. The contents are listed in the same order as the sources in line 5. “null” may be used if some original sources should be retrieved by name. Line 7: A list of symbol names used by the “mappings” entry. Line 8: A string with the encoded mapping data.
1 parent efa6496 commit 12e36dc

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/source_map.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ namespace Sass {
2525

2626
json_append_member(json_srcmap, "version", json_mknumber(3));
2727

28+
const char *include = file.c_str();
29+
JsonNode *json_include = json_mkstring(include);
30+
json_append_member(json_srcmap, "file", json_include);
31+
2832
// pass-through sourceRoot option
2933
if (!ctx.source_map_root.empty()) {
3034
JsonNode* root = json_mkstring(ctx.source_map_root.c_str());
3135
json_append_member(json_srcmap, "sourceRoot", root);
3236
}
3337

34-
const char *include = file.c_str();
35-
JsonNode *json_include = json_mkstring(include);
36-
json_append_member(json_srcmap, "file", json_include);
37-
3838
JsonNode *json_includes = json_mkarray();
3939
for (size_t i = 0; i < source_index.size(); ++i) {
4040
const char *include = links[source_index[i]].c_str();
@@ -54,15 +54,15 @@ namespace Sass {
5454
json_append_member(json_srcmap, "sourcesContent", json_contents);
5555
}
5656

57-
std::string mappings = serialize_mappings();
58-
JsonNode *json_mappings = json_mkstring(mappings.c_str());
59-
json_append_member(json_srcmap, "mappings", json_mappings);
60-
6157
JsonNode *json_names = json_mkarray();
6258
// so far we have no implementation for names
6359
// no problem as we do not alter any identifiers
6460
json_append_member(json_srcmap, "names", json_names);
6561

62+
std::string mappings = serialize_mappings();
63+
JsonNode *json_mappings = json_mkstring(mappings.c_str());
64+
json_append_member(json_srcmap, "mappings", json_mappings);
65+
6666
char *str = json_stringify(json_srcmap, "\t");
6767
std::string result = std::string(str);
6868
free(str);

0 commit comments

Comments
 (0)