prettier 1.14.3 → 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 () {
@@ -160,6 +161,191 @@ function _createClass(Constructor, protoProps, staticProps) {
160
161
  return Constructor;
161
162
  }
162
163
 
164
+ function _toArray(arr) {
165
+ return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest();
166
+ }
167
+
168
+ function _arrayWithHoles(arr) {
169
+ if (Array.isArray(arr)) return arr;
170
+ }
171
+
172
+ function _iterableToArray(iter) {
173
+ if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
174
+ }
175
+
176
+ function _nonIterableRest() {
177
+ throw new TypeError("Invalid attempt to destructure non-iterable instance");
178
+ }
179
+
180
+ function _toPrimitive(input, hint) {
181
+ if (typeof input !== "object" || input === null) return input;
182
+ var prim = input[Symbol.toPrimitive];
183
+
184
+ if (prim !== undefined) {
185
+ var res = prim.call(input, hint || "default");
186
+ if (typeof res !== "object") return res;
187
+ throw new TypeError("@@toPrimitive must return a primitive value.");
188
+ }
189
+
190
+ return (hint === "string" ? String : Number)(input);
191
+ }
192
+
193
+ function _toPropertyKey(arg) {
194
+ var key = _toPrimitive(arg, "string");
195
+
196
+ return typeof key === "symbol" ? key : String(key);
197
+ }
198
+
199
+ function _addElementPlacement(element, placements, silent) {
200
+ var keys = placements[element.placement];
201
+
202
+ if (!silent && keys.indexOf(element.key) !== -1) {
203
+ throw new TypeError("Duplicated element (" + element.key + ")");
204
+ }
205
+
206
+ keys.push(element.key);
207
+ }
208
+
209
+ function _fromElementDescriptor(element) {
210
+ var obj = {
211
+ kind: element.kind,
212
+ key: element.key,
213
+ placement: element.placement,
214
+ descriptor: element.descriptor
215
+ };
216
+ var desc = {
217
+ value: "Descriptor",
218
+ configurable: true
219
+ };
220
+ Object.defineProperty(obj, Symbol.toStringTag, desc);
221
+ if (element.kind === "field") obj.initializer = element.initializer;
222
+ return obj;
223
+ }
224
+
225
+ function _toElementDescriptors(elementObjects) {
226
+ if (elementObjects === undefined) return;
227
+ return _toArray(elementObjects).map(function (elementObject) {
228
+ var element = _toElementDescriptor(elementObject);
229
+
230
+ _disallowProperty(elementObject, "finisher", "An element descriptor");
231
+
232
+ _disallowProperty(elementObject, "extras", "An element descriptor");
233
+
234
+ return element;
235
+ });
236
+ }
237
+
238
+ function _toElementDescriptor(elementObject) {
239
+ var kind = String(elementObject.kind);
240
+
241
+ if (kind !== "method" && kind !== "field") {
242
+ throw new TypeError('An element descriptor\'s .kind property must be either "method" or' + ' "field", but a decorator created an element descriptor with' + ' .kind "' + kind + '"');
243
+ }
244
+
245
+ var key = _toPropertyKey(elementObject.key);
246
+
247
+ var placement = String(elementObject.placement);
248
+
249
+ if (placement !== "static" && placement !== "prototype" && placement !== "own") {
250
+ throw new TypeError('An element descriptor\'s .placement property must be one of "static",' + ' "prototype" or "own", but a decorator created an element descriptor' + ' with .placement "' + placement + '"');
251
+ }
252
+
253
+ var descriptor = elementObject.descriptor;
254
+
255
+ _disallowProperty(elementObject, "elements", "An element descriptor");
256
+
257
+ var element = {
258
+ kind: kind,
259
+ key: key,
260
+ placement: placement,
261
+ descriptor: Object.assign({}, descriptor)
262
+ };
263
+
264
+ if (kind !== "field") {
265
+ _disallowProperty(elementObject, "initializer", "A method descriptor");
266
+ } else {
267
+ _disallowProperty(descriptor, "get", "The property descriptor of a field descriptor");
268
+
269
+ _disallowProperty(descriptor, "set", "The property descriptor of a field descriptor");
270
+
271
+ _disallowProperty(descriptor, "value", "The property descriptor of a field descriptor");
272
+
273
+ element.initializer = elementObject.initializer;
274
+ }
275
+
276
+ return element;
277
+ }
278
+
279
+ function _toElementFinisherExtras(elementObject) {
280
+ var element = _toElementDescriptor(elementObject);
281
+
282
+ var finisher = _optionalCallableProperty(elementObject, "finisher");
283
+
284
+ var extras = _toElementDescriptors(elementObject.extras);
285
+
286
+ return {
287
+ element: element,
288
+ finisher: finisher,
289
+ extras: extras
290
+ };
291
+ }
292
+
293
+ function _fromClassDescriptor(elements) {
294
+ var obj = {
295
+ kind: "class",
296
+ elements: elements.map(_fromElementDescriptor)
297
+ };
298
+ var desc = {
299
+ value: "Descriptor",
300
+ configurable: true
301
+ };
302
+ Object.defineProperty(obj, Symbol.toStringTag, desc);
303
+ return obj;
304
+ }
305
+
306
+ function _toClassDescriptor(obj) {
307
+ var kind = String(obj.kind);
308
+
309
+ if (kind !== "class") {
310
+ throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator' + ' created a class descriptor with .kind "' + kind + '"');
311
+ }
312
+
313
+ _disallowProperty(obj, "key", "A class descriptor");
314
+
315
+ _disallowProperty(obj, "placement", "A class descriptor");
316
+
317
+ _disallowProperty(obj, "descriptor", "A class descriptor");
318
+
319
+ _disallowProperty(obj, "initializer", "A class descriptor");
320
+
321
+ _disallowProperty(obj, "extras", "A class descriptor");
322
+
323
+ var finisher = _optionalCallableProperty(obj, "finisher");
324
+
325
+ var elements = _toElementDescriptors(obj.elements);
326
+
327
+ return {
328
+ elements: elements,
329
+ finisher: finisher
330
+ };
331
+ }
332
+
333
+ function _disallowProperty(obj, name, objectType) {
334
+ if (obj[name] !== undefined) {
335
+ throw new TypeError(objectType + " can't have a ." + name + " property.");
336
+ }
337
+ }
338
+
339
+ function _optionalCallableProperty(obj, name) {
340
+ var value = obj[name];
341
+
342
+ if (value !== undefined && typeof value !== "function") {
343
+ throw new TypeError("Expected '" + name + "' to be a function");
344
+ }
345
+
346
+ return value;
347
+ }
348
+
163
349
  var isArrayish = function isArrayish(obj) {
164
350
  if (!obj) {
165
351
  return false;
@@ -211,17 +397,25 @@ var errorEx = function errorEx(name, properties) {
211
397
  message = v;
212
398
  }
213
399
  });
400
+ var overwrittenStack = null;
214
401
  var stackDescriptor = Object.getOwnPropertyDescriptor(this, 'stack');
215
402
  var stackGetter = stackDescriptor.get;
216
403
  var stackValue = stackDescriptor.value;
217
404
  delete stackDescriptor.value;
218
405
  delete stackDescriptor.writable;
219
406
 
407
+ stackDescriptor.set = function (newstack) {
408
+ overwrittenStack = newstack;
409
+ };
410
+
220
411
  stackDescriptor.get = function () {
221
- 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.
222
413
  // just replace it.
223
414
 
224
- stack[0] = this.name + ': ' + this.message;
415
+ if (!overwrittenStack) {
416
+ stack[0] = this.name + ': ' + this.message;
417
+ }
418
+
225
419
  var lineCount = 1;
226
420
 
227
421
  for (var key in properties) {
@@ -922,17 +1116,19 @@ var int_1 = new type('tag:yaml.org,2002:int', {
922
1116
  construct: constructYamlInteger,
923
1117
  predicate: isInteger,
924
1118
  represent: {
925
- binary: function binary(object) {
926
- return '0b' + object.toString(2);
1119
+ binary: function binary(obj) {
1120
+ return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1);
927
1121
  },
928
- octal: function octal(object) {
929
- return '0' + object.toString(8);
1122
+ octal: function octal(obj) {
1123
+ return obj >= 0 ? '0' + obj.toString(8) : '-0' + obj.toString(8).slice(1);
930
1124
  },
931
- decimal: function decimal(object) {
932
- return object.toString(10);
1125
+ decimal: function decimal(obj) {
1126
+ return obj.toString(10);
933
1127
  },
934
- hexadecimal: function hexadecimal(object) {
935
- 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);
936
1132
  }
937
1133
  },
938
1134
  defaultStyle: 'decimal',
@@ -1525,7 +1721,7 @@ function resolveJavascriptFunction(data) {
1525
1721
  range: true
1526
1722
  });
1527
1723
 
1528
- 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') {
1529
1725
  return false;
1530
1726
  }
1531
1727
 
@@ -1544,7 +1740,7 @@ function constructJavascriptFunction(data) {
1544
1740
  params = [],
1545
1741
  body;
1546
1742
 
1547
- 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') {
1548
1744
  throw new Error('Failed to resolve function');
1549
1745
  }
1550
1746
 
@@ -1554,9 +1750,16 @@ function constructJavascriptFunction(data) {
1554
1750
  body = ast.body[0].expression.body.range; // Esprima's ranges include the first '{' and the last '}' characters on
1555
1751
  // function expressions. So cut them out.
1556
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
+
1557
1759
  /*eslint-disable no-new-func*/
1558
1760
 
1559
- 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]));
1560
1763
  }
1561
1764
 
1562
1765
  function representJavascriptFunction(object
@@ -3492,6 +3695,12 @@ function isPlainSafeFirst(c) {
3492
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 // | “#” | “&” | “*” | “!” | “|” | “>” | “'” | “"”
3493
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 // | “%” | “@” | “`”)
3494
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);
3495
3704
  }
3496
3705
 
3497
3706
  var STYLE_PLAIN = 1;
@@ -3563,7 +3772,7 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te
3563
3772
  } // Edge case: block indentation indicator can only have one digit.
3564
3773
 
3565
3774
 
3566
- if (string[0] === ' ' && indentPerLevel > 9) {
3775
+ if (indentPerLevel > 9 && needIndentIndicator(string)) {
3567
3776
  return STYLE_DOUBLE;
3568
3777
  } // At this point we know block styles are valid.
3569
3778
  // Prefer literal style unless we want to fold.
@@ -3630,7 +3839,7 @@ function writeScalar(state, string, level, iskey) {
3630
3839
 
3631
3840
 
3632
3841
  function blockHeader(string, indentPerLevel) {
3633
- 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.
3634
3843
 
3635
3844
  var clip = string[string.length - 1] === '\n';
3636
3845
  var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
@@ -4139,9 +4348,118 @@ var jsYaml$2 = {
4139
4348
 
4140
4349
  var jsYaml = jsYaml$2;
4141
4350
 
4142
- function loadJs(filepath) {
4143
- 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
+ };
4144
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';
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);
4145
4463
  return result;
4146
4464
  }
4147
4465
 
@@ -4525,7 +4843,7 @@ function () {
4525
4843
  }
4526
4844
 
4527
4845
  var loaderKey = path.extname(filepath) || 'noExt';
4528
- return this.config.loaders[loaderKey];
4846
+ return this.config.loaders[loaderKey] || {};
4529
4847
  }
4530
4848
  }, {
4531
4849
  key: "getSyncLoaderForFile",