Izmjenjena struktura, dodan backand

This commit is contained in:
GotPPay
2017-10-16 11:19:46 +02:00
parent 1ec88afacb
commit 048e32c4aa
37153 changed files with 2975854 additions and 1 deletions

View File

@@ -0,0 +1,69 @@
import _regeneratorRuntime from 'babel-runtime/regenerator';
var _this = this;
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { extractSourceMapUrl } from '../utils/getSourceMap';
test('extracts last source map directive', _asyncToGenerator(_regeneratorRuntime.mark(function _callee() {
var res;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return extractSourceMapUrl('test.js', '//# sourceMappingURL=test.js.map\nconsole.log(\'a\')\n//# sourceMappingURL=bundle.js.map');
case 2:
res = _context.sent;
expect(res).toBe('bundle.js.map');
case 4:
case 'end':
return _context.stop();
}
}
}, _callee, _this);
})));
test('errors when no source map', _asyncToGenerator(_regeneratorRuntime.mark(function _callee2() {
var testFileName;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
expect.assertions(1);
testFileName = 'test.js';
_context2.prev = 2;
_context2.next = 5;
return extractSourceMapUrl(testFileName, 'console.log(\'hi\')\n\nconsole.log(\'bye\')');
case 5:
_context2.next = 10;
break;
case 7:
_context2.prev = 7;
_context2.t0 = _context2['catch'](2);
expect(_context2.t0).toBe('Cannot find a source map directive for ' + testFileName + '.');
case 10:
case 'end':
return _context2.stop();
}
}
}, _callee2, _this, [[2, 7]]);
})));

View File

@@ -0,0 +1,110 @@
import _regeneratorRuntime from 'babel-runtime/regenerator';
var _this = this;
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { getSourceMap } from '../utils/getSourceMap';
import fs from 'fs';
import { resolve } from 'path';
test('finds an external source map', _asyncToGenerator(_regeneratorRuntime.mark(function _callee() {
var file, sm;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
file = fs.readFileSync(resolve(__dirname, '../../fixtures/bundle.mjs')).toString('utf8');
fetch.mockResponseOnce(fs.readFileSync(resolve(__dirname, '../../fixtures/bundle.mjs.map')).toString('utf8'));
_context.next = 4;
return getSourceMap('/', file);
case 4:
sm = _context.sent;
expect(sm.getOriginalPosition(26122, 21)).toEqual({
line: 7,
column: 0,
source: 'webpack:///packages/react-scripts/template/src/App.js'
});
case 6:
case 'end':
return _context.stop();
}
}
}, _callee, _this);
})));
test('find an inline source map', _asyncToGenerator(_regeneratorRuntime.mark(function _callee2() {
var sourceName, file, fileO, sm;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
sourceName = 'test.js';
file = fs.readFileSync(resolve(__dirname, '../../fixtures/inline.mjs')).toString('utf8');
fileO = fs.readFileSync(resolve(__dirname, '../../fixtures/inline.es6.mjs')).toString('utf8');
_context2.next = 5;
return getSourceMap('/', file);
case 5:
sm = _context2.sent;
expect(sm.getSources()).toEqual([sourceName]);
expect(sm.getSource(sourceName)).toBe(fileO);
expect(sm.getGeneratedPosition(sourceName, 5, 10)).toEqual({
line: 10,
column: 8
});
case 9:
case 'end':
return _context2.stop();
}
}
}, _callee2, _this);
})));
test('error on a source map with unsupported encoding', _asyncToGenerator(_regeneratorRuntime.mark(function _callee3() {
var file;
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
expect.assertions(2);
file = fs.readFileSync(resolve(__dirname, '../../fixtures/junk-inline.mjs')).toString('utf8');
_context3.prev = 2;
_context3.next = 5;
return getSourceMap('/', file);
case 5:
_context3.next = 11;
break;
case 7:
_context3.prev = 7;
_context3.t0 = _context3['catch'](2);
expect(_context3.t0 instanceof Error).toBe(true);
expect(_context3.t0.message).toBe('Sorry, non-base64 inline source-map encoding is not supported.');
case 11:
case 'end':
return _context3.stop();
}
}
}, _callee3, _this, [[2, 7]]);
})));

View File

@@ -0,0 +1,20 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { getLinesAround } from '../utils/getLinesAround';
var arr = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight'];
test('should return lines around from a string', function () {
expect(getLinesAround(4, 2, arr)).toMatchSnapshot();
});
test('should return lines around from an array', function () {
expect(getLinesAround(4, 2, arr.join('\n'))).toMatchSnapshot();
});

View File

@@ -0,0 +1,113 @@
import _regeneratorRuntime from 'babel-runtime/regenerator';
var _this = this;
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { map } from '../utils/mapper';
import { parse } from '../utils/parser';
import fs from 'fs';
import { resolve } from 'path';
test('basic error; 0 context', _asyncToGenerator(_regeneratorRuntime.mark(function _callee() {
var error, frames;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
expect.assertions(1);
error = 'TypeError: document.body.missing is not a function\n at App.componentDidMount (http://localhost:3000/static/js/bundle.js:26122:21)\n at http://localhost:3000/static/js/bundle.js:30091:25\n at measureLifeCyclePerf (http://localhost:3000/static/js/bundle.js:29901:12)\n at http://localhost:3000/static/js/bundle.js:30090:11\n at CallbackQueue.notifyAll (http://localhost:3000/static/js/bundle.js:13256:22)\n at ReactReconcileTransaction.close (http://localhost:3000/static/js/bundle.js:35124:26)\n at ReactReconcileTransaction.closeAll (http://localhost:3000/static/js/bundle.js:7390:25)\n at ReactReconcileTransaction.perform (http://localhost:3000/static/js/bundle.js:7337:16)\n at batchedMountComponentIntoNode (http://localhost:3000/static/js/bundle.js:14204:15)\n at ReactDefaultBatchingStrategyTransaction.perform (http://localhost:3000/static/js/bundle.js:7324:20)\n at Object.batchedUpdates (http://localhost:3000/static/js/bundle.js:33900:26)\n at Object.batchedUpdates (http://localhost:3000/static/js/bundle.js:2181:27)\n at Object._renderNewRootComponent (http://localhost:3000/static/js/bundle.js:14398:18)\n at Object._renderSubtreeIntoContainer (http://localhost:3000/static/js/bundle.js:14479:32)\n at Object.render (http://localhost:3000/static/js/bundle.js:14500:23)\n at Object.friendlySyntaxErrorLabel (http://localhost:3000/static/js/bundle.js:17287:20)\n at __webpack_require__ (http://localhost:3000/static/js/bundle.js:660:30)\n at fn (http://localhost:3000/static/js/bundle.js:84:20)\n at Object.<anonymous> (http://localhost:3000/static/js/bundle.js:41219:18)\n at __webpack_require__ (http://localhost:3000/static/js/bundle.js:660:30)\n at validateFormat (http://localhost:3000/static/js/bundle.js:709:39)\n at http://localhost:3000/static/js/bundle.js:712:10';
fetch.mockResponseOnce(fs.readFileSync(resolve(__dirname, '../../fixtures/bundle.mjs')).toString('utf8'));
fetch.mockResponseOnce(fs.readFileSync(resolve(__dirname, '../../fixtures/bundle.mjs.map')).toString('utf8'));
_context.next = 6;
return map(parse(error), 0);
case 6:
frames = _context.sent;
expect(frames).toEqual(JSON.parse(fs.readFileSync(resolve(__dirname, '../../fixtures/bundle.json')).toString('utf8')));
case 8:
case 'end':
return _context.stop();
}
}
}, _callee, _this);
})));
test('default context (3)', _asyncToGenerator(_regeneratorRuntime.mark(function _callee2() {
var error, frames;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
expect.assertions(1);
error = 'TypeError: document.body.missing is not a function\n at App.componentDidMount (http://localhost:3000/static/js/bundle.js:26122:21)';
fetch.mockResponseOnce(fs.readFileSync(resolve(__dirname, '../../fixtures/bundle.mjs')).toString('utf8'));
fetch.mockResponseOnce(fs.readFileSync(resolve(__dirname, '../../fixtures/bundle.mjs.map')).toString('utf8'));
_context2.next = 6;
return map(parse(error));
case 6:
frames = _context2.sent;
expect(frames).toEqual(JSON.parse(fs.readFileSync(resolve(__dirname, '../../fixtures/bundle-default.json')).toString('utf8')));
case 8:
case 'end':
return _context2.stop();
}
}
}, _callee2, _this);
})));
test('bad comes back same', _asyncToGenerator(_regeneratorRuntime.mark(function _callee3() {
var error, orig, frames;
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
expect.assertions(2);
error = 'TypeError: document.body.missing is not a function\n at App.componentDidMount (A:1:2)';
orig = parse(error);
expect(orig).toEqual([{
_originalColumnNumber: null,
_originalFileName: null,
_originalFunctionName: null,
_originalLineNumber: null,
_originalScriptCode: null,
_scriptCode: null,
columnNumber: 2,
fileName: 'A',
functionName: 'App.componentDidMount',
lineNumber: 1
}]);
_context3.next = 6;
return map(orig);
case 6:
frames = _context3.sent;
expect(frames).toEqual(orig);
case 8:
case 'end':
return _context3.stop();
}
}
}, _callee3, _this);
})));

View File

@@ -0,0 +1,14 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { parse } from '../../utils/parser';
test('stack with eval', function () {
expect(parse('TypeError: window[f] is not a function\n at e (file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:25:18)\n at eval (eval at c (file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:12:9), <anonymous>:1:1)\n at a (file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:8:9)\n at file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:32:7')).toMatchSnapshot();
});

View File

@@ -0,0 +1,32 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { parse } from '../../utils/parser';
test('eval 1', function () {
expect(parse('test1@file:///C:/example.html line 7 > eval line 1 > eval:1:1\ntest2@file:///C:/example.html line 7 > eval:1:1\ntest3@file:///C:/example.html:7:6'.split('\n'))).toMatchSnapshot();
});
test('eval 2', function () {
expect(parse({
stack: 'anonymous@file:///C:/example.html line 7 > Function:1:1\n@file:///C:/example.html:7:6'
})).toMatchSnapshot();
});
test('stack with eval', function () {
expect(parse('e@file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:25:9\n@file:///Users/joe/Documents/Development/OSS/stack-frame/index.html line 17 > eval:1:1\na@file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:8:9\n@file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:32:7')).toMatchSnapshot();
});
test('v14 to v29', function () {
expect(parse('trace@file:///C:/example.html:9\nb@file:///C:/example.html:16\na@file:///C:/example.html:19\n@file:///C:/example.html:21')).toMatchSnapshot();
});
test('v30+', function () {
expect(parse('trace@file:///C:/example.html:9:17\nb@file:///C:/example.html:16:13\na@file:///C:/example.html:19:13\n@file:///C:/example.html:21:9')).toMatchSnapshot();
});

View File

@@ -0,0 +1,30 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { parse } from '../../utils/parser';
test('throws on null', function () {
expect.assertions(2);
try {
parse(null);
} catch (e) {
expect(e instanceof Error).toBe(true);
expect(e.message).toBe('You cannot pass a null object.');
}
});
test('throws on unparsable', function () {
expect.assertions(2);
try {
parse({});
} catch (e) {
expect(e instanceof Error).toBe(true);
expect(e.message).toBe('The error you provided does not contain a stack trace.');
}
});

View File

@@ -0,0 +1,14 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { parse } from '../../utils/parser';
test('15.y.z', function () {
expect(parse('Warning: Each child in array should have a unique "key" prop. Check render method of `FileA`.\n in div (at FileA.js:9)\n in FileA (at App.js:9)\n in div (at App.js:8)\n in App (at index.js:7)')).toMatchSnapshot();
});

View File

@@ -0,0 +1,14 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { parse } from '../../utils/parser';
test('stack with eval', function () {
expect(parse('e@file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:25:18\neval code\neval@[native code]\na@file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:8:10\nglobal code@file:///Users/joe/Documents/Development/OSS/stack-frame/index.html:32:8')).toMatchSnapshot();
});

View File

@@ -0,0 +1,18 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { ScriptLine } from '../utils/stack-frame';
test('script line shape', function () {
expect(new ScriptLine(5, 'foobar', true)).toMatchSnapshot();
});
test('script line to provide default highlight', function () {
expect(new ScriptLine(5, 'foobar')).toMatchSnapshot();
});

View File

@@ -0,0 +1,10 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
global.fetch = require('jest-fetch-mock');

View File

@@ -0,0 +1,28 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { StackFrame } from '../utils/stack-frame';
test('proper empty shape', function () {
var empty = new StackFrame();
expect(empty).toMatchSnapshot();
expect(empty.getFunctionName()).toBe(null);
expect(empty.getSource()).toBe('');
expect(empty.toString()).toBe('');
});
test('proper full shape', function () {
var empty = new StackFrame('a', 'b.js', 13, 37, undefined, 'apple', 'test.js', 37, 13);
expect(empty).toMatchSnapshot();
expect(empty.getFunctionName()).toBe('a');
expect(empty.getSource()).toBe('b.js:13:37');
expect(empty.toString()).toBe('a (b.js:13:37)');
});

View File

@@ -0,0 +1,87 @@
import _regeneratorRuntime from 'babel-runtime/regenerator';
var _this = this;
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { unmap } from '../utils/unmapper';
import { parse } from '../utils/parser';
import fs from 'fs';
import { resolve } from 'path';
test('basic warning', _asyncToGenerator(_regeneratorRuntime.mark(function _callee() {
var error, frames, expected;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
expect.assertions(2);
error = 'Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `B`. See https://fb.me/react-warning-keys for more information.\n in div (at B.js:8)\n in B (at A.js:6)\n in A (at App.js:8)\n in div (at App.js:10)\n in App (at index.js:6)';
fetch.mockResponseOnce(fs.readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs')).toString('utf8'));
fetch.mockResponseOnce(fs.readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs.map')).toString('utf8'));
_context.next = 6;
return unmap('/static/js/bundle.js', parse(error), 0);
case 6:
frames = _context.sent;
expected = JSON.parse(fs.readFileSync(resolve(__dirname, '../../fixtures/bundle2.json')).toString('utf8'));
expect(frames).toEqual(expected);
fetch.mockResponseOnce(fs.readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs')).toString('utf8'));
fetch.mockResponseOnce(fs.readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs.map')).toString('utf8'));
_context.t0 = expect;
_context.next = 14;
return unmap('/static/js/bundle.js', expected);
case 14:
_context.t1 = _context.sent;
_context.t2 = expected;
(0, _context.t0)(_context.t1).toEqual(_context.t2);
case 17:
case 'end':
return _context.stop();
}
}
}, _callee, _this);
})));
test('default context & unfound source', _asyncToGenerator(_regeneratorRuntime.mark(function _callee2() {
var error, frames;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
expect.assertions(1);
error = 'Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `B`. See https://fb.me/react-warning-keys for more information.\n in div (at B.js:8)\n in unknown (at blabla.js:10)';
fetch.mockResponseOnce(fs.readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs')).toString('utf8'));
fetch.mockResponseOnce(fs.readFileSync(resolve(__dirname, '../../fixtures/bundle_u.mjs.map')).toString('utf8'));
_context2.next = 6;
return unmap('/static/js/bundle.js', parse(error));
case 6:
frames = _context2.sent;
expect(frames).toMatchSnapshot();
case 8:
case 'end':
return _context2.stop();
}
}
}, _callee2, _this);
})));

View File

@@ -0,0 +1,58 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { applyStyles } from '../utils/dom/css';
import { additionalChildStyle, groupStyle, groupElemLeft, groupElemRight } from '../styles';
import { consumeEvent } from '../utils/dom/consumeEvent';
import { enableTabClick } from '../utils/dom/enableTabClick';
function updateAdditional(document, additionalReference, currentError, totalErrors, switchCallback) {
if (additionalReference.lastChild) {
additionalReference.removeChild(additionalReference.lastChild);
}
if (totalErrors <= 1) {
return;
}
var div = document.createElement('div');
applyStyles(div, additionalChildStyle);
var group = document.createElement('span');
applyStyles(group, groupStyle);
var left = document.createElement('button');
applyStyles(left, groupElemLeft);
left.addEventListener('click', function (e) {
consumeEvent(e);
switchCallback(-1);
});
left.appendChild(document.createTextNode('←'));
enableTabClick(left);
var right = document.createElement('button');
applyStyles(right, groupElemRight);
right.addEventListener('click', function (e) {
consumeEvent(e);
switchCallback(1);
});
right.appendChild(document.createTextNode('→'));
enableTabClick(right);
group.appendChild(left);
group.appendChild(right);
div.appendChild(group);
var text = currentError + ' of ' + totalErrors + ' errors on the page';
div.appendChild(document.createTextNode(text));
additionalReference.appendChild(div);
}
export { updateAdditional };

View File

@@ -0,0 +1,34 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { applyStyles } from '../utils/dom/css';
import { hintsStyle, hintStyle, closeButtonStyle } from '../styles';
function createHint(document, hint, title) {
var span = document.createElement('span');
span.appendChild(document.createTextNode(hint));
span.setAttribute('title', title);
applyStyles(span, hintStyle);
return span;
}
function createClose(document, callback) {
var hints = document.createElement('div');
applyStyles(hints, hintsStyle);
var close = createHint(document, '×', 'Click or press Escape to dismiss.');
close.addEventListener('click', function () {
return callback();
});
applyStyles(close, closeButtonStyle);
hints.appendChild(close);
return hints;
}
export { createClose };

View File

@@ -0,0 +1,90 @@
import { applyStyles } from '../utils/dom/css'; /**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { absolutifyCaret } from '../utils/dom/absolutifyCaret';
import { codeStyle, primaryErrorStyle, primaryPreStyle, secondaryErrorStyle, secondaryPreStyle } from '../styles';
import generateAnsiHtml from 'react-dev-utils/ansiHTML';
import codeFrame from 'babel-code-frame';
function createCode(document, sourceLines, lineNum, columnNum, contextSize, main, onSourceClick) {
var sourceCode = [];
var whiteSpace = Infinity;
sourceLines.forEach(function (e) {
var text = e.content;
var m = text.match(/^\s*/);
if (text === '') {
return;
}
if (m && m[0]) {
whiteSpace = Math.min(whiteSpace, m[0].length);
} else {
whiteSpace = 0;
}
});
sourceLines.forEach(function (e) {
var text = e.content;
var line = e.lineNumber;
if (isFinite(whiteSpace)) {
text = text.substring(whiteSpace);
}
sourceCode[line - 1] = text;
});
var ansiHighlight = codeFrame(sourceCode.join('\n'), lineNum, columnNum == null ? 0 : columnNum - (isFinite(whiteSpace) ? whiteSpace : 0), {
forceColor: true,
linesAbove: contextSize,
linesBelow: contextSize
});
var htmlHighlight = generateAnsiHtml(ansiHighlight);
var code = document.createElement('code');
code.innerHTML = htmlHighlight;
absolutifyCaret(code);
applyStyles(code, codeStyle);
var ccn = code.childNodes;
// eslint-disable-next-line
oLoop: for (var index = 0; index < ccn.length; ++index) {
var node = ccn[index];
var ccn2 = node.childNodes;
for (var index2 = 0; index2 < ccn2.length; ++index2) {
var lineNode = ccn2[index2];
var text = lineNode.innerText;
if (text == null) {
continue;
}
if (text.indexOf(' ' + lineNum + ' |') === -1) {
continue;
}
// $FlowFixMe
applyStyles(node, main ? primaryErrorStyle : secondaryErrorStyle);
// eslint-disable-next-line
break oLoop;
}
}
var pre = document.createElement('pre');
applyStyles(pre, main ? primaryPreStyle : secondaryPreStyle);
pre.appendChild(code);
if (typeof onSourceClick === 'function') {
var handler = onSourceClick;
pre.style.cursor = 'pointer';
pre.addEventListener('click', function () {
handler();
});
}
return pre;
}
export { createCode };

View File

@@ -0,0 +1,22 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { applyStyles } from '../utils/dom/css';
import { footerStyle } from '../styles';
function createFooter(document) {
var div = document.createElement('div');
applyStyles(div, footerStyle);
div.appendChild(document.createTextNode('This screen is visible only in development. It will not appear if the app crashes in production.'));
div.appendChild(document.createElement('br'));
div.appendChild(document.createTextNode('Open your browsers developer console to further inspect this error.'));
return div;
}
export { createFooter };

View File

@@ -0,0 +1,241 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { enableTabClick } from '../utils/dom/enableTabClick';
import { createCode } from './code';
import { isInternalFile } from '../utils/isInternalFile';
import { applyStyles } from '../utils/dom/css';
import { omittedFramesExpandedStyle, omittedFramesCollapsedStyle, functionNameStyle, depStyle, linkStyle, anchorStyle, hiddenStyle } from '../styles';
function getGroupToggle(document, omitsCount, omitBundle) {
var omittedFrames = document.createElement('div');
enableTabClick(omittedFrames);
var text1 = document.createTextNode('\u25B6 ' + omitsCount + ' stack frames were collapsed.');
omittedFrames.appendChild(text1);
omittedFrames.addEventListener('click', function () {
var hide = text1.textContent.match(/▲/);
var list = document.getElementsByName('bundle-' + omitBundle);
for (var index = 0; index < list.length; ++index) {
var n = list[index];
if (hide) {
n.style.display = 'none';
} else {
n.style.display = '';
}
}
if (hide) {
text1.textContent = text1.textContent.replace(/▲/, '▶');
text1.textContent = text1.textContent.replace(/expanded/, 'collapsed');
applyStyles(omittedFrames, omittedFramesCollapsedStyle);
} else {
text1.textContent = text1.textContent.replace(/▶/, '▲');
text1.textContent = text1.textContent.replace(/collapsed/, 'expanded');
applyStyles(omittedFrames, omittedFramesExpandedStyle);
}
});
applyStyles(omittedFrames, omittedFramesCollapsedStyle);
return omittedFrames;
}
function insertBeforeBundle(document, parent, omitsCount, omitBundle, actionElement) {
var children = document.getElementsByName('bundle-' + omitBundle);
if (children.length < 1) {
return;
}
var first = children[0];
while (first != null && first.parentNode !== parent) {
first = first.parentNode;
}
var div = document.createElement('div');
enableTabClick(div);
div.setAttribute('name', 'bundle-' + omitBundle);
var text = document.createTextNode('\u25BC ' + omitsCount + ' stack frames were expanded.');
div.appendChild(text);
div.addEventListener('click', function () {
return actionElement.click();
});
applyStyles(div, omittedFramesExpandedStyle);
div.style.display = 'none';
parent.insertBefore(div, first);
}
function frameDiv(document, functionName, url, internalUrl, onSourceClick) {
var frame = document.createElement('div');
var frameFunctionName = document.createElement('div');
var cleanedFunctionName = void 0;
if (!functionName || functionName === 'Object.<anonymous>') {
cleanedFunctionName = '(anonymous function)';
} else {
cleanedFunctionName = functionName;
}
var cleanedUrl = url.replace('webpack://', '.');
if (internalUrl) {
applyStyles(frameFunctionName, Object.assign({}, functionNameStyle, depStyle));
} else {
applyStyles(frameFunctionName, functionNameStyle);
}
frameFunctionName.appendChild(document.createTextNode(cleanedFunctionName));
frame.appendChild(frameFunctionName);
var frameLink = document.createElement('div');
applyStyles(frameLink, linkStyle);
var frameAnchor = document.createElement('a');
applyStyles(frameAnchor, anchorStyle);
frameAnchor.appendChild(document.createTextNode(cleanedUrl));
frameLink.appendChild(frameAnchor);
frame.appendChild(frameLink);
if (typeof onSourceClick === 'function') {
var handler = onSourceClick;
enableTabClick(frameAnchor);
frameAnchor.style.cursor = 'pointer';
frameAnchor.addEventListener('click', function () {
handler();
});
}
return frame;
}
function isBultinErrorName(errorName) {
switch (errorName) {
case 'EvalError':
case 'InternalError':
case 'RangeError':
case 'ReferenceError':
case 'SyntaxError':
case 'TypeError':
case 'URIError':
return true;
default:
return false;
}
}
function getPrettyURL(sourceFileName, sourceLineNumber, sourceColumnNumber, fileName, lineNumber, columnNumber, compiled) {
var prettyURL = void 0;
if (!compiled && sourceFileName && typeof sourceLineNumber === 'number') {
// Remove everything up to the first /src/ or /node_modules/
var trimMatch = /^[/|\\].*?[/|\\]((src|node_modules)[/|\\].*)/.exec(sourceFileName);
if (trimMatch && trimMatch[1]) {
prettyURL = trimMatch[1];
} else {
prettyURL = sourceFileName;
}
prettyURL += ':' + sourceLineNumber;
// Note: we intentionally skip 0's because they're produced by cheap Webpack maps
if (sourceColumnNumber) {
prettyURL += ':' + sourceColumnNumber;
}
} else if (fileName && typeof lineNumber === 'number') {
prettyURL = fileName + ':' + lineNumber;
// Note: we intentionally skip 0's because they're produced by cheap Webpack maps
if (columnNumber) {
prettyURL += ':' + columnNumber;
}
} else {
prettyURL = 'unknown';
}
return prettyURL;
}
function createFrame(document, frameSetting, frame, contextSize, critical, omits, omitBundle, parentContainer, lastElement, errorName) {
var compiled = frameSetting.compiled;
var functionName = frame.functionName,
sourceFileName = frame._originalFileName;
var fileName = frame.fileName,
lineNumber = frame.lineNumber,
columnNumber = frame.columnNumber,
scriptLines = frame._scriptCode,
sourceLineNumber = frame._originalLineNumber,
sourceColumnNumber = frame._originalColumnNumber,
sourceLines = frame._originalScriptCode;
// TODO: find a better place for this.
// Chrome has a bug with inferring function.name:
// https://github.com/facebookincubator/create-react-app/issues/2097
// Let's ignore a meaningless name we get for top-level modules.
if (functionName === 'Object.friendlySyntaxErrorLabel' || functionName === 'Object.exports.__esModule') {
functionName = '(anonymous function)';
}
var prettyURL = getPrettyURL(sourceFileName, sourceLineNumber, sourceColumnNumber, fileName, lineNumber, columnNumber, compiled);
var needsHidden = false;
var isInternalUrl = isInternalFile(sourceFileName, fileName);
var isThrownIntentionally = !isBultinErrorName(errorName);
var shouldCollapse = isInternalUrl && (isThrownIntentionally || omits.hasReachedAppCode);
if (!isInternalUrl) {
omits.hasReachedAppCode = true;
}
if (shouldCollapse) {
++omits.value;
needsHidden = true;
}
var collapseElement = null;
if (!shouldCollapse || lastElement) {
if (omits.value > 0) {
var capV = omits.value;
var omittedFrames = getGroupToggle(document, capV, omitBundle);
window.requestAnimationFrame(function () {
insertBeforeBundle(document, parentContainer, capV, omitBundle, omittedFrames);
});
if (lastElement && shouldCollapse) {
collapseElement = omittedFrames;
} else {
parentContainer.appendChild(omittedFrames);
}
++omits.bundle;
}
omits.value = 0;
}
var onSourceClick = null;
if (sourceFileName) {
// e.g. "/path-to-my-app/webpack/bootstrap eaddeb46b67d75e4dfc1"
var isInternalWebpackBootstrapCode = sourceFileName.trim().indexOf(' ') !== -1;
if (!isInternalWebpackBootstrapCode) {
onSourceClick = function onSourceClick() {
// Keep this in sync with react-error-overlay/middleware.js
fetch('/__open-stack-frame-in-editor?fileName=' + window.encodeURIComponent(sourceFileName) + '&lineNumber=' + window.encodeURIComponent(sourceLineNumber || 1)).then(function () {}, function () {});
};
}
}
var elem = frameDiv(document, functionName, prettyURL, shouldCollapse, onSourceClick);
if (needsHidden) {
applyStyles(elem, hiddenStyle);
elem.setAttribute('name', 'bundle-' + omitBundle);
}
var hasSource = false;
if (!shouldCollapse) {
if (compiled && scriptLines && scriptLines.length !== 0 && lineNumber != null) {
elem.appendChild(createCode(document, scriptLines, lineNumber, columnNumber, contextSize, critical, onSourceClick));
hasSource = true;
} else if (!compiled && sourceLines && sourceLines.length !== 0 && sourceLineNumber != null) {
elem.appendChild(createCode(document, sourceLines, sourceLineNumber, sourceColumnNumber, contextSize, critical, onSourceClick));
hasSource = true;
}
}
return { elem: elem, hasSource: hasSource, collapseElement: collapseElement };
}
export { createFrame };

View File

@@ -0,0 +1,82 @@
import { applyStyles } from '../utils/dom/css'; /**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { traceStyle, toggleStyle } from '../styles';
import { enableTabClick } from '../utils/dom/enableTabClick';
import { createFrame } from './frame';
function createFrameWrapper(document, parent, factory, lIndex, frameSettings, contextSize) {
var fac = factory();
if (fac == null) {
return;
}
var hasSource = fac.hasSource,
elem = fac.elem,
collapseElement = fac.collapseElement;
var elemWrapper = document.createElement('div');
elemWrapper.appendChild(elem);
if (hasSource) {
var compiledDiv = document.createElement('div');
enableTabClick(compiledDiv);
applyStyles(compiledDiv, toggleStyle);
var o = frameSettings[lIndex];
var compiledText = document.createTextNode('View ' + (o && o.compiled ? 'source' : 'compiled'));
compiledDiv.addEventListener('click', function () {
if (o) {
o.compiled = !o.compiled;
}
var next = createFrameWrapper(document, parent, factory, lIndex, frameSettings, contextSize);
if (next != null) {
parent.insertBefore(next, elemWrapper);
parent.removeChild(elemWrapper);
}
});
compiledDiv.appendChild(compiledText);
elemWrapper.appendChild(compiledDiv);
}
if (collapseElement != null) {
elemWrapper.appendChild(collapseElement);
}
return elemWrapper;
}
function createFrames(document, resolvedFrames, frameSettings, contextSize, errorName) {
if (resolvedFrames.length !== frameSettings.length) {
throw new Error('You must give a frame settings array of identical length to resolved frames.');
}
var trace = document.createElement('div');
applyStyles(trace, traceStyle);
var index = 0;
var critical = true;
var omits = { value: 0, bundle: 1, hasReachedAppCode: false };
resolvedFrames.forEach(function (frame) {
var lIndex = index++;
var elem = createFrameWrapper(document, trace, createFrame.bind(undefined, document, frameSettings[lIndex], frame, contextSize, critical, omits, omits.bundle, trace, index === resolvedFrames.length, errorName), lIndex, frameSettings, contextSize);
if (elem == null) {
return;
}
critical = false;
trace.appendChild(elem);
});
//TODO: fix this
omits.value = 0;
return trace;
}
export { createFrames };

View File

@@ -0,0 +1,71 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { applyStyles } from '../utils/dom/css';
import { containerStyle, overlayStyle, headerStyle } from '../styles';
import { createClose } from './close';
import { createFrames } from './frames';
import { createFooter } from './footer';
import { updateAdditional } from './additional';
function createOverlay(document, name, message, frames, contextSize, currentError, totalErrors, switchCallback, closeCallback) {
var frameSettings = frames.map(function () {
return { compiled: false };
});
// Create overlay
var overlay = document.createElement('div');
applyStyles(overlay, overlayStyle);
// Create container
var container = document.createElement('div');
applyStyles(container, containerStyle);
overlay.appendChild(container);
container.appendChild(createClose(document, closeCallback));
// Create "Errors X of Y" in case of multiple errors
var additional = document.createElement('div');
updateAdditional(document, additional, currentError, totalErrors, switchCallback);
container.appendChild(additional);
// Create header
var header = document.createElement('div');
applyStyles(header, headerStyle);
// Make message prettier
var finalMessage = message.match(/^\w*:/) || !name ? message : name + ': ' + message;
finalMessage = finalMessage
// TODO: maybe remove this prefix from fbjs?
// It's just scaring people
.replace(/^Invariant Violation:\s*/, '')
// This is not helpful either:
.replace(/^Warning:\s*/, '')
// Break the actionable part to the next line.
// AFAIK React 16+ should already do this.
.replace(' Check the render method', '\n\nCheck the render method').replace(' Check your code at', '\n\nCheck your code at');
// Put it in the DOM
header.appendChild(document.createTextNode(finalMessage));
container.appendChild(header);
// Create trace
container.appendChild(createFrames(document, frames, frameSettings, contextSize, name));
// Show message
container.appendChild(createFooter(document));
return {
overlay: overlay,
additional: additional
};
}
export { createOverlay };

View File

@@ -0,0 +1,62 @@
var reactFrameStack = []; /**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
// This is a stripped down barebones version of this proposal:
// https://gist.github.com/sebmarkbage/bdefa100f19345229d526d0fdd22830f
// We're implementing just enough to get the invalid element type warnings
// to display the component stack in React 15.6+:
// https://github.com/facebook/react/pull/9679
/// TODO: a more comprehensive implementation.
var registerReactStack = function registerReactStack() {
if (typeof console !== 'undefined') {
// $FlowFixMe
console.reactStack = function (frames) {
return reactFrameStack.push(frames);
};
// $FlowFixMe
console.reactStackEnd = function (frames) {
return reactFrameStack.pop();
};
}
};
var unregisterReactStack = function unregisterReactStack() {
if (typeof console !== 'undefined') {
// $FlowFixMe
console.reactStack = undefined;
// $FlowFixMe
console.reactStackEnd = undefined;
}
};
var permanentRegister = function proxyConsole(type, callback) {
if (typeof console !== 'undefined') {
var orig = console[type];
if (typeof orig === 'function') {
console[type] = function __stack_frame_overlay_proxy_console__() {
try {
var _message = arguments[0];
if (typeof _message === 'string' && reactFrameStack.length > 0) {
callback(_message, reactFrameStack[reactFrameStack.length - 1]);
}
} catch (err) {
// Warnings must never crash. Rethrow with a clean stack.
setTimeout(function () {
throw err;
});
}
return orig.apply(this, arguments);
};
}
}
};
export { permanentRegister, registerReactStack, unregisterReactStack };

View File

@@ -0,0 +1,46 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var SHORTCUT_ESCAPE = 'SHORTCUT_ESCAPE',
SHORTCUT_LEFT = 'SHORTCUT_LEFT',
SHORTCUT_RIGHT = 'SHORTCUT_RIGHT';
var boundKeyHandler = null;
function keyHandler(callback, e) {
var key = e.key,
keyCode = e.keyCode,
which = e.which;
if (key === 'Escape' || keyCode === 27 || which === 27) {
callback(SHORTCUT_ESCAPE);
} else if (key === 'ArrowLeft' || keyCode === 37 || which === 37) {
callback(SHORTCUT_LEFT);
} else if (key === 'ArrowRight' || keyCode === 39 || which === 39) {
callback(SHORTCUT_RIGHT);
}
}
function registerShortcuts(target, callback) {
if (boundKeyHandler !== null) {
return;
}
boundKeyHandler = keyHandler.bind(undefined, callback);
target.addEventListener('keydown', boundKeyHandler);
}
function unregisterShortcuts(target) {
if (boundKeyHandler === null) {
return;
}
target.removeEventListener('keydown', boundKeyHandler);
boundKeyHandler = null;
}
export { SHORTCUT_ESCAPE, SHORTCUT_LEFT, SHORTCUT_RIGHT, registerShortcuts as register, unregisterShortcuts as unregister, keyHandler as handler };

View File

@@ -0,0 +1,43 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var stackTraceRegistered = false;
// Default: https://docs.microsoft.com/en-us/scripting/javascript/reference/stacktracelimit-property-error-javascript
var restoreStackTraceValue = 10;
var MAX_STACK_LENGTH = 50;
function registerStackTraceLimit() {
var limit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : MAX_STACK_LENGTH;
if (stackTraceRegistered) {
return;
}
try {
restoreStackTraceValue = Error.stackTraceLimit;
Error.stackTraceLimit = limit;
stackTraceRegistered = true;
} catch (e) {
// Not all browsers support this so we don't care if it errors
}
}
function unregisterStackTraceLimit() {
if (!stackTraceRegistered) {
return;
}
try {
Error.stackTraceLimit = restoreStackTraceValue;
stackTraceRegistered = false;
} catch (e) {
// Not all browsers support this so we don't care if it errors
}
}
export { registerStackTraceLimit as register, unregisterStackTraceLimit as unregister };

View File

@@ -0,0 +1,44 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var boundErrorHandler = null;
function errorHandler(callback, e) {
if (!e.error) {
return;
}
// $FlowFixMe
var error = e.error;
if (error instanceof Error) {
callback(error);
} else {
// A non-error was thrown, we don't have a trace. :(
// Look in your browser's devtools for more information
callback(new Error(error));
}
}
function registerUnhandledError(target, callback) {
if (boundErrorHandler !== null) {
return;
}
boundErrorHandler = errorHandler.bind(undefined, callback);
target.addEventListener('error', boundErrorHandler);
}
function unregisterUnhandledError(target) {
if (boundErrorHandler === null) {
return;
}
target.removeEventListener('error', boundErrorHandler);
boundErrorHandler = null;
}
export { registerUnhandledError as register, unregisterUnhandledError as unregister };

View File

@@ -0,0 +1,44 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var boundRejectionHandler = null;
function rejectionHandler(callback, e) {
if (e == null || e.reason == null) {
return callback(new Error('Unknown'));
}
var reason = e.reason;
if (reason instanceof Error) {
return callback(reason);
}
// A non-error was rejected, we don't have a trace :(
// Look in your browser's devtools for more information
return callback(new Error(reason));
}
function registerUnhandledRejection(target, callback) {
if (boundRejectionHandler !== null) {
return;
}
boundRejectionHandler = rejectionHandler.bind(undefined, callback);
// $FlowFixMe
target.addEventListener('unhandledrejection', boundRejectionHandler);
}
function unregisterUnhandledRejection(target) {
if (boundRejectionHandler === null) {
return;
}
// $FlowFixMe
target.removeEventListener('unhandledrejection', boundRejectionHandler);
boundRejectionHandler = null;
}
export { registerUnhandledRejection as register, unregisterUnhandledRejection as unregister };

17
web/node_modules/react-error-overlay/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { inject, uninject } from './overlay';
inject();
if (module.hot && typeof module.hot.dispose === 'function') {
module.hot.dispose(function () {
uninject();
});
}

200
web/node_modules/react-error-overlay/lib/overlay.js generated vendored Normal file
View File

@@ -0,0 +1,200 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { register as registerError, unregister as unregisterError } from './effects/unhandledError';
import { register as registerPromise, unregister as unregisterPromise } from './effects/unhandledRejection';
import { register as registerShortcuts, unregister as unregisterShortcuts, handler as keyEventHandler, SHORTCUT_ESCAPE, SHORTCUT_LEFT, SHORTCUT_RIGHT } from './effects/shortcuts';
import { register as registerStackTraceLimit, unregister as unregisterStackTraceLimit } from './effects/stackTraceLimit';
import { permanentRegister as permanentRegisterConsole, registerReactStack, unregisterReactStack } from './effects/proxyConsole';
import { massage as massageWarning } from './utils/warnings';
import { consume as consumeError, getErrorRecord, drain as drainErrors } from './utils/errorRegister';
import { iframeStyle } from './styles';
import { applyStyles } from './utils/dom/css';
import { createOverlay } from './components/overlay';
import { updateAdditional } from './components/additional';
var CONTEXT_SIZE = 3;
var iframeReference = null;
var additionalReference = null;
var errorReferences = [];
var currReferenceIndex = -1;
function render(name, message, resolvedFrames) {
disposeCurrentView();
var iframe = window.document.createElement('iframe');
applyStyles(iframe, iframeStyle);
iframeReference = iframe;
iframe.onload = function () {
if (iframeReference == null) {
return;
}
var w = iframeReference.contentWindow;
var document = iframeReference.contentDocument;
var _createOverlay = createOverlay(document, name, message, resolvedFrames, CONTEXT_SIZE, currReferenceIndex + 1, errorReferences.length, function (offset) {
switchError(offset);
}, function () {
unmount();
}),
overlay = _createOverlay.overlay,
additional = _createOverlay.additional;
if (w != null) {
w.onkeydown = function (event) {
keyEventHandler(function (type) {
return shortcutHandler(type);
}, event);
};
}
if (document.body != null) {
document.body.style.margin = '0';
// Keep popup within body boundaries for iOS Safari
// $FlowFixMe
document.body.style['max-width'] = '100vw';
document.body.appendChild(overlay);
}
additionalReference = additional;
};
window.document.body.appendChild(iframe);
}
function renderErrorByIndex(index) {
currReferenceIndex = index;
var _getErrorRecord = getErrorRecord(errorReferences[index]),
error = _getErrorRecord.error,
unhandledRejection = _getErrorRecord.unhandledRejection,
enhancedFrames = _getErrorRecord.enhancedFrames;
if (unhandledRejection) {
render('Unhandled Rejection (' + error.name + ')', error.message, enhancedFrames);
} else {
render(error.name, error.message, enhancedFrames);
}
}
function switchError(offset) {
if (errorReferences.length === 0) {
return;
}
var nextView = currReferenceIndex + offset;
if (nextView < 0) {
nextView = errorReferences.length - 1;
} else if (nextView >= errorReferences.length) {
nextView = 0;
}
renderErrorByIndex(nextView);
}
function disposeCurrentView() {
if (iframeReference === null) {
return;
}
window.document.body.removeChild(iframeReference);
iframeReference = null;
additionalReference = null;
}
function unmount() {
disposeCurrentView();
drainErrors();
errorReferences = [];
currReferenceIndex = -1;
}
function crash(error) {
var unhandledRejection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (module.hot && typeof module.hot.decline === 'function') {
module.hot.decline();
}
consumeError(error, unhandledRejection, CONTEXT_SIZE).then(function (ref) {
if (ref == null) {
return;
}
errorReferences.push(ref);
if (iframeReference !== null && additionalReference !== null) {
updateAdditional(iframeReference.contentDocument, additionalReference, currReferenceIndex + 1, errorReferences.length, function (offset) {
switchError(offset);
});
} else {
if (errorReferences.length !== 1) {
throw new Error('Something is *really* wrong.');
}
renderErrorByIndex(currReferenceIndex = 0);
}
}).catch(function (e) {
console.log('Could not consume error:', e);
});
}
function shortcutHandler(type) {
switch (type) {
case SHORTCUT_ESCAPE:
{
unmount();
break;
}
case SHORTCUT_LEFT:
{
switchError(-1);
break;
}
case SHORTCUT_RIGHT:
{
switchError(1);
break;
}
default:
{
//TODO: this
break;
}
}
}
function inject() {
registerError(window, function (error) {
return crash(error);
});
registerPromise(window, function (error) {
return crash(error, true);
});
registerShortcuts(window, shortcutHandler);
registerStackTraceLimit();
registerReactStack();
permanentRegisterConsole('error', function (warning, stack) {
var data = massageWarning(warning, stack);
crash(
// $FlowFixMe
{
message: data.message,
stack: data.stack,
__unmap_source: '/static/js/bundle.js'
}, false);
});
}
function uninject() {
unregisterStackTraceLimit();
unregisterShortcuts(window);
unregisterPromise(window);
unregisterError(window);
unregisterReactStack();
}
export { inject, uninject };

196
web/node_modules/react-error-overlay/lib/styles.js generated vendored Normal file
View File

@@ -0,0 +1,196 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var black = '#293238',
darkGray = '#878e91',
red = '#ce1126',
redTransparent = 'rgba(206, 17, 38, 0.05)',
lightRed = '#fccfcf',
yellow = '#fbf5b4',
yellowTransparent = 'rgba(251, 245, 180, 0.3)',
white = '#ffffff';
var iframeStyle = {
position: 'fixed',
top: '0',
left: '0',
width: '100%',
height: '100%',
border: 'none',
'z-index': 2147483647 - 1 // below the compile error overlay
};
var overlayStyle = {
width: '100%',
height: '100%',
'box-sizing': 'border-box',
'text-align': 'center',
'background-color': white
};
var containerStyle = {
position: 'relative',
display: 'inline-flex',
'flex-direction': 'column',
height: '100%',
width: '1024px',
'max-width': '100%',
'overflow-x': 'hidden',
'overflow-y': 'auto',
padding: '0.5rem',
'box-sizing': 'border-box',
'text-align': 'left',
'font-family': 'Consolas, Menlo, monospace',
'font-size': '11px',
'white-space': 'pre-wrap',
'word-break': 'break-word',
'line-height': 1.5,
color: black
};
var hintsStyle = {
color: darkGray
};
var hintStyle = {
padding: '0.5em 1em',
cursor: 'pointer'
};
var closeButtonStyle = {
color: black,
'line-height': '1rem',
'font-size': '1.5rem',
padding: '1rem',
cursor: 'pointer',
position: 'absolute',
right: 0,
top: 0
};
var additionalChildStyle = {
'margin-bottom': '0.5rem'
};
var headerStyle = {
'font-size': '2em',
'font-family': 'sans-serif',
color: red,
'white-space': 'pre-wrap',
// Top bottom margin spaces header
// Right margin revents overlap with close button
margin: '0 2rem 0.75rem 0',
flex: '0 0 auto',
'max-height': '50%',
overflow: 'auto'
};
var functionNameStyle = {};
var linkStyle = {
'font-size': '0.9em',
'margin-bottom': '0.9em'
};
var anchorStyle = {
'text-decoration': 'none',
color: darkGray
};
var traceStyle = {
'font-size': '1em',
flex: '0 1 auto',
'min-height': '0px',
overflow: 'auto'
};
var depStyle = {};
var primaryErrorStyle = {
'background-color': lightRed
};
var secondaryErrorStyle = {
'background-color': yellow
};
var omittedFramesCollapsedStyle = {
color: black,
cursor: 'pointer',
'margin-bottom': '1.5em'
};
var omittedFramesExpandedStyle = {
color: black,
cursor: 'pointer',
'margin-bottom': '0.6em'
};
var _preStyle = {
display: 'block',
padding: '0.5em',
'margin-top': '0.5em',
'margin-bottom': '0.5em',
'overflow-x': 'auto',
'white-space': 'pre-wrap',
'border-radius': '0.25rem'
};
var primaryPreStyle = Object.assign({}, _preStyle, {
'background-color': redTransparent
});
var secondaryPreStyle = Object.assign({}, _preStyle, {
'background-color': yellowTransparent
});
var toggleStyle = {
'margin-bottom': '1.5em',
color: darkGray,
cursor: 'pointer'
};
var codeStyle = {
'font-family': 'Consolas, Menlo, monospace'
};
var hiddenStyle = {
display: 'none'
};
var groupStyle = {
'margin-right': '1em'
};
var _groupElemStyle = {
'background-color': redTransparent,
color: red,
border: 'none',
'border-radius': '4px',
padding: '3px 6px',
cursor: 'pointer'
};
var groupElemLeft = Object.assign({}, _groupElemStyle, {
'border-top-right-radius': '0px',
'border-bottom-right-radius': '0px',
'margin-right': '1px'
});
var groupElemRight = Object.assign({}, _groupElemStyle, {
'border-top-left-radius': '0px',
'border-bottom-left-radius': '0px'
});
var footerStyle = {
'font-family': 'sans-serif',
color: darkGray,
'margin-top': '0.5rem',
flex: '0 0 auto'
};
export { containerStyle, iframeStyle, overlayStyle, hintsStyle, hintStyle, closeButtonStyle, additionalChildStyle, headerStyle, functionNameStyle, linkStyle, anchorStyle, traceStyle, depStyle, primaryErrorStyle, primaryPreStyle, secondaryErrorStyle, secondaryPreStyle, omittedFramesCollapsedStyle, omittedFramesExpandedStyle, toggleStyle, codeStyle, hiddenStyle, groupStyle, groupElemLeft, groupElemRight, footerStyle };

View File

@@ -0,0 +1,42 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
function removeNextBr(parent, component) {
while (component != null && component.tagName.toLowerCase() !== 'br') {
component = component.nextElementSibling;
}
if (component != null) {
parent.removeChild(component);
}
}
function absolutifyCaret(component) {
var ccn = component.childNodes;
for (var index = 0; index < ccn.length; ++index) {
var c = ccn[index];
// $FlowFixMe
if (c.tagName.toLowerCase() !== 'span') {
continue;
}
var _text = c.innerText;
if (_text == null) {
continue;
}
var text = _text.replace(/\s/g, '');
if (text !== '|^') {
continue;
}
// $FlowFixMe
c.style.position = 'absolute';
// $FlowFixMe
removeNextBr(component, c);
}
}
export { absolutifyCaret };

View File

@@ -0,0 +1,17 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
function consumeEvent(e) {
e.preventDefault();
if (typeof e.target.blur === 'function') {
e.target.blur();
}
}
export { consumeEvent };

View File

@@ -0,0 +1,48 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
var injectedCount = 0;
var injectedCache = {};
function getHead(document) {
return document.head || document.getElementsByTagName('head')[0];
}
function injectCss(document, css) {
var head = getHead(document);
var style = document.createElement('style');
style.type = 'text/css';
style.appendChild(document.createTextNode(css));
head.appendChild(style);
injectedCache[++injectedCount] = style;
return injectedCount;
}
function removeCss(document, ref) {
if (injectedCache[ref] == null) {
return;
}
var head = getHead(document);
head.removeChild(injectedCache[ref]);
delete injectedCache[ref];
}
function applyStyles(element, styles) {
element.setAttribute('style', '');
for (var key in styles) {
if (!styles.hasOwnProperty(key)) {
continue;
}
// $FlowFixMe
element.style[key] = styles[key];
}
}
export { getHead, injectCss, removeCss, applyStyles };

View File

@@ -0,0 +1,26 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
function enableTabClick(node) {
node.setAttribute('tabindex', '0');
node.addEventListener('keydown', function (e) {
var key = e.key,
which = e.which,
keyCode = e.keyCode;
if (key === 'Enter' || which === 13 || keyCode === 13) {
e.preventDefault();
if (typeof e.target.click === 'function') {
e.target.click();
}
}
});
}
export { enableTabClick };

View File

@@ -0,0 +1,65 @@
import { parse } from './parser'; /**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { map } from './mapper';
import { unmap } from './unmapper';
var recorded = [];
var errorsConsumed = 0;
function consume(error) {
var unhandledRejection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var contextSize = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 3;
var parsedFrames = parse(error);
var enhancedFramesPromise = void 0;
if (error.__unmap_source) {
enhancedFramesPromise = unmap(
// $FlowFixMe
error.__unmap_source, parsedFrames, contextSize);
} else {
enhancedFramesPromise = map(parsedFrames, contextSize);
}
return enhancedFramesPromise.then(function (enhancedFrames) {
if (enhancedFrames.map(function (f) {
return f._originalFileName;
}).filter(function (f) {
return f != null && f.indexOf('node_modules') === -1;
}).length === 0) {
return null;
}
enhancedFrames = enhancedFrames.filter(function (_ref) {
var functionName = _ref.functionName;
return functionName == null || functionName.indexOf('__stack_frame_overlay_proxy_console__') === -1;
});
recorded[++errorsConsumed] = {
error: error,
unhandledRejection: unhandledRejection,
contextSize: contextSize,
enhancedFrames: enhancedFrames
};
return errorsConsumed;
});
}
function getErrorRecord(ref) {
return recorded[ref];
}
function drain() {
// $FlowFixMe
var keys = Object.keys(recorded);
for (var index = 0; index < keys.length; ++index) {
delete recorded[keys[index]];
}
}
export { consume, getErrorRecord, drain };

View File

@@ -0,0 +1,30 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { ScriptLine } from './stack-frame';
/**
*
* @param {number} line The line number to provide context around.
* @param {number} count The number of lines you'd like for context.
* @param {string[] | string} lines The source code.
*/
function getLinesAround(line, count, lines) {
if (typeof lines === 'string') {
lines = lines.split('\n');
}
var result = [];
for (var index = Math.max(0, line - 1 - count); index <= Math.min(lines.length - 1, line - 1 + count); ++index) {
result.push(new ScriptLine(index + 1, lines[index], index === line - 1));
}
return result;
}
export { getLinesAround };
export default getLinesAround;

View File

@@ -0,0 +1,179 @@
import _regeneratorRuntime from 'babel-runtime/regenerator';
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
/**
* Returns an instance of <code>{@link SourceMap}</code> for a given fileUri and fileContents.
* @param {string} fileUri The URI of the source file.
* @param {string} fileContents The contents of the source file.
*/
var getSourceMap = function () {
var _ref = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(fileUri, fileContents) {
var sm, base64, match2, index, url, obj;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return extractSourceMapUrl(fileUri, fileContents);
case 2:
sm = _context.sent;
if (!(sm.indexOf('data:') === 0)) {
_context.next = 14;
break;
}
base64 = /^data:application\/json;([\w=:"-]+;)*base64,/;
match2 = sm.match(base64);
if (match2) {
_context.next = 8;
break;
}
throw new Error('Sorry, non-base64 inline source-map encoding is not supported.');
case 8:
sm = sm.substring(match2[0].length);
sm = window.atob(sm);
sm = JSON.parse(sm);
return _context.abrupt('return', new SourceMap(new SourceMapConsumer(sm)));
case 14:
index = fileUri.lastIndexOf('/');
url = fileUri.substring(0, index + 1) + sm;
_context.next = 18;
return fetch(url).then(function (res) {
return res.json();
});
case 18:
obj = _context.sent;
return _context.abrupt('return', new SourceMap(new SourceMapConsumer(obj)));
case 20:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
return function getSourceMap(_x, _x2) {
return _ref.apply(this, arguments);
};
}();
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import { SourceMapConsumer } from 'source-map';
/**
* A wrapped instance of a <code>{@link https://github.com/mozilla/source-map SourceMapConsumer}</code>.
*
* This exposes methods which will be indifferent to changes made in <code>{@link https://github.com/mozilla/source-map source-map}</code>.
*/
var SourceMap = function () {
function SourceMap(sourceMap) {
_classCallCheck(this, SourceMap);
this.__source_map = sourceMap;
}
/**
* Returns the original code position for a generated code position.
* @param {number} line The line of the generated code position.
* @param {number} column The column of the generated code position.
*/
_createClass(SourceMap, [{
key: 'getOriginalPosition',
value: function getOriginalPosition(line, column) {
var _source_map$original = this.__source_map.originalPositionFor({
line: line,
column: column
}),
l = _source_map$original.line,
c = _source_map$original.column,
s = _source_map$original.source;
return { line: l, column: c, source: s };
}
/**
* Returns the generated code position for an original position.
* @param {string} source The source file of the original code position.
* @param {number} line The line of the original code position.
* @param {number} column The column of the original code position.
*/
}, {
key: 'getGeneratedPosition',
value: function getGeneratedPosition(source, line, column) {
var _source_map$generate = this.__source_map.generatedPositionFor({
source: source,
line: line,
column: column
}),
l = _source_map$generate.line,
c = _source_map$generate.column;
return {
line: l,
column: c
};
}
/**
* Returns the code for a given source file name.
* @param {string} sourceName The name of the source file.
*/
}, {
key: 'getSource',
value: function getSource(sourceName) {
return this.__source_map.sourceContentFor(sourceName);
}
}, {
key: 'getSources',
value: function getSources() {
return this.__source_map.sources;
}
}]);
return SourceMap;
}();
function extractSourceMapUrl(fileUri, fileContents) {
var regex = /\/\/[#@] ?sourceMappingURL=([^\s'"]+)\s*$/gm;
var match = null;
for (;;) {
var next = regex.exec(fileContents);
if (next == null) {
break;
}
match = next;
}
if (!(match && match[1])) {
return Promise.reject('Cannot find a source map directive for ' + fileUri + '.');
}
return Promise.resolve(match[1].toString());
}
export { extractSourceMapUrl, getSourceMap };
export default getSourceMap;

View File

@@ -0,0 +1,14 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
function isInternalFile(sourceFileName, fileName) {
return sourceFileName == null || sourceFileName === '' || sourceFileName.indexOf('/~/') !== -1 || sourceFileName.indexOf('/node_modules/') !== -1 || sourceFileName.trim().indexOf(' ') !== -1 || fileName == null || fileName === '';
}
export { isInternalFile };

View File

@@ -0,0 +1,122 @@
import _regeneratorRuntime from 'babel-runtime/regenerator';
/**
* Enhances a set of <code>StackFrame</code>s with their original positions and code (when available).
* @param {StackFrame[]} frames A set of <code>StackFrame</code>s which contain (generated) code positions.
* @param {number} [contextLines=3] The number of lines to provide before and after the line specified in the <code>StackFrame</code>.
*/
var map = function () {
var _ref = _asyncToGenerator(_regeneratorRuntime.mark(function _callee2(frames) {
var _this = this;
var contextLines = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
var cache, files;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
cache = {};
files = [];
frames.forEach(function (frame) {
var fileName = frame.fileName;
if (fileName == null) {
return;
}
if (files.indexOf(fileName) !== -1) {
return;
}
files.push(fileName);
});
_context2.next = 5;
return settle(files.map(function () {
var _ref2 = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(fileName) {
var fileSource, map;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return fetch(fileName).then(function (r) {
return r.text();
});
case 2:
fileSource = _context.sent;
_context.next = 5;
return getSourceMap(fileName, fileSource);
case 5:
map = _context.sent;
cache[fileName] = { fileSource: fileSource, map: map };
case 7:
case 'end':
return _context.stop();
}
}
}, _callee, _this);
}));
return function (_x3) {
return _ref2.apply(this, arguments);
};
}()));
case 5:
return _context2.abrupt('return', frames.map(function (frame) {
var functionName = frame.functionName,
fileName = frame.fileName,
lineNumber = frame.lineNumber,
columnNumber = frame.columnNumber;
var _ref3 = cache[fileName] || {},
map = _ref3.map,
fileSource = _ref3.fileSource;
if (map == null || lineNumber == null) {
return frame;
}
var _map$getOriginalPosit = map.getOriginalPosition(lineNumber, columnNumber),
source = _map$getOriginalPosit.source,
line = _map$getOriginalPosit.line,
column = _map$getOriginalPosit.column;
var originalSource = source == null ? [] : map.getSource(source);
return new StackFrame(functionName, fileName, lineNumber, columnNumber, getLinesAround(lineNumber, contextLines, fileSource), functionName, source, line, column, getLinesAround(line, contextLines, originalSource));
}));
case 6:
case 'end':
return _context2.stop();
}
}
}, _callee2, this);
}));
return function map(_x2) {
return _ref.apply(this, arguments);
};
}();
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import StackFrame from './stack-frame';
import { getSourceMap } from './getSourceMap';
import { getLinesAround } from './getLinesAround';
import { settle } from 'settle-promise';
export { map };
export default map;

View File

@@ -0,0 +1,80 @@
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import StackFrame from './stack-frame';
var regexExtractLocation = /\(?(.+?)(?::(\d+))?(?::(\d+))?\)?$/;
function extractLocation(token) {
return regexExtractLocation.exec(token).slice(1).map(function (v) {
var p = Number(v);
if (!isNaN(p)) {
return p;
}
return v;
});
}
var regexValidFrame_Chrome = /^\s*(at|in)\s.+(:\d+)/;
var regexValidFrame_FireFox = /(^|@)\S+:\d+|.+line\s+\d+\s+>\s+(eval|Function).+/;
function parseStack(stack) {
var frames = stack.filter(function (e) {
return regexValidFrame_Chrome.test(e) || regexValidFrame_FireFox.test(e);
}).map(function (e) {
if (regexValidFrame_FireFox.test(e)) {
// Strip eval, we don't care about it
var isEval = false;
if (/ > (eval|Function)/.test(e)) {
e = e.replace(/ line (\d+)(?: > eval line \d+)* > (eval|Function):\d+:\d+/g, ':$1');
isEval = true;
}
var data = e.split(/[@]/g);
var last = data.pop();
return new (Function.prototype.bind.apply(StackFrame, [null].concat([data.join('@') || (isEval ? 'eval' : null)], _toConsumableArray(extractLocation(last)))))();
} else {
// Strip eval, we don't care about it
if (e.indexOf('(eval ') !== -1) {
e = e.replace(/(\(eval at [^()]*)|(\),.*$)/g, '');
}
if (e.indexOf('(at ') !== -1) {
e = e.replace(/\(at /, '(');
}
var _data = e.trim().split(/\s+/g).slice(1);
var _last = _data.pop();
return new (Function.prototype.bind.apply(StackFrame, [null].concat([_data.join(' ') || null], _toConsumableArray(extractLocation(_last)))))();
}
});
return frames;
}
/**
* Turns an <code>Error</code>, or similar object, into a set of <code>StackFrame</code>s.
* @alias parse
*/
function parseError(error) {
if (error == null) {
throw new Error('You cannot pass a null object.');
}
if (typeof error === 'string') {
return parseStack(error.split('\n'));
}
if (Array.isArray(error)) {
return parseStack(error);
}
if (typeof error.stack === 'string') {
return parseStack(error.stack.split('\n'));
}
throw new Error('The error you provided does not contain a stack trace.');
}
export { parseError as parse };
export default parseError;

View File

@@ -0,0 +1,117 @@
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
/** A container holding a script line. */
var ScriptLine =
/** The content (or value) of this line of source. */
function ScriptLine(lineNumber, content) {
var highlight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
_classCallCheck(this, ScriptLine);
this.lineNumber = lineNumber;
this.content = content;
this.highlight = highlight;
}
/** Whether or not this line should be highlighted. Particularly useful for error reporting with context. */
/** The line number of this line of source. */
;
/**
* A representation of a stack frame.
*/
var StackFrame = function () {
function StackFrame() {
var functionName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
var fileName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var lineNumber = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var columnNumber = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
var scriptCode = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
var sourceFunctionName = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
var sourceFileName = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
var sourceLineNumber = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null;
var sourceColumnNumber = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : null;
var sourceScriptCode = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : null;
_classCallCheck(this, StackFrame);
this.functionName = functionName;
this.fileName = fileName;
this.lineNumber = lineNumber;
this.columnNumber = columnNumber;
this._originalFunctionName = sourceFunctionName;
this._originalFileName = sourceFileName;
this._originalLineNumber = sourceLineNumber;
this._originalColumnNumber = sourceColumnNumber;
this._scriptCode = scriptCode;
this._originalScriptCode = sourceScriptCode;
}
/**
* Returns the name of this function.
*/
_createClass(StackFrame, [{
key: 'getFunctionName',
value: function getFunctionName() {
return this.functionName;
}
/**
* Returns the source of the frame.
* This contains the file name, line number, and column number when available.
*/
}, {
key: 'getSource',
value: function getSource() {
var str = '';
if (this.fileName != null) {
str += this.fileName + ':';
}
if (this.lineNumber != null) {
str += this.lineNumber + ':';
}
if (this.columnNumber != null) {
str += this.columnNumber + ':';
}
return str.slice(0, -1);
}
/**
* Returns a pretty version of this stack frame.
*/
}, {
key: 'toString',
value: function toString() {
var f = this.getFunctionName();
if (f == null) {
return this.getSource();
}
return f + ' (' + this.getSource() + ')';
}
}]);
return StackFrame;
}();
export { StackFrame, ScriptLine };
export default StackFrame;

View File

@@ -0,0 +1,137 @@
import _regeneratorRuntime from 'babel-runtime/regenerator';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
/**
* Turns a set of mapped <code>StackFrame</code>s back into their generated code position and enhances them with code.
* @param {string} fileUri The URI of the <code>bundle.js</code> file.
* @param {StackFrame[]} frames A set of <code>StackFrame</code>s which are already mapped and missing their generated positions.
* @param {number} [fileContents=3] The number of lines to provide before and after the line specified in the <code>StackFrame</code>.
*/
var unmap = function () {
var _ref = _asyncToGenerator(_regeneratorRuntime.mark(function _callee(_fileUri, frames) {
var contextLines = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 3;
var fileContents, fileUri, map;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
fileContents = (typeof _fileUri === 'undefined' ? 'undefined' : _typeof(_fileUri)) === 'object' ? _fileUri.contents : null;
fileUri = (typeof _fileUri === 'undefined' ? 'undefined' : _typeof(_fileUri)) === 'object' ? _fileUri.uri : _fileUri;
if (!(fileContents == null)) {
_context.next = 6;
break;
}
_context.next = 5;
return fetch(fileUri).then(function (res) {
return res.text();
});
case 5:
fileContents = _context.sent;
case 6:
_context.next = 8;
return getSourceMap(fileUri, fileContents);
case 8:
map = _context.sent;
return _context.abrupt('return', frames.map(function (frame) {
var functionName = frame.functionName,
lineNumber = frame.lineNumber,
columnNumber = frame.columnNumber,
_originalLineNumber = frame._originalLineNumber;
if (_originalLineNumber != null) {
return frame;
}
var fileName = frame.fileName;
if (fileName) {
fileName = path.normalize(fileName);
}
if (fileName == null) {
return frame;
}
var fN = fileName;
var source = map.getSources().map(function (s) {
return s.replace(/[\\]+/g, '/');
}).filter(function (p) {
p = path.normalize(p);
var i = p.lastIndexOf(fN);
return i !== -1 && i === p.length - fN.length;
}).map(function (p) {
return {
token: p,
seps: count(path.sep, path.normalize(p)),
penalties: count('node_modules', p) + count('~', p)
};
}).sort(function (a, b) {
var s = Math.sign(a.seps - b.seps);
if (s !== 0) {
return s;
}
return Math.sign(a.penalties - b.penalties);
});
if (source.length < 1 || lineNumber == null) {
return new StackFrame(null, null, null, null, null, functionName, fN, lineNumber, columnNumber, null);
}
var sourceT = source[0].token;
var _map$getGeneratedPosi = map.getGeneratedPosition(sourceT, lineNumber,
// $FlowFixMe
columnNumber),
line = _map$getGeneratedPosi.line,
column = _map$getGeneratedPosi.column;
var originalSource = map.getSource(sourceT);
return new StackFrame(functionName, fileUri, line, column || null, getLinesAround(line, contextLines, fileContents || []), functionName, fN, lineNumber, columnNumber, getLinesAround(lineNumber, contextLines, originalSource));
}));
case 10:
case 'end':
return _context.stop();
}
}
}, _callee, this);
}));
return function unmap(_x2, _x3) {
return _ref.apply(this, arguments);
};
}();
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
import StackFrame from './stack-frame';
import { getSourceMap } from './getSourceMap';
import { getLinesAround } from './getLinesAround';
import path from 'path';
function count(search, string) {
// Count starts at -1 becuse a do-while loop always runs at least once
var count = -1,
index = -1;
do {
// First call or the while case evaluated true, meaning we have to make
// count 0 or we found a character
++count;
// Find the index of our search string, starting after the previous index
index = string.indexOf(search, index + 1);
} while (index !== -1);
return count;
}
export { unmap };
export default unmap;

View File

@@ -0,0 +1,48 @@
function stripInlineStacktrace(message) {
return message.split('\n').filter(function (line) {
return !line.match(/^\s*in/);
}).join('\n'); // " in Foo"
} /**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
function massage(warning, frames) {
var message = stripInlineStacktrace(warning);
// Reassemble the stack with full filenames provided by React
var stack = '';
var lastFilename = void 0;
var lastLineNumber = void 0;
for (var index = 0; index < frames.length; ++index) {
var _frames$index = frames[index],
fileName = _frames$index.fileName,
lineNumber = _frames$index.lineNumber;
if (fileName == null || lineNumber == null) {
continue;
}
// TODO: instead, collapse them in the UI
if (fileName === lastFilename && typeof lineNumber === 'number' && typeof lastLineNumber === 'number' && Math.abs(lineNumber - lastLineNumber) < 3) {
continue;
}
lastFilename = fileName;
lastLineNumber = lineNumber;
var name = frames[index].name;
name = name || '(anonymous function)';
stack += 'in ' + name + ' (at ' + fileName + ':' + lineNumber + ')\n';
}
return { message: message, stack: stack };
}
export { massage };