From d748a1ec394ca340d3997deb4c76f649a384d850 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 31 Jan 2022 11:54:35 +0200 Subject: [PATCH] Some style fixes --- src/scopetools.js | 30 +++++++++++++----------------- tests/original.js | 2 +- tests/with_annotations.js | 2 +- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/scopetools.js b/src/scopetools.js index 7b5f740..34631f6 100644 --- a/src/scopetools.js +++ b/src/scopetools.js @@ -107,24 +107,20 @@ function createScopes(node, parent) { }); const identifier = node.param; - - if (identifier === null) { - return; + if (identifier !== null) { + node.$scope.add(identifier.name, "caught", identifier, null); + + // All hoist-scope keeps track of which variables that are propagated through, + // i.e. an reference inside the scope points to a declaration outside the scope. + // This is used to mark "taint" the name since adding a new variable in the scope, + // with a propagated name, would change the meaning of the existing references. + // + // catch(e) is special because even though e is a variable in its own scope, + // we want to make sure that catch(e){let e} is never transformed to + // catch(e){var e} (but rather var e$0). For that reason we taint the use of e + // in the closest hoist-scope, i.e. where var e$0 belongs. + node.$scope.closestHoistScope().markPropagates(identifier.name); } - - node.$scope.add(identifier.name, "caught", identifier, null); - - // All hoist-scope keeps track of which variables that are propagated through, - // i.e. an reference inside the scope points to a declaration outside the scope. - // This is used to mark "taint" the name since adding a new variable in the scope, - // with a propagated name, would change the meaning of the existing references. - // - // catch(e) is special because even though e is a variable in its own scope, - // we want to make sure that catch(e){let e} is never transformed to - // catch(e){var e} (but rather var e$0). For that reason we taint the use of e - // in the closest hoist-scope, i.e. where var e$0 belongs. - node.$scope.closestHoistScope().markPropagates(identifier.name); - } else if (node.type === "Program") { // Top-level program is a scope // There's no block-scope under it diff --git a/tests/original.js b/tests/original.js index f75a0af..333e725 100644 --- a/tests/original.js +++ b/tests/original.js @@ -1078,4 +1078,4 @@ export function trycatch(foo) { } catch { // empty } -} \ No newline at end of file +} diff --git a/tests/with_annotations.js b/tests/with_annotations.js index 78aca06..2f60cf2 100644 --- a/tests/with_annotations.js +++ b/tests/with_annotations.js @@ -1128,4 +1128,4 @@ export function trycatch(foo) { // empty } } -trycatch.$inject = ["foo"]; \ No newline at end of file +trycatch.$inject = ["foo"];