google / google/closure-compiler

Object literal property is not considered an assignment (for const purposes)

Open
#2,789 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Looks like it doesn't acknowledge the literal as the initial setter.

```
var lit = { /** @const {number} */ x: 0 };
/** @const {number} */ lit.y = 0;
lit.x = 1; // expect an error here, but there is no error.
lit.x = 2; // constant property x assigned a value more than once
lit.y = 1; // constant property y assigned a value more than once
```

Why is this important: Rather nitty but ES6 module keys need to be sorted (according to the spec) and marked as const (for type checking). Right now anything const is done via property access (`/** @const */ exports.proprerty = value`). But anything that is not const is an ES5 getter (`var exports = { get property() { return value; } };`). Because of this mix keys cannot currently be sorted and the property accessors need to change to object literals (then the entire export definition is in the literal and keys can be sorted). But then we lose the constancy above, which we need so exported classes are type checked correctly.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.