samedi 24 octobre 2020

Unexpected token in Javascript if statement

This is a basic javascript question. FYI the context is: It is in a javascript controller for a Salesforce Lightning Web Component, editing in Visual Studio. The code is for selecting the table column definition before rendering the datatable.

The following code throws these 3 errors on the line marked ERRORS HERE below. Visual Studio then goes on to mark another 17 errors later in the file..

LWC1503: Parsing error: Unexpected token, expected "," ts(1005) ',' expected. ts(1005) ';' expected.

I'd appreciate if you can tell me why the if statement does not work and where there is language documentation explaining it if possible. Thank you!

generalReportName = 'general';
complianceReportName = 'compliance';
activeReportName = 'compliance';

searchResultsColumns = [{label: 'Sales', fieldName: 'Record'}];
complCols = [{ label: 'Compliance', fieldName: 'Record'}];

// Throws 20 errors in editor
if (activeReportName != complianceReportName) { //ERRORS HERE
  searchResultsColumns = complCols;
}

// However this works
searchResultsColumns = (activeReportName == complianceReportName) ? searchResultsColumns : complCols;

Aucun commentaire:

Enregistrer un commentaire