From bb895120f7f477ff9c5f132939abbbd787322b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Fri, 26 Mar 2021 14:47:17 -0400 Subject: [PATCH] Add more comments --- packages/babel-traverse/src/path/family.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/babel-traverse/src/path/family.ts b/packages/babel-traverse/src/path/family.ts index cf6ed79ed030..55d3bcbf6600 100644 --- a/packages/babel-traverse/src/path/family.ts +++ b/packages/babel-traverse/src/path/family.ts @@ -85,6 +85,19 @@ function normalCompletionToBreak(completions: Completion[]) { }); } +/** + * Determine how we should handle the break statement for break completions + * + * @param {Completion[]} completions + * @param {boolean} reachable Whether the break statement is reachable after + we mark the noraml completions _before_ the given break completions as the final + completions. For example, + `{ 0 }; break;` is transformed to `{ return 0 }; break;`, the `break` here is unreachable + and thus can be removed without consequences. We may in the future reserve them instead since + we do not consistently remove unreachable statements _after_ break + `{ var x = 0 }; break;` is transformed to `{ var x = 0 }; return void 0;`, the `break` is reachable + because we can not wrap variable declaration under a return statement + */ function replaceBreakStatementInBreakCompletion( completions: Completion[], reachable: boolean,