enable loc #2

Closed
wants to merge 1 commit into
from

3 participants

@ForbesLindesay
Collaborator

Having the line number can be extremely useful and isn't that easy to obtain any other way. Pretty much the only alternative would be to count newlines based on the range.

@ForbesLindesay ForbesLindesay enable loc
Having the line number can be extremely useful and isn't that easy to obtain any other way.
868d7bf
@substack
Owner

This can already be done with no changes. Just pass falafel() an object instead of a source string as the first parameter:

var falafel = require('falafel');
falafel({ source : '5+2', loc : true }, function (node) {
    console.dir(node.loc);
});

{ start: { line: 1, column: 0 }, end: { line: 1, column: 1 } }
{ start: { line: 1, column: 2 }, end: { line: 1, column: 3 } }
{ start: { line: 1, column: 0 }, end: { line: 1, column: 3 } }
{ start: { line: 1, column: 0 }, end: { line: 1, column: 3 } }
{ start: { line: 1, column: 0 }, end: { line: 1, column: 3 } }
@substack substack closed this Aug 12, 2012
@substack
Owner

This is also already documented in the readme:


If typeof src === 'object', then src.source will be used for the source and the rest of the options will be passed directly along to esprima except for 'range' which is always turned on because falafel needs it.

Some of the options you might want from esprima includes: 'loc', 'raw', 'comments', 'tokens', and 'tolerant'.

@ForbesLindesay
Collaborator

Thanks, didn't see that in the docs

@tecfu

It appears that this feature has been removed in at least v1.0.1.

Is there a workaround?

@tecfu tecfu referenced this pull request Apr 24, 2015
Closed

Line number support. #37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment