mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 12:29:18 +02:00
pastojs: added TPas2jsMapper.SaveJSToStream
This commit is contained in:
parent
9a1ccd2a16
commit
7e57e4514a
@ -25,8 +25,8 @@ unit FPPJsSrcMap;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
SysUtils, math,
|
SysUtils, Classes, math,
|
||||||
jswriter, jstree, JSSrcMap;
|
jswriter, jstree, JSSrcMap, fpjson, Pas2JSUtils;
|
||||||
|
|
||||||
type
|
type
|
||||||
{ TPas2JSSrcMap }
|
{ TPas2JSSrcMap }
|
||||||
@ -40,10 +40,13 @@ type
|
|||||||
procedure Release;
|
procedure Release;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TPas2jsMap_IsBinaryEvent = function(Sender: TObject; const aFilename: string): boolean of object;
|
||||||
|
|
||||||
{ TPas2JSMapper }
|
{ TPas2JSMapper }
|
||||||
|
|
||||||
TPas2JSMapper = class(TBufferWriter)
|
TPas2JSMapper = class(TBufferWriter)
|
||||||
private
|
private
|
||||||
|
FOnIsBinary: TPas2jsMap_IsBinaryEvent;
|
||||||
FPCUExt: string;
|
FPCUExt: string;
|
||||||
FDestFileName: String;
|
FDestFileName: String;
|
||||||
FSrcMap: TPas2JSSrcMap;
|
FSrcMap: TPas2JSSrcMap;
|
||||||
@ -62,10 +65,12 @@ type
|
|||||||
public
|
public
|
||||||
property SrcMap: TPas2JSSrcMap read FSrcMap write SetSrcMap;
|
property SrcMap: TPas2JSSrcMap read FSrcMap write SetSrcMap;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
procedure SaveJSToStream(WithUTF8BOM: boolean; const MapFilename: string; s: TFPJSStream);
|
||||||
procedure WriteFile(Src, Filename: string);
|
procedure WriteFile(Src, Filename: string);
|
||||||
// Final destination filename. Usually unit, unless combining javascript in single file.
|
// Final destination filename. Usually unit, unless combining javascript in single file.
|
||||||
property DestFileName : String read FDestFileName Write FDestFileName;
|
property DestFileName : String read FDestFileName Write FDestFileName;
|
||||||
property PCUExt: string read FPCUExt write FPCUExt;
|
property PCUExt: string read FPCUExt write FPCUExt;
|
||||||
|
property OnIsBinary: TPas2jsMap_IsBinaryEvent read FOnIsBinary write FOnIsBinary;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
@ -142,6 +147,8 @@ begin
|
|||||||
if FSrcFilename=Value then exit;
|
if FSrcFilename=Value then exit;
|
||||||
FSrcFilename:=Value;
|
FSrcFilename:=Value;
|
||||||
FSrcIsBinary:=SameText(ExtractFileExt(Value),FPCUExt);
|
FSrcIsBinary:=SameText(ExtractFileExt(Value),FPCUExt);
|
||||||
|
if (not FSrcIsBinary) and Assigned(FOnIsBinary) then
|
||||||
|
FSrcIsBinary:=FOnIsBinary(Self,Value);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPas2JSMapper.Writing;
|
procedure TPas2JSMapper.Writing;
|
||||||
@ -219,6 +226,37 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TPas2JSMapper.SaveJSToStream(WithUTF8BOM: boolean;
|
||||||
|
const MapFilename: string; s: TFPJSStream);
|
||||||
|
var
|
||||||
|
MapSrc: string;
|
||||||
|
{$ifndef pas2js}
|
||||||
|
bom: string;
|
||||||
|
{$endif}
|
||||||
|
begin
|
||||||
|
if MapFilename<>'' then
|
||||||
|
MapSrc:='//# sourceMappingURL='+MapFilename+LineEnding
|
||||||
|
else
|
||||||
|
MapSrc:='';
|
||||||
|
{$ifdef pas2js}
|
||||||
|
if WithUTF8BOM then ;
|
||||||
|
for i:=0 to FBufPos-1 do
|
||||||
|
s.push(Buffer[i]);
|
||||||
|
if MapSrc<>'' then
|
||||||
|
s.push(MapSrc);
|
||||||
|
{$else}
|
||||||
|
if WithUTF8BOM then
|
||||||
|
begin
|
||||||
|
bom:=UTF8BOM;
|
||||||
|
s.Write(bom[1],length(bom));
|
||||||
|
end;
|
||||||
|
if BufferLength>0 then
|
||||||
|
s.Write(Buffer^,BufferLength);
|
||||||
|
if MapSrc<>'' then
|
||||||
|
s.Write(MapSrc[1],length(MapSrc));
|
||||||
|
{$endif}
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TPas2JSMapper.WriteFile(Src, Filename: string);
|
procedure TPas2JSMapper.WriteFile(Src, Filename: string);
|
||||||
var
|
var
|
||||||
l, p, LineStart: integer;
|
l, p, LineStart: integer;
|
||||||
|
Loading…
Reference in New Issue
Block a user