Add CompilerConfiguration to JsConfig
Will be used to store common compiler options (such as source version, inline disabled, etc) as well as JS-specific options, to unify the logic of compiler option initialization between JS and JVM compilers
This commit is contained in:
@@ -119,7 +119,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
|
||||
File outputFile = new File(arguments.outputFile);
|
||||
|
||||
JsConfig config = getConfig(arguments, project);
|
||||
JsConfig config = getConfig(project, configuration, arguments);
|
||||
if (config.checkLibFilesAndReportErrors(new Function1<String, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(String message) {
|
||||
@@ -245,7 +245,11 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static JsConfig getConfig(@NotNull K2JSCompilerArguments arguments, @NotNull Project project) {
|
||||
private static JsConfig getConfig(
|
||||
@NotNull Project project,
|
||||
@NotNull CompilerConfiguration configuration,
|
||||
@NotNull K2JSCompilerArguments arguments
|
||||
) {
|
||||
if (arguments.target != null) {
|
||||
assert arguments.target == "v5" : "Unsupported ECMA version: " + arguments.target;
|
||||
}
|
||||
@@ -262,7 +266,7 @@ public class K2JSCompiler extends CLICompiler<K2JSCompilerArguments> {
|
||||
ContainerUtil.addAllNotNull(libraryFiles, arguments.libraryFiles);
|
||||
}
|
||||
|
||||
return new LibrarySourcesConfig.Builder(project, moduleId, libraryFiles)
|
||||
return new LibrarySourcesConfig.Builder(project, configuration, moduleId, libraryFiles)
|
||||
.ecmaVersion(ecmaVersion)
|
||||
.sourceMap(arguments.sourceMap)
|
||||
.inlineEnabled(inlineEnabled)
|
||||
|
||||
+3
-1
@@ -40,7 +40,9 @@ public abstract class AbstractDiagnosticsTestWithJsStdLib extends AbstractDiagno
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
config = new LibrarySourcesConfig.Builder(getProject(), "module", LibrarySourcesConfig.JS_STDLIB).build();
|
||||
config = new LibrarySourcesConfig.Builder(
|
||||
getProject(), getEnvironment().getConfiguration(), "module", LibrarySourcesConfig.JS_STDLIB
|
||||
).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-3
@@ -39,8 +39,8 @@ import org.jetbrains.kotlin.utils.sure
|
||||
import java.io.File
|
||||
|
||||
class KotlinJavascriptSerializerTest : TestCaseWithTmpdir() {
|
||||
private final val MODULE_NAME = "module"
|
||||
private final val BASE_DIR = "compiler/testData/serialization"
|
||||
private val MODULE_NAME = "module"
|
||||
private val BASE_DIR = "compiler/testData/serialization"
|
||||
|
||||
private fun doTest(fileName: String, metaFileDir: File = tmpdir) {
|
||||
val source = "$BASE_DIR/$fileName"
|
||||
@@ -68,7 +68,9 @@ class KotlinJavascriptSerializerTest : TestCaseWithTmpdir() {
|
||||
try {
|
||||
val environment = KotlinCoreEnvironment.createForTests(rootDisposable, configuration, EnvironmentConfigFiles.JS_CONFIG_FILES)
|
||||
val files = environment.getSourceFiles()
|
||||
val config = LibrarySourcesConfig.Builder(environment.project, MODULE_NAME, LibrarySourcesConfig.JS_STDLIB).build()
|
||||
val config = LibrarySourcesConfig.Builder(
|
||||
environment.project, environment.configuration, MODULE_NAME, LibrarySourcesConfig.JS_STDLIB
|
||||
).build()
|
||||
val analysisResult = TopDownAnalyzerFacadeForJS.analyzeFiles(files, config)
|
||||
FileUtil.writeToFile(metaFile, KotlinJavascriptSerializationUtil.metadataAsString(MODULE_NAME, analysisResult.moduleDescriptor))
|
||||
}
|
||||
|
||||
+2
-1
@@ -60,7 +60,8 @@ public abstract class AbstractDiagnosticMessageJsTest extends AbstractDiagnostic
|
||||
|
||||
@NotNull
|
||||
private JsConfig getConfig() {
|
||||
return new LibrarySourcesConfig.Builder(getProject(), "testModule", LibrarySourcesConfig.JS_STDLIB)
|
||||
CompilerConfiguration configuration = getEnvironment().getConfiguration();
|
||||
return new LibrarySourcesConfig.Builder(getProject(), configuration, "testModule", LibrarySourcesConfig.JS_STDLIB)
|
||||
.inlineEnabled(false)
|
||||
.isUnitTestConfig(true)
|
||||
.build();
|
||||
|
||||
@@ -24,6 +24,7 @@ import kotlin.collections.CollectionsKt;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl;
|
||||
import org.jetbrains.kotlin.js.resolve.JsPlatform;
|
||||
@@ -42,10 +43,12 @@ import java.util.List;
|
||||
* Base class representing a configuration of translator.
|
||||
*/
|
||||
public abstract class JsConfig {
|
||||
private final boolean inlineEnabled;
|
||||
@NotNull
|
||||
private final Project project;
|
||||
@NotNull
|
||||
private final CompilerConfiguration configuration;
|
||||
private final boolean inlineEnabled;
|
||||
@NotNull
|
||||
private final LockBasedStorageManager storageManager = new LockBasedStorageManager();
|
||||
@NotNull
|
||||
private final List<KtFile> sourceFilesFromLibraries = new SmartList<KtFile>();
|
||||
@@ -69,6 +72,7 @@ public abstract class JsConfig {
|
||||
|
||||
protected JsConfig(
|
||||
@NotNull Project project,
|
||||
@NotNull CompilerConfiguration configuration,
|
||||
@NotNull String moduleId,
|
||||
@NotNull EcmaVersion ecmaVersion,
|
||||
boolean sourcemap,
|
||||
@@ -77,6 +81,7 @@ public abstract class JsConfig {
|
||||
boolean kjsm
|
||||
) {
|
||||
this.project = project;
|
||||
this.configuration = configuration;
|
||||
this.target = ecmaVersion;
|
||||
this.moduleId = moduleId;
|
||||
this.sourcemap = sourcemap;
|
||||
|
||||
@@ -29,6 +29,7 @@ import kotlin.jvm.functions.Function1;
|
||||
import kotlin.jvm.functions.Function2;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType;
|
||||
import org.jetbrains.kotlin.js.JavaScript;
|
||||
import org.jetbrains.kotlin.psi.KtFile;
|
||||
@@ -64,6 +65,7 @@ public class LibrarySourcesConfig extends JsConfig {
|
||||
|
||||
private LibrarySourcesConfig(
|
||||
@NotNull Project project,
|
||||
@NotNull CompilerConfiguration configuration,
|
||||
@NotNull String moduleId,
|
||||
@NotNull List<String> files,
|
||||
@NotNull EcmaVersion ecmaVersion,
|
||||
@@ -73,7 +75,7 @@ public class LibrarySourcesConfig extends JsConfig {
|
||||
boolean metaInfo,
|
||||
boolean kjsm
|
||||
) {
|
||||
super(project, moduleId, ecmaVersion, sourceMap, inlineEnabled, metaInfo, kjsm);
|
||||
super(project, configuration, moduleId, ecmaVersion, sourceMap, inlineEnabled, metaInfo, kjsm);
|
||||
this.files = files;
|
||||
this.isUnitTestConfig = isUnitTestConfig;
|
||||
}
|
||||
@@ -189,19 +191,25 @@ public class LibrarySourcesConfig extends JsConfig {
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
Project project;
|
||||
String moduleId;
|
||||
List<String> files;
|
||||
@NotNull
|
||||
EcmaVersion ecmaVersion = EcmaVersion.defaultVersion();
|
||||
private final Project project;
|
||||
private final CompilerConfiguration configuration;
|
||||
private final String moduleId;
|
||||
private final List<String> files;
|
||||
private EcmaVersion ecmaVersion = EcmaVersion.defaultVersion();
|
||||
boolean sourceMap = false;
|
||||
boolean inlineEnabled = true;
|
||||
boolean isUnitTestConfig = false;
|
||||
boolean metaInfo = false;
|
||||
boolean kjsm = false;
|
||||
|
||||
public Builder(@NotNull Project project, @NotNull String moduleId, @NotNull List<String> files) {
|
||||
public Builder(
|
||||
@NotNull Project project,
|
||||
@NotNull CompilerConfiguration configuration,
|
||||
@NotNull String moduleId,
|
||||
@NotNull List<String> files
|
||||
) {
|
||||
this.project = project;
|
||||
this.configuration = configuration;
|
||||
this.moduleId = moduleId;
|
||||
this.files = files;
|
||||
}
|
||||
@@ -237,7 +245,9 @@ public class LibrarySourcesConfig extends JsConfig {
|
||||
}
|
||||
|
||||
public JsConfig build() {
|
||||
return new LibrarySourcesConfig(project, moduleId, files, ecmaVersion, sourceMap, inlineEnabled, isUnitTestConfig, metaInfo, kjsm);
|
||||
return new LibrarySourcesConfig(
|
||||
project, configuration, moduleId, files, ecmaVersion, sourceMap, inlineEnabled, isUnitTestConfig, metaInfo, kjsm
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -342,7 +342,7 @@ public abstract class BasicTest extends KotlinTestWithEnvironment {
|
||||
librariesWithStdlib.addAll(libraries);
|
||||
}
|
||||
|
||||
return new LibrarySourcesConfig.Builder(project, moduleId, librariesWithStdlib)
|
||||
return new LibrarySourcesConfig.Builder(project, getEnvironment().getConfiguration(), moduleId, librariesWithStdlib)
|
||||
.ecmaVersion(ecmaVersion)
|
||||
.sourceMap(shouldGenerateSourceMap())
|
||||
.inlineEnabled(isInlineEnabled)
|
||||
|
||||
Reference in New Issue
Block a user