Skip to content

Commit

Permalink
chore(release): 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bencergazda committed Oct 30, 2019
1 parent ea9f65b commit d625bac
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 82 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Changelog

## 1.1.0 (2019-10-30)

### Features

* Adding support for Dart Sass ([ea9f65b5](https://github.com/body-builder/jsass/commit/ea9f65b5e27e1abd648f7f6743748a89456c1f33))

### API changes

* Changing the names (and file path) of many classes ([adefaa71](https://github.com/body-builder/jsass/commit/adefaa71c77a22d6f3f36e6ce5ce184bd90d98f6))

To be more straightforward, as we are supporting not exclusively `node-sass`

| Old name | New name |
|---|---|
| JSFunctionsToNodeSass | JSFunctionsToSass |
| JSVarsToNodeSass | JSVarsToSass |
| NodeSassVarsToJs | SassVarsToJS |
| JSVarsToSassString | JSVarsToSassData |

(We should create a new major version in normal case, but since the package is quite new (1wo), we make an exception this time. Hopefully we will not have to change the API in the near future.)

## 1.0.0 (2019-10-18)
Initial release
43 changes: 23 additions & 20 deletions dist/JSFunctionsToNodeSass.js → dist/JSFunctionsToSass.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,37 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d

var kindOf = require('kind-of');

var JSVarsToNodeSass = require('./JSVarsToNodeSass');
var JSVarsToSass = require('./JSVarsToSass');

var NodeSassVarsToJs = require('./NodeSassVarsToJs');
var SassVarsToJS = require('./SassVarsToJS');

var JSFunctionsToNodeSass =
var JSFunctionsToSass =
/*#__PURE__*/
function () {
function JSFunctionsToNodeSass(options) {
_classCallCheck(this, JSFunctionsToNodeSass);
function JSFunctionsToSass(options) {
_classCallCheck(this, JSFunctionsToSass);

this._default_options = {
listSeparator: ', ',
quote: "'" // prettier-ignore

};
this._options = Object.assign({}, this._default_options, options);
this._jsVarsToNodeSass = new JSVarsToNodeSass();
this._nodeSassVarsToJs = new NodeSassVarsToJs();
this.implementation = this._options.implementation || require('node-sass');
this._jsVarsToSass = new JSVarsToSass({
implementation: this.implementation
});
this._sassVarsToJS = new SassVarsToJS();
this.convert = this._wrapObject;
}
/**
* Parses the Sass function declaration string and returns the extracted information in an Object
* @param key The Sass function declaration string (the `key` of the node-sass `options.functions` object), eg: 'headings($from: 0, $to: 6)'
* @param key The Sass function declaration string (the `key` of the Sass `options.functions` object), eg: 'headings($from: 0, $to: 6)'
* @returns {null|{name: string, args: string[], spreadArgs: number[]}}
*/


_createClass(JSFunctionsToNodeSass, [{
_createClass(JSFunctionsToSass, [{
key: "_getSassFunctionData",
value: function _getSassFunctionData(key) {
var matches = key.replace(')', '').split('('); // The name of the Sass function
Expand Down Expand Up @@ -97,19 +100,19 @@ function () {
}

if (kindOf(args) !== 'array') {
throw new Error('JSFunctionsToSass - do not forget to pass the arguments from node-sass!');
throw new Error('JSFunctionsToSass - do not forget to pass the arguments from Sass!');
}

options = Object.assign({}, this._options, options);

var sassFunctionData = this._getSassFunctionData(sass_decl);

var done = args.slice(-1)[0];
var sassTypeArgs = args.slice(0, -1); // Converting raw node-sass type arguments to JS
var sassTypeArgs = args.slice(0, -1); // Converting raw Sass type arguments to JS

var jsTypeArgs = [];
sassTypeArgs.forEach(function (sassTypeArg, index) {
var jsTypeArg = _this._nodeSassVarsToJs._convert(sassTypeArg, options); // If the Sass function expects the data to be spread for the current argument, we spread the arguments also for the JS function.
var jsTypeArg = _this._sassVarsToJS._convert(sassTypeArg, options); // If the Sass function expects the data to be spread for the current argument, we spread the arguments also for the JS function.


if (kindOf(jsTypeArg) === 'array' && sassFunctionData.spreadArgs.indexOf(index) !== -1) {
Expand All @@ -124,24 +127,24 @@ function () {
try {
value = fn.apply(null, jsTypeArgs);
} catch (error) {
return this._jsVarsToNodeSass._convert(this._createError(error), options);
} // Returning JS values in node-sass types
return this._jsVarsToSass._convert(this._createError(error), options);
} // Returning JS values in Sass types


if (value instanceof Promise) {
if (kindOf(done) !== 'function') {
throw new Error('JSFunctionsToSass - no callback provided from node-sass!');
throw new Error('JSFunctionsToSass - no callback provided from Sass!');
} // TODO Finish error handling tests
// eslint-disable-next-line prettier/prettier


value["catch"](function (error) {
return done(_this._jsVarsToNodeSass._convert(_this._createError(error), options));
return done(_this._jsVarsToSass._convert(_this._createError(error), options));
}).then(function (resolved) {
return done(_this._jsVarsToNodeSass._convert(resolved, options));
return done(_this._jsVarsToSass._convert(resolved, options));
});
} else {
return this._jsVarsToNodeSass._convert(value, options);
return this._jsVarsToSass._convert(value, options);
}
}
}, {
Expand Down Expand Up @@ -174,7 +177,7 @@ function () {
}
}]);

return JSFunctionsToNodeSass;
return JSFunctionsToSass;
}();

module.exports = JSFunctionsToNodeSass;
module.exports = JSFunctionsToSass;
43 changes: 24 additions & 19 deletions dist/JSVarsToNodeSass.js → dist/JSVarsToSass.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,28 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d

var colorString = require('color-string');

var sass = require('node-sass');

var kindOf = require('kind-of');

var JSVarsToNodeSass =
var JSVarsToSass =
/*#__PURE__*/
function () {
function JSVarsToNodeSass(options) {
_classCallCheck(this, JSVarsToNodeSass);
function JSVarsToSass(options) {
_classCallCheck(this, JSVarsToSass);

var _default_options = {
listSeparator: ', ',
strict: true
};
this._options = Object.assign({}, _default_options, options);
this.implementation = this._options.implementation || require('node-sass');
this.unitKeywords_spec = ['cm', 'mm', 'in', 'px', 'pt', 'pc', 'em', 'ex', 'ch', 'rem', 'vh', 'vw', 'vmin', 'vmax', '%'];
this.unitKeywords_experimental = ['Q', 'cap', 'ic', 'lh', 'rlh', 'vi', 'vb'];
this.unitKeywords = [].concat(_toConsumableArray(this.unitKeywords_spec), _toConsumableArray(this.unitKeywords_experimental));
this.convert = this._convert;
return this;
}

_createClass(JSVarsToNodeSass, [{
_createClass(JSVarsToSass, [{
key: "_isVariable",
value: function _isVariable(value) {
return value.startsWith('$');
Expand All @@ -67,7 +66,7 @@ function () {
if (arguments[1] !== undefined) {
options = _defineProperty({}, options, arguments[1]);
} else {
throw new Error('JSVarsToNodeSass: setOption needs an option');
throw new Error('JSVarsToSass: setOption needs an option');
}
}

Expand Down Expand Up @@ -162,29 +161,35 @@ function () {

default:
if (this._options.strict === false) {
return sass.types.String("[JS ".concat(type.replace(/./, function (x) {
return new this.implementation.types.String("[JS ".concat(type.replace(/./, function (x) {
return x.toUpperCase();
}), "]"));
} else {
throw new Error('JSVarsToNodeSass - Unexpected variable type `' + kindOf(value) + '`');
throw new Error('JSVarsToSass - Unexpected variable type `' + kindOf(value) + '`');
}

}
}
}, {
key: "_convert_null",
value: function _convert_null(value, options) {
return sass.types.Null();
return this.implementation.types.Null.NULL;
}
}, {
key: "_convert_boolean",
value: function _convert_boolean(value, options) {
return sass.types.Boolean(value);
switch (value) {
case true:
return this.implementation.types.Boolean.TRUE;

case false:
return this.implementation.types.Boolean.FALSE;
}
}
}, {
key: "_convert_error",
value: function _convert_error(value, options) {
return sass.types.Error(value.message);
return new this.implementation.types.Error(value.message);
}
/**
* Converts a JS Number or a { value: Number, unit: String } object to a SassNumber instance
Expand All @@ -204,7 +209,7 @@ function () {
};
}

return sass.types.Number(value.value, value.unit);
return new this.implementation.types.Number(value.value, value.unit);
}
/**
* Converts a JS String to a SassString instance
Expand All @@ -230,7 +235,7 @@ function () {
return this._convert_number(hasUnit, options);
}

return sass.types.String(value);
return new this.implementation.types.String(value);
}
}, {
key: "_convert_color",
Expand All @@ -239,15 +244,15 @@ function () {
g = _ref.g,
b = _ref.b,
a = _ref.a;
return new sass.types.Color(r, g, b, a);
return new this.implementation.types.Color(r, g, b, a);
}
}, {
key: "_convert_array",
value: function _convert_array(value, options) {
var _this = this;

if (kindOf(value) !== 'array') throw new Error('JSFunctionsToSass - _convert_array() needs an array, but got `' + kindOf(value) + '`');
var list = new sass.types.List(value.length, options.listSeparator.trim() === ',');
var list = new this.implementation.types.List(value.length, options.listSeparator.trim() === ',');
value.map(function (item, index) {
return list.setValue(index, _this._convert(item, options));
});
Expand All @@ -259,7 +264,7 @@ function () {
var _this2 = this;

if (kindOf(value) !== 'object') throw new Error('JSFunctionsToSass - _convert_object() needs an array, but got `' + kindOf(value) + '`');
var map = new sass.types.Map(Object.keys(value).length);
var map = new this.implementation.types.Map(Object.keys(value).length);
Object.keys(value).map(function (key, index) {
map.setKey(index, _this2._convert(key, options));
map.setValue(index, _this2._convert(value[key], options));
Expand All @@ -268,7 +273,7 @@ function () {
}
}]);

return JSVarsToNodeSass;
return JSVarsToSass;
}();

module.exports = JSVarsToNodeSass;
module.exports = JSVarsToSass;
41 changes: 22 additions & 19 deletions dist/JSVarsToSassString.js → dist/JSVarsToSassData.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || func

var kindOf = require('kind-of');

var JSVarsToNodeSass = require('./JSVarsToNodeSass');
var JSVarsToSass = require('./JSVarsToSass');

var NodeSassVarsToJs = require('./NodeSassVarsToJs');
var SassVarsToJS = require('./SassVarsToJS');
/**
* Converts JS variables (Bool, Number, String, Array, Object) to the 'corresponding' Sass variable definitions (Array -> List, Object -> Map, String -> String|Color|Unit, etc...)
* Important: This Class outputs string data, which can be passed to the `data` option of node-sass (see https://github.com/sass/node-sass#data)
* Important: This Class outputs string data, which can be passed to the `data` option of Sass (see https://github.com/sass/node-sass#data)
*/


var JSVarsToSassString =
var JSVarsToSassData =
/*#__PURE__*/
function (_JSVarsToNodeSass) {
_inherits(JSVarsToSassString, _JSVarsToNodeSass);
function (_JSVarsToSass) {
_inherits(JSVarsToSassData, _JSVarsToSass);

/**
* @param options
* @returns {{setOption: JSVarsToSassString.setOption|*, convert: JSVarsToSassString._iterator|*}}
* @returns {{setOption: JSVarsToSassData.setOption|*, convert: JSVarsToSassData._iterator|*}}
* @constructor
*/
function JSVarsToSassString(options) {
function JSVarsToSassData(options) {
var _this;

_classCallCheck(this, JSVarsToSassString);
_classCallCheck(this, JSVarsToSassData);

// prettier-ignore
_this = _possibleConstructorReturn(this, _getPrototypeOf(JSVarsToSassString).call(this, Object.assign({}, {
_this = _possibleConstructorReturn(this, _getPrototypeOf(JSVarsToSassData).call(this, Object.assign({}, {
syntax: 'scss',
quotedKeys: true,
// Though Sass allows map keys to be of any Sass type, it is recommended to use quoted strings to avoid confusing problems (see https://sass-lang.com/documentation/values/maps)
Expand All @@ -61,14 +61,17 @@ function (_JSVarsToNodeSass) {
important: false,
"default": false,
global: false
}
},
implementation: options.implementation || require('node-sass')
}, options)));
_this.convert = _this._iterator;
_this._nodeSassVarsToJs = new NodeSassVarsToJs();
_this._sassVarsToJS = new SassVarsToJS({
implementation: _this._options.implementation
});
return _possibleConstructorReturn(_this, _assertThisInitialized(_this));
}

_createClass(JSVarsToSassString, [{
_createClass(JSVarsToSassData, [{
key: "_stringify",
value: function _stringify(value, options) {
return options.quote + value + options.quote;
Expand All @@ -77,10 +80,10 @@ function (_JSVarsToNodeSass) {
key: "_convert",
value: function _convert(value) {
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this._options;
value = _get(_getPrototypeOf(JSVarsToSassString.prototype), "_convert", this).call(this, value, options); // The super function may itself return value in edge-cases, and those values are in Sass types. We need to resolve it.
value = _get(_getPrototypeOf(JSVarsToSassData.prototype), "_convert", this).call(this, value, options); // The super function may itself return value in edge-cases, and those values are in Sass types. We need to resolve it.

if (kindOf(value).startsWith('sass')) {
return this._convert(this._nodeSassVarsToJs.convert(value), options);
return this._convert(this._sassVarsToJS.convert(value), options);
}

return value;
Expand All @@ -94,7 +97,7 @@ function (_JSVarsToNodeSass) {
key: "_convert_boolean",
value: function _convert_boolean(value, options) {
return JSON.stringify(value);
} // _convert_error is implemented only because of JSFunctionsToNodeSass, we "skip" it here.
} // _convert_error is implemented only because of JSFunctionsToSass, we "skip" it here.

}, {
key: "_convert_error",
Expand Down Expand Up @@ -201,7 +204,7 @@ function (_JSVarsToNodeSass) {
}
}]);

return JSVarsToSassString;
}(JSVarsToNodeSass);
return JSVarsToSassData;
}(JSVarsToSass);

module.exports = JSVarsToSassString;
module.exports = JSVarsToSassData;
Loading

0 comments on commit d625bac

Please sign in to comment.