Skip to content

Commit

Permalink
Linter fix, ensure this call works
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBuchholz committed Nov 29, 2022
1 parent 84805a6 commit 693f466
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions punyexpr.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const TOKEN_TYPE_IDENTIFIER = 'identifier'
const TOKEN_TYPE_SYMBOL = 'symbol'
const FUNCTION = 'function'

class PunyExprError extends Error {
constructor (name, message, offset) {
super(message)
Expand Down Expand Up @@ -115,8 +115,8 @@
MemberExpression :
PrimaryExpression
MemberExpression [ Expression ] 💬 should we bind ?
⚠️MemberExpression . Identifier 💬 should we bind ?
MemberExpression [ Expression ] 💬 If result is a function, it is bound to the MemberExpression
⚠️MemberExpression . Identifier 💬 If result is a function, it is bound to the MemberExpression
⛔MemberExpression TemplateLiteral
⛔SuperProperty
⛔MetaProperty
Expand All @@ -126,7 +126,7 @@
⛔NewExpression :
⛔new NewExpression
⚠️CallExpression : 💬 does not support this call
⚠️CallExpression : 💬 Supports this call thanks to binding
MemberExpression
MemberExpression ( )
MemberExpression ( AssignmentExpression ⟮, AssignmentExpression⟯∗ )
Expand Down Expand Up @@ -228,7 +228,15 @@

const constant = ['constant', value => value]
const rootGet = ['rootGet', (member, context) => context[member(context)]]
const get = ['get', (object, member, context) => object(context)[member(context)]]
const get = ['get', (object, member, context) => {
const that = object(context)
const result = that[member(context)]
// eslint-disable-next-line valid-typeof
if (typeof result === FUNCTION) {
return result.bind(that)
}
return result
}]
const not = ['not', (value, context) => !value(context)]
const mul = ['mul', (value1, value2, context) => value1(context) * value2(context)]
const div = ['div', (value1, value2, context) => value1(context) / value2(context)]
Expand Down Expand Up @@ -478,6 +486,7 @@

const toJSON = expr => ({
[expr.op]: expr.args.map(
// eslint-disable-next-line valid-typeof
arg => typeof arg === FUNCTION
? toJSON(arg)
: Array.isArray(arg)
Expand Down

0 comments on commit 693f466

Please sign in to comment.