@@ -49,29 +49,30 @@ describe('maybe top-level await syntax errors that are not recognized as top-lev
4949 }
5050 } ) ;
5151
52- it ( 'should crash when the expression is not valid ' , async ( ) => {
53- let { code , signal , stdout , stderr } = await spawnPromisified ( process . execPath , [
54- '--eval' ,
55- `
56- function callAwait( ) {}
57- callAwait(await "" "");
58- ` ,
59- ] ) ;
60- match ( stderr , / S y n t a x E r r o r : m i s s i n g \) a f t e r a r g u m e n t l i s t / ) ;
61- strictEqual ( stdout , '' ) ;
62- strictEqual ( code , 1 ) ;
63- strictEqual ( signal , null ) ;
52+ it ( 'should throw the error for unrelated syntax errors ' , async ( ) => {
53+ const expression = "foo bar" ;
54+ const wrapperExpressions = [
55+ [ `function callSyntaxError() {}; callSyntaxError( ${ expression } );` , / m i s s i n g \) a f t e r a r g u m e n t l i s t / ] ,
56+ [ `if ( ${ expression } ) {}` , / U n e x p e c t e d i d e n t i f i e r / ] ,
57+ [ `{ key: ${ expression } }` , / U n e x p e c t e d i d e n t i f i e r / ] ,
58+ [ `[ ${ expression } ]` , / U n e x p e c t e d i d e n t i f i e r / ] ,
59+ [ `( ${ expression } )` , / U n e x p e c t e d i d e n t i f i e r / ] ,
60+ [ `const ${ expression } = 1;` , / M i s s i n g i n i t i a l i z e r i n c o n s t d e c l a r a t i o n / ] ,
61+ [ `console.log('PI: ' Math.PI);` , / m i s s i n g \) a f t e r a r g u m e n t l i s t / ] ,
62+ [ `callAwait(await "" "");` , / m i s s i n g \) a f t e r a r g u m e n t l i s t / ]
63+ ] ;
6464
65- ( { code, signal, stdout, stderr } = await spawnPromisified ( process . execPath , [
66- '--eval' ,
67- `
68- function callAwait() {}
69- if (a "") {}
70- ` ,
71- ] ) ) ;
72- match ( stderr , / S y n t a x E r r o r : U n e x p e c t e d s t r i n g / ) ;
73- strictEqual ( stdout , '' ) ;
74- strictEqual ( code , 1 ) ;
75- strictEqual ( signal , null ) ;
65+ for ( const [ wrapperExpression , error ] of wrapperExpressions ) {
66+ const { code, signal, stdout, stderr } = await spawnPromisified ( process . execPath , [
67+ '--eval' ,
68+ `
69+ ${ wrapperExpression }
70+ ` ,
71+ ] ) ;
72+ match ( stderr , error ) ;
73+ strictEqual ( stdout , '' ) ;
74+ strictEqual ( code , 1 ) ;
75+ strictEqual ( signal , null ) ;
76+ }
7677 } ) ;
7778} ) ;
0 commit comments