prettier 1.15.2 → 1.15.3

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
@@ -6,6 +6,7 @@ var stream = _interopDefault(require('stream'));
6
6
  var os = _interopDefault(require('os'));
7
7
  var path = _interopDefault(require('path'));
8
8
  var util = _interopDefault(require('util'));
9
+ var module$1 = _interopDefault(require('module'));
9
10
  var fs = _interopDefault(require('fs'));
10
11
 
11
12
  function commonjsRequire () {
@@ -396,17 +397,25 @@ var errorEx = function errorEx(name, properties) {
396
397
  message = v;
397
398
  }
398
399
  });
400
+ var overwrittenStack = null;
399
401
  var stackDescriptor = Object.getOwnPropertyDescriptor(this, 'stack');
400
402
  var stackGetter = stackDescriptor.get;
401
403
  var stackValue = stackDescriptor.value;
402
404
  delete stackDescriptor.value;
403
405
  delete stackDescriptor.writable;
404
406
 
407
+ stackDescriptor.set = function (newstack) {
408
+ overwrittenStack = newstack;
409
+ };
410
+
405
411
  stackDescriptor.get = function () {
406
- var stack = stackGetter ? stackGetter.call(this).split(/\r?\n+/g) : stackValue.split(/\r?\n+/g); // starting in Node 7, the stack builder caches the message.
412
+ var stack = (overwrittenStack || (stackGetter ? stackGetter.call(this) : stackValue)).split(/\r?\n+/g); // starting in Node 7, the stack builder caches the message.
407
413
  // just replace it.
408
414
 
409
- stack[0] = this.name + ': ' + this.message;
415
+ if (!overwrittenStack) {
416
+ stack[0] = this.name + ': ' + this.message;
417
+ }
418
+
410
419
  var lineCount = 1;
411
420
 
412
421
  for (var key in properties) {
@@ -1107,17 +1116,19 @@ var int_1 = new type('tag:yaml.org,2002:int', {
1107
1116
  construct: constructYamlInteger,
1108
1117
  predicate: isInteger,
1109
1118
  represent: {
1110
- binary: function binary(object) {
1111
- return '0b' + object.toString(2);
1119
+ binary: function binary(obj) {
1120
+ return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1);
1112
1121
  },
1113
- octal: function octal(object) {
1114
- return '0' + object.toString(8);
1122
+ octal: function octal(obj) {
1123
+ return obj >= 0 ? '0' + obj.toString(8) : '-0' + obj.toString(8).slice(1);
1115
1124
  },
1116
- decimal: function decimal(object) {
1117
- return object.toString(10);
1125
+ decimal: function decimal(obj) {
1126
+ return obj.toString(10);
1118
1127
  },
1119
- hexadecimal: function hexadecimal(object) {
1120
- return '0x' + object.toString(16).toUpperCase();
1128
+
1129
+ /* eslint-disable max-len */
1130
+ hexadecimal: function hexadecimal(obj) {
1131
+ return obj >= 0 ? '0x' + obj.toString(16).toUpperCase() : '-0x' + obj.toString(16).toUpperCase().slice(1);
1121
1132
  }
1122
1133
  },
1123
1134
  defaultStyle: 'decimal',
@@ -1710,7 +1721,7 @@ function resolveJavascriptFunction(data) {
1710
1721
  range: true
1711
1722
  });
1712
1723
 
1713
- if (ast.type !== 'Program' || ast.body.length !== 1 || ast.body[0].type !== 'ExpressionStatement' || ast.body[0].expression.type !== 'FunctionExpression') {
1724
+ if (ast.type !== 'Program' || ast.body.length !== 1 || ast.body[0].type !== 'ExpressionStatement' || ast.body[0].expression.type !== 'ArrowFunctionExpression' && ast.body[0].expression.type !== 'FunctionExpression') {
1714
1725
  return false;
1715
1726
  }
1716
1727
 
@@ -1729,7 +1740,7 @@ function constructJavascriptFunction(data) {
1729
1740
  params = [],
1730
1741
  body;
1731
1742
 
1732
- if (ast.type !== 'Program' || ast.body.length !== 1 || ast.body[0].type !== 'ExpressionStatement' || ast.body[0].expression.type !== 'FunctionExpression') {
1743
+ if (ast.type !== 'Program' || ast.body.length !== 1 || ast.body[0].type !== 'ExpressionStatement' || ast.body[0].expression.type !== 'ArrowFunctionExpression' && ast.body[0].expression.type !== 'FunctionExpression') {
1733
1744
  throw new Error('Failed to resolve function');
1734
1745
  }
1735
1746
 
@@ -1739,9 +1750,16 @@ function constructJavascriptFunction(data) {
1739
1750
  body = ast.body[0].expression.body.range; // Esprima's ranges include the first '{' and the last '}' characters on
1740
1751
  // function expressions. So cut them out.
1741
1752
 
1753
+ if (ast.body[0].expression.body.type === 'BlockStatement') {
1754
+ /*eslint-disable no-new-func*/
1755
+ return new Function(params, source.slice(body[0] + 1, body[1] - 1));
1756
+ } // ES6 arrow functions can omit the BlockStatement. In that case, just return
1757
+ // the body.
1758
+
1742
1759
  /*eslint-disable no-new-func*/
1743
1760
 
1744
- return new Function(params, source.slice(body[0] + 1, body[1] - 1));
1761
+
1762
+ return new Function(params, 'return ' + source.slice(body[0], body[1]));
1745
1763
  }
1746
1764
 
1747
1765
  function representJavascriptFunction(object
@@ -3677,6 +3695,12 @@ function isPlainSafeFirst(c) {
3677
3695
  && c !== CHAR_MINUS && c !== CHAR_QUESTION && c !== CHAR_COLON && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET // | “#” | “&” | “*” | “!” | “|” | “>” | “'” | “"”
3678
3696
  && c !== CHAR_SHARP && c !== CHAR_AMPERSAND && c !== CHAR_ASTERISK && c !== CHAR_EXCLAMATION && c !== CHAR_VERTICAL_LINE && c !== CHAR_GREATER_THAN && c !== CHAR_SINGLE_QUOTE && c !== CHAR_DOUBLE_QUOTE // | “%” | “@” | “`”)
3679
3697
  && c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT;
3698
+ } // Determines whether block indentation indicator is required.
3699
+
3700
+
3701
+ function needIndentIndicator(string) {
3702
+ var leadingSpaceRe = /^\n* /;
3703
+ return leadingSpaceRe.test(string);
3680
3704
  }
3681
3705
 
3682
3706
  var STYLE_PLAIN = 1;
@@ -3748,7 +3772,7 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te
3748
3772
  } // Edge case: block indentation indicator can only have one digit.
3749
3773
 
3750
3774
 
3751
- if (string[0] === ' ' && indentPerLevel > 9) {
3775
+ if (indentPerLevel > 9 && needIndentIndicator(string)) {
3752
3776
  return STYLE_DOUBLE;
3753
3777
  } // At this point we know block styles are valid.
3754
3778
  // Prefer literal style unless we want to fold.
@@ -3815,7 +3839,7 @@ function writeScalar(state, string, level, iskey) {
3815
3839
 
3816
3840
 
3817
3841
  function blockHeader(string, indentPerLevel) {
3818
- var indentIndicator = string[0] === ' ' ? String(indentPerLevel) : ''; // note the special case: the string '\n' counts as a "trailing" empty line.
3842
+ var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : ''; // note the special case: the string '\n' counts as a "trailing" empty line.
3819
3843
 
3820
3844
  var clip = string[string.length - 1] === '\n';
3821
3845
  var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
@@ -4324,9 +4348,118 @@ var jsYaml$2 = {
4324
4348
 
4325
4349
  var jsYaml = jsYaml$2;
4326
4350
 
4327
- function loadJs(filepath) {
4328
- var result = require(filepath);
4351
+ var resolveFrom_1 = createCommonjsModule(function (module) {
4352
+ 'use strict';
4353
+
4354
+ var resolveFrom = function resolveFrom(fromDir, moduleId, silent) {
4355
+ if (typeof fromDir !== 'string') {
4356
+ throw new TypeError(`Expected \`fromDir\` to be of type \`string\`, got \`${typeof fromDir}\``);
4357
+ }
4358
+
4359
+ if (typeof moduleId !== 'string') {
4360
+ throw new TypeError(`Expected \`moduleId\` to be of type \`string\`, got \`${typeof moduleId}\``);
4361
+ }
4362
+
4363
+ fromDir = path.resolve(fromDir);
4364
+ var fromFile = path.join(fromDir, 'noop.js');
4365
+
4366
+ var resolveFileName = function resolveFileName() {
4367
+ return module$1._resolveFilename(moduleId, {
4368
+ id: fromFile,
4369
+ filename: fromFile,
4370
+ paths: module$1._nodeModulePaths(fromDir)
4371
+ });
4372
+ };
4373
+
4374
+ if (silent) {
4375
+ try {
4376
+ return resolveFileName();
4377
+ } catch (err) {
4378
+ return null;
4379
+ }
4380
+ }
4381
+
4382
+ return resolveFileName();
4383
+ };
4384
+
4385
+ module.exports = function (fromDir, moduleId) {
4386
+ return resolveFrom(fromDir, moduleId);
4387
+ };
4388
+
4389
+ module.exports.silent = function (fromDir, moduleId) {
4390
+ return resolveFrom(fromDir, moduleId, true);
4391
+ };
4392
+ });
4393
+
4394
+ var callsites = createCommonjsModule(function (module) {
4395
+ 'use strict';
4329
4396
 
4397
+ module.exports = function () {
4398
+ var _ = Error.prepareStackTrace;
4399
+
4400
+ Error.prepareStackTrace = function (_, stack) {
4401
+ return stack;
4402
+ };
4403
+
4404
+ var stack = new Error().stack.slice(1);
4405
+ Error.prepareStackTrace = _;
4406
+ return stack;
4407
+ };
4408
+ });
4409
+
4410
+ var callerCallsite = createCommonjsModule(function (module) {
4411
+ 'use strict';
4412
+
4413
+ module.exports = function () {
4414
+ var c = callsites();
4415
+ var caller;
4416
+
4417
+ for (var i = 0; i < c.length; i++) {
4418
+ var hasReceiver = c[i].getTypeName() !== null;
4419
+
4420
+ if (hasReceiver) {
4421
+ caller = i;
4422
+ break;
4423
+ }
4424
+ }
4425
+
4426
+ return c[caller];
4427
+ };
4428
+ });
4429
+
4430
+ var callerPath = function callerPath() {
4431
+ return callerCallsite().getFileName();
4432
+ };
4433
+
4434
+ var importFresh = createCommonjsModule(function (module) {
4435
+ 'use strict';
4436
+
4437
+ module.exports = function (moduleId) {
4438
+ if (typeof moduleId !== 'string') {
4439
+ throw new TypeError('Expected a string');
4440
+ }
4441
+
4442
+ var filePath = resolveFrom_1(path.dirname(callerPath()), moduleId); // Delete itself from module parent
4443
+
4444
+ if (require.cache[filePath] && require.cache[filePath].parent) {
4445
+ var i = require.cache[filePath].parent.children.length;
4446
+
4447
+ while (i--) {
4448
+ if (require.cache[filePath].parent.children[i].id === filePath) {
4449
+ require.cache[filePath].parent.children.splice(i, 1);
4450
+ }
4451
+ }
4452
+ } // Delete module from cache
4453
+
4454
+
4455
+ delete require.cache[filePath]; // Return fresh module
4456
+
4457
+ return require(filePath);
4458
+ };
4459
+ });
4460
+
4461
+ function loadJs(filepath) {
4462
+ var result = importFresh(filepath);
4330
4463
  return result;
4331
4464
  }
4332
4465