Skip to content

Add TypeScript, catch bugs #256

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

Merged
merged 4 commits into from
Apr 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gdbgui/src/js/Breakpoints.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import GdbApi from "./GdbApi.jsx";
import Actions from "./Actions.js";
import Util from "./Util.js";
import FileOps from "./FileOps.jsx";
import { FileLink } from "./Links.jsx";
import { FileLink } from "./Links";

const BreakpointSourceLineCache = {
_cache: {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import React from "react";
import * as React from "react";
import ToolTip from "./ToolTip.jsx";
import { store } from "statorgfc";

class CopyToClipboard extends React.Component {
type Props = {
content: string | null
};

class CopyToClipboard extends React.Component<Props> {
node: HTMLSpanElement | null = null;
render() {
if (!this.props.content) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion gdbgui/src/js/GdbVariable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Memory from "./Memory.jsx";
import constants from "./constants.js";
import { store } from "statorgfc";
import GdbApi from "./GdbApi.jsx";
import CopyToClipboard from "./CopyToClipboard.jsx";
import CopyToClipboard from "./CopyToClipboard";
import Actions from "./Actions.js";

/**
Expand Down
30 changes: 21 additions & 9 deletions gdbgui/src/js/Links.jsx → gdbgui/src/js/Links.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import Actions from "./Actions.js";
import React from "react";
import CopyToClipboard from "./CopyToClipboard.jsx";
import * as React from "react";
import CopyToClipboard from "./CopyToClipboard";
import MemoryLink from "./MemoryLink";

class FileLink extends React.Component {
type Props = {
file?: string
fullname?: string
line: string
num_lines?: number
};

export class FileLink extends React.Component<Props> {
render() {
let line = parseInt(this.props.line);
let onclick = null,
let onclick = () => {},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug #2: React event handlers shouldn't be null.

cls = "";
if (!this.props.file || !line) {
line = "";
line = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug #3: line is a number, not a string.

}
let sep = "";
if (line && line !== 0) {
Expand Down Expand Up @@ -43,7 +51,14 @@ class FileLink extends React.Component {
}
}

class FrameLink extends React.Component {
type FrameLinkProps = {
addr: string
file?: string
fullname?: string
line: string
};

export class FrameLink extends React.Component<FrameLinkProps> {
render() {
return (
<div>
Expand All @@ -58,6 +73,3 @@ class FrameLink extends React.Component {
);
}
}

export { FileLink };
export { FrameLink };
2 changes: 1 addition & 1 deletion gdbgui/src/js/Memory.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { store } from "statorgfc";
import GdbApi from "./GdbApi.jsx";
import constants from "./constants.js";
import ReactTable from "./ReactTable.jsx";
import MemoryLink from "./MemoryLink.jsx";
import MemoryLink from "./MemoryLink.tsx";
import Actions from "./Actions";
import React from "react";

Expand Down
9 changes: 7 additions & 2 deletions gdbgui/src/js/MemoryLink.jsx → gdbgui/src/js/MemoryLink.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React from "react";
import * as React from "react";
import Memory from "./Memory.jsx";

class MemoryLink extends React.Component {
type Props = {
addr: string
style?: React.CSSProperties
};

class MemoryLink extends React.Component<Props> {
render() {
// turn 0x00000000000000 into 0x0
const address_no_leading_zeros = "0x" + parseInt(this.props.addr, 16).toString(16);
Expand Down
2 changes: 1 addition & 1 deletion gdbgui/src/js/SourceCode.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React from "react";
import FileOps from "./FileOps.jsx";
import Breakpoints from "./Breakpoints.jsx";
import Memory from "./Memory.jsx";
import MemoryLink from "./MemoryLink.jsx";
import MemoryLink from "./MemoryLink";
import constants from "./constants.js";
import Actions from "./Actions.js";

Expand Down
2 changes: 1 addition & 1 deletion gdbgui/src/js/SourceCodeHeading.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import constants from "./constants.js";
import { store } from "statorgfc";
import { FileLink } from "./Links.jsx";
import { FileLink } from "./Links";
import FileOps from "./FileOps.jsx";

class SourceCodeHeading extends React.Component {
Expand Down
4 changes: 2 additions & 2 deletions gdbgui/src/js/Threads.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import ReactTable from "./ReactTable.jsx";
import { store } from "statorgfc";
import GdbApi from "./GdbApi.jsx";
import Memory from "./Memory.jsx";
import { FileLink } from "./Links.jsx";
import MemoryLink from "./MemoryLink.jsx";
import { FileLink } from "./Links";
import MemoryLink from "./MemoryLink";

class FrameArguments extends React.Component {
render_frame_arg(frame_arg) {
Expand Down
5 changes: 5 additions & 0 deletions gdbgui/src/js/types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module 'statorgfc' {
export let store: {
get(key: string): any
}
}
9 changes: 4 additions & 5 deletions gdbgui/static/js/build.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {
"preset": 'ts-jest',
"verbose": true,
"testMatch": [__dirname + '/gdbgui/src/js/tests/**']
"testMatch": [__dirname + '/gdbgui/src/js/tests/**'],
"transform": {
'^.+\.(j|t)sx?$': 'ts-jest'
}
}
32 changes: 15 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,30 @@
"version": "0.1.0",
"license": "GPL-3.0",
"scripts": {
"start": "BABEL_ENV=development webpack --mode development --watch --config webpack.config.js",
"start": "NODE_ENV=development webpack --mode development --watch --config webpack.config.js",
"test": "jest",
"build": "BABEL_ENV=production webpack --mode production --config webpack.config.js",
"build": "NODE_ENV=production webpack --mode production --config webpack.config.js",
"prettier": "prettier ./gdbgui/src/js/** --write"
},
"babel": {
"presets": [
"react-app"
]
},
"dependencies": {
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.3",
"babel-loader": "^7.1.4",
"babel-preset-react-app": "^3.1.1",
"babel-runtime": "6.26.0",
"eslint": "^4.19.1",
"eslint-loader": "^2.0.0",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-react": "^7.7.0",
"jest": "^21.2.1",
"prettier": "^1.12.0",
"react": "^16.4",
"react-dom": "^16.4",
"statorgfc": "^0.1.6",
"webpack": "^4.5.0",
"webpack-cli": "^2.0.14"
},
"devDependencies": {
"@types/jest": "^24.0.11",
"@types/react": "^16.8.7",
"@types/react-dom": "^16.8.2",
"fork-ts-checker-webpack-plugin": "^1.0.0",
"jest": "^24.3.1",
"ts-jest": "^24.0.0",
"ts-loader": "^5.3.3",
"tslint": "^5.13.1",
"tslint-config-prettier": "^1.18.0",
"tslint-loader": "^3.5.4",
"typescript": "^3.3.3333"
}
}
22 changes: 22 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"allowJs": true,
"downlevelIteration": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react",
"lib": ["dom", "es2015", "es2016.array.include"],
"module": "esnext",
"moduleResolution": "node",
"newLine": "LF",
"noEmitOnError": false,
"outDir": "dist",
"preserveConstEnums": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"target": "es5"
},
"include": [
"./gdbgui/src/js"
]
}
23 changes: 23 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"env": {
"browser": true,
"es6": true,
"jquery": true
},
"extends": ["tslint-config-prettier"],
"globals": {
"initial_data": true,
"module": true,
"_": true,
"moment": true
},
"jsRules": {
"indent": {
"options": ["spaces"]
}
},
"rules": {
"quotemark": true,
"semicolon": true
}
}
51 changes: 31 additions & 20 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
const path = require('path');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');

module.exports = {
entry: './gdbgui/src/js/gdbgui.jsx',
devtool: 'source-map',
performance: {
hints: false
},
output: {
path: path.resolve(__dirname, 'gdbgui/static/js/'),
filename: 'build.js'
},
module: {
rules: [
{ test: /\.js$/,
use: [
'babel-loader',
'eslint-loader',
],
exclude: /node_modules/
},
{ test: /\.jsx$/,
use: [
'babel-loader',
'eslint-loader',
],
exclude: /node_modules/
}
]
rules: [{
test: /\.(j|t)sx?$/,
use: [
{
loader: 'ts-loader',
options: {
experimentalFileCaching: true,
experimentalWatchApi: true,
transpileOnly: true
}
},
{
loader: 'tslint-loader',
options: {
fix: true,
typeCheck: true
}
}
],
exclude: /node_modules/
}]
},
plugins: [
new ForkTsCheckerWebpackPlugin({
tslint: true,
tslintAutoFix: true
})
],
resolve: {
extensions: ['.js', '.ts', '.tsx']
}
}
Loading