mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-18 05:50:43 -07:00
chore: upgrade typescript
This commit is contained in:
@@ -12,7 +12,7 @@ export class Output extends TemplateImpl<OutputToken> implements Template {
|
||||
super(token)
|
||||
this.value = new Value(token.content, liquid)
|
||||
}
|
||||
public * render (ctx: Context, emitter: Emitter) {
|
||||
public * render (ctx: Context, emitter: Emitter): Generator<unknown, void, unknown> {
|
||||
const val = yield this.value.value(ctx, false)
|
||||
emitter.write(val)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@ import { evalToken } from '../../render/expression'
|
||||
import { Context } from '../../context/context'
|
||||
import { Tokenizer } from '../../parser/tokenizer'
|
||||
|
||||
export interface HashValue {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Key-Value Pairs Representing Tag Arguments
|
||||
* Example:
|
||||
@@ -11,14 +15,14 @@ import { Tokenizer } from '../../parser/tokenizer'
|
||||
* hash['reversed'] === undefined
|
||||
*/
|
||||
export class Hash {
|
||||
hash: { [key: string]: any } = {}
|
||||
hash: HashValue = {}
|
||||
constructor (markup: string) {
|
||||
const tokenizer = new Tokenizer(markup, {})
|
||||
for (const hash of tokenizer.readHashes()) {
|
||||
this.hash[hash.name.content] = hash.value
|
||||
}
|
||||
}
|
||||
* render (ctx: Context) {
|
||||
* render (ctx: Context): Generator<unknown, HashValue, unknown> {
|
||||
const hash = {}
|
||||
for (const key of Object.keys(this.hash)) {
|
||||
hash[key] = this.hash[key] === undefined ? true : yield evalToken(this.hash[key], ctx)
|
||||
|
||||
@@ -2,10 +2,10 @@ import { Context } from '../../context/context'
|
||||
import { TagToken } from '../../tokens/tag-token'
|
||||
import { TopLevelToken } from '../../tokens/toplevel-token'
|
||||
import { TagImpl } from './tag-impl'
|
||||
import { Hash } from '../../template/tag/hash'
|
||||
import { HashValue } from '../../template/tag/hash'
|
||||
import { Emitter } from '../../emitters/emitter'
|
||||
|
||||
export interface TagImplOptions {
|
||||
parse?: (this: TagImpl, token: TagToken, remainingTokens: TopLevelToken[]) => void;
|
||||
render: (this: TagImpl, ctx: Context, emitter: Emitter, hash: Hash) => any;
|
||||
render: (this: TagImpl, ctx: Context, emitter: Emitter, hash: HashValue) => void | string | Promise<void | string> | Generator<unknown, void | string, unknown>;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Liquid } from '../../liquid'
|
||||
import { TemplateImpl } from '../../template/template-impl'
|
||||
import { Emitter, Hash, Context, TagToken, Template, TopLevelToken } from '../../types'
|
||||
import { TagImpl } from './tag-impl'
|
||||
import { HashValue } from './hash'
|
||||
|
||||
export class Tag extends TemplateImpl<TagToken> implements Template {
|
||||
public name: string
|
||||
@@ -20,8 +21,8 @@ export class Tag extends TemplateImpl<TagToken> implements Template {
|
||||
this.impl.parse(token, tokens)
|
||||
}
|
||||
}
|
||||
public * render (ctx: Context, emitter: Emitter) {
|
||||
const hash = yield new Hash(this.token.args).render(ctx)
|
||||
public * render (ctx: Context, emitter: Emitter): Generator<unknown, unknown, HashValue | unknown> {
|
||||
const hash = (yield new Hash(this.token.args).render(ctx)) as HashValue
|
||||
const impl = this.impl
|
||||
if (isFunction(impl.render)) return yield impl.render(ctx, emitter, hash)
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export class Value {
|
||||
this.initial = tokenizer.readExpression()
|
||||
this.filters = tokenizer.readFilters().map(({ name, args }) => new Filter(name, liquid.filters.get(name), args, liquid))
|
||||
}
|
||||
public * value (ctx: Context, lenient: boolean) {
|
||||
public * value (ctx: Context, lenient: boolean): Generator<unknown, unknown, unknown> {
|
||||
lenient = lenient || (ctx.opts.lenientIf && this.filters.length > 0 && this.filters[0].name === 'default')
|
||||
let val = yield this.initial.evaluate(ctx, lenient)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user