File tree 1 file changed +29
-0
lines changed
1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -1195,6 +1195,35 @@ function regexpEscape(s) {
1195
1195
return s . replace ( / [ - [ \] { } ( ) * + ? . , \\ ^ $ | # \s ] / g, '\\$&' ) ;
1196
1196
}
1197
1197
1198
+
1199
+ /**
1200
+ * Converts commands that use var and function <name>() to use the
1201
+ * local exports.context when evaled. This provides a local context
1202
+ * on the REPL.
1203
+ *
1204
+ * @param {String } cmd The cmd to convert.
1205
+ * @return {String } The converted command.
1206
+ */
1207
+ REPLServer . prototype . convertToContext = util . deprecate ( function ( cmd ) {
1208
+ const scopeVar = / ^ \s * v a r \s * ( [ _ \w \$ ] + ) ( .* ) $ / m;
1209
+ const scopeFunc = / ^ \s * f u n c t i o n \s * ( [ _ \w \$ ] + ) / ;
1210
+ var matches ;
1211
+
1212
+ // Replaces: var foo = "bar"; with: self.context.foo = bar;
1213
+ matches = scopeVar . exec ( cmd ) ;
1214
+ if ( matches && matches . length === 3 ) {
1215
+ return 'self.context.' + matches [ 1 ] + matches [ 2 ] ;
1216
+ }
1217
+
1218
+ // Replaces: function foo() {}; with: foo = function foo() {};
1219
+ matches = scopeFunc . exec ( this . bufferedCommand ) ;
1220
+ if ( matches && matches . length === 2 ) {
1221
+ return matches [ 1 ] + ' = ' + this . bufferedCommand ;
1222
+ }
1223
+
1224
+ return cmd ;
1225
+ } , 'replServer.convertToContext will be removed in v8.0.0' ) ;
1226
+
1198
1227
function bailOnIllegalToken ( parser ) {
1199
1228
return parser . _literal === null &&
1200
1229
! parser . blockComment &&
You can’t perform that action at this time.
0 commit comments