-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
༼ つ ◕_◕ ༽つ stack-frame-overlay #2111
Merged
Merged
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e165ff9
༼ つ ◕_◕ ༽つ stack-frame-overlay
Timer 2790d00
Fix linting
Timer 211a36b
Remove auto overlay
Timer a4a1bc3
Fix e2e
Timer 1913cb6
Pull in the rest
Timer 4205406
Appease flow
Timer 9d260fd
Correct dep
Timer d976280
Remove old repo references
Timer 6d8b31d
Check flow on test
Timer 7220e21
Test overlay in e2e
Timer 8343461
Add cross env
Timer a40a67b
Rename package
Timer a5dc84d
Make sure it gets built post-install
Timer d32d2f3
Update the README
Timer 8bf601d
Remove extra builds now that there's a postinstall script
Timer 0605829
Revert "Remove extra builds now that there's a postinstall script"
Timer ed02ad4
Remove broken script
Timer 91c71bf
Fix some dev ergo
Timer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["react-app"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "react-app" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ignore] | ||
|
||
[include] | ||
src/**/*.js | ||
|
||
[libs] | ||
|
||
[options] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lib/ | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
__tests__ | ||
*.test.js | ||
*.spec.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# `stack-frame-overlay` | ||
|
||
An overlay for displaying stack frames. | ||
|
||
# API | ||
|
||
<!-- Generated by documentation.js. Update this documentation by updating the source code. --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"name": "stack-frame-overlay", | ||
"version": "0.4.0", | ||
"description": "An overlay for displaying stack frames.", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"prepublishOnly": "npm run build:prod && npm test", | ||
"start": "cross-env NODE_ENV=development npm run build -- --watch", | ||
"test": "flow && jest", | ||
"build": "babel src/ -d lib/", | ||
"build:prod": "cross-env NODE_ENV=production babel src/ -d lib/" | ||
}, | ||
"repository": "facebookincubator/create-react-app", | ||
"license": "BSD-3-Clause", | ||
"bugs": { | ||
"url": "https://github.com/facebookincubator/create-react-app/issues" | ||
}, | ||
"keywords": [ | ||
"overlay", | ||
"syntax", | ||
"error", | ||
"red", | ||
"box", | ||
"redbox", | ||
"crash", | ||
"warning" | ||
], | ||
"author": "Joe Haddad <timer150@gmail.com>", | ||
"files": [ | ||
"lib/" | ||
], | ||
"dependencies": { | ||
"anser": "^1.2.5", | ||
"babel-code-frame": "^6.22.0", | ||
"babel-runtime": "^6.23.0", | ||
"react-dev-utils": "^0.5.2", | ||
"settle-promise": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.24.1", | ||
"babel-eslint": "7.x", | ||
"babel-preset-react-app": "^2.2.0", | ||
"cross-env": "^4.0.0", | ||
"eslint": "^3.16.1", | ||
"eslint-config-react-app": "^0.6.2", | ||
"eslint-plugin-flowtype": "^2.21.0", | ||
"eslint-plugin-import": "^2.0.1", | ||
"eslint-plugin-jsx-a11y": "^4.0.0", | ||
"eslint-plugin-react": "^6.4.1", | ||
"flow-bin": "^0.46.0", | ||
"jest": "19.x" | ||
}, | ||
"jest": { | ||
"setupFiles": [ | ||
"./src/__tests__/setupJest.js" | ||
], | ||
"collectCoverage": true, | ||
"coverageReporters": [ | ||
"json" | ||
], | ||
"testMatch": [ | ||
"<rootDir>/src/**/__tests__/**/*.js?(x)", | ||
"<rootDir>/src/**/?(*.)(spec|test).js?(x)" | ||
], | ||
"testPathIgnorePatterns": [ | ||
"/node_modules/", | ||
"/fixtures/", | ||
"setupJest.js" | ||
] | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* @flow */ | ||
import { applyStyles } from '../utils/dom/css'; | ||
import { groupStyle, groupElemLeft, groupElemRight } from '../styles'; | ||
import { consumeEvent } from '../utils/dom/consumeEvent'; | ||
import { enableTabClick } from '../utils/dom/enableTabClick'; | ||
|
||
type SwitchCallback = (offset: number) => void; | ||
function updateAdditional( | ||
document: Document, | ||
additionalReference: HTMLDivElement, | ||
currentError: number, | ||
totalErrors: number, | ||
switchCallback: SwitchCallback | ||
) { | ||
if (additionalReference.lastChild) { | ||
additionalReference.removeChild(additionalReference.lastChild); | ||
} | ||
|
||
let text = ' '; | ||
if (totalErrors <= 1) { | ||
additionalReference.appendChild(document.createTextNode(text)); | ||
return; | ||
} | ||
text = `Errors ${currentError} of ${totalErrors}`; | ||
const span = document.createElement('span'); | ||
span.appendChild(document.createTextNode(text)); | ||
const group = document.createElement('span'); | ||
applyStyles(group, groupStyle); | ||
const left = document.createElement('button'); | ||
applyStyles(left, groupElemLeft); | ||
left.addEventListener('click', function(e: MouseEvent) { | ||
consumeEvent(e); | ||
switchCallback(-1); | ||
}); | ||
left.appendChild(document.createTextNode('←')); | ||
enableTabClick(left); | ||
const right = document.createElement('button'); | ||
applyStyles(right, groupElemRight); | ||
right.addEventListener('click', function(e: MouseEvent) { | ||
consumeEvent(e); | ||
switchCallback(1); | ||
}); | ||
right.appendChild(document.createTextNode('→')); | ||
enableTabClick(right); | ||
group.appendChild(left); | ||
group.appendChild(right); | ||
span.appendChild(group); | ||
additionalReference.appendChild(span); | ||
} | ||
|
||
export type { SwitchCallback }; | ||
export { updateAdditional }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* @flow */ | ||
import { applyStyles } from '../utils/dom/css'; | ||
import { hintsStyle, hintStyle, closeButtonStyle } from '../styles'; | ||
|
||
function createHint(document: Document, hint: string) { | ||
const span = document.createElement('span'); | ||
span.appendChild(document.createTextNode(hint)); | ||
applyStyles(span, hintStyle); | ||
return span; | ||
} | ||
|
||
type CloseCallback = () => void; | ||
function createClose(document: Document, callback: CloseCallback) { | ||
const hints = document.createElement('div'); | ||
applyStyles(hints, hintsStyle); | ||
|
||
const close = createHint(document, '×'); | ||
close.addEventListener('click', () => callback()); | ||
applyStyles(close, closeButtonStyle); | ||
hints.appendChild(close); | ||
return hints; | ||
} | ||
|
||
export type { CloseCallback }; | ||
export { createClose }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* @flow */ | ||
import type { ScriptLine } from '../utils/stack-frame'; | ||
import { applyStyles } from '../utils/dom/css'; | ||
import { absolutifyCaret } from '../utils/dom/absolutifyCaret'; | ||
import { | ||
preStyle, | ||
codeStyle, | ||
primaryErrorStyle, | ||
secondaryErrorStyle, | ||
} from '../styles'; | ||
|
||
import generateAnsiHtml from 'react-dev-utils/ansiHTML'; | ||
|
||
import codeFrame from 'babel-code-frame'; | ||
|
||
function createCode( | ||
document: Document, | ||
sourceLines: ScriptLine[], | ||
lineNum: number, | ||
columnNum: number | null, | ||
contextSize: number, | ||
main: boolean = false | ||
) { | ||
const sourceCode = []; | ||
let whiteSpace = Infinity; | ||
sourceLines.forEach(function(e) { | ||
const { content: text } = e; | ||
const 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) { | ||
let { content: text } = e; | ||
const { lineNumber: line } = e; | ||
|
||
if (isFinite(whiteSpace)) { | ||
text = text.substring(whiteSpace); | ||
} | ||
sourceCode[line - 1] = text; | ||
}); | ||
const ansiHighlight = codeFrame( | ||
sourceCode.join('\n'), | ||
lineNum, | ||
columnNum == null ? 0 : columnNum - (isFinite(whiteSpace) ? whiteSpace : 0), | ||
{ | ||
forceColor: true, | ||
linesAbove: contextSize, | ||
linesBelow: contextSize, | ||
} | ||
); | ||
const htmlHighlight = generateAnsiHtml(ansiHighlight); | ||
const code = document.createElement('code'); | ||
code.innerHTML = htmlHighlight; | ||
absolutifyCaret(code); | ||
applyStyles(code, codeStyle); | ||
|
||
const ccn = code.childNodes; | ||
// eslint-disable-next-line | ||
oLoop: for (let index = 0; index < ccn.length; ++index) { | ||
const node = ccn[index]; | ||
const ccn2 = node.childNodes; | ||
for (let index2 = 0; index2 < ccn2.length; ++index2) { | ||
const lineNode = ccn2[index2]; | ||
const 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; | ||
} | ||
} | ||
const pre = document.createElement('pre'); | ||
applyStyles(pre, preStyle); | ||
pre.appendChild(code); | ||
return pre; | ||
} | ||
|
||
export { createCode }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* @flow */ | ||
import { applyStyles } from '../utils/dom/css'; | ||
import { footerStyle } from '../styles'; | ||
|
||
function createFooter(document: Document) { | ||
const div = document.createElement('div'); | ||
applyStyles(div, footerStyle); | ||
div.appendChild( | ||
document.createTextNode( | ||
'This screen is visible only in development. It will not appear when the app crashes in production.' | ||
) | ||
); | ||
div.appendChild(document.createElement('br')); | ||
div.appendChild( | ||
document.createTextNode( | ||
'Open your browser’s developer console to further inspect this error.' | ||
) | ||
); | ||
return div; | ||
} | ||
|
||
export { createFooter }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add info on how to build it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍