@xsrg2008/web-tree-sitter-cpp 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +36 -0
- package/package.json +12 -3
package/index.cjs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const { Parser, Language } = require("web-tree-sitter");
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
|
|
5
|
+
function getCppParser() {
|
|
6
|
+
const wasmPath = path.join(__dirname, "tree-sitter-cpp.wasm");
|
|
7
|
+
return getParser(wasmPath);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} wasmLangFile
|
|
12
|
+
* @returns {Promise<any>}
|
|
13
|
+
*/
|
|
14
|
+
async function getParser(wasmLangFile) {
|
|
15
|
+
return new Promise(async (resolve, reject) => {
|
|
16
|
+
await Parser.init();
|
|
17
|
+
const parser = new Parser();
|
|
18
|
+
fs.readFile(wasmLangFile, async (err, data) => {
|
|
19
|
+
if (err) {
|
|
20
|
+
reject(err);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const lang = await Language.load(data);
|
|
25
|
+
parser.setLanguage(lang);
|
|
26
|
+
resolve(parser);
|
|
27
|
+
} catch (err2) {
|
|
28
|
+
reject(err2);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
getCppParser,
|
|
36
|
+
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xsrg2008/web-tree-sitter-cpp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "tree-sitter-cpp WASM",
|
|
5
|
-
"main": "index.
|
|
5
|
+
"main": "index.cjs",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"import": "./index.js",
|
|
11
|
+
"require": "./index.cjs",
|
|
12
|
+
"default": "./index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
7
15
|
"scripts": {
|
|
8
16
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
17
|
},
|
|
10
18
|
"type": "module",
|
|
11
19
|
"files": [
|
|
20
|
+
"index.cjs",
|
|
12
21
|
"index.js",
|
|
13
22
|
"index.d.ts",
|
|
14
23
|
"tree-sitter-cpp.wasm",
|
|
@@ -24,4 +33,4 @@
|
|
|
24
33
|
"dependencies": {
|
|
25
34
|
"web-tree-sitter": "^0.26.8"
|
|
26
35
|
}
|
|
27
|
-
}
|
|
36
|
+
}
|