paperwm / gnome-shell-mode

Package for developing gnome-shell extensions
GNU General Public License v2.0
27 stars 7 forks source link

Eval fails on (some) nested block statements due to Reflect.parse weirdness #24

Closed olejorgenb closed 6 years ago

olejorgenb commented 6 years ago
// Works:
Eval(`
for (var x in foo) {
  x = 1;
}`)

// Does not work: ("missing } in compound statement")
Eval(`
for (var x in foo) {
  if (true) {
    x = 1;
  }
}`)

// Works:
Eval(`
for (var x in foo) {
  if (true) {
    x = 1;
  }
  x = 2;
}`)

// Seems to be due to the block ast node being totally unpredictable:
// We already know that the block's loc doesn't include the ending '}'
// But apparently it's behavior depends on its content.. !
// When a block A ends with *another* block B , A.loc.end is off by another line.
// ie. A.loc omits both the ending '}' of A **and** the ending '}' of B :/

Keywords: Spidermonkey firefox Reflect.parse

olejorgenb commented 6 years ago

Not sure if we should add a special case or just parse everything?

    case  'BlockStatement':
        // Block AST nodes omits the ending '}'
        var block = `${span(lines, statement.loc)} }`;
        if (statement.body[-1].type === 'BlockStatement') {
            // Omission of ending '}' nests. (but only one level..)
            block += " }"
        }
        return block;

Fixes the problem.