@@ -26,6 +26,15 @@ function assert(condition, text) {
2626 }
2727}
2828
29+ function assertAt ( condition , node , message = '' ) {
30+ if ( ! condition ) {
31+ const loc = acorn . getLineInfo ( input , node . start ) ;
32+ throw new Error (
33+ `${ infile } :${ loc . line } : ${ message } (use EMCC_DEBUG_SAVE=1 to preserve temporary inputs)` ,
34+ ) ;
35+ }
36+ }
37+
2938function warnOnce ( msg ) {
3039 if ( ! warnOnce . msgs ) warnOnce . msgs = { } ;
3140 if ( msg in warnOnce . msgs ) return ;
@@ -190,7 +199,7 @@ function restoreForVars(node) {
190199 let restored = 0 ;
191200 function fix ( init ) {
192201 if ( init && init . type === 'EmptyStatement' ) {
193- assert ( init . oldDeclarations ) ;
202+ assertAt ( init . oldDeclarations , init ) ;
194203 init . type = 'VariableDeclaration' ;
195204 init . declarations = init . oldDeclarations ;
196205 restored ++ ;
@@ -427,12 +436,16 @@ function runJSDCE(ast, aggressive) {
427436 } ) ;
428437 } else if ( id . type === 'ArrayPattern' ) {
429438 id . elements . forEach ( ( node ) => {
430- assert ( node . type === 'Identifier' ) ;
439+ assertAt (
440+ node . type === 'Identifier' ,
441+ node ,
442+ `expected Indentifier but found ${ node . type } ` ,
443+ ) ;
431444 const name = node . name ;
432445 ensureData ( scopes [ scopes . length - 1 ] , name ) . def = 1 ;
433446 } ) ;
434447 } else {
435- assert ( id . type === 'Identifier' ) ;
448+ assertAt ( id . type === 'Identifier' , id ) ;
436449 const name = id . name ;
437450 ensureData ( scopes [ scopes . length - 1 ] , name ) . def = 1 ;
438451 }
@@ -726,7 +739,7 @@ function emitDCEGraph(ast) {
726739 // use the left hand identifier.
727740 value = value . left ;
728741 }
729- assert ( value . type === 'Identifier' ) ;
742+ assertAt ( value . type === 'Identifier' , value ) ;
730743 imports . push ( value . name ) ; // the name doesn't matter, only the value which is that actual thing we are importing
731744 } ) ;
732745 foundWasmImportsAssign = true ;
@@ -786,7 +799,7 @@ function emitDCEGraph(ast) {
786799 // var x = Module['x'] = 1234;
787800 // this form occurs when global addresses are exported from the
788801 // module. It doesn't constitute a usage.
789- assert ( typeof value . right . value === 'number' ) ;
802+ assertAt ( typeof value . right . value === 'number' , value . right ) ;
790803 emptyOut ( node ) ;
791804 }
792805 }
@@ -1723,7 +1736,7 @@ function minifyLocals(ast) {
17231736 // locals are just numbers, not functions; functions are all declared
17241737 // in the outer scope. If a local is called, that is a bug.
17251738 if ( node . callee . type === 'Identifier' ) {
1726- assert ( ! isLocalName ( node . callee . name ) , 'cannot call a local' ) ;
1739+ assertAt ( ! isLocalName ( node . callee . name ) , node . callee , 'cannot call a local' ) ;
17271740 }
17281741 } ,
17291742 } ) ;
0 commit comments