mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 00:27:50 +00:00
Ensure that passing settings=... does not clobber the default moduleId.
Precompiling a template with `settings` previously generated a snippet
resembling `define(["undefined"], function(lodash) { ... })` if the `settings`
object did not contain a `moduleId` property. You can now pass `settings` and
`moduleId` options simultaneously; the builder will always use the `moduleId`
property in `settings` if it is provided, and default to `moduleId` otherwise.
Former-commit-id: 711b4f167dc08ce3d42029e9001ebdb2d8d60a56
This commit is contained in:
2
build.js
2
build.js
@@ -1050,7 +1050,7 @@
|
||||
var templateSettings = options.reduce(function(result, value) {
|
||||
var match = value.match(/settings=(.+)$/);
|
||||
return match
|
||||
? Function('return {' + match[1].replace(/^{|}$/g, '') + '}')()
|
||||
? Function('assign, result', 'return assign(result, {' + match[1].replace(/^{|}$/g, '') + '})')(_.assign, result)
|
||||
: result;
|
||||
}, _.assign(_.clone(_.templateSettings), {
|
||||
'moduleId': moduleId
|
||||
|
||||
@@ -525,25 +525,36 @@
|
||||
start();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
asyncTest('`lodash settings=...`', function() {
|
||||
var start = _.after(2, _.once(QUnit.start));
|
||||
asyncTest('`lodash settings=...`' + (command ? ' ' + command : ''), function() {
|
||||
var start = _.after(2, _.once(QUnit.start));
|
||||
|
||||
build(['-s', 'template=' + templatePath + '/*.tpl', 'settings={interpolate:/\\{\\{([\\s\\S]+?)\\}\\}/}'], function(source, filePath) {
|
||||
var basename = path.basename(filePath, '.js'),
|
||||
context = createContext();
|
||||
build(['-s', 'template=' + templatePath + '/*.tpl', 'settings={interpolate:/\\{\\{([\\s\\S]+?)\\}\\}/}'].concat(command || []), function(source, filePath) {
|
||||
var moduleId, templates,
|
||||
basename = path.basename(filePath, '.js'),
|
||||
context = createContext();
|
||||
|
||||
var data = {
|
||||
'd': { 'name': 'Mustache' }
|
||||
};
|
||||
var data = {
|
||||
'd': { 'name': 'Mustache' }
|
||||
};
|
||||
|
||||
context._ = _;
|
||||
vm.runInContext(source, context);
|
||||
var templates = context._.templates;
|
||||
(context.define = function(requires, factory) {
|
||||
factory(_);
|
||||
templates = _.templates;
|
||||
moduleId = requires + '';
|
||||
})
|
||||
.amd = {};
|
||||
|
||||
equal(templates.d(data.d), 'Hello Mustache!', basename);
|
||||
start();
|
||||
context._ = _;
|
||||
vm.runInContext(source, context);
|
||||
|
||||
var templates = context._.templates;
|
||||
|
||||
equal(moduleId, command ? 'underscore' : 'lodash');
|
||||
equal(templates.d(data.d), 'Hello Mustache!', basename);
|
||||
delete _.templates;
|
||||
start();
|
||||
});
|
||||
});
|
||||
});
|
||||
}());
|
||||
|
||||
Reference in New Issue
Block a user