-
-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce precompiled-grammars (#880)
- Loading branch information
Showing
43 changed files
with
1,588 additions
and
594 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,4 @@ cache | |
.eslintcache | ||
report-engine-js-compat.json | ||
scripts/compares | ||
tm-grammars-themes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-disable ts/ban-ts-comment */ | ||
/* eslint-disable antfu/no-import-dist */ | ||
|
||
import { bench, describe } from 'vitest' | ||
// @ts-ignore - ignore type error | ||
import { highlight as highlightA } from './dist/index-lite.min.mjs' | ||
// @ts-ignore - ignore type error | ||
import { highlight as highlightB } from './dist/index-wasm.min.mjs' | ||
|
||
const code = ` | ||
import { ref } from 'vue' | ||
const message = ref('Hello World!') | ||
function reverseMessage() { | ||
// Access/mutate the value of a ref via | ||
// its .value property. | ||
message.value = message.value.split('').reverse().join('') | ||
} | ||
function notify() { | ||
alert('navigation was prevented.') | ||
} | ||
` | ||
|
||
describe('bundle', () => { | ||
bench('js-precompiled', async () => { | ||
await highlightA(code) | ||
}) | ||
|
||
bench('wasm', async () => { | ||
await highlightB(code) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { codeToHtml, createShikiInternal } from '@shikijs/core' | ||
import { createJavaScriptRawEngine } from '@shikijs/engine-javascript/raw' | ||
|
||
const shiki = createShikiInternal( | ||
{ | ||
langs: [ | ||
import('@shikijs/langs-precompiled/ts'), | ||
], | ||
themes: [ | ||
import('@shikijs/themes/vitesse-dark'), | ||
], | ||
engine: createJavaScriptRawEngine(), | ||
}, | ||
) | ||
|
||
export async function highlight(code: string): Promise<string> { | ||
return codeToHtml(await shiki, code, { lang: 'ts', theme: 'vitesse-dark' }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { codeToHtml, createShikiInternal } from '@shikijs/core' | ||
import { createWasmOnigEngine } from '@shikijs/engine-oniguruma' | ||
|
||
const shiki = createShikiInternal( | ||
{ | ||
langs: [ | ||
import('@shikijs/langs/ts'), | ||
], | ||
themes: [ | ||
import('@shikijs/themes/vitesse-dark'), | ||
], | ||
engine: createWasmOnigEngine(import('@shikijs/engine-oniguruma/wasm-inlined')), | ||
}, | ||
) | ||
|
||
export async function highlight(code: string): Promise<string> { | ||
return codeToHtml(await shiki, code, { lang: 'ts', theme: 'vitesse-dark' }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"private": true, | ||
"scripts": { | ||
"bench:prepare": "rollup -c && du -h dist/*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import resolve from '@rollup/plugin-node-resolve' | ||
import esbuild from 'rollup-plugin-esbuild' | ||
|
||
const plugins = [ | ||
resolve(), | ||
esbuild({ | ||
minify: true, | ||
target: 'esnext', | ||
}), | ||
] | ||
|
||
export default [ | ||
{ | ||
input: 'index-wasm.ts', | ||
output: { | ||
file: 'dist/index-wasm.min.mjs', | ||
format: 'es', | ||
inlineDynamicImports: true, | ||
}, | ||
plugins, | ||
}, | ||
{ | ||
input: 'index-lite.ts', | ||
output: { | ||
file: 'dist/index-lite.min.mjs', | ||
format: 'es', | ||
inlineDynamicImports: true, | ||
}, | ||
plugins, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.