Git Product home page Git Product logo

Comments (1)

vweevers avatar vweevers commented on July 28, 2024 2

@ralphtheninja @juliangruber I tested and looked up some more ES6+ features. We can now use many goodies: Symbol, destructuring, rest parameters, block scoped let/const, Map, Set, String.prototype.startsWith, Array.from(), etc.

If we drop support of Safari < 11.1 (2018-04-12, 0.43% global share) and Safari iOS < 11.3 (2018-03-29, 0.69%) then we can also use Rest/Spread Properties and Spread in object literals. That alone is not worth it, but...

If we drop support of Safari < 12 (2018-09-17, 0.5%) and Safari iOS < 12 (2018-09-17, 0.78%) then we can use async generators with for await...of ✨. See Level/abstract-leveldown#338 for an example. I previously planned to only support that on node.

React with thumbs up to drop those versions. I'm for.

Tests (click to expand)
// Temporary test for browsers
test('language features', function (t) {
  // Destructuring
  const { foo } = { foo: 1 }
  t.is(foo, 1)

  // Rest/Spread Properties. Not on Safari < 11.1 (2018-04-12, 0.43%), Safari iOS < 11.3 (2018-03-29, 0.69%)
  // https://github.com/tc39/proposal-object-rest-spread
  const { a, ...rest } = { a: 1, b: 2, c: 3 }
  t.is(a, 1)
  t.same(Object.keys(rest), ['b', 'c'])

  // Spread in object literals
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax#spread_in_object_literals
  t.same({ ...rest, c: 100 }, { b: 2, c: 100 }) // Not on Safari iOS < 11.3 (2018-03-29, 0.69%)

  // Rest parameters
  ;((...rest) => t.same(rest, [1, 2, 3]))(1, 2, 3)

  // Block scope
  const x = 9
  for (const x of [10]) t.is(x, 10)
  { const x = 11; t.is(x, 11) }
  t.is(x, 9)

  t.is(`foo ${88}`, 'foo 88')

  // Random stuff
  class Test {}
  t.is(typeof Test, 'function')
  t.is(typeof global.Map, 'function', 'map')
  t.is(typeof global.Set, 'function', 'set')
  t.is(typeof String.prototype.startsWith, 'function', 'String#startsWith')
  t.is(typeof String.prototype.includes, 'function', 'String#includes')
  t.is(typeof Array.from, 'function', 'Array.from()')
  t.is(typeof Number.isInteger, 'function', 'Number.isInteger')

  // Symbol
  const kA = Symbol('a')
  const kB = Symbol('b')
  const obj = { [kA]: true, [kB]: false }
  t.is(obj[kA], true)
  t.is(obj[kB], false)
  t.is(typeof Symbol.for, 'function', 'global symbol registry')

  new Promise((resolve) => resolve(123)).then((res) => {
    t.is(res, 123)
    t.end()
  })
})

// Not on Safari < 12 (0.5%, 2018-09-17) and Safari iOS < 12 (0.78%, 2018-09-17)
test('async generator', async function (t) {
  let ended = false

  async function * generator () {
    try {
      yield 1
      yield 2
      yield 3
    } finally {
      ended = true
    }
  }

  const res = []

  for await (const x of generator()) {
    res.push(x)
  }

  t.same(res, [1, 2, 3])
  t.is(ended, true)
})

from community.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.