mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
chore(TypeScript): demo for typescript
This commit is contained in:
+2
-1
@@ -8,6 +8,7 @@ import Render from './render/render'
|
||||
import Tag from './template/tag/tag'
|
||||
import Filter from './template/filter'
|
||||
import Parser from './parser/parser'
|
||||
import ITagImplOptions from './template/tag/itag-impl-options'
|
||||
import Value from './template/value'
|
||||
import { isTruthy, isFalsy, evalExp, evalValue } from './render/syntax'
|
||||
import builtinTags from './builtin/tags'
|
||||
@@ -76,7 +77,7 @@ export default class Liquid {
|
||||
registerFilter (name, filter) {
|
||||
return Filter.register(name, filter)
|
||||
}
|
||||
registerTag (name, tag) {
|
||||
registerTag (name: string, tag: ITagImplOptions) {
|
||||
return Tag.register(name, tag)
|
||||
}
|
||||
plugin (plugin) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import Liquid from 'src/liquid'
|
||||
import ITagImplOptions from './itag-impl-options'
|
||||
|
||||
export default interface ITagImpl extends ITagImplOptions {
|
||||
liquid: Liquid
|
||||
}
|
||||
@@ -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 () {
|
||||
|
||||
@@ -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>
|
||||
}
|
||||
+7
-7
@@ -8,14 +8,14 @@ function captureStack () {
|
||||
}
|
||||
|
||||
abstract class LiquidError {
|
||||
input: string
|
||||
line: string
|
||||
file: string
|
||||
message: string
|
||||
name: string
|
||||
message: string
|
||||
stack: string
|
||||
token: Token
|
||||
originalError: Error
|
||||
private line: string
|
||||
private file: string
|
||||
private input: string
|
||||
private token: Token
|
||||
private originalError: Error
|
||||
constructor(err, token) {
|
||||
this.input = token.input
|
||||
this.line = token.line
|
||||
@@ -30,7 +30,7 @@ abstract class LiquidError {
|
||||
const err = this.originalError
|
||||
const context = mkContext(this.input, this.line)
|
||||
this.message = mkMessage(err.message, this.token)
|
||||
this.stack = context +
|
||||
this.stack = this.message + '\n' + context +
|
||||
'\n' + (this.stack || this.message) +
|
||||
(err.stack ? '\nFrom ' + err.stack : '')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user