mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 04:40:39 -07:00
refactor: import rollup
This commit is contained in:
+15
-16
@@ -1,17 +1,19 @@
|
||||
const lexical = require('./lexical.js')
|
||||
const TokenizationError = require('./util/error.js').TokenizationError
|
||||
const _ = require('./util/underscore.js')
|
||||
const whiteSpaceCtrl = require('./whitespace-ctrl.js')
|
||||
const assert = require('./util/assert.js')
|
||||
import * as lexical from './lexical.js'
|
||||
import {TokenizationError} from './util/error.js'
|
||||
import * as _ from './util/underscore.js'
|
||||
import assert from './util/assert.js'
|
||||
import whiteSpaceCtrl from './whitespace-ctrl.js'
|
||||
|
||||
function parse (input, file, options) {
|
||||
export {default as whiteSpaceCtrl} from './whitespace-ctrl.js'
|
||||
|
||||
export function parse (input, file, options) {
|
||||
assert(_.isString(input), 'illegal input')
|
||||
|
||||
let rLiquid = /({%-?([\s\S]*?)-?%})|({{-?([\s\S]*?)-?}})/g
|
||||
const rLiquid = /({%-?([\s\S]*?)-?%})|({{-?([\s\S]*?)-?}})/g
|
||||
let currIndent = 0
|
||||
let lineNumber = LineNumber(input)
|
||||
const lineNumber = LineNumber(input)
|
||||
let lastMatchEnd = 0
|
||||
let tokens = []
|
||||
const tokens = []
|
||||
|
||||
for (let match; (match = rLiquid.exec(input)); lastMatchEnd = rLiquid.lastIndex) {
|
||||
if (match.index > lastMatchEnd) {
|
||||
@@ -28,8 +30,8 @@ function parse (input, file, options) {
|
||||
return tokens
|
||||
|
||||
function parseTagToken (raw, value, pos) {
|
||||
let match = value.match(lexical.tagLine)
|
||||
let token = {
|
||||
const match = value.match(lexical.tagLine)
|
||||
const token = {
|
||||
type: 'tag',
|
||||
indent: currIndent,
|
||||
line: lineNumber.get(pos),
|
||||
@@ -62,7 +64,7 @@ function parse (input, file, options) {
|
||||
}
|
||||
|
||||
function parseHTMLToken (begin, end) {
|
||||
let htmlFragment = input.slice(begin, end)
|
||||
const htmlFragment = input.slice(begin, end)
|
||||
currIndent = _.last((htmlFragment).split('\n')).length
|
||||
|
||||
return {
|
||||
@@ -79,13 +81,10 @@ function LineNumber (html) {
|
||||
|
||||
return {
|
||||
get: function (pos) {
|
||||
let lines = html.slice(lastMatchBegin + 1, pos).split('\n')
|
||||
const lines = html.slice(lastMatchBegin + 1, pos).split('\n')
|
||||
parsedLinesCount += lines.length - 1
|
||||
lastMatchBegin = pos
|
||||
return parsedLinesCount + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.parse = parse
|
||||
exports.whiteSpaceCtrl = whiteSpaceCtrl
|
||||
|
||||
Reference in New Issue
Block a user