Skip to content

Commit

Permalink
Merge branch 'release/v0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ClassicOldSong committed Dec 31, 2017
2 parents 2957b6e + 9b980c4 commit 3d191af
Show file tree
Hide file tree
Showing 8 changed files with 2,151 additions and 804 deletions.
2,886 changes: 2,106 additions & 780 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eft-parser",
"version": "0.5.12",
"version": "0.6.0",
"description": "ef.js template parser",
"main": "dist/eft-parser.min.js",
"module": "src/eft-parser.js",
Expand All @@ -26,12 +26,12 @@
},
"homepage": "https://github.com/ClassicOldSong/eft-parser#readme",
"devDependencies": {
"chokidar": "^1.7.0",
"eslint": "^4.5.0",
"rollup": "^0.48.2",
"rollup-plugin-browsersync": "^0.2.4",
"rollup-plugin-buble": "^0.15.0",
"rollup-plugin-commonjs": "^8.1.0",
"chokidar": "^2.0.0",
"eslint": "^4.14.0",
"rollup": "^0.53.2",
"rollup-plugin-browsersync": "^0.2.6",
"rollup-plugin-buble": "^0.18.0",
"rollup-plugin-commonjs": "^8.2.6",
"rollup-plugin-eslint": "^4.0.0",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-progress": "^0.4.0",
Expand Down
22 changes: 17 additions & 5 deletions src/eft-parser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ESCAPE from './escape-parser.js'
import efEscape from './escape-parser.js'

const typeSymbols = '>#%@.-+'.split('')
const reserved = '__EFPLACEHOLDER__ $parent $key $data $element $refs $methods $mount $umount $subscribe $unsubscribe $update $destroy __DIRECTMOUNT__'.split(' ')
Expand All @@ -10,6 +10,18 @@ const getErrorMsg = (msg, line = -2) => `Failed to parse eft template: ${msg}. a

const isEmpty = string => !string.replace(/\s/, '')

const checkValidType = obj => ['number', 'boolean', 'string'].indexOf(typeof obj) > -1

const ESCAPE = (string) => {
try {
const parsed = JSON.parse(string)
if (['number', 'boolean'].indexOf(typeof parsed) === -1) return efEscape(string)
return parsed
} catch (e) {
return efEscape(string)
}
}

const getOffset = (string, parsingInfo) => {
if (parsingInfo.offset !== null) return
parsingInfo.offset = string.match(/\s*/)[0]
Expand Down Expand Up @@ -58,7 +70,7 @@ const splitDefault = (string) => {
const [_path, ..._default] = string.split('=')
const pathArr = _path.trim().split('.')
const defaultVal = ESCAPE(_default.join('=').trim())
if (defaultVal) return [pathArr, defaultVal]
if (checkValidType(defaultVal)) return [pathArr, defaultVal]
return [pathArr]
}

Expand All @@ -67,7 +79,7 @@ const splitLiterals = (string) => {
if (strs.length === 1) return ESCAPE(string)
const tmpl = []
if (strs.length === 2 && !strs[0] && !strs[1]) tmpl.push(0)
else tmpl.push(strs.map(ESCAPE))
else tmpl.push(strs.map(efEscape))
const mustaches = string.match(mustache)
if (mustaches) tmpl.push(...mustaches.map(splitDefault))
return tmpl
Expand All @@ -79,7 +91,7 @@ const pushStr = (textArr, str) => {

const parseText = (string) => {
const result = splitLiterals(string)
if (typeof result === 'string') return [result]
if (checkValidType(result)) return [`${result}`]
const [strs, ...exprs] = result
const textArr = []
for (let i = 0; i < exprs.length; i++) {
Expand Down Expand Up @@ -276,7 +288,7 @@ const parseLine = ({line, ast, parsingInfo, i}) => {
}

const parseEft = (template) => {
if (!template) throw new TypeError(getErrorMsg('Template required, but nothing present'))
if (!template) throw new TypeError(getErrorMsg('Template required, but nothing given'))
const tplType = typeof template
if (tplType !== 'string') throw new TypeError(getErrorMsg(`Expected a string, but got a(n) ${tplType}`))
const lines = template.split(/\r?\n/)
Expand Down
1 change: 1 addition & 0 deletions test/ef-core.dev.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion test/ef.min.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/eft-parser.dev.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8">
<title>eft-parser Test Page</title>
<script src="./eft-parser.dev.js"></script>
<script src="./ef.min.js"></script>
<script src="./ef-core.dev.js"></script>
<style type="text/css" media="screen">
.box {
border: 1px solid #000;
Expand Down
27 changes: 18 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var ef = efCore

var template = '\n' +
'>div.{{class.text = box test}}\n' +
' #id = id1\n' +
Expand Down Expand Up @@ -26,7 +28,7 @@ var template = '\n' +
' .One way binded with particle update:\n' +
' >input\n' +
' #type = text\n' +
' %value = 1: {{class.text}} 2: {{class.text2}}\n' +
' %value = "1: {{class.text}} 2: {{class.text2}}"\n' +
' >br\n' +
' >input\n' +
' #type = radio\n' +
Expand All @@ -38,7 +40,11 @@ var template = '\n' +
' %checked = {{testRadio2}}\n' +
' >input\n' +
' #type = checkbox\n' +
' %checked = {{testCheck}}\n' +
' %checked = {{testCheck = true}}\n' +
' >input\n' +
' #type = checkbox\n' +
' #disabled = false\n' +
' %checked = {{testCheck = true}}\n' +
' >br\n' +
' .Input style here: \n' +
' >br\n' +
Expand All @@ -51,6 +57,9 @@ var template = '\n' +
' >button\n' +
' @click = sendMsg:some data\n' +
' .{{btnText = sendMsg}}\n' +
' >button\n' +
' @click = nothing\n' +
' .Button that does nothing\n' +
' +list'

var template2 = ' this is a comment\n' +
Expand Down Expand Up @@ -91,15 +100,15 @@ var data1 = {
}
}

var module1 = new ef(ast)
var module2 = new ef(ast2)
var module1 = ef.create(ast)
var module2 = ef.create(ast2)

ef.inform()

var state = module1.render()
var state2 = module1.render()
var state3 = module2.render()
var state4 = module2.render(data1)
var state = new module1()
var state2 = new module1()
var state3 = new module2()
var state4 = new module2(data1)

state3.list1.push(state4)
state2.branch = state3
Expand Down Expand Up @@ -150,7 +159,7 @@ state2.$methods.sendMsg = function (info) {
ef.inform()
var count = parseInt(info.state.$data.style)
var startTime = Date.now()
for (var i = 0; i < count; i++) states.push(module1.render())
for (var i = 0; i < count; i++) states.push(new module1())
state4.list1.push.apply(state4.list1, states)
ef.exec()
var endTime = Date.now()
Expand Down

0 comments on commit 3d191af

Please sign in to comment.