You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix how JSCompiler parses TTL expressions and modifies their lineno/charno
#### How does JSCompiler currently parse TTL expressions?
JSDocInfoParser envokes a TTL parser which adjusts all the lineno/charno within JSDocs to the lineno/charno that the TTL should have within the source JS file.
This doesn't work because the TTL parser is using the lineno/charno of the "@" in the "@template" JSDoc annotation and trying to add this lineno/charno to all nodes within the TTL ast.
If the TTL spans multiple lines, the charno of the "@" is not the right number to add/adjust by. Also in some cases we need to use a 0-indexed lineno and other cases a 1-indexed lineno within the JSDoc to get things working.
Currently, we set wrong lineno/charno to TTL ast nodes, and things work without errors by luck. When we need to print an error/warning message pointing to something in the TTL expression, there is a good chance the lineno/charno are inaccurate and the compiler crashes with a `String index out of bounds exception`
#### What does this change do?
Any time an error occurs within a TTL expression, show the error message with an error location pointing to the @template. This means every node in the TTL ast will have the same line/charno as that of the “@” and a length of 9 (length of “@template”). This means error messages within a TTL expression will be logged as:
#### How will error messages look now?
The `@template` will be underlined with `^` when an error occurs in the TTL expression. E.g:
```
WARNING: test.js:3:3: WARNING - [TYPENAME_UNDEFINED] Reference to an unknown type name q
3| * @template Q := cond(isUnknown(T), 'q', T) =:
^^^^^^^^^
```
PiperOrigin-RevId: 500274723
0 commit comments