From 88c89fe3b326ab06d797ddefea83bd8ac2f4bc5b Mon Sep 17 00:00:00 2001 From: harttle Date: Sat, 6 Jul 2019 14:33:34 +0800 Subject: [PATCH] style: introduce @typescript-eslint/recommended --- .eslintrc.json | 10 +++- package-lock.json | 59 +++++++++++++--------- package.json | 3 +- src/builtin/filters/array.ts | 2 +- src/builtin/filters/math.ts | 2 +- src/builtin/tags/cycle.ts | 4 +- src/builtin/tags/for.ts | 4 +- src/builtin/tags/include.ts | 4 +- src/builtin/tags/raw.ts | 4 +- src/context/context.ts | 22 ++++---- src/context/scope.ts | 6 +-- src/drop/blank-drop.ts | 2 +- src/drop/drop.ts | 4 +- src/drop/empty-drop.ts | 12 ++--- src/drop/forloop-drop.ts | 20 ++++---- src/drop/icomparable.ts | 10 ++-- src/drop/null-drop.ts | 12 ++--- src/drop/tablerowloop-drop.ts | 12 ++--- src/fs/ifs.ts | 6 +-- src/liquid-options.ts | 64 ++++++++++++------------ src/liquid.ts | 34 ++++++------- src/parser/delimited-token.ts | 2 +- src/parser/html-token.ts | 4 +- src/parser/output-token.ts | 4 +- src/parser/parse-stream.ts | 12 ++--- src/parser/parser.ts | 10 ++-- src/parser/tag-token.ts | 8 +-- src/parser/token.ts | 20 ++++---- src/parser/tokenizer.ts | 4 +- src/render/render.ts | 2 +- src/template/filter/filter-impl.ts | 2 +- src/template/filter/filter.ts | 16 +++--- src/template/html.ts | 6 +-- src/template/output.ts | 6 +-- src/template/tag/hash.ts | 2 +- src/template/tag/itag-impl-options.ts | 4 +- src/template/tag/itag-impl.ts | 4 +- src/template/tag/tag.ts | 12 ++--- src/template/template.ts | 4 +- src/template/value.ts | 10 ++-- src/util/error.ts | 14 +++--- src/util/underscore.ts | 2 +- test/e2e/drop.ts | 12 ++--- test/e2e/xhr.ts | 4 +- test/integration/builtin/tags/include.ts | 4 +- test/integration/drop/drop.ts | 12 ++--- test/stub/mockfs.ts | 11 ++-- test/unit/parser/lexical.ts | 8 +-- 48 files changed, 260 insertions(+), 235 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 9b85153f0..2fbd4286b 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,5 +1,5 @@ { - "extends": "standard", + "extends": ["standard", "plugin:@typescript-eslint/recommended"], "env": { "mocha": true, "es6": true, @@ -17,6 +17,14 @@ "no-var": 2, "prefer-const": 2, "no-unused-vars": "off", + "indent": "off", + "@typescript-eslint/indent": ["error", 2], + "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-object-literal-type-assertion": "off", + "@typescript-eslint/no-use-before-define": "off", + "@typescript-eslint/interface-name-prefix": "off", + "@typescript-eslint/no-non-null-assertion": "off", "import/export": "off", "@typescript-eslint/no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": false }] } diff --git a/package-lock.json b/package-lock.json index fc49cbd8f..64a2317c6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -448,6 +448,12 @@ "integrity": "sha512-aRnpPa7ysx3aNW60hTiCtLHlQaIFsXFCgQlpakNgDNVFzbtusSY8PwjAQgRWfSk0ekNoBjO51eQRB6upA9uuyw==", "dev": true }, + "@types/eslint-visitor-keys": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@types/eslint-visitor-keys/-/eslint-visitor-keys-1.0.0.tgz", + "integrity": "sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==", + "dev": true + }, "@types/estree": { "version": "0.0.39", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", @@ -568,31 +574,44 @@ "dev": true }, "@typescript-eslint/eslint-plugin": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-1.3.0.tgz", - "integrity": "sha512-s+vjO9+PvYS2A6FnQC/imyEDOkrEKIzSpPf2OEGnkKqa5+1d0cuXgCi/oROtuBht2/u/iK22nrYcO/Ei4R8F/g==", + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-1.11.0.tgz", + "integrity": "sha512-mXv9ccCou89C8/4avKHuPB2WkSZyY/XcTQUXd5LFZAcLw1I3mWYVjUu6eS9Ja0QkP/ClolbcW9tb3Ov/pMdcqw==", "dev": true, "requires": { - "@typescript-eslint/parser": "1.3.0", - "requireindex": "^1.2.0", + "@typescript-eslint/experimental-utils": "1.11.0", + "eslint-utils": "^1.3.1", + "functional-red-black-tree": "^1.0.1", + "regexpp": "^2.0.1", "tsutils": "^3.7.0" } }, - "@typescript-eslint/parser": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-1.3.0.tgz", - "integrity": "sha512-Q5cz9nyEQyRrtItRElvQXdNs0Xja1xvOdphDQR7N6MqUdi4juWVNxHKypdHQCx9OcEBev6pWHOda8lwg/2W9/g==", + "@typescript-eslint/experimental-utils": { + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-1.11.0.tgz", + "integrity": "sha512-7LbfaqF6B8oa8cp/315zxKk8FFzosRzzhF8Kn/ZRsRsnpm7Qcu25cR/9RnAQo5utZ2KIWVgaALr+ZmcbG47ruw==", "dev": true, "requires": { - "@typescript-eslint/typescript-estree": "1.3.0", - "eslint-scope": "^4.0.0", + "@typescript-eslint/typescript-estree": "1.11.0", + "eslint-scope": "^4.0.0" + } + }, + "@typescript-eslint/parser": { + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-1.11.0.tgz", + "integrity": "sha512-5xBExyXaxVyczrZvbRKEXvaTUFFq7gIM9BynXukXZE0zF3IQP/FxF4mPmmh3gJ9egafZFqByCpPTFm3dk4SY7Q==", + "dev": true, + "requires": { + "@types/eslint-visitor-keys": "^1.0.0", + "@typescript-eslint/experimental-utils": "1.11.0", + "@typescript-eslint/typescript-estree": "1.11.0", "eslint-visitor-keys": "^1.0.0" } }, "@typescript-eslint/typescript-estree": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-1.3.0.tgz", - "integrity": "sha512-h6UxHSmBUopFcxHg/eryrA+GwHMbh7PxotMbkq9p2f3nX60CKm5Zc0VN8krBD3IS5KqsK0iOz24VpEWrP+JZ2Q==", + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-1.11.0.tgz", + "integrity": "sha512-fquUHF5tAx1sM2OeRCC7wVxFd1iMELWMGCzOSmJ3pLzArj9+kRixdlC4d5MncuzXpjEqc6045p3KwM0o/3FuUA==", "dev": true, "requires": { "lodash.unescape": "4.0.1", @@ -9316,12 +9335,6 @@ "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", "dev": true }, - "requireindex": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.2.0.tgz", - "integrity": "sha512-L9jEkOi3ASd9PYit2cwRfyppc9NoABujTP8/5gFcbERmo5jUoAKovIC3fsF17pkTnGsrByysqX+Kxd2OTNI1ww==", - "dev": true - }, "resolve": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.10.0.tgz", @@ -10475,9 +10488,9 @@ "dev": true }, "tsutils": { - "version": "3.8.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.8.0.tgz", - "integrity": "sha512-XQdPhgcoTbCD8baXC38PQ0vpTZ8T3YrE+vR66YIj/xvDt1//8iAhafpIT/4DmvzzC1QFapEImERu48Pa01dIUA==", + "version": "3.14.0", + "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.14.0.tgz", + "integrity": "sha512-SmzGbB0l+8I0QwsPgjooFRaRvHLBLNYM8SeQ0k6rtNDru5sCGeLJcZdwilNndN+GysuFjF5EIYgN8GfFG6UeUw==", "dev": true, "requires": { "tslib": "^1.8.1" diff --git a/package.json b/package.json index c5d675e83..4272712d7 100644 --- a/package.json +++ b/package.json @@ -57,7 +57,8 @@ "@types/sinon": "^7.0.6", "@types/sinon-chai": "^3.2.2", "@types/supertest": "^2.0.7", - "@typescript-eslint/eslint-plugin": "^1.3.0", + "@typescript-eslint/eslint-plugin": "^1.11.0", + "@typescript-eslint/parser": "^1.11.0", "benchmark": "^2.1.4", "chai": "^4.2.0", "chai-as-promised": "^7.1.1", diff --git a/src/builtin/filters/array.ts b/src/builtin/filters/array.ts index 6033b7ce4..d357abe04 100644 --- a/src/builtin/filters/array.ts +++ b/src/builtin/filters/array.ts @@ -9,7 +9,7 @@ export default { 'reverse': (v: any[]) => [...v].reverse(), 'sort': (v: T[], arg: (lhs: T, rhs: T) => number) => v.sort(arg), 'size': (v: string | any[]) => v.length, - 'concat': (v: T1[], arg: T2[] | T2): Array => Array.prototype.concat.call(v, arg), + 'concat': (v: T1[], arg: T2[] | T2): (T1 | T2)[] => Array.prototype.concat.call(v, arg), 'slice': (v: T[], begin: number, length: number = 1): T[] => { begin = begin < 0 ? v.length + begin : begin return v.slice(begin, begin + length) diff --git a/src/builtin/filters/math.ts b/src/builtin/filters/math.ts index b7c8811a4..4dc69f84c 100644 --- a/src/builtin/filters/math.ts +++ b/src/builtin/filters/math.ts @@ -18,7 +18,7 @@ export default { 'times': (v: number, arg: number) => v * arg } -function caseInsensitiveCmp (a, b) { +function caseInsensitiveCmp (a: any, b: any) { if (!b) return -1 if (!a) return 1 a = toLowerCase.call(a) diff --git a/src/builtin/tags/cycle.ts b/src/builtin/tags/cycle.ts index 1095a5758..c10ee06df 100644 --- a/src/builtin/tags/cycle.ts +++ b/src/builtin/tags/cycle.ts @@ -8,7 +8,7 @@ import ITagImplOptions from '../../template/tag/itag-impl-options' const groupRE = new RegExp(`^(?:(${rValue.source})\\s*:\\s*)?(.*)$`) const candidatesRE = new RegExp(rValue.source, 'g') -export default { +export default { parse: function (tagToken: TagToken) { let match: RegExpExecArray | null = groupRE.exec(tagToken.args) as RegExpExecArray assert(match, `illegal tag: ${tagToken.raw}`) @@ -40,4 +40,4 @@ export default { return evalValue(candidate, ctx) } -} +} as ITagImplOptions diff --git a/src/builtin/tags/for.ts b/src/builtin/tags/for.ts index dcd427c4d..3529977d8 100644 --- a/src/builtin/tags/for.ts +++ b/src/builtin/tags/for.ts @@ -17,7 +17,7 @@ const re = new RegExp(`^(${identifier.source})\\s+in\\s+` + `(?:\\s+(reversed))?` + `(?:\\s+${hash.source})*$`) -export default { +export default { type: 'block', parse: function (tagToken: TagToken, remainTokens: Token[]) { const match = re.exec(tagToken.args) as RegExpExecArray @@ -79,4 +79,4 @@ export default { ctx.pop() return html } -} +} as ITagImplOptions diff --git a/src/builtin/tags/include.ts b/src/builtin/tags/include.ts index f0c34f2d1..94162debf 100644 --- a/src/builtin/tags/include.ts +++ b/src/builtin/tags/include.ts @@ -10,7 +10,7 @@ import ITagImplOptions from '../../template/tag/itag-impl-options' const staticFileRE = /[^\s,]+/ const withRE = new RegExp(`with\\s+(${value.source})`) -export default { +export default { parse: function (token: TagToken) { let match = staticFileRE.exec(token.args) if (match) this.staticValue = match[0] @@ -51,4 +51,4 @@ export default { ctx.setRegister('blockMode', originBlockMode) return html } -} +} as ITagImplOptions diff --git a/src/builtin/tags/raw.ts b/src/builtin/tags/raw.ts index 7863d3e28..bfcfe0ede 100644 --- a/src/builtin/tags/raw.ts +++ b/src/builtin/tags/raw.ts @@ -2,7 +2,7 @@ import TagToken from '../../parser/tag-token' import Token from '../../parser/token' import ITagImplOptions from '../../template/tag/itag-impl-options' -export default { +export default { parse: function (tagToken: TagToken, remainTokens: Token[]) { this.tokens = [] @@ -20,4 +20,4 @@ export default { render: function () { return this.tokens.map((token: Token) => token.raw).join('') } -} +} as ITagImplOptions diff --git a/src/context/context.ts b/src/context/context.ts index 196776763..53b6b200d 100644 --- a/src/context/context.ts +++ b/src/context/context.ts @@ -6,25 +6,25 @@ import { NormalizedFullOptions, applyDefault } from '../liquid-options' import { Scope } from './scope' export default class Context { - opts: NormalizedFullOptions - environments: Scope - private scopes: Array = [{}] + private scopes: Scope[] = [{}] private registers = {} - constructor (ctx: object = {}, opts?: NormalizedFullOptions) { + public environments: Scope + public opts: NormalizedFullOptions + public constructor (ctx: object = {}, opts?: NormalizedFullOptions) { this.opts = applyDefault(opts) this.environments = ctx } - getRegister (key: string, defaultValue = {}) { + public getRegister (key: string, defaultValue = {}) { return (this.registers[key] = this.registers[key] || defaultValue) } - setRegister (key: string, value: any) { + public setRegister (key: string, value: any) { return (this.registers[key] = value) } - getAll () { + public getAll () { return [this.environments, ...this.scopes] .reduce((ctx, val) => __assign(ctx, val), {}) } - async get (path: string) { + public async get (path: string) { const paths = await this.parseProp(path) let ctx = this.findScope(paths[0]) || this.environments for (const path of paths) { @@ -35,13 +35,13 @@ export default class Context { } return ctx } - push (ctx: object) { + public push (ctx: object) { return this.scopes.push(ctx) } - pop () { + public pop () { return this.scopes.pop() } - front () { + public front () { return this.scopes[0] } private findScope (key: string) { diff --git a/src/context/scope.ts b/src/context/scope.ts index 3ae6aca30..18c6f4ce6 100644 --- a/src/context/scope.ts +++ b/src/context/scope.ts @@ -1,8 +1,8 @@ import { Drop } from '../drop/drop' -type PlainObject = { - [key: string]: any - toLiquid?: () => any +interface PlainObject { + [key: string]: any; + toLiquid?: () => any; } export type Scope = PlainObject | Drop diff --git a/src/drop/blank-drop.ts b/src/drop/blank-drop.ts index 23713e0d1..652dcf8b1 100644 --- a/src/drop/blank-drop.ts +++ b/src/drop/blank-drop.ts @@ -2,7 +2,7 @@ import { isNil, isString, toValue } from '../util/underscore' import { EmptyDrop } from '../drop/empty-drop' export class BlankDrop extends EmptyDrop { - equals (value: any) { + public equals (value: any) { if (value === false) return true if (isNil(toValue(value))) return true if (isString(value)) return /^\s*$/.test(value) diff --git a/src/drop/drop.ts b/src/drop/drop.ts index 7015e39a1..8ea839c75 100644 --- a/src/drop/drop.ts +++ b/src/drop/drop.ts @@ -1,9 +1,9 @@ export abstract class Drop { - valueOf (): any { + public valueOf (): any { return undefined } - liquidMethodMissing (key: string): Promise | string | undefined { + public liquidMethodMissing (key: string): Promise | string | undefined { return undefined } } diff --git a/src/drop/empty-drop.ts b/src/drop/empty-drop.ts index 8cd095c58..5b8becab0 100644 --- a/src/drop/empty-drop.ts +++ b/src/drop/empty-drop.ts @@ -3,24 +3,24 @@ import { IComparable } from './icomparable' import { isObject, isString, isArray } from '../util/underscore' export class EmptyDrop extends Drop implements IComparable { - equals (value: any) { + public equals (value: any) { if (isString(value) || isArray(value)) return value.length === 0 if (isObject(value)) return Object.keys(value).length === 0 return false } - gt () { + public gt () { return false } - geq () { + public geq () { return false } - lt () { + public lt () { return false } - leq () { + public leq () { return false } - valueOf () { + public valueOf () { return '' } } diff --git a/src/drop/forloop-drop.ts b/src/drop/forloop-drop.ts index 699d5c429..f902a5663 100644 --- a/src/drop/forloop-drop.ts +++ b/src/drop/forloop-drop.ts @@ -2,33 +2,33 @@ import { Drop } from './drop' export class ForloopDrop extends Drop { protected i: number = 0 - length: number - constructor (length: number) { + public length: number + public constructor (length: number) { super() this.length = length } - next () { + public next () { this.i++ } - index0 () { + public index0 () { return this.i } - index () { + public index () { return this.i + 1 } - first () { + public first () { return this.i === 0 } - last () { + public last () { return this.i === this.length - 1 } - rindex () { + public rindex () { return this.length - this.i } - rindex0 () { + public rindex0 () { return this.length - this.i - 1 } - valueOf () { + public valueOf () { return JSON.stringify(this) } } diff --git a/src/drop/icomparable.ts b/src/drop/icomparable.ts index a07a5501f..cf11ca870 100644 --- a/src/drop/icomparable.ts +++ b/src/drop/icomparable.ts @@ -1,11 +1,11 @@ import { isFunction } from '../util/underscore' export interface IComparable { - equals: (rhs: any) => boolean - gt: (rhs: any) => boolean - geq: (rhs: any) => boolean - lt: (rhs: any) => boolean - leq: (rhs: any) => boolean + equals: (rhs: any) => boolean; + gt: (rhs: any) => boolean; + geq: (rhs: any) => boolean; + lt: (rhs: any) => boolean; + leq: (rhs: any) => boolean; } export function isComparable (arg: any): arg is IComparable { diff --git a/src/drop/null-drop.ts b/src/drop/null-drop.ts index 239b92301..5c8026e93 100644 --- a/src/drop/null-drop.ts +++ b/src/drop/null-drop.ts @@ -4,22 +4,22 @@ import { isNil, toValue } from '../util/underscore' import { BlankDrop } from '../drop/blank-drop' export class NullDrop extends Drop implements IComparable { - equals (value: any) { + public equals (value: any) { return isNil(toValue(value)) || value instanceof BlankDrop } - gt () { + public gt () { return false } - geq () { + public geq () { return false } - lt () { + public lt () { return false } - leq () { + public leq () { return false } - valueOf () { + public valueOf () { return null } } diff --git a/src/drop/tablerowloop-drop.ts b/src/drop/tablerowloop-drop.ts index 835bf3737..041ef9661 100644 --- a/src/drop/tablerowloop-drop.ts +++ b/src/drop/tablerowloop-drop.ts @@ -2,24 +2,24 @@ import { ForloopDrop } from './forloop-drop' export class TablerowloopDrop extends ForloopDrop { private cols: number - constructor (length: number, cols: number) { + public constructor (length: number, cols: number) { super(length) this.length = length this.cols = cols } - row () { + public row () { return Math.floor(this.i / this.cols) + 1 } - col0 () { + public col0 () { return (this.i % this.cols) } - col () { + public col () { return this.col0() + 1 } - col_first () { // eslint-disable-line + public col_first () { // eslint-disable-line return this.col0() === 0 } - col_last () { // eslint-disable-line + public col_last () { // eslint-disable-line return this.col() === this.cols } } diff --git a/src/fs/ifs.ts b/src/fs/ifs.ts index cc4392c23..6734e937e 100644 --- a/src/fs/ifs.ts +++ b/src/fs/ifs.ts @@ -1,5 +1,5 @@ export default interface IFS { - exists: (filepath: string) => Promise - readFile: (filepath:string) => Promise - resolve: (root: string, file: string, ext: string) => string + exists: (filepath: string) => Promise; + readFile: (filepath: string) => Promise; + resolve: (root: string, file: string, ext: string) => string; } diff --git a/src/liquid-options.ts b/src/liquid-options.ts index c154a6eb9..abc6f3a61 100644 --- a/src/liquid-options.ts +++ b/src/liquid-options.ts @@ -3,57 +3,57 @@ import IFS from './fs/ifs' export interface LiquidOptions { /** `root` is a directory or an array of directories to resolve layouts and includes, as well as the filename passed in when calling `.renderFile()`. If an array, the files are looked up in the order they occur in the array. Defaults to `["."]` */ - root?: string | string[] + root?: string | string[]; /** `extname` is used to lookup the template file when filepath doesn't include an extension name. Eg: setting to `".html"` will allow including file by basename. Defaults to `""`. */ - extname?: string + extname?: string; /** `cache` indicates whether or not to cache resolved templates. Defaults to `false`. */ - cache?: boolean + cache?: boolean; /** `dynamicPartials`: if set, treat `` parameter in `{%include filepath %}`, `{%layout filepath%}` as a variable, otherwise as a literal value. Defaults to `true`. */ - dynamicPartials?: boolean + dynamicPartials?: boolean; /** `strictFilters` is used to enable strict filter existence. If set to `false`, undefined filters will be rendered as empty string. Otherwise, undefined filters will cause an exception. Defaults to `false`. */ - strictFilters?: boolean + strictFilters?: boolean; /** `strictVariables` is used to enable strict variable derivation. If set to `false`, undefined variables will be rendered as empty string. Otherwise, undefined variables will cause an exception. Defaults to `false`. */ - strictVariables?: boolean + strictVariables?: boolean; /** `trimTagRight` is used to strip blank characters (including ` `, `\t`, and `\r`) from the right of tags (`{% %}`) until `\n` (inclusive). Defaults to `false`. */ - trimTagRight?: boolean + trimTagRight?: boolean; /** `trimTagLeft` is similar to `trimTagRight`, whereas the `\n` is exclusive. Defaults to `false`. See Whitespace Control for details. */ - trimTagLeft?: boolean + trimTagLeft?: boolean; /** ``trimOutputRight` is used to strip blank characters (including ` `, `\t`, and `\r`) from the right of values (`{{ }}`) until `\n` (inclusive). Defaults to `false`. */ - trimOutputRight?: boolean + trimOutputRight?: boolean; /** `trimOutputLeft` is similar to `trimOutputRight`, whereas the `\n` is exclusive. Defaults to `false`. See Whitespace Control for details. */ - trimOutputLeft?: boolean + trimOutputLeft?: boolean; /** `tagDelimiterLeft` and `tagDelimiterRight` are used to override the delimiter for liquid tags **/ - tagDelimiterLeft?: string, - tagDelimiterRight?: string, + tagDelimiterLeft?: string; + tagDelimiterRight?: string; /** `outputDelimiterLeft` and `outputDelimiterRight` are used to override the delimiter for liquid outputs **/ - outputDelimiterLeft?: string, - outputDelimiterRight?: string, + outputDelimiterLeft?: string; + outputDelimiterRight?: string; /** `greedy` is used to specify whether `trim*Left`/`trim*Right` is greedy. When set to `true`, all consecutive blank characters including `\n` will be trimed regardless of line breaks. Defaults to `true`. */ - greedy?: boolean, + greedy?: boolean; /** `fs` is used to override the default file-system module with a custom implementation */ - fs?: IFS + fs?: IFS; } interface NormalizedOptions extends LiquidOptions { - root?: string[] + root?: string[]; } export interface NormalizedFullOptions extends NormalizedOptions { - root: string[] - extname: string - cache: boolean - dynamicPartials: boolean - strictFilters: boolean - strictVariables: boolean - trimTagRight: boolean - trimTagLeft: boolean - trimOutputRight: boolean - trimOutputLeft: boolean - tagDelimiterLeft: string, - tagDelimiterRight: string, - outputDelimiterLeft: string, - outputDelimiterRight: string, - greedy: boolean + root: string[]; + extname: string; + cache: boolean; + dynamicPartials: boolean; + strictFilters: boolean; + strictVariables: boolean; + trimTagRight: boolean; + trimTagLeft: boolean; + trimOutputRight: boolean; + trimOutputLeft: boolean; + tagDelimiterLeft: string; + tagDelimiterRight: string; + outputDelimiterLeft: string; + outputDelimiterRight: string; + greedy: boolean; } const defaultOptions: NormalizedFullOptions = { diff --git a/src/liquid.ts b/src/liquid.ts index 3fbbe1859..89f463ca8 100644 --- a/src/liquid.ts +++ b/src/liquid.ts @@ -25,7 +25,7 @@ export default class Liquid { private tokenizer: Tokenizer private fs: IFS - constructor (opts: LiquidOptions = {}) { + public constructor (opts: LiquidOptions = {}) { this.options = applyDefault(normalize(opts)) this.parser = new Parser(this) this.renderer = new Render() @@ -35,20 +35,20 @@ export default class Liquid { _.forOwn(builtinTags, (conf, name) => this.registerTag(name, conf)) _.forOwn(builtinFilters, (handler, name) => this.registerFilter(name, handler)) } - parse (html: string, filepath?: string) { + public parse (html: string, filepath?: string) { const tokens = this.tokenizer.tokenize(html, filepath) return this.parser.parse(tokens) } - render (tpl: Array, ctx?: object, opts?: LiquidOptions) { + public render (tpl: ITemplate[], ctx?: object, opts?: LiquidOptions) { const options = { ...this.options, ...normalize(opts) } const scope = new Context(ctx, options) return this.renderer.renderTemplates(tpl, scope) } - async parseAndRender (html: string, ctx?: object, opts?: LiquidOptions) { + public async parseAndRender (html: string, ctx?: object, opts?: LiquidOptions) { const tpl = await this.parse(html) return this.render(tpl, ctx, opts) } - async getTemplate (file: string, opts?: LiquidOptions) { + public async getTemplate (file: string, opts?: LiquidOptions) { const options = normalize(opts) const roots = options.root ? [...options.root, ...this.options.root] : this.options.root const paths = roots.map(root => this.fs.resolve(root, file, this.options.extname)) @@ -68,34 +68,34 @@ export default class Liquid { err.code = 'ENOENT' throw err } - async renderFile (file: string, ctx?: object, opts?: LiquidOptions) { + public async renderFile (file: string, ctx?: object, opts?: LiquidOptions) { const options = normalize(opts) const templates = await this.getTemplate(file, options) return this.render(templates, ctx, opts) } - evalValue (str: string, ctx: Context) { + public evalValue (str: string, ctx: Context) { return new Value(str, this.options.strictFilters).value(ctx) } - registerFilter (name: string, filter: FilterImplOptions) { + public registerFilter (name: string, filter: FilterImplOptions) { return Filter.register(name, filter) } - registerTag (name: string, tag: ITagImplOptions) { + public registerTag (name: string, tag: ITagImplOptions) { return Tag.register(name, tag) } - plugin (plugin: (this: Liquid, L: typeof Liquid) => void) { + public plugin (plugin: (this: Liquid, L: typeof Liquid) => void) { return plugin.call(this, Liquid) } - express () { + public express () { const self = this return function (this: any, filePath: string, ctx: object, cb: (err: Error | null, html?: string) => void) { const opts = { root: this.root } self.renderFile(filePath, ctx, opts).then(html => cb(null, html), cb) } } - static default = Liquid - static isTruthy = isTruthy - static isFalsy = isFalsy - static evalExp = evalExp - static evalValue = evalValue - static Types = Types + public static default = Liquid + public static isTruthy = isTruthy + public static isFalsy = isFalsy + public static evalExp = evalExp + public static evalValue = evalValue + public static Types = Types } diff --git a/src/parser/delimited-token.ts b/src/parser/delimited-token.ts index bc3d011b8..e2371dcca 100644 --- a/src/parser/delimited-token.ts +++ b/src/parser/delimited-token.ts @@ -2,7 +2,7 @@ import Token from './token' import { last } from '../util/underscore' export default class DelimitedToken extends Token { - constructor ( + public constructor ( raw: string, value: string, input: string, diff --git a/src/parser/html-token.ts b/src/parser/html-token.ts index 53d70515a..7581c6258 100644 --- a/src/parser/html-token.ts +++ b/src/parser/html-token.ts @@ -1,12 +1,12 @@ import Token from './token' export default class HTMLToken extends Token { - constructor (str: string, input: string, line: number, col: number, file?: string) { + public constructor (str: string, input: string, line: number, col: number, file?: string) { super(str, input, line, col, file) this.type = 'html' this.value = str } - static is (token: Token): token is HTMLToken { + public static is (token: Token): token is HTMLToken { return token.type === 'html' } } diff --git a/src/parser/output-token.ts b/src/parser/output-token.ts index 7674729d5..edd21261a 100644 --- a/src/parser/output-token.ts +++ b/src/parser/output-token.ts @@ -3,7 +3,7 @@ import Token from './token' import { NormalizedFullOptions } from '../liquid-options' export default class OutputToken extends DelimitedToken { - constructor ( + public constructor ( raw: string, value: string, input: string, @@ -15,7 +15,7 @@ export default class OutputToken extends DelimitedToken { super(raw, value, input, line, pos, options.trimOutputLeft, options.trimOutputRight, file) this.type = 'output' } - static is (token: Token): token is OutputToken { + public static is (token: Token): token is OutputToken { return token.type === 'output' } } diff --git a/src/parser/parse-stream.ts b/src/parser/parse-stream.ts index 6141e092f..47df7d63a 100644 --- a/src/parser/parse-stream.ts +++ b/src/parser/parse-stream.ts @@ -2,19 +2,19 @@ import Token from '../parser/token' import ITemplate from '../template/itemplate' import TagToken from './tag-token' -type ParseToken = ((token: Token, remainTokens: Array) => ITemplate) +type ParseToken = ((token: Token, remainTokens: Token[]) => ITemplate) export default class ParseStream { - private tokens: Array + private tokens: Token[] private handlers: {[key: string]: (arg: any) => void} = {} private stopRequested: boolean = false private parseToken: ParseToken - constructor (tokens: Array, parseToken: ParseToken) { + public constructor (tokens: Token[], parseToken: ParseToken) { this.tokens = tokens this.parseToken = parseToken } - on (name: string, cb: (arg: T) => void): ParseStream { + public on (name: string, cb: (arg: T) => void): ParseStream { this.handlers[name] = cb return this } @@ -22,7 +22,7 @@ export default class ParseStream { const h = this.handlers[event] return h ? (h(arg), true) : false } - start () { + public start () { this.trigger('start') let token: Token | undefined while (!this.stopRequested && (token = this.tokens.shift())) { @@ -36,7 +36,7 @@ export default class ParseStream { if (!this.stopRequested) this.trigger('end') return this } - stop () { + public stop () { this.stopRequested = true return this } diff --git a/src/parser/parser.ts b/src/parser/parser.ts index 4fead687a..be5e960b1 100644 --- a/src/parser/parser.ts +++ b/src/parser/parser.ts @@ -10,12 +10,12 @@ import HTML from '../template/html' import ITemplate from '../template/itemplate' export default class Parser { - liquid: Liquid + private liquid: Liquid - constructor (liquid: Liquid) { + public constructor (liquid: Liquid) { this.liquid = liquid } - parse (tokens: Array) { + public parse (tokens: Token[]) { let token const templates: ITemplate[] = [] while ((token = tokens.shift())) { @@ -23,7 +23,7 @@ export default class Parser { } return templates } - parseToken (token: Token, remainTokens: Array) { + public parseToken (token: Token, remainTokens: Token[]) { try { if (TagToken.is(token)) { return new Tag(token, remainTokens, this.liquid) @@ -36,7 +36,7 @@ export default class Parser { throw new ParseError(e, token) } } - parseStream (tokens: Array) { + public parseStream (tokens: Token[]) { return new ParseStream(tokens, (token, tokens) => this.parseToken(token, tokens)) } } diff --git a/src/parser/tag-token.ts b/src/parser/tag-token.ts index 7cec7673e..04b36f6b0 100644 --- a/src/parser/tag-token.ts +++ b/src/parser/tag-token.ts @@ -5,9 +5,9 @@ import * as lexical from './lexical' import { NormalizedFullOptions } from '../liquid-options' export default class TagToken extends DelimitedToken { - name: string - args: string - constructor ( + public name: string + public args: string + public constructor ( raw: string, value: string, input: string, @@ -25,7 +25,7 @@ export default class TagToken extends DelimitedToken { this.name = match[1] this.args = match[2] } - static is (token: Token): token is TagToken { + public static is (token: Token): token is TagToken { return token.type === 'tag' } } diff --git a/src/parser/token.ts b/src/parser/token.ts index 7a493ffc7..3c2375f33 100644 --- a/src/parser/token.ts +++ b/src/parser/token.ts @@ -1,14 +1,14 @@ export default class Token { - trimLeft: boolean = false - trimRight: boolean = false - type: string = 'notset' - line: number - col: number - raw: string - input: string - file?: string - value: string - constructor (raw: string, input: string, line: number, col: number, file?: string) { + public trimLeft: boolean = false + public trimRight: boolean = false + public type: string = 'notset' + public line: number + public col: number + public raw: string + public input: string + public file?: string + public value: string + public constructor (raw: string, input: string, line: number, col: number, file?: string) { this.col = col this.line = line this.raw = raw diff --git a/src/parser/tokenizer.ts b/src/parser/tokenizer.ts index 40e7b7c3d..0e8a97efe 100644 --- a/src/parser/tokenizer.ts +++ b/src/parser/tokenizer.ts @@ -10,10 +10,10 @@ enum ParseState { HTML, OUTPUT, TAG } export default class Tokenizer { private options: NormalizedFullOptions - constructor (options?: NormalizedFullOptions) { + public constructor (options?: NormalizedFullOptions) { this.options = applyDefault(options) } - tokenize (input: string, file?: string) { + public tokenize (input: string, file?: string) { const tokens: Token[] = [] const { tagDelimiterLeft, diff --git a/src/render/render.ts b/src/render/render.ts index 6d920b5c0..2f06971b4 100644 --- a/src/render/render.ts +++ b/src/render/render.ts @@ -4,7 +4,7 @@ import Context from '../context/context' import ITemplate from '../template/itemplate' export default class Render { - async renderTemplates (templates: ITemplate[], ctx: Context) { + public async renderTemplates (templates: ITemplate[], ctx: Context) { assert(ctx, 'unable to evalTemplates: context undefined') let html = '' diff --git a/src/template/filter/filter-impl.ts b/src/template/filter/filter-impl.ts index 314134015..3f8facc2c 100644 --- a/src/template/filter/filter-impl.ts +++ b/src/template/filter/filter-impl.ts @@ -1,5 +1,5 @@ import Context from '../../context/context' export interface FilterImpl { - context: Context + context: Context; } diff --git a/src/template/filter/filter.ts b/src/template/filter/filter.ts index faae475f7..f98c55f98 100644 --- a/src/template/filter/filter.ts +++ b/src/template/filter/filter.ts @@ -5,15 +5,15 @@ import { FilterImplOptions } from './filter-impl-options' type KeyValuePair = [string?, string?] type FilterArg = string|KeyValuePair -export type FilterArgs = Array +export type FilterArgs = FilterArg[] export class Filter { - name: string - impl: FilterImplOptions - args: FilterArgs + private name: string + private impl: FilterImplOptions + private args: FilterArgs private static impls: {[key: string]: FilterImplOptions} = {} - constructor (name: string, args: FilterArgs, strictFilters: boolean) { + public constructor (name: string, args: FilterArgs, strictFilters: boolean) { const impl = Filter.impls[name] if (!impl && strictFilters) throw new TypeError(`undefined filter: ${name}`) @@ -21,7 +21,7 @@ export class Filter { this.impl = impl || (x => x) this.args = args } - async render (value: any, context: Context) { + public async render (value: any, context: Context) { const argv: any[] = [] for (const arg of this.args) { if (isKeyValuePair(arg)) argv.push([arg[0], await parseValue(arg[1], context)]) @@ -29,10 +29,10 @@ export class Filter { } return this.impl.apply({ context }, [value, ...argv]) } - static register (name: string, filter: FilterImplOptions) { + public static register (name: string, filter: FilterImplOptions) { Filter.impls[name] = filter } - static clear () { + public static clear () { Filter.impls = {} } } diff --git a/src/template/html.ts b/src/template/html.ts index a5babff96..07abd8255 100644 --- a/src/template/html.ts +++ b/src/template/html.ts @@ -3,12 +3,12 @@ import ITemplate from '../template/itemplate' import HTMLToken from '../parser/html-token' export default class extends Template implements ITemplate { - str: string - constructor (token: HTMLToken) { + private str: string + public constructor (token: HTMLToken) { super(token) this.str = token.value } - async render (): Promise { + public async render (): Promise { return this.str } } diff --git a/src/template/output.ts b/src/template/output.ts index 60b31b7d5..91c740fd5 100644 --- a/src/template/output.ts +++ b/src/template/output.ts @@ -6,12 +6,12 @@ import Context from '../context/context' import OutputToken from '../parser/output-token' export default class Output extends Template implements ITemplate { - value: Value - constructor (token: OutputToken, strictFilters: boolean) { + private value: Value + public constructor (token: OutputToken, strictFilters: boolean) { super(token) this.value = new Value(token.value, strictFilters) } - async render (ctx: Context): Promise { + public async render (ctx: Context): Promise { const val = await this.value.value(ctx) return stringify(toValue(val)) } diff --git a/src/template/tag/hash.ts b/src/template/tag/hash.ts index f95c63fca..1d25c879b 100644 --- a/src/template/tag/hash.ts +++ b/src/template/tag/hash.ts @@ -10,7 +10,7 @@ import Context from '../../context/context' */ export default class Hash { [key: string]: any - static async create (markup: string, ctx: Context) { + public static async create (markup: string, ctx: Context) { const instance = new Hash() let match hashCapture.lastIndex = 0 diff --git a/src/template/tag/itag-impl-options.ts b/src/template/tag/itag-impl-options.ts index 7234fcf9e..c77df11ab 100644 --- a/src/template/tag/itag-impl-options.ts +++ b/src/template/tag/itag-impl-options.ts @@ -5,6 +5,6 @@ import Hash from '../../template/tag/hash' import ITagImpl from './itag-impl' export default interface ITagImplOptions { - parse?: (this: ITagImpl, token: TagToken, remainingTokens: Array) => void - render?: (this: ITagImpl, ctx: Context, hash: Hash) => any | Promise + parse?: (this: ITagImpl, token: TagToken, remainingTokens: Token[]) => void; + render?: (this: ITagImpl, ctx: Context, hash: Hash) => any | Promise; } diff --git a/src/template/tag/itag-impl.ts b/src/template/tag/itag-impl.ts index 6216875f4..c9a02f331 100644 --- a/src/template/tag/itag-impl.ts +++ b/src/template/tag/itag-impl.ts @@ -2,6 +2,6 @@ import Liquid from '../../liquid' import ITagImplOptions from './itag-impl-options' export default interface ITagImpl extends ITagImplOptions { - liquid: Liquid, - [key: string]: any + liquid: Liquid; + [key: string]: any; } diff --git a/src/template/tag/tag.ts b/src/template/tag/tag.ts index 91366153f..f1fad0142 100644 --- a/src/template/tag/tag.ts +++ b/src/template/tag/tag.ts @@ -11,11 +11,11 @@ import TagToken from '../../parser/tag-token' import Token from '../../parser/token' export default class Tag extends Template implements ITemplate { - name: string + public name: string private impl: ITagImpl - static impls: { [key: string]: ITagImplOptions } = {} + private static impls: { [key: string]: ITagImplOptions } = {} - constructor (token: TagToken, tokens: Token[], liquid: Liquid) { + public constructor (token: TagToken, tokens: Token[], liquid: Liquid) { super(token) this.name = token.name @@ -28,15 +28,15 @@ export default class Tag extends Template implements ITemplate { this.impl.parse(token, tokens) } } - async render (ctx: Context) { + public async render (ctx: Context) { const hash = await Hash.create(this.token.args, ctx) const impl = this.impl return isFunction(impl.render) ? stringify(await impl.render(ctx, hash)) : '' } - static register (name: string, tag: ITagImplOptions) { + public static register (name: string, tag: ITagImplOptions) { Tag.impls[name] = tag } - static clear () { + public static clear () { Tag.impls = {} } } diff --git a/src/template/template.ts b/src/template/template.ts index 431d056d5..bf38e69af 100644 --- a/src/template/template.ts +++ b/src/template/template.ts @@ -1,6 +1,6 @@ export default abstract class Template { - token: T; - constructor (token: T) { + public token: T; + public constructor (token: T) { this.token = token } } diff --git a/src/template/value.ts b/src/template/value.ts index 3e25c7e63..ff02dcbd7 100644 --- a/src/template/value.ts +++ b/src/template/value.ts @@ -5,12 +5,12 @@ import Context from '../context/context' export default class Value { private strictFilters: boolean private initial: string - private filters: Array = [] + private filters: Filter[] = [] /** * @param str value string, like: "i have a dream | truncate: 3 */ - constructor (str: string, strictFilters: boolean) { + public constructor (str: string, strictFilters: boolean) { const tokens = Value.tokenize(str) this.strictFilters = strictFilters this.initial = tokens[0] @@ -35,7 +35,7 @@ export default class Value { for (let i = begin + 1; i < end + 1; i++) { if (i === end || tokens[i] === ',') { if (argName || argValue) { - args.push(argName ? [argName, argValue] : argValue) + args.push(argName ? [argName, argValue] : argValue as string) } argValue = argName = undefined } else if (tokens[i] === ':') { @@ -47,14 +47,14 @@ export default class Value { } this.filters.push(new Filter(name, args, this.strictFilters)) } - async value (ctx: Context) { + public async value (ctx: Context) { let val = await parseExp(this.initial, ctx) for (const filter of this.filters) { val = await filter.render(val, ctx) } return val } - static tokenize (str: string): Array<'|' | ',' | ':' | string> { + public static tokenize (str: string): ('|' | ',' | ':' | string)[] { const tokens = [] let i = 0 while (i < str.length) { diff --git a/src/util/error.ts b/src/util/error.ts index b5d0c1492..2fc085607 100644 --- a/src/util/error.ts +++ b/src/util/error.ts @@ -5,7 +5,7 @@ import ITemplate from '../template/itemplate' abstract class LiquidError extends Error { private token: Token private originalError: Error - constructor (err: Error, token: Token) { + public constructor (err: Error, token: Token) { super(err.message) this.originalError = err this.token = token @@ -20,7 +20,7 @@ abstract class LiquidError extends Error { } export class TokenizationError extends LiquidError { - constructor (message: string, token: Token) { + public constructor (message: string, token: Token) { super(new Error(message), token) this.name = 'TokenizationError' super.update() @@ -28,7 +28,7 @@ export class TokenizationError extends LiquidError { } export class ParseError extends LiquidError { - constructor (err: Error, token: Token) { + public constructor (err: Error, token: Token) { super(err, token) this.name = 'ParseError' this.message = err.message @@ -37,7 +37,7 @@ export class ParseError extends LiquidError { } export class RenderError extends LiquidError { - constructor (err: Error, tpl: ITemplate) { + public constructor (err: Error, tpl: ITemplate) { super(err, tpl.token) this.name = 'RenderError' this.message = err.message @@ -46,8 +46,8 @@ export class RenderError extends LiquidError { } export class RenderBreakError extends Error { - resolvedHTML: string = '' - constructor (message: string) { + public resolvedHTML: string = '' + public constructor (message: string) { super(message) this.name = 'RenderBreakError' this.message = message + '' @@ -55,7 +55,7 @@ export class RenderBreakError extends Error { } export class AssertionError extends Error { - constructor (message: string) { + public constructor (message: string) { super(message) this.name = 'AssertionError' this.message = message + '' diff --git a/src/util/underscore.ts b/src/util/underscore.ts index acee3dabc..986f6d88b 100644 --- a/src/util/underscore.ts +++ b/src/util/underscore.ts @@ -16,7 +16,7 @@ export function isFunction (value: any): value is Function { } export function promisify (fn: (arg1: T1, cb: (err: Error | null, result: T2) => void) => void): (arg1: T1) => Promise; -export function promisify (fn: (arg1: T1, arg2: T2, cb: (err: Error | null, result: T3) => void) => void):(arg1: T1, arg2: T2) => Promise; +export function promisify (fn: (arg1: T1, arg2: T2, cb: (err: Error | null, result: T3) => void) => void): (arg1: T1, arg2: T2) => Promise; export function promisify (fn: any) { return function (...args: any[]) { return new Promise((resolve, reject) => { diff --git a/test/e2e/drop.ts b/test/e2e/drop.ts index f63e6ead2..6d17a2904 100644 --- a/test/e2e/drop.ts +++ b/test/e2e/drop.ts @@ -5,11 +5,11 @@ import * as chaiAsPromised from 'chai-as-promised' use(chaiAsPromised) class SettingsDrop extends Liquid.Types.Drop { - foo: string = 'FOO' - bar () { + private foo: string = 'FOO' + public bar () { return 'BAR' } - liquidMethodMissing (key: string) { + public liquidMethodMissing (key: string) { return key.toUpperCase() } } @@ -29,10 +29,10 @@ describe('drop', function () { describe('BlandDrop', function () { it('should test blank strings', async function () { const src = ` - {% unless settings.fp_heading == blank %} -

{{ settings.fp_heading }}

+ {% unless settings.fpHeading == blank %} +

{{ settings.fpHeading }}

{% endunless %}` - var ctx = { settings: { fp_heading: '' } } + var ctx = { settings: { fpHeading: '' } } const html = await engine.parseAndRender(src, ctx) return expect(html).to.match(/^\s+$/) }) diff --git a/test/e2e/xhr.ts b/test/e2e/xhr.ts index 3dcfe508a..d33102407 100644 --- a/test/e2e/xhr.ts +++ b/test/e2e/xhr.ts @@ -136,7 +136,7 @@ describe('xhr', () => { [200, { 'Content-Type': 'text/plain' }, 'foo2']) return engine.renderFile('foo.html') }) - .then((html:string) => expect(html).to.equal('foo2')) + .then((html: string) => expect(html).to.equal('foo2')) }) it('should respect cache=true option', () => { engine = new Liquid({ @@ -153,7 +153,7 @@ describe('xhr', () => { [200, { 'Content-Type': 'text/plain' }, 'foo2']) return engine.renderFile('foo.html') }) - .then((html:string) => expect(html).to.equal('foo1')) + .then((html: string) => expect(html).to.equal('foo1')) }) }) }) diff --git a/test/integration/builtin/tags/include.ts b/test/integration/builtin/tags/include.ts index 83531b2b2..57f328e3b 100644 --- a/test/integration/builtin/tags/include.ts +++ b/test/integration/builtin/tags/include.ts @@ -85,7 +85,7 @@ describe('tags/include', function () { }) it('should support include: with as Liquid Drop', async function () { class ColorDrop extends Liquid.Types.Drop { - valueOf (): string { + public valueOf (): string { return 'red!' } } @@ -98,7 +98,7 @@ describe('tags/include', function () { }) it('should support include: with passed as Liquid Drop', async function () { class ColorDrop extends Liquid.Types.Drop { - valueOf (): string { + public valueOf (): string { return 'red!' } } diff --git a/test/integration/drop/drop.ts b/test/integration/drop/drop.ts index 3ac1674b8..ef0ec6992 100644 --- a/test/integration/drop/drop.ts +++ b/test/integration/drop/drop.ts @@ -6,22 +6,22 @@ describe('drop/drop', function () { before(() => (liquid = new Liquid())) class CustomDrop extends Liquid.Types.Drop { - name: string = 'NAME' - getName () { + private name: string = 'NAME' + public getName () { return 'GET NAME' } } class CustomDropWithMethodMissing extends CustomDrop { - liquidMethodMissing (key: string) { + public liquidMethodMissing (key: string) { return key.toUpperCase() } } class PromiseDrop extends Liquid.Types.Drop { - name = Promise.resolve('NAME') - async getName () { + private name = Promise.resolve('NAME') + public async getName () { return 'GET NAME' } - async liquidMethodMissing (key: string) { + public async liquidMethodMissing (key: string) { return key.toUpperCase() } } diff --git a/test/stub/mockfs.ts b/test/stub/mockfs.ts index 6d59c3192..e29d7d50c 100644 --- a/test/stub/mockfs.ts +++ b/test/stub/mockfs.ts @@ -2,17 +2,20 @@ import { isString, forOwn } from '../../src/util/underscore' import fs from '../../src/fs/node' import { resolve } from 'path' -type fileDescriptor = { mode: string, content: string } +interface FileDescriptor { + mode: string; + content: string; +} -let files: { [path: string]: fileDescriptor } = {} +let files: { [path: string]: FileDescriptor } = {} const readFile = fs.readFile const exists = fs.exists -export function mock (options: { [path: string]: (string | fileDescriptor) }) { +export function mock (options: { [path: string]: (string | FileDescriptor) }) { forOwn(options, (val, key) => { files[resolve(key)] = isString(val) ? { mode: '33188', content: val } - : val as fileDescriptor + : val as FileDescriptor }) fs.readFile = async function (path) { const file = files[path] diff --git a/test/unit/parser/lexical.ts b/test/unit/parser/lexical.ts index e53499f6b..93fdf3778 100644 --- a/test/unit/parser/lexical.ts +++ b/test/unit/parser/lexical.ts @@ -1,12 +1,12 @@ import * as chai from 'chai' +import { isRange } from '../../../src/parser/lexical' const expect = chai.expect -const lexical = require('../../../src/parser/lexical') describe('lexical', function () { it('should test range literal', function () { - expect(lexical.isRange('(12..32)')).to.equal(true) - expect(lexical.isRange('(12..foo)')).to.equal(true) - expect(lexical.isRange('(foo.bar..foo)')).to.equal(true) + expect(isRange('(12..32)')).to.equal(true) + expect(isRange('(12..foo)')).to.equal(true) + expect(isRange('(foo.bar..foo)')).to.equal(true) }) })