rollup 2.0.3 → 2.1.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/dist/bin/rollup CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  /*
4
4
  @license
5
- Rollup.js v2.0.3
6
- Tue, 10 Mar 2020 07:01:48 GMT - commit 3ef6f073e4b54da2b2e61de5e3fd66f9f7352bca
5
+ Rollup.js v2.1.0
6
+ Wed, 18 Mar 2020 05:17:01 GMT - commit f8bc01847155ccf69f9e772ee99fc0905848548f
7
7
 
8
8
 
9
9
  https://github.com/rollup/rollup
@@ -121,13 +121,13 @@ var tokenizeArgString = function (argString) {
121
121
 
122
122
  argString = argString.trim();
123
123
 
124
- var i = 0;
125
- var prevC = null;
126
- var c = null;
127
- var opening = null;
128
- var args = [];
124
+ let i = 0;
125
+ let prevC = null;
126
+ let c = null;
127
+ let opening = null;
128
+ const args = [];
129
129
 
130
- for (var ii = 0; ii < argString.length; ii++) {
130
+ for (let ii = 0; ii < argString.length; ii++) {
131
131
  prevC = c;
132
132
  c = argString.charAt(ii);
133
133
 
@@ -155,58 +155,59 @@ var tokenizeArgString = function (argString) {
155
155
  };
156
156
 
157
157
  function parse (args, opts) {
158
- if (!opts) opts = {};
158
+ opts = Object.assign(Object.create(null), opts);
159
159
  // allow a string argument to be passed in rather
160
160
  // than an argv array.
161
161
  args = tokenizeArgString(args);
162
162
 
163
163
  // aliases might have transitive relationships, normalize this.
164
- var aliases = combineAliases(opts.alias || {});
165
- var configuration = Object.assign({
166
- 'short-option-groups': true,
164
+ const aliases = combineAliases(Object.assign(Object.create(null), opts.alias));
165
+ const configuration = Object.assign({
166
+ 'boolean-negation': true,
167
167
  'camel-case-expansion': true,
168
+ 'combine-arrays': false,
168
169
  'dot-notation': true,
169
- 'parse-numbers': true,
170
- 'boolean-negation': true,
171
- 'negation-prefix': 'no-',
172
170
  'duplicate-arguments-array': true,
173
171
  'flatten-duplicate-arrays': true,
172
+ 'greedy-arrays': true,
173
+ 'halt-at-non-option': false,
174
+ 'nargs-eats-options': false,
175
+ 'negation-prefix': 'no-',
176
+ 'parse-numbers': true,
174
177
  'populate--': false,
175
- 'combine-arrays': false,
176
178
  'set-placeholder-key': false,
177
- 'halt-at-non-option': false,
179
+ 'short-option-groups': true,
178
180
  'strip-aliased': false,
179
181
  'strip-dashed': false,
180
182
  'unknown-options-as-args': false
181
183
  }, opts.configuration);
182
- var defaults = opts.default || {};
183
- var configObjects = opts.configObjects || [];
184
- var envPrefix = opts.envPrefix;
185
- var notFlagsOption = configuration['populate--'];
186
- var notFlagsArgv = notFlagsOption ? '--' : '_';
187
- var newAliases = {};
188
- var defaulted = {};
184
+ const defaults = Object.assign(Object.create(null), opts.default);
185
+ const configObjects = opts.configObjects || [];
186
+ const envPrefix = opts.envPrefix;
187
+ const notFlagsOption = configuration['populate--'];
188
+ const notFlagsArgv = notFlagsOption ? '--' : '_';
189
+ const newAliases = Object.create(null);
190
+ const defaulted = Object.create(null);
189
191
  // allow a i18n handler to be passed in, default to a fake one (util.format).
190
- var __ = opts.__ || _events_commonjsExternal.require$$1.format;
191
- var error = null;
192
- var flags = {
193
- aliases: {},
194
- arrays: {},
195
- bools: {},
196
- strings: {},
197
- numbers: {},
198
- counts: {},
199
- normalize: {},
200
- configs: {},
201
- nargs: {},
202
- coercions: {},
192
+ const __ = opts.__ || _events_commonjsExternal.require$$1.format;
193
+ const flags = {
194
+ aliases: Object.create(null),
195
+ arrays: Object.create(null),
196
+ bools: Object.create(null),
197
+ strings: Object.create(null),
198
+ numbers: Object.create(null),
199
+ counts: Object.create(null),
200
+ normalize: Object.create(null),
201
+ configs: Object.create(null),
202
+ nargs: Object.create(null),
203
+ coercions: Object.create(null),
203
204
  keys: []
204
205
  };
205
- var negative = /^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/;
206
- var negatedBoolean = new RegExp('^--' + configuration['negation-prefix'] + '(.+)')
206
+ const negative = /^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/;
207
+ const negatedBoolean = new RegExp('^--' + configuration['negation-prefix'] + '(.+)')
207
208
 
208
209
  ;[].concat(opts.array).filter(Boolean).forEach(function (opt) {
209
- var key = opt.key || opt;
210
+ const key = opt.key || opt;
210
211
 
211
212
  // assign to flags[bools|strings|numbers]
212
213
  const assignment = Object.keys(opt).map(function (key) {
@@ -282,19 +283,25 @@ function parse (args, opts) {
282
283
  });
283
284
  });
284
285
 
286
+ let error = null;
285
287
  checkConfiguration();
286
288
 
287
- var argv = { _: [] };
288
- var notFlags = [];
289
+ let notFlags = [];
289
290
 
290
- for (var i = 0; i < args.length; i++) {
291
- var arg = args[i];
292
- var broken;
293
- var key;
294
- var letters;
295
- var m;
296
- var next;
297
- var value;
291
+ const argv = Object.assign(Object.create(null), { _: [] });
292
+ // TODO(bcoe): for the first pass at removing object prototype we didn't
293
+ // remove all prototypes from objects returned by this API, we might want
294
+ // to gradually move towards doing so.
295
+ const argvReturn = {};
296
+
297
+ for (let i = 0; i < args.length; i++) {
298
+ const arg = args[i];
299
+ let broken;
300
+ let key;
301
+ let letters;
302
+ let m;
303
+ let next;
304
+ let value;
298
305
 
299
306
  // any unknown option (except for end-of-options, "--")
300
307
  if (arg !== '--' && isUnknownOptionAsArg(arg)) {
@@ -308,14 +315,14 @@ function parse (args, opts) {
308
315
  // http://stackoverflow.com/a/1068308/13216
309
316
  m = arg.match(/^--?([^=]+)=([\s\S]*)$/);
310
317
 
311
- // nargs format = '--f=monkey washing cat'
312
- if (checkAllAliases(m[1], flags.nargs)) {
313
- args.splice(i + 1, 0, m[2]);
314
- i = eatNargs(i, m[1], args);
315
318
  // arrays format = '--f=a b c'
316
- } else if (checkAllAliases(m[1], flags.arrays)) {
319
+ if (checkAllAliases(m[1], flags.arrays)) {
317
320
  args.splice(i + 1, 0, m[2]);
318
321
  i = eatArray(i, m[1], args);
322
+ } else if (checkAllAliases(m[1], flags.nargs)) {
323
+ // nargs format = '--f=monkey washing cat'
324
+ args.splice(i + 1, 0, m[2]);
325
+ i = eatNargs(i, m[1], args);
319
326
  } else {
320
327
  setArg(m[1], m[2]);
321
328
  }
@@ -329,13 +336,13 @@ function parse (args, opts) {
329
336
  )) {
330
337
  key = arg.match(/^--?(.+)/)[1];
331
338
 
332
- // nargs format = '--foo a b c'
333
- // should be truthy even if: flags.nargs[key] === 0
334
- if (checkAllAliases(key, flags.nargs) !== false) {
335
- i = eatNargs(i, key, args);
336
- // array format = '--foo a b c'
337
- } else if (checkAllAliases(key, flags.arrays)) {
339
+ if (checkAllAliases(key, flags.arrays)) {
340
+ // array format = '--foo a b c'
338
341
  i = eatArray(i, key, args);
342
+ } else if (checkAllAliases(key, flags.nargs) !== false) {
343
+ // nargs format = '--foo a b c'
344
+ // should be truthy even if: flags.nargs[key] === 0
345
+ i = eatNargs(i, key, args);
339
346
  } else {
340
347
  next = args[i + 1];
341
348
 
@@ -375,21 +382,21 @@ function parse (args, opts) {
375
382
  letters = arg.slice(1, -1).split('');
376
383
  broken = false;
377
384
 
378
- for (var j = 0; j < letters.length; j++) {
385
+ for (let j = 0; j < letters.length; j++) {
379
386
  next = arg.slice(j + 2);
380
387
 
381
388
  if (letters[j + 1] && letters[j + 1] === '=') {
382
389
  value = arg.slice(j + 3);
383
390
  key = letters[j];
384
391
 
385
- // nargs format = '-f=monkey washing cat'
386
- if (checkAllAliases(key, flags.nargs)) {
387
- args.splice(i + 1, 0, value);
388
- i = eatNargs(i, key, args);
389
- // array format = '-f=a b c'
390
- } else if (checkAllAliases(key, flags.arrays)) {
392
+ if (checkAllAliases(key, flags.arrays)) {
393
+ // array format = '-f=a b c'
391
394
  args.splice(i + 1, 0, value);
392
395
  i = eatArray(i, key, args);
396
+ } else if (checkAllAliases(key, flags.nargs)) {
397
+ // nargs format = '-f=monkey washing cat'
398
+ args.splice(i + 1, 0, value);
399
+ i = eatNargs(i, key, args);
393
400
  } else {
394
401
  setArg(key, value);
395
402
  }
@@ -423,13 +430,13 @@ function parse (args, opts) {
423
430
  key = arg.slice(-1)[0];
424
431
 
425
432
  if (!broken && key !== '-') {
426
- // nargs format = '-f a b c'
427
- // should be truthy even if: flags.nargs[key] === 0
428
- if (checkAllAliases(key, flags.nargs) !== false) {
429
- i = eatNargs(i, key, args);
430
- // array format = '-f a b c'
431
- } else if (checkAllAliases(key, flags.arrays)) {
433
+ if (checkAllAliases(key, flags.arrays)) {
434
+ // array format = '-f a b c'
432
435
  i = eatArray(i, key, args);
436
+ } else if (checkAllAliases(key, flags.nargs) !== false) {
437
+ // nargs format = '-f a b c'
438
+ // should be truthy even if: flags.nargs[key] === 0
439
+ i = eatNargs(i, key, args);
433
440
  } else {
434
441
  next = args[i + 1];
435
442
 
@@ -447,6 +454,12 @@ function parse (args, opts) {
447
454
  }
448
455
  }
449
456
  }
457
+ } else if (arg.match(/^-[0-9]$/) &&
458
+ arg.match(negative) &&
459
+ checkAllAliases(arg.slice(1), flags.bools)) {
460
+ // single-digit boolean alias, e.g: xargs -0
461
+ key = arg.slice(1);
462
+ setArg(key, defaultValue(key));
450
463
  } else if (arg === '--') {
451
464
  notFlags = args.slice(i + 1);
452
465
  break
@@ -502,24 +515,32 @@ function parse (args, opts) {
502
515
  // how many arguments should we consume, based
503
516
  // on the nargs option?
504
517
  function eatNargs (i, key, args) {
505
- var ii;
506
- const toEat = checkAllAliases(key, flags.nargs);
518
+ let ii;
519
+ let toEat = checkAllAliases(key, flags.nargs);
520
+ // NaN has a special meaning for the array type, indicating that one or
521
+ // more values are expected.
522
+ toEat = isNaN(toEat) ? 1 : toEat;
507
523
 
508
524
  if (toEat === 0) {
509
525
  setArg(key, defaultValue(key));
510
526
  return i
511
527
  }
512
528
 
513
- // nargs will not consume flag arguments, e.g., -abc, --foo,
514
- // and terminates when one is observed.
515
- var available = 0;
516
- for (ii = i + 1; ii < args.length; ii++) {
517
- if (!args[ii].match(/^-[^0-9]/) || args[ii].match(negative) || isUnknownOptionAsArg(args[ii])) available++;
518
- else break
529
+ let available = 0;
530
+ if (configuration['nargs-eats-options']) {
531
+ // classic behavior, yargs eats positional and dash arguments.
532
+ if (args.length - (i + 1) < toEat) error = Error(__('Not enough arguments following: %s', key));
533
+ available = toEat;
534
+ } else {
535
+ // nargs will not consume flag arguments, e.g., -abc, --foo,
536
+ // and terminates when one is observed.
537
+ for (ii = i + 1; ii < args.length; ii++) {
538
+ if (!args[ii].match(/^-[^0-9]/) || args[ii].match(negative) || isUnknownOptionAsArg(args[ii])) available++;
539
+ else break
540
+ }
541
+ if (available < toEat) error = Error(__('Not enough arguments following: %s', key));
519
542
  }
520
543
 
521
- if (available < toEat) error = Error(__('Not enough arguments following: %s', key));
522
-
523
544
  const consumed = Math.min(available, toEat);
524
545
  for (ii = i + 1; ii < (consumed + i + 1); ii++) {
525
546
  setArg(key, args[ii]);
@@ -534,40 +555,51 @@ function parse (args, opts) {
534
555
  function eatArray (i, key, args) {
535
556
  let argsToSet = [];
536
557
  let next = args[i + 1];
558
+ // If both array and nargs are configured, enforce the nargs count:
559
+ const nargsCount = checkAllAliases(key, flags.nargs);
537
560
 
538
561
  if (checkAllAliases(key, flags.bools) && !(/^(true|false)$/.test(next))) {
539
562
  argsToSet.push(true);
540
563
  } else if (isUndefined(next) || (/^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next))) {
541
564
  // for keys without value ==> argsToSet remains an empty []
542
565
  // set user default value, if available
543
- if (defaults.hasOwnProperty(key)) {
566
+ if (defaults[key] !== undefined) {
544
567
  const defVal = defaults[key];
545
568
  argsToSet = Array.isArray(defVal) ? defVal : [defVal];
546
569
  }
547
570
  } else {
548
- for (var ii = i + 1; ii < args.length; ii++) {
571
+ for (let ii = i + 1; ii < args.length; ii++) {
549
572
  next = args[ii];
550
573
  if (/^-/.test(next) && !negative.test(next) && !isUnknownOptionAsArg(next)) break
551
574
  i = ii;
552
575
  argsToSet.push(processValue(key, next));
576
+ if (!configuration['greedy-arrays'] ||
577
+ (nargsCount && argsToSet.length >= nargsCount)) break
553
578
  }
554
579
  }
555
580
 
581
+ // If both array and nargs are configured, create an error if less than
582
+ // nargs positionals were found. NaN has special meaning, indicating
583
+ // that at least one value is required (more are okay).
584
+ if ((nargsCount && argsToSet.length < nargsCount) ||
585
+ (isNaN(nargsCount) && argsToSet.length === 0)) {
586
+ error = Error(__('Not enough arguments following: %s', key));
587
+ }
588
+
556
589
  setArg(key, argsToSet);
557
590
  return i
558
591
  }
559
592
 
560
593
  function setArg (key, val) {
561
594
  if (/-/.test(key) && configuration['camel-case-expansion']) {
562
- var alias = key.split('.').map(function (prop) {
595
+ const alias = key.split('.').map(function (prop) {
563
596
  return camelcase(prop)
564
597
  }).join('.');
565
598
  addNewAlias(key, alias);
566
599
  }
567
600
 
568
- var value = processValue(key, val);
569
-
570
- var splitKey = key.split('.');
601
+ const value = processValue(key, val);
602
+ const splitKey = key.split('.');
571
603
  setKey(argv, splitKey, value);
572
604
 
573
605
  // handle populating aliases of the full key
@@ -584,7 +616,7 @@ function parse (args, opts) {
584
616
  x = x.split('.');
585
617
 
586
618
  // expand alias with nested objects in key
587
- var a = [].concat(splitKey);
619
+ const a = [].concat(splitKey);
588
620
  a.shift(); // nuke the old key.
589
621
  x = x.concat(a);
590
622
 
@@ -594,14 +626,16 @@ function parse (args, opts) {
594
626
 
595
627
  // Set normalize getter and setter when key is in 'normalize' but isn't an array
596
628
  if (checkAllAliases(key, flags.normalize) && !checkAllAliases(key, flags.arrays)) {
597
- var keys = [key].concat(flags.aliases[key] || []);
629
+ const keys = [key].concat(flags.aliases[key] || []);
598
630
  keys.forEach(function (key) {
599
- argv.__defineSetter__(key, function (v) {
600
- val = _events_commonjsExternal.sysPath.normalize(v);
601
- });
602
-
603
- argv.__defineGetter__(key, function () {
604
- return typeof val === 'string' ? _events_commonjsExternal.sysPath.normalize(val) : val
631
+ Object.defineProperty(argvReturn, key, {
632
+ enumerable: true,
633
+ get () {
634
+ return val
635
+ },
636
+ set (value) {
637
+ val = typeof value === 'string' ? _events_commonjsExternal.sysPath.normalize(value) : value;
638
+ }
605
639
  });
606
640
  });
607
641
  }
@@ -631,7 +665,7 @@ function parse (args, opts) {
631
665
  if (typeof val === 'string') val = val === 'true';
632
666
  }
633
667
 
634
- var value = Array.isArray(val)
668
+ let value = Array.isArray(val)
635
669
  ? val.map(function (v) { return maybeCoerceNumber(key, v) })
636
670
  : maybeCoerceNumber(key, val);
637
671
 
@@ -661,18 +695,18 @@ function parse (args, opts) {
661
695
  // set args from config.json file, this should be
662
696
  // applied last so that defaults can be applied.
663
697
  function setConfig (argv) {
664
- var configLookup = {};
698
+ const configLookup = Object.create(null);
665
699
 
666
700
  // expand defaults/aliases, in-case any happen to reference
667
701
  // the config.json file.
668
702
  applyDefaultsAndAliases(configLookup, flags.aliases, defaults);
669
703
 
670
704
  Object.keys(flags.configs).forEach(function (configKey) {
671
- var configPath = argv[configKey] || configLookup[configKey];
705
+ const configPath = argv[configKey] || configLookup[configKey];
672
706
  if (configPath) {
673
707
  try {
674
- var config = null;
675
- var resolvedConfigPath = _events_commonjsExternal.sysPath.resolve(process.cwd(), configPath);
708
+ let config = null;
709
+ const resolvedConfigPath = _events_commonjsExternal.sysPath.resolve(process.cwd(), configPath);
676
710
 
677
711
  if (typeof flags.configs[configKey] === 'function') {
678
712
  try {
@@ -700,8 +734,8 @@ function parse (args, opts) {
700
734
  // it recursively checks nested objects.
701
735
  function setConfigObject (config, prev) {
702
736
  Object.keys(config).forEach(function (key) {
703
- var value = config[key];
704
- var fullKey = prev ? prev + '.' + key : key;
737
+ const value = config[key];
738
+ const fullKey = prev ? prev + '.' + key : key;
705
739
 
706
740
  // if the value is an inner object and we have dot-notation
707
741
  // enabled, treat inner objects in config the same as
@@ -730,11 +764,11 @@ function parse (args, opts) {
730
764
  function applyEnvVars (argv, configOnly) {
731
765
  if (typeof envPrefix === 'undefined') return
732
766
 
733
- var prefix = typeof envPrefix === 'string' ? envPrefix : '';
767
+ const prefix = typeof envPrefix === 'string' ? envPrefix : '';
734
768
  Object.keys(process.env).forEach(function (envVar) {
735
769
  if (prefix === '' || envVar.lastIndexOf(prefix, 0) === 0) {
736
770
  // get array of nested keys and convert them to camel case
737
- var keys = envVar.split('__').map(function (key, i) {
771
+ const keys = envVar.split('__').map(function (key, i) {
738
772
  if (i === 0) {
739
773
  key = key.substring(prefix.length);
740
774
  }
@@ -749,16 +783,17 @@ function parse (args, opts) {
749
783
  }
750
784
 
751
785
  function applyCoercions (argv) {
752
- var coerce;
753
- var applied = {};
786
+ let coerce;
787
+ const applied = new Set();
754
788
  Object.keys(argv).forEach(function (key) {
755
- if (!applied.hasOwnProperty(key)) { // If we haven't already coerced this option via one of its aliases
789
+ if (!applied.has(key)) { // If we haven't already coerced this option via one of its aliases
756
790
  coerce = checkAllAliases(key, flags.coercions);
757
791
  if (typeof coerce === 'function') {
758
792
  try {
759
- var value = maybeCoerceNumber(key, coerce(argv[key]))
793
+ const value = maybeCoerceNumber(key, coerce(argv[key]))
760
794
  ;([].concat(flags.aliases[key] || [], key)).forEach(ali => {
761
- applied[ali] = argv[ali] = value;
795
+ applied.add(ali);
796
+ argv[ali] = value;
762
797
  });
763
798
  } catch (err) {
764
799
  error = err;
@@ -792,7 +827,7 @@ function parse (args, opts) {
792
827
  }
793
828
 
794
829
  function hasKey (obj, keys) {
795
- var o = obj;
830
+ let o = obj;
796
831
 
797
832
  if (!configuration['dot-notation']) keys = [keys.join('.')];
798
833
 
@@ -800,18 +835,22 @@ function parse (args, opts) {
800
835
  o = (o[key] || {});
801
836
  });
802
837
 
803
- var key = keys[keys.length - 1];
838
+ const key = keys[keys.length - 1];
804
839
 
805
840
  if (typeof o !== 'object') return false
806
841
  else return key in o
807
842
  }
808
843
 
809
844
  function setKey (obj, keys, value) {
810
- var o = obj;
845
+ let o = obj;
811
846
 
812
847
  if (!configuration['dot-notation']) keys = [keys.join('.')];
813
848
 
814
849
  keys.slice(0, -1).forEach(function (key, index) {
850
+ // TODO(bcoe): in the next major version of yargs, switch to
851
+ // Object.create(null) for dot notation:
852
+ key = sanitizeKey(key);
853
+
815
854
  if (typeof o === 'object' && o[key] === undefined) {
816
855
  o[key] = {};
817
856
  }
@@ -831,11 +870,13 @@ function parse (args, opts) {
831
870
  }
832
871
  });
833
872
 
834
- var key = keys[keys.length - 1];
873
+ // TODO(bcoe): in the next major version of yargs, switch to
874
+ // Object.create(null) for dot notation:
875
+ const key = sanitizeKey(keys[keys.length - 1]);
835
876
 
836
- var isTypeArray = checkAllAliases(keys.join('.'), flags.arrays);
837
- var isValueArray = Array.isArray(value);
838
- var duplicate = configuration['duplicate-arguments-array'];
877
+ const isTypeArray = checkAllAliases(keys.join('.'), flags.arrays);
878
+ const isValueArray = Array.isArray(value);
879
+ let duplicate = configuration['duplicate-arguments-array'];
839
880
 
840
881
  // nargs has higher priority than duplicate
841
882
  if (!duplicate && checkAllAliases(key, flags.nargs)) {
@@ -857,8 +898,12 @@ function parse (args, opts) {
857
898
  }
858
899
  } else if (o[key] === undefined && isTypeArray) {
859
900
  o[key] = isValueArray ? value : [value];
860
- } else if (duplicate && !(o[key] === undefined || checkAllAliases(key, flags.counts))) {
861
- o[key] = [ o[key], value ];
901
+ } else if (duplicate && !(
902
+ o[key] === undefined ||
903
+ checkAllAliases(key, flags.counts) ||
904
+ checkAllAliases(key, flags.bools)
905
+ )) {
906
+ o[key] = [o[key], value];
862
907
  } else {
863
908
  o[key] = value;
864
909
  }
@@ -877,7 +922,7 @@ function parse (args, opts) {
877
922
  // For "--option-name", also set argv.optionName
878
923
  flags.aliases[key].concat(key).forEach(function (x) {
879
924
  if (/-/.test(x) && configuration['camel-case-expansion']) {
880
- var c = camelcase(x);
925
+ const c = camelcase(x);
881
926
  if (c !== key && flags.aliases[key].indexOf(c) === -1) {
882
927
  flags.aliases[key].push(c);
883
928
  newAliases[c] = true;
@@ -887,7 +932,7 @@ function parse (args, opts) {
887
932
  // For "--optionName", also set argv['option-name']
888
933
  flags.aliases[key].concat(key).forEach(function (x) {
889
934
  if (x.length > 1 && /[A-Z]/.test(x) && configuration['camel-case-expansion']) {
890
- var c = decamelize(x, '-');
935
+ const c = decamelize(x, '-');
891
936
  if (c !== key && flags.aliases[key].indexOf(c) === -1) {
892
937
  flags.aliases[key].push(c);
893
938
  newAliases[c] = true;
@@ -905,24 +950,23 @@ function parse (args, opts) {
905
950
 
906
951
  // return the 1st set flag for any of a key's aliases (or false if no flag set)
907
952
  function checkAllAliases (key, flag) {
908
- var toCheck = [].concat(flags.aliases[key] || [], key);
909
- let setAlias = toCheck.find(key => flag.hasOwnProperty(key));
953
+ const toCheck = [].concat(flags.aliases[key] || [], key);
954
+ const keys = Object.keys(flag);
955
+ const setAlias = toCheck.find(key => keys.includes(key));
910
956
  return setAlias ? flag[setAlias] : false
911
957
  }
912
958
 
913
959
  function hasAnyFlag (key) {
914
- // XXX Switch to [].concat(...Object.values(flags)) once node.js 6 is dropped
915
- var toCheck = [].concat(...Object.keys(flags).map(k => flags[k]));
916
-
960
+ const toCheck = [].concat(Object.keys(flags).map(k => flags[k]));
917
961
  return toCheck.some(function (flag) {
918
- return flag[key]
962
+ return Array.isArray(flag) ? flag.includes(key) : flag[key]
919
963
  })
920
964
  }
921
965
 
922
966
  function hasFlagsMatching (arg, ...patterns) {
923
- var toCheck = [].concat(...patterns);
967
+ const toCheck = [].concat(...patterns);
924
968
  return toCheck.some(function (pattern) {
925
- var match = arg.match(pattern);
969
+ const match = arg.match(pattern);
926
970
  return match && hasAnyFlag(match[1])
927
971
  })
928
972
  }
@@ -931,10 +975,10 @@ function parse (args, opts) {
931
975
  function hasAllShortFlags (arg) {
932
976
  // if this is a negative number, or doesn't start with a single hyphen, it's not a short flag group
933
977
  if (arg.match(negative) || !arg.match(/^-[^-]+/)) { return false }
934
- var hasAllFlags = true;
935
- var letters = arg.slice(1).split('');
936
- var next;
937
- for (var j = 0; j < letters.length; j++) {
978
+ let hasAllFlags = true;
979
+ let next;
980
+ const letters = arg.slice(1).split('');
981
+ for (let j = 0; j < letters.length; j++) {
938
982
  next = arg.slice(j + 2);
939
983
 
940
984
  if (!hasAnyFlag(letters[j])) {
@@ -968,7 +1012,7 @@ function parse (args, opts) {
968
1012
  // e.g. '-a-'
969
1013
  const flagEndingInHyphen = /^-+([^=]+?)-$/;
970
1014
  // e.g. '-abc123'
971
- const flagEndingInDigits = /^-+([^=]+?)\d+$/;
1015
+ const flagEndingInDigits = /^-+([^=]+?\d+)$/;
972
1016
  // e.g. '-a/usr/local'
973
1017
  const flagEndingInNonWordCharacters = /^-+([^=]+?)\W+.*$/;
974
1018
  // check the different types of flag styles, including negatedBoolean, a pattern defined near the start of the parse method
@@ -990,7 +1034,7 @@ function parse (args, opts) {
990
1034
  // return a default value, given the type of a flag.,
991
1035
  // e.g., key of type 'string' will default to '', rather than 'true'.
992
1036
  function defaultForType (type) {
993
- var def = {
1037
+ const def = {
994
1038
  boolean: true,
995
1039
  string: '',
996
1040
  number: undefined,
@@ -1002,13 +1046,11 @@ function parse (args, opts) {
1002
1046
 
1003
1047
  // given a flag, enforce a default type.
1004
1048
  function guessType (key) {
1005
- var type = 'boolean';
1006
-
1049
+ let type = 'boolean';
1007
1050
  if (checkAllAliases(key, flags.strings)) type = 'string';
1008
1051
  else if (checkAllAliases(key, flags.numbers)) type = 'number';
1009
1052
  else if (checkAllAliases(key, flags.bools)) type = 'boolean';
1010
1053
  else if (checkAllAliases(key, flags.arrays)) type = 'array';
1011
-
1012
1054
  return type
1013
1055
  }
1014
1056
 
@@ -1042,11 +1084,11 @@ function parse (args, opts) {
1042
1084
  }
1043
1085
 
1044
1086
  return {
1045
- argv: argv,
1087
+ argv: Object.assign(argvReturn, argv),
1046
1088
  error: error,
1047
- aliases: flags.aliases,
1048
- newAliases: newAliases,
1049
- defaulted: defaulted,
1089
+ aliases: Object.assign({}, flags.aliases),
1090
+ newAliases: Object.assign({}, newAliases),
1091
+ defaulted: Object.assign({}, defaulted),
1050
1092
  configuration: configuration
1051
1093
  }
1052
1094
  }
@@ -1054,9 +1096,9 @@ function parse (args, opts) {
1054
1096
  // if any aliases reference each other, we should
1055
1097
  // merge them together.
1056
1098
  function combineAliases (aliases) {
1057
- var aliasArrays = [];
1058
- var change = true;
1059
- var combined = {};
1099
+ const aliasArrays = [];
1100
+ const combined = Object.create(null);
1101
+ let change = true;
1060
1102
 
1061
1103
  // turn alias lookup hash {key: ['alias1', 'alias2']} into
1062
1104
  // a simple array ['key', 'alias1', 'alias2']
@@ -1070,9 +1112,9 @@ function combineAliases (aliases) {
1070
1112
  // made in an iteration.
1071
1113
  while (change) {
1072
1114
  change = false;
1073
- for (var i = 0; i < aliasArrays.length; i++) {
1074
- for (var ii = i + 1; ii < aliasArrays.length; ii++) {
1075
- var intersect = aliasArrays[i].filter(function (v) {
1115
+ for (let i = 0; i < aliasArrays.length; i++) {
1116
+ for (let ii = i + 1; ii < aliasArrays.length; ii++) {
1117
+ const intersect = aliasArrays[i].filter(function (v) {
1076
1118
  return aliasArrays[ii].indexOf(v) !== -1
1077
1119
  });
1078
1120
 
@@ -1106,8 +1148,7 @@ function increment (orig) {
1106
1148
  }
1107
1149
 
1108
1150
  function Parser (args, opts) {
1109
- var result = parse(args.slice(), opts);
1110
-
1151
+ const result = parse(args.slice(), opts);
1111
1152
  return result.argv
1112
1153
  }
1113
1154
 
@@ -1117,6 +1158,13 @@ Parser.detailed = function (args, opts) {
1117
1158
  return parse(args.slice(), opts)
1118
1159
  };
1119
1160
 
1161
+ // TODO(bcoe): in the next major version of yargs, switch to
1162
+ // Object.create(null) for dot notation:
1163
+ function sanitizeKey (key) {
1164
+ if (key === '__proto__') return '___proto___'
1165
+ return key
1166
+ }
1167
+
1120
1168
  var yargsParser = Parser;
1121
1169
 
1122
1170
  var modules = {};