Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

feat: Bundle JSDoc-built TypeScript declaration file #34

Merged
merged 16 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
9 changes: 9 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
"sourceType": "module",
"ecmaVersion": 2020
},
"settings": {
"jsdoc": {
"mode": "typescript",
"preferredTypes": {
brettz9 marked this conversation as resolved.
Show resolved Hide resolved
"Object": "object",
"object<>": "Object"
}
}
},
"overrides": [
{
"files": ["*.cjs"],
Expand Down
15 changes: 10 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
*/
import KEYS from "./visitor-keys.js";

/**
* @typedef {{ [type: string]: ReadonlyArray<string> }} KeysStrict
* @typedef {{ readonly [type: string]: ReadonlyArray<string> }} KeysStrictReadonly
brettz9 marked this conversation as resolved.
Show resolved Hide resolved
*/

// List to ignore keys.
const KEY_BLACKLIST = new Set([
"parent",
Expand All @@ -22,8 +27,8 @@ function filterKey(key) {

/**
* Get visitor keys of a given node.
* @param {Object} node The AST node to get keys.
* @returns {string[]} Visitor keys of the node.
* @param {object} node The AST node to get keys.
* @returns {readonly string[]} Visitor keys of the node.
*/
export function getKeys(node) {
return Object.keys(node).filter(filterKey);
Expand All @@ -33,11 +38,11 @@ export function getKeys(node) {
// eslint-disable-next-line valid-jsdoc
/**
* Make the union set with `KEYS` and given keys.
* @param {Object} additionalKeys The additional keys.
* @returns {{ [type: string]: string[] | undefined }} The union set.
* @param {KeysStrictReadonly} additionalKeys The additional keys.
* @returns {KeysStrictReadonly} The union set.
*/
export function unionWith(additionalKeys) {
const retv = Object.assign({}, KEYS);
const retv = /** @type {KeysStrict} */ (Object.assign({}, KEYS));

for (const type of Object.keys(additionalKeys)) {
if (Object.prototype.hasOwnProperty.call(retv, type)) {
Expand Down
7 changes: 7 additions & 0 deletions lib/visitor-keys.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* @typedef {{ readonly [type: string]: ReadonlyArray<string> }} KeysLooseReadonly
*/
brettz9 marked this conversation as resolved.
Show resolved Hide resolved

/**
* @type {KeysLooseReadonly}
*/
const KEYS = {
AssignmentExpression: [
"left",
Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "Constants and utilities about visitor keys to traverse AST.",
"type": "module",
"main": "dist/eslint-visitor-keys.cjs",
"types": "./dist/index.d.ts",
"exports": {
".": [
{
Expand All @@ -15,6 +16,8 @@
"./package.json": "./package.json"
},
"files": [
"dist/index.d.ts",
"dist/visitor-keys.d.ts",
"dist/eslint-visitor-keys.cjs",
"lib"
],
Expand All @@ -30,12 +33,14 @@
"eslint-release": "^3.2.0",
"mocha": "^9.0.1",
"opener": "^1.5.2",
"rollup": "^2.52.1"
"rollup": "^2.52.1",
"typescript": "^4.6.0-dev.20220206"
brettz9 marked this conversation as resolved.
Show resolved Hide resolved
},
"scripts": {
"prepare": "npm run build",
"prepare": "npm run build && npm run tsc",
brettz9 marked this conversation as resolved.
Show resolved Hide resolved
"build": "rollup -c",
"lint": "eslint .",
"tsc": "tsc",
"test": "mocha tests/lib/**/*.cjs && c8 mocha tests/lib/**/*.js",
"coverage": "c8 report --reporter lcov && opener coverage/lcov-report/index.html",
"generate-release": "eslint-generate-release",
Expand Down
19 changes: 19 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"lib": ["es2020"],
"moduleResolution": "nodenext",
"module": "esnext",
"resolveJsonModule": true,
"allowJs": true,
"checkJs": true,
"noEmit": false,
"declaration": true,
"declarationMap": true,
"emitDeclarationOnly": true,
"strict": true,
"target": "es5",
brettz9 marked this conversation as resolved.
Show resolved Hide resolved
"outDir": "dist"
},
"include": ["lib/**/*.js"],
"exclude": ["node_modules"]
}