Skip to content

Commit 49d4c0e

Browse files
committed
rustdoc: add nobuild typescript checking to our JS
By nobuild, I mean that the type annotations are all in comments, not in the "native" typescript syntax. This is a bit uglier, but it lets you rapid-prototype without tsc, works with all the native browser debugging tools, and keeps Node out of Rust's bootstrap chain. This pull request mostly just adds ts-ignore annotations and type declarations. To actually take good advantage of typescript, we'll want to "burn down" this pile of unsafe code until we eventually have a version with almost none of these. This PR also adds tsc to the mingw-check Dockerfile, so that it can't fall out of date like the Closure annotations did. https://rust-lang.zulipchat.com/#narrow/channel/266220-t-rustdoc/topic/typescript
1 parent 2f348cb commit 49d4c0e

File tree

11 files changed

+1707
-678
lines changed

11 files changed

+1707
-678
lines changed

src/ci/docker/host-x86_64/mingw-check/Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ENV PATH="/node/bin:${PATH}"
2929

3030
# Install es-check
3131
# Pin its version to prevent unrelated CI failures due to future es-check versions.
32-
RUN npm install es-check@6.1.1 eslint@8.6.0 -g
32+
RUN npm install es-check@6.1.1 eslint@8.6.0 typescript@5.7.3 -g
3333

3434
COPY scripts/sccache.sh /scripts/
3535
RUN sh /scripts/sccache.sh
@@ -68,4 +68,5 @@ ENV SCRIPT \
6868
es-check es2019 ../src/librustdoc/html/static/js/*.js && \
6969
eslint -c ../src/librustdoc/html/static/.eslintrc.js ../src/librustdoc/html/static/js/*.js && \
7070
eslint -c ../src/tools/rustdoc-js/.eslintrc.js ../src/tools/rustdoc-js/tester.js && \
71-
eslint -c ../src/tools/rustdoc-gui/.eslintrc.js ../src/tools/rustdoc-gui/tester.js
71+
eslint -c ../src/tools/rustdoc-gui/.eslintrc.js ../src/tools/rustdoc-gui/tester.js && \
72+
tsc --project ../src/librustdoc/html/static/js/tsconfig.json

src/librustdoc/html/static/js/README.md

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
These JavaScript files are incorporated into the rustdoc binary at build time,
44
and are minified and written to the filesystem as part of the doc build process.
55

6-
We use the [Closure Compiler](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler)
6+
We use the [TypeScript Compiler](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html)
77
dialect of JSDoc to comment our code and annotate params and return types.
88
To run a check:
99

10-
./x.py doc library/std
11-
npm i -g google-closure-compiler
12-
google-closure-compiler -W VERBOSE \
13-
build/<YOUR PLATFORM>/doc/{search-index*.js,crates*.js} \
14-
src/librustdoc/html/static/js/{search.js,main.js,storage.js} \
15-
--externs src/librustdoc/html/static/js/externs.js >/dev/null
10+
npm i -g typescript
11+
tsc --project tsconfig.json

src/librustdoc/html/static/js/externs.js

-270
This file was deleted.

0 commit comments

Comments
 (0)