Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Bump LibSass@3.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyfer committed Apr 25, 2018
1 parent eb5ad0a commit 7ec14df
Show file tree
Hide file tree
Showing 26 changed files with 257 additions and 136 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "node-sass",
"version": "4.9.0",
"libsass": "3.5.2",
"libsass": "3.5.3",
"description": "Wrapper around libsass",
"license": "MIT",
"bugs": "https://github.com/sass/node-sass/issues",
Expand Down Expand Up @@ -83,7 +83,7 @@
"object-merge": "^2.5.1",
"read-yaml": "^1.0.0",
"rimraf": "^2.5.2",
"sass-spec": "^3.5.1",
"sass-spec": "3.5.3",
"unique-temp-dir": "^1.0.0"
}
}
56 changes: 21 additions & 35 deletions src/libsass/GNUmakefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -25,63 +25,49 @@ else
AM_CXXFLAGS += -std=c++0x
endif

TEST_EXTENSIONS = .rb

if ENABLE_TESTS

noinst_PROGRAMS = tester
SASS_SASSC_PATH ?= $(top_srcdir)/sassc
SASS_SPEC_PATH ?= $(top_srcdir)/sass-spec

noinst_PROGRAMS = tester
tester_LDADD = src/libsass.la
tester_SOURCES = $(SASS_SASSC_PATH)/sassc.c
tester_VERSION ?= `cd "$(SASS_SASSC_PATH)" && ./version.sh`
tester_CFLAGS = $(AM_CFLAGS) -DSASSC_VERSION="\"$(tester_VERSION)\""
tester_CXXFLAGS = $(AM_CXXFLAGS) -DSASSC_VERSION="\"$(tester_VERSION)\""
tester_LDFLAGS = $(AM_LDFLAGS)
nodist_tester_SOURCES = $(SASS_SASSC_PATH)/sassc.c
SASS_SASSC_VERSION ?= `cd "$(SASS_SASSC_PATH)" && ./version.sh`
tester_CFLAGS = $(AM_CFLAGS) -DSASSC_VERSION="\"$(SASS_SASSC_VERSION)\""
tester_CXXFLAGS = $(AM_CXXFLAGS) -DSASSC_VERSION="\"$(SASS_SASSC_VERSION)\""

if ENABLE_COVERAGE
nodist_EXTRA_tester_SOURCES = non-existent-file-to-force-CXX-linking.cxx
endif

SASS_SASSC_PATH ?= $(top_srcdir)/sassc
SASS_SPEC_PATH ?= $(top_srcdir)/sass-spec

TESTS = \
$(SASS_SPEC_PATH)/spec/basic \
$(SASS_SPEC_PATH)/spec/css \
$(SASS_SPEC_PATH)/spec/extend-tests \
$(SASS_SPEC_PATH)/spec/extends \
$(SASS_SPEC_PATH)/spec/libsass \
$(SASS_SPEC_PATH)/spec/libsass-closed-issues \
$(SASS_SPEC_PATH)/spec/maps \
$(SASS_SPEC_PATH)/spec/misc \
$(SASS_SPEC_PATH)/spec/regressions \
$(SASS_SPEC_PATH)/spec/scss \
$(SASS_SPEC_PATH)/spec/scss-tests \
$(SASS_SPEC_PATH)/spec/types
TESTS = $(SASS_SPEC_PATH)/sass-spec.rb
RB_LOG_COMPILER = ./script/tap-runner
AM_RB_LOG_FLAGS = $(RUBY)

SASS_TEST_FLAGS = -V 3.5 --impl libsass
LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) ./script/tap-driver
AM_LOG_FLAGS = -c ./tester $(LOG_FLAGS)
if USE_TAP
AM_LOG_FLAGS += -t
SASS_TEST_FLAGS += -t | tapout
LOG_COMPILER = ./script/tap-runner $(RUBY) $(SASS_SPEC_PATH)/sass-spec.rb
else
LOG_COMPILER = $(RUBY) $(SASS_SPEC_PATH)/sass-spec.rb
endif
SASS_TEST_FLAGS += -r $(SASS_SPEC_PATH)
SASS_TEST_FLAGS += -c $(top_srcdir)/tester$(EXEEXT)
AM_TESTS_ENVIRONMENT = TEST_FLAGS='$(SASS_TEST_FLAGS)'

SASS_TESTER = $(RUBY) $(SASS_SPEC_PATH)/sass-spec.rb
SASS_TESTER += -c $(top_srcdir)/tester$(EXEEXT)

test:
$(SASS_TESTER) $(LOG_FLAGS) $(SASS_SPEC_PATH) $(SASS_TEST_FLAGS)
$(SASS_TESTER) $(SASS_TEST_FLAGS)

test_build:
$(SASS_TESTER) $(LOG_FLAGS) $(SASS_SPEC_PATH) $(SASS_TEST_FLAGS)
$(SASS_TESTER) $(SASS_TEST_FLAGS)

test_full:
$(SASS_TESTER) --run-todo $(LOG_FLAGS) $(SASS_SPEC_PATH) $(SASS_TEST_FLAGS)
$(SASS_TESTER) --run-todo $(SASS_TEST_FLAGS)

test_probe:
$(SASS_TESTER) --probe-todo $(LOG_FLAGS) $(SASS_SPEC_PATH) $(SASS_TEST_FLAGS)
$(SASS_TESTER) --probe-todo $(SASS_TEST_FLAGS)

.PHONY: test test_build test_full test_probe

endif

Expand Down
20 changes: 8 additions & 12 deletions src/libsass/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_FILES([include/sass/version.h])
AC_CONFIG_AUX_DIR([script])

# These are flags passed to automake
# Though they look like gcc flags!
AM_INIT_AUTOMAKE([foreign parallel-tests -Wall])
Expand Down Expand Up @@ -93,21 +94,16 @@ the --with-sass-spec-dir=<dir> argument.
;;
esac
AC_SUBST(SASS_SPEC_PATH)

# TODO: Remove this when automake requirements are 1.12+
AC_MSG_CHECKING([whether we can use TAP mode])
tmp=`$AWK '/TEST_LOG_DRIVER/' $srcdir/GNUmakefile.in`
if test "x$tmp" != "x"; then
use_tap=yes
else
use_tap=no
fi
AC_MSG_RESULT([$use_tap])

else
# we do not really need these paths for non test build
# but automake may error if we do not define them here
SASS_SPEC_PATH=sass-spec
SASS_SASSC_PATH=sassc
AC_SUBST(SASS_SPEC_PATH)
AC_SUBST(SASS_SASSC_PATH)
fi

AM_CONDITIONAL(ENABLE_TESTS, test "x$enable_tests" = "xyes")
AM_CONDITIONAL(USE_TAP, test "x$use_tap" = "xyes")

AC_ARG_ENABLE([coverage],
[AS_HELP_STRING([--enable-coverage],
Expand Down
25 changes: 17 additions & 8 deletions src/libsass/docs/implementations.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,32 @@ There are several implementations of `libsass` for a variety of languages. Here
* [go_sass](https://github.com/suapapa/go_sass)
* [go-sass](https://github.com/SamWhited/go-sass)

### Haskell
* [hLibsass](https://github.com/jakubfijalkowski/hlibsass)
* [hSass](https://github.com/jakubfijalkowski/hsass)

### Java
* [libsass-maven-plugin](https://github.com/warmuuh/libsass-maven-plugin)
* [jsass](https://github.com/bit3/jsass)

### JavaScript
* [sass.js](https://github.com/medialize/sass.js)

### Lua
* [lua-sass](https://github.com/craigbarnes/lua-sass)

### .NET
* [libsass-net](https://github.com/darrenkopp/libsass-net)
* [NSass](https://github.com/TBAPI-0KA/NSass)
* [Sass.Net](https://github.com/andyalm/Sass.Net)
* [SharpScss](https://github.com/xoofx/SharpScss)
* [LibSassHost](https://github.com/Taritsyn/LibSassHost)

### node.js
* [node-sass](https://github.com/andrew/node-sass)

### Java
* [libsass-maven-plugin](https://github.com/warmuuh/libsass-maven-plugin)
* [jsass](https://github.com/bit3/jsass)
### Nim
* [nim-sass](https://github.com/zacharycarter/nim-sass)

### JavaScript
* [sass.js](https://github.com/medialize/sass.js)
### node.js
* [node-sass](https://github.com/sass/node-sass)

### Perl
* [CSS::Sass](https://github.com/caldwell/CSS-Sass)
Expand Down
26 changes: 16 additions & 10 deletions src/libsass/docs/unicode.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
LibSass currently expects all input to be utf8 encoded (and outputs only utf8), if you actually have any unicode characters at all. We do not support conversion between encodings, even if you declare it with a `@charset` rule. The text below was originally posted as an [issue](https://github.com/sass/libsass/issues/381) on the LibSass tracker.
LibSass currently expects all input to be utf8 encoded (and outputs only utf8), if you actually have any unicode characters at all. We do not support conversion between encodings, even if you declare it with a `@charset` rule. The text below was originally posted as an [issue](https://github.com/sass/libsass/issues/381) on the LibSass tracker. Since then the status is outdated as LibSass now expects your
input to be utf8/ascii compatible, as it has been proven that reading ANSI (e.g. single byte encodings) as utf8 can lead to unexpected
behavior, which can in the worst case lead to buffer overruns/segfaults. Therefore LibSass now checks your input to be valid utf8 encoded!

### [Declaring character encodings in CSS](http://www.w3.org/International/questions/qa-css-charset.en)

This [explains](http://www.w3.org/International/questions/qa-css-charset.en) how the character encoding of a css file is determined. Since we are only dealing with local files, we never have a HTTP header. So the precedence should be 'charset' rule, byte-order mark (BOM) or auto-detection (finally falling back to system default/UTF-8). This may not sound too hard to implement, but what about import rules? The CSS specs do not forbid the mixing of different encodings! I solved that by converting all files to UTF-8 internally. On writing there is an option to tell the tool what encoding it should be (UTF-8 by default). One can also define if it should write a BOM or not and if it should add the charset declaration.
This [explains](http://www.w3.org/International/questions/qa-css-charset.en) how the character encoding of a css file is determined. Since we are only dealing with local files, we never have a HTTP header. So the precedence should be 'charset' rule, byte-order mark (BOM) or auto-detection (finally falling back to system default/UTF-8). This may not sound too hard to implement, but what about import rules? The CSS specs do not forbid the mixing of different encodings! I [solved that](https://github.com/mgreter/webmerge/) by converting all files to UTF-8 internally. On writing there is an option to tell the tool what encoding it should be (UTF-8 by default). One can also define if it should write a BOM or not and if it should add the charset declaration.

Since my tool is written in perl, I have a lot of utilities at hand to deal with different unicode charsets. I'm pretty sure that most OSS uses [libiconv](https://www.gnu.org/software/libiconv/) to convert between different encodings. But I have now idea how easy/hard this would be to integrate platform independent (it seems doable).
Since my [tool]((https://github.com/mgreter/webmerge/)) is written in perl, I have a lot of utilities at hand to deal with different unicode charsets. I'm pretty sure that most OSS uses [ICU](http://site.icu-project.org/) or [libiconv](https://www.gnu.org/software/libiconv/) to convert between different encodings. But I have now idea how easy/hard this would be to integrate platform independent (it seems doable). ANSII (single byte encoding) to utf8 is basically just a conversion table (for every supported code-page).

### Current status on LibSass unicode support

Currently LibSass seems to handle the common UTF-8 case pretty well. I believe it should correctly support all ASCII compatible encodings (like UTF-8 or Latin-1). If all includes use the same encoding, the output should be correct (in the same encoding). It should also handle unicode chars in [selectors, variable names and other identifiers](https://github.com/hcatlin/libsass/issues/244#issuecomment-34681227). This is true for all ASCII compatible encodings. So the main incompatible encodings (I'm aware of) are UTF-16/UTF-32 (which could be converted to UTF-8 with libiconv).
LibSass should/is fully UTF (and therefore plain ASCII) compatible.

~~Currently LibSass seems to handle the common UTF-8 case pretty well. I believe it should correctly support all ASCII compatible encodings (like UTF-8 or Latin-1). If all includes use the same encoding, the output should be correct (in the same encoding). It should also handle unicode chars in [selectors, variable names and other identifiers](https://github.com/hcatlin/libsass/issues/244#issuecomment-34681227). This is true for all ASCII compatible encodings. So the main incompatible encodings (I'm aware of) are UTF-16/UTF-32 (which could be converted to UTF-8 with libiconv).~~

LibSass 3.5 will enforce that your input is either plain ASCII (chars below 127) or utf8. It does not handle anything else, but therefore ensures that the output is in a valid form. Before version 3.5 you were able to mix different code-pages, which yielded unexpected behavior.

### Current encoding auto detection

LibSass currently reads all kind of BOMs and will error out if it finds something it doesn't know how to handle! It seems that it throws away the optional UTF-8 BOM (if any is found). IMO it would be nice if users could configure that (also if a charset rule should be added to the output).
LibSass currently reads all kind of BOMs and will error out if it finds something it doesn't know how to handle! It seems that it throws away the optional UTF-8 BOM (if any is found). IMO it would be nice if users could configure that (also if a charset rule should be added to the output). But it does not really take any `@charset` into account, it always assumes your input is utf8 and ignores any given `@charset`!

### What is currently not supported

- Using non ASCII compatible encodings (like UTF-16)
- Using non ASCII compatible encodings (like UTF-16, Latin-1 etc.)
- Using non ASCII characters in different encodings in different includes

### What is missing to support the above cases

- A way to convert between encodings (like libiconv)
- A way to convert between encodings (like libiconv/ICU)
- Sniffing the charset inside the file (source is available)
- Handling the conversion on import (and export)
- Optional: Make output encoding configurable
Expand All @@ -31,9 +37,9 @@ LibSass currently reads all kind of BOMs and will error out if it finds somethin

I guess the current implementation should handle more than 99% of all real world use cases.
A) Unicode characters are still seldomly seen (as they can be written escaped)
B) It will still work if it's UTF-8 or in any of the most common known western ISO codepages.
Although I'm not sure how this applies to asian and other "exotic" codepages!
~~B) It will still work if it's UTF-8 or in any of the most common known western ISO codepages.
Although I'm not sure how this applies to asian and other "exotic" codepages!~~

I guess the biggest Problem is to have libiconv (or some other) library as a dependency. Since it contains a lot of rules for the conversions, I see it as the only way to handle this correctly. Once that is sorted out it should be pretty much straight forward to implement the missing pieces (in parser.cpp - Parser::parse should return encoding and add Parser::sniff_charset, then convert the source byte stream to UTF-8).
I guess the biggest Problem is to have libiconv/ICU (or some other) library as a dependency. Since it contains a lot of rules for the conversions, I see it as the only way to handle this correctly. Once that is sorted out it should be pretty much straight forward to implement the missing pieces (in parser.cpp - Parser::parse should return encoding and add Parser::sniff_charset, then convert the source byte stream to UTF-8).

I hope the statements above all hold true. Unicode is really not the easiest topic to wrap your head around. But since I did all the above recently in Perl, I wanted to document it here. Feel free to extend or criticize.
3 changes: 3 additions & 0 deletions src/libsass/include/sass/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ ADDAPI size_t ADDCALL sass_compiler_get_callee_stack_size(struct Sass_Compiler*
ADDAPI Sass_Callee_Entry ADDCALL sass_compiler_get_last_callee(struct Sass_Compiler* compiler);
ADDAPI Sass_Callee_Entry ADDCALL sass_compiler_get_callee_entry(struct Sass_Compiler* compiler, size_t idx);

// Push function for import extenions
ADDAPI void ADDCALL sass_option_push_import_extension (struct Sass_Options* options, const char* ext);

// Push function for paths (no manipulation support for now)
ADDAPI void ADDCALL sass_option_push_plugin_path (struct Sass_Options* options, const char* path);
ADDAPI void ADDCALL sass_option_push_include_path (struct Sass_Options* options, const char* path);
Expand Down
2 changes: 1 addition & 1 deletion src/libsass/script/tap-runner
Original file line number Diff line number Diff line change
@@ -1 +1 @@
$@ | tapout tap
$@ $TEST_FLAGS --tap --silent | tapout tap
50 changes: 48 additions & 2 deletions src/libsass/src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ namespace Sass {
// include_paths.push_back(CWD);

// collect more paths from different options
collect_extensions(c_options.extension);
collect_extensions(c_options.extensions);
collect_include_paths(c_options.include_path);
collect_include_paths(c_options.include_paths);
collect_plugin_paths(c_options.plugin_path);
Expand Down Expand Up @@ -166,6 +168,37 @@ namespace Sass {
{
}

void Context::collect_extensions(const char* exts_str)
{
if (exts_str) {
const char* beg = exts_str;
const char* end = Prelexer::find_first<PATH_SEP>(beg);

while (end) {
std::string ext(beg, end - beg);
if (!ext.empty()) {
extensions.push_back(ext);
}
beg = end + 1;
end = Prelexer::find_first<PATH_SEP>(beg);
}

std::string ext(beg);
if (!ext.empty()) {
extensions.push_back(ext);
}
}
}

void Context::collect_extensions(string_list* paths_array)
{
while (paths_array)
{
collect_extensions(paths_array->string);
paths_array = paths_array->next;
}
}

void Context::collect_include_paths(const char* paths_str)
{
if (paths_str) {
Expand Down Expand Up @@ -236,15 +269,20 @@ namespace Sass {
// looks for alternatives and returns a list from one directory
std::vector<Include> Context::find_includes(const Importer& import)
{
// include configured extensions
std::vector<std::string> exts(File::defaultExtensions);
if (extensions.size() > 0) {
exts.insert(exts.end(), extensions.begin(), extensions.end());
}
// make sure we resolve against an absolute path
std::string base_path(rel2abs(import.base_path));
// first try to resolve the load path relative to the base path
std::vector<Include> vec(resolve_includes(base_path, import.imp_path));
std::vector<Include> vec(resolve_includes(base_path, import.imp_path, exts));
// then search in every include path (but only if nothing found yet)
for (size_t i = 0, S = include_paths.size(); vec.size() == 0 && i < S; ++i)
{
// call resolve_includes and individual base path and append all results
std::vector<Include> resolved(resolve_includes(include_paths[i], import.imp_path));
std::vector<Include> resolved(resolve_includes(include_paths[i], import.imp_path, exts));
if (resolved.size()) vec.insert(vec.end(), resolved.begin(), resolved.end());
}
// return vector
Expand Down Expand Up @@ -365,6 +403,14 @@ namespace Sass {
// process the resolved entry
else if (resolved.size() == 1) {
bool use_cache = c_importers.size() == 0;
if (resolved[0].deprecated) {
// emit deprecation warning when import resolves to a .css file
deprecated(
"Including .css files with @import is non-standard behaviour which will be removed in future versions of LibSass.",
"Use a custom importer to maintain this behaviour. Check your implementations documentation on how to create a custom importer.",
true, pstate
);
}
// use cache for the resource loading
if (use_cache && sheets.count(resolved[0].abs_path)) return resolved[0];
// try to read the content of the resolved file entry
Expand Down
3 changes: 3 additions & 0 deletions src/libsass/src/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ namespace Sass {

std::vector<std::string> plugin_paths; // relative paths to load plugins
std::vector<std::string> include_paths; // lookup paths for includes
std::vector<std::string> extensions; // lookup extensions for imports`



Expand Down Expand Up @@ -109,6 +110,8 @@ namespace Sass {
void collect_plugin_paths(string_list* paths_array);
void collect_include_paths(const char* paths_str);
void collect_include_paths(string_list* paths_array);
void collect_extensions(const char* extensions_str);
void collect_extensions(string_list* extensions_array);
std::string format_embedded_source_map();
std::string format_source_mapping_url(const std::string& out_path);

Expand Down
2 changes: 1 addition & 1 deletion src/libsass/src/cssize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ namespace Sass {

std::string m1 = std::string(mq1->is_restricted() ? "only" : mq1->is_negated() ? "not" : "");
std::string t1 = mq1->media_type() ? mq1->media_type()->to_string(ctx.c_options) : "";
std::string m2 = std::string(mq2->is_restricted() ? "only" : mq1->is_negated() ? "not" : "");
std::string m2 = std::string(mq2->is_restricted() ? "only" : mq2->is_negated() ? "not" : "");
std::string t2 = mq2->media_type() ? mq2->media_type()->to_string(ctx.c_options) : "";


Expand Down
1 change: 1 addition & 0 deletions src/libsass/src/debugger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ inline void debug_ast(AST_Node_Ptr node, std::string ind, Env* env)
Number_Ptr expression = Cast<Number>(node);
std::cerr << ind << "Number " << expression;
std::cerr << " (" << pstate_source_position(node) << ")";
std::cerr << " [delayed: " << expression->is_delayed() << "] ";
std::cerr << " [interpolant: " << expression->is_interpolant() << "] ";
std::cerr << " [" << expression->value() << expression->unit() << "]" <<
" [hash: " << expression->hash() << "] " <<
Expand Down
Loading

0 comments on commit 7ec14df

Please sign in to comment.