Skip to content

Commit c836e3a

Browse files
authored
(parser/docs) Add jsdoc annotations and TypeScript type file (#2517)
Adds JSDoc annotations and a .tsconfig that allows TypeScript to be run in it's "allowJS" mode and apply type and sanity checking to JavaScript code also. See Type Checking JavaScript Files. I've been using TypeScript a lot lately and finding it very beneficial and wanted to get those same benefits here but without converting the whole project to TypeScript. It was rough at the beginning but now that this is finished I think it's about 80%-90% of the benefits without any of the TS compilation pipeline. The big difference in being JSDoc for adding typing information vs inline types with TypeScript. Should be super helpful for maintainers using an editor with tight TypeScript integration and the improved docs/comments should help everyone else. - Adds types/index.d.ts to NPM build (should be useful for TypeScript peeps) - Improves documentation of many functions - Adds JSDoc annotations to almost all functions - Adds JSDoc type annotations to variables that can't be inferred - Refactors a few smaller things to allow the TypeScript compiler to better infer what is happening (and usually also made the code clearer)
1 parent c5cdc1c commit c836e3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1015
-174
lines changed

.eslintrc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ module.exports = {
1717
"ecmaVersion": 2018,
1818
"sourceType": "module"
1919
},
20+
"parser": '@typescript-eslint/parser',
21+
"plugins": [
22+
"@typescript-eslint"
23+
],
2024
"rules": {
2125
"array-callback-return": "error",
2226
"block-scoped-var": "error",
@@ -27,7 +31,7 @@ module.exports = {
2731
// for now ignore diff between types of quoting
2832
"quotes": "off",
2933
// this is the style we are already using
30-
"operator-linebreak": ["error","after", { "overrides": { "?": "after", ":": "after" } }],
34+
"operator-linebreak": ["error","before", { "overrides": { "?": "after", ":": "after", "+": "after" } }],
3135
// sometimes we declare variables with extra spacing
3236
"indent": ["error", 2, {"VariableDeclarator":2}],
3337
// seems like a good idea not to use explicit undefined

docs/api.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ Applies highlighting to all ``<pre><code>...</code></pre>`` blocks on a page.
101101
Attaches highlighting to the page load event.
102102

103103

104-
``registerLanguage(name, language)``
104+
``registerLanguage(languageName, languageDefinition)``
105105
------------------------------------
106106

107107
Adds new language to the library under the specified name. Used mostly internally.
108108

109-
* ``name``: a string with the name of the language being registered
110-
* ``language``: a function that returns an object which represents the
109+
* ``languageName``: a string with the name of the language being registered
110+
* ``languageDefinition``: a function that returns an object which represents the
111111
language definition. The function is passed the ``hljs`` object to be able
112112
to use common regular expressions defined within it.
113113

package-lock.json

Lines changed: 119 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
"url": "git://github.com/highlightjs/highlight.js.git"
2222
},
2323
"main": "./lib/index.js",
24+
"types": "./types/index.d.ts",
2425
"scripts": {
2526
"mocha": "mocha",
26-
2727
"build_and_test": "npm run build && npm run test",
2828
"build": "node ./tools/build.js -t node",
2929
"build-cdn": "node ./tools/build.js -t cdn",
3030
"build-browser": "node ./tools/build.js -t browser :common",
31-
3231
"test": "mocha --globals document test",
3332
"test-markup": "mocha --globals document test/markup",
3433
"test-detect": "mocha --globals document test/detect",
@@ -38,6 +37,8 @@
3837
"node": "*"
3938
},
4039
"devDependencies": {
40+
"@typescript-eslint/eslint-plugin": "^2.32.0",
41+
"@typescript-eslint/parser": "^2.32.0",
4142
"clean-css": "^4.2.1",
4243
"cli-table": "^0.3.1",
4344
"colors": "^1.1.2",
@@ -62,7 +63,8 @@
6263
"rollup-plugin-json": "^4.0.0",
6364
"should": "^13.2.3",
6465
"terser": "^4.3.9",
65-
"tiny-worker": "^2.3.0"
66+
"tiny-worker": "^2.3.0",
67+
"typescript": "^4.0.0-dev.20200512"
6668
},
6769
"dependencies": {}
6870
}

0 commit comments

Comments
 (0)