Force `import type` to guarantee import removal

This commit is contained in:
RunDevelopment 2023-05-30 20:25:15 +02:00
parent 78cbfe8279
commit 07dfbf5d5a
50 changed files with 95 additions and 82 deletions

View File

@ -184,6 +184,10 @@ module.exports = {
},
'extendDefaults': true
}
],
'@typescript-eslint/consistent-type-imports': [
'warn',
{ disallowTypeAnnotations: true }
]
}
},

View File

@ -2,12 +2,15 @@ import { getLanguage, setLanguage } from '../shared/dom-util';
import { rest, tokenize } from '../shared/symbols';
import { htmlEncode } from '../shared/util';
import { HookState } from './hook-state';
import { HookEnvMap, Hooks } from './hooks';
import { LinkedList, LinkedListHeadNode, LinkedListMiddleNode, LinkedListTailNode } from './linked-list';
import { Hooks } from './hooks';
import { LinkedList } from './linked-list';
import { Registry } from './registry';
import { Token, TokenStream } from './token';
import { Token } from './token';
import type { KnownPlugins } from '../known-plugins';
import type { Grammar, GrammarToken, GrammarTokens } from '../types';
import type { HookEnvMap } from './hooks';
import type { LinkedListHeadNode, LinkedListMiddleNode, LinkedListTailNode } from './linked-list';
import type { TokenStream } from './token';
/**
* Prism: Lightweight, robust, elegant syntax highlighting

View File

@ -1,6 +1,6 @@
import { extend } from '../shared/language-util';
import { forEach, kebabToCamelCase } from '../shared/util';
import { ComponentProto, Grammar } from '../types';
import type { ComponentProto, Grammar } from '../types';
import type { Prism } from './prism';
interface Entry {

View File

@ -1,13 +1,13 @@
import { Autoloader } from './plugins/autoloader/prism-autoloader';
import { CustomClass } from './plugins/custom-class/prism-custom-class';
import { FileHighlight } from './plugins/file-highlight/prism-file-highlight';
import { FilterHighlightAll } from './plugins/filter-highlight-all/prism-filter-highlight-all';
import { JsonpHighlight } from './plugins/jsonp-highlight/prism-jsonp-highlight';
import { LineHighlight } from './plugins/line-highlight/prism-line-highlight';
import { LineNumbers } from './plugins/line-numbers/prism-line-numbers';
import { NormalizeWhitespace } from './plugins/normalize-whitespace/prism-normalize-whitespace';
import { PreviewerCollection } from './plugins/previewers/prism-previewers';
import { Toolbar } from './plugins/toolbar/prism-toolbar';
import type { Autoloader } from './plugins/autoloader/prism-autoloader';
import type { CustomClass } from './plugins/custom-class/prism-custom-class';
import type { FileHighlight } from './plugins/file-highlight/prism-file-highlight';
import type { FilterHighlightAll } from './plugins/filter-highlight-all/prism-filter-highlight-all';
import type { JsonpHighlight } from './plugins/jsonp-highlight/prism-jsonp-highlight';
import type { LineHighlight } from './plugins/line-highlight/prism-line-highlight';
import type { LineNumbers } from './plugins/line-numbers/prism-line-numbers';
import type { NormalizeWhitespace } from './plugins/normalize-whitespace/prism-normalize-whitespace';
import type { PreviewerCollection } from './plugins/previewers/prism-previewers';
import type { Toolbar } from './plugins/toolbar/prism-toolbar';
declare interface KnownPlugins {
autoloader: Autoloader;

View File

@ -1,4 +1,4 @@
import type { LanguageProto } from '../types';
import type { Grammar, LanguageProto } from '../types';
export default {
id: 'bash',
@ -17,7 +17,7 @@ export default {
inside: 'bash'
};
const commandSubstitutionInside: import('../types').Grammar = {
const commandSubstitutionInside: Grammar = {
'variable': /^\$\(|^`|\)$|`$/
};

View File

@ -1,6 +1,6 @@
import { Token } from '../core';
import { withoutTokenize } from '../shared/language-util';
import { tokenize } from '../shared/symbols';
import type { Token } from '../core';
import type { LanguageProto } from '../types';
export default {

View File

@ -1,8 +1,9 @@
import { Token, TokenStream, getTextContent } from '../core/token';
import { Token, getTextContent } from '../core/token';
import { insertBefore, withoutTokenize } from '../shared/language-util';
import { rest, tokenize } from '../shared/symbols';
import javascript from './prism-javascript';
import markup from './prism-markup';
import type { TokenStream } from '../core/token';
import type { Grammar, GrammarToken, LanguageProto } from '../types';
function stringifyToken(token: string | Token | TokenStream | undefined): string {

View File

@ -1,4 +1,4 @@
import type { LanguageProto } from '../types';
import type { GrammarToken, LanguageProto } from '../types';
export default {
id: 'pascal',
@ -28,7 +28,7 @@ export default {
pattern: /(\basm\b)[\s\S]+?(?=\bend\s*[;[])/i,
lookbehind: true,
greedy: true,
inside: null as import('../types').GrammarToken['inside'] // see below
inside: null as GrammarToken['inside'] // see below
},
'keyword': [
{

View File

@ -1,4 +1,4 @@
import type { LanguageProto } from '../types';
import type { Grammar, LanguageProto } from '../types';
export default {
id: 'pascaligo',
@ -8,7 +8,7 @@ export default {
const braces = /\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\)/.source;
const type = /(?:\b\w+(?:<braces>)?|<braces>)/.source.replace(/<braces>/g, () => braces);
const classNameInside: import('../types').Grammar = {};
const classNameInside: Grammar = {};
const pascaligo = {
'comment': /\(\*[\s\S]+?\*\)|\/\/.*/,

View File

@ -2,7 +2,7 @@ import { insertBefore } from '../shared/language-util';
import { rest } from '../shared/symbols';
import javascript from './prism-javascript';
import markup from './prism-markup';
import type { LanguageProto } from '../types';
import type { GrammarTokens, LanguageProto } from '../types';
export default {
id: 'pug',
@ -169,7 +169,7 @@ export default {
{ filter: 'sass', language: 'scss' },
'stylus'
];
const all_filters: import('../types').GrammarTokens = {};
const all_filters: GrammarTokens = {};
for (const filterItem of filters) {
const { filter, language } = typeof filterItem === 'string' ? { filter: filterItem, language: filterItem } : filterItem;
all_filters['filter-' + filter] = {

View File

@ -1,4 +1,4 @@
import type { LanguageProto } from '../types';
import type { Grammar, LanguageProto } from '../types';
export default {
id: 'web-idl',
@ -14,7 +14,7 @@ export default {
/(?!(?:unrestricted|unsigned)\b)/.source + id + /(?:\s*<(?:[^<>]|<[^<>]*>)*>)?/.source +
')' + /(?:\s*\?)?/.source;
const typeInside: import('../types').Grammar = {};
const typeInside: Grammar = {};
const webIdl = {
'comment': {

View File

@ -1,7 +1,8 @@
import { Token, TokenStream, getTextContent } from '../core/token';
import { Token, getTextContent } from '../core/token';
import { withoutTokenize } from '../shared/language-util';
import { tokenize } from '../shared/symbols';
import markup from './prism-markup';
import type { TokenStream } from '../core/token';
import type { Grammar, GrammarToken, LanguageProto } from '../types';
function walkTokens(tokens: TokenStream) {

View File

@ -1,6 +1,6 @@
import { addHooks } from '../../shared/hooks-util';
import { tokenizeStrings } from '../../shared/tokenize-strings';
import { PluginProto } from '../../types';
import type { PluginProto } from '../../types';
export default {
id: 'autolinker',

View File

@ -1,8 +1,8 @@
import { getParentPre } from '../../shared/dom-util';
import { addHooks } from '../../shared/hooks-util';
import { htmlEncode } from '../../shared/util';
import { PluginProto } from '../../types';
import type { StateKey } from '../../core/hook-state';
import type { PluginProto } from '../../types';
const CLASS_PATTERN = /(?:^|\s)command-line(?:\s|$)/;
const PROMPT_CLASS = 'command-line-prompt';

View File

@ -1,4 +1,4 @@
import { PluginProto } from '../../types';
import type { PluginProto } from '../../types';
type ClassMapper = (className: string) => string;
type ClassAdder = (env: ClassAdderEnvironment) => undefined | string | string[];

View File

@ -1,5 +1,5 @@
import { tokenizeStrings } from '../../shared/tokenize-strings';
import { PluginProto } from '../../types';
import type { PluginProto } from '../../types';
export default {
id: 'data-uri-highlight',

View File

@ -1,8 +1,9 @@
import { BeforeSanityCheckEnv, BeforeTokenizeEnv } from '../../core/hooks';
import { Token, TokenStream, getTextContent } from '../../core/token';
import { Token, getTextContent } from '../../core/token';
import diff, { PREFIXES } from '../../languages/prism-diff';
import { addHooks } from '../../shared/hooks-util';
import { PluginProto } from '../../types';
import type { BeforeSanityCheckEnv, BeforeTokenizeEnv } from '../../core/hooks';
import type { TokenStream } from '../../core/token';
import type { PluginProto } from '../../types';
export default {
id: 'diff-highlight',

View File

@ -1,6 +1,6 @@
import { getParentPre } from '../../shared/dom-util';
import { PluginProto } from '../../types';
import toolbar from '../toolbar/prism-toolbar';
import type { PluginProto } from '../../types';
export default {
id: 'download-button',

View File

@ -1,7 +1,7 @@
import { setLanguage } from '../../shared/dom-util';
import { addHooks } from '../../shared/hooks-util';
import { PluginProto } from '../../types';
import type { Prism } from '../../core';
import type { PluginProto } from '../../types';
const FAILURE_MESSAGE = (status: number, message: string) => {
return `✖ Error ${status} while fetching file: ${message}`;

View File

@ -1,5 +1,5 @@
import { getLanguage } from '../../shared/dom-util';
import { PluginProto } from '../../types';
import type { PluginProto } from '../../types';
type Condition = (value: { element: Element; language: string }) => boolean;

View File

@ -1,4 +1,4 @@
import { PluginProto } from '../../types';
import type { PluginProto } from '../../types';
export default {
id: 'highlight-keywords',

View File

@ -1,6 +1,6 @@
import cssExtras from '../../languages/prism-css-extras';
import { MARKUP_TAG } from '../../shared/languages/patterns';
import { PluginProto } from '../../types';
import type { PluginProto } from '../../types';
const HTML_TAG = RegExp(MARKUP_TAG, 'g');

View File

@ -1,6 +1,6 @@
import { Prism } from '../../core';
import { addHooks } from '../../shared/hooks-util';
import { PluginProto } from '../../types';
import type { Prism } from '../../core';
import type { PluginProto } from '../../types';
function getGlobal(): Record<string, unknown> {
return typeof window === 'object' ? window as never : {};

View File

@ -1,7 +1,7 @@
import { StateKey } from '../../core/hook-state';
import { isActive } from '../../shared/dom-util';
import { addHooks } from '../../shared/hooks-util';
import { PluginProto } from '../../types';
import type { StateKey } from '../../core/hook-state';
import type { PluginProto } from '../../types';
function isElement(child: ChildNode): child is Element {
return child.nodeType === 1;

View File

@ -1,8 +1,8 @@
import { Prism } from '../../core';
import { isActive } from '../../shared/dom-util';
import { combineCallbacks } from '../../shared/hooks-util';
import { lazy, noop } from '../../shared/util';
import { PluginProto } from '../../types';
import type { Prism } from '../../core';
import type { PluginProto } from '../../types';
const LINE_NUMBERS_CLASS = 'line-numbers';
const LINKABLE_LINE_NUMBERS_CLASS = 'linkable-line-numbers';

View File

@ -1,7 +1,7 @@
import { getParentPre, isActive } from '../../shared/dom-util';
import { combineCallbacks } from '../../shared/hooks-util';
import { isNonNull, noop } from '../../shared/util';
import { PluginProto } from '../../types';
import type { PluginProto } from '../../types';
/**
* Plugin name which is used as a class name for <pre> which is activating the plugin

View File

@ -1,5 +1,5 @@
import { getParentPre, isActive } from '../../shared/dom-util';
import { PluginProto } from '../../types';
import type { PluginProto } from '../../types';
export default {
id: 'match-braces',

View File

@ -1,5 +1,5 @@
import { getParentPre, isActive } from '../../shared/dom-util';
import { PluginProto } from '../../types';
import type { PluginProto } from '../../types';
function tabLength(str: string) {
let res = 0;

View File

@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import cssExtras from '../../languages/prism-css-extras';
import { forEach } from '../../shared/util';
import { PluginProto } from '../../types';
import type { PluginProto } from '../../types';
/**
* Returns the absolute X, Y offsets for an element

View File

@ -1,5 +1,5 @@
import { tokenizeStrings } from '../../shared/tokenize-strings';
import { PluginProto } from '../../types';
import type { PluginProto } from '../../types';
export default {
id: 'show-invisibles',

View File

@ -1,7 +1,7 @@
import { getParentPre } from '../../shared/dom-util';
import { getTitle } from '../../shared/meta/title-data';
import { PluginProto } from '../../types';
import toolbar from '../toolbar/prism-toolbar';
import type { PluginProto } from '../../types';
export default {
id: 'show-language',

View File

@ -1,7 +1,7 @@
import { CompleteEnv, HookCallback } from '../../core/hooks';
import { getParentPre } from '../../shared/dom-util';
import { noop } from '../../shared/util';
import { PluginProto } from '../../types';
import type { CompleteEnv, HookCallback } from '../../core/hooks';
import type { PluginProto } from '../../types';
/**
* Returns the callback order of the given element.

View File

@ -1,5 +1,5 @@
import treeview from '../../languages/prism-treeview';
import { PluginProto } from '../../types';
import type { PluginProto } from '../../types';
export default {
id: 'treeview-icons',

View File

@ -1,5 +1,5 @@
import { addHooks } from '../../shared/hooks-util';
import { PluginProto } from '../../types';
import type { PluginProto } from '../../types';
export default {
id: 'unescaped-markup',

View File

@ -1,5 +1,5 @@
import cssSelector from '../../languages/prism-css-selector';
import { PluginProto } from '../../types';
import type { PluginProto } from '../../types';
const htmlTags = new Set<string>([
'a', 'abbr', 'acronym', 'b', 'basefont', 'bdo', 'big', 'blink', 'cite', 'code', 'dfn', 'em', 'kbd', 'i',

View File

@ -1,4 +1,4 @@
import { HookCallback, HookEnvMap, Hooks } from '../core/hooks';
import type { HookCallback, HookEnvMap, Hooks } from '../core/hooks';
/**
* Returns a single function that calls all the given functions.

View File

@ -1,7 +1,8 @@
import { Token, TokenStream, getTextContent } from '../../core/token';
import { getTextContent } from '../../core/token';
import { withoutTokenize } from '../language-util';
import type { Prism } from '../../core';
import type { Registry } from '../../core/registry';
import type { Token, TokenStream } from '../../core/token';
import type { Grammar } from '../../types';
import type { tokenize } from '../symbols';

View File

@ -1,4 +1,4 @@
import { TokenStream } from '../core/token';
import type { TokenStream } from '../core/token';
/**
* Given a token stream and a tokenization function, this will tokenize all

View File

@ -1,4 +1,4 @@
import { KebabToCamelCase } from '../types';
import type { KebabToCamelCase } from '../types';
/**
* Returns a function that caches the result of the given supplier.

8
src/types.d.ts vendored
View File

@ -1,7 +1,7 @@
import { Prism } from './core/prism';
import { TokenStream } from './core/token';
import { KnownPlugins } from './known-plugins';
import { rest, tokenize } from './shared/symbols';
import type { Prism } from './core/prism';
import type { TokenStream } from './core/token';
import type { KnownPlugins } from './known-plugins';
import type { rest, tokenize } from './shared/symbols';
export interface GrammarOptions {
readonly getLanguage: (id: string) => Grammar;

View File

@ -1,7 +1,7 @@
import { assert } from 'chai';
import { Prism } from '../../src/core/prism';
import { Grammar } from '../../src/types';
import { simplify } from '../helper/token-stream-transformer';
import type { Grammar } from '../../src/types';
function testTokens({ grammar, code, expected }: { grammar: Grammar, code: string, expected: unknown }) {
const instance = new Prism();

View File

@ -1,7 +1,8 @@
import { KebabToCamelCase } from '../../src/types';
import { PrismDOM, PrismWindow, createPrismDOM } from './prism-loader';
import { createPrismDOM } from './prism-loader';
import { assertEqual, useSnapshot } from './snapshot';
import { formatHtml } from './util';
import type { KebabToCamelCase } from '../../src/types';
import type { PrismDOM, PrismWindow } from './prism-loader';
interface AssertOptions {
language?: string;

View File

@ -1,10 +1,10 @@
import { readdirSync } from 'fs';
import { JSDOM } from 'jsdom';
import { DOMWindow } from 'jsdom';
import path from 'path';
import { Prism } from '../../src/core/prism';
import { isNonNull, lazy, noop, toArray } from '../../src/shared/util';
import { LanguageProto, PluginProto } from '../../src/types';
import type { ComponentProto, LanguageProto, PluginProto } from '../../src/types';
import type { DOMWindow } from 'jsdom';
const SRC_DIR = path.join(__dirname, '../../src');
@ -38,7 +38,7 @@ async function getComponentUncached(id: string) {
return exports.default;
}
}
const componentCache = new Map<string, Promise<import('../../src/types').ComponentProto>>();
const componentCache = new Map<string, Promise<ComponentProto>>();
export function getComponent(id: string) {
let promise = componentCache.get(id);
if (promise === undefined) {

View File

@ -1,10 +1,10 @@
import { assert } from 'chai';
import fs from 'fs';
import { Prism } from '../../src/core';
import { TokenStream } from '../../src/core/token';
import { createInstance } from './prism-loader';
import * as TokenStreamTransformer from './token-stream-transformer';
import { formatHtml, getLeadingSpaces } from './util';
import type { Prism } from '../../src/core';
import type { TokenStream } from '../../src/core/token';
/**
* @param {string[]} languages

View File

@ -1,6 +1,6 @@
import * as Prettier from 'prettier';
import { RegExpParser } from 'regexpp';
import { Flags, Pattern } from 'regexpp/ast';
import type { Flags, Pattern } from 'regexpp/ast';
export interface LiteralAST {
pattern: Pattern;

View File

@ -1,9 +1,9 @@
import { assert } from 'chai';
import { Prism, Token } from '../src/core';
import { TokenStream } from '../src/core/token';
import { toArray } from '../src/shared/util';
import { createInstance, getComponent, getLanguageIds } from './helper/prism-loader';
import { prettyprint } from './helper/token-stream-transformer';
import type { Prism, Token } from '../src/core';
import type { TokenStream } from '../src/core/token';
// This is where you can exclude a language from the identifier test.

View File

@ -2,16 +2,17 @@ import { assert } from 'chai';
import { JS, NFA, Transformers, Words, combineTransformers, getIntersectionWordSets, isDisjointWith, transform } from 'refa';
import * as RAA from 'regexp-ast-analysis';
import { visitRegExpAST } from 'regexpp';
import { CapturingGroup, Element, Group, LookaroundAssertion, Node, Pattern } from 'regexpp/ast';
import * as scslre from 'scslre';
import { Prism } from '../src/core';
import { lazy, toArray } from '../src/shared/util';
import { Grammar, GrammarToken } from '../src/types';
import * as args from './helper/args';
import { createInstance, getComponent, getLanguageIds } from './helper/prism-loader';
import { TestCaseFile, parseLanguageNames } from './helper/test-case';
import { loadAllTests } from './helper/test-discovery';
import { BFS, BFSPathToPrismTokenPath, LiteralAST, PathItem, isRegExp, parseRegex } from './helper/util';
import { BFS, BFSPathToPrismTokenPath, isRegExp, parseRegex } from './helper/util';
import type { Prism } from '../src/core';
import type { Grammar, GrammarToken } from '../src/types';
import type { LiteralAST, PathItem } from './helper/util';
import type { CapturingGroup, Element, Group, LookaroundAssertion, Node, Pattern } from 'regexpp/ast';
/**
* A map from language id to a list of code snippets in that language.

View File

@ -1,6 +1,6 @@
import { assert } from 'chai';
import { createTestSuite } from '../../helper/prism-dom-util';
import { PrismDOM } from '../../helper/prism-loader';
import type { PrismDOM } from '../../helper/prism-loader';
describe('Keep Markup', () => {

View File

@ -1,7 +1,7 @@
import { assert } from 'chai';
import { knownTitles } from '../../../src/shared/meta/title-data';
import { createTestSuite } from '../../helper/prism-dom-util';
import { PrismDOM } from '../../helper/prism-loader';
import type { PrismDOM } from '../../helper/prism-loader';
describe('Show language', () => {

View File

@ -1,6 +1,6 @@
import { assert } from 'chai';
import { createTestSuite } from '../../helper/prism-dom-util';
import { PrismDOM } from '../../helper/prism-loader';
import type { PrismDOM } from '../../helper/prism-loader';
describe('Show language', () => {