-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update deps, use ES6 constructs, require Node 8.x
- Loading branch information
1 parent
d5b4d95
commit 0cee4ac
Showing
17 changed files
with
1,232 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
{ | ||
"extends": "standard" | ||
"extends": "standard", | ||
"plugins": [ | ||
"chai-friendly" | ||
], | ||
"rules": { | ||
"no-unused-expressions": 0, | ||
"chai-friendly/no-unused-expressions": 2 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
language: node_js | ||
node_js: | ||
- "4.0" | ||
- "8.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,104 @@ | ||
var operators = require('./operators') | ||
|
||
function ASTDelegate (options) { | ||
options = options || {} | ||
this.scope = options.scope || {} | ||
this.expression = null | ||
this.scopeIdentifier = undefined | ||
this.indexIdentifier = undefined | ||
} | ||
const operators = require('./operators') | ||
|
||
class ASTDelegate { | ||
constructor (options) { | ||
options = options || {} | ||
this.scope = options.scope || {} | ||
this.expression = null | ||
this.scopeIdentifier = undefined | ||
this.indexIdentifier = undefined | ||
} | ||
|
||
ASTDelegate.prototype = { | ||
createUnaryExpression: function (op, arg) { | ||
createUnaryExpression (op, arg) { | ||
if (!operators.unary[op]) { | ||
throw Error('Disallowed operator: ' + op) | ||
} | ||
|
||
return () => operators.unary[op](arg()) | ||
}, | ||
} | ||
|
||
createBinaryExpression: function (op, left, right) { | ||
createBinaryExpression (op, left, right) { | ||
if (!operators.binary[op]) { | ||
throw Error('Disallowed operator: ' + op) | ||
} | ||
|
||
return () => operators.binary[op](left(), right()) | ||
}, | ||
} | ||
|
||
createConditionalExpression: function (test, consequent, alternate) { | ||
createConditionalExpression (test, consequent, alternate) { | ||
return () => test() ? consequent() : alternate() | ||
}, | ||
} | ||
|
||
createIdentifier: function (name) { | ||
createIdentifier (name) { | ||
var self = this | ||
return options => (options && options.child) ? name : self.scope[name] | ||
}, | ||
} | ||
|
||
createMemberExpression: function (accessor, object, property) { | ||
createMemberExpression (accessor, object, property) { | ||
var exp = () => object()[property({ child: true })] | ||
exp.scope = object() | ||
return exp | ||
}, | ||
} | ||
|
||
createCallExpression: function (expression, args) { | ||
createCallExpression (expression, args) { | ||
return () => expression().apply(expression.scope, args.map(arg => arg())) | ||
}, | ||
} | ||
|
||
createLiteral: function (token) { | ||
createLiteral (token) { | ||
return () => token.value | ||
}, | ||
} | ||
|
||
createArrayExpression: function (elements) { | ||
createArrayExpression (elements) { | ||
return () => { | ||
var array = [] | ||
for (var i = 0; i < elements.length; i++) { | ||
array.push(elements[i]()) | ||
} | ||
return array | ||
} | ||
}, | ||
} | ||
|
||
createProperty: function (kind, key, value) { | ||
createProperty (kind, key, value) { | ||
return () => ({ | ||
key: key({ child: true }), | ||
value: value() | ||
}) | ||
}, | ||
} | ||
|
||
createObjectExpression: function (properties) { | ||
createObjectExpression (properties) { | ||
return () => { | ||
var object = {} | ||
for (var i = 0; i < properties.length; i++) { | ||
object[properties[i]().key] = properties[i]().value | ||
} | ||
return object | ||
} | ||
}, | ||
} | ||
|
||
createFilter: function (name, args) { | ||
createFilter (name, args) { | ||
// TODO (Should filters be supported?) | ||
throw new Error('Filters are not supported') | ||
}, | ||
} | ||
|
||
createAsExpression: function (expression, scopeIdentifier) { | ||
createAsExpression (expression, scopeIdentifier) { | ||
this.expression = expression | ||
this.scopeIdentifier = scopeIdentifier | ||
}, | ||
} | ||
|
||
createInExpression: function (scopeIdentifier, indexIdentifier, expression) { | ||
createInExpression (scopeIdentifier, indexIdentifier, expression) { | ||
this.expression = expression | ||
this.scopeIdentifier = scopeIdentifier | ||
this.indexIdentifier = indexIdentifier | ||
}, | ||
} | ||
|
||
createTopLevel: function (expression) { | ||
createTopLevel (expression) { | ||
this.expression = expression | ||
}, | ||
} | ||
|
||
createThisExpression: function (expression) { | ||
createThisExpression (expression) { | ||
// TODO | ||
throw new Error('`this` is not supported') | ||
} | ||
|
||
} | ||
|
||
module.exports = ASTDelegate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.