javascriptecmascript-6sapui5eslintsap-web-ide

SAP Web IDE shows errors about ES6+ features


for (var items in _selectedContexts) {
  var downloadModel = __parsed[__parsed[items].toString().split("/")[1]][__parsed[items].toString().split("/")[2]];
  var length = downloadModel["Value"].length;
  var base64 = downloadModel["Value"];
  var bytes =  new Uint8Array(length);
  while (length--) {
    bytes[length] = base64.charCodeAt(length);
  }
  MessageToast.show(bytes.length);
}

How can I initialize a Uint8Array in UI5? I always get "Uint8Array is not defined" in SAP Web IDE as an error message. Do I need to import any special libraries? I'm also using the latest SAPUI5 version and Chrome for testing so it shouldn't be a problem I guess?


Solution

  • Yes, you can ignore the message as long as your target browser supports the object. Uint8Array was added to a somewhat newer JS specification (ECMAScript 2015 aka. ES6). In order to make SAP Web IDE understand and parse ES6, add es6 to the ESLint environment settings:

    1. Go to Project settings > Code Checking > JavaScript
    2. Expand the Validator Configuration panel
    3. Add "es6": true to the env object:
      "env": {
        "es6": true,
        "...": "..."
      }
      
      This will edit the internal .eslintrc file accordingly.
    4. Save the settings.