MCPcopy Index your code
hub / github.com/josdejong/mathjs / _compile

Method _compile

src/expression/node/ObjectNode.js:52–78  ·  view source on GitHub ↗

* Compile a node into a JavaScript function. * This basically pre-calculates as much as possible and only leaves open * calculations which depend on a dynamic scope with variables. * @param {Object} math Math.js namespace with functions and constants. * @param {Object} argNam

(math, argNames)

Source from the content-addressed store, hash-verified

50 * evalNode(scope: Object, args: Object, context: *)
51 */
52 _compile (math, argNames) {
53 const evalEntries = {}
54
55 for (const key in this.properties) {
56 if (hasOwnProperty(this.properties, key)) {
57 // we stringify/parse the key here to resolve unicode characters,
58 // so you cannot create a key like {"co\\u006Estructor": null}
59 const stringifiedKey = stringify(key)
60 const parsedKey = JSON.parse(stringifiedKey)
61 const prop = getSafeProperty(this.properties, key)
62
63 evalEntries[parsedKey] = prop._compile(math, argNames)
64 }
65 }
66
67 return function evalObjectNode (scope, args, context) {
68 const obj = {}
69
70 for (const key in evalEntries) {
71 if (hasOwnProperty(evalEntries, key)) {
72 obj[key] = evalEntries[key](scope, args, context)
73 }
74 }
75
76 return obj
77 }
78 }
79
80 /**
81 * Execute a callback for each of the child nodes of this node

Callers

nothing calls this directly

Calls 4

hasOwnPropertyFunction · 0.90
stringifyFunction · 0.90
getSafePropertyFunction · 0.90
parseMethod · 0.65

Tested by

no test coverage detected