-
Notifications
You must be signed in to change notification settings - Fork 44
Description
Our app was hitting the following error when we added tests that relied on a package that relied on this package:
TypeError: Cannot assign to read only property 'name' of function 'function SequenceMatcher(isjunk, a, b, autojunk) {
at ../../node_modules/difflib/lib/difflib.js:78:25
at call (../../node_modules/difflib/lib/difflib.js:660:3)
at Object.<anonymous> (../../node_modules/difflib/lib/difflib.js:1486:4)
at Object.<anonymous> (../../node_modules/difflib/index.js:1:18)
with the issue being these two lines:
Line 78 in e11553b
SequenceMatcher.name = 'SequenceMatcher'; Line 740 in e11553b
Differ.name = 'Differ';
Per https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name, the issue is that the name property for a function is not writable, and so doing assignment isn't allowed, and will do nothing in non-strict contexts, or error in strict contexts. For an example of the former context, see this REPL output:
> a = (function() { console.log('foo') });
[Function: a]
> a.name
'a'
> a.name = 'b'
'b'
> a.name
'a'
If assigning the name is necessary, it needs to be done by doing Object.defineProperty instead, which can bypass the writable attribute:
> a = (function() { console.log('foo') });
[Function: a]
> a.name
'a'
> Object.defineProperty(a, 'name', { value: 'b' })
[Function: b]
> a
[Function: b]
> a.name
'b'
To workaround this, for now we're mocking out the dependency with a stub as we don't depend on the output, but it'd be nice to not have to.