web-audio-api
web-audio-api copied to clipboard
Use native es6 if available
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')
}
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.
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?