Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 530787 - Block scoping for const expressions computes wrong block…
… scope
  • Loading branch information
mrennie committed Feb 6, 2018
1 parent 07b6ec8 commit 963d482
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 19 deletions.
@@ -1,6 +1,6 @@
/*******************************************************************************
* @license
* Copyright (c) 2016 IBM Corporation and others.
* Copyright (c) 2016, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0
* (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution
Expand Down Expand Up @@ -754,7 +754,7 @@ define([
*/
function _popBlock() {
var scope = scopes[scopes.length-1];
if (!scope.isLet || !scope.blocks || scope.blocks.length === 0){
if (!scope.blocks || scope.blocks.length === 0){
return false;
}
var block = scope.blocks.pop();
Expand All @@ -764,23 +764,24 @@ define([
}
return false;
}
var i, j;
var len = block.occurrences.length;
if (defscope && defscope === block){
for(i = 0; i < len; i++) {
occurrences.push(block.occurrences[i]);
}
return true;
}

// We popped out of a scope but don't know where the define is, treat the occurrences like they belong to the outer scope (Bug 445410)
if (scope.blocks.length > 0){
for (j=0; j< len; j++) {
scope.blocks[scope.blocks.length - 1].occurrences.push(block.occurrences[j]);
if(scope.isLet && Array.isArray(block.occurrences)) {
var i, j;
var len = block.occurrences.length;
if (defscope && defscope === block){
for(i = 0; i < len; i++) {
occurrences.push(block.occurrences[i]);
}
return true;
}
} else {
for (j=0; j< len; j++) {
scope.occurrences.push(block.occurrences[j]);
// We popped out of a scope but don't know where the define is, treat the occurrences like they belong to the outer scope (Bug 445410)
if (scope.blocks.length > 0){
for (j=0; j< len; j++) {
scope.blocks[scope.blocks.length - 1].occurrences.push(block.occurrences[j]);
}
} else {
for (j=0; j< len; j++) {
scope.occurrences.push(block.occurrences[j]);
}
}
}
return false;
Expand Down
@@ -1,6 +1,6 @@
/*******************************************************************************
* @license
* Copyright (c) 2016 IBM Corporation and others.
* Copyright (c) 2016, 2018 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0
* (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution
Expand Down Expand Up @@ -349,6 +349,27 @@ define([
});
});
describe('Let and Const', function(){
/**
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=530787
*/
it('Const trailing inner scopes', function(done) {
var text = "function f() {if(true) {}const c = 1;}";
return computeOccurrences(text, getOptions(done, 31, 31), [{start:31, end:32}]);
});
/**
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=530787
*/
it('Const trailing inner scope with nested same name', function(done) {
var text = "function f() {if(true) {const c = 43;}const c = 1;}";
return computeOccurrences(text, getOptions(done, 44, 44), [{start:44, end:45}]);
});
/**
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=530787
*/
it('Const trailing inner scope with nested same name 2', function(done) {
var text = "function f() {if(true) {const c = 43;}const c = 1;}";
return computeOccurrences(text, getOptions(done, 31, 31), [{start:30, end:31}]);
});
it('Const basic 1', function(done) {
var text = "if (true) { const a=3; a++; }";
return computeOccurrences(text, getOptions(done, 18, 19), [{start:18, end:19}, {start:23, end:24}]);
Expand Down

0 comments on commit 963d482

Please sign in to comment.