postcss-less
Advanced tools
Comparing version 0.10.0 to 0.11.0
@@ -138,2 +138,5 @@ 'use strict'; | ||
this.current.important = this.current.selector.indexOf('!important') >= 0; | ||
this.pos--; | ||
this.end(this.tokens[this.pos]); | ||
@@ -140,0 +143,0 @@ } |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,i,n){return i&&e(t.prototype,i),n&&e(t,n),t}}(),_comment=require("postcss/lib/comment"),_comment2=_interopRequireDefault(_comment),_parser=require("postcss/lib/parser"),_parser2=_interopRequireDefault(_parser),_findExtendRule=require("./find-extend-rule"),_findExtendRule2=_interopRequireDefault(_findExtendRule),_isMixinToken=require("./is-mixin-token"),_isMixinToken2=_interopRequireDefault(_isMixinToken),_lessTokenize=require("./less-tokenize"),_lessTokenize2=_interopRequireDefault(_lessTokenize),blockCommentEndPattern=/\*\/$/,LessParser=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,Object.getPrototypeOf(t).apply(this,arguments))}return _inherits(t,e),_createClass(t,[{key:"tokenize",value:function(){this.tokens=(0,_lessTokenize2["default"])(this.input)}},{key:"comment",value:function(e){var t=new _comment2["default"],i=e[1],n=i.slice(2).replace(blockCommentEndPattern,"");if(this.init(t,e[2],e[3]),t.source.end={line:e[4],column:e[5]},t.raws.content=i,t.raws.begin=i[0]+i[1],t.inline="inline"===e[6],t.block=!t.inline,/^\s*$/.test(n))t.text="",t.raws.left=n,t.raws.right="";else{var s=n.match(/^(\s*)([^]*[^\s])(\s*)$/);t.text=s[2],t.raws.left=s[1]||" ",t.raws.right=s[3]||" "}}},{key:"createRule",value:function(e){this.rule(this.tokens.slice(e.start,this.pos+1)),e.params[0]&&(e.isMixin||e.isExtendRule)&&this.raw(this.current,"params",e.params)}},{key:"createDeclaration",value:function(e){this.decl(this.tokens.slice(e.start,this.pos+1))}},{key:"ruleWithoutBody",value:function(e){this.createRule(e),this.current.ruleWithoutBody=!0,delete this.current.nodes,this.current.extendRule=this.current.selector.indexOf("&:extend")>=0,this.current.important=this.current.selector.indexOf("!important")>=0,this.end(this.tokens[this.pos])}},{key:"processEndOfRule",value:function(e){var t=e.start;if(e.isExtendRule||e.isMixin)return this.ruleWithoutBody(e),!0;if(e.colon){if(e.isEndOfBlock)for(;this.pos>t;){var i=this.tokens[this.pos][0];if("space"!==i&&"comment"!==i)break;this.pos-=1}return this.createDeclaration({start:t}),!0}return!1}},{key:"word",value:function(){var e=!1,t=!1,i=null,n=0,s=this.pos,r=(0,_isMixinToken2["default"])(this.tokens[s]),o=Boolean((0,_findExtendRule2["default"])(this.tokens,s)),u=[];for(this.pos+=1;this.pos<this.tokens.length;){var a=this.tokens[this.pos],l=a[0];if("("===l)i||(i=a),n+=1;else if(0===n){if(";"===l){var c=this.processEndOfRule({start:s,params:u,colon:t,isMixin:r,isExtendRule:o});if(c)return;break}if("{"===l)return void this.createRule({start:s,params:u,isMixin:r});if("}"===l){this.pos-=1,e=!0;break}":"===l&&(t=!0)}else")"===l&&(n-=1,0===n&&(i=null));(n||"brackets"===l||u[0])&&u.push(a),this.pos+=1}if(this.pos===this.tokens.length&&(this.pos-=1,e=!0),n>0&&this.unclosedBracket(i),e){var f=this.processEndOfRule({start:s,params:u,colon:t,isMixin:r,isExtendRule:o,isEndOfBlock:!0});if(f)return}this.unknownWord(s)}}]),t}(_parser2["default"]);exports["default"]=LessParser,module.exports=exports["default"]; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var s=0;s<t.length;s++){var i=t[s];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,s,i){return s&&e(t.prototype,s),i&&e(t,i),t}}(),_comment=require("postcss/lib/comment"),_comment2=_interopRequireDefault(_comment),_parser=require("postcss/lib/parser"),_parser2=_interopRequireDefault(_parser),_findExtendRule=require("./find-extend-rule"),_findExtendRule2=_interopRequireDefault(_findExtendRule),_isMixinToken=require("./is-mixin-token"),_isMixinToken2=_interopRequireDefault(_isMixinToken),_lessTokenize=require("./less-tokenize"),_lessTokenize2=_interopRequireDefault(_lessTokenize),blockCommentEndPattern=/\*\/$/,LessParser=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,Object.getPrototypeOf(t).apply(this,arguments))}return _inherits(t,e),_createClass(t,[{key:"tokenize",value:function(){this.tokens=(0,_lessTokenize2["default"])(this.input)}},{key:"comment",value:function(e){var t=new _comment2["default"],s=e[1],i=s.slice(2).replace(blockCommentEndPattern,"");if(this.init(t,e[2],e[3]),t.source.end={line:e[4],column:e[5]},t.raws.content=s,t.raws.begin=s[0]+s[1],t.inline="inline"===e[6],t.block=!t.inline,/^\s*$/.test(i))t.text="",t.raws.left=i,t.raws.right="";else{var n=i.match(/^(\s*)([^]*[^\s])(\s*)$/);t.text=n[2],t.raws.left=n[1]||" ",t.raws.right=n[3]||" "}}},{key:"createRule",value:function(e){this.rule(this.tokens.slice(e.start,this.pos+1)),e.params[0]&&(e.isMixin||e.isExtendRule)&&this.raw(this.current,"params",e.params)}},{key:"createDeclaration",value:function(e){this.decl(this.tokens.slice(e.start,this.pos+1))}},{key:"ruleWithoutBody",value:function(e){this.createRule(e),this.current.ruleWithoutBody=!0,delete this.current.nodes,this.current.extendRule=this.current.selector.indexOf("&:extend")>=0,this.current.important=this.current.selector.indexOf("!important")>=0,this.pos--,this.end(this.tokens[this.pos])}},{key:"processEndOfRule",value:function(e){var t=e.start;if(e.isExtendRule||e.isMixin)return this.ruleWithoutBody(e),!0;if(e.colon){if(e.isEndOfBlock)for(;this.pos>t;){var s=this.tokens[this.pos][0];if("space"!==s&&"comment"!==s)break;this.pos-=1}return this.createDeclaration({start:t}),!0}return!1}},{key:"word",value:function(){var e=!1,t=!1,s=null,i=0,n=this.pos,r=(0,_isMixinToken2["default"])(this.tokens[n]),o=Boolean((0,_findExtendRule2["default"])(this.tokens,n)),u=[];for(this.pos+=1;this.pos<this.tokens.length;){var a=this.tokens[this.pos],l=a[0];if("("===l)s||(s=a),i+=1;else if(0===i){if(";"===l){var c=this.processEndOfRule({start:n,params:u,colon:t,isMixin:r,isExtendRule:o});if(c)return;break}if("{"===l)return void this.createRule({start:n,params:u,isMixin:r});if("}"===l){this.pos-=1,e=!0;break}":"===l&&(t=!0)}else")"===l&&(i-=1,0===i&&(s=null));(i||"brackets"===l||u[0])&&u.push(a),this.pos+=1}if(this.pos===this.tokens.length&&(this.pos-=1,e=!0),i>0&&this.unclosedBracket(s),e){var f=this.processEndOfRule({start:n,params:u,colon:t,isMixin:r,isExtendRule:o,isEndOfBlock:!0});if(f)return}this.unknownWord(n)}}]),t}(_parser2["default"]);exports["default"]=LessParser,module.exports=exports["default"]; |
@@ -42,2 +42,31 @@ 'use strict'; | ||
} | ||
}, { | ||
key: 'block', | ||
value: function block(node, start) { | ||
var ruleWithoutBody = node.ruleWithoutBody; | ||
var between = this.raw(node, 'between', 'beforeOpen'); | ||
var after = ''; | ||
if (ruleWithoutBody) { | ||
this.builder(start + between, node, 'start'); | ||
} else { | ||
this.builder(start + between + '{', node, 'start'); | ||
} | ||
if (node.nodes && node.nodes.length) { | ||
this.body(node); | ||
after = this.raw(node, 'after'); | ||
} else { | ||
after = this.raw(node, 'after', 'emptyBody'); | ||
} | ||
if (after) { | ||
this.builder(after); | ||
} | ||
if (!ruleWithoutBody) { | ||
this.builder('}', node, 'end'); | ||
} | ||
} | ||
}]); | ||
@@ -44,0 +73,0 @@ |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),_stringifier=require("postcss/lib/stringifier"),_stringifier2=_interopRequireDefault(_stringifier),LessStringifier=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,Object.getPrototypeOf(t).apply(this,arguments))}return _inherits(t,e),_createClass(t,[{key:"comment",value:function(e){var t=this.raw(e,"left","commentLeft"),r=this.raw(e,"right","commentRight");e.inline?this.builder("//"+t+e.text+r,e):this.builder("/*"+t+e.text+r+"*/",e)}}]),t}(_stringifier2["default"]);exports["default"]=LessStringifier,module.exports=exports["default"]; | ||
"use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{"default":e}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _possibleConstructorReturn(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(exports,"__esModule",{value:!0});var _createClass=function(){function e(e,t){for(var r=0;r<t.length;r++){var i=t[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(t,r,i){return r&&e(t.prototype,r),i&&e(t,i),t}}(),_stringifier=require("postcss/lib/stringifier"),_stringifier2=_interopRequireDefault(_stringifier),LessStringifier=function(e){function t(){return _classCallCheck(this,t),_possibleConstructorReturn(this,Object.getPrototypeOf(t).apply(this,arguments))}return _inherits(t,e),_createClass(t,[{key:"comment",value:function(e){var t=this.raw(e,"left","commentLeft"),r=this.raw(e,"right","commentRight");e.inline?this.builder("//"+t+e.text+r,e):this.builder("/*"+t+e.text+r+"*/",e)}},{key:"block",value:function(e,t){var r=e.ruleWithoutBody,i=this.raw(e,"between","beforeOpen"),n="";r?this.builder(t+i,e,"start"):this.builder(t+i+"{",e,"start"),e.nodes&&e.nodes.length?(this.body(e),n=this.raw(e,"after")):n=this.raw(e,"after","emptyBody"),n&&this.builder(n),r||this.builder("}",e,"end")}}]),t}(_stringifier2["default"]);exports["default"]=LessStringifier,module.exports=exports["default"]; |
{ | ||
"name": "postcss-less", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"description": "LESS parser for PostCSS", | ||
@@ -12,2 +12,6 @@ "keywords": [ | ||
], | ||
"main": "dist/less-syntax.js", | ||
"files": [ | ||
"dist/*.js" | ||
], | ||
"author": "Denys Kniazevych <webschik@gmail.com>", | ||
@@ -41,3 +45,2 @@ "contributors": [ | ||
"chai": "^3.5.0", | ||
"eslint": "^2.5.1", | ||
"eslint-config-strict": "^8.5.0", | ||
@@ -48,3 +51,2 @@ "eslint-plugin-filenames": "^0.2.0", | ||
"gulp-eslint": "^2.0.0", | ||
"gulp-jscs": "^3.0.2", | ||
"gulp-json-editor": "2.2.1", | ||
@@ -51,0 +53,0 @@ "gulp-mocha": "^2.2.0", |
@@ -1,2 +0,2 @@ | ||
# PostCSS LESS Syntax - Work in Progress | ||
# PostCSS LESS Syntax | ||
@@ -60,16 +60,4 @@ [PostCSS]: https://github.com/postcss/postcss | ||
one will automatically convert single line comments into block comments. | ||
If you need to get inline comments, use stringifier from `postcss-less` module: | ||
If you need to get inline comments, use [custom PostCSSLess stringifier](#stringifier) | ||
````js | ||
import postCssLess from 'postcss-less'; | ||
const root = postCssLess.parse('// Hello world'); | ||
root.first.toString(); // returns '/* Hello world */' | ||
root.first.toString({ | ||
stringify: postCssLess.stringify | ||
}); // returns '// Hello world' | ||
```` | ||
### Rule node | ||
@@ -165,5 +153,35 @@ [PostCSS Rule Node](https://github.com/postcss/postcss/blob/master/docs/api.md#rule-node) | ||
### Stylelint support | ||
`postcss-less` parser **is not compatible** with `Stylelint`, because `Stylelint` can't process syntax tree from `postcss-less`! | ||
### Stringifier | ||
If you need to have LESS code without PostCSS transformation, you have to specify a custom stringifier: | ||
````js | ||
import postcss from 'postcss'; | ||
import postcssLess from 'postcss-less'; | ||
import stringify from 'postcss-less/less-stringify'; | ||
const lessCode = ` | ||
// Non-css comment | ||
.container { | ||
.mixin-1(); | ||
.mixin-2; | ||
.mixin-3 (@width: 100px) { | ||
width: @width; | ||
} | ||
} | ||
.rotation(@deg:5deg){ | ||
.transform(rotate(@deg)); | ||
} | ||
`; | ||
postcss().process(less, { | ||
syntax: postcssLess, | ||
stringifier: stringify | ||
}).then((result) => { | ||
console.log(result.content); // this will be value of `lessCode` without changing of comment nodes and mixins | ||
}); | ||
```` | ||
## Contribution | ||
@@ -170,0 +188,0 @@ Please, check our guidelines: [CONTRIBUTING.md](./CONTRIBUTING.md) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 2 instances in 1 package
22
8
191
35404
20
399
1