Skip to content

Commit dc63472

Browse files
authored
Enable checkJs (#648)
* Add more ts-checks * cover extattrs * cover more * Enable checkJs * Add .js to import() * TODO:
1 parent 0c7c2e8 commit dc63472

29 files changed

+215
-89
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
dist/*
33
!dist/package.json
4+
.vscode/

jsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"compilerOptions": {
33
"target": "es2020",
44
"module": "es2020",
5-
"moduleResolution": "node"
5+
"moduleResolution": "node",
6+
"checkJs": true
67
},
78
"include": [
89
"lib/"

lib/error.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@ function contextAsText(node) {
2828
* @typedef {object} WebIDL2ErrorOptions
2929
* @property {"error" | "warning"} [level]
3030
* @property {Function} [autofix]
31+
* @property {string} [ruleName]
3132
*
3233
* @typedef {ReturnType<typeof error>} WebIDLErrorData
3334
*
3435
* @param {string} message error message
36+
* @param {*} position
37+
* @param {*} current
38+
* @param {*} message
3539
* @param {"Syntax" | "Validation"} kind error type
36-
* @param {WebIDL2ErrorOptions} [options]
40+
* @param {WebIDL2ErrorOptions=} options
3741
*/
3842
function error(
3943
source,
@@ -52,6 +56,12 @@ function error(
5256
: source.slice(Math.max(position + count, 0), position);
5357
}
5458

59+
/**
60+
* @param {import("./tokeniser.js").Token[]} inputs
61+
* @param {object} [options]
62+
* @param {boolean} [options.precedes]
63+
* @returns
64+
*/
5565
function tokensToText(inputs, { precedes } = {}) {
5666
const text = inputs.map((t) => t.trivia + t.value).join("");
5767
const nextToken = source[position];

lib/productions/argument.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-check
2-
31
import { Base } from "./base.js";
42
import { Default } from "./default.js";
53
import { ExtendedAttributes } from "./extended-attributes.js";
@@ -18,7 +16,7 @@ import {
1816

1917
export class Argument extends Base {
2018
/**
21-
* @param {import("../tokeniser").Tokeniser} tokeniser
19+
* @param {import("../tokeniser.js").Tokeniser} tokeniser
2220
*/
2321
static parse(tokeniser) {
2422
const start_position = tokeniser.position;

lib/productions/array-base.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-check
2-
31
export class ArrayBase extends Array {
42
constructor({ source, tokens }) {
53
super();

lib/productions/attribute.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-check
2-
31
import { validationError } from "../error.js";
42
import { idlTypeIncludesDictionary } from "../validators/helpers.js";
53
import { Base } from "./base.js";

lib/productions/base.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// @ts-check
2-
31
export class Base {
42
/**
53
* @param {object} initializer

lib/productions/callback-interface.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
// @ts-check
2-
31
import { Container } from "./container.js";
42
import { Operation } from "./operation.js";
53
import { Constant } from "./constant.js";
64

75
export class CallbackInterface extends Container {
86
/**
9-
* @param {import("../tokeniser").Tokeniser} tokeniser
7+
* @param {import("../tokeniser.js").Tokeniser} tokeniser
108
*/
119
static parse(tokeniser, callback, { partial = null } = {}) {
1210
const tokens = { callback };

lib/productions/constructor.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { argument_list, autoParenter } from "./helpers.js";
33

44
export class Constructor extends Base {
55
/**
6-
* @param {import("../tokeniser").Tokeniser} tokeniser
6+
* @param {import("../tokeniser.js").Tokeniser} tokeniser
77
*/
88
static parse(tokeniser) {
99
const base = tokeniser.consume("constructor");
@@ -31,9 +31,6 @@ export class Constructor extends Base {
3131
}
3232

3333
*validate(defs) {
34-
if (this.idlType) {
35-
yield* this.idlType.validate(defs);
36-
}
3734
for (const argument of this.arguments) {
3835
yield* argument.validate(defs);
3936
}

lib/productions/container.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ function inheritance(tokeniser) {
1818

1919
export class Container extends Base {
2020
/**
21-
* @template T
2221
* @param {import("../tokeniser.js").Tokeniser} tokeniser
23-
* @param {T} instance
22+
* @param {*} instance TODO: This should be {T extends Container}, but see https://github.com/microsoft/TypeScript/issues/4628
2423
* @param {*} args
2524
*/
2625
static parse(tokeniser, instance, { inheritable, allowedMembers }) {

0 commit comments

Comments
 (0)