Skip to content

Commit 0f27a20

Browse files
committed
feat: improve warning messages
1 parent 708e3f2 commit 0f27a20

File tree

14 files changed

+73
-59
lines changed

14 files changed

+73
-59
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export class GrammarState implements GrammarStateInterface {
107107
lang: this.lang,
108108
theme: this.theme,
109109
themes: this.themes,
110-
scopes: this.scopes,
110+
scopes: this.getScopes(),
111111
}
112112
}
113113
}

packages/engine-javascript/test/compare.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Execution } from './types'
44

55
import { hash as createHash } from 'ohash'
66
import { describe, expect, it } from 'vitest'
7-
import { createWasmOnigEngine, loadWasm } from '../../engine-oniguruma/src'
7+
import { createOnigurumaEngine, loadWasm } from '../../engine-oniguruma/src'
88
import { createHighlighterCore } from '../../shiki/src/core'
99
import { createJavaScriptRegexEngine } from '../src/engine-compile'
1010

@@ -176,20 +176,20 @@ describe('cases', async () => {
176176
const run = c.c.skip ? it.skip : it
177177
run(c.c.name, async () => {
178178
const engineWasm = createEngineWrapper(
179-
await createWasmOnigEngine(),
179+
await createOnigurumaEngine(),
180180
)
181181
const engineJs = createEngineWrapper(
182182
createJavaScriptRegexEngine({
183183
forgiving: true,
184184
}),
185185
)
186186

187-
const shiki1 = await createHighlighterCore({
187+
using shiki1 = await createHighlighterCore({
188188
langs: c.lang,
189189
themes: [c.theme],
190190
engine: engineWasm,
191191
})
192-
const shiki2 = await createHighlighterCore({
192+
using shiki2 = await createHighlighterCore({
193193
langs: c.lang,
194194
themes: [c.theme],
195195
engine: engineJs,

packages/shiki/test/wasm1.test.ts renamed to packages/engine-oniguruma/test/wasm1.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
import { createHighlighterCore } from '@shikijs/core'
2+
import js from '@shikijs/langs/js'
3+
import nord from '@shikijs/themes/nord'
14
import { expect, it } from 'vitest'
5+
26
// eslint-disable-next-line antfu/no-import-dist
3-
import { wasmBinary } from '../../engine-oniguruma/dist/wasm-inlined.mjs'
4-
import { createHighlighterCore } from '../src/core'
5-
import js from '../src/langs/javascript.mjs'
6-
import nord from '../src/themes/nord.mjs'
7+
import { wasmBinary } from '../dist/wasm-inlined.mjs'
8+
import { createOnigurumaEngine } from '../src/index'
79

810
it('wasm', async () => {
911
const shiki = await createHighlighterCore({
1012
themes: [nord],
1113
langs: [js as any],
12-
loadWasm: {
14+
engine: createOnigurumaEngine({
1315
instantiator: obj => WebAssembly.instantiate(wasmBinary, obj),
14-
},
16+
}),
1517
})
1618

1719
expect(shiki.codeToHtml('1 + 1', { lang: 'javascript', theme: 'nord' }))

packages/shiki/test/wasm2.test.ts renamed to packages/engine-oniguruma/test/wasm2.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
import { createHighlighterCore } from '@shikijs/core'
2+
import js from '@shikijs/langs/js'
3+
import nord from '@shikijs/themes/nord'
4+
import { createOnigurumaEngine } from 'shiki'
15
import { expect, it } from 'vitest'
6+
27
// eslint-disable-next-line antfu/no-import-dist
3-
import { wasmBinary } from '../../engine-oniguruma/dist/wasm-inlined.mjs'
4-
import { createHighlighterCore } from '../src/core'
5-
import js from '../src/langs/javascript.mjs'
6-
import nord from '../src/themes/nord.mjs'
8+
import { wasmBinary } from '../dist/wasm-inlined.mjs'
79

810
it('wasm', async () => {
911
const shiki = await createHighlighterCore({
1012
themes: [nord],
1113
langs: [js as any],
12-
loadWasm: {
14+
engine: createOnigurumaEngine({
1315
default: obj => WebAssembly.instantiate(wasmBinary, obj).then(r => r.instance.exports),
14-
},
16+
}),
1517
})
1618

1719
expect(shiki.codeToHtml('1 + 1', { lang: 'javascript', theme: 'nord' }))

packages/shiki/test/wasm3.test.ts renamed to packages/engine-oniguruma/test/wasm3.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
import { createHighlighterCore } from '@shikijs/core'
2+
import js from '@shikijs/langs/js'
3+
import nord from '@shikijs/themes/nord'
14
import { expect, it } from 'vitest'
5+
26
// eslint-disable-next-line antfu/no-import-dist
3-
import { wasmBinary } from '../../engine-oniguruma/dist/wasm-inlined.mjs'
4-
import { createHighlighterCore } from '../src/core'
5-
import js from '../src/langs/javascript.mjs'
6-
import nord from '../src/themes/nord.mjs'
7+
import { wasmBinary } from '../dist/wasm-inlined.mjs'
8+
import { createOnigurumaEngine } from '../src/index'
79

810
it('wasm', async () => {
911
const shiki = await createHighlighterCore({
1012
themes: [nord],
1113
langs: [js as any],
12-
loadWasm: obj => WebAssembly.instantiate(wasmBinary, obj).then(r => r.instance),
14+
engine: createOnigurumaEngine(obj => WebAssembly.instantiate(wasmBinary, obj).then(r => r.instance)),
1315
})
1416

1517
expect(shiki.codeToHtml('1 + 1', { lang: 'javascript', theme: 'nord' }))

packages/shiki/test/wasm4.test.ts renamed to packages/engine-oniguruma/test/wasm4.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
import { createHighlighterCore } from '@shikijs/core'
2+
import js from '@shikijs/langs/js'
3+
import nord from '@shikijs/themes/nord'
14
import { expect, it } from 'vitest'
5+
26
// eslint-disable-next-line antfu/no-import-dist
3-
import { wasmBinary } from '../../engine-oniguruma/dist/wasm-inlined.mjs'
4-
import { createHighlighterCore } from '../src/core'
5-
import js from '../src/langs/javascript.mjs'
6-
import nord from '../src/themes/nord.mjs'
7+
import { wasmBinary } from '../dist/wasm-inlined.mjs'
8+
import { createOnigurumaEngine } from '../src/index'
79

810
it('wasm', async () => {
911
const shiki = await createHighlighterCore({
1012
themes: [nord],
1113
langs: [js as any],
12-
loadWasm: Promise.resolve().then(() => obj => WebAssembly.instantiate(wasmBinary, obj).then(r => r.instance)),
14+
engine: createOnigurumaEngine(Promise.resolve().then(() => obj => WebAssembly.instantiate(wasmBinary, obj).then(r => r.instance))),
1315
})
1416

1517
expect(shiki.codeToHtml('1 + 1', { lang: 'javascript', theme: 'nord' }))

packages/shiki/test/wasm5.test.ts renamed to packages/engine-oniguruma/test/wasm5.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
import { createHighlighterCore } from '@shikijs/core'
2+
import js from '@shikijs/langs/js'
3+
import nord from '@shikijs/themes/nord'
14
import { expect, it } from 'vitest'
5+
26
// eslint-disable-next-line antfu/no-import-dist
3-
import { wasmBinary } from '../../engine-oniguruma/dist/wasm-inlined.mjs'
4-
import { createHighlighterCore } from '../src/core'
5-
import js from '../src/langs/javascript.mjs'
6-
import nord from '../src/themes/nord.mjs'
7+
import { wasmBinary } from '../dist/wasm-inlined.mjs'
8+
import { createOnigurumaEngine } from '../src/index'
79

810
it('loadWasm: WebAssembly.Module', async () => {
911
const shiki = await createHighlighterCore({
1012
themes: [nord],
1113
langs: [js as any],
12-
loadWasm: WebAssembly.compile(wasmBinary) as any,
14+
engine: createOnigurumaEngine(WebAssembly.compile(wasmBinary) as any),
1315
})
1416

1517
expect(shiki.codeToHtml('1 + 1', { lang: 'javascript', theme: 'nord' }))

packages/shiki/test/wasm6.test.ts renamed to packages/engine-oniguruma/test/wasm6.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
import { createHighlighterCore } from '@shikijs/core'
2+
import js from '@shikijs/langs/js'
3+
import nord from '@shikijs/themes/nord'
14
import { expect, it } from 'vitest'
5+
26
// eslint-disable-next-line antfu/no-import-dist
3-
import { wasmBinary } from '../../engine-oniguruma/dist/wasm-inlined.mjs'
4-
import { createHighlighterCore } from '../src/core'
5-
import js from '../src/langs/javascript.mjs'
6-
import nord from '../src/themes/nord.mjs'
7+
import { wasmBinary } from '../dist/wasm-inlined.mjs'
8+
import { createOnigurumaEngine } from '../src/index'
79

810
it('loadWasm: { default: WebAssembly.Module }', async () => {
911
const shiki = await createHighlighterCore({
1012
themes: [nord],
1113
langs: [js as any],
12-
loadWasm: Promise.resolve({ default: await WebAssembly.compile(wasmBinary) }) as any,
14+
engine: createOnigurumaEngine(Promise.resolve({ default: await WebAssembly.compile(wasmBinary) }) as any),
1315
})
1416

1517
expect(shiki.codeToHtml('1 + 1', { lang: 'javascript', theme: 'nord' }))

packages/shiki/test/core.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { createOnigurumaEngine } from '@shikijs/engine-oniguruma'
12
import { describe, expect, it } from 'vitest'
3+
24
// eslint-disable-next-line antfu/no-import-dist
35
import { wasmBinary } from '../../engine-oniguruma/dist/wasm-inlined.mjs'
4-
56
import { createHighlighterCore } from '../src/core'
67
import js from '../src/langs/javascript.mjs'
78
import ts from '../src/langs/typescript.mjs'
@@ -13,9 +14,9 @@ describe('should', () => {
1314
using shiki = await createHighlighterCore({
1415
themes: [nord],
1516
langs: [js],
16-
loadWasm: {
17+
engine: createOnigurumaEngine({
1718
instantiator: obj => WebAssembly.instantiate(wasmBinary, obj),
18-
},
19+
}),
1920
})
2021

2122
expect(shiki.codeToHtml('console.log("Hi")', { lang: 'javascript', theme: 'nord' }))
@@ -29,10 +30,10 @@ describe('should', () => {
2930
js,
3031
import('../src/langs/c.mjs'),
3132
],
32-
loadWasm: {
33+
engine: createOnigurumaEngine({
3334
// https://github.com/WebAssembly/esm-integration/tree/main/proposals/esm-integration
3435
instantiator: obj => WebAssembly.instantiate(wasmBinary, obj).then(r => r.instance.exports),
35-
},
36+
}),
3637
})
3738

3839
await shiki.loadLanguage(() => import('../src/langs/python.mjs'))
@@ -151,9 +152,9 @@ describe('errors', () => {
151152
using shiki = await createHighlighterCore({
152153
themes: [nord],
153154
langs: [js as any],
154-
loadWasm: {
155+
engine: createOnigurumaEngine({
155156
instantiator: obj => WebAssembly.instantiate(wasmBinary, obj),
156-
},
157+
}),
157158
})
158159

159160
const code = shiki.codeToHtml('console.log("Hi")', { lang: 'javascript', theme: mtp })

packages/transformers/src/shared/notation-transformer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ export function createCommentNotationTransformer(
2626
lines: Element[],
2727
index: number
2828
) => boolean,
29-
matchAlgorithm: MatchAlgorithm = 'v1',
29+
matchAlgorithm: MatchAlgorithm | undefined,
3030
): ShikiTransformer {
31-
if (matchAlgorithm === 'v1') {
32-
warnDeprecated('`matchAlgorithm: "v1"` is deprecated and will be removed in the future. Please explicitly set `matchAlgorithm: "v3"` in the transformer options.', 3)
31+
if (matchAlgorithm == null) {
32+
matchAlgorithm = 'v1'
33+
warnDeprecated('The default `matchAlgorithm: "v1"` is deprecated and will be removed in the future. Please explicitly set `matchAlgorithm: "v3"` in the transformer options.', 3)
3334
}
3435

3536
return {

0 commit comments

Comments
 (0)