chore(TypeScript): demo for typescript

This commit is contained in:
harttle
2019-02-17 14:22:13 +08:00
parent 677e8511e6
commit 7ee87008c7
22 changed files with 9062 additions and 53 deletions
+1
View File
@@ -8,6 +8,7 @@ import { evalValue } from 'src/render/syntax'
* hash['foo'] === 'bar'
*/
export default class Hash {
[key: string]: any
constructor(markup, scope) {
let match
hashCapture.lastIndex = 0
+10
View File
@@ -0,0 +1,10 @@
import Scope from 'src/scope/scope'
import TagToken from 'src/parser/tag-token'
import Token from 'src/parser/token'
import Hash from 'src/template/tag/hash'
import ITagImpl from './itag-impl'
export default interface ITagImplOptions {
parse?: (this: ITagImpl, token: TagToken, remainingTokens: Array<Token>) => void
render?: (this: ITagImpl, scope: Scope, hash: Hash) => string | Promise<string>
}
+6
View File
@@ -0,0 +1,6 @@
import Liquid from 'src/liquid'
import ITagImplOptions from './itag-impl-options'
export default interface ITagImpl extends ITagImplOptions {
liquid: Liquid
}
+6 -4
View File
@@ -1,7 +1,9 @@
import { create } from 'src/util/underscore'
import { stringify } from 'src/util/underscore'
import assert from 'src/util/assert'
import TagImpl from './tagimpl'
import ITagImpl from './itag-impl'
import ITagImplOptions from './itag-impl-options'
import Liquid from 'src/liquid'
import Hash from './hash'
import Template from 'src/template/template'
import ITemplate from 'src/template/itemplate'
@@ -10,10 +12,10 @@ import TagToken from 'src/parser/tag-token'
export default class Tag extends Template implements ITemplate {
name: string
token: TagToken
private impl: TagImpl
private impl: ITagImpl
static impls: object = {}
constructor (token, tokens, liquid) {
constructor (token, tokens, liquid: Liquid) {
super(token)
this.name = token.name
@@ -34,7 +36,7 @@ export default class Tag extends Template implements ITemplate {
const html = await impl.render(scope, hash)
return stringify(html)
}
static register (name, tag) {
static register (name: string, tag: ITagImplOptions) {
Tag.impls[name] = tag
}
static clear () {
-8
View File
@@ -1,8 +0,0 @@
import Liquid from 'src/liquid'
import Scope from 'src/scope/scope'
export default interface TagImpl {
liquid: Liquid
parse: (token: any, remainingTokens: Array<any>) => void
render: (scope: Scope, hash: any) => Promise<string>
}