Created
May 15, 2018 21:30
-
-
Save jasonLaster/af8e91b7c322d25b1fc122d7d65ffa6f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/workers/parser/getScopes/visitor.js b/src/workers/parser/getScopes/visitor.js | |
index 983279b..d2c7d31 100644 | |
--- a/src/workers/parser/getScopes/visitor.js | |
+++ b/src/workers/parser/getScopes/visitor.js | |
@@ -444,8 +444,11 @@ const scopeCollectionVisitor = { | |
// is probably a fine assumption. | |
state.declarationBindingIds.add(node.id); | |
const fnScope = getVarScope(scope); | |
- scope.bindings[node.id.name] = { | |
- type: fnScope === scope ? "var" : "let", | |
+ | |
+ const applicableScope = scope.parent === fnScope ? fnScope : scope; | |
+ | |
+ applicableScope.bindings[node.id.name] = { | |
+ type: fnScope === applicableScope ? "var" : "let", | |
refs: [ | |
{ | |
type: "fn-decl", | |
diff --git a/src/workers/parser/tests/fixtures/scopes/breakpoint.js b/src/workers/parser/tests/fixtures/scopes/breakpoint.js | |
new file mode 100644 | |
index 0000000..00f0b8b | |
--- /dev/null | |
+++ b/src/workers/parser/tests/fixtures/scopes/breakpoint.js | |
@@ -0,0 +1,12 @@ | |
+(function() { /* outer anonymous (variable level) */ | |
+ /* lexical scope */ | |
+ "use strict"; | |
+ | |
+ function getBreakpointText() { | |
+ console.log(2) | |
+ } | |
+ | |
+ class Breakpoint { | |
+ } | |
+ | |
+})() | |
diff --git a/src/workers/parser/tests/getScopes.spec.js b/src/workers/parser/tests/getScopes.spec.js | |
index eefb766..0b797c2 100644 | |
--- a/src/workers/parser/tests/getScopes.spec.js | |
+++ b/src/workers/parser/tests/getScopes.spec.js | |
@@ -28,6 +28,12 @@ cases( | |
}, | |
[ | |
{ | |
+ name: "finds scope bindings in a breakpoint file", | |
+ file: "scopes/breakpoint", | |
+ locations: [[6, 0]] | |
+ // only: true | |
+ }, | |
+ { | |
name: "finds scope bindings in a vue file", | |
file: "scopes/vue-sample", | |
type: "vue", | |
@@ -63,7 +69,8 @@ cases( | |
{ | |
name: "finds scope bindings for function declarations", | |
file: "scopes/function-declaration", | |
- locations: [[2, 0], [3, 20], [5, 1], [9, 0]] | |
+ locations: [[2, 0], [3, 20], [5, 1], [9, 0]], | |
+ only: true | |
}, | |
{ | |
name: "finds scope bindings for function expressions", |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment