repl: add isValidParentheses check before wrap input · nodejs/node@c206f8d
@@ -157,6 +157,83 @@ async function tests(options) {
157157'\x1B[90m1\x1B[39m\x1B[12G\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r',
158158'\x1B[33m1\x1B[39m',
159159]
160+}, {
161+input: 'aaaa',
162+noPreview: 'Uncaught ReferenceError: aaaa is not defined',
163+preview: [
164+'aaaa\r',
165+'Uncaught ReferenceError: aaaa is not defined',
166+]
167+}, {
168+input: '/0',
169+noPreview: '/0',
170+preview: [
171+'/0\r',
172+'/0',
173+'^',
174+'',
175+'Uncaught SyntaxError: Invalid regular expression: missing /',
176+]
177+}, {
178+input: '{})',
179+noPreview: '{})',
180+preview: [
181+'{})\r',
182+'{})',
183+' ^',
184+'',
185+"Uncaught SyntaxError: Unexpected token ')'",
186+],
187+}, {
188+input: "{ a: '{' }",
189+noPreview: "{ a: \x1B[32m'{'\x1B[39m }",
190+preview: [
191+"{ a: '{' }\r",
192+"{ a: \x1B[32m'{'\x1B[39m }",
193+],
194+}, {
195+input: "{'{':0}",
196+noPreview: "{ \x1B[32m'{'\x1B[39m: \x1B[33m0\x1B[39m }",
197+preview: [
198+"{'{':0}",
199+"\x1B[90m{ '{': 0 }\x1B[39m\x1B[15G\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r",
200+"{ \x1B[32m'{'\x1B[39m: \x1B[33m0\x1B[39m }",
201+],
202+}, {
203+input: '{[Symbol.for("{")]: 0 }',
204+noPreview: '{ \x1B[32mSymbol({)\x1B[39m: \x1B[33m0\x1B[39m }',
205+preview: [
206+'{[Symbol.for("{")]: 0 }\r',
207+'{ \x1B[32mSymbol({)\x1B[39m: \x1B[33m0\x1B[39m }',
208+],
209+}, {
210+input: '{},{}',
211+noPreview: '{}',
212+preview: [
213+'{},{}',
214+'\x1B[90m{}\x1B[39m\x1B[13G\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r',
215+'{}',
216+],
217+}, {
218+input: '{} //',
219+noPreview: 'repl > ',
220+preview: [
221+'{} //\r',
222+],
223+}, {
224+input: '{} //;',
225+noPreview: 'repl > ',
226+preview: [
227+'{} //;\r',
228+],
229+}, {
230+input: '{throw 0}',
231+noPreview: 'Uncaught \x1B[33m0\x1B[39m',
232+preview: [
233+'{throw 0}',
234+'\x1B[90m0\x1B[39m\x1B[17G\x1B[1A\x1B[1B\x1B[2K\x1B[1A\r',
235+'Uncaught \x1B[33m0\x1B[39m',
236+],
160237}];
161238162239const hasPreview = repl.terminal &&
@@ -177,8 +254,13 @@ async function tests(options) {
177254assert.deepStrictEqual(lines, preview);
178255} else {
179256assert.ok(lines[0].includes(noPreview), lines.map(inspect));
180-if (preview.length !== 1 || preview[0] !== `${input}\r`)
181-assert.strictEqual(lines.length, 2);
257+if (preview.length !== 1 || preview[0] !== `${input}\r`) {
258+if (preview[preview.length - 1].includes('Uncaught SyntaxError')) {
259+assert.strictEqual(lines.length, 5);
260+} else {
261+assert.strictEqual(lines.length, 2);
262+}
263+}
182264}
183265}
184266}