Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ES2020: Add optional chaining once possible (Webpack issue) #467

Closed
tobiu opened this issue Apr 13, 2020 · 4 comments
Closed

ES2020: Add optional chaining once possible (Webpack issue) #467

tobiu opened this issue Apr 13, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@tobiu
Copy link
Collaborator

tobiu commented Apr 13, 2020

In short:

const obj = {
  prop1: {
    prop2: {
      prop3: {
        prop4: {
          prop5: 5
        }
      }
    }
  }
}

obj.prop1 &&
  obj.prop1.prop2 &&
  obj.prop1.prop2 &&
  obj.prop1.prop2.prop3 &&
  obj.prop1.prop2.prop3.prop4 &&
  console.log(obj.prop1.prop2.prop3.prop4.prop5);

VS

const obj = {
  prop1: {
    prop2: {
      prop3: {
        prop4: {
          prop5: 5
        }
      }
    }
  }
}

console.log(obj?.prop1?.prop2?.prop3?.prop4?.prop5);

This can some boiler-plate code, but unfortunately, webpack can not handle it yet. Browsers already support it, but webpack wants to parse it.

ERROR in ./apps/covid/view/TableContainerController.mjs 191:37
Module parse failed: Unexpected token (191:37)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| }
|

    me.loadHistoricalData(record?.countryInfo?.iso2 || 'all');

Since Babel is not an option for neo, we need to wait for this PR:

acornjs/acorn#891

(Webpack relies on acornjs)

@tobiu tobiu added the enhancement New feature or request label Apr 13, 2020
@tobiu
Copy link
Collaborator Author

tobiu commented Apr 13, 2020

@dreyks
Copy link

dreyks commented Jun 11, 2020

acornjs/acorn#891 is merged, let's keep an eye on the releases

@tobiu
Copy link
Collaborator Author

tobiu commented Jun 11, 2020

Thanks for the heads up!

There are probably many spots inside the neo.mjs framework & demo apps code base where we can use it. Optional chaining can definitely help removing some boiler plate code (smaller file-size) as well as making the spots cleaner & easier to read.

Looking forward to it.

@tobiu
Copy link
Collaborator Author

tobiu commented Jun 28, 2021

just double-checked this one again and we are now finally good to use optional chaining.

will create new tickets in case i see spots.

@tobiu tobiu closed this as completed Jun 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants