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

Line comment's text value not returned in the AST #2861

Closed
vecerek opened this issue Apr 4, 2016 · 2 comments
Closed

Line comment's text value not returned in the AST #2861

vecerek opened this issue Apr 4, 2016 · 2 comments

Comments

@vecerek
Copy link

vecerek commented Apr 4, 2016

Hi Guys!

I'd like to ask you, what happens to the text value of line comments after parsing? When I get the AST, their value is an empty string. Block comment values are returned correctly.
Here I see, that the parser saves the comment's text value regardless its type.
Should I pass some extra option to the parser, or is it a bug?

Thanks in advance :)

This is my code for parsing:

var less = require('/usr/local/lib/node_modules/less/lib/less-node')
    , fs = require('fs')
    , path = require('path');

module.exports = {
    parse: function(src, isStdin) {
        // Parses a Less file and outputs its AST

        var visit = function(o) {
            // Attaches the node type to the necessary objects
            for (var p in o) {
                if (typeof o[p] == 'object') visit(o[p]);
            }
            if (o != null && o != "") {
                if ("type" in o) o["class"] = o.type;
            }
        };

        var code = src;
        var options = {};

        if (!isStdin) {
            code = fs.readFileSync(src, 'utf8').toString();
            options = {
                filename: path.resolve(src)
            }
        }

        return less.parse(code, options, function(e, tree) {
            if (!e) {
                visit(tree);
                console.log(JSON.stringify(tree, null, 2));
            } else {
                e.class = "error"
                console.log(JSON.stringify(e));
            }
        });
    }
};

And an extract from its output:

{
          "value": "/* Color Properties */",
          "isLineComment": false,
          "currentFileInfo": {
            "filename": "/Users/attila/Projects/OpenSource/less2sass-test/less2sass/tmp/less/test_rules.less",
            "rootpath": "",
            "currentDirectory": "/Users/attila/Projects/OpenSource/less2sass-test/less2sass/tmp/less/",
            "entryPath": "/Users/attila/Projects/OpenSource/less2sass-test/less2sass/tmp/less/",
            "rootFilename": "/Users/attila/Projects/OpenSource/less2sass-test/less2sass/tmp/less/test_rules.less"
          },
          "class": "Comment"
},
{
          "value": "",
          "isLineComment": true,
          "currentFileInfo": {
            "filename": "/Users/attila/Projects/OpenSource/less2sass-test/less2sass/tmp/less/test_rules.less",
            "rootpath": "",
            "currentDirectory": "/Users/attila/Projects/OpenSource/less2sass-test/less2sass/tmp/less/",
            "entryPath": "/Users/attila/Projects/OpenSource/less2sass-test/less2sass/tmp/less/",
            "rootFilename": "/Users/attila/Projects/OpenSource/less2sass-test/less2sass/tmp/less/test_rules.less"
          },
          "class": "Comment"
}
@matthew-dean
Copy link
Member

Merged 4 days ago: #2858

@vecerek
Copy link
Author

vecerek commented Apr 5, 2016

Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants