Skip to content

Commit be07da8

Browse files
committedJul 26, 2024··
feat: add static initial method for GrammarState, #715
1 parent 1349bb4 commit be07da8

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed
 

‎packages/core/src/grammar-state.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
import type { StateStackImpl } from '../vendor/vscode-textmate/src/grammar'
22
import { ShikiError } from './error'
33
import type { StateStack } from './textmate'
4+
import { INITIAL } from './textmate'
45

56
/**
67
* GrammarState is a special reference object that holds the state of a grammar.
78
*
89
* It's used to highlight code snippets that are part of the target language.
910
*/
1011
export class GrammarState {
12+
/**
13+
* Static method to create a initial grammar state.
14+
*/
15+
static initial(lang: string, theme: string) {
16+
return new GrammarState(INITIAL, lang, theme)
17+
}
18+
1119
constructor(
12-
private _stack: StateStack,
13-
public lang: string,
14-
public theme: string,
20+
private readonly _stack: StateStack,
21+
public readonly lang: string,
22+
public readonly theme: string,
1523
) {}
1624

1725
get scopes() {

0 commit comments

Comments
 (0)
Please sign in to comment.