sassc 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/ext/libsass/.gitignore +13 -6
- data/ext/libsass/Makefile +42 -26
- data/ext/libsass/Makefile.am +43 -30
- data/ext/libsass/Readme.md +4 -2
- data/ext/libsass/appveyor.yml +10 -14
- data/ext/libsass/ast.cpp +54 -44
- data/ext/libsass/ast.hpp +404 -236
- data/ext/libsass/ast_def_macros.hpp +5 -0
- data/ext/libsass/ast_factory.hpp +6 -3
- data/ext/libsass/ast_fwd_decl.hpp +12 -0
- data/ext/libsass/b64/encode.h +2 -2
- data/ext/libsass/backtrace.hpp +13 -17
- data/ext/libsass/base64vlq.hpp +4 -1
- data/ext/libsass/bind.cpp +12 -15
- data/ext/libsass/bind.hpp +6 -6
- data/ext/libsass/color_names.hpp +4 -1
- data/ext/libsass/configure.ac +7 -21
- data/ext/libsass/constants.cpp +6 -4
- data/ext/libsass/constants.hpp +10 -4
- data/ext/libsass/context.cpp +89 -58
- data/ext/libsass/context.hpp +28 -35
- data/ext/libsass/contextualize.cpp +20 -10
- data/ext/libsass/contextualize.hpp +8 -23
- data/ext/libsass/contrib/libsass.spec +66 -0
- data/ext/libsass/cssize.cpp +547 -0
- data/ext/libsass/cssize.hpp +82 -0
- data/ext/libsass/debug.hpp +3 -3
- data/ext/libsass/debugger.hpp +358 -0
- data/ext/libsass/emitter.cpp +255 -0
- data/ext/libsass/emitter.hpp +83 -0
- data/ext/libsass/environment.hpp +7 -3
- data/ext/libsass/error_handling.cpp +11 -14
- data/ext/libsass/error_handling.hpp +9 -7
- data/ext/libsass/eval.cpp +253 -161
- data/ext/libsass/eval.hpp +13 -13
- data/ext/libsass/expand.cpp +135 -64
- data/ext/libsass/expand.hpp +11 -13
- data/ext/libsass/extend.cpp +66 -20
- data/ext/libsass/extend.hpp +6 -11
- data/ext/libsass/file.cpp +31 -26
- data/ext/libsass/file.hpp +6 -1
- data/ext/libsass/functions.cpp +270 -287
- data/ext/libsass/functions.hpp +8 -11
- data/ext/libsass/inspect.cpp +385 -255
- data/ext/libsass/inspect.hpp +15 -26
- data/ext/libsass/kwd_arg_macros.hpp +5 -0
- data/ext/libsass/mapping.hpp +4 -3
- data/ext/libsass/memory_manager.hpp +5 -2
- data/ext/libsass/node.cpp +50 -50
- data/ext/libsass/node.hpp +26 -27
- data/ext/libsass/operation.hpp +15 -4
- data/ext/libsass/output.cpp +401 -0
- data/ext/libsass/output.hpp +56 -0
- data/ext/libsass/parser.cpp +573 -399
- data/ext/libsass/parser.hpp +122 -88
- data/ext/libsass/paths.hpp +7 -2
- data/ext/libsass/plugins.cpp +155 -0
- data/ext/libsass/plugins.hpp +56 -0
- data/ext/libsass/position.cpp +128 -0
- data/ext/libsass/position.hpp +108 -11
- data/ext/libsass/prelexer.cpp +184 -110
- data/ext/libsass/prelexer.hpp +131 -24
- data/ext/libsass/remove_placeholders.cpp +1 -1
- data/ext/libsass/remove_placeholders.hpp +6 -6
- data/ext/libsass/sass.cpp +3 -3
- data/ext/libsass/sass.h +12 -4
- data/ext/libsass/sass2scss.cpp +3 -2
- data/ext/libsass/sass2scss.h +5 -0
- data/ext/libsass/sass_context.cpp +136 -37
- data/ext/libsass/sass_context.h +19 -10
- data/ext/libsass/sass_functions.cpp +29 -2
- data/ext/libsass/sass_functions.h +8 -2
- data/ext/libsass/sass_interface.cpp +32 -23
- data/ext/libsass/sass_interface.h +9 -4
- data/ext/libsass/sass_util.cpp +19 -23
- data/ext/libsass/sass_util.hpp +28 -27
- data/ext/libsass/sass_values.cpp +6 -4
- data/ext/libsass/sass_values.h +3 -3
- data/ext/libsass/script/ci-build-libsass +13 -1
- data/ext/libsass/script/ci-report-coverage +2 -1
- data/ext/libsass/source_map.cpp +79 -28
- data/ext/libsass/source_map.hpp +35 -16
- data/ext/libsass/subset_map.hpp +6 -4
- data/ext/libsass/to_c.hpp +4 -4
- data/ext/libsass/to_string.cpp +13 -8
- data/ext/libsass/to_string.hpp +6 -4
- data/ext/libsass/units.cpp +2 -1
- data/ext/libsass/units.hpp +6 -1
- data/ext/libsass/utf8_string.cpp +0 -5
- data/ext/libsass/utf8_string.hpp +3 -2
- data/ext/libsass/util.cpp +461 -49
- data/ext/libsass/util.hpp +34 -13
- data/ext/libsass/version.sh +10 -0
- data/ext/libsass/win/libsass.filters +20 -11
- data/ext/libsass/win/libsass.vcxproj +11 -8
- data/lib/sassc/importer.rb +1 -8
- data/lib/sassc/native.rb +7 -0
- data/lib/sassc/native/native_context_api.rb +5 -5
- data/lib/sassc/version.rb +1 -1
- data/test/native_test.rb +1 -1
- metadata +14 -10
- data/ext/libsass/copy_c_str.cpp +0 -13
- data/ext/libsass/copy_c_str.hpp +0 -5
- data/ext/libsass/output_compressed.cpp +0 -401
- data/ext/libsass/output_compressed.hpp +0 -95
- data/ext/libsass/output_nested.cpp +0 -364
- data/ext/libsass/output_nested.hpp +0 -108
- data/ext/libsass/test-driver +0 -127
- data/ext/libsass/token.hpp +0 -32
data/ext/libsass/sass_util.hpp
CHANGED
@@ -1,24 +1,23 @@
|
|
1
|
+
#ifndef SASS_SASS_UTIL_H
|
2
|
+
#define SASS_SASS_UTIL_H
|
3
|
+
|
1
4
|
#include <deque>
|
2
5
|
#include <iostream>
|
3
6
|
|
4
|
-
#ifndef SASS_AST
|
5
7
|
#include "ast.hpp"
|
6
|
-
#endif
|
7
|
-
|
8
8
|
#include "node.hpp"
|
9
9
|
#include "debug.hpp"
|
10
10
|
|
11
|
-
|
12
11
|
namespace Sass {
|
13
12
|
|
14
|
-
|
13
|
+
|
15
14
|
using namespace std;
|
16
15
|
|
17
16
|
|
18
17
|
/*
|
19
18
|
This is for ports of functions in the Sass:Util module.
|
20
19
|
*/
|
21
|
-
|
20
|
+
|
22
21
|
|
23
22
|
/*
|
24
23
|
# Return a Node collection of all possible paths through the given Node collection of Node collections.
|
@@ -34,8 +33,8 @@ namespace Sass {
|
|
34
33
|
# # [2, 4, 5]]
|
35
34
|
*/
|
36
35
|
Node paths(const Node& arrs, Context& ctx);
|
37
|
-
|
38
|
-
|
36
|
+
|
37
|
+
|
39
38
|
/*
|
40
39
|
This class is a default implementation of a Node comparator that can be passed to the lcs function below.
|
41
40
|
It uses operator== for equality comparision. It then returns one if the Nodes are equal.
|
@@ -54,13 +53,13 @@ namespace Sass {
|
|
54
53
|
}
|
55
54
|
};
|
56
55
|
|
57
|
-
|
56
|
+
|
58
57
|
typedef vector<vector<int> > LCSTable;
|
59
|
-
|
60
|
-
|
58
|
+
|
59
|
+
|
61
60
|
/*
|
62
61
|
This is the equivalent of ruby's Sass::Util.lcs_backtrace.
|
63
|
-
|
62
|
+
|
64
63
|
# Computes a single longest common subsequence for arrays x and y.
|
65
64
|
# Algorithm from http://en.wikipedia.org/wiki/Longest_common_subsequence_problem#Reading_out_an_LCS
|
66
65
|
*/
|
@@ -72,7 +71,7 @@ namespace Sass {
|
|
72
71
|
DEBUG_PRINTLN(LCS, "RETURNING EMPTY")
|
73
72
|
return Node::createCollection();
|
74
73
|
}
|
75
|
-
|
74
|
+
|
76
75
|
NodeDeque& xChildren = *(x.collection());
|
77
76
|
NodeDeque& yChildren = *(y.collection());
|
78
77
|
|
@@ -83,20 +82,20 @@ namespace Sass {
|
|
83
82
|
result.collection()->push_back(compareOut);
|
84
83
|
return result;
|
85
84
|
}
|
86
|
-
|
85
|
+
|
87
86
|
if (c[i][j - 1] > c[i - 1][j]) {
|
88
87
|
DEBUG_PRINTLN(LCS, "RETURNING AFTER TABLE COMPARE")
|
89
88
|
return lcs_backtrace(c, x, y, i, j - 1, comparator);
|
90
89
|
}
|
91
|
-
|
90
|
+
|
92
91
|
DEBUG_PRINTLN(LCS, "FINAL RETURN")
|
93
92
|
return lcs_backtrace(c, x, y, i - 1, j, comparator);
|
94
93
|
}
|
95
|
-
|
94
|
+
|
96
95
|
|
97
96
|
/*
|
98
97
|
This is the equivalent of ruby's Sass::Util.lcs_table.
|
99
|
-
|
98
|
+
|
100
99
|
# Calculates the memoization table for the Least Common Subsequence algorithm.
|
101
100
|
# Algorithm from http://en.wikipedia.org/wiki/Longest_common_subsequence_problem#Computing_the_length_of_the_LCS
|
102
101
|
*/
|
@@ -108,7 +107,7 @@ namespace Sass {
|
|
108
107
|
NodeDeque& yChildren = *(y.collection());
|
109
108
|
|
110
109
|
LCSTable c(xChildren.size(), vector<int>(yChildren.size()));
|
111
|
-
|
110
|
+
|
112
111
|
// These shouldn't be necessary since the vector will be initialized to 0 already.
|
113
112
|
// x.size.times {|i| c[i][0] = 0}
|
114
113
|
// y.size.times {|j| c[0][j] = 0}
|
@@ -131,7 +130,7 @@ namespace Sass {
|
|
131
130
|
|
132
131
|
/*
|
133
132
|
This is the equivalent of ruby's Sass::Util.lcs.
|
134
|
-
|
133
|
+
|
135
134
|
# Computes a single longest common subsequence for `x` and `y`.
|
136
135
|
# If there are more than one longest common subsequences,
|
137
136
|
# the one returned is that which starts first in `x`.
|
@@ -150,14 +149,14 @@ namespace Sass {
|
|
150
149
|
Node newX = Node::createCollection();
|
151
150
|
newX.collection()->push_back(Node::createNil());
|
152
151
|
newX.plus(x);
|
153
|
-
|
152
|
+
|
154
153
|
Node newY = Node::createCollection();
|
155
154
|
newY.collection()->push_back(Node::createNil());
|
156
155
|
newY.plus(y);
|
157
|
-
|
156
|
+
|
158
157
|
LCSTable table;
|
159
158
|
lcs_table(newX, newY, comparator, table);
|
160
|
-
|
159
|
+
|
161
160
|
return lcs_backtrace(table, newX, newY, static_cast<int>(newX.collection()->size()) - 1, static_cast<int>(newY.collection()->size()) - 1, comparator);
|
162
161
|
}
|
163
162
|
|
@@ -167,7 +166,7 @@ namespace Sass {
|
|
167
166
|
Sass::Util.flatten requires the number of levels to flatten, while
|
168
167
|
[].flatten doesn't and will flatten the entire array. This function
|
169
168
|
supports both.
|
170
|
-
|
169
|
+
|
171
170
|
# Flattens the first `n` nested arrays. If n == -1, all arrays will be flattened
|
172
171
|
#
|
173
172
|
# @param arr [NodeCollection] The array to flatten
|
@@ -189,10 +188,10 @@ namespace Sass {
|
|
189
188
|
# @return [Array<[Object, Array]>] An array of pairs.
|
190
189
|
|
191
190
|
TODO: update @param and @return once I know what those are.
|
192
|
-
|
191
|
+
|
193
192
|
The following is the modified version of the ruby code that was more portable to C++. You
|
194
193
|
should be able to drop it into ruby 3.2.19 and get the same results from ruby sass.
|
195
|
-
|
194
|
+
|
196
195
|
def group_by_to_a(enum, &block)
|
197
196
|
order = {}
|
198
197
|
|
@@ -230,7 +229,7 @@ namespace Sass {
|
|
230
229
|
|
231
230
|
for (typename vector<EnumType>::iterator enumIter = enumeration.begin(), enumIterEnd = enumeration.end(); enumIter != enumIterEnd; enumIter++) {
|
232
231
|
EnumType& e = *enumIter;
|
233
|
-
|
232
|
+
|
234
233
|
KeyType key = keyFunc(e);
|
235
234
|
|
236
235
|
if (grouped.find(key) == grouped.end()) {
|
@@ -244,7 +243,7 @@ namespace Sass {
|
|
244
243
|
collection.push_back(e);
|
245
244
|
}
|
246
245
|
}
|
247
|
-
|
246
|
+
|
248
247
|
for (unsigned int index = 0; index < order.size(); index++) {
|
249
248
|
KeyType& key = order.at(index);
|
250
249
|
vector<EnumType>& values = grouped.at(key);
|
@@ -257,3 +256,5 @@ namespace Sass {
|
|
257
256
|
|
258
257
|
|
259
258
|
}
|
259
|
+
|
260
|
+
#endif
|
data/ext/libsass/sass_values.cpp
CHANGED
@@ -6,10 +6,12 @@
|
|
6
6
|
|
7
7
|
#include <cstdlib>
|
8
8
|
#include <cstring>
|
9
|
+
#include "util.hpp"
|
9
10
|
#include "sass_values.h"
|
10
11
|
|
11
12
|
extern "C" {
|
12
13
|
using namespace std;
|
14
|
+
using namespace Sass;
|
13
15
|
|
14
16
|
struct Sass_Unknown {
|
15
17
|
enum Sass_Tag tag;
|
@@ -164,7 +166,7 @@ extern "C" {
|
|
164
166
|
if (v == 0) return 0;
|
165
167
|
v->number.tag = SASS_NUMBER;
|
166
168
|
v->number.value = val;
|
167
|
-
v->number.unit =
|
169
|
+
v->number.unit = unit ? sass_strdup(unit) : 0;
|
168
170
|
if (v->number.unit == 0) { free(v); return 0; }
|
169
171
|
return v;
|
170
172
|
}
|
@@ -186,7 +188,7 @@ extern "C" {
|
|
186
188
|
Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
|
187
189
|
if (v == 0) return 0;
|
188
190
|
v->string.tag = SASS_STRING;
|
189
|
-
v->string.value =
|
191
|
+
v->string.value = val ? sass_strdup(val) : 0;
|
190
192
|
if (v->string.value == 0) { free(v); return 0; }
|
191
193
|
return v;
|
192
194
|
}
|
@@ -227,7 +229,7 @@ extern "C" {
|
|
227
229
|
Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
|
228
230
|
if (v == 0) return 0;
|
229
231
|
v->error.tag = SASS_ERROR;
|
230
|
-
v->error.message =
|
232
|
+
v->error.message = msg ? sass_strdup(msg) : 0;
|
231
233
|
if (v->error.message == 0) { free(v); return 0; }
|
232
234
|
return v;
|
233
235
|
}
|
@@ -237,7 +239,7 @@ extern "C" {
|
|
237
239
|
Sass_Value* v = (Sass_Value*) calloc(1, sizeof(Sass_Value));
|
238
240
|
if (v == 0) return 0;
|
239
241
|
v->warning.tag = SASS_WARNING;
|
240
|
-
v->warning.message =
|
242
|
+
v->warning.message = msg ? sass_strdup(msg) : 0;
|
241
243
|
if (v->warning.message == 0) { free(v); return 0; }
|
242
244
|
return v;
|
243
245
|
}
|
data/ext/libsass/sass_values.h
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
#ifndef
|
2
|
-
#define
|
1
|
+
#ifndef SASS_C_VALUES_H
|
2
|
+
#define SASS_C_VALUES_H
|
3
3
|
|
4
4
|
#include <stddef.h>
|
5
5
|
#include <stdbool.h>
|
@@ -83,7 +83,7 @@ ADDAPI void ADDCALL sass_list_set_value (union Sass_Value* v, size_t i, union Sa
|
|
83
83
|
|
84
84
|
// Getter for the number of items in map
|
85
85
|
ADDAPI size_t ADDCALL sass_map_get_length (const union Sass_Value* v);
|
86
|
-
// Getters and setters for
|
86
|
+
// Getters and setters for Sass_Map keys and values
|
87
87
|
ADDAPI union Sass_Value* ADDCALL sass_map_get_key (const union Sass_Value* v, size_t i);
|
88
88
|
ADDAPI void ADDCALL sass_map_set_key (union Sass_Value* v, size_t i, union Sass_Value*);
|
89
89
|
ADDAPI union Sass_Value* ADDCALL sass_map_get_value (const union Sass_Value* v, size_t i);
|
@@ -30,13 +30,18 @@ else
|
|
30
30
|
MAKE_TARGET="shared"
|
31
31
|
fi
|
32
32
|
|
33
|
-
|
33
|
+
if [ "$(expr substr $(uname -s) 1 10)" == "MINGW32_NT" ]; then
|
34
|
+
MAKE_OPTS="$MAKE_OPTS -j1 V=1"
|
35
|
+
else
|
36
|
+
MAKE_OPTS="$MAKE_OPTS -j3 V=1"
|
37
|
+
fi
|
34
38
|
|
35
39
|
if [ "x$AUTOTOOLS" == "xyes" ]; then
|
36
40
|
|
37
41
|
echo -en 'travis_fold:start:configure\r'
|
38
42
|
autoreconf --force --install
|
39
43
|
./configure --enable-tests $COVERAGE_OPT \
|
44
|
+
--prefix=build \
|
40
45
|
--disable-silent-rules \
|
41
46
|
--with-sassc-dir=$SASS_SASSC_PATH \
|
42
47
|
--with-sass-spec-dir=$SASS_SPEC_PATH \
|
@@ -44,8 +49,15 @@ if [ "x$AUTOTOOLS" == "xyes" ]; then
|
|
44
49
|
${SHARED_OPT}
|
45
50
|
echo -en 'travis_fold:end:configure\r'
|
46
51
|
|
52
|
+
make clean
|
53
|
+
|
47
54
|
make $MAKE_OPTS install
|
48
55
|
|
56
|
+
if [ -d build/lib ]; then
|
57
|
+
mkdir -p lib
|
58
|
+
cp -a build/lib/* lib/
|
59
|
+
fi
|
60
|
+
|
49
61
|
else
|
50
62
|
|
51
63
|
make clean
|
@@ -9,7 +9,8 @@ if [ "x$COVERAGE" = "xyes" ]; then
|
|
9
9
|
--exclude cencode.c --exclude b64
|
10
10
|
--exclude utf8 --exclude utf8_string.hpp
|
11
11
|
--exclude utf8.h --exclude utf8_string.cpp
|
12
|
-
--exclude
|
12
|
+
--exclude sass2scss.h --exclude sass2scss.cpp
|
13
|
+
--exclude test --exclude posix"
|
13
14
|
# debug via gcovr
|
14
15
|
gcov -v
|
15
16
|
gcovr -r .
|
data/ext/libsass/source_map.cpp
CHANGED
@@ -1,18 +1,19 @@
|
|
1
|
-
#include "source_map.hpp"
|
2
|
-
#include "json.hpp"
|
3
|
-
|
4
|
-
#ifndef SASS_CONTEXT
|
5
|
-
#include "context.hpp"
|
6
|
-
#endif
|
7
|
-
|
8
1
|
#include <string>
|
9
2
|
#include <sstream>
|
3
|
+
#include <iostream>
|
10
4
|
#include <cstddef>
|
11
5
|
#include <iomanip>
|
12
6
|
|
7
|
+
#include "ast.hpp"
|
8
|
+
#include "json.hpp"
|
9
|
+
#include "context.hpp"
|
10
|
+
#include "position.hpp"
|
11
|
+
#include "source_map.hpp"
|
12
|
+
|
13
13
|
namespace Sass {
|
14
14
|
using std::ptrdiff_t;
|
15
|
-
SourceMap::SourceMap(
|
15
|
+
SourceMap::SourceMap() : current_position(0, 0, 0), file("stdin") { }
|
16
|
+
SourceMap::SourceMap(const string& file) : current_position(0, 0, 0), file(file) { }
|
16
17
|
|
17
18
|
string SourceMap::generate_source_map(Context &ctx) {
|
18
19
|
|
@@ -20,10 +21,16 @@ namespace Sass {
|
|
20
21
|
const vector<string> includes = ctx.include_links;
|
21
22
|
const vector<const char*> sources = ctx.sources;
|
22
23
|
|
23
|
-
JsonNode
|
24
|
+
JsonNode* json_srcmap = json_mkobject();
|
24
25
|
|
25
26
|
json_append_member(json_srcmap, "version", json_mknumber(3));
|
26
27
|
|
28
|
+
// pass-through sourceRoot option
|
29
|
+
if (!ctx.source_map_root.empty()) {
|
30
|
+
JsonNode* root = json_mkstring(ctx.source_map_root.c_str());
|
31
|
+
json_append_member(json_srcmap, "sourceRoot", root);
|
32
|
+
}
|
33
|
+
|
27
34
|
const char *include = file.c_str();
|
28
35
|
JsonNode *json_include = json_mkstring(include);
|
29
36
|
json_append_member(json_srcmap, "file", json_include);
|
@@ -71,11 +78,11 @@ namespace Sass {
|
|
71
78
|
size_t previous_original_column = 0;
|
72
79
|
size_t previous_original_file = 0;
|
73
80
|
for (size_t i = 0; i < mappings.size(); ++i) {
|
74
|
-
const size_t generated_line = mappings[i].generated_position.line
|
75
|
-
const size_t generated_column = mappings[i].generated_position.column
|
76
|
-
const size_t original_line = mappings[i].original_position.line
|
77
|
-
const size_t original_column = mappings[i].original_position.column
|
78
|
-
const size_t original_file = mappings[i].original_position.file
|
81
|
+
const size_t generated_line = mappings[i].generated_position.line;
|
82
|
+
const size_t generated_column = mappings[i].generated_position.column;
|
83
|
+
const size_t original_line = mappings[i].original_position.line;
|
84
|
+
const size_t original_column = mappings[i].original_position.column;
|
85
|
+
const size_t original_file = mappings[i].original_position.file;
|
79
86
|
|
80
87
|
if (generated_line != previous_generated_line) {
|
81
88
|
previous_generated_column = 0;
|
@@ -105,29 +112,73 @@ namespace Sass {
|
|
105
112
|
return result;
|
106
113
|
}
|
107
114
|
|
108
|
-
void SourceMap::
|
115
|
+
void SourceMap::prepend(const OutputBuffer& out)
|
109
116
|
{
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
117
|
+
Offset size(out.smap.current_position);
|
118
|
+
for (Mapping mapping : out.smap.mappings) {
|
119
|
+
if (mapping.generated_position.line > size.line) {
|
120
|
+
throw(runtime_error("prepend sourcemap has illegal line"));
|
121
|
+
}
|
122
|
+
if (mapping.generated_position.line == size.line) {
|
123
|
+
if (mapping.generated_position.column > size.column) {
|
124
|
+
throw(runtime_error("prepend sourcemap has illegal column"));
|
125
|
+
}
|
126
|
+
}
|
114
127
|
}
|
128
|
+
// will adjust the offset
|
129
|
+
prepend(Offset(out.buffer));
|
130
|
+
// now add the new mappings
|
131
|
+
VECTOR_UNSHIFT(mappings, out.smap.mappings);
|
115
132
|
}
|
116
133
|
|
117
|
-
void SourceMap::
|
134
|
+
void SourceMap::append(const OutputBuffer& out)
|
118
135
|
{
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
136
|
+
append(Offset(out.buffer));
|
137
|
+
}
|
138
|
+
|
139
|
+
void SourceMap::prepend(const Offset& offset)
|
140
|
+
{
|
141
|
+
if (offset.line != 0 || offset.column != 0) {
|
142
|
+
for (Mapping& mapping : mappings) {
|
143
|
+
// move stuff on the first old line
|
144
|
+
if (mapping.generated_position.line == 0) {
|
145
|
+
mapping.generated_position.column += offset.column;
|
146
|
+
}
|
147
|
+
// make place for the new lines
|
148
|
+
mapping.generated_position.line += offset.line;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
if (current_position.line == 0) {
|
152
|
+
current_position.column += offset.column;
|
125
153
|
}
|
154
|
+
current_position.line += offset.line;
|
126
155
|
}
|
127
156
|
|
128
|
-
void SourceMap::
|
157
|
+
void SourceMap::append(const Offset& offset)
|
129
158
|
{
|
130
|
-
|
159
|
+
current_position += offset;
|
160
|
+
}
|
161
|
+
|
162
|
+
void SourceMap::add_open_mapping(AST_Node* node)
|
163
|
+
{
|
164
|
+
mappings.push_back(Mapping(node->pstate(), current_position));
|
165
|
+
}
|
166
|
+
|
167
|
+
void SourceMap::add_close_mapping(AST_Node* node)
|
168
|
+
{
|
169
|
+
mappings.push_back(Mapping(node->pstate() + node->pstate().offset, current_position));
|
170
|
+
}
|
171
|
+
|
172
|
+
ParserState SourceMap::remap(const ParserState& pstate) {
|
173
|
+
for (size_t i = 0; i < mappings.size(); ++i) {
|
174
|
+
if (
|
175
|
+
mappings[i].generated_position.file == pstate.file &&
|
176
|
+
mappings[i].generated_position.line == pstate.line &&
|
177
|
+
mappings[i].generated_position.column == pstate.column
|
178
|
+
) return ParserState(pstate.path, mappings[i].original_position, pstate.offset);
|
179
|
+
}
|
180
|
+
return ParserState(pstate.path, Position(-1, -1, -1), Offset(0, 0));
|
181
|
+
|
131
182
|
}
|
132
183
|
|
133
184
|
}
|
data/ext/libsass/source_map.hpp
CHANGED
@@ -1,37 +1,41 @@
|
|
1
|
-
#
|
1
|
+
#ifndef SASS_SOURCE_MAP_H
|
2
|
+
#define SASS_SOURCE_MAP_H
|
2
3
|
|
3
4
|
#include <vector>
|
4
5
|
|
5
|
-
#
|
6
|
-
#include "mapping.hpp"
|
7
|
-
#endif
|
8
|
-
|
9
|
-
#ifndef SASS_AST
|
10
|
-
#include "ast.hpp"
|
11
|
-
#endif
|
12
|
-
|
13
|
-
#ifndef SASSS_BASE64VLQ
|
6
|
+
#include "ast_fwd_decl.hpp"
|
14
7
|
#include "base64vlq.hpp"
|
15
|
-
#
|
16
|
-
|
8
|
+
#include "position.hpp"
|
9
|
+
#include "mapping.hpp"
|
17
10
|
|
11
|
+
#define VECTOR_PUSH(vec, ins) vec.insert(vec.end(), ins.begin(), ins.end())
|
12
|
+
#define VECTOR_UNSHIFT(vec, ins) vec.insert(vec.begin(), ins.begin(), ins.end())
|
18
13
|
|
19
14
|
namespace Sass {
|
20
15
|
using std::vector;
|
21
16
|
|
22
|
-
|
17
|
+
class Context;
|
18
|
+
class OutputBuffer;
|
23
19
|
|
24
20
|
class SourceMap {
|
25
21
|
|
26
22
|
public:
|
27
23
|
vector<size_t> source_index;
|
24
|
+
SourceMap();
|
28
25
|
SourceMap(const string& file);
|
29
26
|
|
30
|
-
void
|
31
|
-
|
32
|
-
|
27
|
+
void setFile(const string& str) {
|
28
|
+
file = str;
|
29
|
+
}
|
30
|
+
void append(const Offset& offset);
|
31
|
+
void prepend(const Offset& offset);
|
32
|
+
void append(const OutputBuffer& out);
|
33
|
+
void prepend(const OutputBuffer& out);
|
34
|
+
void add_open_mapping(AST_Node* node);
|
35
|
+
void add_close_mapping(AST_Node* node);
|
33
36
|
|
34
37
|
string generate_source_map(Context &ctx);
|
38
|
+
ParserState remap(const ParserState& pstate);
|
35
39
|
|
36
40
|
private:
|
37
41
|
|
@@ -39,8 +43,23 @@ namespace Sass {
|
|
39
43
|
|
40
44
|
vector<Mapping> mappings;
|
41
45
|
Position current_position;
|
46
|
+
public:
|
42
47
|
string file;
|
48
|
+
private:
|
43
49
|
Base64VLQ base64vlq;
|
44
50
|
};
|
45
51
|
|
52
|
+
class OutputBuffer {
|
53
|
+
public:
|
54
|
+
OutputBuffer(void)
|
55
|
+
: buffer(""),
|
56
|
+
smap()
|
57
|
+
{ }
|
58
|
+
public:
|
59
|
+
string buffer;
|
60
|
+
SourceMap smap;
|
61
|
+
};
|
62
|
+
|
46
63
|
}
|
64
|
+
|
65
|
+
#endif
|