-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π Fix
each
expression not supporting function calls
- Loading branch information
Showing
5 changed files
with
48 additions
and
29 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
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 |
---|---|---|
|
@@ -15,7 +15,7 @@ Each.setHasArguments(true); | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 2.0.0 | ||
* @version 2.0.0 | ||
* @version 2.3.19 | ||
* | ||
* @param {Object} options | ||
* | ||
|
@@ -30,10 +30,10 @@ Each.setStatic(function parseArguments(options) { | |
} | ||
|
||
let result = { | ||
variable : tokens.getVariable(1), | ||
as_key : null, | ||
as : null, | ||
where : null, | ||
expression : tokens.getExpressionForEach(), | ||
as_key : null, | ||
as : null, | ||
where : null, | ||
}; | ||
|
||
// Go to the AS keyword | ||
|
@@ -63,7 +63,7 @@ Each.setStatic(function parseArguments(options) { | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.2.9 | ||
* @version 2.2.17 | ||
* @version 2.3.19 | ||
* | ||
* @param {String} name | ||
* @param {Array} pieces | ||
|
@@ -80,9 +80,9 @@ Each.setMethod(function execute() { | |
|
||
let options = this.options[0]; | ||
|
||
if (options && options.variable) { | ||
if (options && options.expression) { | ||
|
||
variable = this.getValueByPath(options.variable); | ||
variable = this.parseExpression(options.expression, this.vars); | ||
|
||
if (!variable) { | ||
return this; | ||
|
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ With.setHasArguments(true); | |
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.2.9 | ||
* @version 2.0.0 | ||
* @version 2.3.19 | ||
* | ||
* @param {Object} options | ||
* | ||
|
@@ -29,9 +29,9 @@ With.setStatic(function parseArguments(options) { | |
let tokens = options.tokens; | ||
|
||
let result = { | ||
variable : tokens.getVariable(), | ||
as : null, | ||
where : null, | ||
expression : tokens.getExpressionForEach(), | ||
as : null, | ||
where : null, | ||
}; | ||
|
||
// Go to the AS keyword | ||
|
@@ -69,24 +69,12 @@ With.setStatic(function parseArguments(options) { | |
*/ | ||
With.setMethod(function execute() { | ||
|
||
let variable, | ||
vars, | ||
let vars, | ||
i; | ||
|
||
let options = this.options[0]; | ||
|
||
// Get the possible paths | ||
let paths = options.variable; | ||
|
||
// Get the actual variable to work with | ||
for (i = 0; i < paths.length; i++) { | ||
// Get the variable | ||
variable = this.getValueByPath(paths[i]); | ||
|
||
if (variable) { | ||
break; | ||
} | ||
} | ||
let variable = this.parseExpression(options.expression, this.vars); | ||
|
||
let {keys, values, length} = Hawkejs.splitIntoKeysAndValues(variable); | ||
|
||
|
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,7 +1,8 @@ | ||
const IN_LITERAL = Symbol('literal'), | ||
IN_ARGUMENTS = Symbol('arguments'), | ||
IN_OPTIONS = Symbol('options'), | ||
IN_PATH_EXPRESSION = Symbol('path_expression'); | ||
IN_PATH_EXPRESSION = Symbol('path_expression'), | ||
IN_EACH_EXPRESSION = Symbol('each_expression'); | ||
|
||
/** | ||
* Expressions parser class: | ||
|
@@ -520,12 +521,25 @@ Eparser.setMethod(function getObjectLiteral() { | |
return result; | ||
}); | ||
|
||
/** | ||
* Get an expression used in an each statement | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 2.3.19 | ||
* @version 2.3.19 | ||
* | ||
* @return {Array} | ||
*/ | ||
Eparser.setMethod(function getExpressionForEach() { | ||
return this.getExpression(0, IN_EACH_EXPRESSION); | ||
}); | ||
|
||
/** | ||
* Get expression | ||
* | ||
* @author Jelle De Loecker <[email protected]> | ||
* @since 1.2.9 | ||
* @version 2.3.18 | ||
* @version 2.3.19 | ||
* | ||
* @param {Number} level | ||
* @param {Symbol} state Are we in some kind of literal ({}, []) | ||
|
@@ -669,6 +683,14 @@ Eparser.setMethod(function getExpression(level, state) { | |
|
||
let lower_value = token.value.toLowerCase(); | ||
|
||
if (state === IN_EACH_EXPRESSION) { | ||
// If we only need to get the first part of an `each` expression, | ||
// ignore the 'as' or 'where' parts | ||
if (lower_value == 'as' || lower_value == 'where') { | ||
break; | ||
} | ||
} | ||
|
||
switch (lower_value) { | ||
case 'where': | ||
case 'neq': | ||
|
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