Packages: Syntax hightlight issue with object shorthands (JavaScript)

Created on 16 Jan 2017  路  3Comments  路  Source: sublimehq/Packages

the field is highlighted (in green in the image below) is a comment follows, for no specific reason

var pop = 1;
var o = {
    pop // ok
}

image

Most helpful comment

So it's not a 'bug'?

I don鈥檛 think that was what they meant. It seems that the merely explored on when the bug happens in more detail.

All 3 comments

If you write it all on one line, it gets it right:

var a = "foo", 
    b = 42, 
    c = {};

// Shorthand property names (ES2015) // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer
var o = { a, b, c };

// In other words,
console.log((o.a === { a }.a)); // true

same with no comments on multiple lines:

var o = {
    a,
    b,
    c
}

but as soon as you add a comment to an item without a comma after it, the identifier before the comment gets scoped as entity.name.function.js:

var o = {
    a,
    b, // variable.other.readwrite.js
    c // entity.name.function
}

So it's not a 'bug'? Yes I know ES2015 shorthand, but I'm still surprised that something after // would be interpreted as function name, it's clearly a comment, line return or not, trailing comma or not

So it's not a 'bug'?

I don鈥檛 think that was what they meant. It seems that the merely explored on when the bug happens in more detail.

Was this page helpful?
0 / 5 - 0 ratings