Skip to content

Commit

Permalink
Add an option to print the source for a single file after each pass.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=132083348
  • Loading branch information
blickly committed Sep 2, 2016
1 parent 08e3623 commit c41c741
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
21 changes: 20 additions & 1 deletion src/com/google/javascript/jscomp/Compiler.java
Expand Up @@ -966,7 +966,7 @@ final void beforePass(String passName) {
@Override
final void afterPass(String passName) {
if (options.printSourceAfterEachPass) {
String currentJsSource = toSource();
String currentJsSource = getCurrentJsSource();
if (!currentJsSource.equals(this.lastJsSource)) {
System.out.println();
System.out.println("// " + passName + " yields:");
Expand All @@ -977,6 +977,25 @@ final void afterPass(String passName) {
}
}

final String getCurrentJsSource() {
String filename = options.fileToPrintAfterEachPass;
if (filename == null) {
return toSource();
} else {
Node script = getScriptNode(filename);
return script != null ? toSource(script) : ("File '" + filename + "' not found");
}
}

final Node getScriptNode(String filename) {
for (Node file : jsRoot.children()) {
if (file.getSourceFileName() != null && file.getSourceFileName().endsWith(filename)) {
return file;
}
}
return null;
}

/**
* Returns a new tracer for the given pass name.
*/
Expand Down
12 changes: 9 additions & 3 deletions src/com/google/javascript/jscomp/CompilerOptions.java
Expand Up @@ -880,15 +880,21 @@ public void setTrustedStrings(boolean yes) {
trustedStrings = yes;
}

String reportPath;

// Should only be used when debugging compiler bugs using small JS inputs.
// Should only be used when debugging compiler bugs.
boolean printSourceAfterEachPass;
// Used to narrow down the printed source when overall input size is large.
String fileToPrintAfterEachPass;

public void setPrintSourceAfterEachPass(boolean printSource) {
this.printSourceAfterEachPass = printSource;
}

public void setFileToPrintAfterEachPass(String filename) {
this.fileToPrintAfterEachPass = filename;
}

String reportPath;

/** Where to save a report of global name usage */
public void setReportPath(String reportPath) {
this.reportPath = reportPath;
Expand Down

0 comments on commit c41c741

Please sign in to comment.