satteri 0.2.0 → 0.2.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bruits
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1 +1 @@
1
- export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseExpression, parseToHtml, renderHandle, serializeHandle, serializeMdastHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../satteri_napi.wasi-browser.js";
1
+ export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, serializeMdastHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../satteri_napi.wasi-browser.js";
@@ -1,2 +1,2 @@
1
1
  // @ts-nocheck — WASM browser binding has no type declarations
2
- export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseExpression, parseToHtml, renderHandle, serializeHandle, serializeMdastHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../satteri_napi.wasi-browser.js";
2
+ export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, serializeMdastHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../satteri_napi.wasi-browser.js";
package/dist/binding.d.ts CHANGED
@@ -1 +1 @@
1
- export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseExpression, parseToHtml, renderHandle, serializeHandle, serializeMdastHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../index.js";
1
+ export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, serializeMdastHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../index.js";
package/dist/binding.js CHANGED
@@ -1 +1 @@
1
- export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseExpression, parseToHtml, renderHandle, serializeHandle, serializeMdastHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../index.js";
1
+ export { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, serializeMdastHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle, } from "../index.js";
@@ -52,7 +52,9 @@ export interface HastVisitorInstance {
52
52
  mdxTextExpression?: HastVisitorFn<MdxTextExpressionHast & {
53
53
  parseExpression(): EstreeProgram | null;
54
54
  }>;
55
- mdxjsEsm?: HastVisitorFn<MdxjsEsmHast>;
55
+ mdxjsEsm?: HastVisitorFn<MdxjsEsmHast & {
56
+ parseExpression(): EstreeProgram | null;
57
+ }>;
56
58
  }
57
59
  interface ResolvedSubscription {
58
60
  nodeType: number;
@@ -1,17 +1,17 @@
1
1
  import { materializeHastNode } from "./hast-materializer.js";
2
2
  import { HastReader, HAST_ELEMENT, HAST_TEXT, HAST_COMMENT, HAST_RAW, HAST_MDX_JSX_ELEMENT, HAST_MDX_JSX_TEXT_ELEMENT, HAST_MDX_FLOW_EXPRESSION, HAST_MDX_TEXT_EXPRESSION, HAST_MDX_ESM, } from "./hast-reader.js";
3
3
  import { CommandBuffer } from "../command-buffer.js";
4
- import { walkHandle, applyCommandsToHandle, serializeHandle, textContentHandle, getNodeData as napiGetNodeData, parseExpression as napiParseExpression, } from "#binding";
4
+ import { walkHandle, applyCommandsToHandle, serializeHandle, textContentHandle, getNodeData as napiGetNodeData, parseExpression as napiParseExpression, parseEsm as napiParseEsm, } from "#binding";
5
5
  /** Maps HastNode objects to their arena node IDs without Object.defineProperty overhead. */
6
6
  const nodeIdMap = new WeakMap();
7
- /** Attach `parseExpression()` to an MDX expression node. */
8
- function attachParseExpression(node) {
7
+ /** Attach `parseExpression()` to an MDX expression or ESM node. */
8
+ function attachParseExpression(node, parseFn) {
9
9
  Object.defineProperty(node, "parseExpression", {
10
10
  value() {
11
11
  const value = this.value;
12
12
  if (typeof value !== "string")
13
13
  return null;
14
- const json = napiParseExpression(value);
14
+ const json = parseFn(value);
15
15
  if (json == null)
16
16
  return null;
17
17
  return JSON.parse(json);
@@ -299,6 +299,7 @@ const TEXT_NODE_TYPES = {
299
299
  5: "raw",
300
300
  [HAST_MDX_FLOW_EXPRESSION]: "mdxFlowExpression",
301
301
  [HAST_MDX_TEXT_EXPRESSION]: "mdxTextExpression",
302
+ [HAST_MDX_ESM]: "mdxjsEsm",
302
303
  };
303
304
  function readTextFromBinary(view, buf, offset, nodeId, nodeType) {
304
305
  const valLen = view.getUint32(offset, true);
@@ -306,7 +307,10 @@ function readTextFromBinary(view, buf, offset, nodeId, nodeType) {
306
307
  const node = { type: TEXT_NODE_TYPES[nodeType], value };
307
308
  nodeIdMap.set(node, nodeId);
308
309
  if (nodeType === HAST_MDX_FLOW_EXPRESSION || nodeType === HAST_MDX_TEXT_EXPRESSION) {
309
- attachParseExpression(node);
310
+ attachParseExpression(node, napiParseExpression);
311
+ }
312
+ else if (nodeType === HAST_MDX_ESM) {
313
+ attachParseExpression(node, napiParseEsm);
310
314
  }
311
315
  return node;
312
316
  }
package/index.d.ts CHANGED
@@ -138,6 +138,9 @@ export interface JsTextContentOptions {
138
138
  */
139
139
  export declare function mdastTextContentHandle(handle: ArenaHandle, nodeId: number, options?: JsTextContentOptions | undefined | null): string
140
140
 
141
+ /** Parse ESM (import/export statements) and return ESTree-compatible AST as JSON. */
142
+ export declare function parseEsm(source: string): string | null
143
+
141
144
  /**
142
145
  * Parse a JavaScript expression and return its ESTree-compatible AST as a JSON string.
143
146
  * Returns null if parsing fails. The JS layer calls JSON.parse (faster than serde_json → NAPI).
package/index.js CHANGED
@@ -579,7 +579,7 @@ if (!nativeBinding) {
579
579
  throw new Error(`Failed to load native binding`)
580
580
  }
581
581
 
582
- const { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseExpression, parseToHtml, renderHandle, serializeHandle, serializeMdastHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle } = nativeBinding
582
+ const { applyCommandsAndConvertToHastHandle, applyCommandsToHandle, applyCommandsToMdastHandle, compileHandle, compileMdx, convertMdastToHastHandle, createHastHandle, createMdastHandle, createMdxHastHandle, createMdxMdastHandle, dropHandle, getHandleSource, getNodeData, mdastTextContentHandle, parseEsm, parseExpression, parseToHtml, renderHandle, serializeHandle, serializeMdastHandle, setNodeData, textContentHandle, walkHandle, walkMdastHandle } = nativeBinding
583
583
  export { applyCommandsAndConvertToHastHandle }
584
584
  export { applyCommandsToHandle }
585
585
  export { applyCommandsToMdastHandle }
@@ -594,6 +594,7 @@ export { dropHandle }
594
594
  export { getHandleSource }
595
595
  export { getNodeData }
596
596
  export { mdastTextContentHandle }
597
+ export { parseEsm }
597
598
  export { parseExpression }
598
599
  export { parseToHtml }
599
600
  export { renderHandle }
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "satteri",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "High-performance Markdown and MDX processing",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/bruits/satteri.git"
8
+ },
5
9
  "files": [
6
10
  "dist",
7
11
  "browser.js",
@@ -29,20 +33,6 @@
29
33
  "default": "./dist/index.js"
30
34
  }
31
35
  },
32
- "scripts": {
33
- "build:wasm": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --release --esm --strip --target wasm32-wasip1-threads",
34
- "build:native": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --release --esm --strip",
35
- "build:native:cross": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --release --esm --strip --cross-compile",
36
- "build:native:debug": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --esm",
37
- "build:ts": "tsc --project tsconfig.build.json",
38
- "build": "pnpm build:native && pnpm build:ts",
39
- "artifacts": "napi create-npm-dirs && napi artifacts --output-dir .",
40
- "prepublishOnly": "pnpm run build:ts && napi create-npm-dirs && napi artifacts --output-dir .",
41
- "dev": "tsc --watch",
42
- "vitest": "vitest",
43
- "test": "vitest run",
44
- "bench": "vitest bench --run"
45
- },
46
36
  "dependencies": {
47
37
  "@types/hast": "^3.0.4",
48
38
  "@types/mdast": "^4.0.4",
@@ -57,13 +47,6 @@
57
47
  "shiki": "^4.0.2",
58
48
  "vitest": "^4"
59
49
  },
60
- "optionalDependencies": {
61
- "@bruits/satteri-linux-x64-gnu": "0.2.0",
62
- "@bruits/satteri-darwin-x64": "0.2.0",
63
- "@bruits/satteri-darwin-arm64": "0.2.0",
64
- "@bruits/satteri-win32-x64-msvc": "0.2.0",
65
- "@bruits/satteri-wasm32-wasi": "0.2.0"
66
- },
67
50
  "napi": {
68
51
  "binaryName": "satteri_napi",
69
52
  "packageName": "@bruits/satteri",
@@ -74,5 +57,18 @@
74
57
  "x86_64-pc-windows-msvc",
75
58
  "wasm32-wasip1-threads"
76
59
  ]
60
+ },
61
+ "scripts": {
62
+ "build:wasm": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --release --esm --strip --target wasm32-wasip1-threads",
63
+ "build:native": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --release --esm --strip",
64
+ "build:native:cross": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --release --esm --strip --cross-compile",
65
+ "build:native:debug": "napi build --manifest-path ../../crates/satteri-napi-binding/Cargo.toml --output-dir . --platform --esm",
66
+ "build:ts": "tsc --project tsconfig.build.json",
67
+ "build": "pnpm build:native && pnpm build:ts",
68
+ "artifacts": "napi create-npm-dirs && napi artifacts",
69
+ "dev": "tsc --watch",
70
+ "vitest": "vitest",
71
+ "test": "vitest run",
72
+ "bench": "vitest bench --run"
77
73
  }
78
- }
74
+ }
@@ -71,6 +71,7 @@ export const dropHandle = __napiModule.exports.dropHandle
71
71
  export const getHandleSource = __napiModule.exports.getHandleSource
72
72
  export const getNodeData = __napiModule.exports.getNodeData
73
73
  export const mdastTextContentHandle = __napiModule.exports.mdastTextContentHandle
74
+ export const parseEsm = __napiModule.exports.parseEsm
74
75
  export const parseExpression = __napiModule.exports.parseExpression
75
76
  export const parseToHtml = __napiModule.exports.parseToHtml
76
77
  export const renderHandle = __napiModule.exports.renderHandle
@@ -122,6 +122,7 @@ module.exports.dropHandle = __napiModule.exports.dropHandle
122
122
  module.exports.getHandleSource = __napiModule.exports.getHandleSource
123
123
  module.exports.getNodeData = __napiModule.exports.getNodeData
124
124
  module.exports.mdastTextContentHandle = __napiModule.exports.mdastTextContentHandle
125
+ module.exports.parseEsm = __napiModule.exports.parseEsm
125
126
  module.exports.parseExpression = __napiModule.exports.parseExpression
126
127
  module.exports.parseToHtml = __napiModule.exports.parseToHtml
127
128
  module.exports.renderHandle = __napiModule.exports.renderHandle