Skip to content

Commit

Permalink
update to typescript v5
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Mar 31, 2023
1 parent 4142011 commit cca9c82
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 60 deletions.
24 changes: 18 additions & 6 deletions bin/gendocs.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

// @ts-ignore
import jsdoc from 'jsdoc-api'
import fs from 'fs'
import * as fs from 'fs'

const firstTagContentRegex = /<\w>([^<]+)<\/\w>([^]*)/
const jsdocReturnRegex = /\* @return {(.*)}/
Expand All @@ -10,15 +10,21 @@ const files = fs.readdirSync('./').filter(file => /(?<!(test|config))\.js$/.test

const _ltregex = /</g
const _rtregex = />/g
/**
* @param {string} s
*/
const toSafeHtml = s => s.replace(_ltregex, '&lt;').replace(_rtregex, '&gt;')

const READMEcontent = fs.readFileSync('./README.md', 'utf8')

jsdoc.explain({
files,
configure: '.jsdoc.json'
}).then(json => {
}).then(/** @param {Array<any>} json */ json => {
const strBuilder = []
/**
* @type {Object<string, { items: Array<any>, name: string, description: string }>}
*/
const modules = {}
json.forEach(item => {
if (item.meta && item.meta.filename) {
Expand All @@ -31,6 +37,9 @@ jsdoc.explain({
}
}
})
/**
* @type {Object<string,string>}
*/
const classDescriptions = {}
for (const fileName in modules) {
const mod = modules[fileName]
Expand Down Expand Up @@ -68,16 +77,19 @@ jsdoc.explain({
}
// eslint-disable-next-line
case 'function': {
/**
* @param {string} name
*/
const getOriginalParamTypeDecl = name => {
const regval = new RegExp('@param {(.*)} \\[?' + name + '\\]?[^\\w]*').exec(item.comment)
return regval ? regval[1] : null
}
if (item.params == null && item.returns == null) {
break
}
const paramVal = (item.params || []).map(ret => `${ret.name}: ${getOriginalParamTypeDecl(ret.name) || ret.type.names.join('|')}`).join(', ')
const paramVal = (item.params || []).map(/** @param {any} ret */ ret => `${ret.name}: ${getOriginalParamTypeDecl(ret.name) || ret.type.names.join('|')}`).join(', ')
const evalReturnRegex = jsdocReturnRegex.exec(item.comment)
const returnVal = evalReturnRegex ? `: ${evalReturnRegex[1]}` : (item.returns ? item.returns.map(r => r.type.names.join('|')).join('|') : '')
const returnVal = evalReturnRegex ? `: ${evalReturnRegex[1]}` : (item.returns ? item.returns.map(/** @param {any} r */ r => r.type.names.join('|')).join('|') : '')
strBuilder.push(`<b><code>${item.kind === 'class' ? 'new ' : ''}${item.longname.slice(7)}(${toSafeHtml(paramVal)})${toSafeHtml(returnVal)}</code></b><br>`)
const desc = item.description || item.classdesc || classDescriptions[item.longname] || null
if (desc) {
Expand All @@ -87,7 +99,7 @@ jsdoc.explain({
}
case 'member': {
if (item.type) {
strBuilder.push(`<b><code>${item.longname.slice(7)}: ${toSafeHtml(jsdocTypeRegex.exec(item.comment)[1])}</code></b><br>`)
strBuilder.push(`<b><code>${item.longname.slice(7)}: ${toSafeHtml(/** @type {RegExpExecArray} */ (jsdocTypeRegex.exec(item.comment))[1])}</code></b><br>`)
if (item.description) {
strBuilder.push(`<dd>${item.description}</dd>`)
}
Expand Down
54 changes: 31 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"jsdoc-plugin-typescript": "^2.0.6",
"rollup": "^2.42.1",
"standard": "^14.3.4",
"typescript": "^4.2.3"
"typescript": "^5.0.3"
},
"scripts": {
"clean": "rm -rf dist *.d.ts */*.d.ts *.d.ts.map */*.d.ts.map",
Expand Down
29 changes: 13 additions & 16 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es2018",
"lib": ["es2018", "dom"], /* Specify library files to be included in the compilation. */
"allowJs": true, /* Allow javascript files to be compiled. */
"checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
// "outFile": "./index.js", /* Concatenate and emit output to single file. */
"outDir": "dist", // this is overritten by `npm run types`
"baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"target": "ES2020",
"lib": ["ES2020", "dom"],
"module": "ES2020",
"allowJs": true,
"checkJs": true,
"declaration": true,
"declarationMap": true,
"outDir": "./dist",
"baseUrl": "./",
"rootDir": "./",
"emitDeclarationOnly": true,
"strict": true,
"noImplicitAny": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
"moduleResolution": "nodenext"
},
"include": ["./*.js"],
"exclude": ["./dist"]
"include": ["./**/*.js"],
"exclude": ["./dist/**/*"]
}
4 changes: 2 additions & 2 deletions y-keyvalue.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class YKeyValue extends Observable {
*/
const itemsToRemove = new Set()
const vals = yarray.toArray()
this.doc.transact(tr => {
this.doc.transact(_tr => {
/**
* Iterate from right to left and update the map while we find the items in addedVals
*/
Expand Down Expand Up @@ -143,7 +143,7 @@ export class YKeyValue extends Observable {
* @param {T} val
*/
set (key, val) {
this.doc.transact(tr => {
this.doc.transact(_tr => {
// if this value existed before, we will delete it first
if (this.map.has(key)) {
this.delete(key)
Expand Down
24 changes: 12 additions & 12 deletions y-multidoc-undomanager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import * as t from 'lib0/testing'
import { YMultiDocUndoManager } from './y-multidoc-undomanager.js'

/**
* @param {t.TestCase} tc
* @param {t.TestCase} _tc
*/
export const testUndo = tc => {
export const testUndo = _tc => {
const um = new YMultiDocUndoManager()
const ydoc1 = new Y.Doc()
const ydoc2 = new Y.Doc()
Expand Down Expand Up @@ -47,16 +47,16 @@ export const testUndo = tc => {
}

/**
* @param {t.TestCase} tc
* @param {t.TestCase} _tc
*/
export const testUndoMap = tc => {
export const testUndoMap = _tc => {
const ydoc1 = new Y.Doc()
const ymap = ydoc1.getMap()
const um = new YMultiDocUndoManager([ymap], {
trackedOrigins: new Set(['this-client'])
})

ydoc1.transact(tr => {
ydoc1.transact(_tr => {
ymap.set('a', 1)
}, 'this-client')

Expand All @@ -68,9 +68,9 @@ export const testUndoMap = tc => {
}

/**
* @param {t.TestCase} tc
* @param {t.TestCase} _tc
*/
export const testUndoEvents = tc => {
export const testUndoEvents = _tc => {
const undoManager = new YMultiDocUndoManager()
const ydoc1 = new Y.Doc()
const text0 = ydoc1.getText()
Expand All @@ -83,7 +83,7 @@ export const testUndoEvents = tc => {
t.assert(event.changedParentTypes != null && event.changedParentTypes.has(text0))
event.stackItem.meta.set('test', counter++)
})
undoManager.on('stack-item-updated', /** @param {any} event */ event => {
undoManager.on('stack-item-updated', /** @param {any} _event */ _event => {
itemUpdated = true
})
undoManager.on('stack-item-popped', /** @param {any} event */ event => {
Expand All @@ -103,9 +103,9 @@ export const testUndoEvents = tc => {
}

/**
* @param {t.TestCase} tc
* @param {t.TestCase} _tc
*/
export const testUndoAfterChangeAfterUndo = tc => {
export const testUndoAfterChangeAfterUndo = _tc => {
const um = new YMultiDocUndoManager([], { captureTimeout: -1 })
const ydoc1 = new Y.Doc()
const ytype1 = ydoc1.getText()
Expand Down Expand Up @@ -134,9 +134,9 @@ export const testUndoAfterChangeAfterUndo = tc => {
}

/**
* @param {t.TestCase} tc
* @param {t.TestCase} _tc
*/
export const testAfterDestroy = tc => {
export const testAfterDestroy = _tc => {
const um = new YMultiDocUndoManager([], { captureTimeout: -1 })
const ydoc1 = new Y.Doc()
const ytype1 = ydoc1.getText()
Expand Down

0 comments on commit cca9c82

Please sign in to comment.