/** * @testdox reset() clears the stored objects */ public function testReset() { $optimizer = new ConfigOptimizer(new Encoder()); $optimizer->optimize([['xyz'], ['xyz']]); $this->assertNotEmpty($optimizer->getVarDeclarations()); $optimizer->reset(); $this->assertEmpty($optimizer->getVarDeclarations()); }
/** * Get a JavaScript parser * * @param array $config Config array returned by the configurator * @return string JavaScript parser */ public function getParser(array $config = null) { $this->configOptimizer->reset(); // Get the stylesheet used for rendering $this->xsl = (new XSLT())->getXSL($this->configurator->rendering); // Prepare the parser's config $this->config = isset($config) ? $config : $this->configurator->asConfig(); ConfigHelper::filterVariants($this->config, 'JS'); $this->config = $this->callbackGenerator->replaceCallbacks($this->config); // Get the parser's source and inject its config $src = $this->getHints() . $this->injectConfig($this->getSource()); // Export the public API $src .= $this->getExports(); // Minify the source $src = $this->getMinifier()->get($src); // Wrap the source in a function to protect the global scope $src = '(function(){' . $src . '})()'; return $src; }