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AiB,4BAAO,EAAP,EAAW,KAAK,QAAL,CAAc,MAAzB,CAAjB;;AAEA;AACA,aAAO,QAAQ,MAAf;AACA,aAAO,QAAQ,SAAf;AACA,aAAO,QAAQ,UAAf;AACA,aAAO,QAAQ,UAAf;;AAEA,aAAO,OAAP;AACD;;;;;;kBAgCY,UAAC,QAAD,EAAW,OAAX,EAAuB;AACpC;AADoC,4BAEkB,OAFlB,CAE9B,UAF8B;AAAA,MAE9B,UAF8B,uCAEjB,CAAC,KAAD,EAAQ,MAAR,EAAgB,KAAhB,EAAuB,MAAvB,CAFiB;AAGpC;;AACA,eAAa,MAAM,OAAN,CAAc,UAAd,IAA4B,UAA5B,GAAyC,CAAC,UAAD,CAAtD;;AAEA,MAAM,kBAAkB,4BAAO;AAC7B,eAAW,IADkB;AAE7B,gBAAY;AAFiB,GAAP,EAGrB,OAHqB,EAGZ,EAAE,sBAAF,EAHY,CAAxB;;AAKA,MAAM,mBAAmB,WAAW,OAAX,CAAmB,mBAAQ,QAAR,CAAnB,MAA0C,CAAC,CAApE;AACA;AACA,MAAI,gBAAJ,EAAsB;AACpB;AACA,WAAO,0BAAP;AACD;;AAED,SAAO,IAAI,QAAJ,CAAa,QAAb,EAAuB,eAAvB,CAAP;AACD,C","file":"Bubleify.js","sourcesContent":["import { transform } from 'buble';\nimport assign from 'object-assign';\nimport { Transform, PassThrough } from 'stream';\nimport { EOL } from 'os';\nimport { extname } from 'path';\n\nclass Bubleify extends Transform {\n constructor(filename, options) {\n super();\n this._data = '';\n this._filename = filename;\n this._options = options;\n }\n\n get _bubleOptions() {\n const defaults = { source: this._filename };\n const options = assign(defaults, this._options);\n\n // copy properties to not modify the existing objects\n // set default transforms with deactivated modules\n options.transforms = assign({ modules: false }, this._options.transforms);\n options.target = assign({}, this._options.target);\n\n // remove browserify options\n delete options._flags;\n delete options.sourceMap;\n delete options.extensions;\n delete options.bubleError;\n\n return options;\n }\n\n _transform(buf, enc, cb) {\n this._data += buf;\n cb();\n }\n\n _flush(cb) {\n try {\n const result = transform(this._data, this._bubleOptions);\n let { code } = result;\n\n if (this._options.sourceMap) {\n // append sourcemaps to code\n code += `${EOL}//# sourceMappingURL=${result.map.toUrl()}`;\n }\n\n this.emit('bubleify', result, this._filename);\n this.push(code);\n } catch (err) {\n // emit buble error message instead of the default error\n if (this._options.bubleError && err.snippet) {\n this.emit('error', `---${EOL}${err.snippet}${EOL}${EOL}${err.message}${EOL}`);\n } else {\n this.emit('error', err);\n }\n return;\n }\n cb();\n }\n}\n\nexport default (filename, options) => {\n // get extensions or defaults\n let { extensions = ['.js', '.jsx', '.es', '.es6'] } = options;\n // convert to json\n extensions = Array.isArray(extensions) ? extensions : [extensions];\n\n const enrishedOptions = assign({\n sourceMap: true,\n bubleError: false,\n }, options, { extensions });\n\n const shouldIgnoreFile = extensions.indexOf(extname(filename)) === -1;\n // return empty stream for files that should not be transformed\n if (shouldIgnoreFile) {\n // eslint-disable-next-line new-cap\n return PassThrough();\n }\n\n return new Bubleify(filename, enrishedOptions);\n};\n"]} |