Add -keep command line option to JS DCE tool
This commit is contained in:
+7
@@ -26,6 +26,13 @@ class K2JSDceArguments : CommonToolArguments() {
|
||||
@JvmField
|
||||
var outputDirectory: String? = null
|
||||
|
||||
@field:Argument(
|
||||
value = "-keep",
|
||||
valueDescription = "<fully.qualified.name[,]>",
|
||||
description = "List of fully-qualified names of declarations that shouldn't be eliminated")
|
||||
@JvmField
|
||||
var declarationsToKeep: Array<String>? = null
|
||||
|
||||
@field:GradleOption(DefaultValues.BooleanFalseDefault::class)
|
||||
@field:Argument(value = "-Xprint-reachability-info", description = "Print declarations marked as reachable")
|
||||
@JvmField
|
||||
|
||||
@@ -49,7 +49,9 @@ class K2JSDce : CLITool<K2JSDceArguments>() {
|
||||
return ExitCode.COMPILATION_ERROR
|
||||
}
|
||||
|
||||
val dceResult = DeadCodeElimination.run(files, emptySet()) {
|
||||
val includedDeclarations = arguments.declarationsToKeep.orEmpty().toSet()
|
||||
|
||||
val dceResult = DeadCodeElimination.run(files, includedDeclarations) {
|
||||
messageCollector.report(CompilerMessageSeverity.LOGGING, it)
|
||||
}
|
||||
val nodes = dceResult.reachableNodes
|
||||
|
||||
+2
@@ -1,6 +1,8 @@
|
||||
Usage: kotlin-dce-js <options> <source files>
|
||||
where possible options include:
|
||||
-output-dir <path> Output directory
|
||||
-keep <fully.qualified.name[,]>
|
||||
List of fully-qualified names of declarations that shouldn't be eliminated
|
||||
-help (-h) Print a synopsis of standard options
|
||||
-X Print a synopsis of advanced options
|
||||
-version Display compiler version
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
define(["exports"], function(exports) {
|
||||
function foo() {
|
||||
}
|
||||
|
||||
function bar() {
|
||||
}
|
||||
|
||||
function baz() {
|
||||
}
|
||||
|
||||
function ignore() {
|
||||
}
|
||||
|
||||
baz();
|
||||
|
||||
exports.foo = foo;
|
||||
exports.bar = bar;
|
||||
exports.baz = baz;
|
||||
exports.ignore = ignore;
|
||||
});
|
||||
@@ -0,0 +1,6 @@
|
||||
$TESTDATA_DIR$/include.js
|
||||
-output-dir
|
||||
$TEMP_DIR$/min
|
||||
-keep
|
||||
global.foo,global.bar
|
||||
-Xprint-reachability-info
|
||||
@@ -560,6 +560,12 @@ public class CliTestGenerated extends AbstractCliTest {
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("includeDeclarations.args")
|
||||
public void testIncludeDeclarations() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/includeDeclarations.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("jsExtraHelp.args")
|
||||
public void testJsExtraHelp() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/jsExtraHelp.args");
|
||||
|
||||
Reference in New Issue
Block a user