Skip to content

Commit ea488fd

Browse files
committed
Move to typescript
1 parent df33219 commit ea488fd

File tree

8 files changed

+662
-681
lines changed

8 files changed

+662
-681
lines changed

lib/dist/index.cjs.js

+327-314
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/dist/index.esm.mjs

+313-300
Large diffs are not rendered by default.

lib/rollup.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import typescript from "@rollup/plugin-typescript";
88
const pkg = require("./package.json");
99

1010
export default {
11-
input: "src/index.js",
11+
input: "src/index.ts",
1212
output: [
1313
{
1414
file: "dist/index.cjs.js",

lib/src/alias.ts

-50
This file was deleted.

lib/src/index.js renamed to lib/src/index.ts

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import { Registry } from "vscode-textmate";
2-
import vscodeOniguruma from "vscode-oniguruma";
2+
import {
3+
loadWASM,
4+
createOnigScanner,
5+
createOnigString,
6+
} from "vscode-oniguruma";
7+
// @ts-ignore
38
import onig from "vscode-oniguruma/release/onig.wasm";
49
import { loadTheme, getThemeColors } from "./themes";
510
import { tokenize } from "./tokenizer.js";
611
import { loadGrammarByScope } from "./grammars.js";
712
import { aliasToLangData } from "./language";
13+
import { LanguageAlias } from "./language-data";
814

9-
let registry = null;
15+
let registry: Registry | null = null;
1016

11-
export async function highlight(code, alias, themeOrThemeName = "dark-plus") {
17+
export async function highlight(
18+
code: string,
19+
alias: LanguageAlias,
20+
themeOrThemeName = "dark-plus"
21+
) {
1222
// get the language object from the alias
1323
const langData = aliasToLangData(alias);
1424

@@ -19,9 +29,12 @@ export async function highlight(code, alias, themeOrThemeName = "dark-plus") {
1929

2030
// initialize the registry the first time
2131
if (!registry) {
22-
await vscodeOniguruma.loadWASM(onig);
32+
const onigLibPromise = loadWASM(onig).then(() => ({
33+
createOnigScanner,
34+
createOnigString,
35+
}));
2336
registry = new Registry({
24-
onigLib: vscodeOniguruma,
37+
onigLib: onigLibPromise,
2538
loadGrammar: (scopeName) => loadGrammarByScope(scopeName),
2639
});
2740
}
@@ -31,7 +44,7 @@ export async function highlight(code, alias, themeOrThemeName = "dark-plus") {
3144
const theme = await loadTheme(themeOrThemeName);
3245
registry.setTheme(theme);
3346

34-
const grammar = await grammarsPromise;
47+
const grammar = (await grammarsPromise)!;
3548
const colorMap = registry.getColorMap();
3649

3750
return {
@@ -42,8 +55,8 @@ export async function highlight(code, alias, themeOrThemeName = "dark-plus") {
4255
}
4356

4457
export class UnknownLanguageError extends Error {
45-
alias;
46-
constructor(alias) {
58+
alias: string;
59+
constructor(alias: string) {
4760
super(`Unknown language: ${alias}`);
4861
this.alias = alias;
4962
}

lib/src/resolve.js

-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// from https://github.com/browserify/resolve
22
// removed the "is-core-module" dependency because it fails on edge runtime
3-
43
export default function resolveSync(x, options) {
54
var fs = require("fs");
65
var path = require("path");
@@ -9,13 +8,6 @@ export default function resolveSync(x, options) {
98
var os = require("os");
109

1110
function normalizeOptions(x, opts) {
12-
/**
13-
* This file is purposefully a passthrough. It's expected that third-party
14-
* environments will override it at runtime in order to inject special logic
15-
* into `resolve` (by manipulating the options). One such example is the PnP
16-
* code path in Yarn.
17-
*/
18-
1911
return opts || {};
2012
}
2113

File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)