소스 검색

fcl-js: added example srcmapdump

git-svn-id: trunk@37263 -
Mattias Gaertner 7 년 전
부모
커밋
4b4e40c98e
3개의 변경된 파일181개의 추가작업 그리고 0개의 파일을 삭제
  1. 2 0
      .gitattributes
  2. 60 0
      packages/fcl-js/examples/srcmapdump.lpi
  3. 119 0
      packages/fcl-js/examples/srcmapdump.lpr

+ 2 - 0
.gitattributes

@@ -2507,6 +2507,8 @@ packages/fcl-js/Makefile.fpc svneol=native#text/plain
 packages/fcl-js/Makefile.fpc.fpcmake svneol=native#text/plain
 packages/fcl-js/README.TXT svneol=native#text/plain
 packages/fcl-js/examples/fpjsmin.pp svneol=native#text/plain
+packages/fcl-js/examples/srcmapdump.lpi svneol=native#text/plain
+packages/fcl-js/examples/srcmapdump.lpr svneol=native#text/plain
 packages/fcl-js/fpmake.pp svneol=native#text/plain
 packages/fcl-js/src/jsbase.pp svneol=native#text/plain
 packages/fcl-js/src/jsminifier.pp svneol=native#text/plain

+ 60 - 0
packages/fcl-js/examples/srcmapdump.lpi

@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<CONFIG>
+  <ProjectOptions>
+    <Version Value="10"/>
+    <General>
+      <Flags>
+        <MainUnitHasCreateFormStatements Value="False"/>
+        <MainUnitHasScaledStatement Value="False"/>
+      </Flags>
+      <SessionStorage Value="InProjectDir"/>
+      <MainUnit Value="0"/>
+      <Title Value="SrcMapDump"/>
+      <UseAppBundle Value="False"/>
+      <ResourceType Value="res"/>
+    </General>
+    <VersionInfo>
+      <StringTable ProductVersion=""/>
+    </VersionInfo>
+    <BuildModes Count="1">
+      <Item1 Name="Default" Default="True"/>
+    </BuildModes>
+    <PublishOptions>
+      <Version Value="2"/>
+    </PublishOptions>
+    <RunParams>
+      <local>
+        <FormatVersion Value="1"/>
+      </local>
+    </RunParams>
+    <Units Count="1">
+      <Unit0>
+        <Filename Value="srcmapdump.lpr"/>
+        <IsPartOfProject Value="True"/>
+      </Unit0>
+    </Units>
+  </ProjectOptions>
+  <CompilerOptions>
+    <Version Value="11"/>
+    <Target>
+      <Filename Value="srcmapdump"/>
+    </Target>
+    <SearchPaths>
+      <IncludeFiles Value="$(ProjOutDir)"/>
+      <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
+    </SearchPaths>
+  </CompilerOptions>
+  <Debugging>
+    <Exceptions Count="3">
+      <Item1>
+        <Name Value="EAbort"/>
+      </Item1>
+      <Item2>
+        <Name Value="ECodetoolError"/>
+      </Item2>
+      <Item3>
+        <Name Value="EFOpenError"/>
+      </Item3>
+    </Exceptions>
+  </Debugging>
+</CONFIG>

+ 119 - 0
packages/fcl-js/examples/srcmapdump.lpr

@@ -0,0 +1,119 @@
+program srcmapdump;
+
+{$mode objfpc}{$H+}
+
+uses
+  {$IFDEF UNIX}{$IFDEF UseCThreads}
+  cthreads,
+  {$ENDIF}{$ENDIF}
+  Classes, SysUtils, CustApp, JSSrcMap;
+
+type
+
+  { TSrcMapDump }
+
+  TSrcMapDump = class(TCustomApplication)
+  protected
+    procedure DoRun; override;
+    procedure DumpSrcMap(SrcMapFile, aGeneratedFilename: string);
+  public
+    constructor Create(TheOwner: TComponent); override;
+    destructor Destroy; override;
+    procedure WriteHelp; virtual;
+  end;
+
+{ TSrcMapDump }
+
+procedure TSrcMapDump.DoRun;
+var
+  ErrorMsg, SrcMapFilename, GeneratedFilename: String;
+begin
+  // quick check parameters
+  ErrorMsg:=CheckOptions('hs:g:', 'help srcmap: generatedfile:');
+  if ErrorMsg<>'' then begin
+    ShowException(Exception.Create(ErrorMsg));
+    Terminate;
+    Exit;
+  end;
+
+  // parse parameters
+  if HasOption('h', 'help') then begin
+    WriteHelp;
+    Terminate;
+    Exit;
+  end;
+
+  if not HasOption('s','srcmap') then begin
+    writeln('missing -s >srcmap>');
+    WriteHelp;
+    Terminate;
+    Exit;
+  end;
+  SrcMapFilename:=ExpandFileName(GetOptionValue('s','srcmap'));
+
+  if not HasOption('g','generatedfile') then begin
+    writeln('missing -g <generatedfile>');
+    WriteHelp;
+    Terminate;
+    Exit;
+  end;
+  GeneratedFilename:=ExpandFileName(GetOptionValue('g','generatedfile'));
+
+  DumpSrcMap(SrcMapFilename,GeneratedFilename);
+
+  // stop program loop
+  Terminate;
+end;
+
+procedure TSrcMapDump.DumpSrcMap(SrcMapFile, aGeneratedFilename: string);
+var
+  SrcMap: TSourceMap;
+  GenSrc: TStringList;
+  i: Integer;
+  GenSrcLine, InfoLine: String;
+begin
+  GenSrc:=TStringList.Create;
+  SrcMap:=TSourceMap.Create(aGeneratedFilename);
+  try
+    SrcMap.LoadFromFile(SrcMapFile);
+    GenSrc.LoadFromFile(aGeneratedFilename);
+    for i:=1 to GenSrc.Count do begin
+      GenSrcLine:=GenSrc[i-1];
+      DebugSrcMapLine(i,GenSrcLine,SrcMap,InfoLine);
+      writeln(GenSrcLine);
+      writeln(InfoLine);
+    end;
+  finally
+    SrcMap.Free;
+    GenSrc.Free;
+  end;
+end;
+
+constructor TSrcMapDump.Create(TheOwner: TComponent);
+begin
+  inherited Create(TheOwner);
+  StopOnException:=True;
+end;
+
+destructor TSrcMapDump.Destroy;
+begin
+  inherited Destroy;
+end;
+
+procedure TSrcMapDump.WriteHelp;
+begin
+  writeln('Usage: ', ExeName, ' -h');
+  writeln;
+  writeln('-s <srcmap>');
+  writeln('-g <generatedfile>');
+end;
+
+var
+  Application: TSrcMapDump;
+begin
+  Application:=TSrcMapDump.Create(nil);
+  Application.Title:='SrcMapDump';
+  Application.Run;
+  Application.Free;
+end.
+