From ff112a4750f91475e9eccdb301d7a468e895f6ca Mon Sep 17 00:00:00 2001 From: Jun Yang Date: Mon, 14 Nov 2022 20:51:25 +0800 Subject: [PATCH] chore: rename filters to snake style, #487 BREAKING CHANGE: keys in `.filters` are now in snake case (instead of camel case), identical to that in Liquid template. --- .eslintrc.json | 5 +++++ src/builtin/filters/index.ts | 7 ------- src/builtin/filters/url.ts | 4 ---- src/{builtin => }/filters/array.ts | 14 +++++++------- src/{builtin => }/filters/date.ts | 10 +++++----- src/{builtin => }/filters/html.ts | 8 ++++---- src/filters/index.ts | 19 +++++++++++++++++++ src/{builtin => }/filters/math.ts | 8 ++++---- src/{builtin => }/filters/misc.ts | 6 +++--- src/{builtin => }/filters/string.ts | 10 +++++----- src/filters/url.ts | 4 ++++ src/liquid-options.ts | 13 ++++--------- src/liquid.ts | 10 +++++----- src/{builtin => }/tags/assign.ts | 2 +- src/{builtin => }/tags/block.ts | 6 +++--- src/{builtin => }/tags/break.ts | 2 +- src/{builtin => }/tags/capture.ts | 4 ++-- src/{builtin => }/tags/case.ts | 4 ++-- src/{builtin => }/tags/comment.ts | 6 +++--- src/{builtin => }/tags/continue.ts | 2 +- src/{builtin => }/tags/cycle.ts | 6 +++--- src/{builtin => }/tags/decrement.ts | 4 ++-- src/{builtin => }/tags/echo.ts | 6 +++--- src/{builtin => }/tags/for.ts | 8 ++++---- src/{builtin => }/tags/if.ts | 2 +- src/{builtin => }/tags/include.ts | 4 ++-- src/{builtin => }/tags/increment.ts | 4 ++-- src/{builtin => }/tags/index.ts | 6 ++---- src/{builtin => }/tags/inline-comment.ts | 6 +++--- src/{builtin => }/tags/layout.ts | 6 +++--- src/{builtin => }/tags/liquid.ts | 6 +++--- src/{builtin => }/tags/raw.ts | 2 +- src/{builtin => }/tags/render.ts | 10 +++++----- src/{builtin => }/tags/tablerow.ts | 8 ++++---- src/{builtin => }/tags/unless.ts | 2 +- src/types.ts | 4 ++-- src/util/underscore.ts | 7 ------- test/unit/util/underscore.ts | 9 --------- 38 files changed, 119 insertions(+), 125 deletions(-) delete mode 100644 src/builtin/filters/index.ts delete mode 100644 src/builtin/filters/url.ts rename src/{builtin => }/filters/array.ts (89%) rename src/{builtin => }/filters/date.ts (77%) rename src/{builtin => }/filters/html.ts (77%) create mode 100644 src/filters/index.ts rename src/{builtin => }/filters/math.ts (65%) rename src/{builtin => }/filters/misc.ts (72%) rename src/{builtin => }/filters/string.ts (90%) create mode 100644 src/filters/url.ts rename src/{builtin => }/tags/assign.ts (96%) rename src/{builtin => }/tags/block.ts (91%) rename src/{builtin => }/tags/break.ts (69%) rename src/{builtin => }/tags/capture.ts (91%) rename src/{builtin => }/tags/case.ts (96%) rename src/{builtin => }/tags/comment.ts (69%) rename src/{builtin => }/tags/continue.ts (69%) rename src/{builtin => }/tags/cycle.ts (91%) rename src/{builtin => }/tags/decrement.ts (86%) rename src/{builtin => }/tags/echo.ts (65%) rename src/{builtin => }/tags/for.ts (94%) rename src/{builtin => }/tags/if.ts (96%) rename src/{builtin => }/tags/include.ts (94%) rename src/{builtin => }/tags/increment.ts (87%) rename src/{builtin => }/tags/index.ts (85%) rename src/{builtin => }/tags/inline-comment.ts (59%) rename src/{builtin => }/tags/layout.ts (91%) rename src/{builtin => }/tags/liquid.ts (73%) rename src/{builtin => }/tags/raw.ts (89%) rename src/{builtin => }/tags/render.ts (95%) rename src/{builtin => }/tags/tablerow.ts (89%) rename src/{builtin => }/tags/unless.ts (95%) diff --git a/.eslintrc.json b/.eslintrc.json index 4008221b3e..66b32c6ce9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -37,6 +37,11 @@ "@typescript-eslint/no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": false }] }, "overrides": [{ + "files": ["**/filters/*.ts"], + "rules": { + "camelcase": "off" + } + }, { "files": ["**/*.js", "**/*.mjs"], "rules": { "@typescript-eslint/no-var-requires": "off" diff --git a/src/builtin/filters/index.ts b/src/builtin/filters/index.ts deleted file mode 100644 index 2219dee48a..0000000000 --- a/src/builtin/filters/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -export * from './html' -export * from './math' -export * from './url' -export * from './array' -export * from './date' -export * from './misc' -export * from './string' diff --git a/src/builtin/filters/url.ts b/src/builtin/filters/url.ts deleted file mode 100644 index 087a6de276..0000000000 --- a/src/builtin/filters/url.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { stringify } from '../../util/underscore' - -export const urlDecode = (x: string) => stringify(x).split('+').map(decodeURIComponent).join(' ') -export const urlEncode = (x: string) => stringify(x).split(' ').map(encodeURIComponent).join('+') diff --git a/src/builtin/filters/array.ts b/src/filters/array.ts similarity index 89% rename from src/builtin/filters/array.ts rename to src/filters/array.ts index 8c444ee3b2..a7ae807b0f 100644 --- a/src/builtin/filters/array.ts +++ b/src/filters/array.ts @@ -1,9 +1,9 @@ -import { argumentsToValue, toValue, stringify, caseInsensitiveCompare, isArray, isNil, last as arrayLast, hasOwnProperty } from '../../util/underscore' -import { toArray } from '../../util/collection' -import { isTruthy } from '../../render/boolean' -import { FilterImpl } from '../../template/filter/filter-impl' -import { Scope } from '../../context/scope' -import { isComparable } from '../../drop/comparable' +import { argumentsToValue, toValue, stringify, caseInsensitiveCompare, isArray, isNil, last as arrayLast, hasOwnProperty } from '../util/underscore' +import { toArray } from '../util/collection' +import { isTruthy } from '../render/boolean' +import { FilterImpl } from '../template/filter/filter-impl' +import { Scope } from '../context/scope' +import { isComparable } from '../drop/comparable' export const join = argumentsToValue((v: any[], arg: string) => toArray(v).join(arg === undefined ? ' ' : arg)) export const last = argumentsToValue((v: any) => isArray(v) ? arrayLast(v) : '') @@ -25,7 +25,7 @@ export function * sort (this: FilterImpl, arr: T[], property?: string): Itera }).map(tuple => tuple[0]) } -export function sortNatural (input: T[], property?: string) { +export function sort_natural (input: T[], property?: string) { input = toValue(input) const propertyString = stringify(property) const compare = property === undefined diff --git a/src/builtin/filters/date.ts b/src/filters/date.ts similarity index 77% rename from src/builtin/filters/date.ts rename to src/filters/date.ts index 59f1df9584..6c1a9af9b8 100644 --- a/src/builtin/filters/date.ts +++ b/src/filters/date.ts @@ -1,8 +1,8 @@ -import strftime from '../../util/strftime' -import { LiquidDate } from '../../util/liquid-date' -import { toValue, stringify, isString, isNumber } from '../../util/underscore' -import { FilterImpl } from '../../template/filter/filter-impl' -import { TimezoneDate } from '../../util/timezone-date' +import strftime from '../util/strftime' +import { LiquidDate } from '../util/liquid-date' +import { toValue, stringify, isString, isNumber } from '../util/underscore' +import { FilterImpl } from '../template/filter/filter-impl' +import { TimezoneDate } from '../util/timezone-date' export function date (this: FilterImpl, v: string | Date, format: string, timeZoneOffset?: number) { const opts = this.context.opts diff --git a/src/builtin/filters/html.ts b/src/filters/html.ts similarity index 77% rename from src/builtin/filters/html.ts rename to src/filters/html.ts index cdb340fe91..36b57b2a40 100644 --- a/src/builtin/filters/html.ts +++ b/src/filters/html.ts @@ -1,4 +1,4 @@ -import { stringify } from '../../util/underscore' +import { stringify } from '../util/underscore' const escapeMap = { '&': '&', @@ -23,14 +23,14 @@ function unescape (str: string) { return stringify(str).replace(/&(amp|lt|gt|#34|#39);/g, m => unescapeMap[m]) } -export function escapeOnce (str: string) { +export function escape_once (str: string) { return escape(unescape(stringify(str))) } -export function newlineToBr (v: string) { +export function newline_to_br (v: string) { return stringify(v).replace(/\n/g, '
\n') } -export function stripHtml (v: string) { +export function strip_html (v: string) { return stringify(v).replace(/|||<.*?>/g, '') } diff --git a/src/filters/index.ts b/src/filters/index.ts new file mode 100644 index 0000000000..8fa56176e2 --- /dev/null +++ b/src/filters/index.ts @@ -0,0 +1,19 @@ +import * as htmlFilters from './html' +import * as mathFilters from './math' +import * as urlFilters from './url' +import * as arrayFilters from './array' +import * as dateFilters from './date' +import * as stringFilters from './string' +import { Default, json } from './misc' +import { FilterImplOptions } from '../template/filter/filter-impl-options' + +export const filters: { [key: string]: FilterImplOptions } = { + ...htmlFilters, + ...mathFilters, + ...urlFilters, + ...arrayFilters, + ...dateFilters, + ...stringFilters, + json, + default: Default +} diff --git a/src/builtin/filters/math.ts b/src/filters/math.ts similarity index 65% rename from src/builtin/filters/math.ts rename to src/filters/math.ts index 28be0cf822..b009532064 100644 --- a/src/builtin/filters/math.ts +++ b/src/filters/math.ts @@ -1,10 +1,10 @@ -import { toValue, argumentsToValue } from '../../util/underscore' +import { toValue, argumentsToValue } from '../util/underscore' export const abs = argumentsToValue(Math.abs) -export const atLeast = argumentsToValue(Math.max) -export const atMost = argumentsToValue(Math.min) +export const at_least = argumentsToValue(Math.max) +export const at_most = argumentsToValue(Math.min) export const ceil = argumentsToValue(Math.ceil) -export const dividedBy = argumentsToValue((dividend: number, divisor: number, integerArithmetic = false) => integerArithmetic ? Math.floor(dividend / divisor) : dividend / divisor) +export const divided_by = argumentsToValue((dividend: number, divisor: number, integerArithmetic = false) => integerArithmetic ? Math.floor(dividend / divisor) : dividend / divisor) export const floor = argumentsToValue(Math.floor) export const minus = argumentsToValue((v: number, arg: number) => v - arg) export const modulo = argumentsToValue((v: number, arg: number) => v % arg) diff --git a/src/builtin/filters/misc.ts b/src/filters/misc.ts similarity index 72% rename from src/builtin/filters/misc.ts rename to src/filters/misc.ts index be7b1a936e..a6b9619f8c 100644 --- a/src/builtin/filters/misc.ts +++ b/src/filters/misc.ts @@ -1,6 +1,6 @@ -import { isFalsy } from '../../render/boolean' -import { identify, isArray, isString, toValue } from '../../util/underscore' -import { FilterImpl } from '../../template/filter/filter-impl' +import { isFalsy } from '../render/boolean' +import { identify, isArray, isString, toValue } from '../util/underscore' +import { FilterImpl } from '../template/filter/filter-impl' export function Default (this: FilterImpl, value: T1, defaultValue: T2, ...args: Array<[string, any]>): T1 | T2 { value = toValue(value) diff --git a/src/builtin/filters/string.ts b/src/filters/string.ts similarity index 90% rename from src/builtin/filters/string.ts rename to src/filters/string.ts index faf042bf90..49ff3cb6dc 100644 --- a/src/builtin/filters/string.ts +++ b/src/filters/string.ts @@ -3,8 +3,8 @@ * * * prefer stringify() to String() since `undefined`, `null` should eval '' */ -import { escapeRegExp, stringify } from '../../util/underscore' -import { assert } from '../../util/assert' +import { escapeRegExp, stringify } from '../util/underscore' +import { assert } from '../util/assert' export function append (v: string, arg: string) { assert(arguments.length === 2, 'append expect 2 arguments') @@ -36,7 +36,7 @@ export function remove (v: string, arg: string) { return stringify(v).split(String(arg)).join('') } -export function removeFirst (v: string, l: string) { +export function remove_first (v: string, l: string) { return stringify(v).replace(String(l), '') } @@ -66,7 +66,7 @@ export function strip (v: string, chars?: string) { return stringify(v).trim() } -export function stripNewlines (v: string) { +export function strip_newlines (v: string) { return stringify(v).replace(/\n/g, '') } @@ -79,7 +79,7 @@ export function replace (v: string, pattern: string, replacement: string) { return stringify(v).split(String(pattern)).join(replacement) } -export function replaceFirst (v: string, arg1: string, arg2: string) { +export function replace_first (v: string, arg1: string, arg2: string) { return stringify(v).replace(String(arg1), arg2) } diff --git a/src/filters/url.ts b/src/filters/url.ts new file mode 100644 index 0000000000..c5719099e6 --- /dev/null +++ b/src/filters/url.ts @@ -0,0 +1,4 @@ +import { stringify } from '../util/underscore' + +export const url_decode = (x: string) => stringify(x).split('+').map(decodeURIComponent).join(' ') +export const url_encode = (x: string) => stringify(x).split(' ').map(encodeURIComponent).join('+') diff --git a/src/liquid-options.ts b/src/liquid-options.ts index 9dd1c7a4d6..bf91548752 100644 --- a/src/liquid-options.ts +++ b/src/liquid-options.ts @@ -1,17 +1,12 @@ -import { snakeCase, forOwn, isArray, isString, isFunction } from './util/underscore' +import { isArray, isString, isFunction } from './util/underscore' import { LiquidCache } from './cache/cache' import { LRU } from './cache/lru' import { FS } from './fs/fs' import * as fs from './fs/node' import { defaultOperators, Operators } from './render/operator' import { createTrie, Trie } from './util/operator-trie' -import * as builtinFilters from './builtin/filters' -import { assert, FilterImplOptions } from './types' - -const filters = new Map() -forOwn(builtinFilters, (conf: FilterImplOptions, name: string) => { - filters.set(snakeCase(name), conf) -}) +import { filters } from './filters' +import { assert } from './types' type OutputEscape = (value: any) => string type OutputEscapeOption = 'escape' | 'json' | OutputEscape @@ -198,7 +193,7 @@ export function normalize (options: LiquidOptions): NormalizedFullOptions { function getOutputEscapeFunction (nameOrFunction: OutputEscapeOption) { if (isString(nameOrFunction)) { - const filterImpl = filters.get(nameOrFunction) + const filterImpl = filters[nameOrFunction] assert(isFunction(filterImpl), `filter "${nameOrFunction}" not found`) return filterImpl } else { diff --git a/src/liquid.ts b/src/liquid.ts index 3e1536ce5e..c0e1a69800 100644 --- a/src/liquid.ts +++ b/src/liquid.ts @@ -1,13 +1,13 @@ import { Context } from './context/context' -import { forOwn, snakeCase } from './util/underscore' +import { forOwn } from './util/underscore' import { Template } from './template/template' import { LookupType } from './fs/loader' import { Render } from './render/render' import Parser from './parser/parser' import { TagImplOptions } from './template/tag/tag-impl-options' import { Value } from './template/value' -import builtinTags from './builtin/tags' -import * as builtinFilters from './builtin/filters' +import { tags } from './tags' +import { filters } from './filters' import { TagMap } from './template/tag/tag-map' import { FilterMap } from './template/filter/filter-map' import { LiquidOptions, normalizeDirectoryList, NormalizedFullOptions, normalize, RenderOptions } from './liquid-options' @@ -32,8 +32,8 @@ export class Liquid { this.filters = new FilterMap(this.options.strictFilters, this) this.tags = new TagMap() - forOwn(builtinTags, (conf: TagImplOptions, name: string) => this.registerTag(snakeCase(name), conf)) - forOwn(builtinFilters, (handler: FilterImplOptions, name: string) => this.registerFilter(snakeCase(name), handler)) + forOwn(tags, (conf: TagImplOptions, name: string) => this.registerTag(name, conf)) + forOwn(filters, (handler: FilterImplOptions, name: string) => this.registerFilter(name, handler)) } public parse (html: string, filepath?: string): Template[] { return this.parser.parse(html, filepath) diff --git a/src/builtin/tags/assign.ts b/src/tags/assign.ts similarity index 96% rename from src/builtin/tags/assign.ts rename to src/tags/assign.ts index 8891105137..82f08d766c 100644 --- a/src/builtin/tags/assign.ts +++ b/src/tags/assign.ts @@ -1,4 +1,4 @@ -import { Value, Tokenizer, assert, TagImplOptions, TagToken, Context } from '../../types' +import { Value, Tokenizer, assert, TagImplOptions, TagToken, Context } from '../types' export default { parse: function (token: TagToken) { diff --git a/src/builtin/tags/block.ts b/src/tags/block.ts similarity index 91% rename from src/builtin/tags/block.ts rename to src/tags/block.ts index d966017baa..ec3ba67040 100644 --- a/src/builtin/tags/block.ts +++ b/src/tags/block.ts @@ -1,6 +1,6 @@ -import BlockMode from '../../context/block-mode' -import { BlockDrop } from '../../drop/block-drop' -import { TagToken, TopLevelToken, Template, Context, TagImpl, Emitter } from '../../types' +import BlockMode from '../context/block-mode' +import { BlockDrop } from '../drop/block-drop' +import { TagToken, TopLevelToken, Template, Context, TagImpl, Emitter } from '../types' export default { parse (this: TagImpl, token: TagToken, remainTokens: TopLevelToken[]) { diff --git a/src/builtin/tags/break.ts b/src/tags/break.ts similarity index 69% rename from src/builtin/tags/break.ts rename to src/tags/break.ts index bfa8450c9f..fc73ce7ff8 100644 --- a/src/builtin/tags/break.ts +++ b/src/tags/break.ts @@ -1,4 +1,4 @@ -import { Emitter, Context } from '../../types' +import { Emitter, Context } from '../types' export default { render: function (ctx: Context, emitter: Emitter) { diff --git a/src/builtin/tags/capture.ts b/src/tags/capture.ts similarity index 91% rename from src/builtin/tags/capture.ts rename to src/tags/capture.ts index 5e17870256..3dde40d376 100644 --- a/src/builtin/tags/capture.ts +++ b/src/tags/capture.ts @@ -1,5 +1,5 @@ -import { Tokenizer, assert, Template, Context, TagImplOptions, TagToken, TopLevelToken } from '../../types' -import { evalQuotedToken } from '../../render/expression' +import { Tokenizer, assert, Template, Context, TagImplOptions, TagToken, TopLevelToken } from '../types' +import { evalQuotedToken } from '../render/expression' export default { parse: function (tagToken: TagToken, remainTokens: TopLevelToken[]) { diff --git a/src/builtin/tags/case.ts b/src/tags/case.ts similarity index 96% rename from src/builtin/tags/case.ts rename to src/tags/case.ts index d779fe8ffb..742d011350 100644 --- a/src/builtin/tags/case.ts +++ b/src/tags/case.ts @@ -1,5 +1,5 @@ -import { toValue, _evalToken, Value, Emitter, TagToken, TopLevelToken, Context, Template, TagImplOptions, ParseStream } from '../../types' -import { Tokenizer } from '../../parser/tokenizer' +import { toValue, _evalToken, Value, Emitter, TagToken, TopLevelToken, Context, Template, TagImplOptions, ParseStream } from '../types' +import { Tokenizer } from '../parser/tokenizer' export default { parse: function (tagToken: TagToken, remainTokens: TopLevelToken[]) { diff --git a/src/builtin/tags/comment.ts b/src/tags/comment.ts similarity index 69% rename from src/builtin/tags/comment.ts rename to src/tags/comment.ts index dacb19fa9d..0c07446739 100644 --- a/src/builtin/tags/comment.ts +++ b/src/tags/comment.ts @@ -1,6 +1,6 @@ -import { TagToken } from '../../tokens/tag-token' -import { TopLevelToken } from '../../tokens/toplevel-token' -import { TagImplOptions } from '../../template/tag/tag-impl-options' +import { TagToken } from '../tokens/tag-token' +import { TopLevelToken } from '../tokens/toplevel-token' +import { TagImplOptions } from '../template/tag/tag-impl-options' export default { parse: function (tagToken: TagToken, remainTokens: TopLevelToken[]) { diff --git a/src/builtin/tags/continue.ts b/src/tags/continue.ts similarity index 69% rename from src/builtin/tags/continue.ts rename to src/tags/continue.ts index 1f5b28cd7e..ce92d96701 100644 --- a/src/builtin/tags/continue.ts +++ b/src/tags/continue.ts @@ -1,4 +1,4 @@ -import { Emitter, Context } from '../../types' +import { Emitter, Context } from '../types' export default { render: function (ctx: Context, emitter: Emitter) { diff --git a/src/builtin/tags/cycle.ts b/src/tags/cycle.ts similarity index 91% rename from src/builtin/tags/cycle.ts rename to src/tags/cycle.ts index b4f05cc363..a542df1099 100644 --- a/src/builtin/tags/cycle.ts +++ b/src/tags/cycle.ts @@ -1,6 +1,6 @@ -import { assert } from '../../util/assert' -import { _evalToken, Emitter, TagToken, Context, TagImplOptions } from '../../types' -import { Tokenizer } from '../../parser/tokenizer' +import { assert } from '../util/assert' +import { _evalToken, Emitter, TagToken, Context, TagImplOptions } from '../types' +import { Tokenizer } from '../parser/tokenizer' export default { parse: function (tagToken: TagToken) { diff --git a/src/builtin/tags/decrement.ts b/src/tags/decrement.ts similarity index 86% rename from src/builtin/tags/decrement.ts rename to src/tags/decrement.ts index 6c05506e57..b8b3c49557 100644 --- a/src/builtin/tags/decrement.ts +++ b/src/tags/decrement.ts @@ -1,5 +1,5 @@ -import { Tokenizer, Emitter, TagToken, Context, TagImplOptions } from '../../types' -import { isNumber, stringify } from '../../util/underscore' +import { Tokenizer, Emitter, TagToken, Context, TagImplOptions } from '../types' +import { isNumber, stringify } from '../util/underscore' export default { parse: function (token: TagToken) { diff --git a/src/builtin/tags/echo.ts b/src/tags/echo.ts similarity index 65% rename from src/builtin/tags/echo.ts rename to src/tags/echo.ts index fee2b81ab4..4ed8805c2c 100644 --- a/src/builtin/tags/echo.ts +++ b/src/tags/echo.ts @@ -1,6 +1,6 @@ -import { Value } from '../../template/value' -import { Emitter } from '../../emitters/emitter' -import { TagImplOptions, TagToken, Context } from '../../types' +import { Value } from '../template/value' +import { Emitter } from '../emitters/emitter' +import { TagImplOptions, TagToken, Context } from '../types' export default { parse: function (token: TagToken) { diff --git a/src/builtin/tags/for.ts b/src/tags/for.ts similarity index 94% rename from src/builtin/tags/for.ts rename to src/tags/for.ts index 64535ac55c..2c47ddffcd 100644 --- a/src/builtin/tags/for.ts +++ b/src/tags/for.ts @@ -1,7 +1,7 @@ -import { assert, Tokenizer, _evalToken, Emitter, TagToken, TopLevelToken, Context, Template, TagImplOptions, ParseStream } from '../../types' -import { toEnumerable } from '../../util/collection' -import { ForloopDrop } from '../../drop/forloop-drop' -import { Hash, HashValue } from '../../template/tag/hash' +import { assert, Tokenizer, _evalToken, Emitter, TagToken, TopLevelToken, Context, Template, TagImplOptions, ParseStream } from '../types' +import { toEnumerable } from '../util/collection' +import { ForloopDrop } from '../drop/forloop-drop' +import { Hash, HashValue } from '../template/tag/hash' const MODIFIERS = ['offset', 'limit', 'reversed'] diff --git a/src/builtin/tags/if.ts b/src/tags/if.ts similarity index 96% rename from src/builtin/tags/if.ts rename to src/tags/if.ts index 7ba72ddde4..4aba47b510 100644 --- a/src/builtin/tags/if.ts +++ b/src/tags/if.ts @@ -1,4 +1,4 @@ -import { Value, Emitter, isTruthy, TagToken, TopLevelToken, Context, Template, TagImplOptions } from '../../types' +import { Value, Emitter, isTruthy, TagToken, TopLevelToken, Context, Template, TagImplOptions } from '../types' export default { parse: function (tagToken: TagToken, remainTokens: TopLevelToken[]) { diff --git a/src/builtin/tags/include.ts b/src/tags/include.ts similarity index 94% rename from src/builtin/tags/include.ts rename to src/tags/include.ts index 7432afce94..87cb7b13c2 100644 --- a/src/builtin/tags/include.ts +++ b/src/tags/include.ts @@ -1,5 +1,5 @@ -import { assert, Tokenizer, _evalToken, Hash, Emitter, TagToken, Context, TagImplOptions } from '../../types' -import BlockMode from '../../context/block-mode' +import { assert, Tokenizer, _evalToken, Hash, Emitter, TagToken, Context, TagImplOptions } from '../types' +import BlockMode from '../context/block-mode' import { parseFilePath, renderFilePath } from './render' export default { diff --git a/src/builtin/tags/increment.ts b/src/tags/increment.ts similarity index 87% rename from src/builtin/tags/increment.ts rename to src/tags/increment.ts index 1fdc61605c..5cde2dc34d 100644 --- a/src/builtin/tags/increment.ts +++ b/src/tags/increment.ts @@ -1,5 +1,5 @@ -import { isNumber, stringify } from '../../util/underscore' -import { Tokenizer, Emitter, TagToken, Context, TagImplOptions } from '../../types' +import { isNumber, stringify } from '../util/underscore' +import { Tokenizer, Emitter, TagToken, Context, TagImplOptions } from '../types' export default { parse: function (token: TagToken) { diff --git a/src/builtin/tags/index.ts b/src/tags/index.ts similarity index 85% rename from src/builtin/tags/index.ts rename to src/tags/index.ts index 82ec5b4a49..19e6e3ac4f 100644 --- a/src/builtin/tags/index.ts +++ b/src/tags/index.ts @@ -19,10 +19,8 @@ import Continue from './continue' import echo from './echo' import liquid from './liquid' import inlineComment from './inline-comment' -import { TagImplOptions } from '../../template/tag/tag-impl-options' +import { TagImplOptions } from '../template/tag/tag-impl-options' -const tags: { [key: string]: TagImplOptions } = { +export const tags: { [key: string]: TagImplOptions } = { assign, 'for': For, capture, 'case': Case, comment, include, render, decrement, increment, cycle, 'if': If, layout, block, raw, tablerow, unless, 'break': Break, 'continue': Continue, echo, liquid, '#': inlineComment } - -export default tags diff --git a/src/builtin/tags/inline-comment.ts b/src/tags/inline-comment.ts similarity index 59% rename from src/builtin/tags/inline-comment.ts rename to src/tags/inline-comment.ts index 755d4ca3f2..2a1d740d20 100644 --- a/src/builtin/tags/inline-comment.ts +++ b/src/tags/inline-comment.ts @@ -1,6 +1,6 @@ -import { TagToken } from '../../tokens/tag-token' -import { TopLevelToken } from '../../tokens/toplevel-token' -import { TagImplOptions } from '../../template/tag/tag-impl-options' +import { TagToken } from '../tokens/tag-token' +import { TopLevelToken } from '../tokens/toplevel-token' +import { TagImplOptions } from '../template/tag/tag-impl-options' export default { parse: function (tagToken: TagToken, remainTokens: TopLevelToken[]) { diff --git a/src/builtin/tags/layout.ts b/src/tags/layout.ts similarity index 91% rename from src/builtin/tags/layout.ts rename to src/tags/layout.ts index 87c0a20246..fc5d618fd0 100644 --- a/src/builtin/tags/layout.ts +++ b/src/tags/layout.ts @@ -1,7 +1,7 @@ -import { assert, Tokenizer, Emitter, Hash, TagToken, TopLevelToken, Context, TagImplOptions } from '../../types' -import BlockMode from '../../context/block-mode' +import { assert, Tokenizer, Emitter, Hash, TagToken, TopLevelToken, Context, TagImplOptions } from '../types' +import BlockMode from '../context/block-mode' import { parseFilePath, renderFilePath } from './render' -import { BlankDrop } from '../../drop/blank-drop' +import { BlankDrop } from '../drop/blank-drop' export default { parseFilePath, diff --git a/src/builtin/tags/liquid.ts b/src/tags/liquid.ts similarity index 73% rename from src/builtin/tags/liquid.ts rename to src/tags/liquid.ts index 55294254c3..00be32fb28 100644 --- a/src/builtin/tags/liquid.ts +++ b/src/tags/liquid.ts @@ -1,6 +1,6 @@ -import { Emitter } from '../../emitters/emitter' -import { TagImplOptions, TagToken, Context } from '../../types' -import { Tokenizer } from '../../parser/tokenizer' +import { Emitter } from '../emitters/emitter' +import { TagImplOptions, TagToken, Context } from '../types' +import { Tokenizer } from '../parser/tokenizer' export default { parse: function (token: TagToken) { diff --git a/src/builtin/tags/raw.ts b/src/tags/raw.ts similarity index 89% rename from src/builtin/tags/raw.ts rename to src/tags/raw.ts index 1aa5d1bf6a..41cbeda52b 100644 --- a/src/builtin/tags/raw.ts +++ b/src/tags/raw.ts @@ -1,4 +1,4 @@ -import { TagToken, TopLevelToken, TagImplOptions } from '../../types' +import { TagToken, TopLevelToken, TagImplOptions } from '../types' export default { parse: function (tagToken: TagToken, remainTokens: TopLevelToken[]) { diff --git a/src/builtin/tags/render.ts b/src/tags/render.ts similarity index 95% rename from src/builtin/tags/render.ts rename to src/tags/render.ts index 97268d6697..eb9033953c 100644 --- a/src/builtin/tags/render.ts +++ b/src/tags/render.ts @@ -1,9 +1,9 @@ import { __assign } from 'tslib' -import { assert } from '../../util/assert' -import { ForloopDrop } from '../../drop/forloop-drop' -import { toEnumerable } from '../../util/collection' -import { Liquid } from '../../liquid' -import { Token, Template, evalQuotedToken, TypeGuards, Tokenizer, _evalToken, Hash, Emitter, TagToken, Context, TagImplOptions } from '../../types' +import { assert } from '../util/assert' +import { ForloopDrop } from '../drop/forloop-drop' +import { toEnumerable } from '../util/collection' +import { Liquid } from '../liquid' +import { Token, Template, evalQuotedToken, TypeGuards, Tokenizer, _evalToken, Hash, Emitter, TagToken, Context, TagImplOptions } from '../types' export default { parseFilePath, diff --git a/src/builtin/tags/tablerow.ts b/src/tags/tablerow.ts similarity index 89% rename from src/builtin/tags/tablerow.ts rename to src/tags/tablerow.ts index 900a241b70..0fc17fa617 100644 --- a/src/builtin/tags/tablerow.ts +++ b/src/tags/tablerow.ts @@ -1,7 +1,7 @@ -import { toEnumerable } from '../../util/collection' -import { assert, _evalToken, Emitter, Hash, TagToken, TopLevelToken, Context, Template, TagImplOptions, ParseStream } from '../../types' -import { TablerowloopDrop } from '../../drop/tablerowloop-drop' -import { Tokenizer } from '../../parser/tokenizer' +import { toEnumerable } from '../util/collection' +import { assert, _evalToken, Emitter, Hash, TagToken, TopLevelToken, Context, Template, TagImplOptions, ParseStream } from '../types' +import { TablerowloopDrop } from '../drop/tablerowloop-drop' +import { Tokenizer } from '../parser/tokenizer' export default { parse: function (tagToken: TagToken, remainTokens: TopLevelToken[]) { diff --git a/src/builtin/tags/unless.ts b/src/tags/unless.ts similarity index 95% rename from src/builtin/tags/unless.ts rename to src/tags/unless.ts index 54ed7d63ec..8c0465921e 100644 --- a/src/builtin/tags/unless.ts +++ b/src/tags/unless.ts @@ -1,4 +1,4 @@ -import { Value, TopLevelToken, Template, Emitter, isTruthy, isFalsy, Context, TagImplOptions, TagToken } from '../../types' +import { Value, TopLevelToken, Template, Emitter, isTruthy, isFalsy, Context, TagImplOptions, TagToken } from '../types' export default { parse: function (tagToken: TagToken, remainTokens: TopLevelToken[]) { diff --git a/src/types.ts b/src/types.ts index 62040703ea..1a24849e32 100644 --- a/src/types.ts +++ b/src/types.ts @@ -27,6 +27,6 @@ export { defaultOperators, Operators } from './render/operator' export { createTrie, Trie } from './util/operator-trie' export { toValue } from './util/underscore' export { TimezoneDate } from './util/timezone-date' -export * as filters from './builtin/filters' -export * as tags from './builtin/tags' +export { filters } from './filters' +export { tags } from './tags' export { defaultOptions } from './liquid-options' diff --git a/src/util/underscore.ts b/src/util/underscore.ts index 96f80c35d0..fd679fc4e1 100644 --- a/src/util/underscore.ts +++ b/src/util/underscore.ts @@ -137,13 +137,6 @@ export function identify (val: T): T { return val } -export function snakeCase (str: string) { - return str.replace( - /(\w?)([A-Z])/g, - (_, a, b) => (a ? a + '_' : '') + b.toLowerCase() - ) -} - export function changeCase (str: string): string { const hasLowerCase = [...str].some(ch => ch >= 'a' && ch <= 'z') return hasLowerCase ? str.toUpperCase() : str.toLowerCase() diff --git a/test/unit/util/underscore.ts b/test/unit/util/underscore.ts index 623024e8de..844960d966 100644 --- a/test/unit/util/underscore.ts +++ b/test/unit/util/underscore.ts @@ -7,15 +7,6 @@ const expect = chai.expect chai.use(sinonChai) describe('util/underscore', function () { - describe('.camel2snake()', function () { - it('should convert camelCase to snakeCase', function () { - expect(_.snakeCase('fooBarCoo')).to.equal('foo_bar_coo') - }) - it('should convert empty string to empty string', function () { - expect(_.snakeCase('')).to.equal('') - }) - }) - describe('.isString()', function () { it('should return true for literal string', function () { expect(_.isString('foo')).to.be.true