Skip to content

Commit d0225d1

Browse files
committed
replace bind()
1 parent 509ae40 commit d0225d1

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

build/build.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ function processFile (inputLoc, out, replacements) {
4242

4343
data = data.toString()
4444
replacements.forEach(function (replacement) {
45-
data = data.replace.apply(data, replacement)
45+
const regexp = replacement[0]
46+
var arg2 = replacement[1]
47+
if (typeof arg2 === 'function')
48+
arg2 = arg2.bind(data)
49+
data = data.replace(regexp, arg2)
4650
})
4751
if (inputLoc.slice(-3) === '.js') {
4852
const transformed = babel.transform(data, {

build/files.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,23 @@ const headRegexp = /(^module.exports = \w+;?)/m
183183
/if \(typeof Symbol === 'function' && Symbol\.hasInstance\) \{/,
184184
`if (typeof Symbol === 'function' && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === 'function') {`
185185
]
186+
, removeOnWriteBind = [
187+
/onwrite\.bind\([^)]+?\)/,
188+
`function(er) { onwrite(stream, er); }`
189+
]
190+
, removeCorkedFinishBind = [
191+
/onCorkedFinish\.bind\([^)]+?\)/,
192+
function (match) {
193+
const code = this
194+
var src = /^function onCorkedFinish[^{]*?\{([\s\S]+?\r?\n)\}/m.exec(code)
195+
src = src[1].trim().replace(/corkReq/g, 'this').replace(/(\r?\n)/mg, ' $1')
196+
return `(err) => {\n${src}\n}`
197+
}
198+
]
199+
, removeOnCorkedFinish = [
200+
/^function onCorkedFinish[\s\S]+?\r?\n\}/m,
201+
''
202+
]
186203

187204
module.exports['_stream_duplex.js'] = [
188205
requireReplacement
@@ -261,6 +278,9 @@ module.exports['_stream_writable.js'] = [
261278
, bufferShimFix
262279
, bufferStaticMethods
263280
, fixInstanceCheck
281+
, removeOnWriteBind
282+
, removeCorkedFinishBind
283+
, removeOnCorkedFinish
264284
]
265285
module.exports['internal/streams/BufferList.js'] = [
266286
bufferShimFix

0 commit comments

Comments
 (0)