Skip to content

Commit 82f7a68

Browse files
committed
(chore) clean up types a bit
1 parent 331c65f commit 82f7a68

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

src/highlight.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const HLJS = function(hljs) {
107107
* @property {boolean} illegal - indicates whether any illegal matches were found
108108
*/
109109
function highlight(languageName, code, ignoreIllegals, continuation) {
110-
/** @type {{ code: string, language: string, result?: any }} */
110+
/** @type {BeforeHighlightContext} */
111111
const context = {
112112
code,
113113
language: languageName

src/lib/logger.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ export const error = (message) => {
1414

1515
/**
1616
* @param {string} message
17+
* @param {any} args
1718
*/
18-
export const warn = (message) => {
19-
console.log(`WARN: ${message}`);
19+
export const warn = (message, ...args) => {
20+
console.log(`WARN: ${message}`, ...args);
2021
};
2122

2223
/**

types/index.d.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable no-unused-vars */
2+
/* eslint-disable no-use-before-define */
13
// For TS consumers who use Node and don't have dom in their tsconfig lib, import the necessary types here.
24
/// <reference lib="dom" />
35

@@ -77,6 +79,7 @@ interface HighlightResult {
7779
errorRaised? : Error
7880
// * for auto-highlight
7981
second_best? : Omit<HighlightResult, 'second_best'>
82+
code?: string
8083
}
8184
interface AutoHighlightResult extends HighlightResult {}
8285

@@ -86,14 +89,17 @@ interface illegalData {
8689
mode: CompiledMode
8790
}
8891

89-
type PluginEvent =
90-
'before:highlight'
91-
| 'after:highlight'
92-
| 'before:highlightBlock'
93-
| 'after:highlightBlock'
94-
92+
type BeforeHighlightContext = {
93+
code: string,
94+
language: string,
95+
result?: HighlightResult
96+
}
97+
type PluginEvent = keyof HLJSPlugin;
9598
type HLJSPlugin = {
96-
[K in PluginEvent]? : any
99+
'after:highlight'?: (result: HighlightResult) => void,
100+
'before:highlight'?: (context: BeforeHighlightContext) => void,
101+
'after:highlightBlock'?: (data: { result: HighlightResult}) => void,
102+
'before:highlightBlock'?: (data: { block: Element, language: string}) => void,
97103
}
98104

99105
interface EmitterConstructor {
@@ -162,6 +168,7 @@ interface LanguageDetail {
162168
exports?: any,
163169
classNameAliases?: Record<string, string>
164170
compilerExtensions?: CompilerExt[]
171+
supersetOf?: string
165172
}
166173

167174
type Language = LanguageDetail & Partial<Mode>

0 commit comments

Comments
 (0)