google / google/closure-compiler

Quoted string keys in record-literal types behave inconsistently

Open
#2,750 1 comment 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

Example:
```js
var /** {'a': number} */ foo;
```

`JSDocInfoParser` creates a JSDoc AST with a STRING_KEY node whose `getString()` returns the string "`'a'`", *with the single quoted included*. A number of spots in the compiler explicitly remove these quotes (OTI's JSTypeRegistry and NTI's JSTypeCreatorFromJSDoc - search for "startsWith") before doing anything with the names, though it's not entirely consistent, since JSTypeCreatorFromJSDoc passes the STRING_KEY node to GlobalTypeInfo#recordPropertyName which gets the string but does not remove the quotes, to store it in allPropertyNames and/or externPropertyNames.

Ideally we should normalize these as early as possible. As far as I'm aware, the compiler does not behave any differently if a property name in a record literal is quoted, but if we needed to, we should instead add an annotation on the node and strip the quotes before storing the node's string. That said, I don't know what we would do differently, so maybe we can forgo that and just ignore the quotes completely?

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.