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