sassc 1.9.0 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +30 -3
  3. data/ext/libsass/.gitignore +3 -0
  4. data/ext/libsass/.travis.yml +1 -1
  5. data/ext/libsass/GNUmakefile.am +7 -7
  6. data/ext/libsass/Makefile +7 -4
  7. data/ext/libsass/Makefile.conf +0 -1
  8. data/ext/libsass/appveyor.yml +6 -2
  9. data/ext/libsass/docs/api-context.md +4 -4
  10. data/ext/libsass/docs/api-doc.md +29 -11
  11. data/ext/libsass/docs/api-importer-example.md +5 -5
  12. data/ext/libsass/docs/build-on-windows.md +1 -1
  13. data/ext/libsass/include/sass/base.h +10 -0
  14. data/ext/libsass/include/sass/version.h +4 -0
  15. data/ext/libsass/include/sass/version.h.in +4 -0
  16. data/ext/libsass/include/sass2scss.h +1 -1
  17. data/ext/libsass/script/ci-build-libsass +15 -3
  18. data/ext/libsass/src/ast.cpp +161 -6
  19. data/ext/libsass/src/ast.hpp +71 -44
  20. data/ext/libsass/src/ast_factory.hpp +1 -1
  21. data/ext/libsass/src/ast_fwd_decl.hpp +2 -2
  22. data/ext/libsass/src/constants.cpp +2 -4
  23. data/ext/libsass/src/constants.hpp +3 -4
  24. data/ext/libsass/src/context.cpp +16 -17
  25. data/ext/libsass/src/context.hpp +2 -2
  26. data/ext/libsass/src/cssize.cpp +19 -8
  27. data/ext/libsass/src/cssize.hpp +5 -2
  28. data/ext/libsass/src/debugger.hpp +6 -3
  29. data/ext/libsass/src/emitter.cpp +1 -1
  30. data/ext/libsass/src/environment.cpp +1 -1
  31. data/ext/libsass/src/eval.cpp +42 -14
  32. data/ext/libsass/src/eval.hpp +1 -1
  33. data/ext/libsass/src/expand.cpp +24 -8
  34. data/ext/libsass/src/expand.hpp +2 -1
  35. data/ext/libsass/src/extend.cpp +55 -15
  36. data/ext/libsass/src/extend.hpp +5 -1
  37. data/ext/libsass/src/functions.cpp +10 -5
  38. data/ext/libsass/src/inspect.cpp +25 -19
  39. data/ext/libsass/src/inspect.hpp +2 -2
  40. data/ext/libsass/src/json.cpp +20 -9
  41. data/ext/libsass/src/json.hpp +5 -5
  42. data/ext/libsass/src/lexer.cpp +4 -1
  43. data/ext/libsass/src/lexer.hpp +21 -0
  44. data/ext/libsass/src/listize.cpp +2 -1
  45. data/ext/libsass/src/operation.hpp +4 -4
  46. data/ext/libsass/src/output.cpp +1 -1
  47. data/ext/libsass/src/output.hpp +1 -1
  48. data/ext/libsass/src/parser.cpp +189 -90
  49. data/ext/libsass/src/parser.hpp +42 -2
  50. data/ext/libsass/src/prelexer.cpp +474 -7
  51. data/ext/libsass/src/prelexer.hpp +15 -2
  52. data/ext/libsass/src/remove_placeholders.cpp +5 -5
  53. data/ext/libsass/src/remove_placeholders.hpp +3 -2
  54. data/ext/libsass/src/sass.cpp +33 -3
  55. data/ext/libsass/src/sass2scss.cpp +7 -0
  56. data/ext/libsass/src/sass_context.cpp +32 -62
  57. data/ext/libsass/src/sass_functions.cpp +3 -3
  58. data/ext/libsass/src/sass_values.cpp +5 -5
  59. data/ext/libsass/src/utf8/unchecked.h +16 -16
  60. data/ext/libsass/src/util.cpp +51 -30
  61. data/ext/libsass/src/util.hpp +6 -1
  62. data/ext/libsass/win/libsass.targets +0 -2
  63. data/ext/libsass/win/libsass.vcxproj.filters +0 -6
  64. data/lib/sassc/engine.rb +4 -1
  65. data/lib/sassc/error.rb +23 -1
  66. data/lib/sassc/version.rb +1 -1
  67. data/test/error_test.rb +27 -0
  68. data/test/native_test.rb +1 -1
  69. metadata +5 -5
  70. data/ext/libsass/include/sass/interface.h +0 -105
  71. data/ext/libsass/src/sass_interface.cpp +0 -215
@@ -12,11 +12,6 @@
12
12
 
13
13
  namespace Sass {
14
14
 
15
- #define out_of_memory() do { \
16
- std::cerr << "Out of memory.\n"; \
17
- exit(EXIT_FAILURE); \
18
- } while (0)
19
-
20
15
  double round(double val, size_t precision)
21
16
  {
22
17
  // https://github.com/sass/sass/commit/4e3e1d5684cc29073a507578fc977434ff488c93
@@ -28,16 +23,6 @@ namespace Sass {
28
23
  return ::round(val);
29
24
  }
30
25
 
31
- /* Sadly, sass_strdup is not portable. */
32
- char *sass_strdup(const char *str)
33
- {
34
- char *ret = (char*) malloc(strlen(str) + 1);
35
- if (ret == NULL)
36
- out_of_memory();
37
- strcpy(ret, str);
38
- return ret;
39
- }
40
-
41
26
  /* Locale unspecific atof function. */
42
27
  double sass_atof(const char *str)
43
28
  {
@@ -50,7 +35,7 @@ namespace Sass {
50
35
  if(found != NULL){
51
36
  // substitution is required. perform the substitution on a copy
52
37
  // of the string. This is slower but it is thread safe.
53
- char *copy = sass_strdup(str);
38
+ char *copy = sass_copy_c_string(str);
54
39
  *(copy + (found - str)) = separator;
55
40
  double res = atof(copy);
56
41
  free(copy);
@@ -118,7 +103,10 @@ namespace Sass {
118
103
  }
119
104
  out.push_back(i);
120
105
  }
121
- if (esc) out += '\\';
106
+ // happens when parsing does not correctly skip
107
+ // over escaped sequences for ie. interpolations
108
+ // one example: foo\#{interpolate}
109
+ // if (esc) out += '\\';
122
110
  return out;
123
111
  }
124
112
 
@@ -473,7 +461,7 @@ namespace Sass {
473
461
  bool hasPrintableChildBlocks = false;
474
462
  for (size_t i = 0, L = b->length(); i < L; ++i) {
475
463
  Statement* stm = (*b)[i];
476
- if (dynamic_cast<At_Rule*>(stm)) {
464
+ if (dynamic_cast<Directive*>(stm)) {
477
465
  return true;
478
466
  } else if (dynamic_cast<Has_Block*>(stm)) {
479
467
  Block* pChildBlock = ((Has_Block*)stm)->block();
@@ -540,7 +528,7 @@ namespace Sass {
540
528
  // is NULL, then that means there was never a wrapping selector and it is printable (think of a top level media block with
541
529
  // a declaration in it).
542
530
  }
543
- else if (typeid(*stm) == typeid(Declaration) || typeid(*stm) == typeid(At_Rule)) {
531
+ else if (typeid(*stm) == typeid(Declaration) || typeid(*stm) == typeid(Directive)) {
544
532
  hasDeclarations = true;
545
533
  }
546
534
  else if (dynamic_cast<Has_Block*>(stm)) {
@@ -565,15 +553,53 @@ namespace Sass {
565
553
  if (b == 0) return false;
566
554
  for (size_t i = 0, L = b->length(); i < L; ++i) {
567
555
  Statement* stm = (*b)[i];
568
- if (typeid(*stm) == typeid(At_Rule)) return true;
569
- if (typeid(*stm) == typeid(Declaration)) return true;
570
- if (Has_Block* child = dynamic_cast<Has_Block*>(stm)) {
571
- if (isPrintable(child->block(), style)) return true;
556
+ if (typeid(*stm) == typeid(Directive)) return true;
557
+ else if (typeid(*stm) == typeid(Declaration)) return true;
558
+ else if (typeid(*stm) == typeid(Comment)) {
559
+ Comment* c = (Comment*) stm;
560
+ if (isPrintable(c, style)) {
561
+ return true;
562
+ }
563
+ }
564
+ else if (typeid(*stm) == typeid(Ruleset)) {
565
+ Ruleset* r = (Ruleset*) stm;
566
+ if (isPrintable(r, style)) {
567
+ return true;
568
+ }
569
+ }
570
+ else if (typeid(*stm) == typeid(Supports_Block)) {
571
+ Supports_Block* f = (Supports_Block*) stm;
572
+ if (isPrintable(f, style)) {
573
+ return true;
574
+ }
575
+ }
576
+ else if (typeid(*stm) == typeid(Media_Block)) {
577
+ Media_Block* m = (Media_Block*) stm;
578
+ if (isPrintable(m, style)) {
579
+ return true;
580
+ }
581
+ }
582
+ else if (dynamic_cast<Has_Block*>(stm) && isPrintable(((Has_Block*)stm)->block(), style)) {
583
+ return true;
572
584
  }
573
585
  }
574
586
  return false;
575
587
  }
576
588
 
589
+ bool isPrintable(Comment* c, Sass_Output_Style style)
590
+ {
591
+ // keep for uncompressed
592
+ if (style != COMPRESSED) {
593
+ return true;
594
+ }
595
+ // output style compressed
596
+ if (c->is_important()) {
597
+ return true;
598
+ }
599
+ // not printable
600
+ return false;
601
+ };
602
+
577
603
  bool isPrintable(Block* b, Sass_Output_Style style) {
578
604
  if (b == NULL) {
579
605
  return false;
@@ -581,17 +607,12 @@ namespace Sass {
581
607
 
582
608
  for (size_t i = 0, L = b->length(); i < L; ++i) {
583
609
  Statement* stm = (*b)[i];
584
- if (typeid(*stm) == typeid(Declaration) || typeid(*stm) == typeid(At_Rule)) {
610
+ if (typeid(*stm) == typeid(Declaration) || typeid(*stm) == typeid(Directive)) {
585
611
  return true;
586
612
  }
587
613
  else if (typeid(*stm) == typeid(Comment)) {
588
614
  Comment* c = (Comment*) stm;
589
- // keep for uncompressed
590
- if (style != COMPRESSED) {
591
- return true;
592
- }
593
- // output style compressed
594
- if (c->is_important()) {
615
+ if (isPrintable(c, style)) {
595
616
  return true;
596
617
  }
597
618
  }
@@ -12,8 +12,12 @@
12
12
 
13
13
  namespace Sass {
14
14
 
15
+ #define out_of_memory() do { \
16
+ std::cerr << "Out of memory.\n"; \
17
+ exit(EXIT_FAILURE); \
18
+ } while (0)
19
+
15
20
  double round(double val, size_t precision = 0);
16
- char* sass_strdup(const char* str);
17
21
  double sass_atof(const char* str);
18
22
  const char* safe_str(const char *, const char* = "");
19
23
  void free_string_array(char **);
@@ -46,6 +50,7 @@ namespace Sass {
46
50
  bool isPrintable(Ruleset* r, Sass_Output_Style style = NESTED);
47
51
  bool isPrintable(Supports_Block* r, Sass_Output_Style style = NESTED);
48
52
  bool isPrintable(Media_Block* r, Sass_Output_Style style = NESTED);
53
+ bool isPrintable(Comment* b, Sass_Output_Style style = NESTED);
49
54
  bool isPrintable(Block* b, Sass_Output_Style style = NESTED);
50
55
  bool isPrintable(String_Constant* s, Sass_Output_Style style = NESTED);
51
56
  bool isPrintable(String_Quoted* s, Sass_Output_Style style = NESTED);
@@ -5,7 +5,6 @@
5
5
  <ClInclude Include="$(LIBSASS_INCLUDES_DIR)\sass\base.h" />
6
6
  <ClInclude Include="$(LIBSASS_INCLUDES_DIR)\sass\context.h" />
7
7
  <ClInclude Include="$(LIBSASS_INCLUDES_DIR)\sass\functions.h" />
8
- <ClInclude Include="$(LIBSASS_INCLUDES_DIR)\sass\interface.h" />
9
8
  <ClInclude Include="$(LIBSASS_INCLUDES_DIR)\sass\values.h" />
10
9
  <ClInclude Include="$(LIBSASS_INCLUDES_DIR)\sass\version.h" />
11
10
  <ClInclude Include="$(LIBSASS_INCLUDES_DIR)\sass\version.h.in" />
@@ -97,7 +96,6 @@
97
96
  <ClCompile Include="$(LIBSASS_SRC_DIR)\prelexer.cpp" />
98
97
  <ClCompile Include="$(LIBSASS_SRC_DIR)\remove_placeholders.cpp" />
99
98
  <ClCompile Include="$(LIBSASS_SRC_DIR)\sass.cpp" />
100
- <ClCompile Include="$(LIBSASS_SRC_DIR)\sass_interface.cpp" />
101
99
  <ClCompile Include="$(LIBSASS_SRC_DIR)\sass_context.cpp" />
102
100
  <ClCompile Include="$(LIBSASS_SRC_DIR)\sass_functions.cpp" />
103
101
  <ClCompile Include="$(LIBSASS_SRC_DIR)\sass_util.cpp" />
@@ -34,9 +34,6 @@
34
34
  <ClInclude Include="$(LIBSASS_INCLUDES_DIR)\sass\functions.h">
35
35
  <Filter>Include Headers</Filter>
36
36
  </ClInclude>
37
- <ClInclude Include="$(LIBSASS_INCLUDES_DIR)\sass\interface.h">
38
- <Filter>Include Headers</Filter>
39
- </ClInclude>
40
37
  <ClInclude Include="$(LIBSASS_INCLUDES_DIR)\sass\values.h">
41
38
  <Filter>Include Headers</Filter>
42
39
  </ClInclude>
@@ -302,9 +299,6 @@
302
299
  <ClCompile Include="$(LIBSASS_SRC_DIR)\sass.cpp">
303
300
  <Filter>Sources</Filter>
304
301
  </ClCompile>
305
- <ClCompile Include="$(LIBSASS_SRC_DIR)\sass_interface.cpp">
306
- <Filter>Sources</Filter>
307
- </ClCompile>
308
302
  <ClCompile Include="$(LIBSASS_SRC_DIR)\sass_context.cpp">
309
303
  <Filter>Sources</Filter>
310
304
  </ClCompile>
@@ -40,7 +40,10 @@ module SassC
40
40
 
41
41
  if status != 0
42
42
  message = Native.context_get_error_message(context)
43
- raise SyntaxError.new(message)
43
+ filename = Native.context_get_error_file(context)
44
+ line = Native.context_get_error_line(context)
45
+
46
+ raise SyntaxError.new(message, filename: filename, line: line)
44
47
  end
45
48
 
46
49
  css = Native.context_get_output_string(context)
@@ -1,9 +1,31 @@
1
+ require 'pathname'
1
2
  require 'sass/error'
2
3
 
3
4
  module SassC
4
5
  class BaseError < StandardError; end
5
- class SyntaxError < BaseError; end
6
6
  class NotRenderedError < BaseError; end
7
7
  class InvalidStyleError < BaseError; end
8
8
  class UnsupportedValue < BaseError; end
9
+
10
+ # When dealing with SyntaxErrors,
11
+ # it's important to provide filename and line number information.
12
+ # This will be used in various error reports to users, including backtraces;
13
+ class SyntaxError < BaseError
14
+ def initialize(message, filename: nil, line: nil)
15
+ @filename = filename
16
+ @line = line
17
+ super(message)
18
+ end
19
+
20
+ def backtrace
21
+ return nil if super.nil?
22
+ sass_backtrace + super
23
+ end
24
+
25
+ # The backtrace of the error within Sass files.
26
+ def sass_backtrace
27
+ return [] unless @filename && @line
28
+ ["#{@filename}:#{@line}"]
29
+ end
30
+ end
9
31
  end
@@ -1,3 +1,3 @@
1
1
  module SassC
2
- VERSION = "1.9.0"
2
+ VERSION = "1.10.0"
3
3
  end
@@ -0,0 +1,27 @@
1
+ require_relative "test_helper"
2
+
3
+ module SassC
4
+ class ErrorTest < MiniTest::Test
5
+ def render(data, opts={})
6
+ Engine.new(data, opts).render
7
+ end
8
+
9
+ def test_first_backtrace_is_sass
10
+ filename = "app/assets/stylesheets/application.scss"
11
+
12
+ begin
13
+ template = <<-SCSS
14
+ .foo {
15
+ baz: bang;
16
+ padding top: 10px;
17
+ }
18
+ SCSS
19
+
20
+ render(template, filename: filename)
21
+ rescue SassC::SyntaxError => err
22
+ expected = "#{filename}:3"
23
+ assert_equal expected, err.backtrace.first
24
+ end
25
+ end
26
+ end
27
+ end
@@ -9,7 +9,7 @@ module SassC
9
9
 
10
10
  class General < MiniTest::Test
11
11
  def test_it_reports_the_libsass_version
12
- assert_equal "3.3.4", Native.version
12
+ assert_equal "3.3.6", Native.version
13
13
  end
14
14
  end
15
15
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sassc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Boland
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-29 00:00:00.000000000 Z
11
+ date: 2016-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -192,7 +192,6 @@ files:
192
192
  - ext/libsass/include/sass/base.h
193
193
  - ext/libsass/include/sass/context.h
194
194
  - ext/libsass/include/sass/functions.h
195
- - ext/libsass/include/sass/interface.h
196
195
  - ext/libsass/include/sass/values.h
197
196
  - ext/libsass/include/sass/version.h
198
197
  - ext/libsass/include/sass/version.h.in
@@ -285,7 +284,6 @@ files:
285
284
  - ext/libsass/src/sass_context.hpp
286
285
  - ext/libsass/src/sass_functions.cpp
287
286
  - ext/libsass/src/sass_functions.hpp
288
- - ext/libsass/src/sass_interface.cpp
289
287
  - ext/libsass/src/sass_util.cpp
290
288
  - ext/libsass/src/sass_util.hpp
291
289
  - ext/libsass/src/sass_values.cpp
@@ -355,6 +353,7 @@ files:
355
353
  - sassc.gemspec
356
354
  - test/custom_importer_test.rb
357
355
  - test/engine_test.rb
356
+ - test/error_test.rb
358
357
  - test/fixtures/paths.scss
359
358
  - test/functions_test.rb
360
359
  - test/native_test.rb
@@ -381,13 +380,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
381
380
  version: '0'
382
381
  requirements: []
383
382
  rubyforge_project:
384
- rubygems_version: 2.2.2
383
+ rubygems_version: 2.5.1
385
384
  signing_key:
386
385
  specification_version: 4
387
386
  summary: Use libsass with Ruby!
388
387
  test_files:
389
388
  - test/custom_importer_test.rb
390
389
  - test/engine_test.rb
390
+ - test/error_test.rb
391
391
  - test/fixtures/paths.scss
392
392
  - test/functions_test.rb
393
393
  - test/native_test.rb
@@ -1,105 +0,0 @@
1
- #ifndef SASS_C_INTERFACE_H
2
- #define SASS_C_INTERFACE_H
3
-
4
- // the API in this header has been deprecated
5
- // please use the new API from sass/context.h
6
-
7
- #include <stddef.h>
8
- #include <stdbool.h>
9
- #include <sass/base.h>
10
-
11
- #ifdef __cplusplus
12
- extern "C" {
13
- #endif
14
-
15
-
16
- // Please ensure there are no null values.
17
- // Thar be dragons.
18
- struct sass_options {
19
- // Output style for the generated css code
20
- // A value from above SASS_STYLE_* constants
21
- int output_style;
22
- // If you want inline source comments
23
- bool source_comments;
24
- // Path to source map file
25
- // Enables the source map generating
26
- // Used to create sourceMappingUrl
27
- const char* source_map_file;
28
- // Disable sourceMappingUrl in css output
29
- bool omit_source_map_url;
30
- // embed sourceMappingUrl as data uri
31
- bool source_map_embed;
32
- // embed include contents in maps
33
- bool source_map_contents;
34
- // Pass-through as sourceRoot property
35
- const char* source_map_root;
36
- // Treat source_string as sass (as opposed to scss)
37
- bool is_indented_syntax_src;
38
- // Colon-separated list of paths
39
- // Semicolon-separated on Windows
40
- const char* include_paths;
41
- const char* plugin_paths;
42
- // String to be used for indentation
43
- const char* indent;
44
- // String to be used to for line feeds
45
- const char* linefeed;
46
- // Precision for outputting fractional numbers
47
- int precision;
48
- };
49
-
50
- struct sass_context {
51
- const char* input_path;
52
- const char* output_path;
53
- char* source_string;
54
- char* output_string;
55
- char* source_map_string;
56
- struct sass_options options;
57
- int error_status;
58
- char* error_message;
59
- Sass_Function_List c_functions;
60
- char** included_files;
61
- int num_included_files;
62
- };
63
-
64
- struct sass_file_context {
65
- const char* input_path;
66
- const char* output_path;
67
- char* output_string;
68
- char* source_map_string;
69
- struct sass_options options;
70
- int error_status;
71
- char* error_message;
72
- Sass_Function_List c_functions;
73
- char** included_files;
74
- int num_included_files;
75
- };
76
-
77
- struct sass_folder_context {
78
- const char* search_path;
79
- const char* output_path;
80
- struct sass_options options;
81
- int error_status;
82
- char* error_message;
83
- Sass_Function_List c_functions;
84
- char** included_files;
85
- int num_included_files;
86
- };
87
-
88
- struct sass_context* sass_new_context (void);
89
- struct sass_file_context* sass_new_file_context (void);
90
- struct sass_folder_context* sass_new_folder_context (void);
91
-
92
- void sass_free_context (struct sass_context* ctx);
93
- void sass_free_file_context (struct sass_file_context* ctx);
94
- void sass_free_folder_context(struct sass_folder_context* ctx);
95
-
96
- int sass_compile (struct sass_context* ctx);
97
- int sass_compile_file (struct sass_file_context* ctx);
98
- int sass_compile_folder (struct sass_folder_context* ctx);
99
-
100
-
101
- #ifdef __cplusplus
102
- }
103
- #endif
104
-
105
- #endif