1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-10-18 01:07:38 +00:00

Fixes issue with #4504 and importvariable copying (#4518)

* Fixes issue with #4504 and importvariable copying

ImportVariables widget was using $tw.utils.extend to copy the
variables from temporary set widgets into itself. However,
$tw.utils.extend does NOT behave like Object.assign. It not only
copies all self-owned variables over, but also all variables
in that object's prototype chain. This led to some redundant copying,
and a problem where some variables might show up more than once
(like transclusion).

Fixed now. importvariables widget does its own copying, since it
can't rely on $tw.utils.extend to do the right job, and it can't
count on Object.assign to be there.

* Added test to prevent reversion of #4504

* Slight corrections to new importvariables test
This commit is contained in:
Cameron Fischer
2020-03-19 16:32:51 -04:00
committed by GitHub
parent 33fb4f5c0d
commit 561662782e
2 changed files with 40 additions and 1 deletions

View File

@@ -61,7 +61,14 @@ ImportVariablesWidget.prototype.execute = function(tiddlerList) {
var widget = widgetPointer.makeChildWidget(node);
widget.computeAttributes();
widget.execute();
$tw.utils.extend(widgetPointer.variables,widget.variables);
// We SHALLOW copy over all variables
// in widget. We can't use
// $tw.utils.assign, because that copies
// up the prototype chain, which we
// don't want.
$tw.utils.each(Object.keys(widget.variables), function(key) {
widgetPointer.variables[key] = widget.variables[key];
});
} else {
widgetPointer.makeChildWidgets([node]);
widgetPointer = widgetPointer.children[0];