Fixin vars declaration inside templating fn because they cannot be declared as const.

+ minor eslint fixes
This commit is contained in:
Michał Lipiński
2017-02-20 14:37:13 +01:00
parent 31500cd6e4
commit 3a375c0ae1

View File

@@ -162,12 +162,12 @@ function template(string, options, guard) {
let source = "__p += '" let source = "__p += '"
// Compile the regexp to match each delimiter. // Compile the regexp to match each delimiter.
const reDelimiters = RegExp( const reDelimiters = RegExp(`${ [
(options.escape || reNoMatch).source + '|' + (options.escape || reNoMatch).source,
interpolate.source + '|' + interpolate.source,
(interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' + (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source,
(options.evaluate || reNoMatch).source + '|$' (options.evaluate || reNoMatch).source
, 'g') ].join('|') }|$`, 'g')
// Use a sourceURL for easier debugging. // Use a sourceURL for easier debugging.
const sourceURL = 'sourceURL' in options const sourceURL = 'sourceURL' in options
@@ -223,22 +223,11 @@ function template(string, options, guard) {
// Frame code as the function body. // Frame code as the function body.
source = `function(${ variable || 'obj' }) {\n` + source = `function(${ variable || 'obj' }) {\n` +
(variable `${ variable ? '' : 'obj || (obj = {});\n' }` +
? '' `var __t, __p = ''` +
: 'obj || (obj = {});\n' `${ isEscaping ? ', __e = _.escape' : '' }` +
) + `${ isEvaluating ? ', __j = Array.prototype.join;\nfunction print() { __p += __j.call(arguments, \'\') }\n' : ';\n' }` +
"const __t, __p = ''" + `${ source } return __p;\n}`
(isEscaping
? ', __e = _.escape'
: ''
) +
(isEvaluating
? ', __j = Array.prototype.join;\n' +
"function print() { __p += __j.call(arguments, '') }\n"
: ';\n'
) +
source +
'return __p\n}'
const result = attempt(() => ( const result = attempt(() => (
Function(importsKeys, `${ sourceURL }return ${ source }`))(...importsValues) Function(importsKeys, `${ sourceURL }return ${ source }`))(...importsValues)