mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +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 templateSettings = options.reduce(function(result, value) {
|
||||||
var match = value.match(/settings=(.+)$/);
|
var match = value.match(/settings=(.+)$/);
|
||||||
return match
|
return match
|
||||||
? Function('return {' + match[1].replace(/^{|}$/g, '') + '}')()
|
? Function('assign, result', 'return assign(result, {' + match[1].replace(/^{|}$/g, '') + '})')(_.assign, result)
|
||||||
: result;
|
: result;
|
||||||
}, _.assign(_.clone(_.templateSettings), {
|
}, _.assign(_.clone(_.templateSettings), {
|
||||||
'moduleId': moduleId
|
'moduleId': moduleId
|
||||||
|
|||||||
@@ -525,25 +525,36 @@
|
|||||||
start();
|
start();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
asyncTest('`lodash settings=...`', function() {
|
asyncTest('`lodash settings=...`' + (command ? ' ' + command : ''), function() {
|
||||||
var start = _.after(2, _.once(QUnit.start));
|
var start = _.after(2, _.once(QUnit.start));
|
||||||
|
|
||||||
build(['-s', 'template=' + templatePath + '/*.tpl', 'settings={interpolate:/\\{\\{([\\s\\S]+?)\\}\\}/}'], function(source, filePath) {
|
build(['-s', 'template=' + templatePath + '/*.tpl', 'settings={interpolate:/\\{\\{([\\s\\S]+?)\\}\\}/}'].concat(command || []), function(source, filePath) {
|
||||||
var basename = path.basename(filePath, '.js'),
|
var moduleId, templates,
|
||||||
context = createContext();
|
basename = path.basename(filePath, '.js'),
|
||||||
|
context = createContext();
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
'd': { 'name': 'Mustache' }
|
'd': { 'name': 'Mustache' }
|
||||||
};
|
};
|
||||||
|
|
||||||
context._ = _;
|
(context.define = function(requires, factory) {
|
||||||
vm.runInContext(source, context);
|
factory(_);
|
||||||
var templates = context._.templates;
|
templates = _.templates;
|
||||||
|
moduleId = requires + '';
|
||||||
|
})
|
||||||
|
.amd = {};
|
||||||
|
|
||||||
equal(templates.d(data.d), 'Hello Mustache!', basename);
|
context._ = _;
|
||||||
start();
|
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