Class RewritePolyfills

  • All Implemented Interfaces:
    CompilerPass, HotSwapCompilerPass

    public class RewritePolyfills
    extends java.lang.Object
    implements HotSwapCompilerPass
    Injects polyfill libraries to ensure that ES6+ library functions are available.

    Also runs if polyfill isolation is enabled, even if polyfill injection is disabled, in order to prevent deletion of a required library function by dead code elimination.

    TODO(b/120486392): consider merging this pass with InjectRuntimeLibraries and InjectTranspilationRuntimeLibraries.

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void hotSwapScript​(Node scriptRoot, Node originalRoot)
      Process the JS with root node root.
      void process​(Node externs, Node root)
      Process the JS with root node root.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RewritePolyfills

        public RewritePolyfills​(AbstractCompiler compiler,
                                boolean injectPolyfills,
                                boolean isolatePolyfills)
        Parameters:
        injectPolyfills - if true, injects $jscomp.polyfill initializations into the first input. if false, no polyfills are injected.
        isolatePolyfills - if true, adds externs for library functions used by IsolatePolyfills to prevent their deletion.
    • Method Detail

      • hotSwapScript

        public void hotSwapScript​(Node scriptRoot,
                                  Node originalRoot)
        Description copied from interface: HotSwapCompilerPass
        Process the JS with root node root. This is supposed to be significantly faster compared to corresponding full-compiler passes.
        Specified by:
        hotSwapScript in interface HotSwapCompilerPass
        Parameters:
        scriptRoot - Root node corresponding to the file that is modified, should be of type Token.SCRIPT.
        originalRoot - Root node corresponding to the original version of the file that is modified. Should be of type token.SCRIPT.
      • process

        public void process​(Node externs,
                            Node root)
        Description copied from interface: CompilerPass
        Process the JS with root node root. Can modify the contents of each Node tree
        Specified by:
        process in interface CompilerPass
        Parameters:
        externs - Top of external JS tree
        root - Top of JS tree