Introduce some convenience methods related to EcmaVersion
This commit is contained in:
@@ -35,6 +35,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.k2js.analyze.AnalyzerFacadeForJS;
|
||||
import org.jetbrains.k2js.config.Config;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.config.ZippedLibrarySourcesConfig;
|
||||
import org.jetbrains.k2js.facade.K2JSTranslator;
|
||||
|
||||
@@ -93,8 +94,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments, K2JSCompile
|
||||
private static ExitCode translateAndGenerateOutputFile(@NotNull PrintingMessageCollector messageCollector,
|
||||
@NotNull JetCoreEnvironment environmentForJS, @NotNull Config config, @NotNull String outputFile) {
|
||||
try {
|
||||
K2JSTranslator.translateWithCallToMainAndSaveToFile(environmentForJS.getSourceFiles(), outputFile, config
|
||||
);
|
||||
K2JSTranslator.translateWithCallToMainAndSaveToFile(environmentForJS.getSourceFiles(), outputFile, config);
|
||||
}
|
||||
catch (Exception e) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "Exception while translating:\n" + e.getMessage(),
|
||||
@@ -123,6 +123,6 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments, K2JSCompile
|
||||
if (arguments.libzip == null) {
|
||||
return Config.getEmptyConfig(project, arguments.target);
|
||||
}
|
||||
return new ZippedLibrarySourcesConfig(project, arguments.libzip, arguments.target);
|
||||
return new ZippedLibrarySourcesConfig(project, arguments.libzip, EcmaVersion.fromString(arguments.target));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.jet.plugin.project;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.config.ZippedLibrarySourcesConfig;
|
||||
|
||||
import static org.jetbrains.jet.plugin.project.JsModuleDetector.getLibLocationAndTargetForProject;
|
||||
@@ -26,8 +27,7 @@ import static org.jetbrains.jet.plugin.project.JsModuleDetector.getLibLocationAn
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class IDEAConfig extends ZippedLibrarySourcesConfig {
|
||||
|
||||
public IDEAConfig(@NotNull Project project) {
|
||||
super(project, getLibLocationAndTargetForProject(project).first, null);
|
||||
super(project, getLibLocationAndTargetForProject(project).first, EcmaVersion.defaultVersion());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.k2js.config.Config;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
import org.jetbrains.k2js.utils.JetFileUtils;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
@@ -36,12 +37,11 @@ import java.util.List;
|
||||
//TODO: review/refactor
|
||||
public final class TestConfig extends Config {
|
||||
|
||||
|
||||
@Nullable
|
||||
private /*var*/ List<JetFile> jsLibFiles = null;
|
||||
|
||||
public TestConfig(@NotNull Project project) {
|
||||
super(project, null);
|
||||
super(project, EcmaVersion.v3);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -34,7 +34,7 @@ public abstract class Config {
|
||||
|
||||
@NotNull
|
||||
public static Config getEmptyConfig(@NotNull Project project, @Nullable String target) {
|
||||
return new Config(project, target) {
|
||||
return new Config(project, EcmaVersion.fromString(target)) {
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<JetFile> generateLibFiles() {
|
||||
@@ -70,9 +70,9 @@ public abstract class Config {
|
||||
@NotNull
|
||||
private final EcmaVersion target;
|
||||
|
||||
public Config(@NotNull Project project, @Nullable String target) {
|
||||
public Config(@NotNull Project project, @NotNull EcmaVersion ecmaVersion) {
|
||||
this.project = project;
|
||||
this.target = EcmaVersion.fromString(target);
|
||||
this.target = ecmaVersion;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -27,7 +27,12 @@ public enum EcmaVersion {
|
||||
v3, v5;
|
||||
|
||||
@NotNull
|
||||
static EcmaVersion fromString(@Nullable String target) {
|
||||
public static EcmaVersion fromString(@Nullable String target) {
|
||||
return StringUtil.compareVersionNumbers(target, "5") >= 0 ? v5 : v3;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static EcmaVersion defaultVersion() {
|
||||
return v3;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,8 +40,8 @@ public class ZippedLibrarySourcesConfig extends Config {
|
||||
@Nullable
|
||||
protected final String pathToLibZip;
|
||||
|
||||
public ZippedLibrarySourcesConfig(@NotNull Project project, @Nullable String pathToZip, @Nullable String target) {
|
||||
super(project, target);
|
||||
public ZippedLibrarySourcesConfig(@NotNull Project project, @Nullable String pathToZip, @NotNull EcmaVersion ecmaVersion) {
|
||||
super(project, ecmaVersion);
|
||||
pathToLibZip = pathToZip;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user