'use strict';
const bcd = require('..');

const { argv } = require('yargs').command('$0 <browser> [folder] [value]', 'Test for specified values in any specified browser', (yargs) => {
  yargs.positional('browser', {
    describe: 'The browser to test for',
    type: 'string'
  }).positional('folder', {
    describe: 'The folder(s) to test',
    type: 'array',
    default: ['api', 'css', 'html', 'http', 'svg', 'javascript', 'mathml', 'webdriver', 'xpath', 'xslt']
  }).positional('value', {
    describe: 'The value(s) to test against',
    type: 'array',
    default: ["null", "true"]
  });
});

function traverseFeatures(obj, depth, identifier) {
  depth--;
  if (depth >= 0) {
    for (let i in obj) {
      if (!!obj[i] && typeof(obj[i]) == "object" && i !== '__compat') {
         if (obj[i].__compat) {
           let comp = obj[i].__compat.support;
           let browser = comp[argv.browser];
           if (!Array.isArray(browser)) {
              browser = [browser];
            }
            for (let range in browser) {
              if (browser[range] === undefined) {
                if (values.includes("null")) features.push(`${identifier}${i}`);
              }
             else if (values.includes(String(browser[range].version_added)) ||
                        values.includes(String(browser[range].version_removed))) {
                if (browser[range].prefix) features.push(`${identifier}${i} (${browser[range].prefix} prefix)`);
                else features.push(`${identifier}${i}`);
              }
           }
         }
         traverseFeatures(obj[i], depth, identifier + i + '.');
       }
     }
   }
}

let features = [];
let folders = Array.isArray(argv.folder) ? argv.folder : argv.folder.split(",");
let values = Array.isArray(argv.value) ? argv.value : argv.value.toString().split(",");

for (let folder in folders) traverseFeatures(bcd[folders[folder]], 100, `${folders[folder]}.`);

console.log(features.join("\n"));
console.log(features.length);

@@ -777,25 +777,24 @@
 ) %7B%0A        
- 
 if (obj%5Bi%5D._
@@ -800,25 +800,24 @@
 __compat) %7B%0A
- 
           le
@@ -856,25 +856,24 @@
 ;%0A          
- 
 let browser 
@@ -886,33 +886,32 @@
 %5Bargv.browser%5D;%0A
- 
           if (!A
@@ -947,18 +947,16 @@
         
-  
 browser 
@@ -960,34 +960,32 @@
 er = %5Bbrowser%5D;%0A
-  
           %7D%0A    
@@ -990,18 +990,16 @@
         
-  
 for (let
@@ -1015,26 +1015,24 @@
  browser) %7B%0A
-  
             
@@ -1077,26 +1077,24 @@
             
-  
 if (values.i
@@ -1138,34 +1138,32 @@
 ntifier%7D$%7Bi%7D%60);%0A
-  
             %7D%0A  
@@ -1168,25 +1168,24 @@
             
- 
 else if (val
@@ -1238,19 +1238,16 @@
 ed)) %7C%7C%0A
-   
         
@@ -1324,34 +1324,32 @@
 %7B%0A              
-  
 if (browser%5Brang
@@ -1425,26 +1425,24 @@
  prefix)%60);%0A
-  
             
@@ -1488,37 +1488,34 @@
 %60);%0A            
-  
 %7D%0A
- 
           %7D%0A    
@@ -1510,36 +1510,34 @@
       %7D%0A        
- 
 %7D%0A
- 
         traverse
@@ -1593,19 +1593,16 @@
     
- 
 %7D%0A
- 
     %7D%0A
- 
   %7D%0A

Fix indentation in scripts/traverse.js (#4419)