babel-plugin-transform-wxs
Babel plugin for wxs environment.
Example
Normalize variable name
In
var $var = val;
Out
var _var = val;
Transform constructors
In
new Date(timestamp)
new RegExp('pattern', 'i')
Out
getDate(timestamp)
getRegExp('pattern', 'i')
Inject exports automatically
In
exports.value = val;
Out
var exports = module.exports;
exports.value = val;
Normalize for statements
In
for (var i = 0, ii = array.length; i < ii; i++) {
}
Out
var i = 0, ii = array.length;
for (; i < ii; i++) {
}
Transform instanceof
In
value instanceof Function
value instanceof Array
value instanceof Date
value instanceof RegExp
Out
value && value.constructor === 'Function'
value && value.constructor === 'Array'
value && value.constructor === 'Date'
value && value.constructor === 'RegExp'
Transform Array.isArray call
In
Array.isArray(value)
Out
value && value.constructor === 'Array'
Transform regexp
In
regex1 = /pattern/
regex2 = /pattern/i
Out
regex1 = getRegExp('pattern')
regex2 = getRegExp('pattern', 'i')