static class RewritePolyfills.Polyfills.Builder
extends java.lang.Object
RewritePolyfills.Polyfills
object by calling
addStatics(com.google.javascript.jscomp.parsing.parser.FeatureSet, com.google.javascript.jscomp.parsing.parser.FeatureSet, java.lang.String, java.lang.String, java.lang.String...)
, addMethods(com.google.javascript.jscomp.parsing.parser.FeatureSet, com.google.javascript.jscomp.parsing.parser.FeatureSet, java.lang.String, java.lang.String...)
, and addClasses(com.google.javascript.jscomp.parsing.parser.FeatureSet, com.google.javascript.jscomp.parsing.parser.FeatureSet, java.lang.String, java.lang.String...)
to register the various polyfills and provide information about
the native and polyfilled versions, and how to use the polyfills.Modifier and Type | Field and Description |
---|---|
private com.google.common.collect.ImmutableMultimap.Builder<java.lang.String,RewritePolyfills.Polyfill> |
methodsBuilder |
private com.google.common.collect.ImmutableMap.Builder<java.lang.String,RewritePolyfills.Polyfill> |
staticsBuilder |
Constructor and Description |
---|
Builder() |
Modifier and Type | Method and Description |
---|---|
(package private) RewritePolyfills.Polyfills.Builder |
addClasses(FeatureSet nativeVersion,
FeatureSet polyfillVersion,
java.lang.String base,
java.lang.String... classes)
Registers one or more class polyfill.
|
(package private) RewritePolyfills.Polyfills.Builder |
addMethods(FeatureSet nativeVersion,
FeatureSet polyfillVersion,
java.lang.String base,
java.lang.String... methods)
Registers one or more prototype method in a single namespace.
|
(package private) RewritePolyfills.Polyfills.Builder |
addStatics(FeatureSet nativeVersion,
FeatureSet polyfillVersion,
java.lang.String polyfillBase,
java.lang.String nativeBase,
java.lang.String... statics)
Registers one or more static rewrite polyfill, which is a
simple rewrite of one qualified name to another.
|
(package private) RewritePolyfills.Polyfills |
build()
Builds the
RewritePolyfills.Polyfills . |
private final com.google.common.collect.ImmutableMultimap.Builder<java.lang.String,RewritePolyfills.Polyfill> methodsBuilder
private final com.google.common.collect.ImmutableMap.Builder<java.lang.String,RewritePolyfills.Polyfill> staticsBuilder
RewritePolyfills.Polyfills.Builder addMethods(FeatureSet nativeVersion, FeatureSet polyfillVersion, java.lang.String base, java.lang.String... methods)
base
parameter specifies the
qualified namespace where all the methods
reside. Each
method is expected to have a sibling named with the $install
suffix. The method calls themselves are not rewritten, but
whenever one is detected, its installer(s) will be added to the
top of the source file whenever the output version is less than
nativeVersion
. For example, defining addMethods(ES6, ES5, "$jscomp.string", "startsWith", "endsWith")
will cause $jscomp.string.startsWith$install();
to be
added to any source file that calls, e.g. foo.startsWith
.
If base
is blank, then no polyfills will be installed.
This is useful for documenting unimplemented polyfills.
RewritePolyfills.Polyfills.Builder addStatics(FeatureSet nativeVersion, FeatureSet polyfillVersion, java.lang.String polyfillBase, java.lang.String nativeBase, java.lang.String... statics)
name
in statics
, nativeBase + '.' + name
will be replaced with polyfillBase + '.' + name
whenever the output version is less than nativeVersion
.
For eaxmple, defining addStatics(ES6, ES5, "$jscomp.math", "Math", "clz32", "imul")
will cause Math.clz32
to be rewritten as
$jscomp.math.clz32
.
If polyfillBase
is blank, then no polyfills will be
installed. This is useful for documenting unimplemented polyfills,
and will trigger a warning if the language output mode is less than
the native version.
RewritePolyfills.Polyfills.Builder addClasses(FeatureSet nativeVersion, FeatureSet polyfillVersion, java.lang.String base, java.lang.String... classes)
base
parameter is a qualified name prefix
added to the class name to get the polyfill's name.
A sibling method with the $install
suffix should
also be present.
For example, defining addClasses(ES6, ES5, "$jscomp", "Map", "Set")
will cause new Map()
to be rewritten as
new $jscomp.Map()
and will insert $jscomp.Map$install();
at the top of the source
file whenever the output version is less than
nativeVersion
.
If base
is blank, then no polyfills will be
installed. This is useful for documenting unimplemented
polyfills, and will trigger a warning if the language
output mode is less than the native version.
RewritePolyfills.Polyfills build()
RewritePolyfills.Polyfills
.