Remove json.org library, use own JSON parser to parse source maps
This commit is contained in:
@@ -64,7 +64,6 @@
|
|||||||
<fileset dir="${dependencies}" includes="jline3.jar"/>
|
<fileset dir="${dependencies}" includes="jline3.jar"/>
|
||||||
<fileset dir="${dependencies}" includes="jansi.jar"/>
|
<fileset dir="${dependencies}" includes="jansi.jar"/>
|
||||||
<fileset dir="${dependencies}" includes="javaslang-2.0.6.jar"/>
|
<fileset dir="${dependencies}" includes="javaslang-2.0.6.jar"/>
|
||||||
<fileset dir="${dependencies}" includes="json-org.jar"/>
|
|
||||||
<fileset dir="${dependencies}" includes="kotlinx-coroutines-core.jar"/>
|
<fileset dir="${dependencies}" includes="kotlinx-coroutines-core.jar"/>
|
||||||
<fileset dir="${basedir}/ideaSDK/jps" includes="jps-model.jar"/>
|
<fileset dir="${basedir}/ideaSDK/jps" includes="jps-model.jar"/>
|
||||||
</path>
|
</path>
|
||||||
@@ -402,7 +401,6 @@
|
|||||||
<zipfileset src="${dependencies}/jline3.jar"/>
|
<zipfileset src="${dependencies}/jline3.jar"/>
|
||||||
<zipfileset src="${dependencies}/jansi.jar"/>
|
<zipfileset src="${dependencies}/jansi.jar"/>
|
||||||
<zipfileset src="${dependencies}/javaslang-2.0.6.jar"/>
|
<zipfileset src="${dependencies}/javaslang-2.0.6.jar"/>
|
||||||
<zipfileset src="${dependencies}/json-org.jar"/>
|
|
||||||
<zipfileset src="${protobuf.jar}"/>
|
<zipfileset src="${protobuf.jar}"/>
|
||||||
<zipfileset src="${dependencies}/kotlinx-coroutines-core.jar"/>
|
<zipfileset src="${dependencies}/kotlinx-coroutines-core.jar"/>
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ val packagesToExcludeFromDummy =
|
|||||||
"one/util/streamex/**",
|
"one/util/streamex/**",
|
||||||
"org/iq80/snappy/**",
|
"org/iq80/snappy/**",
|
||||||
"org/jline/**",
|
"org/jline/**",
|
||||||
"org/json/**",
|
|
||||||
"org/xmlpull/**",
|
"org/xmlpull/**",
|
||||||
"*.txt")
|
"*.txt")
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
// EXISTS: out.js
|
// EXISTS: out.js
|
||||||
// CONTAINS: out.js.map, \"©∑\\n\"
|
// CONTAINS: out.js.map, \"\u00a9\u2211\\n\"
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ dependencies {
|
|||||||
compile(project(":compiler:util"))
|
compile(project(":compiler:util"))
|
||||||
compile(project(":js:js.ast"))
|
compile(project(":js:js.ast"))
|
||||||
compile(ideaSdkCoreDeps("intellij-core"))
|
compile(ideaSdkCoreDeps("intellij-core"))
|
||||||
compile(preloadedDeps("json-org"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
|||||||
@@ -16,10 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.js.parser.sourcemaps
|
package org.jetbrains.kotlin.js.parser.sourcemaps
|
||||||
|
|
||||||
import org.json.JSONArray
|
|
||||||
import org.json.JSONException
|
|
||||||
import org.json.JSONObject
|
|
||||||
import org.json.JSONTokener
|
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.Reader
|
import java.io.Reader
|
||||||
import java.io.StringReader
|
import java.io.StringReader
|
||||||
@@ -28,57 +24,68 @@ object SourceMapParser {
|
|||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
fun parse(reader: Reader): SourceMapParseResult {
|
fun parse(reader: Reader): SourceMapParseResult {
|
||||||
val jsonObject = try {
|
val jsonObject = try {
|
||||||
JSONObject(JSONTokener(reader))
|
parseJson(reader)
|
||||||
}
|
}
|
||||||
catch (e: JSONException) {
|
catch (e: JsonSyntaxException) {
|
||||||
return SourceMapError(e.message ?: "parse error")
|
return SourceMapError(e.message ?: "parse error")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!jsonObject.has("version")) return SourceMapError("Version not defined")
|
if (jsonObject !is JsonObject) return SourceMapError("Top-level object expected")
|
||||||
jsonObject.get("version").let {
|
|
||||||
if (it != 3) return SourceMapError("Unsupported version: $it")
|
val version = jsonObject.properties["version"] ?: return SourceMapError("Version not defined")
|
||||||
|
version.let {
|
||||||
|
if (version !is JsonNumber || version.value != 3.0) return SourceMapError("Unsupported version: $it")
|
||||||
}
|
}
|
||||||
|
|
||||||
val sourceRoot = if (jsonObject.has("sourceRoot")) {
|
val sourceRoot = jsonObject.properties["sourceRoot"].let {
|
||||||
jsonObject.get("sourceRoot") as? String ?: return SourceMapError("'sourceRoot' property is not of string type")
|
if (it != null) {
|
||||||
}
|
(it as? JsonString ?: return SourceMapError("'sourceRoot' property is not of string type")).value
|
||||||
else {
|
}
|
||||||
""
|
else {
|
||||||
}
|
""
|
||||||
|
|
||||||
val sources = if (jsonObject.has("sources")) {
|
|
||||||
val sourcesProperty = jsonObject.get("sources") as? JSONArray ?:
|
|
||||||
return SourceMapError("'sources' property is not of array type")
|
|
||||||
sourcesProperty.map {
|
|
||||||
it as? String ?: return SourceMapError("'sources' array must contain strings")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
emptyList()
|
val sources = jsonObject.properties["sources"].let {
|
||||||
|
if (it != null) {
|
||||||
|
val sourcesProperty = it as? JsonArray ?:
|
||||||
|
return SourceMapError("'sources' property is not of array type")
|
||||||
|
sourcesProperty.elements.map {
|
||||||
|
(it as? JsonString ?: return SourceMapError("'sources' array must contain strings")).value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
emptyList()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val sourcesContent: List<String?> = if (jsonObject.has("sourcesContent")) {
|
val sourcesContent: List<String?> = jsonObject.properties["sourcesContent"].let {
|
||||||
val sourcesContentProperty = jsonObject.get("sourcesContent") as? JSONArray ?:
|
if (it != null) {
|
||||||
return SourceMapError("'sourcesContent' property is not of array type")
|
val sourcesContentProperty = it as? JsonArray ?:
|
||||||
if (sourcesContentProperty.any { it != JSONObject.NULL && it !is String? }) {
|
return SourceMapError("'sourcesContent' property is not of array type")
|
||||||
return SourceMapError("'sources' array must contain strings")
|
sourcesContentProperty.elements.map {
|
||||||
|
when (it) {
|
||||||
|
is JsonNull -> null
|
||||||
|
is JsonString -> it.value
|
||||||
|
else -> return SourceMapError("'sources' array must contain strings")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
emptyList()
|
||||||
}
|
}
|
||||||
sourcesContentProperty.map { if (it == JSONObject.NULL) null else it as String? }
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
emptyList()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val sourcePathToContent = sources.zip(sourcesContent).associate { it }
|
val sourcePathToContent = sources.zip(sourcesContent).associate { it }
|
||||||
|
|
||||||
if (!jsonObject.has("mappings")) return SourceMapError("'mappings' property not found")
|
val mappings = jsonObject.properties["mappings"] ?: return SourceMapError("'mappings' property not found")
|
||||||
val mappings = jsonObject.get("mappings") as? String ?: return SourceMapError("'mappings' property is not of string type")
|
if (mappings !is JsonString) return SourceMapError("'mappings' property is not of string type")
|
||||||
|
|
||||||
var jsColumn = 0
|
var jsColumn = 0
|
||||||
var sourceLine = 0
|
var sourceLine = 0
|
||||||
var sourceColumn = 0
|
var sourceColumn = 0
|
||||||
var sourceIndex = 0
|
var sourceIndex = 0
|
||||||
val stream = MappingStream(mappings)
|
val stream = MappingStream(mappings.value)
|
||||||
val sourceMap = SourceMap { sourcePathToContent[it]?.let { StringReader(it) } }
|
val sourceMap = SourceMap { sourcePathToContent[it]?.let { StringReader(it) } }
|
||||||
var currentGroup = SourceMapGroup().also { sourceMap.groups += it }
|
var currentGroup = SourceMapGroup().also { sourceMap.groups += it }
|
||||||
|
|
||||||
|
|||||||
@@ -21,13 +21,11 @@ import gnu.trove.TObjectIntHashMap;
|
|||||||
import kotlin.io.TextStreamsKt;
|
import kotlin.io.TextStreamsKt;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.kotlin.js.parser.sourcemaps.*;
|
||||||
import org.jetbrains.kotlin.js.util.TextOutput;
|
import org.jetbrains.kotlin.js.util.TextOutput;
|
||||||
import org.json.JSONWriter;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@@ -72,44 +70,31 @@ public class SourceMap3Builder implements SourceMapBuilder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String build() {
|
public String build() {
|
||||||
try {
|
JsonObject json = new JsonObject();
|
||||||
StringWriter stringWriter = new StringWriter();
|
json.getProperties().put("version", new JsonNumber(3));
|
||||||
JSONWriter writer = new JSONWriter(stringWriter);
|
json.getProperties().put("file", new JsonString(generatedFile.getName()));
|
||||||
writer.object();
|
appendSources(json);
|
||||||
writer.key("version").value(3);
|
appendSourcesContent(json);
|
||||||
writer.key("file").value(generatedFile.getName());
|
json.getProperties().put("names", new JsonArray());
|
||||||
|
json.getProperties().put("mappings", new JsonString(out.toString()));
|
||||||
appendSources(writer);
|
return json.toString();
|
||||||
appendSourcesContent(writer);
|
|
||||||
|
|
||||||
writer.key("names").array().endArray();
|
|
||||||
writer.key("mappings").value(out.toString());
|
|
||||||
|
|
||||||
writer.endObject();
|
|
||||||
stringWriter.close();
|
|
||||||
|
|
||||||
return stringWriter.toString();
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw new AssertionError("This exception should have not been thrown from StringWriter", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendSources(JSONWriter writer) {
|
private void appendSources(JsonObject json) {
|
||||||
writer.key("sources").array();
|
JsonArray array = new JsonArray();
|
||||||
for (String source : orderedSources) {
|
for (String source : orderedSources) {
|
||||||
writer.value(pathPrefix + source);
|
array.getElements().add(new JsonString(pathPrefix + source));
|
||||||
}
|
}
|
||||||
writer.endArray();
|
json.getProperties().put("sources", array);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendSourcesContent(JSONWriter writer) {
|
private void appendSourcesContent(JsonObject json) {
|
||||||
writer.key("sourcesContent").array();
|
JsonArray array = new JsonArray();
|
||||||
for (Supplier<Reader> contentSupplier : orderedSourceContentSuppliers) {
|
for (Supplier<Reader> contentSupplier : orderedSourceContentSuppliers) {
|
||||||
Reader reader = contentSupplier.get();
|
Reader reader = contentSupplier.get();
|
||||||
writer.value(reader != null ? TextStreamsKt.readText(reader) : null);
|
array.getElements().add(reader != null ? new JsonString(TextStreamsKt.readText(reader)) : JsonNull.INSTANCE);
|
||||||
}
|
}
|
||||||
writer.endArray();
|
json.getProperties().put("sourcesContent", array);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Vendored
-23
@@ -1,23 +0,0 @@
|
|||||||
JSON
|
|
||||||
|
|
||||||
Copyright (c) 2002 JSON.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
The Software shall be used for Good, not Evil.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
@@ -272,9 +272,6 @@
|
|||||||
|
|
||||||
<!-- node.js -->
|
<!-- node.js -->
|
||||||
<antcall target="download-nodejs-and-npm"/>
|
<antcall target="download-nodejs-and-npm"/>
|
||||||
|
|
||||||
<!-- JSON.org -->
|
|
||||||
<get src="https://repo.maven.apache.org/maven2/org/json/json/20160807/json-20160807.jar" dest="${dependencies}/json-org.jar"/>
|
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<macrodef name="get-protobuf-and-rename-packages">
|
<macrodef name="get-protobuf-and-rename-packages">
|
||||||
|
|||||||
Reference in New Issue
Block a user