File tree Expand file tree Collapse file tree 1 file changed +31
-6
lines changed Expand file tree Collapse file tree 1 file changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -956,13 +956,38 @@ Parser.prototype.parseCalculatedString = function parseCalculatedString(expressi
956956 } ;
957957} ) ;
958958
959+ var POSSIBLE_AST_OPTIONS = [ {
960+ ranges : true ,
961+ locations : true ,
962+ ecmaVersion : 6 ,
963+ sourceType : "module"
964+ } , {
965+ ranges : true ,
966+ locations : true ,
967+ ecmaVersion : 6 ,
968+ sourceType : "script"
969+ } ]
970+
959971Parser . prototype . parse = function parse ( source , initialState ) {
960- var ast = acorn . parse ( source , {
961- ranges : true ,
962- locations : true ,
963- ecmaVersion : 6 ,
964- sourceType : "module"
965- } ) ;
972+ var ast ;
973+ for ( var i = 0 ; i < POSSIBLE_AST_OPTIONS . length ; i ++ ) {
974+ if ( ! ast ) {
975+ try {
976+ ast = acorn . parse ( source , POSSIBLE_AST_OPTIONS [ i ] ) ;
977+ } catch ( e ) {
978+ // ignore the error
979+ }
980+ }
981+ }
982+ if ( ! ast ) {
983+ // for the error
984+ ast = acorn . parse ( source , {
985+ ranges : true ,
986+ locations : true ,
987+ ecmaVersion : 6 ,
988+ sourceType : "module"
989+ } ) ;
990+ }
966991 if ( ! ast || typeof ast !== "object" )
967992 throw new Error ( "Source couldn't be parsed" ) ;
968993 var oldScope = this . scope ;
You can’t perform that action at this time.
0 commit comments