Skip to content

Commit

Permalink
Reminimization of Closure 156
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg4cr committed Feb 14, 2019
1 parent 8d5946f commit 7b53dc2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 333 deletions.
341 changes: 8 additions & 333 deletions framework/projects/Closure/patches/156.src.patch
@@ -1,295 +1,8 @@
diff --git a/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java b/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java
index c4b47104..852da8de 100644
--- a/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java
+++ b/src/com/google/javascript/jscomp/AbstractCommandLineRunner.java
@@ -27,14 +27,11 @@ import com.google.javascript.rhino.Node;
import com.google.javascript.rhino.TokenStream;
import com.google.protobuf.CodedOutputStream;

-import java.io.BufferedWriter;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
-import java.io.FileWriter;
import java.io.IOException;
-import java.io.OutputStreamWriter;
import java.io.PrintStream;
-import java.io.Writer;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
@@ -83,7 +80,7 @@ abstract class AbstractCommandLineRunner<A extends Compiler,

private final CommandLineConfig config;

- private Appendable out;
+ private PrintStream out;
private final PrintStream err;
private A compiler;

@@ -423,26 +420,27 @@ abstract class AbstractCommandLineRunner<A extends Compiler,
* Writes code to an output stream, optionally wrapping it in an arbitrary
* wrapper that contains a placeholder where the code should be inserted.
*/
- static void writeOutput(Appendable out, Compiler compiler, String code,
- String wrapper, String codePlaceholder) throws IOException {
+ static void writeOutput(PrintStream out, Compiler compiler, String code,
+ String wrapper, String codePlaceholder) {
int pos = wrapper.indexOf(codePlaceholder);
if (pos != -1) {
String prefix = "";

if (pos > 0) {
prefix = wrapper.substring(0, pos);
- out.append(prefix);
+ out.print(prefix);
}

- out.append(code);
+ out.print(code);

int suffixStart = pos + codePlaceholder.length();
- if (suffixStart != wrapper.length()) {
- // Something after placeholder?
- out.append(wrapper.substring(suffixStart));
+ if (suffixStart == wrapper.length()) {
+ // Nothing after placeholder?
+ // Make sure we always end output with a line feed.
+ out.println();
+ } else {
+ out.println(wrapper.substring(suffixStart));
}
- // Make sure we always end output with a line feed.
- out.append('\n');

// If we have a source map, adjust its offsets to match
// the code WITHIN the wrapper.
@@ -451,8 +449,7 @@ abstract class AbstractCommandLineRunner<A extends Compiler,
}

} else {
- out.append(code);
- out.append('\n');
+ out.println(code);
}
}

@@ -504,7 +501,7 @@ abstract class AbstractCommandLineRunner<A extends Compiler,

boolean writeOutputToFile = !options.jsOutputFile.isEmpty();
if (writeOutputToFile) {
- out = toWriter(options.jsOutputFile, inputCharset.name());
+ out = toPrintStream(options.jsOutputFile, inputCharset.name());
}

List<String> jsFiles = config.js;
@@ -522,7 +519,7 @@ abstract class AbstractCommandLineRunner<A extends Compiler,
int errCode = processResults(result, modules, options);
// Close the output if we are writing to a file.
if (writeOutputToFile) {
- ((Writer)out).close();
+ out.close();
}
return errCode;
}
@@ -541,7 +538,7 @@ abstract class AbstractCommandLineRunner<A extends Compiler,
return 1;
} else {
out.append(DotFormatter.toDot(compiler.getPassConfig().getPassGraph()));
- out.append('\n');
+ out.println();
return 0;
}
}
@@ -552,18 +549,18 @@ abstract class AbstractCommandLineRunner<A extends Compiler,
} else {
ControlFlowGraph<Node> cfg = compiler.computeCFG();
DotFormatter.appendDot(compiler.getRoot(), cfg, out);
- out.append('\n');
+ out.println();
return 0;
}
}

if (config.printTree) {
if (compiler.getRoot() == null) {
- out.append("Code contains errors; no tree was generated.\n");
+ out.println("Code contains errors; no tree was generated.");
return 1;
} else {
compiler.getRoot().appendStringTree(out);
- out.append("\n");
+ out.println("");
return 0;
}
}
@@ -584,32 +581,32 @@ abstract class AbstractCommandLineRunner<A extends Compiler,
// If the source map path is in fact a pattern for each
// module, create a stream per-module. Otherwise, create
// a single source map.
- Writer mapOut = null;
+ PrintStream mapOut = null;

if (!shouldGenerateMapPerModule(options)) {
- mapOut = toWriter(expandSourceMapPath(options, null));
+ mapOut = toPrintStream(expandSourceMapPath(options, null));
}

for (JSModule m : modules) {
if (shouldGenerateMapPerModule(options)) {
- mapOut = toWriter(expandSourceMapPath(options, m));
+ mapOut = toPrintStream(expandSourceMapPath(options, m));
}

- Writer writer = toWriter(
+ PrintStream ps = toPrintStream(
moduleFilePrefix + m.getName() + ".js");

if (options.sourceMapOutputPath != null) {
compiler.getSourceMap().reset();
}

- writeOutput(writer, compiler, compiler.toSource(m), moduleWrappers.get(
+ writeOutput(ps, compiler, compiler.toSource(m), moduleWrappers.get(
m.getName()), "%s");

if (options.sourceMapOutputPath != null) {
compiler.getSourceMap().appendTo(mapOut, m.getName());
}

- writer.close();
+ ps.close();

if (shouldGenerateMapPerModule(options) && mapOut != null) {
mapOut.close();
@@ -624,7 +621,7 @@ abstract class AbstractCommandLineRunner<A extends Compiler,

// Output the externs if required.
if (options.externExportsPath != null) {
- Writer eeOut =
+ PrintStream eeOut =
openExternExportsStream(options, options.jsOutputFile);
eeOut.append(result.externExport);
eeOut.close();
@@ -682,7 +679,7 @@ abstract class AbstractCommandLineRunner<A extends Compiler,
*
* @return The stream or null if no extern-ed exports are being generated.
*/
- private Writer openExternExportsStream(B options,
+ private PrintStream openExternExportsStream(B options,
String path) throws IOException {
if (options.externExportsPath == null) {
return null;
@@ -695,7 +692,7 @@ abstract class AbstractCommandLineRunner<A extends Compiler,
exPath = outputFile.getParent() + File.separatorChar + exPath;
}

- return toWriter(exPath);
+ return toPrintStream(exPath);
}

/**
@@ -744,29 +741,30 @@ abstract class AbstractCommandLineRunner<A extends Compiler,
}

/**
- * Converts a file name into a Writer.
+ * Converts a file name into a print stream.
* Returns null if the file name is null.
*/
- private Writer toWriter(String fileName) throws IOException {
+ private PrintStream toPrintStream(String fileName) throws IOException {
if (fileName == null) {
return null;
}
- // Use a FileWriter if the charset translation isn't required.
- return new BufferedWriter(new FileWriter(fileName));
+ return new PrintStream(
+ new BufferedOutputStream(
+ new FileOutputStream(fileName)), false);
}

/**
- * Converts a file name into a Writer.
+ * Coverts a file name into a print stream.
* Returns null if the file name is null.
*/
- private Writer toWriter(String fileName, String charSet)
+ private PrintStream toPrintStream(String fileName, String charSet)
throws IOException {
if (fileName == null) {
return null;
}
- // Use a FileOutputStream for a non-default charset.
- return new BufferedWriter(
- new OutputStreamWriter(new FileOutputStream(fileName), charSet));
+ return new PrintStream(
+ new BufferedOutputStream(
+ new FileOutputStream(fileName)), false, charSet);
}

/**
@@ -782,7 +780,7 @@ abstract class AbstractCommandLineRunner<A extends Compiler,
}

String outName = expandSourceMapPath(options, null);
- Writer out = toWriter(outName);
+ PrintStream out = toPrintStream(outName);
compiler.getSourceMap().appendTo(out, outName);
out.close();
}
@@ -971,13 +969,13 @@ abstract class AbstractCommandLineRunner<A extends Compiler,
// Generate per-module manifests.
Iterable<JSModule> modules = graph.getAllModules();
for (JSModule module : modules) {
- Writer out = toWriter(expandManifest(module));
+ PrintStream out = toPrintStream(expandManifest(module));
printManifestTo(module.getInputs(), out);
out.close();
}
} else {
// Generate a single file manifest.
- Writer out = toWriter(expandManifest(null));
+ PrintStream out = toPrintStream(expandManifest(null));
if (graph == null) {
printManifestTo(compiler.getInputsInOrder(), out);
} else {
@@ -1057,17 +1055,13 @@ abstract class AbstractCommandLineRunner<A extends Compiler,
* Print the best phase loop to stderr.
*/
private void outputBestPhaseOrdering() {
- try {
- out.append("Best time: " + bestRunTime + "\n");
- out.append("Worst time: " + worstRunTime + "\n");
+ out.println("Best time: " + bestRunTime);
+ out.println("Worst time: " + worstRunTime);

- int i = 1;
- for (List<String> loop : loopedPassesInBestRun) {
- out.append("\nLoop " + i + ":\n" + Joiner.on("\n").join(loop)+ "\n");
- i++;
- }
- } catch (IOException e) {
- throw new RuntimeException("unexpected exception", e);
+ int i = 1;
+ for (List<String> loop : loopedPassesInBestRun) {
+ out.println("\nLoop " + i + ":\n" + Joiner.on("\n").join(loop));
+ i++;
}
}
}
diff --git a/src/com/google/javascript/jscomp/CheckGlobalThis.java b/src/com/google/javascript/jscomp/CheckGlobalThis.java
index 604526e6..514f19e1 100644
index 604526e6..d63c72b1 100644
--- a/src/com/google/javascript/jscomp/CheckGlobalThis.java
+++ b/src/com/google/javascript/jscomp/CheckGlobalThis.java
@@ -99,14 +99,12 @@ final class CheckGlobalThis implements Callback {
// be able to have a @this annotation associated with them. e.g.,
// var a = function() { }; // or
// function a() {} // or
- // a.x = function() {}; // or
- // var a = {x: function() {}};
+ // a.x = function() {};
int pType = parent.getType();
@@ -105,8 +105,7 @@ final class CheckGlobalThis implements Callback {
if (!(pType == Token.BLOCK ||
pType == Token.SCRIPT ||
pType == Token.NAME ||
Expand All @@ -302,60 +15,22 @@ index 604526e6..514f19e1 100644
diff --git a/src/com/google/javascript/jscomp/CrossModuleCodeMotion.java b/src/com/google/javascript/jscomp/CrossModuleCodeMotion.java
old mode 100755
new mode 100644
diff --git a/src/com/google/javascript/jscomp/DefaultPassConfig.java b/src/com/google/javascript/jscomp/DefaultPassConfig.java
index 622fad0f..22b15c93 100644
--- a/src/com/google/javascript/jscomp/DefaultPassConfig.java
+++ b/src/com/google/javascript/jscomp/DefaultPassConfig.java
@@ -862,7 +862,7 @@ public class DefaultPassConfig extends PassConfig {
};

/** Various peephole optimizations. */
- private final PassFactory peepholeOptimizations =
+ static final PassFactory peepholeOptimizations =
new PassFactory("peepholeOptimizations", false) {
@Override
protected CompilerPass createInternal(AbstractCompiler compiler) {
diff --git a/src/com/google/javascript/jscomp/RuntimeTypeCheck.java b/src/com/google/javascript/jscomp/RuntimeTypeCheck.java
index 5cedf1e0..509453c2 100644
index 5cedf1e0..ed4a6b9a 100644
--- a/src/com/google/javascript/jscomp/RuntimeTypeCheck.java
+++ b/src/com/google/javascript/jscomp/RuntimeTypeCheck.java
@@ -240,16 +240,7 @@ class RuntimeTypeCheck implements CompilerPass {
FunctionType funType = (FunctionType) n.getJSType();
Node block = n.getLastChild();
Node paramName = NodeUtil.getFnParameters(n).getFirstChild();
- Node insertionPoint = null;
-
- // To satisfy normalization constraints, the type checking must be
- // added after any inner function declarations.
@@ -244,11 +244,6 @@ class RuntimeTypeCheck implements CompilerPass {

// To satisfy normalization constraints, the type checking must be
// added after any inner function declarations.
- for (Node next = block.getFirstChild();
- next != null && NodeUtil.isFunctionDeclaration(next);
- next = next.getNext()) {
- insertionPoint = next;
- }
-
+ Node prev = null;

for (Node paramType : funType.getParameters()) {
// Can this ever happen?
if (paramName == null) {
@@ -266,15 +257,15 @@ class RuntimeTypeCheck implements CompilerPass {
}

checkNode = new Node(Token.EXPR_RESULT, checkNode);
- if (insertionPoint == null) {
+ if (prev == null) {
block.addChildToFront(checkNode);
} else {
- block.addChildAfter(checkNode, insertionPoint);
+ block.addChildAfter(checkNode, prev);
}

compiler.reportCodeChange();
paramName = paramName.getNext();
- insertionPoint = checkNode;
+ prev = checkNode;
}
}

diff --git a/src/com/google/javascript/jscomp/SourceInformationAnnotator.java b/src/com/google/javascript/jscomp/SourceInformationAnnotator.java
old mode 100755
new mode 100644
Expand Down
6 changes: 6 additions & 0 deletions framework/projects/Closure/trigger_tests/156
Expand Up @@ -21,6 +21,8 @@ junit.framework.AssertionFailedError: There should be one error. expected:<1> b
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:520)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:1484)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:872)
Expand Down Expand Up @@ -66,6 +68,8 @@ junit.framework.AssertionFailedError: There should be one error. expected:<1> b
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:520)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:1484)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:872)
Expand Down Expand Up @@ -2183,6 +2187,8 @@ Subtree2: EXPR_RESULT
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:520)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.executeInVM(JUnitTask.java:1484)
at org.apache.tools.ant.taskdefs.optional.junit.JUnitTask.execute(JUnitTask.java:872)
Expand Down

0 comments on commit 7b53dc2

Please sign in to comment.