Skip to content

Commit fc7d3e5

Browse files
LeaVerouDmitrySharabin
authored andcommitted
Move the Token class under the classes folder
1 parent 84dd295 commit fc7d3e5

File tree

15 files changed

+56
-22
lines changed

15 files changed

+56
-22
lines changed

src/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export { Prism } from './core/prism';
2-
export { Token } from './core/token';
2+
export { Token } from './core/classes/token';

src/core/token.ts renamed to src/core/classes/token.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
1-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2-
import type { Grammar, GrammarToken, TokenName } from '../types';
1+
type StandardTokenName =
2+
| 'atrule'
3+
| 'attr-name'
4+
| 'attr-value'
5+
| 'bold'
6+
| 'boolean'
7+
| 'builtin'
8+
| 'cdata'
9+
| 'char'
10+
| 'class-name'
11+
| 'comment'
12+
| 'constant'
13+
| 'deleted'
14+
| 'doctype'
15+
| 'entity'
16+
| 'function'
17+
| 'important'
18+
| 'inserted'
19+
| 'italic'
20+
| 'keyword'
21+
| 'namespace'
22+
| 'number'
23+
| 'operator'
24+
| 'prolog'
25+
| 'property'
26+
| 'punctuation'
27+
| 'regex'
28+
| 'selector'
29+
| 'string'
30+
| 'symbol'
31+
| 'tag'
32+
| 'url';
33+
34+
export type TokenName = (string & {}) | StandardTokenName;
335

436
export class Token {
537
/**
@@ -68,6 +100,8 @@ export class Token {
68100
}
69101
}
70102

103+
export default Token;
104+
71105
/**
72106
* A token stream is an array of strings and {@link Token Token} objects.
73107
*
@@ -77,7 +111,7 @@ export class Token {
77111
* 1. No adjacent strings.
78112
* 2. No empty strings.
79113
*
80-
* The only exception here is the token stream that only contains the empty string and nothing else.
114+
* The only exception here is the token stream that only contains the empty string and nothing else.
81115
*/
82116
export type TokenStream = (string | Token)[];
83117

src/core/hooks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Grammar, TokenName } from '../types';
22
import type { HookState } from './hook-state';
3-
import type { TokenStream } from './token';
3+
import type { TokenStream } from './classes/token';
44

55
export class Hooks {
66
// eslint-disable-next-line func-call-spacing

src/core/prism.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import { HookState } from './hook-state';
55
import { Hooks } from './hooks';
66
import { LinkedList } from './linked-list';
77
import { Registry } from './registry';
8-
import { Token } from './token';
8+
import { Token } from './classes/token';
99
import type { KnownPlugins } from '../known-plugins';
1010
import type { Grammar, GrammarToken, GrammarTokens, RegExpLike } from '../types';
1111
import type { HookEnvMap } from './hooks';
1212
import type { LinkedListHeadNode, LinkedListMiddleNode, LinkedListTailNode } from './linked-list';
13-
import type { TokenStream } from './token';
13+
import type { TokenStream } from './classes/token';
1414

1515
/**
1616
* Prism: Lightweight, robust, elegant syntax highlighting

src/languages/jsx.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Token, getTextContent } from '../core/token';
1+
import { getTextContent, Token } from '../core/classes/token';
22
import { insertBefore, withoutTokenize } from '../shared/language-util';
33
import { rest, tokenize } from '../shared/symbols';
44
import javascript from './javascript';
55
import markup from './markup';
6-
import type { TokenStream } from '../core/token';
6+
import type { TokenStream } from '../core/classes/token';
77
import type { Grammar, GrammarToken, LanguageProto } from '../types';
88

99
function stringifyToken (token: string | Token | TokenStream | undefined): string {

src/languages/markdown.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getTextContent } from '../core/token';
1+
import { getTextContent } from '../core/classes/token';
22
import { insertBefore, withoutTokenize } from '../shared/language-util';
33
import { tokenize } from '../shared/symbols';
44
import markup from './markup';

src/languages/naniscript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getTextContent } from '../core/token';
1+
import { getTextContent } from '../core/classes/token';
22
import { withoutTokenize } from '../shared/language-util';
33
import { tokenize } from '../shared/symbols';
44
import type { LanguageProto } from '../types';

src/languages/treeview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getTextContent } from '../core/token';
1+
import { getTextContent } from '../core/classes/token';
22
import { withoutTokenize } from '../shared/language-util';
33
import { tokenize } from '../shared/symbols';
44
import type { LanguageProto } from '../types';

src/languages/xquery.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Token, getTextContent } from '../core/token';
1+
import { getTextContent, Token } from '../core/classes/token';
22
import { withoutTokenize } from '../shared/language-util';
33
import { tokenize } from '../shared/symbols';
44
import markup from './markup';
5-
import type { TokenStream } from '../core/token';
5+
import type { TokenStream } from '../core/classes/token';
66
import type { Grammar, GrammarToken, LanguageProto } from '../types';
77

88
function walkTokens (tokens: TokenStream) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Token, getTextContent } from '../../core/token';
1+
import { Token, getTextContent } from '../../core/classes/token';
22
import diff, { PREFIXES } from '../../languages/diff';
33
import { addHooks } from '../../shared/hooks-util';
44
import type { BeforeSanityCheckEnv, BeforeTokenizeEnv } from '../../core/hooks';
5-
import type { TokenStream } from '../../core/token';
5+
import type { TokenStream } from '../../core/classes/token';
66
import type { PluginProto } from '../../types';
77

88
export default {

0 commit comments

Comments
 (0)