You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Return proxy redirecting keys for options-as-properties from Command constructor
Borrowed from tj#1919.
Makes _optionValues the only true storage for option values.
Has the added benefit of supporting option names conflicting with
instance's properties even when options-as-properties are enabled.
Copy file name to clipboardExpand all lines: lib/command.js
+65-9Lines changed: 65 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -95,6 +95,67 @@ Option value deletion is not supported`);
95
95
Options value configuration is not supported`);
96
96
}
97
97
});
98
+
99
+
// Because of how the returned proxy works, ideally, no prooerties should be defined outside the cinstructor.
100
+
// They can still be defined outside the constructor in subclasses, but only when _storeOptionsAsProperties is set to false.
101
+
this._version=undefined;
102
+
this._versionOptionName=undefined;
103
+
104
+
// The proxy only treats keys not present in the instance and its prototype chain as keys for _optionValues when _storeOptionsAsProperties is set to true.
105
+
// Setting option values for keys present in the instance and its prototype chain is still possible by calling .setOptionValue() or .setOptionValueWithSource(),
106
+
// but such values will not be accessible as instnace properties because the instance and its prototype chain has precedence.
107
+
// However, they will be accessible via .getOptionValue(), .opts() and .optsWithGlobals().
0 commit comments