-
-
Notifications
You must be signed in to change notification settings - Fork 279
feat: Add support of inner expressions enclosed by parentheses #863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 8 commits
e7e3aeb
75314d0
489d136
a84df57
4b5296a
ba50a32
0bedce9
d6ec7cd
f45c4f1
bd65ca6
2cc74bf
e1afb68
60a6d0a
c4b4b6a
7f2b3ff
74e73b7
4b620a5
2d5b811
e202158
1b9fb80
4ff6534
db271da
5e60327
2c5f36d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { QuotedToken, RangeToken, OperatorToken, Token, PropertyAccessToken, OperatorType, operatorTypes } from '../tokens' | ||
| import { isRangeToken, isPropertyAccessToken, UndefinedVariableError, range, isOperatorToken, assert } from '../util' | ||
| import { QuotedToken, RangeToken, OperatorToken, Token, PropertyAccessToken, OperatorType, operatorTypes, GroupedExpressionToken } from '../tokens' | ||
| import { isRangeToken, isPropertyAccessToken, isGroupedExpressionToken, UndefinedVariableError, range, isOperatorToken, assert } from '../util' | ||
| import type { Context } from '../context' | ||
| import type { UnaryOperatorHandler } from '../render' | ||
| import { Drop } from '../drop' | ||
|
|
@@ -40,6 +40,12 @@ export function * evalToken (token: Token | undefined, ctx: Context, lenient = f | |
| if ('content' in token) return token.content | ||
| if (isPropertyAccessToken(token)) return yield evalPropertyAccessToken(token, ctx, lenient) | ||
| if (isRangeToken(token)) return yield evalRangeToken(token, ctx) | ||
| if (isGroupedExpressionToken(token)) return yield evalGroupedExpressionToken(token, ctx, lenient) | ||
| } | ||
|
|
||
| function * evalGroupedExpressionToken (token: GroupedExpressionToken, ctx: Context, lenient: boolean): IterableIterator<unknown> { | ||
| assert(token.resolvedValue, 'grouped expression not resolved') | ||
| return yield token.resolvedValue!.value(ctx, lenient) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try to create something like |
||
| } | ||
|
|
||
| function * evalPropertyAccessToken (token: PropertyAccessToken, ctx: Context, lenient: boolean): IterableIterator<unknown> { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ import { Hash, ValueToken, Liquid, Tag, evalToken, Emitter, TagToken, TopLevelTo | |
| import { assertEmpty, isValueToken, toEnumerable } from '../util' | ||
| import { ForloopDrop } from '../drop/forloop-drop' | ||
| import { Parser } from '../parser' | ||
| import { Arguments } from '../template' | ||
| import { Arguments, resolveGroupedExpressions } from '../template' | ||
|
|
||
| const MODIFIERS = ['offset', 'limit', 'reversed'] | ||
|
|
||
|
|
@@ -26,6 +26,7 @@ export default class extends Tag { | |
|
|
||
| this.variable = variable.content | ||
| this.collection = collection | ||
| resolveGroupedExpressions(this.collection, liquid) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be removed now. |
||
| this.hash = new Hash(this.tokenizer, liquid.options.keyValueSeparator) | ||
| this.templates = [] | ||
| this.elseTemplates = [] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import { Argument, Template, Value } from '.' | |
| import { isKeyValuePair } from '../parser/filter-arg' | ||
| import { PropertyAccessToken, ValueToken } from '../tokens' | ||
| import { | ||
| isGroupedExpressionToken, | ||
| isNumberToken, | ||
| isPropertyAccessToken, | ||
| isQuotedToken, | ||
|
|
@@ -371,6 +372,16 @@ function * extractValueTokenVariables (token: ValueToken): Generator<Variable> { | |
| if (isRangeToken(token)) { | ||
| yield * extractValueTokenVariables(token.lhs) | ||
| yield * extractValueTokenVariables(token.rhs) | ||
| } else if (isGroupedExpressionToken(token)) { | ||
| for (const t of token.initial.postfix) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. create a |
||
| if (isValueToken(t)) yield * extractValueTokenVariables(t) | ||
| } | ||
| for (const filter of token.filters) { | ||
| for (const arg of filter.args) { | ||
| if (isKeyValuePair(arg) && arg[1]) yield * extractValueTokenVariables(arg[1]) | ||
| else if (isValueToken(arg)) yield * extractValueTokenVariables(arg) | ||
| } | ||
| } | ||
| } else if (isPropertyAccessToken(token)) { | ||
| yield extractPropertyAccessVariable(token) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why
readNumberis special to move it afterreadGroupOrRange?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had a quick look,it also returns
undefinedwhen no number is valid to read.