Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Unified Diff: compiler/javatests/com/google/dart/compiler/backend/js/analysis/TreeShakerTest.java

Issue 8676041: JS tree shaking for incremental builds. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: DartCompilerWarmup doesn't write files ending in *.app.js* Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: compiler/javatests/com/google/dart/compiler/backend/js/analysis/TreeShakerTest.java
diff --git a/compiler/javatests/com/google/dart/compiler/backend/js/analysis/TreeShakerTest.java b/compiler/javatests/com/google/dart/compiler/backend/js/analysis/TreeShakerTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..543ca4fa9f29940d084daa5a3e2458d9612ec369
--- /dev/null
+++ b/compiler/javatests/com/google/dart/compiler/backend/js/analysis/TreeShakerTest.java
@@ -0,0 +1,73 @@
+// Copyright 2011 Google Inc. All Rights Reserved.
+
+package com.google.dart.compiler.backend.js.analysis;
+
+import com.google.dart.compiler.DartCompilerContext;
+import com.google.dart.compiler.LibrarySource;
+import com.google.dart.compiler.MockLibrarySource;
+import com.google.dart.compiler.Source;
+import com.google.dart.compiler.testing.TestCompilerContext;
+
+import junit.framework.TestCase;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+
+/**
+ * Tests the JS based tree shaker used in incremental compilation.
+ */
+public class TreeShakerTest extends TestCase {
+ class MockCompilerContext extends TestCompilerContext {
+ private final String srcCode;
+
+ public MockCompilerContext(String srcCode) {
+ this.srcCode = srcCode;
+ }
+
+ @Override
+ public Reader getArtifactReader(Source source, String part, String extension) {
+ return new StringReader(srcCode);
+ }
+ }
+
+ /**
+ * Tests that {@link TreeShaker#reduce(LibrarySource, DartCompilerContext, String, Writer)} can
+ * remove unused methods.
+ */
+ public void testReduce() throws IOException {
+ StringBuffer inputSrc = new StringBuffer();
+ inputSrc.append("function A() {}\n");
+ inputSrc.append("A.prototype.foo = function(){}\n");
+ inputSrc.append("function B() {}\n");
+ inputSrc.append("B.prototype.foo = function(){}\n");
+ inputSrc.append("function C() { A(); }\n");
+ inputSrc.append("RunEntry(C);\n");
+
+ StringWriter outputCode = new StringWriter();
+
+ TreeShaker.reduce(new MockLibrarySource(), new MockCompilerContext(inputSrc.toString()), "",
+ outputCode);
+
+ StringBuffer outputSrc = new StringBuffer();
+ outputSrc.append("function A() {}\n");
+ outputSrc.append("function C() { A(); }\n");
+ outputSrc.append("RunEntry(C);\n");
+
+ assertEquals(outputSrc.toString(), outputCode.toString());
+ }
+
+ /**
+ * Tests that {@link TreeShaker#reduce(LibrarySource, DartCompilerContext, String, Writer)} can
+ * handle empty code.
+ */
+ public void testReduceEmpty() throws IOException {
+ StringReader inputSrc = new StringReader("");
+ StringWriter outputSrc = new StringWriter();
+ TreeShaker.reduce(new MockLibrarySource(), new MockCompilerContext(""), "", outputSrc);
+
+ assertEquals("", outputSrc.toString());
+ }
+}
« no previous file with comments | « compiler/java/com/google/dart/compiler/backend/js/analysis/TreeShaker.java ('k') | compiler/lib/implementation/rtt.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698