Skip to content

Commit da0d780

Browse files
test: add tests for repl tab completion on computer variable properties
1 parent c8b2767 commit da0d780

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

lib/repl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ const importRE = /\bimport\s*\(\s*['"`](([\w@./:-]+\/)?(?:[\w@./:-]*))(?![^'"`])
12261226
const requireRE = /\brequire\s*\(\s*['"`](([\w@./:-]+\/)?(?:[\w@./:-]*))(?![^'"`])$/;
12271227
const fsAutoCompleteRE = /fs(?:\.promises)?\.\s*[a-z][a-zA-Z]+\(\s*["'](.*)/;
12281228
const simpleExpressionRE =
1229-
/(?:[\w$'"`[{(](?:\w|['"`](\w| |\t)*['"`]|\$|['"`\]})])*\??(?:\.|])?)*(?:[a-zA-Z_$])?(?:\w|\$)*\??\.?$/m;
1229+
/(?:[\w$'"`[{(](?:(\w| |\t)*?['"`]|\$|['"`\]})])*\??(?:\.|])?)*?(?:[a-zA-Z_$])?(?:\w|\$)*\??\.?$/;
12301230
const versionedFileNamesRe = /-\d+\.\d+/;
12311231

12321232
function isIdentifier(str) {

test/parallel/test-repl-tab-complete-computed-props.js

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ function prepareREPL() {
2424

2525
function testCompletion(replServer, { input, expectedCompletions }) {
2626
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+
}),
3131
);
3232
};
3333

@@ -92,4 +92,39 @@ describe('REPL tab object completion on computed properties', () => {
9292
expectedCompletions: ['obj["inner object"].three'],
9393
}));
9494
});
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+
});
95130
});

0 commit comments

Comments
 (0)