0

My personal javascript variable definition style is a single var statement followed by one or more definitions. It's an unimportant choice, but one that some find benefits in.

Carrying this over to Apps Script, I find it often ends up giving up early—cutting off its interpretation of those comma-separated definitions and so skipping some variables' creation and assignment.

For an example, the following is valid js syntax according to several checkers, but editBottom will not be defined (nor, indeed, get syntax highlighting to variables' blue):

function rangeToBounds() {
  var activeRange = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("R1C2:R3C4");

  var editTop = activeRange.getRow(),
      editLeft = activeRange.getColumn(),
      editRight = activeRange.getColumn()+activeRange.getNumColumns()-1,
      editBottom = activeRange.getRow()+activeRange.getNumRows()-1;
}

Whereas swapping in this equivalent set works as expected:

  var editTop = activeRange.getRow();
  var editLeft = activeRange.getColumn();
  var editRight = activeRange.getColumn()+activeRange.getNumColumns()-1;
  var editBottom = activeRange.getRow()+activeRange.getNumRows()-1;

Even this works:

  var editTop = activeRange.getRow(),
      editLeft = activeRange.getColumn(),
      editRight = activeRange.getColumn()+activeRange.getNumColumns()-1;
  var editBottom = activeRange.getRow()+activeRange.getNumRows()-1;

So I believe I'm hitting some length or nested-eval limit, not an Apps Script syntax rule.
What's actually going on?

  • I've looked around as best I could, but this is apparently a difficult one to search for due to its rarity and the search terms involved. That, or I'm just bad at the internet. – Joel Reid Apr 23 at 18:56
  • The function included doesn't do anything with editBottom. What is the purpose of this variable? If you are getting an error message, add it textually to the question. – Rubén Apr 23 at 19:05
  • I just tested the code. editBottom is defined the only "problem" is that font color is the default color (black) instead of blue. – Rubén Apr 23 at 19:18
  • I've pulled it all out from other complex but irrelevant code a la mcve. They will all be used. – Joel Reid Apr 23 at 19:18
  • 1
    Gotta love no-comment downvotes on well-written, clearly-defined, effort-demonstrated questions—clearly we need fewer of these *eyeroll* – Joel Reid Apr 23 at 23:07
1

I just tested the code. editBottom is defined, the only "problem" is that the font color for editBottom is the default color (black) instead of blue.

Here is my "mcve" version of the the OP code:

function rangeToBounds() {
  var activeRange = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getRange("R1C2:R3C4");

  var editTop = activeRange.getRow(),
      editLeft = activeRange.getColumn(),
      editRight = activeRange.getColumn()+activeRange.getNumColumns()-1,
      editBottom = activeRange.getRow()+activeRange.getNumRows()-1;
  Logger.log(editBottom);
}

It's known from years (references pending) that Google Apps Script editor have this and other "soft problems".

It worth to note that now it's easier to develop Apps Script projects locally with other less buggy IDEs by using CLASP .

Related

  • Can concur. I don't edit GAS in their editor, my IDE sees it as javascript, and what actually happened was I was annoyed to see it not accepted as-written when pasted in. Thanks for the CLASP mention. Cheers. – Joel Reid Apr 23 at 19:31
  • I was been reluctant to use CLASP but some of my projects are becoming bigger and the Apps Script IDE is becoming a real pain. – Rubén Apr 23 at 19:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.