Skip to content

Commit

Permalink
(chore) clean up types a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Dec 23, 2020
1 parent 331c65f commit 82f7a68
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

/**
Expand Down
21 changes: 14 additions & 7 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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.
/// <reference lib="dom" />

Expand Down Expand Up @@ -77,6 +79,7 @@ interface HighlightResult {
errorRaised? : Error
// * for auto-highlight
second_best? : Omit<HighlightResult, 'second_best'>
code?: string
}
interface AutoHighlightResult extends HighlightResult {}

Expand All @@ -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 {
Expand Down Expand Up @@ -162,6 +168,7 @@ interface LanguageDetail {
exports?: any,
classNameAliases?: Record<string, string>
compilerExtensions?: CompilerExt[]
supersetOf?: string
}

type Language = LanguageDetail & Partial<Mode>
Expand Down

0 comments on commit 82f7a68

Please sign in to comment.