From 82f7a68cef989d2de3aa2b02faf2f80f6ce7ee60 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Wed, 23 Dec 2020 12:02:03 -0500 Subject: [PATCH] (chore) clean up types a bit --- src/highlight.js | 2 +- src/lib/logger.js | 5 +++-- types/index.d.ts | 21 ++++++++++++++------- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/highlight.js b/src/highlight.js index e525d94354..e0406d91eb 100644 --- a/src/highlight.js +++ b/src/highlight.js @@ -107,7 +107,7 @@ const HLJS = function(hljs) { * @property {boolean} illegal - indicates whether any illegal matches were found */ function highlight(languageName, code, ignoreIllegals, continuation) { - /** @type {{ code: string, language: string, result?: any }} */ + /** @type {BeforeHighlightContext} */ const context = { code, language: languageName diff --git a/src/lib/logger.js b/src/lib/logger.js index e5ccce4493..d102f74aea 100644 --- a/src/lib/logger.js +++ b/src/lib/logger.js @@ -14,9 +14,10 @@ export const error = (message) => { /** * @param {string} message + * @param {any} args */ -export const warn = (message) => { - console.log(`WARN: ${message}`); +export const warn = (message, ...args) => { + console.log(`WARN: ${message}`, ...args); }; /** diff --git a/types/index.d.ts b/types/index.d.ts index c66773faae..fa5b06f9bf 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,3 +1,5 @@ +/* eslint-disable no-unused-vars */ +/* eslint-disable no-use-before-define */ // For TS consumers who use Node and don't have dom in their tsconfig lib, import the necessary types here. /// @@ -77,6 +79,7 @@ interface HighlightResult { errorRaised? : Error // * for auto-highlight second_best? : Omit + code?: string } interface AutoHighlightResult extends HighlightResult {} @@ -86,14 +89,17 @@ interface illegalData { mode: CompiledMode } -type PluginEvent = - 'before:highlight' - | 'after:highlight' - | 'before:highlightBlock' - | 'after:highlightBlock' - +type BeforeHighlightContext = { + code: string, + language: string, + result?: HighlightResult +} +type PluginEvent = keyof HLJSPlugin; type HLJSPlugin = { - [K in PluginEvent]? : any + 'after:highlight'?: (result: HighlightResult) => void, + 'before:highlight'?: (context: BeforeHighlightContext) => void, + 'after:highlightBlock'?: (data: { result: HighlightResult}) => void, + 'before:highlightBlock'?: (data: { block: Element, language: string}) => void, } interface EmitterConstructor { @@ -162,6 +168,7 @@ interface LanguageDetail { exports?: any, classNameAliases?: Record compilerExtensions?: CompilerExt[] + supersetOf?: string } type Language = LanguageDetail & Partial