@@ -24,10 +24,10 @@ function prepareREPL() {
24
24
25
25
function testCompletion ( replServer , { input, expectedCompletions } ) {
26
26
replServer . complete (
27
- input ,
28
- common . mustCall ( ( _error , data ) => {
29
- assert . deepStrictEqual ( data , [ expectedCompletions , input ] ) ;
30
- } ) ,
27
+ input ,
28
+ common . mustCall ( ( _error , data ) => {
29
+ assert . deepStrictEqual ( data , [ expectedCompletions , input ] ) ;
30
+ } ) ,
31
31
) ;
32
32
} ;
33
33
@@ -92,4 +92,39 @@ describe('REPL tab object completion on computed properties', () => {
92
92
expectedCompletions : [ 'obj["inner object"].three' ] ,
93
93
} ) ) ;
94
94
} ) ;
95
+
96
+ describe ( 'variables as indexes' , ( ) => {
97
+ let replServer ;
98
+
99
+ before ( ( ) => {
100
+ const { replServer : server , input } = prepareREPL ( ) ;
101
+ replServer = server ;
102
+
103
+ input . run ( [
104
+ `
105
+ const oneStr = 'One';
106
+ const helloWorldStr = 'Hello' + ' ' + 'World';
107
+
108
+ const obj = {
109
+ [oneStr]: 1,
110
+ ['Hello World']: 'hello world!',
111
+ };
112
+ ` ,
113
+ ] ) ;
114
+ } ) ;
115
+
116
+ after ( ( ) => {
117
+ replServer . close ( ) ;
118
+ } ) ;
119
+
120
+ it ( 'works with a simple variable' , ( ) => testCompletion ( replServer , {
121
+ input : 'obj[oneStr].toFi' ,
122
+ expectedCompletions : [ 'obj[oneStr].toFixed' ] ,
123
+ } ) ) ;
124
+
125
+ it ( 'works with a computed variable' , ( ) => testCompletion ( replServer , {
126
+ input : 'obj[helloWorldStr].tolocaleup' ,
127
+ expectedCompletions : [ 'obj[helloWorldStr].toLocaleUpperCase' ] ,
128
+ } ) ) ;
129
+ } ) ;
95
130
} ) ;
0 commit comments