Error guides

Fix expression closures and let (…) blocks on Apps Script V8

SyntaxError: Unexpected identifier 'x'      (function (x) x * x)
SyntaxError: Unexpected token '{'           (let (a = 1) { … })

Expression closures

JavaScript 1.8 let you omit braces and return in a function: function (x) x * x. Rhino supported it; V8 doesn't.

// Rhino
var square = function (x) x * x;
rows.filter(function (r) r[0] != '');

// V8
var square = (x) => x * x;
rows.filter((r) => r[0] != '');
// or: function (x) { return x * x; }

Careful with this: arrow functions don't get their own this. If the closure used this, write function (x) { return …; } instead.

let blocks and let expressions

JavaScript 1.7 had let (a = 1, b = 2) { … } and let (x = 5) x + 1. Use a normal block:

// Rhino
let (start = new Date()) {
  run();
  Logger.log(new Date() - start);
}

// V8
{
  let start = new Date();
  run();
  Logger.log(new Date() - start);
}

How V8Shift handles it

Both patterns are flagged as errors with file and line. They're on the manual checklist because the end of the expression can't be found reliably by pattern rules.

Have a whole project to migrate? Paste your .gs or upload a zip for a free V8 compatibility report — every occurrence of this pattern with file and line, plus an auto-rewritten project.
Related errors