summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/readable-stream/node_modules/inline-process-browser/index.js
blob: c1fb0077e96b0e45f83cd81a8f04bca3dcff4461 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
var through = require('through2');
var falafel = require('falafel');

module.exports = apply;
var regex = /process\s*\.\s*browser/;
function apply() {
  var buffers = [];

  return through(function(chunk, enc, next) {
    buffers.push(chunk);
    next();
  }, function(next) {
    var string = Buffer.concat(buffers).toString();
    if (!string.match(regex)) {
      this.push(string);
      return next();
    }
    var resp = falafel(string, {
      ecmaVersion: 6,
      allowReturnOutsideFunction: true
    }, function (node) {

      if (
        node.type === 'MemberExpression' &&
        node.object && node.property &&
        node.object.name === 'process'
        && node.property.name === 'browser' &&
        !(node.parent ? node.parent.operator === '=' && node.parent.left === node : true)
        ) {
        node.update('true');
      }
    });
    this.push(resp.toString());
    next();
  });
}