mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 18:37:50 +00:00
Fixin vars declaration inside templating fn because they cannot be declared as const.
+ minor eslint fixes
This commit is contained in:
33
template.js
33
template.js
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user