浏览代码

fcl-js: jssrcmap: added property SourceTranslatedFiles to allow custom filenames written to JSON

git-svn-id: trunk@36600 -
Mattias Gaertner 8 年之前
父节点
当前提交
84b08b61a8
共有 1 个文件被更改,包括 21 次插入3 次删除
  1. 21 3
      packages/fcl-js/src/jssrcmap.pas

+ 21 - 3
packages/fcl-js/src/jssrcmap.pas

@@ -45,7 +45,8 @@ type
 
 
   TSourceMapSrc = class
   TSourceMapSrc = class
   public
   public
-    Filename: string;
+    Filename: string; // as added by AddMapping
+    TranslatedFilename: string; // same as Filename, can be altered, written to JSON
     Source: String;
     Source: String;
   end;
   end;
 
 
@@ -82,8 +83,10 @@ type
     function GetItems(Index: integer): TSourceMapSegment;
     function GetItems(Index: integer): TSourceMapSegment;
     function GetSourceContents(Index: integer): String;
     function GetSourceContents(Index: integer): String;
     function GetSourceFiles(Index: integer): String;
     function GetSourceFiles(Index: integer): String;
+    function GetSourceTranslatedFiles(Index: integer): String;
     procedure SetGeneratedFilename(const AValue: string);
     procedure SetGeneratedFilename(const AValue: string);
     procedure SetSourceContents(Index: integer; const AValue: String);
     procedure SetSourceContents(Index: integer; const AValue: String);
+    procedure SetSourceTranslatedFiles(Index: integer; const AValue: String);
   public
   public
     constructor Create(const aGeneratedFilename: string);
     constructor Create(const aGeneratedFilename: string);
     destructor Destroy; override;
     destructor Destroy; override;
@@ -105,11 +108,13 @@ type
     property GeneratedFilename: string read FGeneratedFilename write SetGeneratedFilename;
     property GeneratedFilename: string read FGeneratedFilename write SetGeneratedFilename;
     function IndexOfName(const Name: string; AddIfNotExists: boolean = false): integer;
     function IndexOfName(const Name: string; AddIfNotExists: boolean = false): integer;
     function IndexOfSourceFile(const SrcFile: string; AddIfNotExists: boolean = false): integer;
     function IndexOfSourceFile(const SrcFile: string; AddIfNotExists: boolean = false): integer;
-    function Count: integer;
+    function Count: integer; // segments
     property Items[Index: integer]: TSourceMapSegment read GetItems; default; // segments
     property Items[Index: integer]: TSourceMapSegment read GetItems; default; // segments
     function SourceCount: integer;
     function SourceCount: integer;
     property SourceRoot: string read FSourceRoot write FSourceRoot;
     property SourceRoot: string read FSourceRoot write FSourceRoot;
     property SourceFiles[Index: integer]: String read GetSourceFiles;
     property SourceFiles[Index: integer]: String read GetSourceFiles;
+    property SourceTranslatedFiles[Index: integer]: String read GetSourceTranslatedFiles
+      write SetSourceTranslatedFiles;
     property SourceContents[Index: integer]: String read GetSourceContents write SetSourceContents;
     property SourceContents[Index: integer]: String read GetSourceContents write SetSourceContents;
     function NameCount: integer;
     function NameCount: integer;
     property Names[Index: integer]: string read GetNames;
     property Names[Index: integer]: string read GetNames;
@@ -264,6 +269,12 @@ begin
   TSourceMapSrc(FSources[Index]).Source:=AValue;
   TSourceMapSrc(FSources[Index]).Source:=AValue;
 end;
 end;
 
 
+procedure TSourceMap.SetSourceTranslatedFiles(Index: integer;
+  const AValue: String);
+begin
+  TSourceMapSrc(FSources[Index]).TranslatedFilename:=AValue;
+end;
+
 function TSourceMap.GetItems(Index: integer): TSourceMapSegment;
 function TSourceMap.GetItems(Index: integer): TSourceMapSegment;
 begin
 begin
   Result:=TSourceMapSegment(FItems[Index]);
   Result:=TSourceMapSegment(FItems[Index]);
@@ -284,6 +295,11 @@ begin
   Result:=TSourceMapSrc(FSources[Index]).Filename;
   Result:=TSourceMapSrc(FSources[Index]).Filename;
 end;
 end;
 
 
+function TSourceMap.GetSourceTranslatedFiles(Index: integer): String;
+begin
+  Result:=TSourceMapSrc(FSources[Index]).TranslatedFilename;
+end;
+
 constructor TSourceMap.Create(const aGeneratedFilename: string);
 constructor TSourceMap.Create(const aGeneratedFilename: string);
 begin
 begin
   FVersion:=3;
   FVersion:=3;
@@ -474,6 +490,7 @@ begin
   end;
   end;
 end;
 end;
 
 
+
 function TSourceMap.ToJSON: TJSONObject;
 function TSourceMap.ToJSON: TJSONObject;
 var
 var
   Obj: TJSONObject;
   Obj: TJSONObject;
@@ -501,7 +518,7 @@ begin
     Arr:=TJSONArray.Create;
     Arr:=TJSONArray.Create;
     Obj.Add('sources',Arr);
     Obj.Add('sources',Arr);
     for i:=0 to SourceCount-1 do
     for i:=0 to SourceCount-1 do
-      Arr.Add(SourceFiles[i]);
+      Arr.Add(SourceTranslatedFiles[i]);
 
 
     // "sourcesContent" - array of source content: null or source as string
     // "sourcesContent" - array of source content: null or source as string
     // only needed if there is a source
     // only needed if there is a source
@@ -597,6 +614,7 @@ begin
   if (Result>=0) or not AddIfNotExists then exit;
   if (Result>=0) or not AddIfNotExists then exit;
   Src:=TSourceMapSrc.Create;
   Src:=TSourceMapSrc.Create;
   Src.Filename:=SrcFile;
   Src.Filename:=SrcFile;
+  Src.TranslatedFilename:=SrcFile;
   Result:=FSources.Count;
   Result:=FSources.Count;
   FSources.Add(Src);
   FSources.Add(Src);
   FSourceToIndex.Add(SrcFile,Result);
   FSourceToIndex.Add(SrcFile,Result);