Skip to content

Instantly share code, notes, and snippets.

@weinshel
Last active July 10, 2018 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weinshel/c6676c36eead578eded3d2de5026eab5 to your computer and use it in GitHub Desktop.
Save weinshel/c6676c36eead578eded3d2de5026eab5 to your computer and use it in GitHub Desktop.
math.js range override bug
const math = require('mathjs')
// define factory functions for range and reshape
function myRangeFactory (type, config, load, typed) {
return (() => 12)
}
function myReshapeFactory (type, config, load, typed) {
return (() => 21)
}
const factoryArr = [
{
name: 'range',
factory: myRangeFactory
},
{
name: 'reshape',
factory: myReshapeFactory
},
]
// uncomment to override using non factory function
// this will work, and subsequently overriding `range` using factory function will work
//math.import({ range: () => 13 }, { override: true })
// attempt to override using factory function
// this works for reshape but NOT for range
math.import(factoryArr, { override: true })
const rangeEval = math.eval('range(2,5)')
const reshapeEval = math.eval('reshape(2,5)')
// this _should_ be 12
// if it is [2,3,4,5] then the original function was not overwritten
console.log('range(2,5) evaluates to', rangeEval)
// note that reshape can be overritten with a single factory function without issue
// should return 21
console.log('reshape(2,5) evaluates to', reshapeEval)
{
"dependencies": {
"mathjs": "^5.0.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment