Skip to content

Commit eedc845

Browse files
LeaVerouDmitrySharabin
authored andcommitted
Remove known plugins + type safety
1 parent 564701b commit eedc845

File tree

21 files changed

+58
-70
lines changed

21 files changed

+58
-70
lines changed

eslint.config.mjs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const config = [
2727
languageOptions: {
2828
ecmaVersion: 'latest',
2929
sourceType: 'module',
30+
globals: {
31+
...globals.browser,
32+
...globals.node,
33+
},
3034
},
3135
rules: {
3236
'no-use-before-define': ['warn', { 'functions': false, 'classes': false }],
@@ -152,16 +156,6 @@ const config = [
152156
'@typescript-eslint/no-explicit-any': 'off',
153157
},
154158
},
155-
{
156-
// Core
157-
files: ['src/core/**/*.ts'],
158-
languageOptions: {
159-
globals: {
160-
...globals.browser,
161-
...globals.node,
162-
},
163-
},
164-
},
165159
{
166160
// Browser-specific parts
167161
files: ['src/auto-start.ts'],

scripts/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ async function buildTypes () {
331331
await mkdir('./types');
332332

333333
// Copy existing type definitions
334-
const typeFiles = ['types.d.ts', 'known-plugins.d.ts'];
334+
const typeFiles = ['types.d.ts'];
335335

336336
await Promise.all(
337337
typeFiles.map(file => copyFile(path.join(SRC_DIR, file), path.join('./types', file)))

src/core/classes/prism.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { highlightElement } from '../highlight-element';
44
import { Registry } from '../registry';
55
import { tokenize } from '../tokenize/tokenize';
66
import { Hooks } from './hooks';
7-
import type { KnownPlugins } from '../../known-plugins';
87
import type { Grammar } from '../../types';
98
import type { HighlightOptions } from '../highlight';
109
import type { HighlightAllOptions } from '../highlight-all';
@@ -18,7 +17,7 @@ import type { TokenStream } from './token';
1817
export default class Prism {
1918
hooks = new Hooks();
2019
components = new Registry(this);
21-
plugins: Partial<Record<string, unknown> & KnownPlugins> = {};
20+
plugins: Record<string, unknown> = {};
2221

2322
/**
2423
* See {@link highlightAll}.

src/known-plugins.d.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/languages/markdown.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { insertBefore, withoutTokenize } from '../util/language-util';
33
import markup from './markup';
44
import type { Grammar, GrammarToken, LanguageProto } from '../types';
55
import type { Prism } from '../core/prism';
6+
import type { Autoloader } from '../plugins/autoloader/prism-autoloader';
67

78
export default {
89
id: 'markdown',
@@ -360,7 +361,8 @@ export default {
360361
const id = `md-${new Date().valueOf()}-${Math.floor(Math.random() * 1e16)}`;
361362
env.attributes['id'] = id;
362363

363-
Prism.plugins.autoloader.loadLanguages(codeLang).then(
364+
const autoloader = Prism.plugins.autoloader as Autoloader;
365+
autoloader.loadLanguages(codeLang).then(
364366
() => {
365367
const element = document.getElementById(id);
366368
if (element) {

src/plugins/autoloader/prism-autoloader.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ export default {
146146
return;
147147
}
148148

149-
Prism.plugins.autoloader.loadLanguages(deps).then(
149+
const autoloader = Prism.plugins.autoloader as Autoloader;
150+
autoloader.loadLanguages(deps).then(
150151
() => Prism.highlightElement(element),
151152
(reason) => {
152153
console.error(`Failed to load languages (${deps.join(', ')}): ${String(reason)}`);

src/plugins/copy-to-clipboard/prism-copy-to-clipboard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import toolbar from '../toolbar/prism-toolbar';
22
import type { PluginProto } from '../../types';
3+
import type { Toolbar } from '../toolbar/prism-toolbar';
34

45
interface CopyInfo {
56
getText: () => string;
@@ -118,8 +119,7 @@ export default {
118119
id: 'copy-to-clipboard',
119120
require: toolbar,
120121
effect(Prism) {
121-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
122-
const toolbar = Prism.plugins.toolbar!;
122+
const toolbar = Prism.plugins.toolbar as Toolbar;
123123

124124
return toolbar.registerButton('copy-to-clipboard', (env) => {
125125
const element = env.element;

src/plugins/custom-class/prism-custom-class.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default {
5353
return new CustomClass();
5454
},
5555
effect(Prism) {
56-
const customClass = Prism.plugins.customClass;
56+
const customClass = Prism.plugins.customClass as CustomClass;
5757

5858
return Prism.hooks.add('wrap', (env) => {
5959
if (customClass['adder']) {

src/plugins/download-button/prism-download-button.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { getParentPre } from '../../shared/dom-util';
22
import toolbar from '../toolbar/prism-toolbar';
33
import type { PluginProto } from '../../types';
4+
import type { Toolbar } from '../toolbar/prism-toolbar';
45

56
export default {
67
id: 'download-button',
78
require: toolbar,
89
effect(Prism) {
9-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
10-
const toolbar = Prism.plugins.toolbar!;
10+
const toolbar = Prism.plugins.toolbar as Toolbar;
1111

1212
return toolbar.registerButton('download-file', (env) => {
1313
const pre = getParentPre(env.element);

src/plugins/file-highlight/prism-file-highlight.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { setLanguage } from '../../shared/dom-util';
22
import type { Prism } from '../../core';
33
import type { PluginProto } from '../../types';
4+
import type { Autoloader } from '../autoloader/prism-autoloader';
45

56
const FAILURE_MESSAGE = (status: number, message: string) => {
67
return `✖ Error ${status} while fetching file: ${message}`;
@@ -145,7 +146,7 @@ export default {
145146
setLanguage(pre, language);
146147

147148
// preload the language
148-
const autoloader = Prism.plugins.autoloader;
149+
const autoloader = Prism.plugins.autoloader as Autoloader;
149150
if (autoloader) {
150151
autoloader.preloadLanguages(language);
151152
}

0 commit comments

Comments
 (0)