From 06217b2f2fee492aa83af4b3429d4e647589733a Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 11 Jul 2011 21:09:45 +0000 Subject: [PATCH] Add jsparse.php maintenance script to run given JavaScript files through JSMin+'s JS parser for syntax validity checks. This also confirms JSMin+'s fairly abysmal memory usage on large complex files. :) Pass --memory-limit to set to arbitrary values to see where it dies on your file. ;) --- maintenance/jsparse.php | 72 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 maintenance/jsparse.php diff --git a/maintenance/jsparse.php b/maintenance/jsparse.php new file mode 100644 index 0000000000..ae6f1f1db0 --- /dev/null +++ b/maintenance/jsparse.php @@ -0,0 +1,72 @@ +mDescription = "Runs parsing/syntax checks on JavaScript files"; + $this->addArg( 'file(s)', 'JavaScript file to test', false ); + } + + public function execute() { + $iterations = $this->getOption( 'i', 100 ); + if ( $this->hasArg() ) { + $files = $this->mArgs; + } else { + $this->maybeHelp( true ); // @fixme this is a lame API :) + exit( 1 ); // it should exit from the above first... + } + + $parser = new JSParser(); + foreach ( $files as $filename ) { + wfSuppressWarnings(); + $js = file_get_contents( $filename ); + wfRestoreWarnings(); + if ($js === false) { + $this->output( "$filename ERROR: could not read file\n" ); + $this->errs++; + continue; + } + + try { + $parser->parse( $js, $filename, 1 ); + } catch (Exception $e) { + $this->errs++; + $this->output( "$filename ERROR: " . $e->getMessage() . "\n" ); + continue; + } + + $this->output( "$filename OK\n" ); + } + + if ($this->errs > 0) { + exit(1); + } + } +} + +$maintClass = "JSParseHelper"; +require_once( RUN_MAINTENANCE_IF_MAIN ); -- 2.20.1