Skip to content

Commit 32d3ffa

Browse files
Merge pull request #1257 from sosy-lab/typescript-migration/migration/entry-points
Convert core entry points to TypeScript
2 parents 332cb2f + 4f72f16 commit 32d3ffa

4 files changed

Lines changed: 52 additions & 19 deletions

File tree

benchexec/tablegenerator/react-table/build/main.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchexec/tablegenerator/react-table/src/App.js renamed to benchexec/tablegenerator/react-table/src/App.tsx

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,39 @@ import "./App.scss";
99
import React from "react";
1010
import Overview from "./components/Overview";
1111

12+
// ==============================
13+
// Global augmentations
14+
// ==============================
15+
16+
declare global {
17+
interface Window {
18+
// Global injected app data (loaded via @data in dev and via index.html in prod).
19+
data: unknown;
20+
}
21+
}
22+
23+
// ==============================
24+
// Component props
25+
// ==============================
26+
27+
interface AppProps {
28+
// Callback that is forwarded to Overview. We keep it generic here
29+
// because the exact payload type is defined by Overview.
30+
onStatsReady?: (stats: unknown) => void;
31+
}
32+
1233
if (process.env.NODE_ENV !== "production") {
1334
// Load example data for development
14-
window.data = require("@data");
15-
window.data.version = "(development build)";
35+
// `require` is used here intentionally because @data is only available in dev builds.
36+
// eslint-disable-next-line @typescript-eslint/no-var-requires
37+
window.data = require("@data") as unknown;
38+
39+
// `window.data` is `unknown` on purpose (shape depends on runtime data).
40+
// We keep the original behavior and only narrow locally for this assignment.
41+
(window.data as { version?: string }).version = "(development build)";
1642
}
1743

18-
const App = (props) => {
44+
const App = (props: AppProps): JSX.Element => {
1945
// If we visit this page without a hash, like www.domain.com/ or www.domain.com/subpage, we
2046
// append a hash to the URL to ensure that the page is loaded correctly. This is necessary
2147
// to ensure correct routing in the app.

benchexec/tablegenerator/react-table/src/index.js

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This file is part of BenchExec, a framework for reliable benchmarking:
2+
// https://github.com/sosy-lab/benchexec
3+
//
4+
// SPDX-FileCopyrightText: 2019-2020 Dirk Beyer <https://www.sosy-lab.org>
5+
//
6+
// SPDX-License-Identifier: Apache-2.0
7+
8+
import React from "react";
9+
import ReactDOM from "react-dom";
10+
import "./index.css";
11+
import App from "./App";
12+
13+
// `getElementById` can return null. We keep the runtime behavior
14+
// (it should exist in production) but add a safe guard for type safety.
15+
const rootEl = document.getElementById("root");
16+
if (rootEl) {
17+
ReactDOM.render(<App />, rootEl);
18+
}
19+
20+
// Remove loading message
21+
// Guard against missing element to avoid runtime errors in non-standard environments (e.g. tests).
22+
document.getElementById("msg-container")?.remove();

0 commit comments

Comments
 (0)