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