Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support anonymous and arrow callbacks #1

Merged
merged 4 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ DIST = "./dist/"

test: build test-mocha test-karma

build: eslint
build:
# rebuild all
@ mkdir -p $(DIST)
@ $(JSPP) $(JSPP_ES6_FLAGS) src/index.js > $(DIST)es6.tmpl.js
Expand Down
42 changes: 27 additions & 15 deletions dist/csp.tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6545,7 +6545,7 @@ return /******/ (function(modules) { // webpackBootstrap

});

var index = hoist;
var hoister = hoist;

function hoist(ast){

Expand Down Expand Up @@ -6683,7 +6683,7 @@ function FunctionFactory(parentContext){
// takes an AST or js source and returns an AST
function prepareAst(src){
var tree = (typeof src === 'string') ? parse(src) : src;
return index(tree)
return hoister(tree)
}

// evaluate an AST in the given context
Expand Down Expand Up @@ -7173,7 +7173,7 @@ function ReturnValue(type, value){

/**
* The riot template engine
* @version v3.0.8
* @version WIP
*/

var skipRegex = (function () { //eslint-disable-line no-unused-vars
Expand Down Expand Up @@ -7666,19 +7666,31 @@ var tmpl = (function () {
function _wrapExpr (expr, asText, key) {
var tb;

expr = expr.replace(JS_VARNAME, function (match, p, mvar, pos, s) {
if (mvar) {
pos = tb ? 0 : pos + match.length;
if (expr.match(/=>/)) {
try {
var match = expr.match(/(.*)((\((.*)))(=>)((.*))\)/);
var body = match[6].replace(/[{}\s]|(return)/g, '');
expr = match[1] + 'function' + match[2] + '{return ' + body + '})';
} catch(error) {
console.error('Failed to transform arrow function in expression:', expr, error);
}
}

if (mvar !== 'this' && mvar !== 'global' && mvar !== 'window') {
match = p + '("' + mvar + JS_CONTEXT + mvar;
if (pos) tb = (s = s[pos]) === '.' || s === '(' || s === '[';
} else if (pos) {
tb = !JS_NOPROPS.test(s.slice(pos));
if (!expr.match(/\(function\(/)) {
expr = expr.replace(JS_VARNAME, function (match, p, mvar, pos, s) {
if (mvar) {
pos = tb ? 0 : pos + match.length;

if (mvar !== 'this' && mvar !== 'global' && mvar !== 'window') {
match = p + '("' + mvar + JS_CONTEXT + mvar;
if (pos) tb = (s = s[pos]) === '.' || s === '(' || s === '[';
} else if (pos) {
tb = !JS_NOPROPS.test(s.slice(pos));
}
}
}
return match
});
return match
});
}

if (tb) {
expr = 'try{return ' + expr + '}catch(e){E(e,this)}';
Expand All @@ -7700,7 +7712,7 @@ var tmpl = (function () {
return expr
}

_tmpl.version = brackets.version = 'v3.0.8';
_tmpl.version = brackets.version = 'WIP';

return _tmpl

Expand Down
38 changes: 25 additions & 13 deletions dist/es6.tmpl.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/**
* The riot template engine
* @version v3.0.8
* @version WIP
*/

var skipRegex = (function () { //eslint-disable-line no-unused-vars
Expand Down Expand Up @@ -496,19 +496,31 @@ var tmpl = (function () {
function _wrapExpr (expr, asText, key) {
var tb

expr = expr.replace(JS_VARNAME, function (match, p, mvar, pos, s) {
if (mvar) {
pos = tb ? 0 : pos + match.length
if (expr.match(/=>/)) {
try {
var match = expr.match(/(.*)((\((.*)))(=>)((.*))\)/)
var body = match[6].replace(/[{}\s]|(return)/g, '')
expr = match[1] + 'function' + match[2] + '{return ' + body + '})'
} catch(error) {
console.error('Failed to transform arrow function in expression:', expr, error)
}
}

if (mvar !== 'this' && mvar !== 'global' && mvar !== 'window') {
match = p + '("' + mvar + JS_CONTEXT + mvar
if (pos) tb = (s = s[pos]) === '.' || s === '(' || s === '['
} else if (pos) {
tb = !JS_NOPROPS.test(s.slice(pos))
if (!expr.match(/\(function\(/)) {
expr = expr.replace(JS_VARNAME, function (match, p, mvar, pos, s) {
if (mvar) {
pos = tb ? 0 : pos + match.length

if (mvar !== 'this' && mvar !== 'global' && mvar !== 'window') {
match = p + '("' + mvar + JS_CONTEXT + mvar
if (pos) tb = (s = s[pos]) === '.' || s === '(' || s === '['
} else if (pos) {
tb = !JS_NOPROPS.test(s.slice(pos))
}
}
}
return match
})
return match
})
}

if (tb) {
expr = 'try{return ' + expr + '}catch(e){E(e,this)}'
Expand All @@ -530,7 +542,7 @@ var tmpl = (function () {
return expr
}

_tmpl.version = brackets.version = 'v3.0.8'
_tmpl.version = brackets.version = 'WIP'

return _tmpl

Expand Down
38 changes: 25 additions & 13 deletions dist/tmpl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/* riot-tmpl v3.0.8, @license MIT, (c) 2015 Muut Inc. + contributors */
/* riot-tmpl WIP, @license MIT, (c) 2015 Muut Inc. + contributors */
;(function (window) { // eslint-disable-line no-extra-semi
'use strict'

Expand Down Expand Up @@ -491,19 +491,31 @@
function _wrapExpr (expr, asText, key) {
var tb

expr = expr.replace(JS_VARNAME, function (match, p, mvar, pos, s) {
if (mvar) {
pos = tb ? 0 : pos + match.length
if (expr.match(/=>/)) {
try {
var match = expr.match(/(.*)((\((.*)))(=>)((.*))\)/)
var body = match[6].replace(/[{}\s]|(return)/g, '')
expr = match[1] + 'function' + match[2] + '{return ' + body + '})'
} catch(error) {
console.error('Failed to transform arrow function in expression:', expr, error)
}
}

if (mvar !== 'this' && mvar !== 'global' && mvar !== 'window') {
match = p + '("' + mvar + JS_CONTEXT + mvar
if (pos) tb = (s = s[pos]) === '.' || s === '(' || s === '['
} else if (pos) {
tb = !JS_NOPROPS.test(s.slice(pos))
if (!expr.match(/\(function\(/)) {
expr = expr.replace(JS_VARNAME, function (match, p, mvar, pos, s) {
if (mvar) {
pos = tb ? 0 : pos + match.length

if (mvar !== 'this' && mvar !== 'global' && mvar !== 'window') {
match = p + '("' + mvar + JS_CONTEXT + mvar
if (pos) tb = (s = s[pos]) === '.' || s === '(' || s === '['
} else if (pos) {
tb = !JS_NOPROPS.test(s.slice(pos))
}
}
}
return match
})
return match
})
}

if (tb) {
expr = 'try{return ' + expr + '}catch(e){E(e,this)}'
Expand All @@ -529,7 +541,7 @@

})()

tmpl.version = brackets.version = 'v3.0.8'
tmpl.version = brackets.version = 'WIP'

/* istanbul ignore else */
if (typeof module === 'object' && module.exports) {
Expand Down
Loading