Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supply a Root stringifier #82

Merged
merged 2 commits into from
Jul 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/less-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Comment from 'postcss/lib/comment';
import Import from './import';
import Parser from 'postcss/lib/parser';
import Rule from './rule';
import Root from './root';
import findExtendRule from './find-extend-rule';
import isMixinToken from './is-mixin-token';
import lessTokenizer from './less-tokenize';
Expand All @@ -10,6 +11,14 @@ const blockCommentEndPattern = /\*\/$/;

export default class LessParser extends Parser {

constructor (input) {
super(input);

this.root = new Root();
this.current = this.root;
this.root.source = { input, start: { line: 1, column: 1 } };
}

atrule (token) {
if (token[1] === '@import') {
this.import(token);
Expand Down
14 changes: 14 additions & 0 deletions lib/root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import PostCssRoot from 'postcss/lib/root';
import stringify from './less-stringify';

export default class Root extends PostCssRoot {
toString (stringifier) {
if (!stringifier) {
stringifier = {
stringify
};
}

return super.toString(stringifier);
}
}
12 changes: 12 additions & 0 deletions test/postcss.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,16 @@ describe('#postcss', () => {
done();
}).catch(done);
});

it('should create its own Root node stringifier (#82)', (done) => {
const lessText = '@import "foo.less"';

postcss()
.process(lessText, { syntax: lessSyntax })
.then((result) => {
expect(result.root.toString()).to.eql(lessText);

done();
}).catch(done);
});
});