Skip to content

Commit 940d4b7

Browse files
authored
fix some types (#295)
1 parent 22325e7 commit 940d4b7

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

src/javascript.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {type Identifier, type Node, type Options, Parser, tokTypes} from "acorn";
1+
import {Parser, tokTypes} from "acorn";
2+
import type {Expression, Identifier, Node, Options, Program} from "acorn";
23
import {fileReference} from "./files.js";
34
import {findAssignments} from "./javascript/assignments.js";
45
import {findAwaits} from "./javascript/awaits.js";
@@ -131,12 +132,12 @@ function parseJavaScript(input: string, options: ParseOptions): JavaScriptNode {
131132
if (expression?.type === "ClassExpression" && expression.id) expression = null; // treat named class as program
132133
if (expression?.type === "FunctionExpression" && expression.id) expression = null; // treat named function as program
133134
if (!expression && inline) throw new SyntaxError("invalid expression");
134-
const body = expression ?? (Parser.parse(input, parseOptions) as any);
135+
const body = expression ?? Parser.parse(input, parseOptions);
135136
const exports = findExports(body);
136137
if (exports.length) throw syntaxError("Unexpected token 'export'", exports[0], input); // disallow exports
137138
const references = findReferences(body, globals);
138139
findAssignments(body, references, globals, input);
139-
const declarations = expression ? null : findDeclarations(body, globals, input);
140+
const declarations = expression ? null : findDeclarations(body as Program, globals, input);
140141
const imports = findImports(body, root, sourcePath);
141142
const features = findFeatures(body, root, sourcePath, references, input);
142143
return {
@@ -152,11 +153,11 @@ function parseJavaScript(input: string, options: ParseOptions): JavaScriptNode {
152153

153154
// Parses a single expression; like parseExpressionAt, but returns null if
154155
// additional input follows the expression.
155-
function maybeParseExpression(input, options) {
156+
function maybeParseExpression(input: string, options: Options): Expression | null {
156157
const parser = new (Parser as any)(options, input, 0); // private constructor
157158
parser.nextToken();
158159
try {
159-
const node = (parser as any).parseExpression();
160+
const node = parser.parseExpression();
160161
return parser.type === tokTypes.eof ? node : null;
161162
} catch {
162163
return null;

src/javascript/imports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export function parseLocalImports(root: string, paths: string[]): ImportReferenc
115115

116116
/** Rewrites import specifiers in the specified ES module source. */
117117
export function rewriteModule(input: string, sourcePath: string, resolver: ImportResolver): string {
118-
const body = Parser.parse(input, parseOptions) as any;
118+
const body = Parser.parse(input, parseOptions);
119119
const output = new Sourcemap(input);
120120

121121
simple(body, {

src/markdown.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ export function normalizePieceHtml(html: string, sourcePath: string, context: Pa
338338
// Extracting references to files (such as from linked stylesheets).
339339
const filePaths = new Set<FileReference["path"]>();
340340
for (const {query, src} of SUPPORTED_PROPERTIES) {
341-
for (const element of document.querySelectorAll(query) as any as Iterable<Element>) {
341+
for (const element of document.querySelectorAll(query)) {
342342
if (src === "srcset") {
343343
const srcset = element.getAttribute(src);
344344
const paths =
@@ -379,15 +379,13 @@ export function normalizePieceHtml(html: string, sourcePath: string, context: Pa
379379
// Syntax highlighting for <code> elements. The code could contain an inline
380380
// expression within, or other HTML, but we only highlight text nodes that are
381381
// direct children of code elements.
382-
for (const code of document.querySelectorAll("code[class*='language-']") as any as Iterable<Element>) {
383-
const language = [...(code.classList as any).keys()]
384-
.find((c) => c.startsWith("language-"))
385-
?.slice("language-".length);
382+
for (const code of document.querySelectorAll("code[class*='language-']")) {
383+
const language = [...code.classList].find((c) => c.startsWith("language-"))?.slice("language-".length);
386384
if (!language || !hljs.getLanguage(language)) continue;
387385
if (code.parentElement?.tagName === "PRE") code.parentElement.setAttribute("data-language", language);
388386
let html = "";
389387
code.normalize(); // coalesce adjacent text nodes
390-
for (const child of [...(code.childNodes as any as Iterable<Node>)]) {
388+
for (const child of code.childNodes) {
391389
html += child.nodeType === TEXT_NODE ? hljs.highlight(child.textContent!, {language}).value : String(child);
392390
}
393391
code.innerHTML = html;

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"_version": "18.1.0",
55
"compilerOptions": {
66
"noImplicitAny": false,
7-
"lib": ["es2023"],
7+
"lib": ["es2023", "DOM.Iterable"],
88
"module": "node16",
99
"target": "es2022",
1010
"strict": true,

0 commit comments

Comments
 (0)