refactor: import rollup

This commit is contained in:
harttle
2018-08-20 23:58:41 +08:00
parent 4ece4e208f
commit bc9d8f92af
82 changed files with 8589 additions and 3963 deletions
+15 -16
View File
@@ -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