-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlsx.js
20 lines (16 loc) · 765 Bytes
/
lsx.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// const LiveScript = require('livescript')
import LiveScript from './livescript.js'
const lsc = it => LiveScript.compile(it, {bare:true, header: false, const: 0})
String.prototype.e = String.prototype.e || String.prototype.replace
const srct = it => it.e(/^\s*[\/]{2}/gm, '#')
.e(/".*?\$.*?"/gm, i => i.e('\\$', '#'))
.e(/^(\s*if .+?) rn\s*(\S*)$/gm, '$1 then return $2')
.e(/\brn\b/gm, 'return')
.e(/^\s*(import .+)$/gm, '\n``$1``\n').e(/^\s*(export default)/gm, '\n``$1``')
const dett = it => it.e(/;$/gm, '').e(/:\s*function/g, '')
.e(/function\s*\((.*)\)/g, '($1) => ')
.e(/\((\w+)\) => /g, '$1 => ')
.e(/=>\s*?\{\s*?return ([\S ]+)\s*?\}\)/g, '=> $1)')
.e(/\{\n\s*(.+)\n\s*\}/g, '{ $1 }')
const lscx = it => dett(lsc(srct(it)))
export { lscx }