@@ -50,7 +50,7 @@ function deepScan(content, repo) {
5050 */
5151
5252var exports = exports || { } ;
53- exports . version = '5.2.6 ' ;
53+ exports . version = '5.2.7 ' ;
5454
5555function isDefined ( o ) {
5656 return typeof o !== 'undefined' ;
@@ -252,12 +252,11 @@ const meriyah_1 = require("meriyah");
252252const nodeutils_1 = require ( "./nodeutils" ) ;
253253const utils_1 = require ( "./utils" ) ;
254254const debugLogEnabled = false ;
255- const log = {
256- debug : debugLogEnabled ? ( ...args ) => {
257- if ( debugLogEnabled )
258- console . debug ( ...args ) ;
259- } : ( ) => { }
260- } ;
255+ const log = debugLogEnabled ? {
256+ debug : ( ...args ) => {
257+ console . debug ( ...args ) ;
258+ }
259+ } : undefined ;
261260exports . functions = {
262261 "join" : {
263262 fn : ( result ) => {
@@ -350,17 +349,17 @@ function createQuerier() {
350349 }
351350 else if ( "node" in filter ) {
352351 if ( filter . node . type == "child" ) {
353- log . debug ( "ADDING FILTER CHILD" , filter . node ) ;
352+ log ? .debug ( "ADDING FILTER CHILD" , filter . node ) ;
354353 state . child [ state . depth + 1 ] . push ( filter ) ;
355354 }
356355 if ( filter . node . type == "descendant" ) {
357- log . debug ( "ADDING FILTER DESCENDANT" , filter . node ) ;
356+ log ? .debug ( "ADDING FILTER DESCENDANT" , filter . node ) ;
358357 state . descendant [ state . depth + 1 ] . push ( filter ) ;
359358 }
360359 }
361360 }
362361 function createFNodeAndAddToState ( token , result , state ) {
363- log . debug ( "ADDING FNODE" , token ) ;
362+ log ? .debug ( "ADDING FNODE" , token ) ;
364363 const fnode = createFNode ( token , result ) ;
365364 if ( token . type == "child" ) {
366365 state . child [ state . depth + 1 ] . push ( fnode ) ;
@@ -374,15 +373,15 @@ function createQuerier() {
374373 if ( fnode . node . attribute ) {
375374 const m = fnode . node . value == path . parentKey || fnode . node . value == path . key ;
376375 if ( m )
377- log . debug ( "ATTR MATCH" , fnode . node . value , breadCrumb ( path ) ) ;
376+ log ? .debug ( "ATTR MATCH" , fnode . node . value , breadCrumb ( path ) ) ;
378377 return m ;
379378 }
380379 if ( fnode . node . value == "*" ) {
381380 return true ;
382381 }
383382 const m = fnode . node . value == path . node . type ;
384383 if ( m )
385- log . debug ( "NODE MATCH" , fnode . node . value , breadCrumb ( path ) ) ;
384+ log ? .debug ( "NODE MATCH" , fnode . node . value , breadCrumb ( path ) ) ;
386385 return m ;
387386 }
388387 function addIfTokenMatch ( fnode , path , state ) {
@@ -450,11 +449,11 @@ function createQuerier() {
450449 const nodes = getPrimitiveChildren ( fnode . node . value , path ) ;
451450 if ( nodes . length == 0 )
452451 return ;
453- log . debug ( "PRIMITIVE" , fnode . node . value , nodes ) ;
452+ log ? .debug ( "PRIMITIVE" , fnode . node . value , nodes ) ;
454453 fnode . result . push ( ...nodes ) ;
455454 }
456455 function evaluateFilter ( filter , path ) {
457- log . debug ( "EVALUATING FILTER" , filter , breadCrumb ( path ) ) ;
456+ log ? .debug ( "EVALUATING FILTER" , filter , breadCrumb ( path ) ) ;
458457 if ( "type" in filter ) {
459458 if ( filter . type == "and" ) {
460459 const left = evaluateFilter ( filter . left , path ) ;
@@ -489,15 +488,15 @@ function createQuerier() {
489488 function resolveBinding ( path ) {
490489 if ( ! ( 0 , nodeutils_1 . isIdentifier ) ( path . node ) )
491490 return undefined ;
492- log . debug ( "RESOLVING BINDING FOR " , path . node ) ;
491+ log ? .debug ( "RESOLVING BINDING FOR " , path . node ) ;
493492 const name = path . node . name ;
494493 if ( name == undefined || typeof name != "string" )
495494 return undefined ;
496495 //const binding = path.scope.getBinding(name);
497496 const binding = getBinding ( path . scopeId , name ) ;
498497 if ( ! binding )
499498 return undefined ;
500- log . debug ( "THIS IS THE BINDING" , binding ) ;
499+ log ? .debug ( "THIS IS THE BINDING" , binding ) ;
501500 return binding . path ;
502501 }
503502 function resolveFilterWithParent ( node , path ) {
@@ -508,7 +507,7 @@ function createQuerier() {
508507 throw new Error ( "Parent filter must have child" ) ;
509508 if ( ! startPath . parentPath )
510509 return [ ] ;
511- log . debug ( "STEP OUT" , startNode , breadCrumb ( startPath ) ) ;
510+ log ? .debug ( "STEP OUT" , startNode , breadCrumb ( startPath ) ) ;
512511 startNode = startNode . child ;
513512 startPath = startPath . parentPath ;
514513 }
@@ -527,9 +526,9 @@ function createQuerier() {
527526 const lookup = startNode . value ;
528527 if ( ! lookup )
529528 throw new Error ( "Selector must have a value" ) ;
530- //log.debug("STEP IN ", lookup, paths.map(p => breadCrumb(p)));
529+ //log? .debug("STEP IN ", lookup, paths.map(p => breadCrumb(p)));
531530 const nodes = paths . filter ( nodeutils_1 . isNodePath ) . map ( n => getPrimitiveChildrenOrNodePaths ( lookup , n ) ) . flat ( ) ;
532- //log.debug("LOOKUP", lookup, path.node.type, nodes.map(n => n.node));
531+ //log? .debug("LOOKUP", lookup, path.node.type, nodes.map(n => n.node));
533532 //console.log(nodes);
534533 if ( nodes . length == 0 )
535534 return [ ] ;
@@ -551,7 +550,7 @@ function createQuerier() {
551550 }
552551 startNode = startNode . child ;
553552 }
554- //log.debug("DIRECT TRAV RESOLVE", startNode, paths.map(p => breadCrumb(p)));
553+ //log? .debug("DIRECT TRAV RESOLVE", startNode, paths.map(p => breadCrumb(p)));
555554 const result = [ ] ;
556555 //console.log(paths.length, subQueryCounter);
557556 for ( const path of paths ) {
@@ -569,7 +568,7 @@ function createQuerier() {
569568 }
570569 }
571570 }
572- log . debug ( "DIRECT TRAV RESOLVE RESULT" , result ) ;
571+ log ? .debug ( "DIRECT TRAV RESOLVE RESULT" , result ) ;
573572 return result ;
574573 }
575574 function addResultIfTokenMatch ( fnode , path , state ) {
@@ -626,7 +625,7 @@ function createQuerier() {
626625 resolveFunctionCalls ( fnode , functionCallResult , path , state ) ;
627626 }
628627 else if ( matchingFilters . length > 0 ) {
629- log . debug ( "HAS MATCHING FILTER" , fnode . result . length , matchingFilters . length , breadCrumb ( path ) ) ;
628+ log ? .debug ( "HAS MATCHING FILTER" , fnode . result . length , matchingFilters . length , breadCrumb ( path ) ) ;
630629 fnode . result . push ( ...matchingFilters . flatMap ( f => f . result ) ) ;
631630 }
632631 }
@@ -642,7 +641,7 @@ function createQuerier() {
642641 }
643642 }
644643 const functionResult = exports . functions [ functionCallResult . functionCall . function ] . fn ( parameterResults ) ;
645- log . debug ( "PARAMETER RESULTS" , functionCallResult . functionCall . function , parameterResults , functionResult ) ;
644+ log ? .debug ( "PARAMETER RESULTS" , functionCallResult . functionCall . function , parameterResults , functionResult ) ;
646645 fnode . result . push ( ...functionResult ) ;
647646 }
648647 function travHandle ( queries , root ) {
@@ -663,7 +662,7 @@ function createQuerier() {
663662 state . descendant . slice ( 0 , state . depth + 1 ) . forEach ( fnodes => fnodes . forEach ( fnode => addPrimitiveAttributeIfMatch ( fnode , root ) ) ) ;
664663 traverse ( root . node , {
665664 enter ( path , state ) {
666- //log.debug("ENTER", breadCrumb(path));
665+ //log? .debug("ENTER", breadCrumb(path));
667666 state . depth ++ ;
668667 state . child . push ( [ ] ) ;
669668 state . descendant . push ( [ ] ) ;
@@ -681,7 +680,7 @@ function createQuerier() {
681680 }
682681 } ,
683682 exit ( path , state ) {
684- log . debug ( "EXIT" , breadCrumb ( path ) ) ;
683+ log ? .debug ( "EXIT" , breadCrumb ( path ) ) ;
685684 // Check for attributes as not all attributes are visited
686685 state . child [ state . depth + 1 ] . forEach ( fnode => addPrimitiveAttributeIfMatch ( fnode , path ) ) ;
687686 for ( const fnodes of state . descendant ) {
@@ -730,18 +729,19 @@ function multiQuery(code, namedQueries, returnAST) {
730729 const queries = Object . fromEntries ( Object . entries ( namedQueries ) . map ( ( [ name , query ] ) => [ name , ( 0 , parseQuery_1 . parse ) ( query ) ] ) ) ;
731730 const querier = createQuerier ( ) ;
732731 const result = querier . beginHandle ( queries , ast ) ;
733- log . debug ( "Query time: " , Date . now ( ) - start ) ;
732+ log ? .debug ( "Query time: " , Date . now ( ) - start ) ;
734733 if ( returnAST ) {
735734 return { ...result , __AST : ast } ;
736735 }
737736 return result ;
738737}
739- function parseSource ( source ) {
738+ function parseSource ( source , optimize = true ) {
739+ const parsingOptions = optimize ? { loc : false , ranges : false } : { loc : true , ranges : true } ;
740740 try {
741- return ( 0 , meriyah_1 . parseScript ) ( source , { module : true , next : true } ) ;
741+ return ( 0 , meriyah_1 . parseScript ) ( source , { module : true , next : true , ... parsingOptions } ) ;
742742 }
743743 catch ( e ) {
744- return ( 0 , meriyah_1 . parseScript ) ( source , { module : false , next : true } ) ;
744+ return ( 0 , meriyah_1 . parseScript ) ( source , { module : false , next : true , ... parsingOptions , webcompat : true } ) ;
745745 }
746746}
747747const scopes = new Map ( ) ;
@@ -961,10 +961,10 @@ function createTraverser() {
961961 const fscope = path ?. functionScopeId ?? node . extra ?. functionScopeId ?? scopeId ;
962962 traverseInner ( node , visitor , scopeId , fscope , state , path ) ;
963963 if ( ! sOut . includes ( scopeIdCounter ) ) {
964- log . debug ( "Scopes created" , scopeIdCounter , " Scopes removed" , removedScopes , "Paths created" , pathsCreated , bindingNodesVisited ) ;
964+ log ? .debug ( "Scopes created" , scopeIdCounter , " Scopes removed" , removedScopes , "Paths created" , pathsCreated , bindingNodesVisited ) ;
965965 sOut . push ( scopeIdCounter ) ;
966966 const k = Object . fromEntries ( Object . entries ( nodePathsCreated ) . sort ( ( a , b ) => a [ 1 ] - b [ 1 ] ) ) ;
967- log . debug ( "Node paths created" , k ) ;
967+ log ? .debug ( "Node paths created" , k ) ;
968968 }
969969 }
970970 return {
@@ -1247,12 +1247,11 @@ exports.parse = parse;
12471247const _1 = require ( "." ) ;
12481248const nodeutils_1 = require ( "./nodeutils" ) ;
12491249const debugLogEnabled = false ;
1250- const log = {
1251- debug : debugLogEnabled ? ( ...args ) => {
1252- if ( debugLogEnabled )
1253- console . debug ( ...args ) ;
1254- } : ( ) => { }
1255- } ;
1250+ const log = debugLogEnabled ? {
1251+ debug : ( ...args ) => {
1252+ console . debug ( ...args ) ;
1253+ }
1254+ } : undefined ;
12561255const supportedIdentifiers = Object . fromEntries ( Object . keys ( nodeutils_1 . VISITOR_KEYS ) . map ( k => [ k , k ] ) ) ;
12571256function isIdentifierToken ( token ) {
12581257 if ( token == undefined )
@@ -1393,7 +1392,7 @@ function tokenize(input) {
13931392 return result ;
13941393}
13951394function buildFilter ( tokens ) {
1396- log . debug ( "BUILD FILTER" , tokens ) ;
1395+ log ? .debug ( "BUILD FILTER" , tokens ) ;
13971396 tokens . shift ( ) ;
13981397 const p = buildTree ( tokens ) ;
13991398 const next = tokens [ 0 ] ;
@@ -1440,7 +1439,7 @@ function buildFilter(tokens) {
14401439}
14411440const subNodes = [ "child" , "descendant" ] ;
14421441function buildTree ( tokens ) {
1443- log . debug ( "BUILD TREE" , tokens ) ;
1442+ log ? .debug ( "BUILD TREE" , tokens ) ;
14441443 if ( tokens . length == 0 )
14451444 throw new Error ( "Unexpected end of input" ) ;
14461445 const token = tokens . shift ( ) ;
@@ -1483,7 +1482,7 @@ function buildTree(tokens) {
14831482 let filter = undefined ;
14841483 if ( tokens . length > 0 && tokens [ 0 ] . type == "filterBegin" ) {
14851484 filter = buildFilter ( tokens ) ;
1486- log . debug ( "FILTER" , filter , tokens ) ;
1485+ log ? .debug ( "FILTER" , filter , tokens ) ;
14871486 }
14881487 let child = undefined ;
14891488 if ( tokens . length > 0 && subNodes . includes ( tokens [ 0 ] . type ) ) {
@@ -1510,7 +1509,7 @@ function buildTree(tokens) {
15101509 throw new Error ( "Unexpected token: " + token . type ) ;
15111510}
15121511function buildFunctionCall ( name , tokens ) {
1513- log . debug ( "BUILD FUNCTION" , name , tokens ) ;
1512+ log ? .debug ( "BUILD FUNCTION" , name , tokens ) ;
15141513 const parameters = [ ] ;
15151514 const next = tokens . shift ( ) ;
15161515 if ( next ?. type != "parametersBegin" )
@@ -1532,7 +1531,7 @@ function buildFunctionCall(name, tokens) {
15321531function parse ( input ) {
15331532 const tokens = tokenize ( input ) ;
15341533 const result = buildTree ( tokens ) ;
1535- log . debug ( "RESULT" , result ) ;
1534+ log ? .debug ( "RESULT" , result ) ;
15361535 if ( ! result )
15371536 throw new Error ( "No root element found" ) ;
15381537 return result ;
0 commit comments