Skip to content

Commit 38a0f51

Browse files
committed
fix: empty tagToken.args since 10.20.0, fixes #796
1 parent 1a893f8 commit 38a0f51

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/tokens/tag-token.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { NormalizedFullOptions } from '../liquid-options'
55
export class TagToken extends DelimitedToken {
66
public name: string
77
public tokenizer: Tokenizer
8+
public readonly args: string;
89
public constructor (
910
input: string,
1011
begin: number,
@@ -20,9 +21,6 @@ export class TagToken extends DelimitedToken {
2021
this.name = this.tokenizer.readTagName()
2122
this.tokenizer.assert(this.name, `illegal tag syntax, tag name expected`)
2223
this.tokenizer.skipBlank()
23-
}
24-
25-
get args (): string {
26-
return this.tokenizer.input.slice(this.tokenizer.p, this.contentRange[1])
24+
this.args = this.tokenizer.input.slice(this.tokenizer.p, this.contentRange[1])
2725
}
2826
}

test/e2e/issues.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TopLevelToken, TagToken, Tokenizer, Context, Liquid, Drop, toValueSync, LiquidError } from '../..'
1+
import { TopLevelToken, TagToken, Tokenizer, Context, Liquid, Drop, toValueSync, LiquidError, IfTag } from '../..'
22
const LiquidUMD = require('../../dist/liquid.browser.umd.js').Liquid
33

44
describe('Issues', function () {
@@ -558,4 +558,11 @@ describe('Issues', function () {
558558
CSharp <sup>2</sup> Posts:page2,page4,
559559
CPP <sup>1</sup> Posts:page0,`)
560560
})
561+
it('if tag condition, the token args is empty #796', () => {
562+
const tpl = 'Hello, {% if name %} {{ name }} {% else %} user {% endif %}'
563+
const engine = new Liquid()
564+
const parsed = engine.parse(tpl)
565+
const ifToken = parsed[1]
566+
expect((ifToken as IfTag).token.args).toEqual('name')
567+
})
561568
})

0 commit comments

Comments
 (0)