ranger-compiler 3.4.0 → 3.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.js CHANGED
@@ -11,7 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ContextTransaction = exports.RangerNodeList = exports.RangerOperatorList = exports.OpFindResult = exports.RangerAppEnum = exports.RangerBackReference = exports.RangerNodeValue = exports.TypeCounts = exports.TTypeRegistry = exports.CodeNode = exports.CodeNodeLiteral = exports.SourceCode = exports.RangerTypeClass = exports.RangerAppClassDesc = exports.RangerTraitParams = exports.RangerAppInterfaceImpl = exports.RangerAppMethodVariants = exports.ShapeGroupMethodSlot = exports.ShapeViewDesc = exports.RangerAppFunctionDesc = exports.RangerAppParamDesc = exports.RangerRefForce = exports.RangerAppValue = exports.RangerAppHashValue = exports.RangerAppArrayValue = exports.RangerParamEventMap = exports.RangerParamEventList = exports.RangerParamEventHandler = exports.RangerApiPackageWriter = exports.RangerApiArtifactWriter = exports.RangerDocCommentWriter = exports.RangerApiBuilder = exports.RangerApiModel = exports.RangerApiClass = exports.RangerApiField = exports.RangerApiMethod = exports.RangerApiParam = exports.RangerDocReader = exports.RangerDocBlock = exports.RangerDocDeprecation = exports.RangerDocParam = exports.RangerCompilerMessage = exports.RangerAppTodo = exports.test_input_filesystem = exports.InputEnv = exports.InputFileResolver = exports.InputFSFile = exports.InputFSFolder = exports.test_cmdparams = exports.CmdParams = void 0;
13
13
  exports.RangerPHPClassWriter = exports.RangerGolangHttpServerWriter = exports.RangerGolangClassWriter = exports.RangerScalaClassWriter = exports.RangerCSharpClassWriter = exports.RangerDartClassWriter = exports.RangerKotlinClassWriter = exports.RangerRustClassWriter = exports.MethodCallList = exports.RangerCppClassWriter = exports.RangerSwift6ClassWriter = exports.RangerSwift3ClassWriter = exports.RangerJava7ClassWriter = exports.AndroidPageWriter = exports.RangerGenericClassWriter = exports.NodeEvalState = exports.CallChain = exports.TFactory = exports.RangerFlowParser = exports.RangerFnParts = exports.WalkLater = exports.ClassJoinPoint = exports.PkgImport = exports.PkgJRead = exports.PkgJVal = exports.PkgHit = exports.TFiles = exports.RangerAppOperatorDesc = exports.RangerServiceBuilder = exports.RangerProcessCodegen = exports.RangerProcessProcStartCheck = exports.RangerProcessProcSend = exports.RangerProcessClass = exports.RangerProcessLifecycle = exports.RangerImmutableExtension = exports.RangerSerializeClass = exports.DictNode = exports.RangerArgMatch = exports.TTypes = exports.RangerLispParser = exports.CodeWriter = exports.CodeSlice = exports.CodeFileSystem = exports.CodeFile = exports.RangerSourceFormat = exports.SourceMapBuilder = exports.SourceMapEntry = exports.RangerAppWriterContext = exports.RangerRegisteredPlugin = exports.ContextTransactionMutation = void 0;
14
- exports.CompilerInterface = exports.VirtualCompiler = exports.CompilerResults = exports.viewbuilder_Web = exports.viewbuilder_Android = exports.StaticAnalyzer = exports.RangerDocGenerator = exports.CLIProgress = exports.ColorConsole = exports.LiveCompiler = exports.RangerActiveOperators = exports.OpList = exports.RangerLLVMClassWriter = exports.RangerLLVMPipeline = exports.WATWriter = exports.LLVMIRWriter = exports.LowIRBuilderPass = exports.LambdaCaptureInfo = exports.LowIRLowerContext = exports.LowIRTarget = exports.LowIRRuntimeGen = exports.LowIRBuilder = exports.LowIRSession = exports.LowIRModule = exports.LowIRExternDecl = exports.LowIRStringGlobal = exports.LowIRStruct = exports.LowIRTypeDesc = exports.LowIRTypeFieldDesc = exports.LowIRField = exports.LowIRFunction = exports.LowIRBlock = exports.LowIRInstr = exports.LowIRParam = exports.LowIRUtil = exports.RangerRangerClassWriter = exports.RangerJavaScriptClassWriter = exports.WebPageWriter = exports.RangerPythonClassWriter = void 0;
14
+ exports.GitEntry = exports.GitPackIO = exports.GitDelta = exports.GitPack = exports.GitObj = exports.GitZlib = exports.Inflate = exports.InflateBitReader = exports.InflateHuffmanTable = exports.GrowableZipBuffer = exports.ZipBuffer = exports.GitPktIO = exports.GitSideband = exports.GitWant = exports.GitAdvertisement = exports.GitRef = exports.GitPkt = exports.GitSha1 = exports.CLIProgress = exports.ColorConsole = exports.LiveCompiler = exports.RangerActiveOperators = exports.OpList = exports.RangerLLVMClassWriter = exports.RangerLLVMPipeline = exports.WATWriter = exports.LLVMIRWriter = exports.LowIRBuilderPass = exports.LambdaCaptureInfo = exports.LowIRLowerContext = exports.LowIRTarget = exports.LowIRRuntimeGen = exports.LowIRBuilder = exports.LowIRSession = exports.LowIRModule = exports.LowIRExternDecl = exports.LowIRStringGlobal = exports.LowIRStruct = exports.LowIRTypeDesc = exports.LowIRTypeFieldDesc = exports.LowIRField = exports.LowIRFunction = exports.LowIRBlock = exports.LowIRInstr = exports.LowIRParam = exports.LowIRUtil = exports.RangerRangerClassWriter = exports.RangerJavaScriptClassWriter = exports.WebPageWriter = exports.RangerPythonClassWriter = void 0;
15
+ exports.CompilerInterface = exports.VirtualCompiler = exports.CompilerResults = exports.viewbuilder_Web = exports.viewbuilder_Android = exports.StaticAnalyzer = exports.RangerDocGenerator = exports.PkgFetch = exports.PkgFetchWork = exports.PkgCache = exports.PkgManifestIO = exports.PkgLock = exports.PkgLockEnt = exports.PkgManifest = exports.PkgDep = exports.PkgJson = exports.PkgVal = exports.GitStore = exports.GitMem = exports.GitTree = exports.GitFile = void 0;
15
16
  class CmdParams {
16
17
  constructor() {
17
18
  this.flags = {};
@@ -15702,6 +15703,26 @@ class PkgImport {
15702
15703
  return 0 - 1;
15703
15704
  }
15704
15705
  ;
15706
+ static manifestChain(env, startDir, libraryPaths) {
15707
+ let dirs = [];
15708
+ const first = PkgImport.walkUp(env, startDir);
15709
+ if (first.length > 0) {
15710
+ dirs.push(first);
15711
+ }
15712
+ let i = libraryPaths.length - 1;
15713
+ while (i >= 0) {
15714
+ const cand = PkgImport.walkUp(env, libraryPaths[i]);
15715
+ if (cand.length > 0) {
15716
+ if (dirs.indexOf(cand) < 0) {
15717
+ dirs.push(cand);
15718
+ }
15719
+ }
15720
+ i = i - 1;
15721
+ }
15722
+ ;
15723
+ return dirs;
15724
+ }
15725
+ ;
15705
15726
  static resolve(env, startDir, spec, libraryPaths) {
15706
15727
  return __awaiter(this, void 0, void 0, function* () {
15707
15728
  const hit = new PkgHit();
@@ -15710,6 +15731,32 @@ class PkgImport {
15710
15731
  hit.name = PkgImport.stripDot(spec);
15711
15732
  return hit;
15712
15733
  }
15734
+ const dirs = PkgImport.manifestChain(env, startDir, libraryPaths);
15735
+ if (dirs.length == 0) {
15736
+ hit.err = "no ranger.json for " + spec;
15737
+ return hit;
15738
+ }
15739
+ let firstErr = "";
15740
+ let di = 0;
15741
+ while (di < dirs.length) {
15742
+ const got = yield PkgImport.resolveIn(env, dirs[di], spec);
15743
+ if (got.ok) {
15744
+ return got;
15745
+ }
15746
+ if (firstErr.length == 0) {
15747
+ firstErr = got.err;
15748
+ }
15749
+ di = di + 1;
15750
+ }
15751
+ ;
15752
+ hit.err = firstErr;
15753
+ return hit;
15754
+ });
15755
+ }
15756
+ ;
15757
+ static resolveIn(env, manDir, spec) {
15758
+ return __awaiter(this, void 0, void 0, function* () {
15759
+ const hit = new PkgHit();
15713
15760
  const rest = spec.substring(4, spec.length);
15714
15761
  let pkgName = rest;
15715
15762
  let sub = "";
@@ -15718,11 +15765,6 @@ class PkgImport {
15718
15765
  pkgName = rest.substring(0, slash);
15719
15766
  sub = rest.substring((slash + 1), rest.length);
15720
15767
  }
15721
- const manDir = PkgImport.findManifestDir(env, startDir, libraryPaths);
15722
- if (manDir.length == 0) {
15723
- hit.err = "no ranger.json for " + spec;
15724
- return hit;
15725
- }
15726
15768
  const manText = yield PkgImport.readText(env, manDir, "ranger.json");
15727
15769
  const reader = new PkgJRead();
15728
15770
  const man = reader.parse(manText);
@@ -15738,23 +15780,37 @@ class PkgImport {
15738
15780
  entry = PkgJRead.strOf(man, "entry");
15739
15781
  }
15740
15782
  else {
15783
+ let dep = new PkgJVal();
15784
+ let declared = false;
15741
15785
  const deps = PkgJRead.child(man, "dependencies");
15742
- if (typeof (deps) === "undefined") {
15743
- hit.err = ("package " + pkgName) + " is not in ranger.json";
15744
- return hit;
15786
+ if ((typeof (deps) !== "undefined" && deps != null)) {
15787
+ const depMap = deps;
15788
+ const specObj = PkgJRead.child(depMap, pkgName);
15789
+ if ((typeof (specObj) !== "undefined" && specObj != null)) {
15790
+ dep = specObj;
15791
+ declared = true;
15792
+ }
15745
15793
  }
15746
- const depMap = deps;
15747
- const specObj = PkgJRead.child(depMap, pkgName);
15748
- if (typeof (specObj) === "undefined") {
15749
- hit.err = ("package " + pkgName) + " is not a dependency";
15750
- return hit;
15794
+ if (declared == false) {
15795
+ const lockOnly = yield PkgImport.readText(env, manDir, "ranger.lock");
15796
+ const lockHit = PkgImport.lockRoot(env, lockOnly, pkgName, manDir);
15797
+ if (lockHit.length == 0) {
15798
+ hit.err = ("package " + pkgName) + " is not a dependency";
15799
+ return hit;
15800
+ }
15801
+ pkgRoot = lockHit;
15751
15802
  }
15752
- const dep = specObj;
15753
- const pathDep = PkgJRead.strOf(dep, "path");
15754
- if (pathDep.length > 0) {
15755
- pkgRoot = PkgImport.foldPath(PkgImport.joinPath(manDir, pathDep));
15803
+ let pathDep = "";
15804
+ if (declared) {
15805
+ pathDep = PkgJRead.strOf(dep, "path");
15756
15806
  }
15757
- else {
15807
+ if (pathDep.length > 0 && pkgRoot.length == 0) {
15808
+ const cand = PkgImport.foldPath(PkgImport.joinPath(manDir, pathDep));
15809
+ if (operatorsOf_8.filec95exists_9(env, cand, "ranger.json")) {
15810
+ pkgRoot = cand;
15811
+ }
15812
+ }
15813
+ if (pkgRoot.length == 0) {
15758
15814
  const vendorDir = PkgImport.joinPath(manDir, ("vendor/ranger/" + pkgName));
15759
15815
  if (operatorsOf_8.filec95exists_9(env, vendorDir, "ranger.json")) {
15760
15816
  pkgRoot = vendorDir;
@@ -20008,6 +20064,11 @@ class RangerFlowParser {
20008
20064
  if (ctx.hasCompilerFlag("verbose")) {
20009
20065
  console.log((("importing " + import_file) + " from ") + filePathIs);
20010
20066
  }
20067
+ const seenKey = "@" + PkgImport.foldPath(((filePathIs + "/") + searchName));
20068
+ if ((typeof (ctx.already_imported[seenKey]) != "undefined" && Object.prototype.hasOwnProperty.call(ctx.already_imported, seenKey))) {
20069
+ return;
20070
+ }
20071
+ ctx.already_imported[seenKey] = true;
20011
20072
  const c = yield operatorsOf_8.readc95file_9(env, filePathIs, searchName);
20012
20073
  source_code = c;
20013
20074
  const fullPath = (filePathIs + "/") + searchName;
@@ -22678,23 +22739,19 @@ class RangerFlowParser {
22678
22739
  }
22679
22740
  }
22680
22741
  ;
22681
- const cClassList = this.serializedClasses.slice().sort(((left, right) => {
22742
+ const cClassList = this.serializedClasses.slice().sort(((left, right) => __awaiter(this, void 0, void 0, function* () {
22682
22743
  let left_had = false;
22683
22744
  let right_had = false;
22684
- for (let i_6 = 0; i_6 < left.variables.length; i_6++) {
22685
- var item = left.variables[i_6];
22745
+ yield operatorsOf.forEach_11(left.variables, ((item, index) => {
22686
22746
  if (item.nameNode.type_name == right.name || item.nameNode.array_type == right.name) {
22687
22747
  left_had = true;
22688
22748
  }
22689
- }
22690
- ;
22691
- for (let i_7 = 0; i_7 < right.variables.length; i_7++) {
22692
- var item_1 = right.variables[i_7];
22693
- if (item_1.nameNode.type_name == left.name || item_1.nameNode.array_type == left.name) {
22749
+ }));
22750
+ yield operatorsOf.forEach_11(right.variables, ((item, index) => {
22751
+ if (item.nameNode.type_name == left.name || item.nameNode.array_type == left.name) {
22694
22752
  right_had = true;
22695
22753
  }
22696
- }
22697
- ;
22754
+ }));
22698
22755
  if (left_had) {
22699
22756
  return 1;
22700
22757
  }
@@ -22702,14 +22759,14 @@ class RangerFlowParser {
22702
22759
  return -1;
22703
22760
  }
22704
22761
  return 0;
22705
- }));
22706
- for (let i_8 = 0; i_8 < cClassList.length; i_8++) {
22707
- var cl_1 = cClassList[i_8];
22762
+ })));
22763
+ for (let i_6 = 0; i_6 < cClassList.length; i_6++) {
22764
+ var cl_1 = cClassList[i_6];
22708
22765
  cl_1.is_serialized = true;
22709
22766
  }
22710
22767
  ;
22711
- for (let i_9 = 0; i_9 < cClassList.length; i_9++) {
22712
- var cl_2 = cClassList[i_9];
22768
+ for (let i_7 = 0; i_7 < cClassList.length; i_7++) {
22769
+ var cl_2 = cClassList[i_7];
22713
22770
  const ser = new RangerSerializeClass();
22714
22771
  if (ser.validateSerializedClass(cl_2, cl_2.ctx) == false) {
22715
22772
  continue;
@@ -22726,8 +22783,8 @@ class RangerFlowParser {
22726
22783
  this.walkAlso.push(rn);
22727
22784
  }
22728
22785
  ;
22729
- for (let i_10 = 0; i_10 < this.immutableClasses.length; i_10++) {
22730
- var cl_3 = this.immutableClasses[i_10];
22786
+ for (let i_8 = 0; i_8 < this.immutableClasses.length; i_8++) {
22787
+ var cl_3 = this.immutableClasses[i_8];
22731
22788
  const ser_1 = new RangerImmutableExtension();
22732
22789
  const extWr_1 = new CodeWriter();
22733
22790
  ser_1.createImmutableExtension(cl_3, cl_3.ctx, extWr_1);
@@ -22775,12 +22832,12 @@ class RangerFlowParser {
22775
22832
  ctx.compilerSettings["processTsHelpers"] = tsWr.getCode();
22776
22833
  }
22777
22834
  }
22778
- for (let i_11 = 0; i_11 < this.processClasses.length; i_11++) {
22779
- var cl_4 = this.processClasses[i_11];
22835
+ for (let i_9 = 0; i_9 < this.processClasses.length; i_9++) {
22836
+ var cl_4 = this.processClasses[i_9];
22780
22837
  cl_4.is_process = true;
22781
22838
  let hasProcessBase = false;
22782
- for (let i_12 = 0; i_12 < cl_4.extends_classes.length; i_12++) {
22783
- var extName = cl_4.extends_classes[i_12];
22839
+ for (let i_10 = 0; i_10 < cl_4.extends_classes.length; i_10++) {
22840
+ var extName = cl_4.extends_classes[i_10];
22784
22841
  if (extName == "RangerProcessBase") {
22785
22842
  hasProcessBase = true;
22786
22843
  }
@@ -22797,7 +22854,7 @@ class RangerFlowParser {
22797
22854
  }
22798
22855
  const procGen = new RangerProcessClass();
22799
22856
  const extWr_2 = new CodeWriter();
22800
- const processTypeId = i_11 + 1;
22857
+ const processTypeId = i_9 + 1;
22801
22858
  procGen.createProcessExtension(cl_4, cl_4.ctx, extWr_2, processTypeId);
22802
22859
  const theCode_2 = extWr_2.getCode();
22803
22860
  const code_2 = new SourceCode(theCode_2);
@@ -22809,16 +22866,16 @@ class RangerFlowParser {
22809
22866
  this.walkAlso.push(rn_2);
22810
22867
  }
22811
22868
  ;
22812
- for (let i_13 = 0; i_13 < ctx.definedClassList.length; i_13++) {
22813
- var cname = ctx.definedClassList[i_13];
22869
+ for (let i_11 = 0; i_11 < ctx.definedClassList.length; i_11++) {
22870
+ var cname = ctx.definedClassList[i_11];
22814
22871
  allTypes.push(cname);
22815
22872
  const c = (Object.prototype.hasOwnProperty.call(ctx.definedClasses, cname) ? ctx.definedClasses[cname] : undefined);
22816
22873
  if (((c.is_system || c.is_interface) || c.is_template) || c.is_trait) {
22817
22874
  continue;
22818
22875
  }
22819
22876
  let varNames = {};
22820
- for (let i_14 = 0; i_14 < c.variables.length; i_14++) {
22821
- var p = c.variables[i_14];
22877
+ for (let i_12 = 0; i_12 < c.variables.length; i_12++) {
22878
+ var p = c.variables[i_12];
22822
22879
  ctx.hadValidType(p.nameNode);
22823
22880
  varNames[p.name] = true;
22824
22881
  }
@@ -22832,8 +22889,8 @@ class RangerFlowParser {
22832
22889
  })));
22833
22890
  }
22834
22891
  ;
22835
- for (let i_15 = 0; i_15 < ctx.definedClassList.length; i_15++) {
22836
- var cname_1 = ctx.definedClassList[i_15];
22892
+ for (let i_13 = 0; i_13 < ctx.definedClassList.length; i_13++) {
22893
+ var cname_1 = ctx.definedClassList[i_13];
22837
22894
  allTypes.push(cname_1);
22838
22895
  }
22839
22896
  ;
@@ -22849,8 +22906,8 @@ class RangerFlowParser {
22849
22906
  rootCtx.addClass("Any", new_class);
22850
22907
  new_class.is_union = true;
22851
22908
  let did_push = {};
22852
- for (let i_16 = 0; i_16 < allTypes.length; i_16++) {
22853
- var typeName_1 = allTypes[i_16];
22909
+ for (let i_14 = 0; i_14 < allTypes.length; i_14++) {
22910
+ var typeName_1 = allTypes[i_14];
22854
22911
  if ((typeof (did_push[typeName_1]) != "undefined" && Object.prototype.hasOwnProperty.call(did_push, typeName_1))) {
22855
22912
  continue;
22856
22913
  }
@@ -23518,6 +23575,16 @@ class RangerFlowParser {
23518
23575
  ctx.addError(node, "Could not import file " + import_file);
23519
23576
  return;
23520
23577
  }
23578
+ const seenKey2 = "@" + PkgImport.foldPath(((filePathIs + "/") + searchName));
23579
+ if ((typeof (ctx.already_imported[seenKey2]) != "undefined" && Object.prototype.hasOwnProperty.call(ctx.already_imported, seenKey2))) {
23580
+ for (let i2 = 0; i2 < node.children.length; i2++) {
23581
+ var item2 = node.children[i2];
23582
+ yield this.WalkCollectMethods(item2, ctx, wr);
23583
+ }
23584
+ ;
23585
+ return;
23586
+ }
23587
+ ctx.already_imported[seenKey2] = true;
23521
23588
  const c = yield operatorsOf_8.readc95file_9(env, filePathIs, searchName);
23522
23589
  const code = new SourceCode(c);
23523
23590
  code.filename = import_file;
@@ -69791,7 +69858,7 @@ class CLIProgress {
69791
69858
  this.inputFile = "";
69792
69859
  this.outputFile = "";
69793
69860
  this.targetLanguage = "";
69794
- this.compilerVersion = "3.4.0";
69861
+ this.compilerVersion = "3.5.1";
69795
69862
  this.useColors = ((typeof process !== "undefined" && process.stdout && process.stdout.isTTY) || false);
69796
69863
  this.startTime = Date.now();
69797
69864
  }
@@ -70127,400 +70194,3974 @@ class CLIProgress {
70127
70194
  ;
70128
70195
  }
70129
70196
  exports.CLIProgress = CLIProgress;
70130
- class RangerDocGenerator {
70197
+ class GitSha1 {
70131
70198
  constructor() {
70132
70199
  }
70133
- writeTypeDef(item, ctx, wr) {
70134
- return __awaiter(this, void 0, void 0, function* () {
70135
- if (item.hasFlag("optional")) {
70136
- wr.out("<optional>", false);
70137
- }
70138
- switch (item.value_type) {
70139
- case 6:
70140
- wr.out(("[" + item.array_type) + "]", false);
70141
- break;
70142
- case 7:
70143
- wr.out(((("[" + item.key_type) + ":") + item.array_type) + "]", false);
70144
- break;
70145
- case 20:
70146
- wr.out("(fn:", false);
70147
- try {
70148
- const rv = item.expression_value.children[0];
70149
- const args = item.expression_value.children[1];
70150
- yield this.writeTypeDef(rv, ctx, wr);
70151
- wr.out(" (", false);
70152
- yield operatorsOf.forEach_15(args.children, ((item, index) => __awaiter(this, void 0, void 0, function* () {
70153
- if (index > 0) {
70154
- wr.out(", ", false);
70155
- }
70156
- wr.out(item.vref, false);
70157
- wr.out(": ", false);
70158
- yield this.writeTypeDef(item, ctx, wr);
70159
- })));
70160
- wr.out(")", false);
70161
- }
70162
- catch (e) {
70163
- }
70164
- wr.out(")", false);
70165
- break;
70166
- default:
70167
- if (item.type_name.length > 0) {
70168
- wr.out("" + item.type_name, false);
70169
- }
70170
- break;
70171
- }
70172
- ;
70173
- });
70200
+ static mask32() {
70201
+ return (65535 | (65535 << 16));
70174
70202
  }
70175
70203
  ;
70176
- writeArgDefs(node, ctx, wr) {
70177
- return __awaiter(this, void 0, void 0, function* () {
70178
- yield operatorsOf.forEach_15(node.children, ((item, index) => __awaiter(this, void 0, void 0, function* () {
70179
- if (index > 0) {
70180
- wr.out(" ", false);
70181
- }
70182
- wr.out(("`" + item.vref) + "`", false);
70183
- wr.out(":", false);
70184
- yield this.writeTypeDef(item, ctx, wr);
70185
- wr.out(" ", false);
70186
- })));
70187
- });
70204
+ static add32(a, b) {
70205
+ return ((a + b) & GitSha1.mask32());
70188
70206
  }
70189
70207
  ;
70190
- createClassDoc(node, ctx, orig_wr) {
70191
- return __awaiter(this, void 0, void 0, function* () {
70192
- if (ctx.hasCompilerSetting("classdoc")) {
70193
- const b_only_documented = false == ctx.hasCompilerFlag("allowempty");
70194
- const wr = orig_wr.getFileWriter(".", ctx.getCompilerSetting("classdoc"));
70195
- if (b_only_documented == false) {
70196
- wr.out("# Classes", true);
70208
+ static not32(x) {
70209
+ return ((~x) & GitSha1.mask32());
70210
+ }
70211
+ ;
70212
+ static rotl(x, n) {
70213
+ const u = (x & GitSha1.mask32());
70214
+ return (((u << n) | (u >>> (32 - n))) & GitSha1.mask32());
70215
+ }
70216
+ ;
70217
+ static copyRange(data, start, count) {
70218
+ let n = count;
70219
+ const __len = data.byteLength;
70220
+ if (start < 0) {
70221
+ return (function () { var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
70222
+ }
70223
+ if (start >= __len) {
70224
+ return (function () { var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
70225
+ }
70226
+ if (start + n > __len) {
70227
+ n = __len - start;
70228
+ }
70229
+ if (n < 0) {
70230
+ n = 0;
70231
+ }
70232
+ let out = (function () { var b = new ArrayBuffer(n); b._view = new DataView(b); return b; })();
70233
+ (function (d, dOff, s, sOff, len) { var dv = new Uint8Array(d); var sv = new Uint8Array(s); for (var i = 0; i < len; i++)
70234
+ dv[dOff + i] = sv[sOff + i]; })(out, 0, data, start, n);
70235
+ return out;
70236
+ }
70237
+ ;
70238
+ static ascii(data, start, count) {
70239
+ let n = count;
70240
+ const __len = data.byteLength;
70241
+ if (start + n > __len) {
70242
+ n = __len - start;
70243
+ }
70244
+ if (n < 0) {
70245
+ n = 0;
70246
+ }
70247
+ let s = "";
70248
+ let i = 0;
70249
+ while (i < n) {
70250
+ s = s + String.fromCharCode(data._view.getUint8((start + i)));
70251
+ i = i + 1;
70252
+ }
70253
+ ;
70254
+ return s;
70255
+ }
70256
+ ;
70257
+ static u32be(data, i) {
70258
+ const b0 = data._view.getUint8(i);
70259
+ const b1 = data._view.getUint8((i + 1));
70260
+ const b2 = data._view.getUint8((i + 2));
70261
+ const b3 = data._view.getUint8((i + 3));
70262
+ return ((b0 << 24) | ((b1 << 16) | ((b2 << 8) | b3)));
70263
+ }
70264
+ ;
70265
+ static hexDigit(d) {
70266
+ const h = "0123456789abcdef";
70267
+ return h.substring(d, (d + 1));
70268
+ }
70269
+ ;
70270
+ static toHex(data) {
70271
+ const n = data.byteLength;
70272
+ let s = "";
70273
+ let i = 0;
70274
+ while (i < n) {
70275
+ const b = data._view.getUint8(i);
70276
+ const hi = (b >>> 4);
70277
+ const lo = (b & 15);
70278
+ s = s + GitSha1.hexDigit(hi);
70279
+ s = s + GitSha1.hexDigit(lo);
70280
+ i = i + 1;
70281
+ }
70282
+ ;
70283
+ return s;
70284
+ }
70285
+ ;
70286
+ static fromHex(hex) {
70287
+ const n = hex.length;
70288
+ const outLen = ((n / 2) | 0);
70289
+ let out = (function () { var b = new ArrayBuffer(outLen); b._view = new DataView(b); return b; })();
70290
+ const digits = "0123456789abcdef";
70291
+ let i = 0;
70292
+ while (i < outLen) {
70293
+ const c0 = hex.substring((i * 2), (i * 2 + 1));
70294
+ const c1 = hex.substring((i * 2 + 1), (i * 2 + 2));
70295
+ let v = 0;
70296
+ let d = 0;
70297
+ while (d < 16) {
70298
+ const ch = digits.substring(d, (d + 1));
70299
+ if (ch == c0) {
70300
+ v = d * 16;
70197
70301
  }
70198
- const root = ctx.getRoot();
70199
- yield operatorsOf_13.forEach_14(root.definedClasses, ((item, index) => __awaiter(this, void 0, void 0, function* () {
70200
- if (false == item.isNormalClass()) {
70201
- return;
70202
- }
70203
- if (b_only_documented == false) {
70204
- wr.out("## " + index, true);
70205
- }
70206
- const theClass = item;
70207
- yield operatorsOf_13.forEach_31(item.method_variants, ((item, index) => __awaiter(this, void 0, void 0, function* () {
70208
- yield operatorsOf.forEach_29(item.variants, ((item, index) => __awaiter(this, void 0, void 0, function* () {
70209
- if (b_only_documented) {
70210
- if (item.git_doc.length == 0) {
70211
- return;
70212
- }
70213
- }
70214
- wr.out("#### ", false);
70215
- if (typeof (item.nameNode) != "undefined") {
70216
- if (item.nameNode.type_name != "void") {
70217
- wr.out("`", false);
70218
- yield this.writeTypeDef(item.nameNode, ctx, wr);
70219
- wr.out("` ", false);
70220
- }
70221
- }
70222
- wr.out((theClass.name + ":: ") + item.name, false);
70223
- wr.out("(", false);
70224
- for (let i = 0; i < item.params.length; i++) {
70225
- var arg = item.params[i];
70226
- if (i > 0) {
70227
- wr.out(" ", false);
70228
- }
70229
- wr.out(("`" + arg.compiledName) + "`", false);
70230
- wr.out(":", false);
70231
- yield this.writeTypeDef(arg.nameNode, ctx, wr);
70232
- }
70233
- ;
70234
- wr.out(")", false);
70235
- wr.out("", true);
70236
- wr.out(item.git_doc, false);
70237
- wr.out("", true);
70238
- })));
70239
- })));
70240
- })));
70302
+ d = d + 1;
70241
70303
  }
70242
- });
70304
+ ;
70305
+ d = 0;
70306
+ while (d < 16) {
70307
+ const ch2 = digits.substring(d, (d + 1));
70308
+ if (ch2 == c1) {
70309
+ v = v + d;
70310
+ }
70311
+ d = d + 1;
70312
+ }
70313
+ ;
70314
+ out._view.setUint8(i, v);
70315
+ i = i + 1;
70316
+ }
70317
+ ;
70318
+ return out;
70243
70319
  }
70244
70320
  ;
70245
- writeOpDesc(item, ctx, wr) {
70246
- return __awaiter(this, void 0, void 0, function* () {
70247
- const fc = item.getFirst();
70248
- const nameNode = item.getSecond();
70249
- const args = item.getThird();
70250
- wr.out("| ", false);
70251
- let name = fc.vref;
70252
- if (fc.vref == "||") {
70253
- name = "&#124;&#124;";
70254
- }
70255
- if (fc.vref == "|") {
70256
- name = "&#124;";
70321
+ static hash(data) {
70322
+ const L = data.byteLength;
70323
+ const cap = L + 128;
70324
+ let msg = (function () { var b = new ArrayBuffer(cap); b._view = new DataView(b); return b; })();
70325
+ if (L > 0) {
70326
+ (function (d, dOff, s, sOff, len) { var dv = new Uint8Array(d); var sv = new Uint8Array(s); for (var i = 0; i < len; i++)
70327
+ dv[dOff + i] = sv[sOff + i]; })(msg, 0, data, 0, L);
70328
+ }
70329
+ msg._view.setUint8(L, 128);
70330
+ let pos = L + 1;
70331
+ while ((pos & 63) != 56) {
70332
+ msg._view.setUint8(pos, 0);
70333
+ pos = pos + 1;
70334
+ }
70335
+ ;
70336
+ const bitLen = L * 8;
70337
+ msg._view.setUint8(pos, 0);
70338
+ msg._view.setUint8(pos + 1, 0);
70339
+ msg._view.setUint8(pos + 2, 0);
70340
+ msg._view.setUint8(pos + 3, 0);
70341
+ msg._view.setUint8(pos + 4, ((bitLen >>> 24) & 255));
70342
+ msg._view.setUint8(pos + 5, ((bitLen >>> 16) & 255));
70343
+ msg._view.setUint8(pos + 6, ((bitLen >>> 8) & 255));
70344
+ msg._view.setUint8(pos + 7, (bitLen & 255));
70345
+ const msgLen = pos + 8;
70346
+ let h0 = 1732584193;
70347
+ let h1 = 0 - 271733879;
70348
+ let h2 = 0 - 1732584194;
70349
+ let h3 = 271733878;
70350
+ let h4 = 0 - 1009589776;
70351
+ let w = [];
70352
+ let wi = 0;
70353
+ while (wi < 80) {
70354
+ w.push(0);
70355
+ wi = wi + 1;
70356
+ }
70357
+ ;
70358
+ let off = 0;
70359
+ while (off < msgLen) {
70360
+ let t = 0;
70361
+ while (t < 16) {
70362
+ w[t] = GitSha1.u32be(msg, (off + t * 4));
70363
+ t = t + 1;
70257
70364
  }
70258
- wr.out(name, false);
70259
- wr.out(" | ", false);
70260
- if (nameNode.type_name != "void") {
70261
- wr.out("`", false);
70262
- yield this.writeTypeDef(nameNode, ctx, wr);
70263
- wr.out("` ", false);
70365
+ ;
70366
+ while (t < 80) {
70367
+ const x = ((w[(t - 3)] ^ w[(t - 8)]) ^ (w[(t - 14)] ^ w[(t - 16)]));
70368
+ w[t] = GitSha1.rotl(x, 1);
70369
+ t = t + 1;
70264
70370
  }
70265
- wr.out("| ", false);
70266
- wr.out(" (", false);
70267
- yield this.writeArgDefs(args, ctx, wr);
70268
- wr.out(" )", false);
70269
- wr.out("| ", false);
70270
- if (item.hasStringProperty("doc")) {
70271
- wr.out(item.getStringProperty("doc"), false);
70371
+ ;
70372
+ let a = h0;
70373
+ let b = h1;
70374
+ let c = h2;
70375
+ let d = h3;
70376
+ let e = h4;
70377
+ t = 0;
70378
+ while (t < 80) {
70379
+ let f = 0;
70380
+ let k = 0;
70381
+ if (t < 20) {
70382
+ f = ((b & c) | (GitSha1.not32(b) & d));
70383
+ k = 1518500249;
70384
+ }
70385
+ if (t >= 20 && t < 40) {
70386
+ f = ((b ^ c) ^ d);
70387
+ k = 1859775393;
70388
+ }
70389
+ if (t >= 40 && t < 60) {
70390
+ f = (((b & c) | (b & d)) | (c & d));
70391
+ k = 0 - 1894007588;
70392
+ }
70393
+ if (t >= 60) {
70394
+ f = ((b ^ c) ^ d);
70395
+ k = 0 - 899497514;
70396
+ }
70397
+ const temp = GitSha1.add32(GitSha1.add32(GitSha1.add32(GitSha1.add32(GitSha1.rotl(a, 5), f), e), k), w[t]);
70398
+ e = d;
70399
+ d = c;
70400
+ c = GitSha1.rotl(b, 30);
70401
+ b = a;
70402
+ a = temp;
70403
+ t = t + 1;
70272
70404
  }
70273
- wr.out("| ", false);
70274
- wr.out("", true);
70275
- });
70405
+ ;
70406
+ h0 = GitSha1.add32(h0, a);
70407
+ h1 = GitSha1.add32(h1, b);
70408
+ h2 = GitSha1.add32(h2, c);
70409
+ h3 = GitSha1.add32(h3, d);
70410
+ h4 = GitSha1.add32(h4, e);
70411
+ off = off + 64;
70412
+ }
70413
+ ;
70414
+ const out = (function () { var b = new ArrayBuffer(20); b._view = new DataView(b); return b; })();
70415
+ GitSha1.writeU32be(out, 0, h0);
70416
+ GitSha1.writeU32be(out, 4, h1);
70417
+ GitSha1.writeU32be(out, 8, h2);
70418
+ GitSha1.writeU32be(out, 12, h3);
70419
+ GitSha1.writeU32be(out, 16, h4);
70420
+ return out;
70276
70421
  }
70277
70422
  ;
70278
- writeTypeDoc(list, tester, ctx, wr) {
70279
- return __awaiter(this, void 0, void 0, function* () {
70280
- const www = wr.fork();
70281
- wr.out("", true);
70282
- wr.out("", true);
70283
- wr.out("| operator | returns | arguments | description |", true);
70284
- wr.out("| -------- | ------- | --------- | ------------| ", true);
70285
- let cnt = 0;
70286
- yield operatorsOf.forEach_17(list, ((item, index) => __awaiter(this, void 0, void 0, function* () {
70287
- if (yield tester(item)) {
70288
- if (cnt > 0) {
70289
- www.out(", ", false);
70290
- }
70291
- www.out((" `" + item.name) + "` ", false);
70292
- yield this.writeOpDesc(item.node, ctx, wr);
70293
- cnt = cnt + 1;
70294
- }
70295
- })));
70296
- });
70423
+ static writeU32be(out, i, v) {
70424
+ out._view.setUint8(i, ((v >>> 24) & 255));
70425
+ out._view.setUint8(i + 1, ((v >>> 16) & 255));
70426
+ out._view.setUint8(i + 2, ((v >>> 8) & 255));
70427
+ out._view.setUint8(i + 3, (v & 255));
70297
70428
  }
70298
70429
  ;
70299
- createOperatorDoc(node, ctx, orig_wr) {
70300
- return __awaiter(this, void 0, void 0, function* () {
70301
- if (ctx.hasCompilerSetting("operatordoc")) {
70302
- const wr = orig_wr.getFileWriter(".", ctx.getCompilerSetting("operatordoc"));
70303
- const allOps = yield ctx.getAllOperators();
70304
- let statements = operatorsOf.filter_52(allOps, ((item, index) => {
70305
- let is_map_array = false;
70306
- if (typeof (item.firstArg) != "undefined") {
70307
- is_map_array = item.firstArg.value_type == 6 || item.firstArg.value_type == 7;
70308
- }
70309
- if (item.name.indexOf("if_") == 0) {
70310
- return false;
70311
- }
70312
- return item.nameNode.type_name == "void" && false == is_map_array;
70313
- }));
70314
- const lang_statements = operatorsOf.filter_52(allOps, ((item, index) => {
70315
- if (item.name.indexOf("if_") == 0) {
70316
- return true;
70317
- }
70318
- return false;
70319
- }));
70320
- statements = operatorsOf.groupBy_53(statements, ((item) => {
70321
- return item.name;
70322
- }));
70323
- const operator_list = operatorsOf.filter_52(allOps, ((item, index) => {
70324
- let is_map_array_1 = false;
70325
- if (typeof (item.firstArg) != "undefined") {
70326
- is_map_array_1 = item.firstArg.value_type == 6 || item.firstArg.value_type == 7;
70327
- }
70328
- return is_map_array_1 || item.nameNode.type_name != "void";
70329
- }));
70330
- const nList = operatorsOf.groupBy_53(operator_list, ((item) => {
70331
- let key = item.name;
70332
- const fc = item.firstArg;
70333
- if (typeof (fc) != "undefined") {
70334
- key = key + (((((":" + fc.type_name) + ":") + fc.key_type) + ":") + fc.array_type);
70335
- }
70336
- return key;
70337
- }));
70338
- wr.out("## Statements", true);
70339
- yield this.writeTypeDoc(statements, ((item) => {
70340
- return true;
70341
- }), ctx, wr);
70342
- wr.out("", true);
70343
- wr.out("## Language switches", true);
70344
- yield this.writeTypeDoc(lang_statements, ((item) => {
70345
- return true;
70346
- }), ctx, wr);
70347
- wr.out("", true);
70348
- wr.out("## Operators without arguments", true);
70349
- yield this.writeTypeDoc(nList, ((item) => {
70350
- return typeof (item.firstArg) === "undefined";
70351
- }), ctx, wr);
70352
- wr.out("", true);
70353
- wr.out("## Generic operators", true);
70354
- yield this.writeTypeDoc(nList, ((item) => {
70355
- if (typeof (item.firstArg) != "undefined") {
70356
- return item.firstArg.type_name == "T";
70357
- }
70358
- return false;
70359
- }), ctx, wr);
70360
- wr.out("", true);
70361
- wr.out("## Numeric operators", true);
70362
- yield this.writeTypeDoc(nList, ((item) => {
70363
- if (typeof (item.firstArg) != "undefined") {
70364
- return (item.firstArg.type_name == "int" || item.firstArg.type_name == "double") && (item.nameNode.type_name == "int" || item.nameNode.type_name == "double");
70365
- }
70366
- return false;
70367
- }), ctx, wr);
70368
- wr.out("", true);
70369
- wr.out("## Miscellaneous operators", true);
70370
- yield this.writeTypeDoc(nList, ((item) => {
70371
- if (typeof (item.firstArg) != "undefined") {
70372
- return (item.firstArg.type_name == "int" || item.firstArg.type_name == "double") && ((item.nameNode.type_name != "int" && item.nameNode.type_name != "double") && item.nameNode.type_name != "boolean");
70373
- }
70374
- return false;
70375
- }), ctx, wr);
70376
- wr.out("", true);
70377
- wr.out("## String operators", true);
70378
- yield this.writeTypeDoc(nList, ((item) => {
70379
- if (typeof (item.firstArg) != "undefined") {
70380
- return item.firstArg.type_name == "string";
70381
- }
70382
- return false;
70383
- }), ctx, wr);
70384
- wr.out("", true);
70385
- wr.out("", true);
70386
- wr.out("## Array operators", true);
70387
- yield this.writeTypeDoc(nList, ((item) => {
70388
- if (typeof (item.firstArg) != "undefined") {
70389
- return item.firstArg.value_type == 6;
70390
- }
70391
- return false;
70392
- }), ctx, wr);
70393
- wr.out("", true);
70394
- wr.out("## Map operators", true);
70395
- yield this.writeTypeDoc(nList, ((item) => {
70396
- if (typeof (item.firstArg) != "undefined") {
70397
- return item.firstArg.value_type == 7;
70398
- }
70399
- return false;
70400
- }), ctx, wr);
70401
- wr.out("", true);
70402
- wr.out("## Boolean / test operators", true);
70403
- yield this.writeTypeDoc(nList, ((item) => {
70404
- if (typeof (item.firstArg) != "undefined") {
70405
- return item.nameNode.type_name == "boolean";
70406
- }
70407
- return false;
70408
- }), ctx, wr);
70409
- }
70410
- });
70430
+ static hashHex(data) {
70431
+ return GitSha1.toHex(GitSha1.hash(data));
70411
70432
  }
70412
70433
  ;
70413
- }
70414
- exports.RangerDocGenerator = RangerDocGenerator;
70415
- class StaticAnalyzer {
70416
- constructor() {
70417
- this.debug = false;
70418
- this.mutatingOps = {};
70419
- this.own_call_params = [];
70420
- this.own_call_callees = [];
70421
- this.own_call_indexes = [];
70422
- this.rss_edge_src = [];
70423
- this.rss_edge_dst = [];
70424
- this.rss_in_place = [];
70425
- }
70426
- initMutatingOps() {
70427
- this.mutatingOps["buffer_set"] = true;
70428
- this.mutatingOps["int_buffer_set"] = true;
70429
- this.mutatingOps["double_buffer_set"] = true;
70430
- this.mutatingOps["buffer_fill"] = true;
70431
- this.mutatingOps["int_buffer_fill"] = true;
70432
- this.mutatingOps["double_buffer_fill"] = true;
70433
- this.mutatingOps["buffer_copy"] = true;
70434
- this.mutatingOps["int_buffer_copy"] = true;
70435
- this.mutatingOps["double_buffer_copy"] = true;
70436
- this.mutatingOps["push"] = true;
70437
- this.mutatingOps["set"] = true;
70438
- this.mutatingOps["clear"] = true;
70439
- this.mutatingOps["remove"] = true;
70440
- this.mutatingOps["removeIndex"] = true;
70441
- this.mutatingOps["removeLast"] = true;
70442
- this.mutatingOps["removeFirst"] = true;
70443
- this.mutatingOps["set_at"] = true;
70444
- this.mutatingOps["remove_index"] = true;
70445
- this.mutatingOps["array_extract"] = true;
70446
- this.mutatingOps["pushString"] = true;
70447
- this.mutatingOps["map_clear"] = true;
70448
- this.mutatingOps["insert"] = true;
70449
- this.mutatingOps["nullify"] = true;
70450
- this.mutatingOps["str_append"] = true;
70451
- this.mutatingOps["put"] = true;
70434
+ static objectId(kind, payload) {
70435
+ const sizeText = (payload.byteLength.toString());
70436
+ const prefix = (kind + " ") + sizeText;
70437
+ const pLen = prefix.length;
70438
+ const n = payload.byteLength;
70439
+ let raw = (function () { var b = new ArrayBuffer(((pLen + 1) + n)); b._view = new DataView(b); return b; })();
70440
+ let i = 0;
70441
+ while (i < pLen) {
70442
+ raw._view.setUint8(i, prefix.charCodeAt(i));
70443
+ i = i + 1;
70444
+ }
70445
+ ;
70446
+ raw._view.setUint8(pLen, 0);
70447
+ if (n > 0) {
70448
+ (function (d, dOff, s, sOff, len) { var dv = new Uint8Array(d); var sv = new Uint8Array(s); for (var i = 0; i < len; i++)
70449
+ dv[dOff + i] = sv[sOff + i]; })(raw, pLen + 1, payload, 0, n);
70450
+ }
70451
+ return GitSha1.hashHex(raw);
70452
70452
  }
70453
70453
  ;
70454
- isMutatingOperator(opName) {
70455
- if ((typeof (this.mutatingOps[opName]) != "undefined" && Object.prototype.hasOwnProperty.call(this.mutatingOps, opName))) {
70456
- return (Object.prototype.hasOwnProperty.call(this.mutatingOps, opName) ? this.mutatingOps[opName] : undefined);
70454
+ static hexEq(a, b) {
70455
+ if (a.length != b.length) {
70456
+ return false;
70457
70457
  }
70458
- return false;
70458
+ return a == b;
70459
70459
  }
70460
70460
  ;
70461
- isMutatingNode(node) {
70462
- if (node.expression == false) {
70463
- return false;
70461
+ }
70462
+ exports.GitSha1 = GitSha1;
70463
+ class GitPkt {
70464
+ constructor() {
70465
+ this.ok = true;
70466
+ this.err = "";
70467
+ this.lines = [];
70468
+ this.raw = [];
70469
+ this.isFlush = [];
70470
+ }
70471
+ }
70472
+ exports.GitPkt = GitPkt;
70473
+ class GitRef {
70474
+ constructor() {
70475
+ this.name = "";
70476
+ this.sha = "";
70477
+ this.peeled = "";
70478
+ }
70479
+ }
70480
+ exports.GitRef = GitRef;
70481
+ class GitAdvertisement {
70482
+ constructor() {
70483
+ this.ok = true;
70484
+ this.err = "";
70485
+ this.service = "";
70486
+ this.caps = "";
70487
+ this.head = "";
70488
+ this.refs = [];
70489
+ }
70490
+ }
70491
+ exports.GitAdvertisement = GitAdvertisement;
70492
+ class GitWant {
70493
+ constructor() {
70494
+ this.ok = true;
70495
+ this.err = "";
70496
+ this.sha = "";
70497
+ this.body = (function () { var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
70498
+ }
70499
+ }
70500
+ exports.GitWant = GitWant;
70501
+ class GitSideband {
70502
+ constructor() {
70503
+ this.ok = true;
70504
+ this.err = "";
70505
+ this.pack = (function () { var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
70506
+ this.progress = "";
70507
+ }
70508
+ }
70509
+ exports.GitSideband = GitSideband;
70510
+ class GitPktIO {
70511
+ constructor() {
70512
+ }
70513
+ static hexVal(ch) {
70514
+ const c = ch.charCodeAt(0);
70515
+ if (c >= 48 && c <= 57) {
70516
+ return c - 48;
70464
70517
  }
70465
- if (node.children.length == 0) {
70466
- return false;
70518
+ if (c >= 97 && c <= 102) {
70519
+ return c - 87;
70467
70520
  }
70468
- const first = node.getFirst();
70469
- if (first.vref.length > 0) {
70470
- return this.isMutatingOperator(first.vref);
70521
+ if (c >= 65 && c <= 70) {
70522
+ return c - 55;
70471
70523
  }
70472
- return false;
70524
+ return 0 - 1;
70473
70525
  }
70474
70526
  ;
70475
- getRootVarName(node) {
70476
- if (node.ns.length > 0) {
70477
- return node.ns[0];
70478
- }
70479
- if (node.vref.length > 0) {
70480
- return node.vref;
70481
- }
70482
- if (node.children.length > 0) {
70483
- const first = node.getFirst();
70484
- if (first.vref.length > 0) {
70485
- return first.vref;
70527
+ static parseHex4(data, at) {
70528
+ const s = GitSha1.ascii(data, at, 4);
70529
+ let v = 0;
70530
+ let i = 0;
70531
+ while (i < 4) {
70532
+ const d = GitPktIO.hexVal(s.substring(i, (i + 1)));
70533
+ if (d < 0) {
70534
+ return 0 - 1;
70486
70535
  }
70536
+ v = v * 16 + d;
70537
+ i = i + 1;
70487
70538
  }
70488
- return "";
70539
+ ;
70540
+ return v;
70489
70541
  }
70490
70542
  ;
70491
- isMemberAccess(node) {
70492
- if (node.hasNewOper) {
70493
- return false;
70494
- }
70495
- if (node.hasFnCall) {
70496
- return false;
70543
+ static hex4(n) {
70544
+ const digits = "0123456789abcdef";
70545
+ const d0 = ((n >>> 12) & 15);
70546
+ const d1 = ((n >>> 8) & 15);
70547
+ const d2 = ((n >>> 4) & 15);
70548
+ const d3 = (n & 15);
70549
+ return ((digits.substring(d0, (d0 + 1)) + digits.substring(d1, (d1 + 1))) + digits.substring(d2, (d2 + 1))) + digits.substring(d3, (d3 + 1));
70550
+ }
70551
+ ;
70552
+ static encodeLine(text) {
70553
+ const n = text.length + 4;
70554
+ const h = GitPktIO.hex4(n);
70555
+ let raw = (function () { var b = new ArrayBuffer(n); b._view = new DataView(b); return b; })();
70556
+ let i = 0;
70557
+ while (i < 4) {
70558
+ raw._view.setUint8(i, h.charCodeAt(i));
70559
+ i = i + 1;
70497
70560
  }
70498
- if (node.ns.length >= 2) {
70499
- return true;
70561
+ ;
70562
+ while (i < n) {
70563
+ raw._view.setUint8(i, text.charCodeAt((i - 4)));
70564
+ i = i + 1;
70500
70565
  }
70501
- if (node.vref.length > 0) {
70502
- const idx = node.vref.indexOf(".");
70503
- if (idx > 0) {
70504
- return true;
70566
+ ;
70567
+ return raw;
70568
+ }
70569
+ ;
70570
+ static encodeFlush() {
70571
+ let raw = (function () { var b = new ArrayBuffer(4); b._view = new DataView(b); return b; })();
70572
+ raw._view.setUint8(0, 48);
70573
+ raw._view.setUint8(1, 48);
70574
+ raw._view.setUint8(2, 48);
70575
+ raw._view.setUint8(3, 48);
70576
+ return raw;
70577
+ }
70578
+ ;
70579
+ static parse(data) {
70580
+ const pkt = new GitPkt();
70581
+ const n = data.byteLength;
70582
+ let at = 0;
70583
+ while (at < n) {
70584
+ if (at + 4 > n) {
70585
+ pkt.ok = false;
70586
+ pkt.err = "truncated pkt-line length";
70587
+ return pkt;
70588
+ }
70589
+ const __len = GitPktIO.parseHex4(data, at);
70590
+ if (__len < 0) {
70591
+ pkt.ok = false;
70592
+ pkt.err = "bad pkt-line hex";
70593
+ return pkt;
70594
+ }
70595
+ if (__len == 0) {
70596
+ pkt.isFlush.push(true);
70597
+ pkt.lines.push("");
70598
+ pkt.raw.push(GitSha1.copyRange(data, at, 4));
70599
+ at = at + 4;
70505
70600
  }
70506
- }
70507
- if (node.expression) {
70508
- if (node.children.length >= 2) {
70509
- const first = node.getFirst();
70510
- if (first.vref.length > 0) {
70511
- if ((first.vref == "buffer_alloc" || first.vref == "int_buffer_alloc") || first.vref == "double_buffer_alloc") {
70512
- return false;
70513
- }
70601
+ else {
70602
+ if (__len == 1 || __len == 2) {
70603
+ pkt.isFlush.push(true);
70604
+ pkt.lines.push("");
70605
+ pkt.raw.push(GitSha1.copyRange(data, at, 4));
70606
+ at = at + 4;
70514
70607
  }
70515
- if (first.vref.length > 0) {
70516
- const second = node.getSecond();
70517
- if (second.vref.length > 0) {
70518
- return true;
70608
+ else {
70609
+ if (__len < 4) {
70610
+ pkt.ok = false;
70611
+ pkt.err = "pkt-line length < 4";
70612
+ return pkt;
70613
+ }
70614
+ if (at + __len > n) {
70615
+ pkt.ok = false;
70616
+ pkt.err = "truncated pkt-line body";
70617
+ return pkt;
70519
70618
  }
70619
+ const body = GitSha1.copyRange(data, (at + 4), (__len - 4));
70620
+ pkt.raw.push(body);
70621
+ pkt.lines.push(GitSha1.ascii(body, 0, body.byteLength));
70622
+ pkt.isFlush.push(false);
70623
+ at = at + __len;
70520
70624
  }
70521
70625
  }
70522
70626
  }
70523
- return false;
70627
+ ;
70628
+ return pkt;
70629
+ }
70630
+ ;
70631
+ static parseAdvertisement(data) {
70632
+ const adv = new GitAdvertisement();
70633
+ const pkt = GitPktIO.parse(data);
70634
+ if (pkt.ok == false) {
70635
+ adv.ok = false;
70636
+ adv.err = pkt.err;
70637
+ return adv;
70638
+ }
70639
+ let i = 0;
70640
+ const n = pkt.lines.length;
70641
+ while (i < n) {
70642
+ const line = pkt.lines[i];
70643
+ const flush = pkt.isFlush[i];
70644
+ if (flush) {
70645
+ i = i + 1;
70646
+ }
70647
+ else {
70648
+ if (line.length > 10) {
70649
+ if (line.substring(0, 10) == "# service=") {
70650
+ adv.service = GitPktIO.trimNl(line.substring(10, line.length));
70651
+ }
70652
+ }
70653
+ if (line.length >= 41) {
70654
+ const sha = line.substring(0, 40);
70655
+ const rest = line.substring(41, line.length);
70656
+ const nulAt = GitPktIO.indexOfChar(rest, 0);
70657
+ let namePart = rest;
70658
+ if (nulAt >= 0) {
70659
+ namePart = rest.substring(0, nulAt);
70660
+ adv.caps = rest.substring((nulAt + 1), rest.length);
70661
+ }
70662
+ let name = GitPktIO.trimNl(namePart);
70663
+ if (name == "HEAD") {
70664
+ adv.head = sha;
70665
+ }
70666
+ let peeled = false;
70667
+ if (name.length > 3) {
70668
+ const tail = name.substring((name.length - 3), name.length);
70669
+ if (tail == "^{}") {
70670
+ peeled = true;
70671
+ name = name.substring(0, (name.length - 3));
70672
+ }
70673
+ }
70674
+ if (peeled) {
70675
+ let r = 0;
70676
+ while (r < adv.refs.length) {
70677
+ const existing = adv.refs[r];
70678
+ if (existing.name == name) {
70679
+ existing.peeled = sha;
70680
+ }
70681
+ r = r + 1;
70682
+ }
70683
+ ;
70684
+ }
70685
+ else {
70686
+ const ref = new GitRef();
70687
+ ref.name = name;
70688
+ ref.sha = sha;
70689
+ adv.refs.push(ref);
70690
+ }
70691
+ if (adv.head.length == 0) {
70692
+ if (name == "refs/heads/master") {
70693
+ adv.head = sha;
70694
+ }
70695
+ if (name == "refs/heads/main") {
70696
+ if (adv.head.length == 0) {
70697
+ adv.head = sha;
70698
+ }
70699
+ }
70700
+ }
70701
+ }
70702
+ i = i + 1;
70703
+ }
70704
+ }
70705
+ ;
70706
+ return adv;
70707
+ }
70708
+ ;
70709
+ static findRef(adv, spec) {
70710
+ if (spec.length == 40) {
70711
+ return spec;
70712
+ }
70713
+ if (spec.length == 0) {
70714
+ return adv.head;
70715
+ }
70716
+ if (spec == "HEAD") {
70717
+ return adv.head;
70718
+ }
70719
+ let i = 0;
70720
+ while (i < adv.refs.length) {
70721
+ const r = adv.refs[i];
70722
+ if (r.name == spec) {
70723
+ if (r.peeled.length == 40) {
70724
+ return r.peeled;
70725
+ }
70726
+ return r.sha;
70727
+ }
70728
+ if (r.name == "refs/heads/" + spec) {
70729
+ return r.sha;
70730
+ }
70731
+ if (r.name == "refs/tags/" + spec) {
70732
+ if (r.peeled.length == 40) {
70733
+ return r.peeled;
70734
+ }
70735
+ return r.sha;
70736
+ }
70737
+ i = i + 1;
70738
+ }
70739
+ ;
70740
+ return "";
70741
+ }
70742
+ ;
70743
+ static hasToken(caps, name) {
70744
+ const n = caps.length;
70745
+ const m = name.length;
70746
+ if (m == 0) {
70747
+ return false;
70748
+ }
70749
+ let i = 0;
70750
+ while (i <= n - m) {
70751
+ if (caps.substring(i, (i + m)) == name) {
70752
+ let left = false;
70753
+ if (i == 0) {
70754
+ left = true;
70755
+ }
70756
+ else {
70757
+ const lc = caps.charCodeAt((i - 1));
70758
+ if ((lc == 32 || lc == 10) || lc == 0) {
70759
+ left = true;
70760
+ }
70761
+ }
70762
+ let right = false;
70763
+ if (i + m == n) {
70764
+ right = true;
70765
+ }
70766
+ else {
70767
+ const rc = caps.charCodeAt((i + m));
70768
+ if (((rc == 32 || rc == 10) || rc == 0) || rc == 61) {
70769
+ right = true;
70770
+ }
70771
+ }
70772
+ if (left && right) {
70773
+ return true;
70774
+ }
70775
+ }
70776
+ i = i + 1;
70777
+ }
70778
+ ;
70779
+ return false;
70780
+ }
70781
+ ;
70782
+ static joinBuf(parts) {
70783
+ let total = 0;
70784
+ let i = 0;
70785
+ while (i < parts.length) {
70786
+ total = total + parts[i].byteLength;
70787
+ i = i + 1;
70788
+ }
70789
+ ;
70790
+ let out = (function () { var b = new ArrayBuffer(total); b._view = new DataView(b); return b; })();
70791
+ let at = 0;
70792
+ i = 0;
70793
+ while (i < parts.length) {
70794
+ const p = parts[i];
70795
+ const pn = p.byteLength;
70796
+ (function (d, dOff, s, sOff, len) { var dv = new Uint8Array(d); var sv = new Uint8Array(s); for (var i = 0; i < len; i++)
70797
+ dv[dOff + i] = sv[sOff + i]; })(out, at, p, 0, pn);
70798
+ at = at + pn;
70799
+ i = i + 1;
70800
+ }
70801
+ ;
70802
+ return out;
70803
+ }
70804
+ ;
70805
+ static encodeDelim() {
70806
+ let raw = (function () { var b = new ArrayBuffer(4); b._view = new DataView(b); return b; })();
70807
+ raw._view.setUint8(0, 48);
70808
+ raw._view.setUint8(1, 48);
70809
+ raw._view.setUint8(2, 48);
70810
+ raw._view.setUint8(3, 49);
70811
+ return raw;
70812
+ }
70813
+ ;
70814
+ static buildWant(adv, spec) {
70815
+ const w = new GitWant();
70816
+ const sha = GitPktIO.findRef(adv, spec);
70817
+ if (sha.length != 40) {
70818
+ w.ok = false;
70819
+ w.err = "unknown rev: " + spec;
70820
+ return w;
70821
+ }
70822
+ let extras = [];
70823
+ return GitPktIO.buildWantFetch(sha, 0, "", extras);
70824
+ }
70825
+ ;
70826
+ static buildWantFetch(sha, deepen, filter, extras) {
70827
+ const w = new GitWant();
70828
+ if (sha.length != 40) {
70829
+ w.ok = false;
70830
+ w.err = "want needs a 40-char sha";
70831
+ return w;
70832
+ }
70833
+ w.sha = sha;
70834
+ let caps = "multi_ack_detailed no-done side-band-64k ofs-delta agent=ranger-pkg/0.1";
70835
+ if (deepen > 0) {
70836
+ caps = caps + " shallow";
70837
+ }
70838
+ if (filter.length > 0) {
70839
+ caps = caps + " filter";
70840
+ }
70841
+ let parts = [];
70842
+ parts.push(GitPktIO.encodeLine((((("want " + sha) + " ") + caps) + "\n")));
70843
+ let i = 0;
70844
+ while (i < extras.length) {
70845
+ parts.push(GitPktIO.encodeLine((("want " + extras[i]) + "\n")));
70846
+ i = i + 1;
70847
+ }
70848
+ ;
70849
+ if (deepen > 0) {
70850
+ parts.push(GitPktIO.encodeLine((("deepen " + (deepen.toString())) + "\n")));
70851
+ }
70852
+ if (filter.length > 0) {
70853
+ parts.push(GitPktIO.encodeLine((("filter " + filter) + "\n")));
70854
+ }
70855
+ parts.push(GitPktIO.encodeFlush());
70856
+ parts.push(GitPktIO.encodeLine("done\n"));
70857
+ w.body = GitPktIO.joinBuf(parts);
70858
+ return w;
70859
+ }
70860
+ ;
70861
+ static buildWantTrees(adv, spec) {
70862
+ const w = new GitWant();
70863
+ const sha = GitPktIO.findRef(adv, spec);
70864
+ if (sha.length != 40) {
70865
+ w.ok = false;
70866
+ w.err = "unknown rev: " + spec;
70867
+ return w;
70868
+ }
70869
+ let extras = [];
70870
+ let filter = "";
70871
+ if (GitPktIO.hasToken(adv.caps, "filter")) {
70872
+ filter = "blob:none";
70873
+ }
70874
+ return GitPktIO.buildWantFetch(sha, 1, filter, extras);
70875
+ }
70876
+ ;
70877
+ static buildWantSha(sha) {
70878
+ let extras = [];
70879
+ return GitPktIO.buildWantFetch(sha, 0, "", extras);
70880
+ }
70881
+ ;
70882
+ static buildFetchV2(sha, deepen, filter) {
70883
+ const w = new GitWant();
70884
+ if (sha.length != 40) {
70885
+ w.ok = false;
70886
+ w.err = "want needs a 40-char sha";
70887
+ return w;
70888
+ }
70889
+ w.sha = sha;
70890
+ let parts = [];
70891
+ parts.push(GitPktIO.encodeLine("command=fetch"));
70892
+ parts.push(GitPktIO.encodeDelim());
70893
+ parts.push(GitPktIO.encodeLine(("want " + sha)));
70894
+ if (deepen > 0) {
70895
+ parts.push(GitPktIO.encodeLine(("deepen " + (deepen.toString()))));
70896
+ }
70897
+ if (filter.length > 0) {
70898
+ parts.push(GitPktIO.encodeLine(("filter " + filter)));
70899
+ }
70900
+ parts.push(GitPktIO.encodeLine("done"));
70901
+ parts.push(GitPktIO.encodeFlush());
70902
+ w.body = GitPktIO.joinBuf(parts);
70903
+ return w;
70904
+ }
70905
+ ;
70906
+ static demux(data) {
70907
+ const sb = new GitSideband();
70908
+ const n = data.byteLength;
70909
+ const mag = GitPktIO.indexOfPack(data);
70910
+ const pkt = GitPktIO.parse(data);
70911
+ if (pkt.ok == false) {
70912
+ if (mag >= 0) {
70913
+ sb.pack = GitSha1.copyRange(data, mag, (n - mag));
70914
+ return sb;
70915
+ }
70916
+ sb.ok = false;
70917
+ sb.err = pkt.err;
70918
+ return sb;
70919
+ }
70920
+ let chunks = [];
70921
+ let total = 0;
70922
+ let i = 0;
70923
+ while (i < pkt.raw.length) {
70924
+ if (pkt.isFlush[i] == false) {
70925
+ const body = pkt.raw[i];
70926
+ if (body.byteLength > 0) {
70927
+ const ch = body._view.getUint8(0);
70928
+ if (ch == 1) {
70929
+ const piece = GitSha1.copyRange(body, 1, (body.byteLength - 1));
70930
+ chunks.push(piece);
70931
+ total = total + piece.byteLength;
70932
+ }
70933
+ if (ch == 2) {
70934
+ sb.progress = sb.progress + GitSha1.ascii(body, 1, (body.byteLength - 1));
70935
+ }
70936
+ if (ch == 3) {
70937
+ sb.ok = false;
70938
+ sb.err = GitSha1.ascii(body, 1, (body.byteLength - 1));
70939
+ }
70940
+ }
70941
+ }
70942
+ i = i + 1;
70943
+ }
70944
+ ;
70945
+ if (chunks.length == 0) {
70946
+ if (mag >= 0) {
70947
+ sb.pack = GitSha1.copyRange(data, mag, (n - mag));
70948
+ return sb;
70949
+ }
70950
+ sb.ok = false;
70951
+ sb.err = "no pack data in response";
70952
+ return sb;
70953
+ }
70954
+ let pack = (function () { var b = new ArrayBuffer(total); b._view = new DataView(b); return b; })();
70955
+ let at = 0;
70956
+ i = 0;
70957
+ while (i < chunks.length) {
70958
+ const piece2 = chunks[i];
70959
+ const pn = piece2.byteLength;
70960
+ (function (d, dOff, s, sOff, len) { var dv = new Uint8Array(d); var sv = new Uint8Array(s); for (var i = 0; i < len; i++)
70961
+ dv[dOff + i] = sv[sOff + i]; })(pack, at, piece2, 0, pn);
70962
+ at = at + pn;
70963
+ i = i + 1;
70964
+ }
70965
+ ;
70966
+ sb.pack = pack;
70967
+ return sb;
70968
+ }
70969
+ ;
70970
+ static indexOfPack(data) {
70971
+ const n = data.byteLength;
70972
+ let i = 0;
70973
+ while (i < n - 3) {
70974
+ if (data._view.getUint8(i) == 80) {
70975
+ if (data._view.getUint8((i + 1)) == 65) {
70976
+ if (data._view.getUint8((i + 2)) == 67) {
70977
+ if (data._view.getUint8((i + 3)) == 75) {
70978
+ return i;
70979
+ }
70980
+ }
70981
+ }
70982
+ }
70983
+ i = i + 1;
70984
+ }
70985
+ ;
70986
+ return 0 - 1;
70987
+ }
70988
+ ;
70989
+ static indexOfChar(s, code) {
70990
+ const n = s.length;
70991
+ let i = 0;
70992
+ while (i < n) {
70993
+ if (s.charCodeAt(i) == code) {
70994
+ return i;
70995
+ }
70996
+ i = i + 1;
70997
+ }
70998
+ ;
70999
+ return 0 - 1;
71000
+ }
71001
+ ;
71002
+ static trimNl(s) {
71003
+ let n = s.length;
71004
+ while (n > 0) {
71005
+ const c = s.charCodeAt((n - 1));
71006
+ if (c == 10) {
71007
+ n = n - 1;
71008
+ }
71009
+ else {
71010
+ if (c == 13) {
71011
+ n = n - 1;
71012
+ }
71013
+ else {
71014
+ if (c == 0) {
71015
+ n = n - 1;
71016
+ }
71017
+ else {
71018
+ return s.substring(0, n);
71019
+ }
71020
+ }
71021
+ }
71022
+ }
71023
+ ;
71024
+ return "";
71025
+ }
71026
+ ;
71027
+ }
71028
+ exports.GitPktIO = GitPktIO;
71029
+ class ZipBuffer {
71030
+ constructor() {
71031
+ this.data = (function () { var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
71032
+ this.pos = 0;
71033
+ this.length = 0;
71034
+ }
71035
+ initWithBuffer(buf) {
71036
+ this.data = buf;
71037
+ this.length = buf.byteLength;
71038
+ this.pos = 0;
71039
+ }
71040
+ ;
71041
+ initWithSize(size) {
71042
+ this.data = (function () { var b = new ArrayBuffer(size); b._view = new DataView(b); return b; })();
71043
+ this.length = size;
71044
+ this.pos = 0;
71045
+ }
71046
+ ;
71047
+ getPosition() {
71048
+ return this.pos;
71049
+ }
71050
+ ;
71051
+ setPosition(newPos) {
71052
+ this.pos = newPos;
71053
+ }
71054
+ ;
71055
+ seek(offset) {
71056
+ this.pos = offset;
71057
+ }
71058
+ ;
71059
+ skip(count) {
71060
+ this.pos = this.pos + count;
71061
+ }
71062
+ ;
71063
+ remaining() {
71064
+ return this.length - this.pos;
71065
+ }
71066
+ ;
71067
+ isEOF() {
71068
+ return this.pos >= this.length;
71069
+ }
71070
+ ;
71071
+ readUint8() {
71072
+ if (this.pos >= this.length) {
71073
+ return 0;
71074
+ }
71075
+ const value = this.data._view.getUint8(this.pos);
71076
+ this.pos = this.pos + 1;
71077
+ return value;
71078
+ }
71079
+ ;
71080
+ readUint16LE() {
71081
+ const b0 = this.readUint8();
71082
+ const b1 = this.readUint8();
71083
+ return b0 + b1 * 256;
71084
+ }
71085
+ ;
71086
+ readUint32LE() {
71087
+ const b0 = this.readUint8();
71088
+ const b1 = this.readUint8();
71089
+ const b2 = this.readUint8();
71090
+ const b3 = this.readUint8();
71091
+ return ((b0 + b1 * 256) + b2 * 65536) + b3 * 16777216;
71092
+ }
71093
+ ;
71094
+ readBytes(count) {
71095
+ let result = (function () { var b = new ArrayBuffer(count); b._view = new DataView(b); return b; })();
71096
+ let i = 0;
71097
+ while (i < count) {
71098
+ if (this.pos < this.length) {
71099
+ const b = this.data._view.getUint8(this.pos);
71100
+ result._view.setUint8(i, b);
71101
+ this.pos = this.pos + 1;
71102
+ }
71103
+ i = i + 1;
71104
+ }
71105
+ ;
71106
+ return result;
71107
+ }
71108
+ ;
71109
+ readString(count) {
71110
+ let result = "";
71111
+ let i = 0;
71112
+ while (i < count) {
71113
+ if (this.pos < this.length) {
71114
+ const ch = this.data._view.getUint8(this.pos);
71115
+ result = result + String.fromCharCode(ch);
71116
+ this.pos = this.pos + 1;
71117
+ }
71118
+ i = i + 1;
71119
+ }
71120
+ ;
71121
+ return result;
71122
+ }
71123
+ ;
71124
+ peekUint8() {
71125
+ if (this.pos >= this.length) {
71126
+ return 0;
71127
+ }
71128
+ return this.data._view.getUint8(this.pos);
71129
+ }
71130
+ ;
71131
+ peekUint32LE() {
71132
+ const savedPos = this.pos;
71133
+ const value = this.readUint32LE();
71134
+ this.pos = savedPos;
71135
+ return value;
71136
+ }
71137
+ ;
71138
+ writeUint8(value) {
71139
+ if (this.pos < this.length) {
71140
+ this.data._view.setUint8(this.pos, value);
71141
+ this.pos = this.pos + 1;
71142
+ }
71143
+ }
71144
+ ;
71145
+ writeUint16LE(value) {
71146
+ const b0 = (value & 255);
71147
+ const b1 = ((value >>> 8) & 255);
71148
+ this.writeUint8(b0);
71149
+ this.writeUint8(b1);
71150
+ }
71151
+ ;
71152
+ writeUint32LE(value) {
71153
+ const b0 = (value & 255);
71154
+ const b1 = ((value >>> 8) & 255);
71155
+ const b2 = ((value >>> 16) & 255);
71156
+ const b3 = ((value >>> 24) & 255);
71157
+ this.writeUint8(b0);
71158
+ this.writeUint8(b1);
71159
+ this.writeUint8(b2);
71160
+ this.writeUint8(b3);
71161
+ }
71162
+ ;
71163
+ writeBytes(src, srcOffset, count) {
71164
+ let i = 0;
71165
+ while (i < count) {
71166
+ const b = src._view.getUint8((srcOffset + i));
71167
+ this.writeUint8(b);
71168
+ i = i + 1;
71169
+ }
71170
+ ;
71171
+ }
71172
+ ;
71173
+ writeBuffer(src) {
71174
+ const __len = src.byteLength;
71175
+ this.writeBytes(src, 0, __len);
71176
+ }
71177
+ ;
71178
+ writeString(s) {
71179
+ const __len = s.length;
71180
+ let i = 0;
71181
+ while (i < __len) {
71182
+ const ch = s.charCodeAt(i);
71183
+ this.writeUint8(ch);
71184
+ i = i + 1;
71185
+ }
71186
+ ;
71187
+ }
71188
+ ;
71189
+ getBuffer() {
71190
+ return this.data;
71191
+ }
71192
+ ;
71193
+ getLength() {
71194
+ return this.length;
71195
+ }
71196
+ ;
71197
+ findSignatureBackward(sig, startPos) {
71198
+ let searchPos = startPos;
71199
+ while (searchPos >= 0) {
71200
+ const savedPos = this.pos;
71201
+ this.pos = searchPos;
71202
+ const value = this.readUint32LE();
71203
+ this.pos = savedPos;
71204
+ if (value == sig) {
71205
+ return searchPos;
71206
+ }
71207
+ searchPos = searchPos - 1;
71208
+ }
71209
+ ;
71210
+ return -1;
71211
+ }
71212
+ ;
71213
+ }
71214
+ exports.ZipBuffer = ZipBuffer;
71215
+ class GrowableZipBuffer {
71216
+ constructor() {
71217
+ this.chunks = [];
71218
+ this.chunkLens = [];
71219
+ this.chunkSize = 65536;
71220
+ this.currentChunk = (function () { var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
71221
+ this.currentPos = 0;
71222
+ this.totalSize = 0;
71223
+ this.currentPos = 0;
71224
+ this.totalSize = 0;
71225
+ const initSize = this.chunkSize;
71226
+ this.currentChunk = (function () { var b = new ArrayBuffer(initSize); b._view = new DataView(b); return b; })();
71227
+ }
71228
+ setChunkSize(size) {
71229
+ if (size < 1) {
71230
+ return;
71231
+ }
71232
+ if (this.totalSize > 0) {
71233
+ return;
71234
+ }
71235
+ this.chunkSize = size;
71236
+ this.currentChunk = (function () { var b = new ArrayBuffer(size); b._view = new DataView(b); return b; })();
71237
+ this.currentPos = 0;
71238
+ }
71239
+ ;
71240
+ allocateNewChunk() {
71241
+ this.chunks.push(this.currentChunk);
71242
+ this.chunkLens.push(this.currentPos);
71243
+ const size = this.chunkSize;
71244
+ this.currentChunk = (function () { var b = new ArrayBuffer(size); b._view = new DataView(b); return b; })();
71245
+ this.currentPos = 0;
71246
+ }
71247
+ ;
71248
+ writeUint8(value) {
71249
+ if (this.currentPos >= this.chunkSize) {
71250
+ this.allocateNewChunk();
71251
+ }
71252
+ this.currentChunk._view.setUint8(this.currentPos, value);
71253
+ this.currentPos = this.currentPos + 1;
71254
+ this.totalSize = this.totalSize + 1;
71255
+ }
71256
+ ;
71257
+ writeUint16LE(value) {
71258
+ const b0 = value % 256;
71259
+ const b1D = value / 256.0;
71260
+ const b1 = Math.floor(b1D) % 256;
71261
+ this.writeUint8(b0);
71262
+ this.writeUint8(b1);
71263
+ }
71264
+ ;
71265
+ writeUint32LE(value) {
71266
+ const b0 = value % 256;
71267
+ const rem1D = value / 256.0;
71268
+ const rem1 = Math.floor(rem1D);
71269
+ const b1 = rem1 % 256;
71270
+ const rem2D = rem1 / 256.0;
71271
+ const rem2 = Math.floor(rem2D);
71272
+ const b2 = rem2 % 256;
71273
+ const rem3D = rem2 / 256.0;
71274
+ const b3 = Math.floor(rem3D);
71275
+ this.writeUint8(b0);
71276
+ this.writeUint8(b1);
71277
+ this.writeUint8(b2);
71278
+ this.writeUint8(b3);
71279
+ }
71280
+ ;
71281
+ writeBytes(src, srcOffset, count) {
71282
+ let left = count;
71283
+ let at = srcOffset;
71284
+ while (left > 0) {
71285
+ if (this.currentPos >= this.chunkSize) {
71286
+ this.allocateNewChunk();
71287
+ }
71288
+ const room = this.chunkSize - this.currentPos;
71289
+ let take = left;
71290
+ if (take > room) {
71291
+ take = room;
71292
+ }
71293
+ (function (d, dOff, s, sOff, len) { var dv = new Uint8Array(d); var sv = new Uint8Array(s); for (var i = 0; i < len; i++)
71294
+ dv[dOff + i] = sv[sOff + i]; })(this.currentChunk, this.currentPos, src, at, take);
71295
+ this.currentPos = this.currentPos + take;
71296
+ this.totalSize = this.totalSize + take;
71297
+ at = at + take;
71298
+ left = left - take;
71299
+ }
71300
+ ;
71301
+ }
71302
+ ;
71303
+ writeBuffer(src) {
71304
+ const __len = src.byteLength;
71305
+ this.writeBytes(src, 0, __len);
71306
+ }
71307
+ ;
71308
+ writeString(s) {
71309
+ const __len = s.length;
71310
+ let i = 0;
71311
+ while (i < __len) {
71312
+ const ch = s.charCodeAt(i);
71313
+ this.writeUint8(ch);
71314
+ i = i + 1;
71315
+ }
71316
+ ;
71317
+ }
71318
+ ;
71319
+ getSize() {
71320
+ return this.totalSize;
71321
+ }
71322
+ ;
71323
+ toBuffer() {
71324
+ const size = this.totalSize;
71325
+ let result = (function () { var b = new ArrayBuffer(size); b._view = new DataView(b); return b; })();
71326
+ let destPos = 0;
71327
+ const numChunks = this.chunks.length;
71328
+ let i = 0;
71329
+ while (i < numChunks) {
71330
+ const chunk = this.chunks[i];
71331
+ const used = this.chunkLens[i];
71332
+ if (used > 0) {
71333
+ (function (d, dOff, s, sOff, len) { var dv = new Uint8Array(d); var sv = new Uint8Array(s); for (var i = 0; i < len; i++)
71334
+ dv[dOff + i] = sv[sOff + i]; })(result, destPos, chunk, 0, used);
71335
+ destPos = destPos + used;
71336
+ }
71337
+ i = i + 1;
71338
+ }
71339
+ ;
71340
+ const curPos = this.currentPos;
71341
+ if (curPos > 0) {
71342
+ const curChunk = this.currentChunk;
71343
+ (function (d, dOff, s, sOff, len) { var dv = new Uint8Array(d); var sv = new Uint8Array(s); for (var i = 0; i < len; i++)
71344
+ dv[dOff + i] = sv[sOff + i]; })(result, destPos, curChunk, 0, curPos);
71345
+ destPos = destPos + curPos;
71346
+ }
71347
+ return result;
71348
+ }
71349
+ ;
71350
+ }
71351
+ exports.GrowableZipBuffer = GrowableZipBuffer;
71352
+ class InflateHuffmanTable {
71353
+ constructor() {
71354
+ this.counts = [];
71355
+ this.symbols = [];
71356
+ this.maxBits = 0;
71357
+ let i_28 = 0;
71358
+ while (i_28 < 16) {
71359
+ this.counts.push(0);
71360
+ i_28 = i_28 + 1;
71361
+ }
71362
+ ;
71363
+ }
71364
+ build(lengths, numSymbols) {
71365
+ let i = 0;
71366
+ while (i < 16) {
71367
+ this.counts[i] = 0;
71368
+ i = i + 1;
71369
+ }
71370
+ ;
71371
+ i = 0;
71372
+ while (i < numSymbols) {
71373
+ const __len = lengths[i];
71374
+ if (__len > 0) {
71375
+ const cnt = this.counts[__len];
71376
+ this.counts[__len] = cnt + 1;
71377
+ if (__len > this.maxBits) {
71378
+ this.maxBits = __len;
71379
+ }
71380
+ }
71381
+ i = i + 1;
71382
+ }
71383
+ ;
71384
+ let offsets = [];
71385
+ let offset = 0;
71386
+ i = 0;
71387
+ while (i < 16) {
71388
+ offsets.push(offset);
71389
+ const cnt_1 = this.counts[i];
71390
+ offset = offset + cnt_1;
71391
+ i = i + 1;
71392
+ }
71393
+ ;
71394
+ i = 0;
71395
+ while (i < numSymbols) {
71396
+ this.symbols.push(0);
71397
+ i = i + 1;
71398
+ }
71399
+ ;
71400
+ i = 0;
71401
+ while (i < numSymbols) {
71402
+ const len_1 = lengths[i];
71403
+ if (len_1 > 0) {
71404
+ const off = offsets[len_1];
71405
+ this.symbols[off] = i;
71406
+ offsets[len_1] = off + 1;
71407
+ }
71408
+ i = i + 1;
71409
+ }
71410
+ ;
71411
+ }
71412
+ ;
71413
+ decode(reader) {
71414
+ let code = 0;
71415
+ let first = 0;
71416
+ let index = 0;
71417
+ let __len = 1;
71418
+ while (__len <= this.maxBits) {
71419
+ const bit = reader.readBit();
71420
+ code = code * 2 + bit;
71421
+ const count = this.counts[__len];
71422
+ if (code - first < count) {
71423
+ return this.symbols[((index + code) - first)];
71424
+ }
71425
+ index = index + count;
71426
+ first = (first + count) * 2;
71427
+ __len = __len + 1;
71428
+ }
71429
+ ;
71430
+ return -1;
71431
+ }
71432
+ ;
71433
+ }
71434
+ exports.InflateHuffmanTable = InflateHuffmanTable;
71435
+ class InflateBitReader {
71436
+ constructor() {
71437
+ this.data = (function () { var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
71438
+ this.bytePos = 0;
71439
+ this.bitPos = 0;
71440
+ this.currentByte = 0;
71441
+ this.dataLength = 0;
71442
+ }
71443
+ init(buf, offset, length) {
71444
+ this.data = buf;
71445
+ this.bytePos = offset;
71446
+ this.dataLength = offset + length;
71447
+ this.bitPos = 0;
71448
+ this.currentByte = 0;
71449
+ }
71450
+ ;
71451
+ readBit() {
71452
+ if (this.bitPos == 0) {
71453
+ if (this.bytePos >= this.dataLength) {
71454
+ return 0;
71455
+ }
71456
+ this.currentByte = this.data._view.getUint8(this.bytePos);
71457
+ this.bytePos = this.bytePos + 1;
71458
+ this.bitPos = 8;
71459
+ }
71460
+ const bit = (this.currentByte & 1);
71461
+ this.currentByte = (this.currentByte >> 1);
71462
+ this.bitPos = this.bitPos - 1;
71463
+ return bit;
71464
+ }
71465
+ ;
71466
+ readBits(count) {
71467
+ let result = 0;
71468
+ let multiplier = 1;
71469
+ let i = 0;
71470
+ while (i < count) {
71471
+ const bit = this.readBit();
71472
+ result = result + bit * multiplier;
71473
+ multiplier = multiplier * 2;
71474
+ i = i + 1;
71475
+ }
71476
+ ;
71477
+ return result;
71478
+ }
71479
+ ;
71480
+ alignToByte() {
71481
+ this.bitPos = 0;
71482
+ }
71483
+ ;
71484
+ readByte() {
71485
+ this.alignToByte();
71486
+ if (this.bytePos >= this.dataLength) {
71487
+ return 0;
71488
+ }
71489
+ const b = this.data._view.getUint8(this.bytePos);
71490
+ this.bytePos = this.bytePos + 1;
71491
+ return b;
71492
+ }
71493
+ ;
71494
+ readUint16LE() {
71495
+ const b0 = this.readByte();
71496
+ const b1 = this.readByte();
71497
+ return b0 + b1 * 256;
71498
+ }
71499
+ ;
71500
+ getBytePosition() {
71501
+ return this.bytePos;
71502
+ }
71503
+ ;
71504
+ isEOF() {
71505
+ return this.bytePos >= this.dataLength && this.bitPos == 0;
71506
+ }
71507
+ ;
71508
+ }
71509
+ exports.InflateBitReader = InflateBitReader;
71510
+ class Inflate {
71511
+ constructor() {
71512
+ this.input = (function () { var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
71513
+ this.reader = new InflateBitReader();
71514
+ this.outBuf = (function () { var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
71515
+ this.outLen = 0;
71516
+ this.outCap = 0;
71517
+ this.fixedLitLen = new InflateHuffmanTable();
71518
+ this.fixedDist = new InflateHuffmanTable();
71519
+ this.fixedTablesBuilt = false;
71520
+ this.lengthBase = [];
71521
+ this.lengthExtra = [];
71522
+ this.distBase = [];
71523
+ this.distExtra = [];
71524
+ this.buildLengthDistTables();
71525
+ }
71526
+ resetOutput(hint) {
71527
+ let cap = hint;
71528
+ if (cap < 4096) {
71529
+ cap = 4096;
71530
+ }
71531
+ this.outBuf = (function () { var b = new ArrayBuffer(cap); b._view = new DataView(b); return b; })();
71532
+ this.outCap = cap;
71533
+ this.outLen = 0;
71534
+ }
71535
+ ;
71536
+ ensureCapacity(extra) {
71537
+ const need = this.outLen + extra;
71538
+ if (need <= this.outCap) {
71539
+ return;
71540
+ }
71541
+ let newCap = this.outCap * 2;
71542
+ if (newCap < need) {
71543
+ newCap = need;
71544
+ }
71545
+ let grown = (function () { var b = new ArrayBuffer(newCap); b._view = new DataView(b); return b; })();
71546
+ (function (d, dOff, s, sOff, len) { var dv = new Uint8Array(d); var sv = new Uint8Array(s); for (var i = 0; i < len; i++)
71547
+ dv[dOff + i] = sv[sOff + i]; })(grown, 0, this.outBuf, 0, this.outLen);
71548
+ this.outBuf = grown;
71549
+ this.outCap = newCap;
71550
+ }
71551
+ ;
71552
+ pushByte(b) {
71553
+ this.ensureCapacity(1);
71554
+ this.outBuf._view.setUint8(this.outLen, b);
71555
+ this.outLen = this.outLen + 1;
71556
+ }
71557
+ ;
71558
+ finalOutput() {
71559
+ const size = this.outLen;
71560
+ let result = (function () { var b = new ArrayBuffer(size); b._view = new DataView(b); return b; })();
71561
+ (function (d, dOff, s, sOff, len) { var dv = new Uint8Array(d); var sv = new Uint8Array(s); for (var i = 0; i < len; i++)
71562
+ dv[dOff + i] = sv[sOff + i]; })(result, 0, this.outBuf, 0, size);
71563
+ return result;
71564
+ }
71565
+ ;
71566
+ buildLengthDistTables() {
71567
+ let bases = [];
71568
+ bases.push(3);
71569
+ bases.push(4);
71570
+ bases.push(5);
71571
+ bases.push(6);
71572
+ bases.push(7);
71573
+ bases.push(8);
71574
+ bases.push(9);
71575
+ bases.push(10);
71576
+ bases.push(11);
71577
+ bases.push(13);
71578
+ bases.push(15);
71579
+ bases.push(17);
71580
+ bases.push(19);
71581
+ bases.push(23);
71582
+ bases.push(27);
71583
+ bases.push(31);
71584
+ bases.push(35);
71585
+ bases.push(43);
71586
+ bases.push(51);
71587
+ bases.push(59);
71588
+ bases.push(67);
71589
+ bases.push(83);
71590
+ bases.push(99);
71591
+ bases.push(115);
71592
+ bases.push(131);
71593
+ bases.push(163);
71594
+ bases.push(195);
71595
+ bases.push(227);
71596
+ bases.push(258);
71597
+ this.lengthBase = bases;
71598
+ let extras = [];
71599
+ extras.push(0);
71600
+ extras.push(0);
71601
+ extras.push(0);
71602
+ extras.push(0);
71603
+ extras.push(0);
71604
+ extras.push(0);
71605
+ extras.push(0);
71606
+ extras.push(0);
71607
+ extras.push(1);
71608
+ extras.push(1);
71609
+ extras.push(1);
71610
+ extras.push(1);
71611
+ extras.push(2);
71612
+ extras.push(2);
71613
+ extras.push(2);
71614
+ extras.push(2);
71615
+ extras.push(3);
71616
+ extras.push(3);
71617
+ extras.push(3);
71618
+ extras.push(3);
71619
+ extras.push(4);
71620
+ extras.push(4);
71621
+ extras.push(4);
71622
+ extras.push(4);
71623
+ extras.push(5);
71624
+ extras.push(5);
71625
+ extras.push(5);
71626
+ extras.push(5);
71627
+ extras.push(0);
71628
+ this.lengthExtra = extras;
71629
+ let dBases = [];
71630
+ dBases.push(1);
71631
+ dBases.push(2);
71632
+ dBases.push(3);
71633
+ dBases.push(4);
71634
+ dBases.push(5);
71635
+ dBases.push(7);
71636
+ dBases.push(9);
71637
+ dBases.push(13);
71638
+ dBases.push(17);
71639
+ dBases.push(25);
71640
+ dBases.push(33);
71641
+ dBases.push(49);
71642
+ dBases.push(65);
71643
+ dBases.push(97);
71644
+ dBases.push(129);
71645
+ dBases.push(193);
71646
+ dBases.push(257);
71647
+ dBases.push(385);
71648
+ dBases.push(513);
71649
+ dBases.push(769);
71650
+ dBases.push(1025);
71651
+ dBases.push(1537);
71652
+ dBases.push(2049);
71653
+ dBases.push(3073);
71654
+ dBases.push(4097);
71655
+ dBases.push(6145);
71656
+ dBases.push(8193);
71657
+ dBases.push(12289);
71658
+ dBases.push(16385);
71659
+ dBases.push(24577);
71660
+ this.distBase = dBases;
71661
+ let dExtras = [];
71662
+ dExtras.push(0);
71663
+ dExtras.push(0);
71664
+ dExtras.push(0);
71665
+ dExtras.push(0);
71666
+ dExtras.push(1);
71667
+ dExtras.push(1);
71668
+ dExtras.push(2);
71669
+ dExtras.push(2);
71670
+ dExtras.push(3);
71671
+ dExtras.push(3);
71672
+ dExtras.push(4);
71673
+ dExtras.push(4);
71674
+ dExtras.push(5);
71675
+ dExtras.push(5);
71676
+ dExtras.push(6);
71677
+ dExtras.push(6);
71678
+ dExtras.push(7);
71679
+ dExtras.push(7);
71680
+ dExtras.push(8);
71681
+ dExtras.push(8);
71682
+ dExtras.push(9);
71683
+ dExtras.push(9);
71684
+ dExtras.push(10);
71685
+ dExtras.push(10);
71686
+ dExtras.push(11);
71687
+ dExtras.push(11);
71688
+ dExtras.push(12);
71689
+ dExtras.push(12);
71690
+ dExtras.push(13);
71691
+ dExtras.push(13);
71692
+ this.distExtra = dExtras;
71693
+ }
71694
+ ;
71695
+ buildFixedTables() {
71696
+ if (this.fixedTablesBuilt) {
71697
+ return;
71698
+ }
71699
+ let lengths = [];
71700
+ let i = 0;
71701
+ while (i < 144) {
71702
+ lengths.push(8);
71703
+ i = i + 1;
71704
+ }
71705
+ ;
71706
+ while (i < 256) {
71707
+ lengths.push(9);
71708
+ i = i + 1;
71709
+ }
71710
+ ;
71711
+ while (i < 280) {
71712
+ lengths.push(7);
71713
+ i = i + 1;
71714
+ }
71715
+ ;
71716
+ while (i < 288) {
71717
+ lengths.push(8);
71718
+ i = i + 1;
71719
+ }
71720
+ ;
71721
+ this.fixedLitLen.build(lengths, 288);
71722
+ let distLengths = [];
71723
+ i = 0;
71724
+ while (i < 32) {
71725
+ distLengths.push(5);
71726
+ i = i + 1;
71727
+ }
71728
+ ;
71729
+ this.fixedDist.build(distLengths, 32);
71730
+ this.fixedTablesBuilt = true;
71731
+ }
71732
+ ;
71733
+ decompress(data) {
71734
+ return this.decompressFrom(data, 0);
71735
+ }
71736
+ ;
71737
+ decompressFrom(data, offset) {
71738
+ this.input = data;
71739
+ const dataLen = data.byteLength;
71740
+ let from = offset;
71741
+ if (from < 0) {
71742
+ from = 0;
71743
+ }
71744
+ if (from > dataLen) {
71745
+ from = dataLen;
71746
+ }
71747
+ const rest = dataLen - from;
71748
+ this.resetOutput(rest * 4);
71749
+ this.reader.init(data, from, rest);
71750
+ this.buildFixedTables();
71751
+ let finalBlock = false;
71752
+ while (false == finalBlock) {
71753
+ const bfinal = this.reader.readBit();
71754
+ const btype = this.reader.readBits(2);
71755
+ finalBlock = bfinal == 1;
71756
+ if (btype == 0) {
71757
+ this.decompressStored();
71758
+ }
71759
+ if (btype == 1) {
71760
+ this.decompressHuffman(this.fixedLitLen, this.fixedDist);
71761
+ }
71762
+ if (btype == 2) {
71763
+ this.decompressDynamic();
71764
+ }
71765
+ }
71766
+ ;
71767
+ return this.finalOutput();
71768
+ }
71769
+ ;
71770
+ inputPos() {
71771
+ return this.reader.getBytePosition();
71772
+ }
71773
+ ;
71774
+ decompressStored() {
71775
+ this.reader.alignToByte();
71776
+ const __len = this.reader.readUint16LE();
71777
+ const nlen = this.reader.readUint16LE();
71778
+ if (__len + nlen != 65535) {
71779
+ }
71780
+ this.ensureCapacity(__len);
71781
+ let i = 0;
71782
+ while (i < __len) {
71783
+ const b = this.reader.readByte();
71784
+ this.pushByte(b);
71785
+ i = i + 1;
71786
+ }
71787
+ ;
71788
+ }
71789
+ ;
71790
+ decompressHuffman(litLenTable, distTable) {
71791
+ let done = false;
71792
+ while (false == done) {
71793
+ const sym = litLenTable.decode(this.reader);
71794
+ if (sym < 256) {
71795
+ this.pushByte(sym);
71796
+ }
71797
+ if (sym == 256) {
71798
+ done = true;
71799
+ }
71800
+ if (sym > 256) {
71801
+ const lengthCode = sym - 257;
71802
+ let length = this.lengthBase[lengthCode];
71803
+ const extraBits = this.lengthExtra[lengthCode];
71804
+ if (extraBits > 0) {
71805
+ length = length + this.reader.readBits(extraBits);
71806
+ }
71807
+ const distCode = distTable.decode(this.reader);
71808
+ let dist = this.distBase[distCode];
71809
+ const distExtraBits = this.distExtra[distCode];
71810
+ if (distExtraBits > 0) {
71811
+ dist = dist + this.reader.readBits(distExtraBits);
71812
+ }
71813
+ this.copyFromOutput(dist, length);
71814
+ }
71815
+ }
71816
+ ;
71817
+ }
71818
+ ;
71819
+ decompressDynamic() {
71820
+ const hlit = this.reader.readBits(5) + 257;
71821
+ const hdist = this.reader.readBits(5) + 1;
71822
+ const hclen = this.reader.readBits(4) + 4;
71823
+ let clOrder = [];
71824
+ clOrder.push(16);
71825
+ clOrder.push(17);
71826
+ clOrder.push(18);
71827
+ clOrder.push(0);
71828
+ clOrder.push(8);
71829
+ clOrder.push(7);
71830
+ clOrder.push(9);
71831
+ clOrder.push(6);
71832
+ clOrder.push(10);
71833
+ clOrder.push(5);
71834
+ clOrder.push(11);
71835
+ clOrder.push(4);
71836
+ clOrder.push(12);
71837
+ clOrder.push(3);
71838
+ clOrder.push(13);
71839
+ clOrder.push(2);
71840
+ clOrder.push(14);
71841
+ clOrder.push(1);
71842
+ clOrder.push(15);
71843
+ let clLengths = [];
71844
+ let i = 0;
71845
+ while (i < 19) {
71846
+ clLengths.push(0);
71847
+ i = i + 1;
71848
+ }
71849
+ ;
71850
+ i = 0;
71851
+ while (i < hclen) {
71852
+ const idx = clOrder[i];
71853
+ const __len = this.reader.readBits(3);
71854
+ clLengths[idx] = __len;
71855
+ i = i + 1;
71856
+ }
71857
+ ;
71858
+ const clTable = new InflateHuffmanTable();
71859
+ clTable.build(clLengths, 19);
71860
+ let allLengths = [];
71861
+ const totalCodes = hlit + hdist;
71862
+ i = 0;
71863
+ while (i < totalCodes) {
71864
+ const sym = clTable.decode(this.reader);
71865
+ if (sym < 16) {
71866
+ allLengths.push(sym);
71867
+ i = i + 1;
71868
+ }
71869
+ if (sym == 16) {
71870
+ const repeat = this.reader.readBits(2) + 3;
71871
+ let prevLen = 0;
71872
+ const arrLen = allLengths.length;
71873
+ if (arrLen > 0) {
71874
+ prevLen = allLengths[(arrLen - 1)];
71875
+ }
71876
+ let j = 0;
71877
+ while (j < repeat) {
71878
+ allLengths.push(prevLen);
71879
+ j = j + 1;
71880
+ }
71881
+ ;
71882
+ i = i + repeat;
71883
+ }
71884
+ if (sym == 17) {
71885
+ const repeat_1 = this.reader.readBits(3) + 3;
71886
+ let j_1 = 0;
71887
+ while (j_1 < repeat_1) {
71888
+ allLengths.push(0);
71889
+ j_1 = j_1 + 1;
71890
+ }
71891
+ ;
71892
+ i = i + repeat_1;
71893
+ }
71894
+ if (sym == 18) {
71895
+ const repeat_2 = this.reader.readBits(7) + 11;
71896
+ let j_2 = 0;
71897
+ while (j_2 < repeat_2) {
71898
+ allLengths.push(0);
71899
+ j_2 = j_2 + 1;
71900
+ }
71901
+ ;
71902
+ i = i + repeat_2;
71903
+ }
71904
+ }
71905
+ ;
71906
+ let litLenLengths = [];
71907
+ let distLengths = [];
71908
+ i = 0;
71909
+ while (i < hlit) {
71910
+ litLenLengths.push(allLengths[i]);
71911
+ i = i + 1;
71912
+ }
71913
+ ;
71914
+ while (i < totalCodes) {
71915
+ distLengths.push(allLengths[i]);
71916
+ i = i + 1;
71917
+ }
71918
+ ;
71919
+ const dynLitLen = new InflateHuffmanTable();
71920
+ dynLitLen.build(litLenLengths, hlit);
71921
+ const dynDist = new InflateHuffmanTable();
71922
+ dynDist.build(distLengths, hdist);
71923
+ this.decompressHuffman(dynLitLen, dynDist);
71924
+ }
71925
+ ;
71926
+ copyFromOutput(distance, length) {
71927
+ const srcPos = this.outLen - distance;
71928
+ this.ensureCapacity(length);
71929
+ let i = 0;
71930
+ while (i < length) {
71931
+ let b = 0;
71932
+ const readPos = srcPos + i;
71933
+ if (readPos >= 0) {
71934
+ if (readPos < this.outLen) {
71935
+ b = this.outBuf._view.getUint8(readPos);
71936
+ }
71937
+ }
71938
+ this.outBuf._view.setUint8(this.outLen, b);
71939
+ this.outLen = this.outLen + 1;
71940
+ i = i + 1;
71941
+ }
71942
+ ;
71943
+ }
71944
+ ;
71945
+ }
71946
+ exports.Inflate = Inflate;
71947
+ class GitZlib {
71948
+ constructor() {
71949
+ this.ok = true;
71950
+ this.err = "";
71951
+ this.nextPos = 0;
71952
+ this.ok = true;
71953
+ this.err = "";
71954
+ this.nextPos = 0;
71955
+ }
71956
+ inflateAt(data, offset) {
71957
+ this.ok = true;
71958
+ this.err = "";
71959
+ this.nextPos = offset;
71960
+ const n = data.byteLength;
71961
+ if (offset + 6 > n) {
71962
+ this.ok = false;
71963
+ this.err = "zlib stream truncated";
71964
+ return (function () { var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
71965
+ }
71966
+ const cmf = data._view.getUint8(offset);
71967
+ const flg = data._view.getUint8((offset + 1));
71968
+ const method = (cmf & 15);
71969
+ if (method != 8) {
71970
+ this.ok = false;
71971
+ this.err = "zlib method is not deflate";
71972
+ return (function () { var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
71973
+ }
71974
+ if ((flg & 32) != 0) {
71975
+ this.ok = false;
71976
+ this.err = "zlib preset dictionary is not used by Git";
71977
+ return (function () { var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
71978
+ }
71979
+ const inf = new Inflate();
71980
+ const out = inf.decompressFrom(data, (offset + 2));
71981
+ const end = inf.inputPos();
71982
+ if (end + 4 > n) {
71983
+ this.ok = false;
71984
+ this.err = "zlib Adler-32 truncated";
71985
+ this.nextPos = n;
71986
+ return out;
71987
+ }
71988
+ this.nextPos = end + 4;
71989
+ return out;
71990
+ }
71991
+ ;
71992
+ inflate(data) {
71993
+ return this.inflateAt(data, 0);
71994
+ }
71995
+ ;
71996
+ }
71997
+ exports.GitZlib = GitZlib;
71998
+ class GitObj {
71999
+ constructor() {
72000
+ this.kind = 0;
72001
+ this.sha = "";
72002
+ this.data = (function () { var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
72003
+ this.packOff = 0;
72004
+ this.resolved = false;
72005
+ this.delta = false;
72006
+ this.baseOff = 0;
72007
+ this.baseSha = "";
72008
+ }
72009
+ }
72010
+ exports.GitObj = GitObj;
72011
+ class GitPack {
72012
+ constructor() {
72013
+ this.ok = true;
72014
+ this.err = "";
72015
+ this.version = 0;
72016
+ this.count = 0;
72017
+ this.objects = [];
72018
+ this.bySha = {};
72019
+ this.byOff = {};
72020
+ }
72021
+ }
72022
+ exports.GitPack = GitPack;
72023
+ class GitDelta {
72024
+ constructor() {
72025
+ }
72026
+ static varInt(data, pos) {
72027
+ let at = pos[0];
72028
+ const n = data.byteLength;
72029
+ if (at >= n) {
72030
+ return 0;
72031
+ }
72032
+ let c = data._view.getUint8(at);
72033
+ at = at + 1;
72034
+ let v = (c & 127);
72035
+ let shift = 7;
72036
+ while ((c & 128) != 0) {
72037
+ if (at >= n) {
72038
+ pos[0] = at;
72039
+ return v;
72040
+ }
72041
+ c = data._view.getUint8(at);
72042
+ at = at + 1;
72043
+ v = (v | ((c & 127) << shift));
72044
+ shift = shift + 7;
72045
+ }
72046
+ ;
72047
+ pos[0] = at;
72048
+ return v;
72049
+ }
72050
+ ;
72051
+ static apply(src, delta) {
72052
+ let pos = [];
72053
+ pos.push(0);
72054
+ const srcSize = GitDelta.varInt(delta, pos);
72055
+ const dstSize = GitDelta.varInt(delta, pos);
72056
+ const srcLen = src.byteLength;
72057
+ if (srcSize != srcLen) {
72058
+ }
72059
+ let out = (function () { var b = new ArrayBuffer(dstSize); b._view = new DataView(b); return b; })();
72060
+ let o = 0;
72061
+ const n = delta.byteLength;
72062
+ let at = pos[0];
72063
+ while (at < n) {
72064
+ const cmd = delta._view.getUint8(at);
72065
+ at = at + 1;
72066
+ if ((cmd & 128) != 0) {
72067
+ let cpOff = 0;
72068
+ let cpSize = 0;
72069
+ if ((cmd & 1) != 0) {
72070
+ cpOff = delta._view.getUint8(at);
72071
+ at = at + 1;
72072
+ }
72073
+ if ((cmd & 2) != 0) {
72074
+ cpOff = (cpOff | (delta._view.getUint8(at) << 8));
72075
+ at = at + 1;
72076
+ }
72077
+ if ((cmd & 4) != 0) {
72078
+ cpOff = (cpOff | (delta._view.getUint8(at) << 16));
72079
+ at = at + 1;
72080
+ }
72081
+ if ((cmd & 8) != 0) {
72082
+ cpOff = (cpOff | (delta._view.getUint8(at) << 24));
72083
+ at = at + 1;
72084
+ }
72085
+ if ((cmd & 16) != 0) {
72086
+ cpSize = delta._view.getUint8(at);
72087
+ at = at + 1;
72088
+ }
72089
+ if ((cmd & 32) != 0) {
72090
+ cpSize = (cpSize | (delta._view.getUint8(at) << 8));
72091
+ at = at + 1;
72092
+ }
72093
+ if ((cmd & 64) != 0) {
72094
+ cpSize = (cpSize | (delta._view.getUint8(at) << 16));
72095
+ at = at + 1;
72096
+ }
72097
+ if (cpSize == 0) {
72098
+ cpSize = 65536;
72099
+ }
72100
+ (function (d, dOff, s, sOff, len) { var dv = new Uint8Array(d); var sv = new Uint8Array(s); for (var i = 0; i < len; i++)
72101
+ dv[dOff + i] = sv[sOff + i]; })(out, o, src, cpOff, cpSize);
72102
+ o = o + cpSize;
72103
+ }
72104
+ else {
72105
+ if (cmd == 0) {
72106
+ return out;
72107
+ }
72108
+ (function (d, dOff, s, sOff, len) { var dv = new Uint8Array(d); var sv = new Uint8Array(s); for (var i = 0; i < len; i++)
72109
+ dv[dOff + i] = sv[sOff + i]; })(out, o, delta, at, cmd);
72110
+ o = o + cmd;
72111
+ at = at + cmd;
72112
+ }
72113
+ }
72114
+ ;
72115
+ return out;
72116
+ }
72117
+ ;
72118
+ }
72119
+ exports.GitDelta = GitDelta;
72120
+ class GitPackIO {
72121
+ constructor() {
72122
+ }
72123
+ static kindName(kind) {
72124
+ if (kind == 1) {
72125
+ return "commit";
72126
+ }
72127
+ if (kind == 2) {
72128
+ return "tree";
72129
+ }
72130
+ if (kind == 3) {
72131
+ return "blob";
72132
+ }
72133
+ if (kind == 4) {
72134
+ return "tag";
72135
+ }
72136
+ return "unknown";
72137
+ }
72138
+ ;
72139
+ static parse(data) {
72140
+ const pack = new GitPack();
72141
+ const n = data.byteLength;
72142
+ if (n < 32) {
72143
+ pack.ok = false;
72144
+ pack.err = "pack too small";
72145
+ return pack;
72146
+ }
72147
+ const mag = GitSha1.ascii(data, 0, 4);
72148
+ if (mag != "PACK") {
72149
+ pack.ok = false;
72150
+ pack.err = "not a pack (missing PACK magic)";
72151
+ return pack;
72152
+ }
72153
+ pack.version = GitSha1.u32be(data, 4);
72154
+ pack.count = GitSha1.u32be(data, 8);
72155
+ if (pack.version != 2) {
72156
+ pack.ok = false;
72157
+ pack.err = "unsupported pack version " + (pack.version.toString());
72158
+ return pack;
72159
+ }
72160
+ const z = new GitZlib();
72161
+ let at = 12;
72162
+ let i = 0;
72163
+ while (i < pack.count) {
72164
+ if (at >= n - 20) {
72165
+ pack.ok = false;
72166
+ pack.err = "truncated pack at object " + (i.toString());
72167
+ return pack;
72168
+ }
72169
+ const obj = new GitObj();
72170
+ obj.packOff = at;
72171
+ let c = data._view.getUint8(at);
72172
+ at = at + 1;
72173
+ obj.kind = ((c >>> 4) & 7);
72174
+ let size = (c & 15);
72175
+ let shift = 4;
72176
+ while ((c & 128) != 0) {
72177
+ if (at >= n) {
72178
+ pack.ok = false;
72179
+ pack.err = "truncated size encoding";
72180
+ return pack;
72181
+ }
72182
+ c = data._view.getUint8(at);
72183
+ at = at + 1;
72184
+ size = (size | ((c & 127) << shift));
72185
+ shift = shift + 7;
72186
+ }
72187
+ ;
72188
+ if (obj.kind == 6) {
72189
+ let oc = data._view.getUint8(at);
72190
+ at = at + 1;
72191
+ let offv = (oc & 127);
72192
+ while ((oc & 128) != 0) {
72193
+ oc = data._view.getUint8(at);
72194
+ at = at + 1;
72195
+ offv = offv + 1;
72196
+ offv = offv * 128 + (oc & 127);
72197
+ }
72198
+ ;
72199
+ obj.delta = true;
72200
+ obj.baseOff = obj.packOff - offv;
72201
+ }
72202
+ if (obj.kind == 7) {
72203
+ obj.delta = true;
72204
+ obj.baseSha = GitSha1.toHex(GitSha1.copyRange(data, at, 20));
72205
+ at = at + 20;
72206
+ }
72207
+ const inflated = z.inflateAt(data, at);
72208
+ if (z.ok == false) {
72209
+ pack.ok = false;
72210
+ pack.err = (("inflate object " + (i.toString())) + ": ") + z.err;
72211
+ return pack;
72212
+ }
72213
+ at = z.nextPos;
72214
+ obj.data = inflated;
72215
+ if (obj.delta) {
72216
+ obj.resolved = false;
72217
+ }
72218
+ else {
72219
+ obj.resolved = true;
72220
+ obj.sha = GitSha1.objectId(GitPackIO.kindName(obj.kind), inflated);
72221
+ pack.bySha[obj.sha] = obj;
72222
+ }
72223
+ pack.byOff[obj.packOff] = obj;
72224
+ pack.objects.push(obj);
72225
+ i = i + 1;
72226
+ }
72227
+ ;
72228
+ GitPackIO.resolveDeltas(pack);
72229
+ return pack;
72230
+ }
72231
+ ;
72232
+ static resolveDeltas(pack) {
72233
+ let guard = 0;
72234
+ let progress = true;
72235
+ while (progress) {
72236
+ if (guard > 64) {
72237
+ pack.ok = false;
72238
+ pack.err = "delta chain too deep";
72239
+ return;
72240
+ }
72241
+ progress = false;
72242
+ let i = 0;
72243
+ while (i < pack.objects.length) {
72244
+ const obj = pack.objects[i];
72245
+ if (obj.resolved == false) {
72246
+ let base;
72247
+ if (obj.kind == 6) {
72248
+ if ((typeof (pack.byOff[obj.baseOff]) != "undefined" && Object.prototype.hasOwnProperty.call(pack.byOff, obj.baseOff))) {
72249
+ base = (Object.prototype.hasOwnProperty.call(pack.byOff, obj.baseOff) ? pack.byOff[obj.baseOff] : undefined);
72250
+ }
72251
+ }
72252
+ if (obj.kind == 7) {
72253
+ if ((typeof (pack.bySha[obj.baseSha]) != "undefined" && Object.prototype.hasOwnProperty.call(pack.bySha, obj.baseSha))) {
72254
+ base = (Object.prototype.hasOwnProperty.call(pack.bySha, obj.baseSha) ? pack.bySha[obj.baseSha] : undefined);
72255
+ }
72256
+ }
72257
+ if (typeof (base) === "undefined") {
72258
+ }
72259
+ else {
72260
+ const b = base;
72261
+ if (b.resolved) {
72262
+ const out = GitDelta.apply(b.data, obj.data);
72263
+ obj.data = out;
72264
+ obj.kind = b.kind;
72265
+ obj.delta = false;
72266
+ obj.resolved = true;
72267
+ obj.sha = GitSha1.objectId(GitPackIO.kindName(obj.kind), out);
72268
+ pack.bySha[obj.sha] = obj;
72269
+ progress = true;
72270
+ }
72271
+ }
72272
+ }
72273
+ i = i + 1;
72274
+ }
72275
+ ;
72276
+ guard = guard + 1;
72277
+ }
72278
+ ;
72279
+ let j = 0;
72280
+ while (j < pack.objects.length) {
72281
+ const o2 = pack.objects[j];
72282
+ if (o2.resolved == false) {
72283
+ pack.ok = false;
72284
+ pack.err = "unresolved delta in pack";
72285
+ return;
72286
+ }
72287
+ j = j + 1;
72288
+ }
72289
+ ;
72290
+ }
72291
+ ;
72292
+ static lookup(pack, sha) {
72293
+ let res;
72294
+ if ((typeof (pack.bySha[sha]) != "undefined" && Object.prototype.hasOwnProperty.call(pack.bySha, sha))) {
72295
+ res = (Object.prototype.hasOwnProperty.call(pack.bySha, sha) ? pack.bySha[sha] : undefined);
72296
+ }
72297
+ return res;
72298
+ }
72299
+ ;
72300
+ static merge(a, b) {
72301
+ const out = new GitPack();
72302
+ if (a.ok == false) {
72303
+ out.ok = false;
72304
+ out.err = a.err;
72305
+ return out;
72306
+ }
72307
+ if (b.ok == false) {
72308
+ out.ok = false;
72309
+ out.err = b.err;
72310
+ return out;
72311
+ }
72312
+ let i = 0;
72313
+ while (i < a.objects.length) {
72314
+ const o = a.objects[i];
72315
+ out.objects.push(o);
72316
+ out.bySha[o.sha] = o;
72317
+ i = i + 1;
72318
+ }
72319
+ ;
72320
+ i = 0;
72321
+ while (i < b.objects.length) {
72322
+ const o2 = b.objects[i];
72323
+ if ((typeof (out.bySha[o2.sha]) != "undefined" && Object.prototype.hasOwnProperty.call(out.bySha, o2.sha))) {
72324
+ }
72325
+ else {
72326
+ out.objects.push(o2);
72327
+ out.bySha[o2.sha] = o2;
72328
+ }
72329
+ i = i + 1;
72330
+ }
72331
+ ;
72332
+ out.count = out.objects.length;
72333
+ out.ok = true;
72334
+ return out;
72335
+ }
72336
+ ;
72337
+ }
72338
+ exports.GitPackIO = GitPackIO;
72339
+ class GitEntry {
72340
+ constructor() {
72341
+ this.name = "";
72342
+ this.sha = "";
72343
+ this.isTree = false;
72344
+ this.mode = "";
72345
+ }
72346
+ }
72347
+ exports.GitEntry = GitEntry;
72348
+ class GitFile {
72349
+ constructor() {
72350
+ this.path = "";
72351
+ this.data = (function () { var b = new ArrayBuffer(0); b._view = new DataView(b); return b; })();
72352
+ }
72353
+ }
72354
+ exports.GitFile = GitFile;
72355
+ class GitTree {
72356
+ constructor() {
72357
+ this.sha = ""; /* note: unused */
72358
+ this.entries = [];
72359
+ }
72360
+ }
72361
+ exports.GitTree = GitTree;
72362
+ class GitMem {
72363
+ constructor() {
72364
+ this.files = [];
72365
+ this.paths = [];
72366
+ this.byPath = {};
72367
+ }
72368
+ }
72369
+ exports.GitMem = GitMem;
72370
+ class GitStore {
72371
+ constructor(p) {
72372
+ this.pack = new GitPack();
72373
+ this.ok = true;
72374
+ this.err = "";
72375
+ this.pack = p;
72376
+ this.ok = p.ok;
72377
+ this.err = p.err;
72378
+ }
72379
+ takeObj(sha) {
72380
+ return GitPackIO.lookup(this.pack, sha);
72381
+ }
72382
+ ;
72383
+ parseTree(payload) {
72384
+ const t = new GitTree();
72385
+ const n = payload.byteLength;
72386
+ let at = 0;
72387
+ while (at < n) {
72388
+ const modeStart = at;
72389
+ while (at < n) {
72390
+ if (payload._view.getUint8(at) == 32) {
72391
+ break;
72392
+ }
72393
+ at = at + 1;
72394
+ }
72395
+ ;
72396
+ const mode = GitSha1.ascii(payload, modeStart, (at - modeStart));
72397
+ at = at + 1;
72398
+ const nameStart = at;
72399
+ while (at < n) {
72400
+ if (payload._view.getUint8(at) == 0) {
72401
+ break;
72402
+ }
72403
+ at = at + 1;
72404
+ }
72405
+ ;
72406
+ const name = GitSha1.ascii(payload, nameStart, (at - nameStart));
72407
+ at = at + 1;
72408
+ if (at + 20 > n) {
72409
+ break;
72410
+ }
72411
+ const sha = GitSha1.toHex(GitSha1.copyRange(payload, at, 20));
72412
+ at = at + 20;
72413
+ const e = new GitEntry();
72414
+ e.name = name;
72415
+ e.sha = sha;
72416
+ e.mode = mode;
72417
+ if (mode.length > 0) {
72418
+ if (mode.substring(0, 1) == "4") {
72419
+ e.isTree = true;
72420
+ }
72421
+ }
72422
+ t.entries.push(e);
72423
+ }
72424
+ ;
72425
+ return t;
72426
+ }
72427
+ ;
72428
+ commitTree(payload) {
72429
+ const text = (function (b) { var v = (b instanceof Uint8Array) ? b : new Uint8Array(b); var s = ""; var i = 0; var n = v.length; var c = 32768; while (i < n) {
72430
+ var e = i + c;
72431
+ if (e > n) {
72432
+ e = n;
72433
+ }
72434
+ s += String.fromCharCode.apply(null, v.subarray(i, e));
72435
+ i = e;
72436
+ } return s; })(payload);
72437
+ if (text.length < 46) {
72438
+ return "";
72439
+ }
72440
+ if (text.substring(0, 5) != "tree ") {
72441
+ return "";
72442
+ }
72443
+ return text.substring(5, 45);
72444
+ }
72445
+ ;
72446
+ checkout(sha, subdir) {
72447
+ const mem = new GitMem();
72448
+ const obj = this.takeObj(sha);
72449
+ if (typeof (obj) === "undefined") {
72450
+ this.ok = false;
72451
+ this.err = "object not in pack: " + sha;
72452
+ return mem;
72453
+ }
72454
+ const o = obj;
72455
+ let treeSha = sha;
72456
+ if (o.kind == 1) {
72457
+ treeSha = this.commitTree(o.data);
72458
+ }
72459
+ if (o.kind == 4) {
72460
+ const tagText = (function (b) { var v = (b instanceof Uint8Array) ? b : new Uint8Array(b); var s = ""; var i = 0; var n = v.length; var c = 32768; while (i < n) {
72461
+ var e = i + c;
72462
+ if (e > n) {
72463
+ e = n;
72464
+ }
72465
+ s += String.fromCharCode.apply(null, v.subarray(i, e));
72466
+ i = e;
72467
+ } return s; })(o.data);
72468
+ if (tagText.length >= 48) {
72469
+ if (tagText.substring(0, 7) == "object ") {
72470
+ treeSha = tagText.substring(7, 47);
72471
+ const inner = this.takeObj(treeSha);
72472
+ if (typeof (inner) === "undefined") {
72473
+ this.ok = false;
72474
+ this.err = "tag target missing: " + treeSha;
72475
+ return mem;
72476
+ }
72477
+ const inn = inner;
72478
+ if (inn.kind == 1) {
72479
+ treeSha = this.commitTree(inn.data);
72480
+ }
72481
+ }
72482
+ }
72483
+ }
72484
+ this.walk(mem, treeSha, "", subdir);
72485
+ return mem;
72486
+ }
72487
+ ;
72488
+ walk(mem, treeSha, prefix, want) {
72489
+ const obj = this.takeObj(treeSha);
72490
+ if (typeof (obj) === "undefined") {
72491
+ this.ok = false;
72492
+ this.err = "tree missing: " + treeSha;
72493
+ return;
72494
+ }
72495
+ const o = obj;
72496
+ const tree = this.parseTree(o.data);
72497
+ let i = 0;
72498
+ while (i < tree.entries.length) {
72499
+ const e = tree.entries[i];
72500
+ let path = e.name;
72501
+ if (prefix.length > 0) {
72502
+ path = (prefix + "/") + e.name;
72503
+ }
72504
+ if (e.isTree) {
72505
+ if (this.mayEnter(path, want)) {
72506
+ this.walk(mem, e.sha, path, want);
72507
+ }
72508
+ }
72509
+ else {
72510
+ if (this.underSubdir(path, want)) {
72511
+ const blob = this.takeObj(e.sha);
72512
+ if (typeof (blob) === "undefined") {
72513
+ this.ok = false;
72514
+ this.err = "blob missing: " + e.sha;
72515
+ }
72516
+ else {
72517
+ const b = blob;
72518
+ const rel = this.stripSubdir(path, want);
72519
+ const f = new GitFile();
72520
+ f.path = rel;
72521
+ f.data = b.data;
72522
+ mem.files.push(f);
72523
+ mem.paths.push(rel);
72524
+ mem.byPath[rel] = f;
72525
+ }
72526
+ }
72527
+ }
72528
+ i = i + 1;
72529
+ }
72530
+ ;
72531
+ }
72532
+ ;
72533
+ mayEnter(path, want) {
72534
+ if (want.length == 0) {
72535
+ return true;
72536
+ }
72537
+ if (this.underSubdir(path, want)) {
72538
+ return true;
72539
+ }
72540
+ const pn = path.length;
72541
+ const wn = want.length;
72542
+ if (wn > pn) {
72543
+ if (want.substring(0, pn) == path) {
72544
+ if (want.charCodeAt(pn) == 47) {
72545
+ return true;
72546
+ }
72547
+ }
72548
+ }
72549
+ return path == want;
72550
+ }
72551
+ ;
72552
+ splitSegs(path) {
72553
+ let parts = [];
72554
+ const n = path.length;
72555
+ let start = 0;
72556
+ let i = 0;
72557
+ while (i <= n) {
72558
+ if (i == n || path.charCodeAt(i) == 47) {
72559
+ const piece = path.substring(start, i);
72560
+ if (piece.length > 0) {
72561
+ parts.push(piece);
72562
+ }
72563
+ start = i + 1;
72564
+ }
72565
+ i = i + 1;
72566
+ }
72567
+ ;
72568
+ return parts;
72569
+ }
72570
+ ;
72571
+ asTreeSha(sha) {
72572
+ const obj = this.takeObj(sha);
72573
+ if (typeof (obj) === "undefined") {
72574
+ this.ok = false;
72575
+ this.err = "object not in pack: " + sha;
72576
+ return "";
72577
+ }
72578
+ const o = obj;
72579
+ if (o.kind == 2) {
72580
+ return sha;
72581
+ }
72582
+ if (o.kind == 1) {
72583
+ return this.commitTree(o.data);
72584
+ }
72585
+ if (o.kind == 4) {
72586
+ const tagText = (function (b) { var v = (b instanceof Uint8Array) ? b : new Uint8Array(b); var s = ""; var i = 0; var n = v.length; var c = 32768; while (i < n) {
72587
+ var e = i + c;
72588
+ if (e > n) {
72589
+ e = n;
72590
+ }
72591
+ s += String.fromCharCode.apply(null, v.subarray(i, e));
72592
+ i = e;
72593
+ } return s; })(o.data);
72594
+ if (tagText.length >= 48) {
72595
+ if (tagText.substring(0, 7) == "object ") {
72596
+ const inner = tagText.substring(7, 47);
72597
+ const inn = this.takeObj(inner);
72598
+ if (typeof (inn) === "undefined") {
72599
+ return inner;
72600
+ }
72601
+ const io = inn;
72602
+ if (io.kind == 1) {
72603
+ return this.commitTree(io.data);
72604
+ }
72605
+ if (io.kind == 2) {
72606
+ return inner;
72607
+ }
72608
+ }
72609
+ }
72610
+ }
72611
+ return sha;
72612
+ }
72613
+ ;
72614
+ treeAt(sha, subdir) {
72615
+ let cur = this.asTreeSha(sha);
72616
+ if (cur.length == 0) {
72617
+ return "";
72618
+ }
72619
+ if (subdir.length == 0) {
72620
+ return cur;
72621
+ }
72622
+ const segs = this.splitSegs(subdir);
72623
+ let s = 0;
72624
+ while (s < segs.length) {
72625
+ const part = segs[s];
72626
+ const obj = this.takeObj(cur);
72627
+ if (typeof (obj) === "undefined") {
72628
+ this.ok = false;
72629
+ this.err = "tree missing: " + cur;
72630
+ return "";
72631
+ }
72632
+ const o = obj;
72633
+ const tree = this.parseTree(o.data);
72634
+ let found = "";
72635
+ let i = 0;
72636
+ while (i < tree.entries.length) {
72637
+ const e = tree.entries[i];
72638
+ if (e.name == part) {
72639
+ if (e.isTree) {
72640
+ found = e.sha;
72641
+ }
72642
+ }
72643
+ i = i + 1;
72644
+ }
72645
+ ;
72646
+ if (found.length == 0) {
72647
+ this.ok = false;
72648
+ this.err = (("no subtree " + part) + " in ") + subdir;
72649
+ return "";
72650
+ }
72651
+ cur = found;
72652
+ s = s + 1;
72653
+ }
72654
+ ;
72655
+ return cur;
72656
+ }
72657
+ ;
72658
+ underSubdir(path, want) {
72659
+ if (want.length == 0) {
72660
+ return true;
72661
+ }
72662
+ if (path == want) {
72663
+ return true;
72664
+ }
72665
+ const prefix = want + "/";
72666
+ const n = prefix.length;
72667
+ if (path.length < n) {
72668
+ return false;
72669
+ }
72670
+ return path.substring(0, n) == prefix;
72671
+ }
72672
+ ;
72673
+ stripSubdir(path, want) {
72674
+ if (want.length == 0) {
72675
+ return path;
72676
+ }
72677
+ if (path == want) {
72678
+ return this.baseName(path);
72679
+ }
72680
+ const prefix = want + "/";
72681
+ const n = prefix.length;
72682
+ if (path.length >= n) {
72683
+ if (path.substring(0, n) == prefix) {
72684
+ return path.substring(n, path.length);
72685
+ }
72686
+ }
72687
+ return path;
72688
+ }
72689
+ ;
72690
+ baseName(path) {
72691
+ const n = path.length;
72692
+ let i = n - 1;
72693
+ while (i >= 0) {
72694
+ if (path.charCodeAt(i) == 47) {
72695
+ return path.substring((i + 1), n);
72696
+ }
72697
+ i = i - 1;
72698
+ }
72699
+ ;
72700
+ return path;
72701
+ }
72702
+ ;
72703
+ writeDisk(mem, root) {
72704
+ let i = 0;
72705
+ while (i < mem.files.length) {
72706
+ const f = mem.files[i];
72707
+ const dir = this.dirOf(((root + "/") + f.path));
72708
+ require("fs").mkdirSync(dir, { recursive: true });
72709
+ const parts = this.splitPath(((root + "/") + f.path));
72710
+ require('fs').writeFileSync(parts[0] + '/' + parts[1], Buffer.from(f.data));
72711
+ i = i + 1;
72712
+ }
72713
+ ;
72714
+ }
72715
+ ;
72716
+ dirOf(path) {
72717
+ const n = path.length;
72718
+ let i = n - 1;
72719
+ while (i >= 0) {
72720
+ if (path.charCodeAt(i) == 47) {
72721
+ return path.substring(0, i);
72722
+ }
72723
+ i = i - 1;
72724
+ }
72725
+ ;
72726
+ return ".";
72727
+ }
72728
+ ;
72729
+ splitPath(path) {
72730
+ let dir = ".";
72731
+ let name = path;
72732
+ const n = path.length;
72733
+ let i = n - 1;
72734
+ while (i >= 0) {
72735
+ if (path.charCodeAt(i) == 47) {
72736
+ dir = path.substring(0, i);
72737
+ name = path.substring((i + 1), n);
72738
+ i = 0 - 1;
72739
+ }
72740
+ else {
72741
+ i = i - 1;
72742
+ }
72743
+ }
72744
+ ;
72745
+ let parts = [];
72746
+ parts.push(dir);
72747
+ parts.push(name);
72748
+ return parts;
72749
+ }
72750
+ ;
72751
+ fileText(mem, path) {
72752
+ if ((typeof (mem.byPath[path]) != "undefined" && Object.prototype.hasOwnProperty.call(mem.byPath, path))) {
72753
+ const f = (Object.prototype.hasOwnProperty.call(mem.byPath, path) ? mem.byPath[path] : undefined);
72754
+ return (function (b) { var v = (b instanceof Uint8Array) ? b : new Uint8Array(b); var s = ""; var i = 0; var n = v.length; var c = 32768; while (i < n) {
72755
+ var e = i + c;
72756
+ if (e > n) {
72757
+ e = n;
72758
+ }
72759
+ s += String.fromCharCode.apply(null, v.subarray(i, e));
72760
+ i = e;
72761
+ } return s; })(f.data);
72762
+ }
72763
+ return "";
72764
+ }
72765
+ ;
72766
+ }
72767
+ exports.GitStore = GitStore;
72768
+ class PkgVal {
72769
+ constructor() {
72770
+ this.kind = "null";
72771
+ this.str = "";
72772
+ this.num = 0;
72773
+ this.flag = false;
72774
+ this.keys = [];
72775
+ this.vals = [];
72776
+ }
72777
+ }
72778
+ exports.PkgVal = PkgVal;
72779
+ class PkgJson {
72780
+ constructor() {
72781
+ this.text = "";
72782
+ this.i = 0;
72783
+ this.n = 0;
72784
+ this.ok = true;
72785
+ this.err = "";
72786
+ }
72787
+ parse(src) {
72788
+ this.text = src;
72789
+ this.i = 0;
72790
+ this.n = src.length;
72791
+ this.ok = true;
72792
+ this.err = "";
72793
+ this.skip();
72794
+ const v = this.value();
72795
+ return v;
72796
+ }
72797
+ ;
72798
+ skip() {
72799
+ while (this.i < this.n) {
72800
+ const c = this.text.charCodeAt(this.i);
72801
+ if (c <= 32) {
72802
+ this.i = this.i + 1;
72803
+ }
72804
+ else {
72805
+ return;
72806
+ }
72807
+ }
72808
+ ;
72809
+ }
72810
+ ;
72811
+ value() {
72812
+ this.skip();
72813
+ const v = new PkgVal();
72814
+ if (this.i >= this.n) {
72815
+ this.ok = false;
72816
+ this.err = "unexpected end of JSON";
72817
+ return v;
72818
+ }
72819
+ const c = this.text.charCodeAt(this.i);
72820
+ if (c == 123) {
72821
+ return this.object();
72822
+ }
72823
+ if (c == 34) {
72824
+ v.kind = "str";
72825
+ v.str = this.str();
72826
+ return v;
72827
+ }
72828
+ if (c == 116) {
72829
+ v.kind = "bool";
72830
+ v.flag = true;
72831
+ this.i = this.i + 4;
72832
+ return v;
72833
+ }
72834
+ if (c == 102) {
72835
+ v.kind = "bool";
72836
+ v.flag = false;
72837
+ this.i = this.i + 5;
72838
+ return v;
72839
+ }
72840
+ if (c == 110) {
72841
+ v.kind = "null";
72842
+ this.i = this.i + 4;
72843
+ return v;
72844
+ }
72845
+ v.kind = "int";
72846
+ v.num = this.num();
72847
+ return v;
72848
+ }
72849
+ ;
72850
+ object() {
72851
+ const v = new PkgVal();
72852
+ v.kind = "obj";
72853
+ this.i = this.i + 1;
72854
+ this.skip();
72855
+ while (this.i < this.n) {
72856
+ const c = this.text.charCodeAt(this.i);
72857
+ if (c == 125) {
72858
+ this.i = this.i + 1;
72859
+ return v;
72860
+ }
72861
+ if (c == 44) {
72862
+ this.i = this.i + 1;
72863
+ this.skip();
72864
+ }
72865
+ else {
72866
+ const key = this.str();
72867
+ this.skip();
72868
+ if (this.i < this.n) {
72869
+ if (this.text.charCodeAt(this.i) == 58) {
72870
+ this.i = this.i + 1;
72871
+ }
72872
+ }
72873
+ const child = this.value();
72874
+ v.keys.push(key);
72875
+ v.vals.push(child);
72876
+ this.skip();
72877
+ }
72878
+ }
72879
+ ;
72880
+ this.ok = false;
72881
+ this.err = "unterminated object";
72882
+ return v;
72883
+ }
72884
+ ;
72885
+ str() {
72886
+ this.skip();
72887
+ if (this.i >= this.n) {
72888
+ return "";
72889
+ }
72890
+ if (this.text.charCodeAt(this.i) != 34) {
72891
+ this.ok = false;
72892
+ this.err = "expected string";
72893
+ return "";
72894
+ }
72895
+ this.i = this.i + 1;
72896
+ let s = "";
72897
+ while (this.i < this.n) {
72898
+ const c = this.text.charCodeAt(this.i);
72899
+ if (c == 34) {
72900
+ this.i = this.i + 1;
72901
+ return s;
72902
+ }
72903
+ if (c == 92) {
72904
+ this.i = this.i + 1;
72905
+ if (this.i < this.n) {
72906
+ const e = this.text.charCodeAt(this.i);
72907
+ if (e == 110) {
72908
+ s = s + String.fromCharCode(10);
72909
+ }
72910
+ else {
72911
+ if (e == 116) {
72912
+ s = s + String.fromCharCode(9);
72913
+ }
72914
+ else {
72915
+ if (e == 114) {
72916
+ s = s + String.fromCharCode(13);
72917
+ }
72918
+ else {
72919
+ s = s + String.fromCharCode(e);
72920
+ }
72921
+ }
72922
+ }
72923
+ this.i = this.i + 1;
72924
+ }
72925
+ }
72926
+ else {
72927
+ s = s + String.fromCharCode(c);
72928
+ this.i = this.i + 1;
72929
+ }
72930
+ }
72931
+ ;
72932
+ this.ok = false;
72933
+ this.err = "unterminated string";
72934
+ return s;
72935
+ }
72936
+ ;
72937
+ num() {
72938
+ let sign = 1;
72939
+ if (this.i < this.n) {
72940
+ if (this.text.charCodeAt(this.i) == 45) {
72941
+ sign = 0 - 1;
72942
+ this.i = this.i + 1;
72943
+ }
72944
+ }
72945
+ let v = 0;
72946
+ while (this.i < this.n) {
72947
+ const c = this.text.charCodeAt(this.i);
72948
+ if (c >= 48 && c <= 57) {
72949
+ v = v * 10 + (c - 48);
72950
+ this.i = this.i + 1;
72951
+ }
72952
+ else {
72953
+ return v * sign;
72954
+ }
72955
+ }
72956
+ ;
72957
+ return v * sign;
72958
+ }
72959
+ ;
72960
+ static child(obj, key) {
72961
+ let res;
72962
+ let i = 0;
72963
+ while (i < obj.keys.length) {
72964
+ if (obj.keys[i] == key) {
72965
+ res = obj.vals[i];
72966
+ return res;
72967
+ }
72968
+ i = i + 1;
72969
+ }
72970
+ ;
72971
+ return res;
72972
+ }
72973
+ ;
72974
+ static strOf(obj, key) {
72975
+ const hit = PkgJson.child(obj, key);
72976
+ if (typeof (hit) === "undefined") {
72977
+ return "";
72978
+ }
72979
+ const v = hit;
72980
+ if (v.kind == "str") {
72981
+ return v.str;
72982
+ }
72983
+ if (v.kind == "int") {
72984
+ return (v.num.toString());
72985
+ }
72986
+ return "";
72987
+ }
72988
+ ;
72989
+ static intOf(obj, key) {
72990
+ const hit = PkgJson.child(obj, key);
72991
+ if (typeof (hit) === "undefined") {
72992
+ return 0;
72993
+ }
72994
+ const v = hit;
72995
+ if (v.kind == "int") {
72996
+ return v.num;
72997
+ }
72998
+ return 0;
72999
+ }
73000
+ ;
73001
+ }
73002
+ exports.PkgJson = PkgJson;
73003
+ class PkgDep {
73004
+ constructor() {
73005
+ this.name = "";
73006
+ this.path = "";
73007
+ this.git = "";
73008
+ this.rev = "";
73009
+ this.tag = "";
73010
+ this.subdir = "";
73011
+ }
73012
+ }
73013
+ exports.PkgDep = PkgDep;
73014
+ class PkgManifest {
73015
+ constructor() {
73016
+ this.name = "";
73017
+ this.version = "";
73018
+ this.entry = "";
73019
+ this.license = "";
73020
+ this.deps = [];
73021
+ this.ok = true;
73022
+ this.err = "";
73023
+ }
73024
+ }
73025
+ exports.PkgManifest = PkgManifest;
73026
+ class PkgLockEnt {
73027
+ constructor() {
73028
+ this.name = "";
73029
+ this.path = "";
73030
+ this.git = "";
73031
+ this.rev = "";
73032
+ this.subdir = "";
73033
+ this.sha256 = "";
73034
+ }
73035
+ }
73036
+ exports.PkgLockEnt = PkgLockEnt;
73037
+ class PkgLock {
73038
+ constructor() {
73039
+ this.lockVersion = 1;
73040
+ this.packages = [];
73041
+ this.ok = true;
73042
+ this.err = "";
73043
+ }
73044
+ }
73045
+ exports.PkgLock = PkgLock;
73046
+ class PkgManifestIO {
73047
+ constructor() {
73048
+ }
73049
+ static load(src) {
73050
+ const m = new PkgManifest();
73051
+ const p = new PkgJson();
73052
+ const root = p.parse(src);
73053
+ if (p.ok == false) {
73054
+ m.ok = false;
73055
+ m.err = p.err;
73056
+ return m;
73057
+ }
73058
+ m.name = PkgJson.strOf(root, "name");
73059
+ m.version = PkgJson.strOf(root, "version");
73060
+ m.entry = PkgJson.strOf(root, "entry");
73061
+ m.license = PkgJson.strOf(root, "license");
73062
+ const deps = PkgJson.child(root, "dependencies");
73063
+ if (typeof (deps) === "undefined") {
73064
+ return m;
73065
+ }
73066
+ const d = deps;
73067
+ let i = 0;
73068
+ while (i < d.keys.length) {
73069
+ const dep = new PkgDep();
73070
+ dep.name = d.keys[i];
73071
+ const spec = d.vals[i];
73072
+ dep.path = PkgJson.strOf(spec, "path");
73073
+ dep.git = PkgJson.strOf(spec, "git");
73074
+ dep.rev = PkgJson.strOf(spec, "rev");
73075
+ dep.tag = PkgJson.strOf(spec, "tag");
73076
+ dep.subdir = PkgJson.strOf(spec, "subdir");
73077
+ m.deps.push(dep);
73078
+ i = i + 1;
73079
+ }
73080
+ ;
73081
+ return m;
73082
+ }
73083
+ ;
73084
+ static loadLock(src) {
73085
+ const lock = new PkgLock();
73086
+ const p = new PkgJson();
73087
+ const root = p.parse(src);
73088
+ if (p.ok == false) {
73089
+ lock.ok = false;
73090
+ lock.err = p.err;
73091
+ return lock;
73092
+ }
73093
+ lock.lockVersion = PkgJson.intOf(root, "lockVersion");
73094
+ if (lock.lockVersion == 0) {
73095
+ lock.lockVersion = 1;
73096
+ }
73097
+ const pkgs = PkgJson.child(root, "packages");
73098
+ if (typeof (pkgs) === "undefined") {
73099
+ return lock;
73100
+ }
73101
+ const o = pkgs;
73102
+ let i = 0;
73103
+ while (i < o.keys.length) {
73104
+ const e = new PkgLockEnt();
73105
+ e.name = o.keys[i];
73106
+ const spec = o.vals[i];
73107
+ e.path = PkgJson.strOf(spec, "path");
73108
+ e.git = PkgJson.strOf(spec, "git");
73109
+ e.rev = PkgJson.strOf(spec, "rev");
73110
+ e.subdir = PkgJson.strOf(spec, "subdir");
73111
+ e.sha256 = PkgJson.strOf(spec, "sha256");
73112
+ lock.packages.push(e);
73113
+ i = i + 1;
73114
+ }
73115
+ ;
73116
+ return lock;
73117
+ }
73118
+ ;
73119
+ static escape(s) {
73120
+ let out = "";
73121
+ const n = s.length;
73122
+ let i = 0;
73123
+ while (i < n) {
73124
+ const c = s.charCodeAt(i);
73125
+ if (c == 34) {
73126
+ out = out + "\\\"";
73127
+ }
73128
+ else {
73129
+ if (c == 92) {
73130
+ out = out + "\\\\";
73131
+ }
73132
+ else {
73133
+ if (c == 10) {
73134
+ out = out + "\\n";
73135
+ }
73136
+ else {
73137
+ out = out + String.fromCharCode(c);
73138
+ }
73139
+ }
73140
+ }
73141
+ i = i + 1;
73142
+ }
73143
+ ;
73144
+ return out;
73145
+ }
73146
+ ;
73147
+ static dumpLock(lock) {
73148
+ let s = ("{\n \"lockVersion\": " + (lock.lockVersion.toString())) + ",\n \"packages\": {\n";
73149
+ let i = 0;
73150
+ const n = lock.packages.length;
73151
+ while (i < n) {
73152
+ const e = lock.packages[i];
73153
+ s = ((s + " \"") + PkgManifestIO.escape(e.name)) + "\": {\n";
73154
+ if (e.path.length > 0) {
73155
+ s = ((s + " \"path\": \"") + PkgManifestIO.escape(e.path)) + "\"";
73156
+ }
73157
+ if (e.git.length > 0) {
73158
+ if (e.path.length > 0) {
73159
+ s = s + ",\n";
73160
+ }
73161
+ s = ((s + " \"git\": \"") + PkgManifestIO.escape(e.git)) + "\"";
73162
+ }
73163
+ if (e.rev.length > 0) {
73164
+ s = ((s + ",\n \"rev\": \"") + PkgManifestIO.escape(e.rev)) + "\"";
73165
+ }
73166
+ if (e.subdir.length > 0) {
73167
+ s = ((s + ",\n \"subdir\": \"") + PkgManifestIO.escape(e.subdir)) + "\"";
73168
+ }
73169
+ if (e.sha256.length > 0) {
73170
+ s = ((s + ",\n \"sha256\": \"") + PkgManifestIO.escape(e.sha256)) + "\"";
73171
+ }
73172
+ s = s + "\n }";
73173
+ if (i < n - 1) {
73174
+ s = s + ",";
73175
+ }
73176
+ s = s + "\n";
73177
+ i = i + 1;
73178
+ }
73179
+ ;
73180
+ s = s + " }\n}\n";
73181
+ return s;
73182
+ }
73183
+ ;
73184
+ static dumpManifest(m) {
73185
+ let s = ("{\n \"name\": \"" + PkgManifestIO.escape(m.name)) + "\",\n";
73186
+ s = ((s + " \"version\": \"") + PkgManifestIO.escape(m.version)) + "\",\n";
73187
+ s = ((s + " \"entry\": \"") + PkgManifestIO.escape(m.entry)) + "\"";
73188
+ if (m.license.length > 0) {
73189
+ s = ((s + ",\n \"license\": \"") + PkgManifestIO.escape(m.license)) + "\"";
73190
+ }
73191
+ if (m.deps.length > 0) {
73192
+ s = s + ",\n \"dependencies\": {\n";
73193
+ let i = 0;
73194
+ const n = m.deps.length;
73195
+ while (i < n) {
73196
+ const d = m.deps[i];
73197
+ s = ((s + " \"") + PkgManifestIO.escape(d.name)) + "\": {";
73198
+ let first = true;
73199
+ if (d.path.length > 0) {
73200
+ s = ((s + " \"path\": \"") + PkgManifestIO.escape(d.path)) + "\"";
73201
+ first = false;
73202
+ }
73203
+ if (d.git.length > 0) {
73204
+ if (first) {
73205
+ }
73206
+ else {
73207
+ s = s + ",";
73208
+ }
73209
+ s = ((s + " \"git\": \"") + PkgManifestIO.escape(d.git)) + "\"";
73210
+ first = false;
73211
+ }
73212
+ if (d.rev.length > 0) {
73213
+ s = ((s + ", \"rev\": \"") + PkgManifestIO.escape(d.rev)) + "\"";
73214
+ }
73215
+ if (d.tag.length > 0) {
73216
+ s = ((s + ", \"tag\": \"") + PkgManifestIO.escape(d.tag)) + "\"";
73217
+ }
73218
+ if (d.subdir.length > 0) {
73219
+ s = ((s + ", \"subdir\": \"") + PkgManifestIO.escape(d.subdir)) + "\"";
73220
+ }
73221
+ s = s + " }";
73222
+ if (i < n - 1) {
73223
+ s = s + ",";
73224
+ }
73225
+ s = s + "\n";
73226
+ i = i + 1;
73227
+ }
73228
+ ;
73229
+ s = s + " }";
73230
+ }
73231
+ s = s + "\n}\n";
73232
+ return s;
73233
+ }
73234
+ ;
73235
+ }
73236
+ exports.PkgManifestIO = PkgManifestIO;
73237
+ class PkgCache {
73238
+ constructor() {
73239
+ }
73240
+ static lessStr(a, b) {
73241
+ const na = a.length;
73242
+ const nb = b.length;
73243
+ let n = na;
73244
+ if (nb < na) {
73245
+ n = nb;
73246
+ }
73247
+ let i = 0;
73248
+ while (i < n) {
73249
+ const ca = a.charCodeAt(i);
73250
+ const cb = b.charCodeAt(i);
73251
+ if (ca < cb) {
73252
+ return true;
73253
+ }
73254
+ if (cb < ca) {
73255
+ return false;
73256
+ }
73257
+ i = i + 1;
73258
+ }
73259
+ ;
73260
+ return na < nb;
73261
+ }
73262
+ ;
73263
+ static hashMem(mem) {
73264
+ let names = [];
73265
+ let i = 0;
73266
+ while (i < mem.paths.length) {
73267
+ names.push(mem.paths[i]);
73268
+ i = i + 1;
73269
+ }
73270
+ ;
73271
+ const n = names.length;
73272
+ let a = 0;
73273
+ while (a < n) {
73274
+ let b = a + 1;
73275
+ while (b < n) {
73276
+ const sa = names[a];
73277
+ const sb = names[b];
73278
+ if (PkgCache.lessStr(sb, sa)) {
73279
+ names[a] = sb;
73280
+ names[b] = sa;
73281
+ }
73282
+ b = b + 1;
73283
+ }
73284
+ ;
73285
+ a = a + 1;
73286
+ }
73287
+ ;
73288
+ let acc = "";
73289
+ i = 0;
73290
+ while (i < n) {
73291
+ const p = names[i];
73292
+ acc = (acc + p) + "\n";
73293
+ if ((typeof (mem.byPath[p]) != "undefined" && Object.prototype.hasOwnProperty.call(mem.byPath, p))) {
73294
+ const f = (Object.prototype.hasOwnProperty.call(mem.byPath, p) ? mem.byPath[p] : undefined);
73295
+ acc = (acc + ((function (b) { var v = (b instanceof Uint8Array) ? b : new Uint8Array(b); var s = ""; var i = 0; var n = v.length; var c = 32768; while (i < n) {
73296
+ var e = i + c;
73297
+ if (e > n) {
73298
+ e = n;
73299
+ }
73300
+ s += String.fromCharCode.apply(null, v.subarray(i, e));
73301
+ i = e;
73302
+ } return s; })(f.data))) + "\n";
73303
+ }
73304
+ i = i + 1;
73305
+ }
73306
+ ;
73307
+ if (acc.length == 0) {
73308
+ return "";
73309
+ }
73310
+ return require('crypto')
73311
+ .createHash('sha256')
73312
+ .update(acc)
73313
+ .digest('hex');
73314
+ }
73315
+ ;
73316
+ static put(mem, cacheRoot) {
73317
+ const hash = PkgCache.hashMem(mem);
73318
+ if (hash.length == 0) {
73319
+ return "";
73320
+ }
73321
+ const dest = (cacheRoot + "/") + hash;
73322
+ require("fs").mkdirSync(dest, { recursive: true });
73323
+ const store = new GitStore(new GitPack());
73324
+ store.writeDisk(mem, dest);
73325
+ return hash;
73326
+ }
73327
+ ;
73328
+ static lockFor(name, git, rev, subdir, hash) {
73329
+ const e = new PkgLockEnt();
73330
+ e.name = name;
73331
+ e.git = git;
73332
+ e.rev = rev;
73333
+ e.subdir = subdir;
73334
+ e.sha256 = hash;
73335
+ return e;
73336
+ }
73337
+ ;
73338
+ }
73339
+ exports.PkgCache = PkgCache;
73340
+ class PkgFetchWork {
73341
+ constructor() {
73342
+ this.dir = "";
73343
+ this.man = new PkgManifest();
73344
+ this.git = "";
73345
+ this.rev = "";
73346
+ this.subdir = "";
73347
+ this.fromGit = false;
73348
+ }
73349
+ }
73350
+ exports.PkgFetchWork = PkgFetchWork;
73351
+ class PkgFetch {
73352
+ constructor() {
73353
+ this.ok = true;
73354
+ this.err = "";
73355
+ this.cacheRoot = "";
73356
+ this.cacheOverride = "";
73357
+ this.rootDir = "";
73358
+ this.tmpRoot = "";
73359
+ this.httpTool = "";
73360
+ this.vendor = false;
73361
+ this.frozen = false;
73362
+ this.force = false;
73363
+ this.lock = new PkgLock();
73364
+ this.previous = new PkgLock();
73365
+ this.seen = {};
73366
+ this.lastRev = "";
73367
+ this.lastMem = new GitMem();
73368
+ }
73369
+ runHttp(args) {
73370
+ let argv = [];
73371
+ argv.push(this.httpTool);
73372
+ let i = 0;
73373
+ while (i < args.length) {
73374
+ argv.push(args[i]);
73375
+ i = i + 1;
73376
+ }
73377
+ ;
73378
+ let noEnv = [];
73379
+ const out = r_process_result("node", argv, "", true, noEnv);
73380
+ if (out.length < 3) {
73381
+ this.err = "could not run node";
73382
+ return false;
73383
+ }
73384
+ if (out[0] == "0") {
73385
+ return true;
73386
+ }
73387
+ this.err = out[2];
73388
+ return false;
73389
+ }
73390
+ ;
73391
+ advertise(url, dest) {
73392
+ let args = [];
73393
+ args.push("advertise");
73394
+ args.push(url);
73395
+ args.push(dest);
73396
+ return this.runHttp(args);
73397
+ }
73398
+ ;
73399
+ post(url, body, dest) {
73400
+ let args = [];
73401
+ args.push("post");
73402
+ args.push(url);
73403
+ args.push(body);
73404
+ args.push(dest);
73405
+ return this.runHttp(args);
73406
+ }
73407
+ ;
73408
+ fetchInto(name, url, wantRev, subdir) {
73409
+ this.lastRev = "";
73410
+ require("fs").mkdirSync(this.tmpRoot, { recursive: true });
73411
+ const adv = ((this.tmpRoot + "/") + name) + ".advertise.bin";
73412
+ if (this.advertise(url, adv) == false) {
73413
+ return "";
73414
+ }
73415
+ const advert = GitPktIO.parseAdvertisement(PkgFetch.readBytes(adv));
73416
+ if (advert.ok == false) {
73417
+ this.err = (("could not read the advertisement of " + url) + ": ") + advert.err;
73418
+ return "";
73419
+ }
73420
+ if (subdir.length == 0) {
73421
+ const commitSha = GitPktIO.findRef(advert, wantRev);
73422
+ if (commitSha.length == 0) {
73423
+ this.err = (url + " has no ") + wantRev;
73424
+ return "";
73425
+ }
73426
+ let extras = [];
73427
+ const wholeWant = GitPktIO.buildWantFetch(commitSha, 1, "", extras);
73428
+ if (wholeWant.ok == false) {
73429
+ this.err = wholeWant.err;
73430
+ return "";
73431
+ }
73432
+ const wantPath = ((this.tmpRoot + "/") + name) + ".want.bin";
73433
+ const packPath = ((this.tmpRoot + "/") + name) + ".pack.bin";
73434
+ PkgFetch.writeBytes(wantPath, wholeWant.body);
73435
+ if (this.post(url, wantPath, packPath) == false) {
73436
+ return "";
73437
+ }
73438
+ const whole = PkgFetch.loadPack(packPath);
73439
+ if (whole.ok == false) {
73440
+ this.err = whole.err;
73441
+ return "";
73442
+ }
73443
+ const wholeStore = new GitStore(whole);
73444
+ const wholeMem = wholeStore.checkout(commitSha, "");
73445
+ if (wholeStore.ok == false) {
73446
+ this.err = wholeStore.err;
73447
+ return "";
73448
+ }
73449
+ this.lastRev = commitSha;
73450
+ return this.storeMem(wholeMem);
73451
+ }
73452
+ const treeWant = GitPktIO.buildWantTrees(advert, wantRev);
73453
+ if (treeWant.ok == false) {
73454
+ this.err = treeWant.err;
73455
+ return "";
73456
+ }
73457
+ const commit = treeWant.sha;
73458
+ const twPath = ((this.tmpRoot + "/") + name) + ".want-trees.bin";
73459
+ const treesPath = ((this.tmpRoot + "/") + name) + ".trees.bin";
73460
+ PkgFetch.writeBytes(twPath, treeWant.body);
73461
+ if (this.post(url, twPath, treesPath) == false) {
73462
+ return "";
73463
+ }
73464
+ const trees = PkgFetch.loadPack(treesPath);
73465
+ if (trees.ok == false) {
73466
+ this.err = trees.err;
73467
+ return "";
73468
+ }
73469
+ const treeStore = new GitStore(trees);
73470
+ const treeSha = treeStore.treeAt(commit, subdir);
73471
+ if (treeStore.ok == false) {
73472
+ this.err = (((((url + " has no ") + subdir) + " at ") + commit) + ": ") + treeStore.err;
73473
+ return "";
73474
+ }
73475
+ const blobWant = GitPktIO.buildWantSha(treeSha);
73476
+ if (blobWant.ok == false) {
73477
+ this.err = blobWant.err;
73478
+ return "";
73479
+ }
73480
+ const bwPath = ((this.tmpRoot + "/") + name) + ".want-blobs.bin";
73481
+ const blobsPath = ((this.tmpRoot + "/") + name) + ".blobs.bin";
73482
+ PkgFetch.writeBytes(bwPath, blobWant.body);
73483
+ if (this.post(url, bwPath, blobsPath) == false) {
73484
+ return "";
73485
+ }
73486
+ const blobs = PkgFetch.loadPack(blobsPath);
73487
+ if (blobs.ok == false) {
73488
+ this.err = blobs.err;
73489
+ return "";
73490
+ }
73491
+ const merged = GitPackIO.merge(trees, blobs);
73492
+ if (merged.ok == false) {
73493
+ this.err = merged.err;
73494
+ return "";
73495
+ }
73496
+ const store = new GitStore(merged);
73497
+ const mem = store.checkout(commit, subdir);
73498
+ if (store.ok == false) {
73499
+ this.err = store.err;
73500
+ return "";
73501
+ }
73502
+ this.lastRev = commit;
73503
+ return this.storeMem(mem);
73504
+ }
73505
+ ;
73506
+ storeMem(mem) {
73507
+ this.lastMem = mem;
73508
+ require("fs").mkdirSync(this.cacheRoot, { recursive: true });
73509
+ const hash = PkgCache.put(mem, this.cacheRoot);
73510
+ if (hash.length == 0) {
73511
+ this.err = "the checkout was empty";
73512
+ return "";
73513
+ }
73514
+ return hash;
73515
+ }
73516
+ ;
73517
+ cachedFor(env, name, git, rev, subdir) {
73518
+ if (this.force) {
73519
+ return "";
73520
+ }
73521
+ let i = 0;
73522
+ while (i < this.previous.packages.length) {
73523
+ const e = this.previous.packages[i];
73524
+ i = i + 1;
73525
+ if (e.name == name) {
73526
+ if (e.sha256.length == 0) {
73527
+ return "";
73528
+ }
73529
+ if (e.git != git) {
73530
+ return "";
73531
+ }
73532
+ if (rev.length > 0) {
73533
+ if (e.rev != rev) {
73534
+ return "";
73535
+ }
73536
+ }
73537
+ if (e.subdir != subdir) {
73538
+ return "";
73539
+ }
73540
+ const dir = PkgImport.joinPath(this.cacheRoot, e.sha256);
73541
+ if (operatorsOf_8.filec95exists_9(env, dir, "ranger.json")) {
73542
+ this.lastRev = e.rev;
73543
+ return e.sha256;
73544
+ }
73545
+ return "";
73546
+ }
73547
+ }
73548
+ ;
73549
+ return "";
73550
+ }
73551
+ ;
73552
+ install(env, manDir) {
73553
+ return __awaiter(this, void 0, void 0, function* () {
73554
+ this.ok = true;
73555
+ this.err = "";
73556
+ this.cacheRoot = PkgImport.cacheRoot();
73557
+ if (this.cacheOverride.length > 0) {
73558
+ this.cacheRoot = this.cacheOverride;
73559
+ }
73560
+ this.tmpRoot = PkgImport.joinPath(this.cacheRoot, ".fetch");
73561
+ this.httpTool = PkgFetch.findHttpTool(env);
73562
+ if (this.httpTool.length == 0) {
73563
+ this.err = "git-http.mjs is not beside rgrc";
73564
+ return false;
73565
+ }
73566
+ this.rootDir = manDir;
73567
+ const rootText = yield PkgImport.readText(env, manDir, "ranger.json");
73568
+ if (rootText.length == 0) {
73569
+ this.err = manDir + "/ranger.json is empty or unreadable";
73570
+ return false;
73571
+ }
73572
+ const rootMan = PkgManifestIO.load(rootText);
73573
+ if (rootMan.ok == false) {
73574
+ this.err = (manDir + "/ranger.json: ") + rootMan.err;
73575
+ return false;
73576
+ }
73577
+ const lockText = yield PkgImport.readText(env, manDir, "ranger.lock");
73578
+ if (lockText.length > 0) {
73579
+ this.previous = PkgManifestIO.loadLock(lockText);
73580
+ }
73581
+ let pending = [];
73582
+ const first = new PkgFetchWork();
73583
+ first.dir = manDir;
73584
+ first.man = rootMan;
73585
+ pending.push(first);
73586
+ let qi = 0;
73587
+ while (qi < pending.length) {
73588
+ const w = pending[qi];
73589
+ qi = qi + 1;
73590
+ let di = 0;
73591
+ while (di < w.man.deps.length) {
73592
+ const d = w.man.deps[di];
73593
+ di = di + 1;
73594
+ if ((typeof (this.seen[d.name]) != "undefined" && Object.prototype.hasOwnProperty.call(this.seen, d.name))) {
73595
+ }
73596
+ else {
73597
+ this.seen[d.name] = true;
73598
+ if ((yield this.oneDep(env, pending, w, d)) == false) {
73599
+ return false;
73600
+ }
73601
+ }
73602
+ }
73603
+ ;
73604
+ }
73605
+ ;
73606
+ const out = PkgManifestIO.dumpLock(this.lock);
73607
+ require('fs').writeFileSync(manDir + '/' + "ranger.lock", Buffer.from((function (s) { var b = new ArrayBuffer(s.length); var v = new Uint8Array(b); for (var i = 0; i < s.length; i++)
73608
+ v[i] = s.charCodeAt(i); b._view = new DataView(b); return b; })(out)));
73609
+ console.log(("wrote " + manDir) + "/ranger.lock");
73610
+ return true;
73611
+ });
73612
+ }
73613
+ ;
73614
+ oneDep(env, pending, w, d) {
73615
+ return __awaiter(this, void 0, void 0, function* () {
73616
+ let git = d.git;
73617
+ let rev = d.rev;
73618
+ let subdir = d.subdir;
73619
+ if (rev.length == 0) {
73620
+ rev = d.tag;
73621
+ }
73622
+ let localPath = d.path;
73623
+ if (localPath.length > 0) {
73624
+ if (w.fromGit) {
73625
+ git = w.git;
73626
+ rev = w.rev;
73627
+ subdir = PkgImport.foldPath(PkgImport.joinPath(w.subdir, localPath));
73628
+ localPath = "";
73629
+ if (subdir.length == 0) {
73630
+ this.err = (((d.name + ": ") + d.path) + " climbs out of ") + w.git;
73631
+ return false;
73632
+ }
73633
+ }
73634
+ }
73635
+ const entry = new PkgLockEnt();
73636
+ entry.name = d.name;
73637
+ let pkgDir = "";
73638
+ let childFromGit = false;
73639
+ if (localPath.length > 0) {
73640
+ pkgDir = PkgImport.foldPath(PkgImport.joinPath(w.dir, localPath));
73641
+ if (operatorsOf_8.filec95exists_9(env, pkgDir, "ranger.json") == false) {
73642
+ this.err = (d.name + ": no ranger.json under ") + localPath;
73643
+ return false;
73644
+ }
73645
+ entry.path = localPath;
73646
+ console.log((d.name + " path ") + localPath);
73647
+ }
73648
+ else {
73649
+ if (git.length == 0) {
73650
+ this.err = d.name + ": the dependency has neither \"path\" nor \"git\"";
73651
+ return false;
73652
+ }
73653
+ if (rev.length == 0) {
73654
+ rev = "HEAD";
73655
+ }
73656
+ let hash = this.cachedFor(env, d.name, git, rev, subdir);
73657
+ let reused = hash.length > 0;
73658
+ if (reused) {
73659
+ if (this.vendor) {
73660
+ const already = PkgImport.joinPath(this.rootDir, ("vendor/ranger/" + d.name));
73661
+ if (operatorsOf_8.filec95exists_9(env, already, "ranger.json") == false) {
73662
+ reused = false;
73663
+ hash = "";
73664
+ }
73665
+ }
73666
+ }
73667
+ if (reused == false) {
73668
+ if (this.frozen) {
73669
+ this.err = d.name + ": ranger.lock does not cover it at this revision, and -frozen was asked for";
73670
+ return false;
73671
+ }
73672
+ hash = this.fetchInto(d.name, git, rev, subdir);
73673
+ if (hash.length == 0) {
73674
+ if (this.err.length == 0) {
73675
+ this.err = (d.name + ": could not fetch ") + git;
73676
+ }
73677
+ return false;
73678
+ }
73679
+ }
73680
+ pkgDir = PkgImport.joinPath(this.cacheRoot, hash);
73681
+ entry.git = git;
73682
+ entry.rev = this.lastRev;
73683
+ entry.subdir = subdir;
73684
+ entry.sha256 = hash;
73685
+ childFromGit = true;
73686
+ let note = "";
73687
+ if (reused) {
73688
+ note = " (cached)";
73689
+ }
73690
+ console.log(((((d.name + " ") + this.lastRev) + " -> ") + pkgDir) + note);
73691
+ if (this.vendor) {
73692
+ if (reused == false) {
73693
+ const vdir = PkgImport.joinPath(this.rootDir, ("vendor/ranger/" + d.name));
73694
+ require("fs").mkdirSync(vdir, { recursive: true });
73695
+ const writer = new GitStore(new GitPack());
73696
+ writer.writeDisk(this.lastMem, vdir);
73697
+ console.log((d.name + " vendored -> vendor/ranger/") + d.name);
73698
+ }
73699
+ }
73700
+ }
73701
+ this.lock.packages.push(entry);
73702
+ const childText = yield PkgImport.readText(env, pkgDir, "ranger.json");
73703
+ if (childText.length > 0) {
73704
+ const childMan = PkgManifestIO.load(childText);
73705
+ if (childMan.ok) {
73706
+ const next = new PkgFetchWork();
73707
+ next.dir = pkgDir;
73708
+ next.man = childMan;
73709
+ next.git = entry.git;
73710
+ next.rev = entry.rev;
73711
+ next.subdir = entry.subdir;
73712
+ next.fromGit = childFromGit;
73713
+ pending.push(next);
73714
+ }
73715
+ }
73716
+ return true;
73717
+ });
73718
+ }
73719
+ ;
73720
+ static findHttpTool(env) {
73721
+ const idir = __dirname;
73722
+ if (operatorsOf_8.filec95exists_9(env, idir, "git-http.mjs")) {
73723
+ return idir + "/git-http.mjs";
73724
+ }
73725
+ const up = PkgImport.joinPath(PkgImport.parentDir(idir), "bin");
73726
+ if (operatorsOf_8.filec95exists_9(env, up, "git-http.mjs")) {
73727
+ return up + "/git-http.mjs";
73728
+ }
73729
+ return "";
73730
+ }
73731
+ ;
73732
+ static splitPath(path) {
73733
+ let parts = [];
73734
+ parts.push(PkgImport.parentDir(path));
73735
+ const d = parts[0];
73736
+ const n = path.length;
73737
+ let cut = d.length + 1;
73738
+ if (d.length == 0) {
73739
+ parts[0] = ".";
73740
+ cut = 0;
73741
+ }
73742
+ parts.push(path.substring(cut, n));
73743
+ return parts;
73744
+ }
73745
+ ;
73746
+ static readBytes(path) {
73747
+ const parts = PkgFetch.splitPath(path);
73748
+ return (function () { var b = require('fs').readFileSync(parts[0] + '/' + parts[1]); var ab = new ArrayBuffer(b.length); var v = new Uint8Array(ab); for (var i = 0; i < b.length; i++)
73749
+ v[i] = b[i]; ab._view = new DataView(ab); return ab; })();
73750
+ }
73751
+ ;
73752
+ static writeBytes(path, data) {
73753
+ const parts = PkgFetch.splitPath(path);
73754
+ require('fs').writeFileSync(parts[0] + '/' + parts[1], Buffer.from(data));
73755
+ }
73756
+ ;
73757
+ static loadPack(path) {
73758
+ const data = PkgFetch.readBytes(path);
73759
+ const sb = GitPktIO.demux(data);
73760
+ let raw = data;
73761
+ if (sb.ok) {
73762
+ if (sb.pack.byteLength > 0) {
73763
+ raw = sb.pack;
73764
+ }
73765
+ }
73766
+ return GitPackIO.parse(raw);
73767
+ }
73768
+ ;
73769
+ }
73770
+ exports.PkgFetch = PkgFetch;
73771
+ class RangerDocGenerator {
73772
+ constructor() {
73773
+ }
73774
+ writeTypeDef(item, ctx, wr) {
73775
+ return __awaiter(this, void 0, void 0, function* () {
73776
+ if (item.hasFlag("optional")) {
73777
+ wr.out("<optional>", false);
73778
+ }
73779
+ switch (item.value_type) {
73780
+ case 6:
73781
+ wr.out(("[" + item.array_type) + "]", false);
73782
+ break;
73783
+ case 7:
73784
+ wr.out(((("[" + item.key_type) + ":") + item.array_type) + "]", false);
73785
+ break;
73786
+ case 20:
73787
+ wr.out("(fn:", false);
73788
+ try {
73789
+ const rv = item.expression_value.children[0];
73790
+ const args = item.expression_value.children[1];
73791
+ yield this.writeTypeDef(rv, ctx, wr);
73792
+ wr.out(" (", false);
73793
+ yield operatorsOf.forEach_15(args.children, ((item, index) => __awaiter(this, void 0, void 0, function* () {
73794
+ if (index > 0) {
73795
+ wr.out(", ", false);
73796
+ }
73797
+ wr.out(item.vref, false);
73798
+ wr.out(": ", false);
73799
+ yield this.writeTypeDef(item, ctx, wr);
73800
+ })));
73801
+ wr.out(")", false);
73802
+ }
73803
+ catch (e) {
73804
+ }
73805
+ wr.out(")", false);
73806
+ break;
73807
+ default:
73808
+ if (item.type_name.length > 0) {
73809
+ wr.out("" + item.type_name, false);
73810
+ }
73811
+ break;
73812
+ }
73813
+ ;
73814
+ });
73815
+ }
73816
+ ;
73817
+ writeArgDefs(node, ctx, wr) {
73818
+ return __awaiter(this, void 0, void 0, function* () {
73819
+ yield operatorsOf.forEach_15(node.children, ((item, index) => __awaiter(this, void 0, void 0, function* () {
73820
+ if (index > 0) {
73821
+ wr.out(" ", false);
73822
+ }
73823
+ wr.out(("`" + item.vref) + "`", false);
73824
+ wr.out(":", false);
73825
+ yield this.writeTypeDef(item, ctx, wr);
73826
+ wr.out(" ", false);
73827
+ })));
73828
+ });
73829
+ }
73830
+ ;
73831
+ createClassDoc(node, ctx, orig_wr) {
73832
+ return __awaiter(this, void 0, void 0, function* () {
73833
+ if (ctx.hasCompilerSetting("classdoc")) {
73834
+ const b_only_documented = false == ctx.hasCompilerFlag("allowempty");
73835
+ const wr = orig_wr.getFileWriter(".", ctx.getCompilerSetting("classdoc"));
73836
+ if (b_only_documented == false) {
73837
+ wr.out("# Classes", true);
73838
+ }
73839
+ const root = ctx.getRoot();
73840
+ yield operatorsOf_13.forEach_14(root.definedClasses, ((item, index) => __awaiter(this, void 0, void 0, function* () {
73841
+ if (false == item.isNormalClass()) {
73842
+ return;
73843
+ }
73844
+ if (b_only_documented == false) {
73845
+ wr.out("## " + index, true);
73846
+ }
73847
+ const theClass = item;
73848
+ yield operatorsOf_13.forEach_31(item.method_variants, ((item, index) => __awaiter(this, void 0, void 0, function* () {
73849
+ yield operatorsOf.forEach_29(item.variants, ((item, index) => __awaiter(this, void 0, void 0, function* () {
73850
+ if (b_only_documented) {
73851
+ if (item.git_doc.length == 0) {
73852
+ return;
73853
+ }
73854
+ }
73855
+ wr.out("#### ", false);
73856
+ if (typeof (item.nameNode) != "undefined") {
73857
+ if (item.nameNode.type_name != "void") {
73858
+ wr.out("`", false);
73859
+ yield this.writeTypeDef(item.nameNode, ctx, wr);
73860
+ wr.out("` ", false);
73861
+ }
73862
+ }
73863
+ wr.out((theClass.name + ":: ") + item.name, false);
73864
+ wr.out("(", false);
73865
+ for (let i = 0; i < item.params.length; i++) {
73866
+ var arg = item.params[i];
73867
+ if (i > 0) {
73868
+ wr.out(" ", false);
73869
+ }
73870
+ wr.out(("`" + arg.compiledName) + "`", false);
73871
+ wr.out(":", false);
73872
+ yield this.writeTypeDef(arg.nameNode, ctx, wr);
73873
+ }
73874
+ ;
73875
+ wr.out(")", false);
73876
+ wr.out("", true);
73877
+ wr.out(item.git_doc, false);
73878
+ wr.out("", true);
73879
+ })));
73880
+ })));
73881
+ })));
73882
+ }
73883
+ });
73884
+ }
73885
+ ;
73886
+ writeOpDesc(item, ctx, wr) {
73887
+ return __awaiter(this, void 0, void 0, function* () {
73888
+ const fc = item.getFirst();
73889
+ const nameNode = item.getSecond();
73890
+ const args = item.getThird();
73891
+ wr.out("| ", false);
73892
+ let name = fc.vref;
73893
+ if (fc.vref == "||") {
73894
+ name = "&#124;&#124;";
73895
+ }
73896
+ if (fc.vref == "|") {
73897
+ name = "&#124;";
73898
+ }
73899
+ wr.out(name, false);
73900
+ wr.out(" | ", false);
73901
+ if (nameNode.type_name != "void") {
73902
+ wr.out("`", false);
73903
+ yield this.writeTypeDef(nameNode, ctx, wr);
73904
+ wr.out("` ", false);
73905
+ }
73906
+ wr.out("| ", false);
73907
+ wr.out(" (", false);
73908
+ yield this.writeArgDefs(args, ctx, wr);
73909
+ wr.out(" )", false);
73910
+ wr.out("| ", false);
73911
+ if (item.hasStringProperty("doc")) {
73912
+ wr.out(item.getStringProperty("doc"), false);
73913
+ }
73914
+ wr.out("| ", false);
73915
+ wr.out("", true);
73916
+ });
73917
+ }
73918
+ ;
73919
+ writeTypeDoc(list, tester, ctx, wr) {
73920
+ return __awaiter(this, void 0, void 0, function* () {
73921
+ const www = wr.fork();
73922
+ wr.out("", true);
73923
+ wr.out("", true);
73924
+ wr.out("| operator | returns | arguments | description |", true);
73925
+ wr.out("| -------- | ------- | --------- | ------------| ", true);
73926
+ let cnt = 0;
73927
+ yield operatorsOf.forEach_17(list, ((item, index) => __awaiter(this, void 0, void 0, function* () {
73928
+ if (yield tester(item)) {
73929
+ if (cnt > 0) {
73930
+ www.out(", ", false);
73931
+ }
73932
+ www.out((" `" + item.name) + "` ", false);
73933
+ yield this.writeOpDesc(item.node, ctx, wr);
73934
+ cnt = cnt + 1;
73935
+ }
73936
+ })));
73937
+ });
73938
+ }
73939
+ ;
73940
+ createOperatorDoc(node, ctx, orig_wr) {
73941
+ return __awaiter(this, void 0, void 0, function* () {
73942
+ if (ctx.hasCompilerSetting("operatordoc")) {
73943
+ const wr = orig_wr.getFileWriter(".", ctx.getCompilerSetting("operatordoc"));
73944
+ const allOps = yield ctx.getAllOperators();
73945
+ let statements = operatorsOf.filter_52(allOps, ((item, index) => {
73946
+ let is_map_array = false;
73947
+ if (typeof (item.firstArg) != "undefined") {
73948
+ is_map_array = item.firstArg.value_type == 6 || item.firstArg.value_type == 7;
73949
+ }
73950
+ if (item.name.indexOf("if_") == 0) {
73951
+ return false;
73952
+ }
73953
+ return item.nameNode.type_name == "void" && false == is_map_array;
73954
+ }));
73955
+ const lang_statements = operatorsOf.filter_52(allOps, ((item, index) => {
73956
+ if (item.name.indexOf("if_") == 0) {
73957
+ return true;
73958
+ }
73959
+ return false;
73960
+ }));
73961
+ statements = operatorsOf.groupBy_53(statements, ((item) => {
73962
+ return item.name;
73963
+ }));
73964
+ const operator_list = operatorsOf.filter_52(allOps, ((item, index) => {
73965
+ let is_map_array_1 = false;
73966
+ if (typeof (item.firstArg) != "undefined") {
73967
+ is_map_array_1 = item.firstArg.value_type == 6 || item.firstArg.value_type == 7;
73968
+ }
73969
+ return is_map_array_1 || item.nameNode.type_name != "void";
73970
+ }));
73971
+ const nList = operatorsOf.groupBy_53(operator_list, ((item) => {
73972
+ let key = item.name;
73973
+ const fc = item.firstArg;
73974
+ if (typeof (fc) != "undefined") {
73975
+ key = key + (((((":" + fc.type_name) + ":") + fc.key_type) + ":") + fc.array_type);
73976
+ }
73977
+ return key;
73978
+ }));
73979
+ wr.out("## Statements", true);
73980
+ yield this.writeTypeDoc(statements, ((item) => {
73981
+ return true;
73982
+ }), ctx, wr);
73983
+ wr.out("", true);
73984
+ wr.out("## Language switches", true);
73985
+ yield this.writeTypeDoc(lang_statements, ((item) => {
73986
+ return true;
73987
+ }), ctx, wr);
73988
+ wr.out("", true);
73989
+ wr.out("## Operators without arguments", true);
73990
+ yield this.writeTypeDoc(nList, ((item) => {
73991
+ return typeof (item.firstArg) === "undefined";
73992
+ }), ctx, wr);
73993
+ wr.out("", true);
73994
+ wr.out("## Generic operators", true);
73995
+ yield this.writeTypeDoc(nList, ((item) => {
73996
+ if (typeof (item.firstArg) != "undefined") {
73997
+ return item.firstArg.type_name == "T";
73998
+ }
73999
+ return false;
74000
+ }), ctx, wr);
74001
+ wr.out("", true);
74002
+ wr.out("## Numeric operators", true);
74003
+ yield this.writeTypeDoc(nList, ((item) => {
74004
+ if (typeof (item.firstArg) != "undefined") {
74005
+ return (item.firstArg.type_name == "int" || item.firstArg.type_name == "double") && (item.nameNode.type_name == "int" || item.nameNode.type_name == "double");
74006
+ }
74007
+ return false;
74008
+ }), ctx, wr);
74009
+ wr.out("", true);
74010
+ wr.out("## Miscellaneous operators", true);
74011
+ yield this.writeTypeDoc(nList, ((item) => {
74012
+ if (typeof (item.firstArg) != "undefined") {
74013
+ return (item.firstArg.type_name == "int" || item.firstArg.type_name == "double") && ((item.nameNode.type_name != "int" && item.nameNode.type_name != "double") && item.nameNode.type_name != "boolean");
74014
+ }
74015
+ return false;
74016
+ }), ctx, wr);
74017
+ wr.out("", true);
74018
+ wr.out("## String operators", true);
74019
+ yield this.writeTypeDoc(nList, ((item) => {
74020
+ if (typeof (item.firstArg) != "undefined") {
74021
+ return item.firstArg.type_name == "string";
74022
+ }
74023
+ return false;
74024
+ }), ctx, wr);
74025
+ wr.out("", true);
74026
+ wr.out("", true);
74027
+ wr.out("## Array operators", true);
74028
+ yield this.writeTypeDoc(nList, ((item) => {
74029
+ if (typeof (item.firstArg) != "undefined") {
74030
+ return item.firstArg.value_type == 6;
74031
+ }
74032
+ return false;
74033
+ }), ctx, wr);
74034
+ wr.out("", true);
74035
+ wr.out("## Map operators", true);
74036
+ yield this.writeTypeDoc(nList, ((item) => {
74037
+ if (typeof (item.firstArg) != "undefined") {
74038
+ return item.firstArg.value_type == 7;
74039
+ }
74040
+ return false;
74041
+ }), ctx, wr);
74042
+ wr.out("", true);
74043
+ wr.out("## Boolean / test operators", true);
74044
+ yield this.writeTypeDoc(nList, ((item) => {
74045
+ if (typeof (item.firstArg) != "undefined") {
74046
+ return item.nameNode.type_name == "boolean";
74047
+ }
74048
+ return false;
74049
+ }), ctx, wr);
74050
+ }
74051
+ });
74052
+ }
74053
+ ;
74054
+ }
74055
+ exports.RangerDocGenerator = RangerDocGenerator;
74056
+ class StaticAnalyzer {
74057
+ constructor() {
74058
+ this.debug = false;
74059
+ this.mutatingOps = {};
74060
+ this.own_call_params = [];
74061
+ this.own_call_callees = [];
74062
+ this.own_call_indexes = [];
74063
+ this.rss_edge_src = [];
74064
+ this.rss_edge_dst = [];
74065
+ this.rss_in_place = [];
74066
+ }
74067
+ initMutatingOps() {
74068
+ this.mutatingOps["buffer_set"] = true;
74069
+ this.mutatingOps["int_buffer_set"] = true;
74070
+ this.mutatingOps["double_buffer_set"] = true;
74071
+ this.mutatingOps["buffer_fill"] = true;
74072
+ this.mutatingOps["int_buffer_fill"] = true;
74073
+ this.mutatingOps["double_buffer_fill"] = true;
74074
+ this.mutatingOps["buffer_copy"] = true;
74075
+ this.mutatingOps["int_buffer_copy"] = true;
74076
+ this.mutatingOps["double_buffer_copy"] = true;
74077
+ this.mutatingOps["push"] = true;
74078
+ this.mutatingOps["set"] = true;
74079
+ this.mutatingOps["clear"] = true;
74080
+ this.mutatingOps["remove"] = true;
74081
+ this.mutatingOps["removeIndex"] = true;
74082
+ this.mutatingOps["removeLast"] = true;
74083
+ this.mutatingOps["removeFirst"] = true;
74084
+ this.mutatingOps["set_at"] = true;
74085
+ this.mutatingOps["remove_index"] = true;
74086
+ this.mutatingOps["array_extract"] = true;
74087
+ this.mutatingOps["pushString"] = true;
74088
+ this.mutatingOps["map_clear"] = true;
74089
+ this.mutatingOps["insert"] = true;
74090
+ this.mutatingOps["nullify"] = true;
74091
+ this.mutatingOps["str_append"] = true;
74092
+ this.mutatingOps["put"] = true;
74093
+ }
74094
+ ;
74095
+ isMutatingOperator(opName) {
74096
+ if ((typeof (this.mutatingOps[opName]) != "undefined" && Object.prototype.hasOwnProperty.call(this.mutatingOps, opName))) {
74097
+ return (Object.prototype.hasOwnProperty.call(this.mutatingOps, opName) ? this.mutatingOps[opName] : undefined);
74098
+ }
74099
+ return false;
74100
+ }
74101
+ ;
74102
+ isMutatingNode(node) {
74103
+ if (node.expression == false) {
74104
+ return false;
74105
+ }
74106
+ if (node.children.length == 0) {
74107
+ return false;
74108
+ }
74109
+ const first = node.getFirst();
74110
+ if (first.vref.length > 0) {
74111
+ return this.isMutatingOperator(first.vref);
74112
+ }
74113
+ return false;
74114
+ }
74115
+ ;
74116
+ getRootVarName(node) {
74117
+ if (node.ns.length > 0) {
74118
+ return node.ns[0];
74119
+ }
74120
+ if (node.vref.length > 0) {
74121
+ return node.vref;
74122
+ }
74123
+ if (node.children.length > 0) {
74124
+ const first = node.getFirst();
74125
+ if (first.vref.length > 0) {
74126
+ return first.vref;
74127
+ }
74128
+ }
74129
+ return "";
74130
+ }
74131
+ ;
74132
+ isMemberAccess(node) {
74133
+ if (node.hasNewOper) {
74134
+ return false;
74135
+ }
74136
+ if (node.hasFnCall) {
74137
+ return false;
74138
+ }
74139
+ if (node.ns.length >= 2) {
74140
+ return true;
74141
+ }
74142
+ if (node.vref.length > 0) {
74143
+ const idx = node.vref.indexOf(".");
74144
+ if (idx > 0) {
74145
+ return true;
74146
+ }
74147
+ }
74148
+ if (node.expression) {
74149
+ if (node.children.length >= 2) {
74150
+ const first = node.getFirst();
74151
+ if (first.vref.length > 0) {
74152
+ if ((first.vref == "buffer_alloc" || first.vref == "int_buffer_alloc") || first.vref == "double_buffer_alloc") {
74153
+ return false;
74154
+ }
74155
+ }
74156
+ if (first.vref.length > 0) {
74157
+ const second = node.getSecond();
74158
+ if (second.vref.length > 0) {
74159
+ return true;
74160
+ }
74161
+ }
74162
+ }
74163
+ }
74164
+ return false;
70524
74165
  }
70525
74166
  ;
70526
74167
  getMemberPath(node) {
@@ -73872,6 +77513,31 @@ class VirtualCompiler {
73872
77513
  return ext == "ts";
73873
77514
  }
73874
77515
  ;
77516
+ runInstall(env, params, cli) {
77517
+ return __awaiter(this, void 0, void 0, function* () {
77518
+ const start = operatorsOf_8.currentc95directory_51(env);
77519
+ const manDir = PkgImport.walkUp(env, start);
77520
+ if (manDir.length == 0) {
77521
+ console.log(cli.error((("no ranger.json in " + start) + " or above it")));
77522
+ return false;
77523
+ }
77524
+ const fetch = new PkgFetch();
77525
+ fetch.vendor = (typeof (params.flags["vendor"]) != "undefined" && Object.prototype.hasOwnProperty.call(params.flags, "vendor"));
77526
+ fetch.frozen = (typeof (params.flags["frozen"]) != "undefined" && Object.prototype.hasOwnProperty.call(params.flags, "frozen")) || (typeof (params.flags["frozen-lockfile"]) != "undefined" && Object.prototype.hasOwnProperty.call(params.flags, "frozen-lockfile"));
77527
+ fetch.force = (typeof (params.flags["force"]) != "undefined" && Object.prototype.hasOwnProperty.call(params.flags, "force"));
77528
+ const cacheOpt = params.getParam("cache");
77529
+ if ((typeof (cacheOpt) !== "undefined" && cacheOpt != null)) {
77530
+ fetch.cacheOverride = cacheOpt;
77531
+ }
77532
+ const done = yield fetch.install(env, manDir);
77533
+ if (done) {
77534
+ return true;
77535
+ }
77536
+ console.log(cli.error(fetch.err));
77537
+ return false;
77538
+ });
77539
+ }
77540
+ ;
73875
77541
  run(env) {
73876
77542
  return __awaiter(this, void 0, void 0, function* () {
73877
77543
  const res = new CompilerResults();
@@ -73882,6 +77548,15 @@ class VirtualCompiler {
73882
77548
  if ((typeof (params.flags["no-color"]) != "undefined" && Object.prototype.hasOwnProperty.call(params.flags, "no-color"))) {
73883
77549
  cli.setUseColors(false);
73884
77550
  }
77551
+ if (params.values.length > 0) {
77552
+ if (params.values[0] == "install") {
77553
+ if (yield this.runInstall(env, params, cli)) {
77554
+ return res;
77555
+ }
77556
+ res.hasErrors = true;
77557
+ return res;
77558
+ }
77559
+ }
73885
77560
  let the_file = "";
73886
77561
  let plugins_only = false;
73887
77562
  const valid_options = ["l", "Selected language, one of " + allowed_languages.join(", "), "d", "output directory, default directory is \"bin/\"", "o", "output file, default is \"output.<language>\"", "classdoc", "write class documentation .md file", "operatordoc", "write operator documention into .md file", "apidoc", "write the API documentation artifacts into this subdirectory", "apiformat", "which API artifacts to write: json, markdown, report (default json,markdown)", "format", "Output formatting: \"ranger\" (the default) drops parentheses a target does not need and breaks a long method chain onto one line per call; \"none\" emits exactly what the writers emit", "width", "Line width the formatter aims at, when -format is not none. Defaults to the target ecosystems own: 80 on JavaScript, Dart and C++, 100 elsewhere", "csnamespace", "C# namespace for the generated types", "ktpackage", "Kotlin package for the generated types"];
@@ -73896,6 +77571,13 @@ class VirtualCompiler {
73896
77571
  else {
73897
77572
  if (params.values.length < 1) {
73898
77573
  cli.printHelpHeader();
77574
+ cli.printSection("Commands:");
77575
+ console.log((" " + cli.bold("install")) + " fetch the packages the nearest ranger.json names into the");
77576
+ console.log(" package cache and write ranger.lock.");
77577
+ console.log(cli.gray(" -vendor also write vendor/ranger/<name>"));
77578
+ console.log(cli.gray(" -frozen fail rather than fetch what the lock does not cover"));
77579
+ console.log(cli.gray(" -force refetch even when the locked checkout is cached"));
77580
+ console.log(cli.gray(" -cache=<dir> instead of RANGER_PKG_CACHE"));
73899
77581
  cli.printSection("Options:");
73900
77582
  let optCnt = 0;
73901
77583
  while (optCnt < valid_options.length) {
@@ -74067,7 +77749,13 @@ class VirtualCompiler {
74067
77749
  comp_attrs["o"] = the_target;
74068
77750
  const dirParam = params.getParam("d");
74069
77751
  if ((typeof (dirParam) !== "undefined" && dirParam != null)) {
74070
- the_target_dir = (operatorsOf_8.currentc95directory_51(env) + "/") + dirParam;
77752
+ const dirGiven = dirParam;
77753
+ if (dirGiven.length > 0 && dirGiven.charCodeAt(0) == 47) {
77754
+ the_target_dir = dirGiven;
77755
+ }
77756
+ else {
77757
+ the_target_dir = (operatorsOf_8.currentc95directory_51(env) + "/") + dirGiven;
77758
+ }
74071
77759
  }
74072
77760
  the_target_dir = require("path").normalize(the_target_dir);
74073
77761
  comp_attrs["d"] = the_target_dir;
@@ -74954,9 +78642,9 @@ class operatorsOf {
74954
78642
  ;
74955
78643
  static filter_52(__self, cb) {
74956
78644
  let res_13 = [];
74957
- for (let i_28 = 0; i_28 < __self.length; i_28++) {
74958
- var it_19 = __self[i_28];
74959
- if (cb(it_19, i_28)) {
78645
+ for (let i_29 = 0; i_29 < __self.length; i_29++) {
78646
+ var it_19 = __self[i_29];
78647
+ if (cb(it_19, i_29)) {
74960
78648
  res_13.push(it_19);
74961
78649
  }
74962
78650
  }
@@ -74967,8 +78655,8 @@ class operatorsOf {
74967
78655
  static groupBy_53(__self, cb) {
74968
78656
  let res_14 = [];
74969
78657
  let mapper = {};
74970
- for (let i_29 = 0; i_29 < __self.length; i_29++) {
74971
- var it_20 = __self[i_29];
78658
+ for (let i_30 = 0; i_30 < __self.length; i_30++) {
78659
+ var it_20 = __self[i_30];
74972
78660
  const key = cb(it_20);
74973
78661
  if (false == (typeof (mapper[key]) != "undefined" && Object.prototype.hasOwnProperty.call(mapper, key))) {
74974
78662
  res_14.push(it_20);
@@ -74981,8 +78669,8 @@ class operatorsOf {
74981
78669
  ;
74982
78670
  static clone_56(__self) {
74983
78671
  let res_15 = [];
74984
- for (let i_31 = 0; i_31 < __self.length; i_31++) {
74985
- var it_21 = __self[i_31];
78672
+ for (let i_32 = 0; i_32 < __self.length; i_32++) {
78673
+ var it_21 = __self[i_32];
74986
78674
  res_15.push(it_21);
74987
78675
  }
74988
78676
  ;
@@ -75281,8 +78969,8 @@ class operatorsOf_13 {
75281
78969
  ;
75282
78970
  static forEach_55(__self, cb) {
75283
78971
  const list_7 = Object.keys(__self);
75284
- for (let i_30 = 0; i_30 < list_7.length; i_30++) {
75285
- var kk_7 = list_7[i_30];
78972
+ for (let i_31 = 0; i_31 < list_7.length; i_31++) {
78973
+ var kk_7 = list_7[i_31];
75286
78974
  const value_7 = (Object.prototype.hasOwnProperty.call(__self, kk_7) ? __self[kk_7] : undefined);
75287
78975
  cb(value_7, kk_7);
75288
78976
  }
@@ -75918,3 +79606,42 @@ class operatorsOf_41 {
75918
79606
  }
75919
79607
  ;
75920
79608
  }
79609
+ // Running another command line program. spawnSync resolves a bare name on
79610
+ // PATH and passes the arguments as a vector, so nothing inside an argument is
79611
+ // re-read as a redirection or a glob.
79612
+ function r_process_env(pairs) {
79613
+ const e = {};
79614
+ const src = process.env;
79615
+ for (const k in src) {
79616
+ e[k] = src[k];
79617
+ }
79618
+ for (let i = 0; i < pairs.length; i++) {
79619
+ const at = pairs[i].indexOf("=");
79620
+ if (at > 0) {
79621
+ e[pairs[i].substring(0, at)] = pairs[i].substring(at + 1);
79622
+ }
79623
+ }
79624
+ return e;
79625
+ }
79626
+ function r_process_result(program, args, cwd, capture, env) {
79627
+ const opt = { maxBuffer: 268435456 };
79628
+ opt.stdio = capture ? "pipe" : "inherit";
79629
+ if (capture) {
79630
+ opt.encoding = "utf8";
79631
+ }
79632
+ if (cwd && cwd.length > 0) {
79633
+ opt.cwd = cwd;
79634
+ }
79635
+ if (env && env.length > 0) {
79636
+ opt.env = r_process_env(env);
79637
+ }
79638
+ const res = require("child_process").spawnSync(program, args, opt);
79639
+ if (res.error) {
79640
+ return ["-1", "", String(res.error.message)];
79641
+ }
79642
+ const code = (typeof res.status === "number") ? res.status : -1;
79643
+ if (!capture) {
79644
+ return [String(code), "", ""];
79645
+ }
79646
+ return [String(code), res.stdout || "", res.stderr || ""];
79647
+ }