mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
feat: inline comment tag (#514)
* style: remove unnecessary intermediate constant * feat: add inline comment tag * refactor: use readIdentifier when reading tag names * docs: add inline comment tag
This commit is contained in:
@@ -18,10 +18,11 @@ import Break from './break'
|
||||
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'
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
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[]) {
|
||||
if (tagToken.args.search(/\n\s*[^#\s]/g) !== -1) {
|
||||
throw new Error('every line of an inline comment must start with a \'#\' character')
|
||||
}
|
||||
}
|
||||
} as TagImplOptions
|
||||
@@ -207,8 +207,7 @@ export class Tokenizer {
|
||||
const begin = this.p
|
||||
let end = this.N
|
||||
if (this.readToDelimiter('\n') !== -1) end = this.p
|
||||
const token = new LiquidTagToken(input, begin, end, options, file)
|
||||
return token
|
||||
return new LiquidTagToken(input, begin, end, options, file)
|
||||
}
|
||||
|
||||
mkError (msg: string, begin: number) {
|
||||
@@ -234,6 +233,13 @@ export class Tokenizer {
|
||||
return new IdentifierToken(this.input, begin, this.p, this.file)
|
||||
}
|
||||
|
||||
readTagName (): string {
|
||||
this.skipBlank()
|
||||
// Handle inline comment tags
|
||||
if (this.input[this.p] === '#') return this.input.slice(this.p, ++this.p)
|
||||
return this.readIdentifier().getText()
|
||||
}
|
||||
|
||||
readHashes (jekyllStyle?: boolean) {
|
||||
const hashes = []
|
||||
while (true) {
|
||||
|
||||
@@ -23,7 +23,7 @@ export class LiquidTagToken extends DelimitedToken {
|
||||
this.args = ''
|
||||
} else {
|
||||
const tokenizer = new Tokenizer(this.content, options.operatorsTrie)
|
||||
this.name = tokenizer.readIdentifier().getText()
|
||||
this.name = tokenizer.readTagName()
|
||||
if (!this.name) throw new TokenizationError(`illegal liquid tag syntax`, this)
|
||||
|
||||
tokenizer.skipBlank()
|
||||
|
||||
@@ -19,7 +19,7 @@ export class TagToken extends DelimitedToken {
|
||||
super(TokenKind.Tag, value, input, begin, end, trimTagLeft, trimTagRight, file)
|
||||
|
||||
const tokenizer = new Tokenizer(this.content, options.operatorsTrie)
|
||||
this.name = tokenizer.readIdentifier().getText()
|
||||
this.name = tokenizer.readTagName()
|
||||
if (!this.name) throw new TokenizationError(`illegal tag syntax`, this)
|
||||
|
||||
tokenizer.skipBlank()
|
||||
|
||||
Reference in New Issue
Block a user