web-audio-api icon indicating copy to clipboard operation
web-audio-api copied to clipboard

Use native es6 if available

Open sebpiq opened this issue 10 years ago • 2 comments
trafficstars

Right now (dec 2014) it seems that even when using the --harmony flag, many ES6 features are not supported (including class which we need). So there's no point yet in doing this. But in a near future, index.js should look like this :

var importRoot

// Test if ES6 is supported 
if ('function' === typeof Map) importRoot = './lib/'

// If not, use the transpiled version
else importRoot = './build/'

module.exports = {

  AudioContext: require(importRoot + 'AudioContext'),
  AudioParam: require(importRoot + 'AudioParam'),
  AudioNode: require(importRoot + 'AudioNode'),
  AudioDestinationNode: require(importRoot + 'AudioDestinationNode'),
  AudioBuffer: require(importRoot + 'AudioBuffer'),
  AudioBufferSourceNode: require(importRoot + 'AudioBufferSourceNode'),
  GainNode: require(importRoot + 'GainNode'),

  constants: require(importRoot + 'constants')

}

sebpiq avatar Dec 15 '14 08:12 sebpiq

There's an approach used by escope, where there're no such environmental code in the source, the whole thing is written on ES6 and transpiled via babel to ES5 on deploy.

dy avatar Mar 26 '15 16:03 dy

Yes here we transpile on publish : https://github.com/sebpiq/node-web-audio-api/blob/master/gulpfile.js#L6 but if the environment the lib is published on supports ES6 natively there's no reason to transpile ... Or did I misunderstood what you suggest?

sebpiq avatar Mar 27 '15 08:03 sebpiq