math-codegen
Advanced tools
Comparing version 0.3.5 to 0.4.0
@@ -19,2 +19,3 @@ 'use strict' | ||
CodeGenerator.prototype.compile = function (namespace) { | ||
var self = this | ||
if (!namespace || !(typeof namespace === 'object' || typeof namespace === 'function')) { | ||
@@ -38,7 +39,14 @@ throw TypeError('namespace must be an object') | ||
getProperty: function (symbol, scope, ns) { | ||
function applyFactoryIfNeeded (value) { | ||
if (self.interpreter.options.applyFactoryToScope && typeof value !== 'function') { | ||
return ns.factory(value) | ||
} | ||
return value | ||
} | ||
if (symbol in scope) { | ||
return scope[symbol] | ||
return applyFactoryIfNeeded(scope[symbol]) | ||
} | ||
if (symbol in ns) { | ||
return ns[symbol] | ||
return applyFactoryIfNeeded(ns[symbol]) | ||
} | ||
@@ -45,0 +53,0 @@ throw SyntaxError('symbol "' + symbol + '" is undefined') |
@@ -21,3 +21,4 @@ 'use strict' | ||
rawArrayExpressionElements: true, | ||
rawCallExpressionElements: false | ||
rawCallExpressionElements: false, | ||
applyFactoryToScope: false | ||
}, options) | ||
@@ -24,0 +25,0 @@ } |
{ | ||
"name": "math-codegen", | ||
"version": "0.3.5", | ||
"version": "0.4.0", | ||
"description": "Generates code from mathematical expressions", | ||
@@ -27,13 +27,13 @@ "bugs": "https://github.com/maurizzzio/math-codegen/issues", | ||
"dependencies": { | ||
"extend": "^3.0.0", | ||
"mr-parser": "^0.2.1" | ||
"extend": "3.0.0", | ||
"mr-parser": "0.2.1" | ||
}, | ||
"devDependencies": { | ||
"coveralls": "^2.11.2", | ||
"doctoc": "^0.14.2", | ||
"istanbul": "^0.3.8", | ||
"mocha": "^2.2.1", | ||
"mocha-lcov-reporter": "^0.0.2", | ||
"nodemon": "^1.3.7", | ||
"standard": "^4.5.4" | ||
"coveralls": "2.11.4", | ||
"doctoc": "0.14.2", | ||
"istanbul": "0.3.21", | ||
"mocha": "2.3.3", | ||
"mocha-lcov-reporter": "0.0.2", | ||
"nodemon": "1.7.1", | ||
"standard": "4.5.4" | ||
}, | ||
@@ -40,0 +40,0 @@ "scripts": { |
@@ -1,4 +0,4 @@ | ||
# math-codegen | ||
# math-codegen | ||
[![Build Status][travis-image]][travis-url] | ||
[![Build Status][travis-image]][travis-url] | ||
[![NPM][npm-image]][npm-url] | ||
@@ -43,3 +43,3 @@ [![Coverage Status][coveralls-image]][coveralls-url] | ||
operator bringing the operator overloading polymorphism to JavaScript (emulated with function calls), | ||
in addition an expression can be evaluated under any adapted namespace providing expression portability between numeric libraries | ||
in addition an expression can be evaluated under any adapted namespace providing expression portability between numeric libraries | ||
@@ -94,3 +94,3 @@ ### Lifecycle | ||
executable JavaScript code | ||
```javascript | ||
@@ -110,3 +110,3 @@ parse('1 + 2 * x').compile(namespace) | ||
} | ||
})(definitions) // definitions created by math-codegen | ||
})(definitions) // definitions created by math-codegen | ||
``` | ||
@@ -128,3 +128,3 @@ | ||
- `math.js` v1.x arrays can represent matrices with `ns.matrix` or as a raw arrays, `math-codegen` doesn't | ||
make any assumptions of the arrays and treats them just like any other literal allowing the namespace to | ||
make any assumptions of the arrays and treats them just like any other literal allowing the namespace to | ||
decide what to do with an array in its `factory` method | ||
@@ -196,6 +196,6 @@ | ||
that exist during the instance lifespan | ||
**params** | ||
* `options` {Object} Options available for the interpreter | ||
* `[options.factory="ns.factory"]` {string} factory method under the namespace | ||
* `[options.factory="ns.factory"]` {string} factory method under the namespace | ||
* `[options.raw=false]` {boolean} True to interpret OperatorNode, UnaryNode and ArrayNode | ||
@@ -206,3 +206,3 @@ in a raw way without wrapping the operators with identifiers e.g. `-1` will be compiled as | ||
* `[options.rawCallExpressionElements=false]` {boolean} true to interpret call expression | ||
elements in a raw way | ||
* `[options.applyFactoryToScope=false]` {boolean} true to apply the factory function on non-function values of the scope/namespace | ||
@@ -214,10 +214,10 @@ ### `instance.parse(code)` | ||
* `code` {string} string to be parsed | ||
Parses a program using [`mr-parse`](https://github.com/maurizzzio/mr-parser), each Expression Statement is saved in | ||
`instance.statements` | ||
The documentation for the available nodes is described in [`mr-parse`](https://github.com/maurizzzio/mr-parser) | ||
The documentation for the available nodes is described in [`mr-parse`](https://github.com/maurizzzio/mr-parser) | ||
### `instance.compile(namespace)` | ||
**chainable** | ||
@@ -229,3 +229,3 @@ **params** | ||
to have the `factory` property defined** | ||
**returns** {Object} | ||
@@ -232,0 +232,0 @@ * `return.code` {string} the body of the function to be evaluated with `eval` |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
20060
266
2
+ Addedextend@3.0.0(transitive)
- Removedextend@3.0.2(transitive)
Updatedextend@3.0.0
Updatedmr-parser@0.2.1