microsoft / microsoft/TypeScript
Tolerate invalid identifier syntax errors in list parsing
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Search Terms
parser variable name list identifiers
Suggestion
Instead of aborting parsing a list when an invalid identifier is reached, have the parser emit a syntax error but otherwise parsing. In other words: it should successfully parse lists such as variable declarations as if the identifiers were valid, with the one difference of emitting a syntax error that doesn't affect parsing.
Use Cases
Issues such as #11648 and #19352 pop up from situations where the parser attempts to read in a list, such as one of variable declarations, and cannot because an identifier is invalid.
const case = 123;
// ~~~~ 'case' is not allowed as a variable declaration name.(1389)
// ~ Variable declaration expected.(1134)
// ~~~ Variable declaration expected.(1134)
Although #40105 improved the first error message (previously it was also Variable declaration expected.), the underlying issue remains: the parser aborts reading in the list, resulting in an odd error message and surprising emitted JavaScript.
const ;
123;
Examples
Collecting a few examples from the linked issues...
const data = { in: 1 };
const { in } = data;
for (const case of [1, 2, 3]) console.log(case);
const case = 123;
let delete = true;
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
issue では実装ファイルやテストが指定されていません。まず、TypeScript parser で列挙された invalid-identifier のケースを再現し、リストのパースが最初の syntax error をどのように処理するかを追跡してください。完了条件は、parser が identifier エラーを報告しつつ、現在の不正な出力を生成せずに、周囲の宣言またはリストのパースを続行することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100