forked from reactjs/React.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourceMap.cs
More file actions
86 lines (76 loc) · 2.55 KB
/
SourceMap.cs
File metadata and controls
86 lines (76 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Copyright (c) 2014-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace React
{
/// <summary>
/// Represents the data contained in a source map
/// </summary>
[Serializable]
public class SourceMap
{
/// <summary>
/// Version number of the source map spec used to build this source map. Expected
/// to be version 3.
/// </summary>
public int Version { get; set; }
/// <summary>
/// An optional name of the generated code that this source map is associated with.
/// </summary>
public string File { get; set; }
/// <summary>
/// An optional source root, useful for relocating source files on a server or
/// removing repeated values in the <see cref="Sources"/> entry. This value is
/// prepended to the individual entries in the <see cref="Sources"/> field.
/// </summary>
public string SourceRoot { get; set; }
/// <summary>
/// A list of original sources used by the <see cref="Mappings"/> entry.
/// </summary>
public IList<string> Sources { get; set; }
/// <summary>
/// An optional list of source content, useful when the <see cref="Sources"/> can't
/// be hosted. The contents are listed in the same order as the <see cref="Sources"/>.
/// <c>null</c> may be used if some original sources should be retrieved by name.
/// </summary>
public IList<string> SourcesContent { get; set; }
/// <summary>
/// A list of symbol names used by the <see cref="Mappings"/> entry.
/// </summary>
public IList<string> Names { get; set; }
/// <summary>
/// A string with the mapping data encoded in base 64 VLQ.
/// </summary>
public string Mappings { get; set; }
/// <summary>
/// Outputs this source map as JSON.
/// </summary>
/// <returns></returns>
public string ToJson()
{
return JsonConvert.SerializeObject(this, new JsonSerializerSettings
{
// Camelcase keys (eg. "SourcesContent" -> "sourcesContent")
ContractResolver = new CamelCasePropertyNamesContractResolver()
});
}
/// <summary>
/// Parse a source map from JSON
/// </summary>
/// <param name="json">JSON input</param>
/// <returns>Source map</returns>
public static SourceMap FromJson(string json)
{
return JsonConvert.DeserializeObject<SourceMap>(json);
}
}
}