Skip to content

Commit

Permalink
Simplify input adding helpers.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=154601745
  • Loading branch information
concavelenz authored and brad4d committed May 1, 2017
1 parent 3c773c4 commit 778833e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/com/google/javascript/jscomp/AbstractCompiler.java
Expand Up @@ -16,6 +16,7 @@

package com.google.javascript.jscomp;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
Expand Down Expand Up @@ -228,6 +229,7 @@ static enum MostRecentTypechecker {
/**
* Parses code for testing.
*/
@VisibleForTesting
abstract Node parseTestCode(String code);

/**
Expand Down
31 changes: 16 additions & 15 deletions src/com/google/javascript/jscomp/Compiler.java
Expand Up @@ -2027,16 +2027,7 @@ public Node parse(SourceFile file) {
return new JsAst(file).getAstRoot(this);
}

private int syntheticCodeId = 0;

@Override
Node parseSyntheticCode(String js) {
SourceFile source = SourceFile.fromCode(" [synthetic:" + (++syntheticCodeId) + "] ", js);
addFilesToSourceMap(ImmutableList.of(source));
CompilerInput input = new CompilerInput(source);
putCompilerInput(input.getInputId(), input);
return input.getAstRoot(this);
}

/**
* Allow subclasses to override the default CompileOptions object.
Expand All @@ -2053,21 +2044,31 @@ void initCompilerOptionsIfTesting() {
}
}

private int syntheticCodeId = 0;

@Override
Node parseSyntheticCode(String js) {
return parseSyntheticCode(" [synthetic:" + (++syntheticCodeId) + "] ", js);
}

@Override
Node parseSyntheticCode(String fileName, String js) {
initCompilerOptionsIfTesting();
addFileToSourceMap(fileName, js);
CompilerInput input = new CompilerInput(SourceFile.fromCode(fileName, js));
putCompilerInput(input.getInputId(), input);
return input.getAstRoot(this);
SourceFile source = SourceFile.fromCode(fileName, js);
addFilesToSourceMap(ImmutableList.of(source));
return parseCodeHelper(source);
}

@Override
@VisibleForTesting
Node parseTestCode(String js) {
initCompilerOptionsIfTesting();
initBasedOnOptions();
CompilerInput input = new CompilerInput(
SourceFile.fromCode("[testcode]", js));
return parseCodeHelper(SourceFile.fromCode("[testcode]", js));
}

private Node parseCodeHelper(SourceFile src) {
CompilerInput input = new CompilerInput(src);
putCompilerInput(input.getInputId(), input);
return input.getAstRoot(this);
}
Expand Down

0 comments on commit 778833e

Please sign in to comment.