jscrewit 3.1.0 → 3.2.0

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/lib/jscrewit.js CHANGED
@@ -1,4 +1,4 @@
1
- // JScrewIt 3.0.0 – https://jscrew.it
1
+ // JScrewIt 3.2.0 – https://jscrew.it
2
2
 
3
3
  (function () {
4
4
  'use strict';
@@ -61,7 +61,7 @@
61
61
  function esToString$1(arg)
62
62
  {
63
63
  if (typeof arg === 'symbol')
64
- throw new _TypeError$1('Cannot convert a symbol to a string');
64
+ throw _TypeError$1('Cannot convert a symbol to a string');
65
65
  var str = _String$1(arg);
66
66
  return str;
67
67
  }
@@ -576,7 +576,7 @@
576
576
  }
577
577
  function validateMask(mask) {
578
578
  if (!isMaskCompatible(mask))
579
- throw new _Error('Incompatible features');
579
+ throw _Error('Incompatible features');
580
580
  }
581
581
  var utilInspect;
582
582
  try {
@@ -828,7 +828,7 @@
828
828
  var createMap = function () { return _Object_create(null); };
829
829
  function esToString(name) {
830
830
  if (typeof name === 'symbol')
831
- throw new _TypeError('Cannot convert a symbol to a string');
831
+ throw _TypeError('Cannot convert a symbol to a string');
832
832
  var str = _String(name);
833
833
  return str;
834
834
  }
@@ -865,7 +865,7 @@
865
865
  return str;
866
866
  }
867
867
  function throwUnknownFeatureError(name) {
868
- throw new _Error("Unknown feature ".concat(_JSON_stringify(name)));
868
+ throw _Error("Unknown feature ".concat(_JSON_stringify(name)));
869
869
  }
870
870
  function wrapCheck(check) {
871
871
  var wrappedCheck = function () { return !!check(); };
@@ -2933,7 +2933,7 @@
2933
2933
  ',':
2934
2934
  [
2935
2935
  define('(RP_0_S + F_A_L_S_E)[1]'),
2936
- define({ expr: '[[]].concat([[]])', solutionType: SolutionType.OBJECT }),
2936
+ define({ expr: '[[]][CONCAT]([[]])', solutionType: SolutionType.OBJECT }),
2937
2937
  ],
2938
2938
  '-': '(.0000001 + [])[2]',
2939
2939
  '.': '(11e20 + [])[1]',
@@ -3314,7 +3314,7 @@
3314
3314
  RegExp: define({ expr: 'RegExp.name', optimize: { complexOpt: false } }, NAME),
3315
3315
  String: define('String.name', NAME),
3316
3316
  fromCharCo:
3317
- define({ expr: '"from3har3o".split(3).join("C")', optimize: { complexOpt: false } }),
3317
+ define({ expr: '"from3har3o"[SPLIT](3)[JOIN]("C")', optimize: { complexOpt: false } }),
3318
3318
  mCh: define('atob("bUNo")'),
3319
3319
  });
3320
3320
 
@@ -3404,10 +3404,11 @@
3404
3404
  [
3405
3405
  define('[].at', AT),
3406
3406
  ],
3407
- FILTER:
3407
+ CONCAT:
3408
3408
  [
3409
- define('[].filter'),
3409
+ define({ expr: '"concat"', solutionType: SolutionType.COMBINED_STRING }),
3410
3410
  ],
3411
+ FILTER: '[].filter',
3411
3412
  FLAT:
3412
3413
  [
3413
3414
  define('[].flat', FLAT),
@@ -3416,11 +3417,19 @@
3416
3417
  [
3417
3418
  define('[][SLICE_OR_FLAT].call("false")'),
3418
3419
  ],
3420
+ JOIN:
3421
+ [
3422
+ define({ expr: '"join"', solutionType: SolutionType.COMBINED_STRING }),
3423
+ ],
3419
3424
  LOCALE_AR:
3420
3425
  [
3421
3426
  define({ expr: '"ar-td"', solutionType: SolutionType.COMBINED_STRING }),
3422
3427
  define({ expr: '"ar"', solutionType: SolutionType.COMBINED_STRING }, SHORT_LOCALES),
3423
3428
  ],
3429
+ MAP:
3430
+ [
3431
+ define({ expr: '"map"', optimize: true, solutionType: SolutionType.COMBINED_STRING }),
3432
+ ],
3424
3433
  PLAIN_OBJECT:
3425
3434
  [
3426
3435
  define('Function("return{}")()'),
@@ -3439,6 +3448,10 @@
3439
3448
  define({ expr: '"slice"', solutionType: SolutionType.COMBINED_STRING }),
3440
3449
  define({ expr: '"substr"', solutionType: SolutionType.COMBINED_STRING }),
3441
3450
  ],
3451
+ SPLIT:
3452
+ [
3453
+ define({ expr: '"split"', optimize: true, solutionType: SolutionType.COMBINED_STRING }),
3454
+ ],
3442
3455
  TO_LOCALE_STRING:
3443
3456
  [
3444
3457
  define
@@ -3664,102 +3677,106 @@
3664
3677
 
3665
3678
  FH_R_PADDING_SHIFTS = [define(1, IE_SRC), define(0, NO_IE_SRC)];
3666
3679
 
3667
- var FORMAT_MAPPER_ENTRIES =
3668
- [
3669
- define
3670
- (
3671
- (function () {
3672
- var formatMapper =
3673
- function (accessor)
3674
- {
3675
- var mapper =
3676
- 'Function("return function(falsefalse){return function(undefined){return ' +
3677
- 'falsefalse' + accessor + '}}")()';
3678
- return mapper;
3679
- };
3680
- formatMapper.argName = 'undefined';
3681
- return formatMapper;
3682
- })()
3683
- ),
3684
- define
3685
- (
3686
- (function () {
3687
- var formatMapper =
3688
- function (accessor)
3689
- {
3690
- var mapper =
3691
- 'Function("return function(undefined){return this' + accessor + '}")().bind';
3692
- return mapper;
3693
- };
3694
- formatMapper.argName = 'undefined';
3695
- return formatMapper;
3696
- })()
3697
- ),
3698
- define
3699
- (
3700
- (function () {
3701
- var formatMapper =
3702
- function (accessor)
3703
- {
3704
- var mapper =
3705
- 'Function("return function(f){return this' + accessor + '}")().bind';
3706
- return mapper;
3707
- };
3708
- formatMapper.argName = 'f';
3709
- return formatMapper;
3710
- })()
3711
- ),
3712
- define
3713
- (
3714
- (function () {
3715
- var formatMapper =
3716
- function (accessor)
3717
- {
3718
- var mapper =
3719
- 'Function("return falsefalse=>undefined=>falsefalse' + accessor + '")()';
3720
- return mapper;
3721
- };
3722
- formatMapper.argName = 'undefined';
3723
- return formatMapper;
3724
- })(),
3725
- ARROW
3726
- ),
3727
- ];
3728
-
3729
3680
  FORMAT_MAPPER_LONG =
3730
3681
  defineList
3731
3682
  (
3732
- FORMAT_MAPPER_ENTRIES,
3683
+ [
3684
+ define
3685
+ (
3686
+ (function () {
3687
+ var formatMapper =
3688
+ function (accessor)
3689
+ {
3690
+ var mapper =
3691
+ 'Function("return function(falsefalse){return function(undefined){return ' +
3692
+ 'falsefalse' + accessor + '}}")()';
3693
+ return mapper;
3694
+ };
3695
+ formatMapper.argName = 'undefined';
3696
+ return formatMapper;
3697
+ })()
3698
+ ),
3699
+ define
3700
+ (
3701
+ (function () {
3702
+ var formatMapper =
3703
+ function (accessor)
3704
+ {
3705
+ var mapper =
3706
+ 'Function("return function(f){return this' + accessor + '}")().bind';
3707
+ return mapper;
3708
+ };
3709
+ formatMapper.argName = 'f';
3710
+ return formatMapper;
3711
+ })()
3712
+ ),
3713
+ define
3714
+ (
3715
+ (function () {
3716
+ var formatMapper =
3717
+ function (accessor)
3718
+ {
3719
+ var mapper =
3720
+ 'Function("return falsefalse=>undefined=>falsefalse' + accessor + '")()';
3721
+ return mapper;
3722
+ };
3723
+ formatMapper.argName = 'undefined';
3724
+ return formatMapper;
3725
+ })(),
3726
+ ARROW
3727
+ ),
3728
+ ],
3733
3729
  [
3734
3730
  define(0),
3735
- define(2, ARRAY_ITERATOR),
3731
+ define(1, ARRAY_ITERATOR),
3736
3732
  define(0, NO_FF_SRC),
3737
3733
  define(0, NO_V8_SRC),
3738
- define(2, ARRAY_ITERATOR, CAPITAL_HTML),
3734
+ define(1, ARRAY_ITERATOR, CAPITAL_HTML),
3739
3735
  define(0, ARRAY_ITERATOR, AT),
3740
3736
  define(0, ARRAY_ITERATOR, FLAT),
3741
3737
  define(0, ARRAY_ITERATOR, NO_IE_SRC),
3742
3738
  define(0, ARRAY_ITERATOR, CAPITAL_HTML, IE_SRC),
3743
- define(3),
3739
+ define(2),
3744
3740
  ]
3745
3741
  );
3746
3742
 
3747
3743
  FORMAT_MAPPER_SHORT =
3748
3744
  defineList
3749
3745
  (
3750
- FORMAT_MAPPER_ENTRIES,
3751
3746
  [
3752
- define(0),
3753
- define(1, ARRAY_ITERATOR),
3754
- define(0, NO_FF_SRC),
3755
- define(0, NO_V8_SRC),
3756
- define(1, ARRAY_ITERATOR, CAPITAL_HTML),
3757
- define(0, ARRAY_ITERATOR, AT),
3758
- define(0, ARRAY_ITERATOR, FLAT),
3759
- define(0, ARRAY_ITERATOR, NO_IE_SRC),
3760
- define(0, ARRAY_ITERATOR, CAPITAL_HTML, IE_SRC),
3761
- define(3),
3762
- ]
3747
+ define
3748
+ (
3749
+ (function () {
3750
+ var formatMapper =
3751
+ function (accessor)
3752
+ {
3753
+ var mapper =
3754
+ 'Function("return function(undefined){return function(falsefalse){return ' +
3755
+ 'undefined[1][undefined[0]' + accessor + ']}}")()';
3756
+ return mapper;
3757
+ };
3758
+ formatMapper.argName = 'falsefalse';
3759
+ return formatMapper;
3760
+ })()
3761
+ ),
3762
+ define
3763
+ (
3764
+ (function () {
3765
+ var formatMapper =
3766
+ function (accessor)
3767
+ {
3768
+ var mapper =
3769
+ 'Function("return undefined=>falsefalse=>undefined[1][undefined[0]' +
3770
+ accessor + ']")()';
3771
+ return mapper;
3772
+ };
3773
+ formatMapper.argName = 'falsefalse';
3774
+ return formatMapper;
3775
+ })(),
3776
+ ARROW
3777
+ ),
3778
+ ],
3779
+ [define(0), define(1)]
3763
3780
  );
3764
3781
 
3765
3782
  FROM_CHAR_CODE =
@@ -4974,7 +4991,7 @@
4974
4991
  var chain = stack.slice(stackIndex);
4975
4992
  var feature = featureFromMask(encoder.mask);
4976
4993
  var message = 'Circular reference detected: ' + chain.join(' < ') + ' – ' + feature;
4977
- var error = new _SyntaxError(message);
4994
+ var error = _SyntaxError(message);
4978
4995
  assignNoEnum$1(error, { chain: chain, feature: feature });
4979
4996
  throw error;
4980
4997
  }
@@ -5193,7 +5210,7 @@
5193
5210
  var stackLength = stack.length;
5194
5211
  if (stackLength)
5195
5212
  message += ' in the definition of ' + stack[stackLength - 1];
5196
- throw new _SyntaxError(message);
5213
+ throw _SyntaxError(message);
5197
5214
  }
5198
5215
 
5199
5216
  var matchSimpleAt =
@@ -5288,6 +5305,8 @@
5288
5305
  throwSyntaxError(this, 'Undefined regular padding block with length ' + length);
5289
5306
  },
5290
5307
 
5308
+ _guardResolution: noop,
5309
+
5291
5310
  _replaceCharByAtob: replaceCharByAtob,
5292
5311
 
5293
5312
  _replaceCharByCharCode: replaceCharByCharCode,
@@ -5496,11 +5515,9 @@
5496
5515
  var firstSolution = options.firstSolution;
5497
5516
  var maxLength = options.maxLength;
5498
5517
  if (firstSolution)
5499
- {
5500
5518
  buffer.append(firstSolution);
5501
- if (buffer.length > maxLength)
5502
- return;
5503
- }
5519
+ if (buffer.length > maxLength)
5520
+ return;
5504
5521
  var length = str.length;
5505
5522
  for (var index = 0; index < length;)
5506
5523
  {
@@ -5563,15 +5580,17 @@
5563
5580
  var solution = charCache[char];
5564
5581
  if (solution === undefined)
5565
5582
  {
5583
+ var charName = _JSON_stringify$1(char);
5566
5584
  callResolver
5567
5585
  (
5568
5586
  this,
5569
- _JSON_stringify$1(char),
5587
+ charName,
5570
5588
  function ()
5571
5589
  {
5572
5590
  var entries = CHARACTERS[char];
5573
5591
  if (!entries || _Array_isArray$1(entries))
5574
5592
  {
5593
+ this._guardResolution(charName);
5575
5594
  if (entries)
5576
5595
  solution = findOptimalSolution(this, char, entries);
5577
5596
  if (!solution)
@@ -5606,6 +5625,7 @@
5606
5625
  var entries = this.constantDefinitions[constant];
5607
5626
  if (_Array_isArray$1(entries))
5608
5627
  {
5628
+ this._guardResolution(constant);
5609
5629
  solution =
5610
5630
  findOptimalSolution(this, constant, entries, SolutionType.OBJECT);
5611
5631
  }
@@ -5624,6 +5644,12 @@
5624
5644
  }
5625
5645
  );
5626
5646
 
5647
+ STATIC_ENCODER._guardResolution =
5648
+ function (name)
5649
+ {
5650
+ throw _Error$1('Unable to resolve ' + name + ' statically');
5651
+ };
5652
+
5627
5653
  initStaticEncoder(STATIC_ENCODER);
5628
5654
 
5629
5655
  function createFigurator(startValues, joiner)
@@ -5747,6 +5773,49 @@
5747
5773
  return figurator;
5748
5774
  }
5749
5775
 
5776
+ function joinWithMaxLength(maxLength)
5777
+ {
5778
+ for (var index = arguments.length; ;)
5779
+ {
5780
+ if (maxLength < 0)
5781
+ return;
5782
+ if (--index < 1)
5783
+ break;
5784
+ var str = arguments[index];
5785
+ maxLength -= str.length;
5786
+ }
5787
+ var array = _Array_prototype_slice_call(arguments, 1);
5788
+ var result = array.join('');
5789
+ return result;
5790
+ }
5791
+
5792
+ // Length of the shortest possible concat head replacement "[]".
5793
+ var CONCAT_HEAD_MIN_LENGTH = 2;
5794
+
5795
+ // The overhead of "[" + "]" plus the minimum concat head replacement length.
5796
+ var CONCAT_HEAD_MIN_OVERHEAD = 2 + CONCAT_HEAD_MIN_LENGTH;
5797
+
5798
+ // Length of the shortest possible concat part replacements "+[] and "![]".
5799
+ var CONCAT_PART_MIN_LENGTH = 3;
5800
+
5801
+ // The overhead of "[" + "](" + ")" plus the minimum concat part replacement length.
5802
+ var CONCAT_PART_MIN_OVERHEAD = 4 + CONCAT_PART_MIN_LENGTH;
5803
+
5804
+ // Length of the shortest possible joiner replacement "[]".
5805
+ var JOINER_MIN_LENGTH = 2;
5806
+
5807
+ // The overhead of "[" + "](" + ")" plus the minimum joiner replacement length.
5808
+ var JOINING_MIN_OVERHEAD = 4 + JOINER_MIN_LENGTH;
5809
+
5810
+ // Length of the shortest possible separator replacement "[]".
5811
+ var SEPARATOR_MIN_LENGTH = 2;
5812
+
5813
+ // The overhead of "[" + "](" + ")" plus the minimum separator replacement length.
5814
+ var SEPARATION_MIN_OVERHEAD = 4 + SEPARATOR_MIN_LENGTH;
5815
+
5816
+ // Length of the shortest possible sequence replacement "([]+[])".
5817
+ var SEQUENCE_MIN_LENGTH = 7;
5818
+
5750
5819
  /**
5751
5820
  * An object that exposes properties used to split a string into an array of strings or to join
5752
5821
  * array elements into a string.
@@ -5762,6 +5831,81 @@
5762
5831
  * to join them into a single string.
5763
5832
  */
5764
5833
 
5834
+ function createConcatenationReplacement
5835
+ (encoder, array, allowZeroForEmptyElements, forceString, maxLength)
5836
+ {
5837
+ var concatReplacement = encoder.resolveConstant('CONCAT').replacement;
5838
+ var concatCount = array.length - 1;
5839
+ maxLength -=
5840
+ CONCAT_HEAD_MIN_OVERHEAD + concatCount * (concatReplacement.length + CONCAT_PART_MIN_OVERHEAD);
5841
+ if (maxLength < 0)
5842
+ return;
5843
+ var options = { screwMode: forceString ? SCREW_AS_STRING : SCREW_NORMAL };
5844
+ var replacements = [];
5845
+ for (var index = 0; index <= concatCount; ++index)
5846
+ {
5847
+ var element = array[index];
5848
+ var elementReplacement = undefinedAsString(replaceStaticString(element, options));
5849
+ var minLength = index ? CONCAT_PART_MIN_LENGTH : CONCAT_HEAD_MIN_LENGTH;
5850
+ if (index)
5851
+ {
5852
+ if (elementReplacement === '[]')
5853
+ elementReplacement = allowZeroForEmptyElements ? '+[]' : '[[]]';
5854
+ replacements.push('[', concatReplacement, '](', elementReplacement, ')');
5855
+ }
5856
+ else
5857
+ replacements.push('[', elementReplacement, ']');
5858
+ maxLength -= elementReplacement.length - minLength;
5859
+ if (maxLength < 0)
5860
+ return;
5861
+ }
5862
+ var concatenationReplacement = replacements.join('');
5863
+ return concatenationReplacement;
5864
+ }
5865
+
5866
+ function createSubstitutionsReplacement(encoder, substitutions, maxLength)
5867
+ {
5868
+ var substitutionCount = substitutions ? substitutions.length : 0;
5869
+ if (!substitutionCount)
5870
+ return '';
5871
+ var splitReplacement = encoder.resolveConstant('SPLIT').replacement;
5872
+ var joinReplacement = encoder.resolveConstant('JOIN').replacement;
5873
+ maxLength -=
5874
+ substitutionCount *
5875
+ (
5876
+ splitReplacement.length + SEPARATION_MIN_OVERHEAD +
5877
+ joinReplacement.length + JOINING_MIN_OVERHEAD
5878
+ );
5879
+ if (maxLength < 0)
5880
+ return;
5881
+ var replacements = [];
5882
+ for (var index = 0; index < substitutionCount; ++index)
5883
+ {
5884
+ var substitution = substitutions[index];
5885
+ var separatorReplacement = undefinedAsString(encoder.replaceExpr(substitution.separator));
5886
+ var joinerReplacement = undefinedAsString(encoder.replaceString(substitution.joiner));
5887
+ maxLength -=
5888
+ separatorReplacement.length - SEPARATOR_MIN_LENGTH +
5889
+ joinerReplacement.length - JOINER_MIN_LENGTH;
5890
+ if (maxLength < 0)
5891
+ return;
5892
+ replacements.push
5893
+ (
5894
+ '[',
5895
+ splitReplacement,
5896
+ '](',
5897
+ separatorReplacement,
5898
+ ')[',
5899
+ joinReplacement,
5900
+ '](',
5901
+ joinerReplacement,
5902
+ ')'
5903
+ );
5904
+ }
5905
+ var substitutionsReplacement = replacements.join('');
5906
+ return substitutionsReplacement;
5907
+ }
5908
+
5765
5909
  function replaceJoinedArrayString(array, joiner, maxLength)
5766
5910
  {
5767
5911
  var str = array.join(joiner);
@@ -5770,18 +5914,8 @@
5770
5914
  return replacement;
5771
5915
  }
5772
5916
 
5773
- function undefinedAsString(replacement)
5774
- {
5775
- if (replacement === '[][[]]')
5776
- replacement += '+[]';
5777
- return replacement;
5778
- }
5779
-
5780
5917
  /**
5781
- * Replaces a given array of strings with equivalent JSFuck code.
5782
- *
5783
- * Array elements may only contain characters with static definitions in their string
5784
- * representations.
5918
+ * Replaces a given array of statically replaceable strings with equivalent JSFuck code.
5785
5919
  *
5786
5920
  * @function Encoder#replaceStringArray
5787
5921
  *
@@ -5790,7 +5924,7 @@
5790
5924
  *
5791
5925
  * @param {Delimiter[]} insertions
5792
5926
  * An array of delimiters of which at most one will be used to compose a joined string and split it
5793
- * into an array of strings.
5927
+ * into an array of strings. Every joiner in the insertions must be a statically replaceable string.
5794
5928
  *
5795
5929
  * The encoder can pick an insertion and insert a joiner between any two adjacent elements to mark
5796
5930
  * the boundary between them. The separator is then used to split the concatenated string back into
@@ -5838,143 +5972,69 @@
5838
5972
  // applied.
5839
5973
  if (substitutions || count > 2)
5840
5974
  {
5841
- var preReplacement =
5842
- function ()
5843
- {
5844
- // Length of the shortest string replacement "([]+[])".
5845
- var STRING_REPLACEMENT_MIN_LENGTH = 7;
5846
-
5847
- // This is for the overhead of "[" + "](" + ")" plus the length of the shortest
5848
- // separator replacement "[]".
5849
- var SEPARATOR_MIN_OVERHEAD = 6;
5850
-
5851
- // This is for the overhead of "[" + "](" + ")" plus the length of the shortest
5852
- // joiner replacement "[]".
5853
- var JOINER_MIN_OVERHEAD = 6;
5854
-
5855
- var joinCount = substitutions ? substitutions.length : 0;
5856
- var splitCount = joinCount + 1;
5857
- var maxSplitReplacementLength =
5858
- (maxLength - STRING_REPLACEMENT_MIN_LENGTH) / splitCount - SEPARATOR_MIN_OVERHEAD;
5859
- var splitReplacement =
5860
- this.replaceString('split', { maxLength: maxSplitReplacementLength, optimize: true });
5861
- if (!splitReplacement)
5862
- return;
5863
- var preReplacement = '';
5864
- if (joinCount)
5865
- {
5866
- var maxJoinReplacementLength =
5867
- (
5868
- maxLength - STRING_REPLACEMENT_MIN_LENGTH -
5869
- splitCount * (splitReplacement.length + SEPARATOR_MIN_OVERHEAD)
5870
- ) /
5871
- joinCount -
5872
- JOINER_MIN_OVERHEAD;
5873
- var joinReplacement =
5874
- this.replaceString('join', { maxLength: maxJoinReplacementLength });
5875
- if (!joinReplacement)
5876
- return;
5877
- substitutions.forEach
5878
- (
5879
- function (substitution)
5880
- {
5881
- var separatorReplacement =
5882
- undefinedAsString(this.replaceExpr(substitution.separator));
5883
- var joinerReplacement =
5884
- undefinedAsString(this.replaceString(substitution.joiner));
5885
- preReplacement +=
5886
- '[' + splitReplacement + '](' + separatorReplacement + ')[' +
5887
- joinReplacement + '](' + joinerReplacement + ')';
5888
- },
5889
- this
5890
- );
5891
- }
5892
- preReplacement += '[' + splitReplacement + ']';
5893
- return preReplacement;
5894
- }
5895
- .call(this);
5975
+ var splitReplacement = this.resolveConstant('SPLIT').replacement;
5976
+ var minSubstitutionsReplacementLength =
5977
+ maxLength -
5978
+ SEQUENCE_MIN_LENGTH -
5979
+ splitReplacement.length -
5980
+ SEPARATION_MIN_OVERHEAD;
5981
+ var substitutionsReplacement =
5982
+ createSubstitutionsReplacement(this, substitutions, minSubstitutionsReplacementLength);
5896
5983
  }
5897
- if (!substitutions && count > 1)
5898
- {
5899
- var concatReplacement =
5900
- this.replaceString('concat', { maxLength: maxLength, optimize: true });
5901
- }
5902
- if (preReplacement)
5984
+ if (substitutionsReplacement != null)
5903
5985
  // Approach 1: (array[0] + joiner + array[1] + joiner + array[2]...).split(separator)
5904
5986
  {
5905
- // 2 is for the additional overhead of "(" + ")".
5906
- var maxBulkLength = maxLength - (preReplacement.length + 2);
5907
- var optimalStrReplacement;
5987
+ var maxBulkLength =
5988
+ maxLength - substitutionsReplacement.length - splitReplacement.length -
5989
+ SEPARATION_MIN_OVERHEAD + SEPARATOR_MIN_LENGTH;
5990
+ var optimalSeqReplacement;
5908
5991
  var optimalSeparatorReplacement;
5909
5992
  insertions.forEach
5910
5993
  (
5911
5994
  function (insertion)
5912
5995
  {
5913
- var strReplacement =
5996
+ var seqReplacement =
5914
5997
  replaceJoinedArrayString(array, insertion.joiner, maxBulkLength);
5915
- if (!strReplacement)
5998
+ if (!seqReplacement)
5916
5999
  return;
5917
6000
  var separatorReplacement = undefinedAsString(this.replaceExpr(insertion.separator));
5918
- var bulkLength = strReplacement.length + separatorReplacement.length;
6001
+ var bulkLength = seqReplacement.length + separatorReplacement.length;
5919
6002
  if (!(bulkLength > maxBulkLength))
5920
6003
  {
5921
6004
  maxBulkLength = bulkLength;
5922
- optimalStrReplacement = strReplacement;
6005
+ optimalSeqReplacement = seqReplacement;
5923
6006
  optimalSeparatorReplacement = separatorReplacement;
5924
6007
  }
5925
6008
  },
5926
6009
  this
5927
6010
  );
5928
- if (optimalStrReplacement)
6011
+ if (optimalSeqReplacement)
5929
6012
  {
5930
6013
  replacement =
5931
- optimalStrReplacement + preReplacement + '(' + optimalSeparatorReplacement + ')';
6014
+ optimalSeqReplacement + substitutionsReplacement + '[' + splitReplacement + '](' +
6015
+ optimalSeparatorReplacement + ')';
5932
6016
  maxLength = replacement.length - 1;
5933
6017
  }
5934
6018
  }
5935
- if
5936
- (
5937
- !substitutions &&
5938
- (
5939
- count <= 1 ||
5940
- concatReplacement &&
5941
- // 4 is the length of the shortest possible replacement "[[]]".
5942
- // 7 is the length of the shortest possible additional overhead for each following array
5943
- // element, as in "[" + "](+[])" or "[" + "](![])".
5944
- !(4 + (concatReplacement.length + 7) * (count - 1) > maxLength)
5945
- )
5946
- )
6019
+ if (!substitutions)
5947
6020
  // Approach 2: [array[0]].concat(array[1]).concat(array[2])...
5948
6021
  {
5949
- var arrayReplacement;
5950
- var options = { screwMode: forceString ? SCREW_AS_STRING : SCREW_NORMAL };
5951
- if
5952
- (
5953
- !array.some
5954
- (
5955
- function (element)
5956
- {
5957
- var elementReplacement =
5958
- undefinedAsString(replaceStaticString(element, options));
5959
- if (arrayReplacement)
5960
- {
5961
- if (elementReplacement === '[]')
5962
- elementReplacement = allowZeroForEmptyElements ? '+[]' : '[[]]';
5963
- arrayReplacement +=
5964
- '[' + concatReplacement + '](' + elementReplacement + ')';
5965
- }
5966
- else
5967
- arrayReplacement = '[' + elementReplacement + ']';
5968
- var result = arrayReplacement.length > maxLength;
5969
- return result;
5970
- }
5971
- )
5972
- )
6022
+ var arrayReplacement =
6023
+ createConcatenationReplacement
6024
+ (this, array, allowZeroForEmptyElements, forceString, maxLength);
6025
+ if (arrayReplacement)
5973
6026
  replacement = arrayReplacement;
5974
6027
  }
5975
6028
  return replacement;
5976
6029
  }
5977
6030
 
6031
+ function undefinedAsString(replacement)
6032
+ {
6033
+ if (replacement === '[][[]]')
6034
+ replacement += '+[]';
6035
+ return replacement;
6036
+ }
6037
+
5978
6038
  var ENCODING_TYPE_COMBINED = 'combined';
5979
6039
  var ENCODING_TYPE_EXPRESSION = 'expression';
5980
6040
  var ENCODING_TYPE_TEXT = 'text';
@@ -5982,6 +6042,12 @@
5982
6042
  var FALSE_FREE_DELIMITER = { joiner: 'false', separator: 'false' };
5983
6043
  var FALSE_TRUE_DELIMITER = { joiner: '', separator: 'Function("return/(?=false|true)/")()' };
5984
6044
 
6045
+ // Underestimated minimum length of the joining: "[" + joinReplacement + "]([])".
6046
+ var JOINING_MIN_LENGTH = 8;
6047
+
6048
+ // Underestimated minimum overhead of the mapping: "[" + "](" + mapperReplacement + ")".
6049
+ var MAPPING_MIN_OVERHEAD = 12;
6050
+
5985
6051
  var REPLACERS =
5986
6052
  {
5987
6053
  identifier:
@@ -6079,23 +6145,62 @@
6079
6145
  return charKeyArrayStr;
6080
6146
  }
6081
6147
 
6082
- function createJSFuckArrayMapping(encoder, arrayStr, mapper, legend)
6148
+ function createLongStrCodesOutput(encoder, arrayReplacement, fromCharCode, arg, maxLength)
6083
6149
  {
6084
- var result =
6085
- arrayStr + '[' + encoder.replaceString('map', { optimize: true }) + '](' +
6086
- encoder.replaceExpr(mapper, true) + '(' + legend + '))';
6087
- return result;
6150
+ var mapReplacement = encoder.resolveConstant('MAP').replacement;
6151
+ var maxCharArrayLength = maxLength - JOINING_MIN_LENGTH;
6152
+ var maxMapReplacementLength =
6153
+ maxCharArrayLength - arrayReplacement.length - MAPPING_MIN_OVERHEAD;
6154
+ if (mapReplacement.length > maxMapReplacementLength)
6155
+ return;
6156
+ var formatter = encoder.findDefinition(FROM_CHAR_CODE_CALLBACK_FORMATTER);
6157
+ var formatterExpr = formatter(fromCharCode, arg);
6158
+ var mapper = 'Function("return ' + formatterExpr + '")()';
6159
+ var mapperReplacement = encoder._replaceMapper(mapper);
6160
+ var charArrayReplacement =
6161
+ joinWithMaxLength
6162
+ (
6163
+ maxCharArrayLength,
6164
+ arrayReplacement,
6165
+ '[',
6166
+ mapReplacement,
6167
+ '](',
6168
+ mapperReplacement,
6169
+ ')'
6170
+ );
6171
+ if (!charArrayReplacement)
6172
+ return;
6173
+ var replacement = encoder._joinCharArray(charArrayReplacement, maxLength);
6174
+ return replacement;
6088
6175
  }
6089
6176
 
6090
- function createLongStrCodesOutput(encoder, strCodeArrayStr, fromCharCode, arg)
6177
+ function createMappedArrayEncoding(encoder, arrayReplacement, mapper, legend, maxLength)
6091
6178
  {
6092
- var formatter = encoder.findDefinition(FROM_CHAR_CODE_CALLBACK_FORMATTER);
6093
- var formatterExpr = formatter(fromCharCode, arg);
6094
- var output =
6095
- strCodeArrayStr + '[' + encoder.replaceString('map', { optimize: true }) + '](' +
6096
- encoder.replaceExpr('Function("return ' + formatterExpr + '")()', true) + ')[' +
6097
- encoder.replaceString('join') + ']([])';
6098
- return output;
6179
+ var mapReplacement = encoder.resolveConstant('MAP').replacement;
6180
+ var maxCharArrayLength = maxLength - JOINING_MIN_LENGTH;
6181
+ var maxMapReplacementLength =
6182
+ // 2 is for the calling parentheses around the legend replacement.
6183
+ maxCharArrayLength - arrayReplacement.length - MAPPING_MIN_OVERHEAD - legend.length - 2;
6184
+ if (mapReplacement.length > maxMapReplacementLength)
6185
+ return;
6186
+ var mapperReplacement = encoder._replaceMapper(mapper);
6187
+ var charArrayReplacement =
6188
+ joinWithMaxLength
6189
+ (
6190
+ maxCharArrayLength,
6191
+ arrayReplacement,
6192
+ '[',
6193
+ mapReplacement,
6194
+ '](',
6195
+ mapperReplacement,
6196
+ '(',
6197
+ legend,
6198
+ '))'
6199
+ );
6200
+ if (!charArrayReplacement)
6201
+ return;
6202
+ var replacement = encoder._joinCharArray(charArrayReplacement, maxLength);
6203
+ return replacement;
6099
6204
  }
6100
6205
 
6101
6206
  function createReindexMap(count, radix, amendingCount, coerceToInt)
@@ -6163,41 +6268,58 @@
6163
6268
  var strCodeCacheKey = 'strCodeCache' + (radix ? 'Radix' + radix : '');
6164
6269
  var cache = inputData[strCodeCacheKey] || (inputData[strCodeCacheKey] = createEmpty());
6165
6270
  var strCodeArray = splitter(input, radix, cache);
6166
- var strCodeArrayStr = encoder.replaceFalseFreeArray(strCodeArray, maxLength);
6271
+ var strCodeArrayStr =
6272
+ encoder.replaceStringArray(strCodeArray, [FALSE_FREE_DELIMITER], null, false, false, maxLength);
6167
6273
  if (strCodeArrayStr)
6168
6274
  {
6169
- var output;
6275
+ var replacement;
6170
6276
  if (radix)
6171
6277
  {
6172
- output =
6278
+ replacement =
6173
6279
  createLongStrCodesOutput
6174
- (encoder, strCodeArrayStr, fromCharCode, 'parseInt(undefined,' + radix + ')');
6280
+ (
6281
+ encoder,
6282
+ strCodeArrayStr,
6283
+ fromCharCode,
6284
+ 'parseInt(undefined,' + radix + ')',
6285
+ maxLength
6286
+ );
6175
6287
  }
6176
6288
  else
6177
6289
  {
6178
6290
  var long = strCodeArray.length > encoder._maxDecodableArgs;
6179
6291
  if (long)
6180
6292
  {
6181
- output =
6182
- createLongStrCodesOutput(encoder, strCodeArrayStr, fromCharCode, 'undefined');
6293
+ replacement =
6294
+ createLongStrCodesOutput
6295
+ (
6296
+ encoder,
6297
+ strCodeArrayStr,
6298
+ fromCharCode,
6299
+ 'undefined',
6300
+ maxLength
6301
+ );
6183
6302
  }
6184
6303
  else
6185
6304
  {
6186
6305
  var returnString = encoder.findDefinition(OPTIMAL_RETURN_STRING);
6187
6306
  var str = returnString + '.' + fromCharCode + '(';
6188
- output =
6189
- encoder.resolveConstant('Function').replacement +
6190
- '(' +
6191
- encoder.replaceString(str, { optimize: true }) +
6192
- '+' +
6193
- strCodeArrayStr +
6194
- '+' +
6195
- encoder.resolveCharacter(')').replacement +
6196
- ')()';
6307
+ replacement =
6308
+ joinWithMaxLength
6309
+ (
6310
+ maxLength,
6311
+ encoder.resolveConstant('Function').replacement,
6312
+ '(',
6313
+ encoder.replaceString(str, { optimize: true }),
6314
+ '+',
6315
+ strCodeArrayStr,
6316
+ '+',
6317
+ encoder.resolveCharacter(')').replacement,
6318
+ ')()'
6319
+ );
6197
6320
  }
6198
6321
  }
6199
- if (!(output.length > maxLength))
6200
- return output;
6322
+ return replacement;
6201
6323
  }
6202
6324
  }
6203
6325
 
@@ -6256,8 +6378,7 @@
6256
6378
  var legend = encodeDictLegend(encoder, dictChars, maxLength - minCharIndexArrayStrLength);
6257
6379
  if (!legend)
6258
6380
  return;
6259
- var figureLegendInsertions =
6260
- encoder._callGetFigureLegendInsertions(getFigureLegendInsertions, figurator, figures);
6381
+ var figureLegendInsertions = getFigureLegendInsertions(figurator, figures);
6261
6382
  var figureMaxLength = maxLength - legend.length;
6262
6383
  var figureLegend =
6263
6384
  encoder.replaceStringArray
@@ -6284,13 +6405,10 @@
6284
6405
  );
6285
6406
  if (!charIndexFigureArrayStr)
6286
6407
  return;
6287
- var formatMapper = encoder.findDefinition(FORMAT_MAPPER_SHORT);
6288
- var argName = formatMapper.argName;
6289
- var accessor = '.indexOf(' + argName + ')';
6290
- var mapper = formatMapper(accessor);
6291
- var charIndexArrayStr =
6292
- createJSFuckArrayMapping(encoder, charIndexFigureArrayStr, mapper, figureLegend);
6293
- var output = encoder.createDictEncoding(legend, charIndexArrayStr, maxLength);
6408
+ var formatMapper = encoder._findFormatMapperShort();
6409
+ var output =
6410
+ encoder._createDblDictEncoding
6411
+ (formatMapper, charIndexFigureArrayStr, figureLegend, legend, maxLength);
6294
6412
  return output;
6295
6413
  }
6296
6414
 
@@ -6798,7 +6916,7 @@
6798
6916
  return output;
6799
6917
  },
6800
6918
  ENCODING_TYPE_TEXT,
6801
- 193
6919
+ 194
6802
6920
  ),
6803
6921
 
6804
6922
  /* -------------------------------------------------------------------------------------- *\
@@ -6853,7 +6971,7 @@
6853
6971
  return output;
6854
6972
  },
6855
6973
  ENCODING_TYPE_TEXT,
6856
- 347
6974
+ 173
6857
6975
  ),
6858
6976
 
6859
6977
  /* -------------------------------------------------------------------------------------- *\
@@ -6943,11 +7061,51 @@
6943
7061
  (
6944
7062
  Encoder.prototype,
6945
7063
  {
6946
- _callGetFigureLegendInsertions:
6947
- function (getFigureLegendInsertions, figurator, figures)
7064
+ _createDblDictEncoding:
7065
+ function (formatMapper, charIndexFigureArrayStr, figureLegend, legend, maxLength)
7066
+ {
7067
+ var argName = formatMapper.argName;
7068
+ var accessor = '.indexOf(' + argName + ')';
7069
+ var mapper = formatMapper(accessor);
7070
+ var concatReplacement = this.resolveConstant('CONCAT').replacement;
7071
+ var maxCombinedLegendLength = maxLength - charIndexFigureArrayStr.length - 10;
7072
+ var combinedLegend =
7073
+ joinWithMaxLength
7074
+ (
7075
+ maxCombinedLegendLength,
7076
+ '[',
7077
+ figureLegend,
7078
+ '][',
7079
+ concatReplacement,
7080
+ '](',
7081
+ legend,
7082
+ ')'
7083
+ );
7084
+ if (!combinedLegend)
7085
+ return;
7086
+ var replacement =
7087
+ createMappedArrayEncoding
7088
+ (this, charIndexFigureArrayStr, mapper, combinedLegend, maxLength);
7089
+ return replacement;
7090
+ },
7091
+
7092
+ _createDictEncoding:
7093
+ function (charIndexArrayStr, legend, radix, coerceToInt, maxLength)
6948
7094
  {
6949
- var figureLegendInsertions = getFigureLegendInsertions(figurator, figures);
6950
- return figureLegendInsertions;
7095
+ var mapper;
7096
+ if (radix)
7097
+ {
7098
+ var formatMapper = this.findDefinition(FORMAT_MAPPER_LONG);
7099
+ var argName = formatMapper.argName;
7100
+ var parseIntArg = (coerceToInt ? '+' : '') + argName;
7101
+ var accessor = '[parseInt(' + parseIntArg + ',' + radix + ')]';
7102
+ mapper = formatMapper(accessor);
7103
+ }
7104
+ else
7105
+ mapper = '"".charAt.bind';
7106
+ var replacement =
7107
+ createMappedArrayEncoding(this, charIndexArrayStr, mapper, legend, maxLength);
7108
+ return replacement;
6951
7109
  },
6952
7110
 
6953
7111
  _encodeByCharCodes:
@@ -7044,7 +7202,7 @@
7044
7202
  if (!charIndexArrayStr)
7045
7203
  return;
7046
7204
  var output =
7047
- this.createDictEncoding(legend, charIndexArrayStr, maxLength, radix, coerceToInt);
7205
+ this._createDictEncoding(charIndexArrayStr, legend, radix, coerceToInt, maxLength);
7048
7206
  return output;
7049
7207
  },
7050
7208
 
@@ -7092,41 +7250,33 @@
7092
7250
  perfInfo.perfLog = perfLog;
7093
7251
  delete this.perfLog;
7094
7252
  if (output == null)
7095
- throw new _Error$1('Encoding failed');
7253
+ throw _Error$1('Encoding failed');
7096
7254
  return output;
7097
7255
  },
7098
7256
 
7099
- _maxDecodableArgs: 65533, // Limit imposed by Internet Explorer.
7257
+ _findFormatMapperShort:
7258
+ function ()
7259
+ {
7260
+ var formatMapper = this.findDefinition(FORMAT_MAPPER_SHORT);
7261
+ return formatMapper;
7262
+ },
7100
7263
 
7101
- createDictEncoding:
7102
- function (legend, charIndexArrayStr, maxLength, radix, coerceToInt)
7264
+ _joinCharArray:
7265
+ function (charArrayReplacement, maxLength)
7103
7266
  {
7104
- var mapper;
7105
- if (radix)
7106
- {
7107
- var formatMapper = this.findDefinition(FORMAT_MAPPER_LONG);
7108
- var argName = formatMapper.argName;
7109
- var parseIntArg = (coerceToInt ? '+' : '') + argName;
7110
- var accessor = '[parseInt(' + parseIntArg + ',' + radix + ')]';
7111
- mapper = formatMapper(accessor);
7112
- }
7113
- else
7114
- mapper = '"".charAt.bind';
7115
- var output =
7116
- createJSFuckArrayMapping(this, charIndexArrayStr, mapper, legend) + '[' +
7117
- this.replaceString('join') + ']([])';
7118
- if (!(output.length > maxLength))
7119
- return output;
7267
+ var joinReplacement = this.resolveConstant('JOIN').replacement;
7268
+ var replacement =
7269
+ joinWithMaxLength(maxLength, charArrayReplacement, '[', joinReplacement, ']([])');
7270
+ return replacement;
7120
7271
  },
7121
7272
 
7122
- // Array elements may not contain the substring "false", because the value false could be
7123
- // used as a separator in the encoding.
7124
- replaceFalseFreeArray:
7125
- function (array, maxLength)
7273
+ _maxDecodableArgs: 65533, // Limit imposed by Internet Explorer.
7274
+
7275
+ _replaceMapper:
7276
+ function (mapper)
7126
7277
  {
7127
- var result =
7128
- this.replaceStringArray(array, [FALSE_FREE_DELIMITER], null, false, false, maxLength);
7129
- return result;
7278
+ var mapperReplacement = this.replaceExpr(mapper, true);
7279
+ return mapperReplacement;
7130
7280
  },
7131
7281
 
7132
7282
  replaceStringArray: replaceStringArray,
@@ -7872,7 +8022,7 @@
7872
8022
  case 'none':
7873
8023
  return [, STRATEGY_NAMES_TEXT];
7874
8024
  }
7875
- throw new _Error$1('Invalid value for option ' + name);
8025
+ throw _Error$1('Invalid value for option ' + name);
7876
8026
  }
7877
8027
 
7878
8028
  function flushEncoderCache()
@@ -8023,7 +8173,7 @@
8023
8173
  {
8024
8174
  constant = _String$1(constant);
8025
8175
  if (!/^[$A-Z_a-z][$\w]*$/.test(constant))
8026
- throw new _SyntaxError('Invalid identifier ' + _JSON_stringify$1(constant));
8176
+ throw _SyntaxError('Invalid identifier ' + _JSON_stringify$1(constant));
8027
8177
  if (!encoder.hasOwnProperty('constantDefinitions'))
8028
8178
  encoder.constantDefinitions = _Object_create$1(CONSTANTS);
8029
8179
  var entries = [define(esToString$1(definition))];