sassc 2.2.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +18 -0
- data/Rakefile +1 -3
- data/ext/extconf.rb +13 -5
- data/ext/libsass/VERSION +1 -1
- data/ext/libsass/include/sass/base.h +2 -1
- data/ext/libsass/include/sass/context.h +4 -0
- data/ext/libsass/src/MurmurHash2.hpp +91 -0
- data/ext/libsass/src/ast.cpp +158 -168
- data/ext/libsass/src/ast.hpp +389 -230
- data/ext/libsass/src/ast_def_macros.hpp +18 -10
- data/ext/libsass/src/ast_fwd_decl.cpp +4 -3
- data/ext/libsass/src/ast_fwd_decl.hpp +98 -165
- data/ext/libsass/src/ast_helpers.hpp +292 -0
- data/ext/libsass/src/ast_sel_cmp.cpp +219 -732
- data/ext/libsass/src/ast_sel_super.cpp +539 -0
- data/ext/libsass/src/ast_sel_unify.cpp +207 -212
- data/ext/libsass/src/ast_sel_weave.cpp +616 -0
- data/ext/libsass/src/ast_selectors.cpp +594 -1026
- data/ext/libsass/src/ast_selectors.hpp +339 -385
- data/ext/libsass/src/ast_supports.cpp +36 -52
- data/ext/libsass/src/ast_supports.hpp +29 -29
- data/ext/libsass/src/ast_values.cpp +271 -84
- data/ext/libsass/src/ast_values.hpp +116 -107
- data/ext/libsass/src/backtrace.cpp +9 -9
- data/ext/libsass/src/backtrace.hpp +5 -5
- data/ext/libsass/src/base64vlq.cpp +2 -2
- data/ext/libsass/src/base64vlq.hpp +1 -1
- data/ext/libsass/src/bind.cpp +18 -18
- data/ext/libsass/src/bind.hpp +1 -1
- data/ext/libsass/src/c2ast.cpp +3 -3
- data/ext/libsass/src/c2ast.hpp +1 -1
- data/ext/libsass/src/cencode.c +4 -6
- data/ext/libsass/src/check_nesting.cpp +40 -41
- data/ext/libsass/src/check_nesting.hpp +6 -2
- data/ext/libsass/src/color_maps.cpp +14 -13
- data/ext/libsass/src/color_maps.hpp +1 -9
- data/ext/libsass/src/constants.cpp +5 -0
- data/ext/libsass/src/constants.hpp +6 -0
- data/ext/libsass/src/context.cpp +92 -119
- data/ext/libsass/src/context.hpp +41 -53
- data/ext/libsass/src/cssize.cpp +66 -149
- data/ext/libsass/src/cssize.hpp +17 -23
- data/ext/libsass/src/dart_helpers.hpp +199 -0
- data/ext/libsass/src/debugger.hpp +451 -295
- data/ext/libsass/src/emitter.cpp +15 -16
- data/ext/libsass/src/emitter.hpp +10 -12
- data/ext/libsass/src/environment.cpp +27 -27
- data/ext/libsass/src/environment.hpp +29 -24
- data/ext/libsass/src/error_handling.cpp +62 -41
- data/ext/libsass/src/error_handling.hpp +61 -51
- data/ext/libsass/src/eval.cpp +167 -281
- data/ext/libsass/src/eval.hpp +27 -29
- data/ext/libsass/src/eval_selectors.cpp +75 -0
- data/ext/libsass/src/expand.cpp +275 -222
- data/ext/libsass/src/expand.hpp +36 -16
- data/ext/libsass/src/extender.cpp +1188 -0
- data/ext/libsass/src/extender.hpp +399 -0
- data/ext/libsass/src/extension.cpp +43 -0
- data/ext/libsass/src/extension.hpp +89 -0
- data/ext/libsass/src/file.cpp +81 -72
- data/ext/libsass/src/file.hpp +28 -37
- data/ext/libsass/src/fn_colors.cpp +20 -18
- data/ext/libsass/src/fn_lists.cpp +30 -29
- data/ext/libsass/src/fn_maps.cpp +3 -3
- data/ext/libsass/src/fn_miscs.cpp +34 -46
- data/ext/libsass/src/fn_numbers.cpp +20 -13
- data/ext/libsass/src/fn_selectors.cpp +98 -128
- data/ext/libsass/src/fn_strings.cpp +47 -33
- data/ext/libsass/src/fn_utils.cpp +31 -29
- data/ext/libsass/src/fn_utils.hpp +17 -11
- data/ext/libsass/src/inspect.cpp +186 -148
- data/ext/libsass/src/inspect.hpp +31 -29
- data/ext/libsass/src/lexer.cpp +20 -82
- data/ext/libsass/src/lexer.hpp +5 -16
- data/ext/libsass/src/listize.cpp +23 -37
- data/ext/libsass/src/listize.hpp +8 -9
- data/ext/libsass/src/mapping.hpp +1 -0
- data/ext/libsass/src/memory/allocator.cpp +48 -0
- data/ext/libsass/src/memory/allocator.hpp +138 -0
- data/ext/libsass/src/memory/config.hpp +20 -0
- data/ext/libsass/src/memory/memory_pool.hpp +186 -0
- data/ext/libsass/src/memory/{SharedPtr.cpp → shared_ptr.cpp} +2 -2
- data/ext/libsass/src/memory/{SharedPtr.hpp → shared_ptr.hpp} +55 -9
- data/ext/libsass/src/memory.hpp +12 -0
- data/ext/libsass/src/operation.hpp +71 -61
- data/ext/libsass/src/operators.cpp +19 -18
- data/ext/libsass/src/operators.hpp +11 -11
- data/ext/libsass/src/ordered_map.hpp +112 -0
- data/ext/libsass/src/output.cpp +45 -64
- data/ext/libsass/src/output.hpp +6 -6
- data/ext/libsass/src/parser.cpp +512 -700
- data/ext/libsass/src/parser.hpp +89 -97
- data/ext/libsass/src/parser_selectors.cpp +189 -0
- data/ext/libsass/src/permutate.hpp +164 -0
- data/ext/libsass/src/plugins.cpp +7 -7
- data/ext/libsass/src/plugins.hpp +8 -8
- data/ext/libsass/src/position.cpp +7 -26
- data/ext/libsass/src/position.hpp +44 -21
- data/ext/libsass/src/prelexer.cpp +6 -6
- data/ext/libsass/src/remove_placeholders.cpp +55 -56
- data/ext/libsass/src/remove_placeholders.hpp +21 -18
- data/ext/libsass/src/sass.cpp +16 -15
- data/ext/libsass/src/sass.hpp +10 -5
- data/ext/libsass/src/sass2scss.cpp +4 -4
- data/ext/libsass/src/sass_context.cpp +91 -122
- data/ext/libsass/src/sass_context.hpp +2 -2
- data/ext/libsass/src/sass_functions.cpp +1 -1
- data/ext/libsass/src/sass_values.cpp +8 -11
- data/ext/libsass/src/settings.hpp +19 -0
- data/ext/libsass/src/source.cpp +69 -0
- data/ext/libsass/src/source.hpp +95 -0
- data/ext/libsass/src/source_data.hpp +32 -0
- data/ext/libsass/src/source_map.cpp +22 -18
- data/ext/libsass/src/source_map.hpp +12 -9
- data/ext/libsass/src/stylesheet.cpp +22 -0
- data/ext/libsass/src/stylesheet.hpp +57 -0
- data/ext/libsass/src/to_value.cpp +2 -2
- data/ext/libsass/src/to_value.hpp +1 -1
- data/ext/libsass/src/units.cpp +24 -22
- data/ext/libsass/src/units.hpp +8 -8
- data/ext/libsass/src/utf8_string.cpp +9 -10
- data/ext/libsass/src/utf8_string.hpp +7 -6
- data/ext/libsass/src/util.cpp +48 -50
- data/ext/libsass/src/util.hpp +20 -21
- data/ext/libsass/src/util_string.cpp +111 -61
- data/ext/libsass/src/util_string.hpp +62 -8
- data/ext/libsass/src/values.cpp +12 -12
- data/lib/sassc/engine.rb +5 -3
- data/lib/sassc/functions_handler.rb +8 -8
- data/lib/sassc/native.rb +4 -6
- data/lib/sassc/script.rb +4 -4
- data/lib/sassc/version.rb +1 -1
- data/test/functions_test.rb +18 -1
- data/test/native_test.rb +4 -4
- metadata +29 -15
- data/ext/libsass/src/extend.cpp +0 -2132
- data/ext/libsass/src/extend.hpp +0 -86
- data/ext/libsass/src/node.cpp +0 -322
- data/ext/libsass/src/node.hpp +0 -118
- data/ext/libsass/src/paths.hpp +0 -71
- data/ext/libsass/src/sass_util.cpp +0 -152
- data/ext/libsass/src/sass_util.hpp +0 -256
- data/ext/libsass/src/subset_map.cpp +0 -58
- data/ext/libsass/src/subset_map.hpp +0 -76
- data/lib/sassc/native/lib_c.rb +0 -21
data/ext/libsass/src/context.cpp
CHANGED
@@ -1,44 +1,23 @@
|
|
1
1
|
// sass.hpp must go before all system headers to get the
|
2
2
|
// __EXTENSIONS__ fix on Solaris.
|
3
3
|
#include "sass.hpp"
|
4
|
-
|
5
|
-
#include <string>
|
6
|
-
#include <cstdlib>
|
7
|
-
#include <cstring>
|
8
|
-
#include <iomanip>
|
9
|
-
#include <sstream>
|
10
|
-
#include <iostream>
|
11
|
-
|
12
4
|
#include "ast.hpp"
|
13
|
-
|
14
|
-
#include "sass.h"
|
15
|
-
#include "context.hpp"
|
16
|
-
#include "plugins.hpp"
|
17
|
-
#include "constants.hpp"
|
18
|
-
#include "parser.hpp"
|
19
|
-
#include "file.hpp"
|
20
|
-
#include "inspect.hpp"
|
21
|
-
#include "output.hpp"
|
22
|
-
#include "expand.hpp"
|
23
|
-
#include "eval.hpp"
|
24
|
-
#include "check_nesting.hpp"
|
25
|
-
#include "cssize.hpp"
|
26
|
-
#include "listize.hpp"
|
27
|
-
#include "extend.hpp"
|
5
|
+
|
28
6
|
#include "remove_placeholders.hpp"
|
29
7
|
#include "sass_functions.hpp"
|
30
|
-
#include "
|
31
|
-
#include "
|
32
|
-
#include "
|
33
|
-
#include "
|
34
|
-
#include "
|
8
|
+
#include "check_nesting.hpp"
|
9
|
+
#include "fn_selectors.hpp"
|
10
|
+
#include "fn_strings.hpp"
|
11
|
+
#include "fn_numbers.hpp"
|
12
|
+
#include "fn_colors.hpp"
|
35
13
|
#include "fn_miscs.hpp"
|
36
|
-
#include "fn_maps.hpp"
|
37
14
|
#include "fn_lists.hpp"
|
38
|
-
#include "
|
39
|
-
#include "
|
40
|
-
#include "
|
41
|
-
#include "
|
15
|
+
#include "fn_maps.hpp"
|
16
|
+
#include "context.hpp"
|
17
|
+
#include "expand.hpp"
|
18
|
+
#include "parser.hpp"
|
19
|
+
#include "cssize.hpp"
|
20
|
+
#include "source.hpp"
|
42
21
|
|
43
22
|
namespace Sass {
|
44
23
|
using namespace Constants;
|
@@ -48,25 +27,19 @@ namespace Sass {
|
|
48
27
|
inline bool sort_importers (const Sass_Importer_Entry& i, const Sass_Importer_Entry& j)
|
49
28
|
{ return sass_importer_get_priority(i) > sass_importer_get_priority(j); }
|
50
29
|
|
51
|
-
static
|
30
|
+
static sass::string safe_input(const char* in_path)
|
52
31
|
{
|
53
|
-
|
54
|
-
|
55
|
-
std::string safe_path(in_path ? in_path : "");
|
56
|
-
return safe_path == "" ? "stdin" : safe_path;
|
32
|
+
if (in_path == nullptr || in_path[0] == '\0') return "stdin";
|
33
|
+
return in_path;
|
57
34
|
}
|
58
35
|
|
59
|
-
static
|
36
|
+
static sass::string safe_output(const char* out_path, sass::string input_path)
|
60
37
|
{
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
int lastindex = static_cast<int>(input_path.find_last_of("."));
|
65
|
-
return (lastindex > -1 ? input_path.substr(0, lastindex) : input_path) + ".css";
|
38
|
+
if (out_path == nullptr || out_path[0] == '\0') {
|
39
|
+
if (input_path.empty()) return "stdout";
|
40
|
+
return input_path.substr(0, input_path.find_last_of(".")) + ".css";
|
66
41
|
}
|
67
|
-
|
68
|
-
// used to create relative file links
|
69
|
-
return safe_path == "" ? "stdout" : safe_path;
|
42
|
+
return out_path;
|
70
43
|
}
|
71
44
|
|
72
45
|
Context::Context(struct Sass_Context& c_ctx)
|
@@ -81,15 +54,15 @@ namespace Sass {
|
|
81
54
|
strings(),
|
82
55
|
resources(),
|
83
56
|
sheets(),
|
84
|
-
subset_map(),
|
85
57
|
import_stack(),
|
86
58
|
callee_stack(),
|
87
59
|
traces(),
|
60
|
+
extender(Extender::NORMAL, traces),
|
88
61
|
c_compiler(NULL),
|
89
62
|
|
90
|
-
c_headers (
|
91
|
-
c_importers (
|
92
|
-
c_functions (
|
63
|
+
c_headers (sass::vector<Sass_Importer_Entry>()),
|
64
|
+
c_importers (sass::vector<Sass_Importer_Entry>()),
|
65
|
+
c_functions (sass::vector<Sass_Function_Entry>()),
|
93
66
|
|
94
67
|
indent (safe_str(c_options.indent, " ")),
|
95
68
|
linefeed (safe_str(c_options.linefeed, "\n")),
|
@@ -160,7 +133,7 @@ namespace Sass {
|
|
160
133
|
}
|
161
134
|
// clear inner structures (vectors) and input source
|
162
135
|
resources.clear(); import_stack.clear();
|
163
|
-
|
136
|
+
sheets.clear();
|
164
137
|
}
|
165
138
|
|
166
139
|
Data_Context::~Data_Context()
|
@@ -183,7 +156,7 @@ namespace Sass {
|
|
183
156
|
const char* end = Prelexer::find_first<PATH_SEP>(beg);
|
184
157
|
|
185
158
|
while (end) {
|
186
|
-
|
159
|
+
sass::string path(beg, end - beg);
|
187
160
|
if (!path.empty()) {
|
188
161
|
if (*path.rbegin() != '/') path += '/';
|
189
162
|
include_paths.push_back(path);
|
@@ -192,7 +165,7 @@ namespace Sass {
|
|
192
165
|
end = Prelexer::find_first<PATH_SEP>(beg);
|
193
166
|
}
|
194
167
|
|
195
|
-
|
168
|
+
sass::string path(beg);
|
196
169
|
if (!path.empty()) {
|
197
170
|
if (*path.rbegin() != '/') path += '/';
|
198
171
|
include_paths.push_back(path);
|
@@ -216,7 +189,7 @@ namespace Sass {
|
|
216
189
|
const char* end = Prelexer::find_first<PATH_SEP>(beg);
|
217
190
|
|
218
191
|
while (end) {
|
219
|
-
|
192
|
+
sass::string path(beg, end - beg);
|
220
193
|
if (!path.empty()) {
|
221
194
|
if (*path.rbegin() != '/') path += '/';
|
222
195
|
plugin_paths.push_back(path);
|
@@ -225,7 +198,7 @@ namespace Sass {
|
|
225
198
|
end = Prelexer::find_first<PATH_SEP>(beg);
|
226
199
|
}
|
227
200
|
|
228
|
-
|
201
|
+
sass::string path(beg);
|
229
202
|
if (!path.empty()) {
|
230
203
|
if (*path.rbegin() != '/') path += '/';
|
231
204
|
plugin_paths.push_back(path);
|
@@ -244,17 +217,17 @@ namespace Sass {
|
|
244
217
|
|
245
218
|
// resolve the imp_path in base_path or include_paths
|
246
219
|
// looks for alternatives and returns a list from one directory
|
247
|
-
|
220
|
+
sass::vector<Include> Context::find_includes(const Importer& import)
|
248
221
|
{
|
249
222
|
// make sure we resolve against an absolute path
|
250
|
-
|
223
|
+
sass::string base_path(rel2abs(import.base_path));
|
251
224
|
// first try to resolve the load path relative to the base path
|
252
|
-
|
225
|
+
sass::vector<Include> vec(resolve_includes(base_path, import.imp_path));
|
253
226
|
// then search in every include path (but only if nothing found yet)
|
254
227
|
for (size_t i = 0, S = include_paths.size(); vec.size() == 0 && i < S; ++i)
|
255
228
|
{
|
256
229
|
// call resolve_includes and individual base path and append all results
|
257
|
-
|
230
|
+
sass::vector<Include> resolved(resolve_includes(include_paths[i], import.imp_path));
|
258
231
|
if (resolved.size()) vec.insert(vec.end(), resolved.begin(), resolved.end());
|
259
232
|
}
|
260
233
|
// return vector
|
@@ -301,22 +274,22 @@ namespace Sass {
|
|
301
274
|
|
302
275
|
// get pointer to the loaded content
|
303
276
|
const char* contents = resources[idx].contents;
|
304
|
-
|
305
|
-
|
306
|
-
|
277
|
+
SourceFileObj source = SASS_MEMORY_NEW(SourceFile,
|
278
|
+
inc.abs_path.c_str(), contents, idx);
|
279
|
+
|
307
280
|
// create the initial parser state from resource
|
308
|
-
|
281
|
+
SourceSpan pstate(source);
|
309
282
|
|
310
283
|
// check existing import stack for possible recursion
|
311
284
|
for (size_t i = 0; i < import_stack.size() - 2; ++i) {
|
312
285
|
auto parent = import_stack[i];
|
313
286
|
if (std::strcmp(parent->abs_path, import->abs_path) == 0) {
|
314
|
-
|
287
|
+
sass::string cwd(File::get_cwd());
|
315
288
|
// make path relative to the current directory
|
316
|
-
|
289
|
+
sass::string stack("An @import loop has been found:");
|
317
290
|
for (size_t n = 1; n < i + 2; ++n) {
|
318
|
-
stack += "\n " +
|
319
|
-
" imports " +
|
291
|
+
stack += "\n " + sass::string(File::abs2rel(import_stack[n]->abs_path, cwd, cwd)) +
|
292
|
+
" imports " + sass::string(File::abs2rel(import_stack[n+1]->abs_path, cwd, cwd));
|
320
293
|
}
|
321
294
|
// implement error throw directly until we
|
322
295
|
// decided how to handle full stack traces
|
@@ -326,7 +299,7 @@ namespace Sass {
|
|
326
299
|
}
|
327
300
|
|
328
301
|
// create a parser instance from the given c_str buffer
|
329
|
-
Parser p(
|
302
|
+
Parser p(source, *this, traces);
|
330
303
|
// do not yet dispose these buffers
|
331
304
|
sass_import_take_source(import);
|
332
305
|
sass_import_take_srcmap(import);
|
@@ -337,7 +310,7 @@ namespace Sass {
|
|
337
310
|
// remove current stack frame
|
338
311
|
import_stack.pop_back();
|
339
312
|
// create key/value pair for ast node
|
340
|
-
std::pair<const
|
313
|
+
std::pair<const sass::string, StyleSheet>
|
341
314
|
ast_pair(inc.abs_path, { res, root });
|
342
315
|
// register resulting resource
|
343
316
|
sheets.insert(ast_pair);
|
@@ -345,7 +318,7 @@ namespace Sass {
|
|
345
318
|
|
346
319
|
// register include with resolved path and its content
|
347
320
|
// memory of the resources will be freed by us on exit
|
348
|
-
void Context::register_resource(const Include& inc, const Resource& res,
|
321
|
+
void Context::register_resource(const Include& inc, const Resource& res, SourceSpan& prstate)
|
349
322
|
{
|
350
323
|
traces.push_back(Backtrace(prstate));
|
351
324
|
register_resource(inc, res);
|
@@ -353,16 +326,16 @@ namespace Sass {
|
|
353
326
|
}
|
354
327
|
|
355
328
|
// Add a new import to the context (called from `import_url`)
|
356
|
-
Include Context::load_import(const Importer& imp,
|
329
|
+
Include Context::load_import(const Importer& imp, SourceSpan pstate)
|
357
330
|
{
|
358
331
|
|
359
332
|
// search for valid imports (ie. partials) on the filesystem
|
360
333
|
// this may return more than one valid result (ambiguous imp_path)
|
361
|
-
const
|
334
|
+
const sass::vector<Include> resolved(find_includes(imp));
|
362
335
|
|
363
336
|
// error nicely on ambiguous imp_path
|
364
337
|
if (resolved.size() > 1) {
|
365
|
-
|
338
|
+
sass::ostream msg_stream;
|
366
339
|
msg_stream << "It's not clear which file to import for ";
|
367
340
|
msg_stream << "'@import \"" << imp.imp_path << "\"'." << "\n";
|
368
341
|
msg_stream << "Candidates:" << "\n";
|
@@ -392,20 +365,20 @@ namespace Sass {
|
|
392
365
|
|
393
366
|
}
|
394
367
|
|
395
|
-
void Context::import_url (Import* imp,
|
368
|
+
void Context::import_url (Import* imp, sass::string load_path, const sass::string& ctx_path) {
|
396
369
|
|
397
|
-
|
398
|
-
|
399
|
-
|
370
|
+
SourceSpan pstate(imp->pstate());
|
371
|
+
sass::string imp_path(unquote(load_path));
|
372
|
+
sass::string protocol("file");
|
400
373
|
|
401
374
|
using namespace Prelexer;
|
402
375
|
if (const char* proto = sequence< identifier, exactly<':'>, exactly<'/'>, exactly<'/'> >(imp_path.c_str())) {
|
403
376
|
|
404
|
-
protocol =
|
377
|
+
protocol = sass::string(imp_path.c_str(), proto - 3);
|
405
378
|
// if (protocol.compare("file") && true) { }
|
406
379
|
}
|
407
380
|
|
408
|
-
// add urls (protocol other than file) and urls without
|
381
|
+
// add urls (protocol other than file) and urls without protocol to `urls` member
|
409
382
|
// ToDo: if ctx_path is already a file resource, we should not add it here?
|
410
383
|
if (imp->import_queries() || protocol != "file" || imp_path.substr(0, 2) == "//") {
|
411
384
|
imp->urls().push_back(SASS_MEMORY_NEW(String_Quoted, imp->pstate(), load_path));
|
@@ -415,7 +388,7 @@ namespace Sass {
|
|
415
388
|
Argument_Obj loc_arg = SASS_MEMORY_NEW(Argument, pstate, loc);
|
416
389
|
Arguments_Obj loc_args = SASS_MEMORY_NEW(Arguments, pstate);
|
417
390
|
loc_args->append(loc_arg);
|
418
|
-
Function_Call* new_url = SASS_MEMORY_NEW(Function_Call, pstate,
|
391
|
+
Function_Call* new_url = SASS_MEMORY_NEW(Function_Call, pstate, sass::string("url"), loc_args);
|
419
392
|
imp->urls().push_back(new_url);
|
420
393
|
}
|
421
394
|
else {
|
@@ -431,7 +404,7 @@ namespace Sass {
|
|
431
404
|
|
432
405
|
|
433
406
|
// call custom importers on the given (unquoted) load_path and eventually parse the resulting style_sheet
|
434
|
-
bool Context::call_loader(const
|
407
|
+
bool Context::call_loader(const sass::string& load_path, const char* ctx_path, SourceSpan& pstate, Import* imp, sass::vector<Sass_Importer_Entry> importers, bool only_one)
|
435
408
|
{
|
436
409
|
// unique counter
|
437
410
|
size_t count = 0;
|
@@ -449,9 +422,9 @@ namespace Sass {
|
|
449
422
|
Sass_Import_List it_includes = includes;
|
450
423
|
while (*it_includes) { ++count;
|
451
424
|
// create unique path to use as key
|
452
|
-
|
425
|
+
sass::string uniq_path = load_path;
|
453
426
|
if (!only_one && count) {
|
454
|
-
|
427
|
+
sass::ostream path_strm;
|
455
428
|
path_strm << uniq_path << ":" << count;
|
456
429
|
uniq_path = path_strm.str();
|
457
430
|
}
|
@@ -468,14 +441,14 @@ namespace Sass {
|
|
468
441
|
// it may (or may not) override the line and column info
|
469
442
|
if (const char* err_message = sass_import_get_error_message(include_ent)) {
|
470
443
|
if (source || srcmap) register_resource({ importer, uniq_path }, { source, srcmap }, pstate);
|
471
|
-
if (line ==
|
472
|
-
else error(err_message,
|
444
|
+
if (line == sass::string::npos && column == sass::string::npos) error(err_message, pstate, traces);
|
445
|
+
else { error(err_message, { pstate.source, { line, column } }, traces); }
|
473
446
|
}
|
474
447
|
// content for import was set
|
475
448
|
else if (source) {
|
476
449
|
// resolved abs_path should be set by custom importer
|
477
450
|
// use the created uniq_path as fallback (maybe enforce)
|
478
|
-
|
451
|
+
sass::string path_key(abs_path ? abs_path : uniq_path);
|
479
452
|
// create the importer struct
|
480
453
|
Include include(importer, path_key);
|
481
454
|
// attach information to AST node
|
@@ -512,7 +485,7 @@ namespace Sass {
|
|
512
485
|
|
513
486
|
void register_function(Context&, Signature sig, Native_Function f, Env* env);
|
514
487
|
void register_function(Context&, Signature sig, Native_Function f, size_t arity, Env* env);
|
515
|
-
void register_overload_stub(Context&,
|
488
|
+
void register_overload_stub(Context&, sass::string name, Env* env);
|
516
489
|
void register_built_in_functions(Context&, Env* env);
|
517
490
|
void register_c_functions(Context&, Env* env, Sass_Function_List);
|
518
491
|
void register_c_function(Context&, Env* env, Sass_Function_Entry);
|
@@ -529,7 +502,7 @@ namespace Sass {
|
|
529
502
|
OutputBuffer emitted = emitter.get_buffer();
|
530
503
|
// should we append a source map url?
|
531
504
|
if (!c_options.omit_source_map_url) {
|
532
|
-
// generate an
|
505
|
+
// generate an embedded source map
|
533
506
|
if (c_options.source_map_embed) {
|
534
507
|
emitted.buffer += linefeed;
|
535
508
|
emitted.buffer += format_embedded_source_map();
|
@@ -545,7 +518,7 @@ namespace Sass {
|
|
545
518
|
return sass_copy_c_string(emitted.buffer.c_str());
|
546
519
|
}
|
547
520
|
|
548
|
-
void Context::apply_custom_headers(Block_Obj root, const char* ctx_path,
|
521
|
+
void Context::apply_custom_headers(Block_Obj root, const char* ctx_path, SourceSpan pstate)
|
549
522
|
{
|
550
523
|
// create a custom import to resolve headers
|
551
524
|
Import_Obj imp = SASS_MEMORY_NEW(Import, pstate);
|
@@ -570,7 +543,7 @@ namespace Sass {
|
|
570
543
|
|
571
544
|
// create absolute path from input filename
|
572
545
|
// ToDo: this should be resolved via custom importers
|
573
|
-
|
546
|
+
sass::string abs_path(rel2abs(input_path, CWD));
|
574
547
|
|
575
548
|
// try to load the entry file
|
576
549
|
char* contents = read_file(abs_path);
|
@@ -585,7 +558,9 @@ namespace Sass {
|
|
585
558
|
}
|
586
559
|
|
587
560
|
// abort early if no content could be loaded (various reasons)
|
588
|
-
if (!contents) throw std::runtime_error(
|
561
|
+
if (!contents) throw std::runtime_error(
|
562
|
+
"File to read not found or unreadable: "
|
563
|
+
+ std::string(input_path.c_str()));
|
589
564
|
|
590
565
|
// store entry path
|
591
566
|
entry_path = abs_path;
|
@@ -628,7 +603,7 @@ namespace Sass {
|
|
628
603
|
entry_path = input_path.empty() ? "stdin" : input_path;
|
629
604
|
|
630
605
|
// ToDo: this may be resolved via custom importers
|
631
|
-
|
606
|
+
sass::string abs_path(rel2abs(entry_path));
|
632
607
|
char* abs_path_c_str = sass_copy_c_string(abs_path.c_str());
|
633
608
|
strings.push_back(abs_path_c_str);
|
634
609
|
|
@@ -649,8 +624,6 @@ namespace Sass {
|
|
649
624
|
return compile();
|
650
625
|
}
|
651
626
|
|
652
|
-
|
653
|
-
|
654
627
|
// parse root block from includes
|
655
628
|
Block_Obj Context::compile()
|
656
629
|
{
|
@@ -678,60 +651,60 @@ namespace Sass {
|
|
678
651
|
}
|
679
652
|
// expand and eval the tree
|
680
653
|
root = expand(root);
|
654
|
+
|
655
|
+
Extension unsatisfied;
|
656
|
+
// check that all extends were used
|
657
|
+
if (extender.checkForUnsatisfiedExtends(unsatisfied)) {
|
658
|
+
throw Exception::UnsatisfiedExtend(traces, unsatisfied);
|
659
|
+
}
|
660
|
+
|
681
661
|
// check nesting
|
682
662
|
check_nesting(root);
|
683
663
|
// merge and bubble certain rules
|
684
664
|
root = cssize(root);
|
685
|
-
// should we extend something?
|
686
|
-
if (!subset_map.empty()) {
|
687
|
-
// create crtp visitor object
|
688
|
-
Extend extend(subset_map);
|
689
|
-
extend.setEval(expand.eval);
|
690
|
-
// extend tree nodes
|
691
|
-
extend(root);
|
692
|
-
}
|
693
665
|
|
694
666
|
// clean up by removing empty placeholders
|
695
667
|
// ToDo: maybe we can do this somewhere else?
|
696
668
|
Remove_Placeholders remove_placeholders;
|
697
669
|
root->perform(&remove_placeholders);
|
670
|
+
|
698
671
|
// return processed tree
|
699
672
|
return root;
|
700
673
|
}
|
701
674
|
// EO compile
|
702
675
|
|
703
|
-
|
676
|
+
sass::string Context::format_embedded_source_map()
|
704
677
|
{
|
705
|
-
|
706
|
-
|
707
|
-
|
678
|
+
sass::string map = emitter.render_srcmap(*this);
|
679
|
+
sass::istream is( map.c_str() );
|
680
|
+
sass::ostream buffer;
|
708
681
|
base64::encoder E;
|
709
682
|
E.encode(is, buffer);
|
710
|
-
|
683
|
+
sass::string url = "data:application/json;base64," + buffer.str();
|
711
684
|
url.erase(url.size() - 1);
|
712
685
|
return "/*# sourceMappingURL=" + url + " */";
|
713
686
|
}
|
714
687
|
|
715
|
-
|
688
|
+
sass::string Context::format_source_mapping_url(const sass::string& file)
|
716
689
|
{
|
717
|
-
|
690
|
+
sass::string url = abs2rel(file, output_path, CWD);
|
718
691
|
return "/*# sourceMappingURL=" + url + " */";
|
719
692
|
}
|
720
693
|
|
721
694
|
char* Context::render_srcmap()
|
722
695
|
{
|
723
696
|
if (source_map_file == "") return 0;
|
724
|
-
|
697
|
+
sass::string map = emitter.render_srcmap(*this);
|
725
698
|
return sass_copy_c_string(map.c_str());
|
726
699
|
}
|
727
700
|
|
728
701
|
|
729
702
|
// for data context we want to start after "stdin"
|
730
703
|
// we probably always want to skip the header includes?
|
731
|
-
|
704
|
+
sass::vector<sass::string> Context::get_included_files(bool skip, size_t headers)
|
732
705
|
{
|
733
706
|
// create a copy of the vector for manipulations
|
734
|
-
|
707
|
+
sass::vector<sass::string> includes = included_files;
|
735
708
|
if (includes.size() == 0) return includes;
|
736
709
|
if (skip) { includes.erase( includes.begin(), includes.begin() + 1 + headers); }
|
737
710
|
else { includes.erase( includes.begin() + 1, includes.begin() + 1 + headers); }
|
@@ -750,20 +723,20 @@ namespace Sass {
|
|
750
723
|
void register_function(Context& ctx, Signature sig, Native_Function f, size_t arity, Env* env)
|
751
724
|
{
|
752
725
|
Definition* def = make_native_function(sig, f, ctx);
|
753
|
-
|
726
|
+
sass::ostream ss;
|
754
727
|
ss << def->name() << "[f]" << arity;
|
755
728
|
def->environment(env);
|
756
729
|
(*env)[ss.str()] = def;
|
757
730
|
}
|
758
731
|
|
759
|
-
void register_overload_stub(Context& ctx,
|
732
|
+
void register_overload_stub(Context& ctx, sass::string name, Env* env)
|
760
733
|
{
|
761
734
|
Definition* stub = SASS_MEMORY_NEW(Definition,
|
762
|
-
|
763
|
-
|
735
|
+
SourceSpan{ "[built-in function]" },
|
736
|
+
nullptr,
|
764
737
|
name,
|
765
|
-
{},
|
766
|
-
|
738
|
+
Parameters_Obj{},
|
739
|
+
nullptr,
|
767
740
|
true);
|
768
741
|
(*env)[name + "[f]"] = stub;
|
769
742
|
}
|
data/ext/libsass/src/context.hpp
CHANGED
@@ -1,45 +1,37 @@
|
|
1
1
|
#ifndef SASS_CONTEXT_H
|
2
2
|
#define SASS_CONTEXT_H
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
#include
|
4
|
+
// sass.hpp must go before all system headers to get the
|
5
|
+
// __EXTENSIONS__ fix on Solaris.
|
6
|
+
#include "sass.hpp"
|
7
|
+
#include "ast.hpp"
|
8
|
+
|
7
9
|
|
8
10
|
#define BUFFERSIZE 255
|
9
11
|
#include "b64/encode.h"
|
10
12
|
|
11
|
-
#include "ast_fwd_decl.hpp"
|
12
|
-
#include "kwd_arg_macros.hpp"
|
13
|
-
#include "ast_fwd_decl.hpp"
|
14
13
|
#include "sass_context.hpp"
|
15
|
-
#include "
|
16
|
-
#include "source_map.hpp"
|
17
|
-
#include "subset_map.hpp"
|
18
|
-
#include "backtrace.hpp"
|
19
|
-
#include "output.hpp"
|
14
|
+
#include "stylesheet.hpp"
|
20
15
|
#include "plugins.hpp"
|
21
|
-
#include "
|
22
|
-
|
23
|
-
|
24
|
-
struct Sass_Function;
|
16
|
+
#include "output.hpp"
|
25
17
|
|
26
18
|
namespace Sass {
|
27
19
|
|
28
20
|
class Context {
|
29
21
|
public:
|
30
|
-
void import_url (Import* imp,
|
31
|
-
bool call_headers(const
|
22
|
+
void import_url (Import* imp, sass::string load_path, const sass::string& ctx_path);
|
23
|
+
bool call_headers(const sass::string& load_path, const char* ctx_path, SourceSpan& pstate, Import* imp)
|
32
24
|
{ return call_loader(load_path, ctx_path, pstate, imp, c_headers, false); };
|
33
|
-
bool call_importers(const
|
25
|
+
bool call_importers(const sass::string& load_path, const char* ctx_path, SourceSpan& pstate, Import* imp)
|
34
26
|
{ return call_loader(load_path, ctx_path, pstate, imp, c_importers, true); };
|
35
27
|
|
36
28
|
private:
|
37
|
-
bool call_loader(const
|
29
|
+
bool call_loader(const sass::string& load_path, const char* ctx_path, SourceSpan& pstate, Import* imp, sass::vector<Sass_Importer_Entry> importers, bool only_one = true);
|
38
30
|
|
39
31
|
public:
|
40
|
-
const
|
32
|
+
const sass::string CWD;
|
41
33
|
struct Sass_Options& c_options;
|
42
|
-
|
34
|
+
sass::string entry_path;
|
43
35
|
size_t head_imports;
|
44
36
|
Plugins plugins;
|
45
37
|
Output emitter;
|
@@ -49,45 +41,41 @@ namespace Sass {
|
|
49
41
|
CallStack ast_gc;
|
50
42
|
// resources add under our control
|
51
43
|
// these are guaranteed to be freed
|
52
|
-
|
53
|
-
|
54
|
-
std::map<const
|
55
|
-
Subset_Map subset_map;
|
44
|
+
sass::vector<char*> strings;
|
45
|
+
sass::vector<Resource> resources;
|
46
|
+
std::map<const sass::string, StyleSheet> sheets;
|
56
47
|
ImporterStack import_stack;
|
57
|
-
|
58
|
-
|
48
|
+
sass::vector<Sass_Callee> callee_stack;
|
49
|
+
sass::vector<Backtrace> traces;
|
50
|
+
Extender extender;
|
59
51
|
|
60
52
|
struct Sass_Compiler* c_compiler;
|
61
53
|
|
62
54
|
// absolute paths to includes
|
63
|
-
|
55
|
+
sass::vector<sass::string> included_files;
|
64
56
|
// relative includes for sourcemap
|
65
|
-
|
57
|
+
sass::vector<sass::string> srcmap_links;
|
66
58
|
// vectors above have same size
|
67
59
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
60
|
+
sass::vector<sass::string> plugin_paths; // relative paths to load plugins
|
61
|
+
sass::vector<sass::string> include_paths; // lookup paths for includes
|
74
62
|
|
75
|
-
void apply_custom_headers(Block_Obj root, const char* path,
|
63
|
+
void apply_custom_headers(Block_Obj root, const char* path, SourceSpan pstate);
|
76
64
|
|
77
|
-
|
78
|
-
|
79
|
-
|
65
|
+
sass::vector<Sass_Importer_Entry> c_headers;
|
66
|
+
sass::vector<Sass_Importer_Entry> c_importers;
|
67
|
+
sass::vector<Sass_Function_Entry> c_functions;
|
80
68
|
|
81
69
|
void add_c_header(Sass_Importer_Entry header);
|
82
70
|
void add_c_importer(Sass_Importer_Entry importer);
|
83
71
|
void add_c_function(Sass_Function_Entry function);
|
84
72
|
|
85
|
-
const
|
86
|
-
const
|
87
|
-
const
|
88
|
-
const
|
89
|
-
const
|
90
|
-
const
|
73
|
+
const sass::string indent; // String to be used for indentation
|
74
|
+
const sass::string linefeed; // String to be used for line feeds
|
75
|
+
const sass::string input_path; // for relative paths in src-map
|
76
|
+
const sass::string output_path; // for relative paths to the output
|
77
|
+
const sass::string source_map_file; // path to source map file (enables feature)
|
78
|
+
const sass::string source_map_root; // path for sourceRoot property (pass-through)
|
91
79
|
|
92
80
|
virtual ~Context();
|
93
81
|
Context(struct Sass_Context&);
|
@@ -97,29 +85,29 @@ namespace Sass {
|
|
97
85
|
virtual char* render_srcmap();
|
98
86
|
|
99
87
|
void register_resource(const Include&, const Resource&);
|
100
|
-
void register_resource(const Include&, const Resource&,
|
101
|
-
|
102
|
-
Include load_import(const Importer&,
|
88
|
+
void register_resource(const Include&, const Resource&, SourceSpan&);
|
89
|
+
sass::vector<Include> find_includes(const Importer& import);
|
90
|
+
Include load_import(const Importer&, SourceSpan pstate);
|
103
91
|
|
104
92
|
Sass_Output_Style output_style() { return c_options.output_style; };
|
105
|
-
|
93
|
+
sass::vector<sass::string> get_included_files(bool skip = false, size_t headers = 0);
|
106
94
|
|
107
95
|
private:
|
108
96
|
void collect_plugin_paths(const char* paths_str);
|
109
97
|
void collect_plugin_paths(string_list* paths_array);
|
110
98
|
void collect_include_paths(const char* paths_str);
|
111
99
|
void collect_include_paths(string_list* paths_array);
|
112
|
-
|
113
|
-
|
100
|
+
sass::string format_embedded_source_map();
|
101
|
+
sass::string format_source_mapping_url(const sass::string& out_path);
|
114
102
|
|
115
103
|
|
116
104
|
// void register_built_in_functions(Env* env);
|
117
105
|
// void register_function(Signature sig, Native_Function f, Env* env);
|
118
106
|
// void register_function(Signature sig, Native_Function f, size_t arity, Env* env);
|
119
|
-
// void register_overload_stub(
|
107
|
+
// void register_overload_stub(sass::string name, Env* env);
|
120
108
|
|
121
109
|
public:
|
122
|
-
const
|
110
|
+
const sass::string& cwd() { return CWD; };
|
123
111
|
};
|
124
112
|
|
125
113
|
class File_Context : public Context {
|