allow the JS compiler to take a list of files, verbose flag and a flag to indicate if a main call is required; plus added a test case to ensure we can compile some of the kotlin standard library using the K2JSCompiler directly
This commit is contained in:
@@ -19,6 +19,8 @@ package org.jetbrains.k2js.test.semantics;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.cli.js.K2JSCompiler;
|
||||
import org.jetbrains.jet.cli.js.K2JSCompilerArguments;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.k2js.config.Config;
|
||||
import org.jetbrains.k2js.config.EcmaVersion;
|
||||
@@ -58,12 +60,6 @@ public final class StdLibToJSTest extends SingleFileTranslationTest {
|
||||
String... stdLibFiles) throws Exception {
|
||||
List<String> files = Lists.newArrayList();
|
||||
|
||||
// lets add the standard JS library files
|
||||
/*
|
||||
for (String libFileName : Config.LIB_FILE_NAMES) {
|
||||
files.add(Config.LIBRARIES_LOCATION + libFileName);
|
||||
}
|
||||
*/
|
||||
|
||||
File stdlibDir = new File("libraries/stdlib/src");
|
||||
assertTrue("Cannot find stdlib source: " + stdlibDir, stdlibDir.exists());
|
||||
@@ -76,5 +72,20 @@ public final class StdLibToJSTest extends SingleFileTranslationTest {
|
||||
runRhinoTests(getOutputFilePaths(kotlinFilename, ecmaVersions),
|
||||
new RhinoFunctionNativeObjectResultChecker("test.browser", "foo", "Some Dynamically Created Content!!!"));
|
||||
*/
|
||||
|
||||
// lets add the standard JS library files
|
||||
for (String libFileName : Config.LIB_FILE_NAMES) {
|
||||
files.add(Config.LIBRARIES_LOCATION + libFileName);
|
||||
}
|
||||
// now lets try invoke the compiler
|
||||
for (EcmaVersion version : ecmaVersions) {
|
||||
System.out.println("Compiling with version: " + version);
|
||||
K2JSCompiler compiler = new K2JSCompiler();
|
||||
K2JSCompilerArguments arguments = new K2JSCompilerArguments();
|
||||
arguments.outputFile = getOutputFilePath(getTestName(false) + ".compiler.kt", version);
|
||||
arguments.sourceFiles = files;
|
||||
arguments.verbose = true;
|
||||
compiler.exec(System.out, arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public abstract class Config {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected static final List<String> LIB_FILE_NAMES = Arrays.asList(
|
||||
public static final List<String> LIB_FILE_NAMES = Arrays.asList(
|
||||
"/core/annotations.kt",
|
||||
"/jquery/common.kt",
|
||||
"/jquery/ui.kt",
|
||||
@@ -67,11 +67,12 @@ public abstract class Config {
|
||||
"/html5/image.kt",
|
||||
"/stdlib/JUMaps.kt",
|
||||
"/stdlib/browser.kt",
|
||||
"/core/dom.kt",
|
||||
"/core/dom/core.kt"
|
||||
"/core/dom.kt"
|
||||
// TODO
|
||||
// "/core/dom/core.kt"
|
||||
);
|
||||
|
||||
protected static final String LIBRARIES_LOCATION = "js/js.libraries/src";
|
||||
public static final String LIBRARIES_LOCATION = "js/js.libraries/src";
|
||||
|
||||
@NotNull
|
||||
private final Project project;
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.jetbrains.k2js.generate.CodeGenerator;
|
||||
import org.jetbrains.k2js.translate.general.Translation;
|
||||
import org.jetbrains.k2js.utils.JetFileUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -47,8 +48,15 @@ public final class K2JSTranslator {
|
||||
public static void translateWithCallToMainAndSaveToFile(@NotNull List<JetFile> files,
|
||||
@NotNull String outputPath,
|
||||
@NotNull Config config) throws Exception {
|
||||
translateWithMainCallParametersAndSaveToFile(MainCallParameters.mainWithoutArguments(), files, outputPath, config);
|
||||
}
|
||||
|
||||
public static void translateWithMainCallParametersAndSaveToFile(MainCallParameters mainCall,
|
||||
List<JetFile> files,
|
||||
String outputPath,
|
||||
Config config) throws TranslationException, IOException {
|
||||
K2JSTranslator translator = new K2JSTranslator(config);
|
||||
String programCode = translator.generateProgramCode(files, MainCallParameters.mainWithoutArguments()) + "\n";
|
||||
String programCode = translator.generateProgramCode(files, mainCall) + "\n";
|
||||
writeCodeToFile(outputPath, programCode);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user