feat: migrate to ESM
This commit is contained in:
parent
67f50b85f5
commit
39a67eec61
59 changed files with 132 additions and 80 deletions
|
|
@ -1,9 +1,9 @@
|
|||
const assert = require("node:assert");
|
||||
const { test } = require("node:test");
|
||||
|
||||
const Parser = require("tree-sitter");
|
||||
import assert from "node:assert";
|
||||
import { test } from "node:test";
|
||||
import Parser from "tree-sitter";
|
||||
import language from "./index.js";
|
||||
|
||||
test("can load grammar", () => {
|
||||
const parser = new Parser();
|
||||
assert.doesNotThrow(() => parser.setLanguage(require(".")));
|
||||
assert.doesNotThrow(() => parser.setLanguage(language));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
/// <reference types="tree-sitter-cli/dsl" />
|
||||
// @ts-check
|
||||
|
||||
module.exports = grammar({
|
||||
export default grammar({
|
||||
name: "LOWER_PARSER_NAME",
|
||||
|
||||
rules: {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,15 @@
|
|||
const root = require("path").join(__dirname, "..", "..");
|
||||
const root = new URL("../..", import.meta.url).pathname;
|
||||
|
||||
module.exports =
|
||||
typeof process.versions.bun === "string"
|
||||
// Support `bun build --compile` by being statically analyzable enough to find the .node file at build-time
|
||||
? require(`../../prebuilds/${process.platform}-${process.arch}/tree-sitter-KEBAB_PARSER_NAME.node`)
|
||||
: require("node-gyp-build")(root);
|
||||
const binding = typeof process.versions.bun === "string"
|
||||
// Support `bun build --compile` by being statically analyzable enough to find the .node file at build-time
|
||||
? await import(`../../prebuilds/${process.platform}-${process.arch}/tree-sitter-KEBAB_PARSER_NAME.node`)
|
||||
: await import("node-gyp-build");
|
||||
|
||||
const result = binding.default ? binding.default(root) : binding(root);
|
||||
|
||||
try {
|
||||
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
||||
const nodeTypeInfo = await import("../../src/node-types.json", {assert: {type: "json"}});
|
||||
result.nodeTypeInfo = nodeTypeInfo.default;
|
||||
} catch (_) {}
|
||||
|
||||
export default result;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
"name": "tree-sitter-PARSER_NAME",
|
||||
"version": "PARSER_VERSION",
|
||||
"description": "PARSER_DESCRIPTION",
|
||||
"type": "module",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+PARSER_URL.git"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue