Compile given JavaScript source via the Closure Compiler Service

@param  string $src JavaScript source
@return string      Compiled source
480325
public function minify($src)
	{
		$body     = $this->generateRequestBody($src);
		$response = $this->query($body);
		if ($response === false)
		{
			throw new RuntimeException('Could not contact the Closure Compiler service');
		}

		return $this->decodeResponse($response);
	}
129017
public static function factory(string $src): Audio
    {
        $audio = new Audio();
        $audio->src = $src;
        return $audio;
    }
841735
private function open_php( &$src ){
		if( ! $this->inphp ){
			$this->inphp = true;
			
			// this may result in back to back tags, which we can avoid with a bit of string manipulation.
			$makenice = $this->opt(COMPILER_OPTION_NICE_TAGS);
			
			if( $makenice && substr( $src, -2 ) === '?>' ){
				// trim trailing close tag, so no need to open one
				$src = substr_replace( $src, '', -2 );
			}
			else {
				$ws = $this->opt(COMPILER_OPTION_WHITESPACE) ? "\n" : ' ';
				$src .= '<?php'.$ws;
			}
		}
		return $src;	
	}
445000
public function script($src, $attributes = [])
    {
        $attributes['type'] = 'text/javascript';
        $attributes['src'] = $src;
        $tag = new Tag('script', $attributes);
        return $tag;
    }
210442
public function embed(string $src){
        if(strtolower(substr($src, 0, 14)) !== "<!doctype html"){
            return $src;
        }

        $src        = $this->getDomDocument($src);
        $debug      = $this->getDomDocument($this->generateDebugHtml());
        $srcPath    = new \DOMXPath($src);
        $debugPath  = new \DOMXPath($debug);

        $headNode   = $srcPath->query("//head")->item(0);
        $bodyNode   = $srcPath->query("//body")->item(0);

        if($headNode !== null && $bodyNode !== null){
            $headNode->appendChild($src->importNode($debugPath->query("//head/style")->item(0), true));
            $bodyNode->appendChild($src->importNode($debugPath->query("//body/div")->item(0), true));
            $bodyNode->appendChild($src->importNode($debugPath->query("//body/script")->item(0), true));
        }

        return $src->saveHTML();
    }
383671
protected function _compileRawEchos($value)
    {
        $pattern = sprintf('/(@)?%s\s*(.+?)\s*%s(\r?\n)?/s', $this->_rawTags[0], $this->_rawTags[1]);

        $callback = function ($matches) {
            $whitespace = empty($matches[3]) ? '' : $matches[3];

            return $matches[1] ? substr($matches[0], 1) : '<?= ' . $this->_compileEchoDefaults($matches[2]) . '; ?>' . $whitespace;
        };

        return preg_replace_callback($pattern, $callback, $value);
    }
556932
function compile($str) {
		return preg_replace_callback(
			'/(?<!\w)@(\w+(?:(?:\->|::)\w+)?)'.
			'((?:\.\w+|\[(?:(?:[^\[\]]*|(?R))*)\]|(?:\->|::)\w+|\()*)/',
			function($expr) {
				$str='$'.$expr[1];
				if (isset($expr[2]))
					$str.=preg_replace_callback(
						'/\.(\w+)(\()?|\[((?:[^\[\]]*|(?R))*)\]/',
						function($sub) {
							if (empty($sub[2])) {
								if (ctype_digit($sub[1]))
									$sub[1]=(int)$sub[1];
								$out='['.
									(isset($sub[3])?
										$this->compile($sub[3]):
										$this->export($sub[1])).
								']';
							}
							else
								$out=function_exists($sub[1])?
									$sub[0]:
									('['.$this->export($sub[1]).']'.$sub[2]);
							return $out;
						},
						$expr[2]
					);
				return $str;
			},
			$str
		);
	}
618479
public function compile(ExpressCompiler $compiler, $flags = 0)
	{
		try
		{
			$helper = $this->getHelper($compiler);
			$field = $compiler->nextField('h');
			
			$compiler->write("\t\t" . 'if(' . $field . ' === NULL) {' . "\n");
			
			$compiler->write("\t\ttry {\n");
			
			$compiler->write("\t\t" . $field . ' = $this->renderer->getHelper(');
			$compiler->write(var_export($this->namespace, true) . ', ' . var_export($this->name, true));
			$compiler->write(");\n");
			$compiler->write("\t\t" . $field . "->bindContext(\$this->context);\n");
			
			$bound = [];
			
			// Setup helper arguments:
			foreach($this->attributes as $attr)
			{
				$name = preg_replace_callback("'-([a-z0-9])'", function(array $m) {
					return strtoupper($m[1]);
				}, $attr->getName());
				
				if(false !== strpos($name, ':'))
				{
					continue;
				}
				
				$dynamic = $attr->isExpressionCallback() || $attr->isDynamic();
				$pass = $helper->isPassthroughAttribute($name);
				
				$bound[$name] = true;
				
				if($pass)
				{
					// Dealing with passthrough attributes.
					
					if($dynamic)
					{
						// Dynamic value passthrough attribute, use ArrayAccess to set compiled closure.
						
						$compiler->write("\t\t" . $field . "[" . var_export($attr->getName(), true));
						$compiler->write("] = function() {\n\t\t\ttry {\n\t\t\treturn ");
						
						$exp = '';
						
						foreach($attr as $i => $sub)
						{
							if($i != 0)
							{
								$compiler->write(' . ');
							}
								
							$compiler->write($sub->compile($compiler, self::FLAG_RAW));
							
							if($sub instanceof ExpressionNode)
							{
								$exp .= $sub->getExpression();
							}
							elseif($sub instanceof TextNode)
							{
								$exp .= $sub->getText();
							}
						}
						
						$compiler->write(";\n\t\t\t} catch(\ExpressViewException \$ex) {\n");
						$compiler->write("\t\t\t\tthrow \$ex;\n");
						$compiler->write("\t\t\t} catch(\Exception \$ex) {\n");
						$compiler->write("\t\t\t\tthrow new ExpressViewException(");
						$compiler->write(var_export(sprintf('Unable to evaluate attribute "%s" in view helper "%s" using expression "%s"', $name, $this->namespace . ':' . $this->name, $exp), true));
						$compiler->write(", \$this->getResource(), {$this->line}, \$ex);\n");
						$compiler->write("\t\t\t}\n\t\t};\n");
					}
					else
					{
						// Static passthrough attribute.
						
						$sub = $compiler->createCompiler();
						$attr->compile($sub);
						
						$compiler->write("\t\t" . $field . "[" . var_export($attr->getName(), true));
						$compiler->write("] = " . var_export($sub->getOutputBuffer(), true) . ";\n");
					}
				}
				else
				{
					if($dynamic)
					{
						// Dynamic and expression attributes are assembled into a string and returned:
					
						$compiler->write("\t\t" . $field . '->setAttr(' . var_export($name, true));
						$compiler->write(", function(\$inspect = false) {\n\t\t\ttry {\n\t\t\treturn ");
					
						$childNodes = iterator_to_array($attr->getIterator());
						$inspectable = false;
						$exp = '';
						
						if(count($childNodes) == 1)
						{
							if($childNodes[0] instanceof ExpressionNode)
							{
								$chain = $childNodes[0]->getExpression()->getNode();
								
								if($chain instanceof AccessorChain)
								{
									$inspectable = true;
								}
							}
						}
						
						if($inspectable)
						{
							$compiler->write('$inspect ? ');
							$compiler->write($chain->compile($compiler->getExpressionContextFactory(), '$this->exp', 'inspectValue'));
							$compiler->write(' : ');
							$compiler->write($chain->compile($compiler->getExpressionContextFactory(), '$this->exp'));
							
							$exp .= $childNodes[0]->getExpression();
						}
						else
						{
							foreach($childNodes as $i => $sub)
							{
								if($i != 0)
								{
									$compiler->write(' . ');
								}
									
								$compiler->write($sub->compile($compiler, self::FLAG_RAW));
								
								if($sub instanceof ExpressionNode)
								{
									$exp .= $sub->getExpression();
								}
								elseif($sub instanceof TextNode)
								{
									$exp .= $sub->getText();
								}
							}
						}
						
						$compiler->write(";\n\t\t\t} catch(\ExpressViewException \$ex) {\n");
						$compiler->write("\t\t\t\tthrow \$ex;\n");
						$compiler->write("\t\t\t} catch(\Exception \$ex) {\n");
						$compiler->write("\t\t\t\tthrow new ExpressViewException(");
						$compiler->write(var_export(sprintf('Unable to evaluate attribute "%s" in view helper "%s" using expression "%s"', $name, $this->namespace . ':' . $this->name, $exp), true));
						$compiler->write(", \$this->getResource(), {$this->line}, \$ex);\n");
						$compiler->write("\t\t\t}\n\t\t});\n");
					}
					else
					{
						// Static attributes are set as property values:
					
						$sub = $compiler->createCompiler();
						$attr->compile($sub);
					
						$compiler->write("\t\t" . $field . '->' . $name . ' = ');
						$compiler->write(var_export($sub->getOutputBuffer(), true) . ";\n");
					}
				}
			}
			
			$compiler->write("\t\t" . $field . "->bindAttr([");
			
			foreach(array_keys($bound) as $i => $key)
			{
				if($i != 0)
				{
					$compiler->write(', ');
				}
				
				$compiler->write(var_export($key, true) . ' => true');
			}
	
			$compiler->write("]);\n");
			
			if(!empty($this->childNodes))
			{
				if($helper instanceof CompositeViewHelperInterface)
				{
					$helpers = [];
	
					foreach($this->childNodes as $node)
					{
						if(!$node instanceof HelperNode)
						{
							continue;
						}
						
						$helpers[] = $node->compile($compiler, self::FLAG_NO_OUTPUT);
					}
					
					$compiler->write("\t\t" . $field . '->setNestedNodes([' . "\n");
					$compiler->write("\t\t" . implode(', ', $helpers) . "\n");
					$compiler->write("\t\t]);\n");
				}
				else
				{
					$compiler->write("\t\t" . $field . '->setNestedNodes([function(OutputBuffer $out) {' . "\n");
					
					foreach($this->childNodes as $node)
					{
						$node->compile($compiler);
					}
					
					$compiler->write("\n\t\t}]);\n");
				}
			}
			
			$compiler->write("\t\t} catch(ExpressViewException \$ex) {\n");
			$compiler->write("\t\t\tthrow \$ex;\n");
			$compiler->write("\t\t} catch(\\Exception \$ex) {\n");
			$compiler->write("\t\t\tthrow new ExpressViewException(");
			$compiler->write(var_export('Unable to instantiate view helper "' . $this->namespace . ':' . $this->name . '"', true));
			$compiler->write(", \$this->getResource(), {$this->line}, \$ex);\n");
			$compiler->write("\t\t}\n");
			
			$compiler->write("\t\t}\n");
			
			if(!($flags & self::FLAG_NO_OUTPUT))
			{
				$compiler->write("\t\ttry {\n");
				$compiler->write("\t\t" . $field . '->__invoke($out);' . "\n");
				$compiler->write("\t\t} catch(ExpressViewException \$ex) {\n");
				$compiler->write("\t\t\tthrow \$ex;\n");
				$compiler->write("\t\t} catch(\\Exception \$ex) {\n");
				$compiler->write("\t\t\tthrow new ExpressViewException(");
				$compiler->write(var_export('Unable to invoke view helper "' . $this->namespace . ':' . $this->name . '"', true));
				$compiler->write(", \$this->getResource(), {$this->line}, \$ex);\n");
				$compiler->write("\t\t}\n");
			}
			
			return $field;
		}
		catch(ExpressViewException $e)
		{
			throw $e;
		}
		catch(\Exception $e)
		{
			throw new ExpressViewException(sprintf('Unable to compile view helper "%s" in namespace "%s"', $this->name, $this->namespace), $compiler->getResource(), $this->line, $e);
		}
	}
629053
@EnsuresNonNull("fn")
  private Function getCompiledScript()
  {
    // JavaScript configuration should be checked when it's actually used because someone might still want Druid
    // nodes to be able to deserialize JavaScript-based objects even though JavaScript is disabled.
    Preconditions.checkState(config.isEnabled(), "JavaScript is disabled");

    Function syncedFn = fn;
    if (syncedFn == null) {
      synchronized (config) {
        syncedFn = fn;
        if (syncedFn == null) {
          syncedFn = compile(function);
          fn = syncedFn;
        }
      }
    }
    return syncedFn;
  }
357043
public function create_simple_html_dom( $src ){
		// Simple HTML DOM
		$simple_html_dom = str_get_html(
			$src ,
			true, // $lowercase
			true, // $forceTagsClosed
			DEFAULT_TARGET_CHARSET, // $target_charset
			false, // $stripRN
			DEFAULT_BR_TEXT, // $defaultBRText
			DEFAULT_SPAN_TEXT // $defaultSpanText
		);
		return $simple_html_dom;
	}
466779
public static function compile(Compiler $compiler, array $rest = array())
    {
        $out = array();
        foreach ($rest as $key => $value) {
            if (!is_numeric($key) && !strstr($key, '$this->scope')) {
                $key = "'" . $key . "'";
            }
            $out[] = $key . '=>' . $value;
        }

        return 'array(' . implode(', ', $out) . ')';
    }
573487
public function compileSource($source)
    {
        $result = false;

        $compiler = $this->getCompiler();
        if(is_callable($compiler)) {
            $result = call_user_func($compiler, $source);
        }

        if(!is_string($result)) {
            throw new \RuntimeException(sprintf('The template content cannot be compiled.'));
        }

        return $result;
    }
977981
public function compile($args, $compiler)
    {
        static $_is_legal_scope = array('local' => true, 'parent' => true, 'root' => true, 'global' => true);
        // check and get attributes
        $_attr = $this->getAttributes($compiler, $args);

        if ($_attr['nocache'] === true) {
            $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
        }

        // save possible attributes
        $conf_file = $_attr['file'];
        if (isset($_attr['section'])) {
            $section = $_attr['section'];
        } else {
            $section = 'null';
        }
        $scope = 'local';
        // scope setup
        if (isset($_attr['scope'])) {
            $_attr['scope'] = trim($_attr['scope'], "'\"");
            if (isset($_is_legal_scope[$_attr['scope']])) {
                $scope = $_attr['scope'];
            } else {
                $compiler->trigger_template_error('illegal value for "scope" attribute', $compiler->lex->taglineno);
            }
        }
        // create config object
        $_output = "<?php  \$_config = new Smarty_Internal_Config($conf_file, \$_smarty_tpl->smarty, \$_smarty_tpl);";
        $_output .= "\$_config->loadConfigVars($section, '$scope'); ?>";

        return $_output;
    }
919720
private function build_src( $src ) {
		if ( ! preg_match( '/^(https?:)?\/\//u', $src ) ) {
			// O.K. This is a library in WPametu!
			$src = trailingslashit( $this->get_root_uri() ) . ltrim( $src, '/' );
		}

		return $src;
	}
844619
public function minify($src)
	{
		$options = ($this->options) ? ' ' . $this->options : '';

		// Add our custom externs if default externs are disabled
		if ($this->excludeDefaultExterns && $this->compilationLevel === 'ADVANCED_OPTIMIZATIONS')
		{
			$options .= ' --externs ' . __DIR__ . '/../externs.application.js --env=CUSTOM';
		}

		$crc     = crc32($src);
		$inFile  = sys_get_temp_dir() . '/' . $crc . '.js';
		$outFile = sys_get_temp_dir() . '/' . $crc . '.min.js';
		file_put_contents($inFile, $src);

		$cmd = $this->command
		     . ' --compilation_level ' . escapeshellarg($this->compilationLevel)
		     . $options
		     . ' --js ' . escapeshellarg($inFile)
		     . ' --js_output_file ' . escapeshellarg($outFile);

		exec($cmd . ' 2>&1', $output, $return);
		unlink($inFile);

		if (file_exists($outFile))
		{
			$src = trim(file_get_contents($outFile));
			unlink($outFile);
		}

		if (!empty($return))
		{
			throw new RuntimeException('An error occured during minification: ' . implode("\n", $output));
		}

		return $src;
	}
1112466
public function compile($args, $compiler)
    {
        // check and get attributes
        $_attr = $this->getAttributes($compiler, $args);
        // save possible attributes
        if (isset($_attr['assign'])) {
            // output will be stored in a smarty variable instead of being displayed
            $_assign = $_attr['assign'];
        }
        $_name = $_attr['name'];
        if ($compiler->compiles_template_function) {
            $compiler->called_functions[] = trim($_name, "'\"");
        }
        unset($_attr['name'], $_attr['assign'], $_attr['nocache']);
        // set flag (compiled code of {function} must be included in cache file
        if ($compiler->nocache || $compiler->tag_nocache) {
            $_nocache = 'true';
        } else {
            $_nocache = 'false';
        }
        $_paramsArray = array();
        foreach ($_attr as $_key => $_value) {
            if (is_int($_key)) {
                $_paramsArray[] = "$_key=>$_value";
            } else {
                $_paramsArray[] = "'$_key'=>$_value";
            }
        }
        if (isset($compiler->template->properties['function'][$_name]['parameter'])) {
            foreach ($compiler->template->properties['function'][$_name]['parameter'] as $_key => $_value) {
                if (!isset($_attr[$_key])) {
                    if (is_int($_key)) {
                        $_paramsArray[] = "$_key=>$_value";
                    } else {
                        $_paramsArray[] = "'$_key'=>$_value";
                    }
                }
            }
        } elseif (isset($compiler->smarty->template_functions[$_name]['parameter'])) {
            foreach ($compiler->smarty->template_functions[$_name]['parameter'] as $_key => $_value) {
                if (!isset($_attr[$_key])) {
                    if (is_int($_key)) {
                        $_paramsArray[] = "$_key=>$_value";
                    } else {
                        $_paramsArray[] = "'$_key'=>$_value";
                    }
                }
            }
        }
        //variable name?
        if (!(strpos($_name, '$') === false)) {
            $call_cache = $_name;
            $call_function = '$tmp = "smarty_template_function_".' . $_name . '; $tmp';
        } else {
            $_name = trim($_name, "'\"");
            $call_cache = "'{$_name}'";
            $call_function = 'smarty_template_function_' . $_name;
        }

        $_params = 'array(' . implode(",", $_paramsArray) . ')';
        $_hash = str_replace('-', '_', $compiler->template->properties['nocache_hash']);
        // was there an assign attribute
        if (isset($_assign)) {
            if ($compiler->template->caching) {
                $_output = "<?php ob_start(); Smarty_Internal_Function_Call_Handler::call ({$call_cache},\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
            } else {
                $_output = "<?php ob_start(); {$call_function}(\$_smarty_tpl,{$_params}); \$_smarty_tpl->assign({$_assign}, ob_get_clean());?>\n";
            }
        } else {
            if ($compiler->template->caching) {
                $_output = "<?php Smarty_Internal_Function_Call_Handler::call ({$call_cache},\$_smarty_tpl,{$_params},'{$_hash}',{$_nocache});?>\n";
            } else {
                $_output = "<?php {$call_function}(\$_smarty_tpl,{$_params});?>\n";
            }
        }

        return $_output;
    }
1060818
public function compile($args, $compiler)
    {
        // check and get attributes
        $_attr = $this->getAttributes($compiler, $args);
        if ($_attr['nocache'] === true) {
            $compiler->trigger_template_error('nocache option not allowed', $compiler->lex->taglineno);
        }
        if (strpos($_attr['file'], '$_tmp') !== false) {
            $compiler->trigger_template_error('illegal value for file attribute', $compiler->lex->taglineno);
        }

        $name = $_attr['file'];
        /** @var Smarty_Internal_Template $_smarty_tpl
         * used in evaluated code
         */
        $_smarty_tpl = $compiler->template;
        eval("\$tpl_name = $name;");
        // create template object
        $_template = new $compiler->smarty->template_class($tpl_name, $compiler->smarty, $compiler->template);
        // check for recursion
        $uid = $_template->source->uid;
        if (isset($compiler->extends_uid[$uid])) {
            $compiler->trigger_template_error("illegal recursive call of \"$include_file\"", $compiler->lex->line - 1);
        }
        $compiler->extends_uid[$uid] = true;
        if (empty($_template->source->components)) {
            array_unshift($compiler->sources, $_template->source);
        } else {
            foreach ($_template->source->components as $source) {
                array_unshift($compiler->sources, $source);
                $uid = $source->uid;
                if (isset($compiler->extends_uid[$uid])) {
                    $compiler->trigger_template_error("illegal recursive call of \"{$source->filepath}\"", $compiler->lex->line - 1);
                }
                $compiler->extends_uid[$uid] = true;
            }
        }
        unset ($_template);
        $compiler->inheritance_child = true;
        $compiler->lex->yypushstate(Smarty_Internal_Templatelexer::CHILDBODY);
        return '';
    }