Skip to content

Commit

Permalink
Make sourcemaps fully unicode aware
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Jan 15, 2018
1 parent a3081e7 commit fbe7e31
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/emitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ namespace Sass {
// prepend some text or token to the buffer
void Emitter::prepend_string(const std::string& text)
{
wbuf.smap.prepend(Offset(text));
// do not adjust mappings for utf8 bom
if (text.compare("\xEF\xBB\xBF") != 0) {
wbuf.smap.prepend(Offset(text));
}
wbuf.buffer = text + wbuf.buffer;
}

Expand Down
16 changes: 14 additions & 2 deletions src/position.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "sass.hpp"
#include "position.hpp"
#include <bitset>

namespace Sass {

Expand Down Expand Up @@ -47,9 +48,20 @@ namespace Sass {
// start new line
column = 0;
} else {
++ column;
std::bitset<8> chr(*begin);
// skip over 10xxxxxx
// continuation bytes
if (chr[7] == 1) {
if (chr[6] != 0) {
column += 1;
}
}
// ascii char
else {
column += 1;
}
}
++begin;
++ begin;
}
return *this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/source_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace Sass {
}
}
}
// will adjust the offset
// adjust the buffer offset
prepend(Offset(out.buffer));
// now add the new mappings
VECTOR_UNSHIFT(mappings, out.smap.mappings);
Expand Down

0 comments on commit fbe7e31

Please sign in to comment.