prettier 1.17.0 → 1.18.2

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/third-party.js CHANGED
@@ -1682,6 +1682,10 @@ var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
1682
1682
  var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
1683
1683
  var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
1684
1684
 
1685
+ function _class(obj) {
1686
+ return Object.prototype.toString.call(obj);
1687
+ }
1688
+
1685
1689
  function is_EOL(c) {
1686
1690
  return c === 0x0A
1687
1691
  /* LF */
@@ -1985,7 +1989,31 @@ function mergeMappings(state, destination, source, overridableKeys) {
1985
1989
  }
1986
1990
 
1987
1991
  function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) {
1988
- var index, quantity;
1992
+ var index, quantity; // The output is a plain object here, so keys can only be strings.
1993
+ // We need to convert keyNode to a string, but doing so can hang the process
1994
+ // (deeply nested arrays that explode exponentially using aliases).
1995
+
1996
+ if (Array.isArray(keyNode)) {
1997
+ keyNode = Array.prototype.slice.call(keyNode);
1998
+
1999
+ for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
2000
+ if (Array.isArray(keyNode[index])) {
2001
+ throwError(state, 'nested arrays are not supported inside keys');
2002
+ }
2003
+
2004
+ if (typeof keyNode === 'object' && _class(keyNode[index]) === '[object Object]') {
2005
+ keyNode[index] = '[object Object]';
2006
+ }
2007
+ }
2008
+ } // Avoid code execution in load() via toString property
2009
+ // (still use its own toString for arrays, timestamps,
2010
+ // and whatever user schema extensions happen to have @@toStringTag)
2011
+
2012
+
2013
+ if (typeof keyNode === 'object' && _class(keyNode) === '[object Object]') {
2014
+ keyNode = '[object Object]';
2015
+ }
2016
+
1989
2017
  keyNode = String(keyNode);
1990
2018
 
1991
2019
  if (_result === null) {
@@ -3480,6 +3508,7 @@ function encodeHex(character) {
3480
3508
  function State$1(options) {
3481
3509
  this.schema = options['schema'] || default_full;
3482
3510
  this.indent = Math.max(1, options['indent'] || 2);
3511
+ this.noArrayIndent = options['noArrayIndent'] || false;
3483
3512
  this.skipInvalid = options['skipInvalid'] || false;
3484
3513
  this.flowLevel = common.isNothing(options['flowLevel']) ? -1 : options['flowLevel'];
3485
3514
  this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
@@ -4080,14 +4109,16 @@ function writeNode(state, level, object, block, compact, iskey) {
4080
4109
  }
4081
4110
  }
4082
4111
  } else if (type === '[object Array]') {
4112
+ var arrayLevel = state.noArrayIndent && level > 0 ? level - 1 : level;
4113
+
4083
4114
  if (block && state.dump.length !== 0) {
4084
- writeBlockSequence(state, level, state.dump, compact);
4115
+ writeBlockSequence(state, arrayLevel, state.dump, compact);
4085
4116
 
4086
4117
  if (duplicate) {
4087
4118
  state.dump = '&ref_' + duplicateIndex + state.dump;
4088
4119
  }
4089
4120
  } else {
4090
- writeFlowSequence(state, level, state.dump);
4121
+ writeFlowSequence(state, arrayLevel, state.dump);
4091
4122
 
4092
4123
  if (duplicate) {
4093
4124
  state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;