Repository navigation
release: v3.5.1 - #89
Merged
Merged
Conversation
…wrapper A Buffer (or any TypedArray view / DataView) returned across the `self` boundary was detected by runtime_isClassInstance as a wrappable class instance and proxy-wrapped. The proxy breaks intrinsic accessors such as TypedArray `.length`/`.byteLength`, which rely on the value's internal slots being read directly off the receiver. Add the abstract %TypedArray% base constructor (covers Buffer and every numeric view) and DataView to EXCLUDED_INSTANCEOF_CLASSES so binary buffers cross `self` untouched, alongside the already-excluded ArrayBuffer.
There was a problem hiding this comment.
Pull request overview
This release PR bumps to v3.5.1 and fixes a runtime wrapping edge case by ensuring binary buffer/view objects (TypedArrays/Buffer/DataView) are excluded from the class-instance proxy wrapper, preventing broken intrinsic accessors (e.g., Buffer.length).
Changes:
- Exclude
%TypedArray%(covering Buffer and all TypedArray views) andDataViewfromruntime_isClassInstancewrapping logic. - Add vitest coverage to assert
Buffer,TypedArrayviews,DataView, andArrayBufferare not treated as wrappable class instances. - Bump package version to
3.5.1(and update lockfile/types sourcemap output).
Reviewed changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/helpers/class-instance-wrapper.mjs | Updates exclusion logic to prevent proxy-wrapping TypedArrays/Buffer/DataView. |
| tests/vitests/suites/helpers/class-instance-wrapper-proxy.test.vitest.mjs | Adds regression tests ensuring binary buffers/views are not wrapped. |
| package.json | Bumps version to 3.5.1 for the release. |
| package-lock.json | Updates lockfile version fields to 3.5.1. |
| types/src/lib/helpers/class-instance-wrapper.d.mts.map | Regenerated types sourcemap reflecting the code change. |
Transformed .ts/.mts modules are written to a cache file under
.slothlet-cache/ and imported from there. esbuild/tsc transform the code
but never rewrite import specifiers, so a relative specifier
(`./sibling.mjs`, `../shared/util.mjs`) resolved against the cache
directory instead of the original source tree and failed with
`Cannot find module`. The 3.5.0 fix moved TS modules off `data:` URLs to
real cache files — fixing bare specifiers — but left relative ones broken.
Add rewriteRelativeSpecifiers(): before the transformed code is hashed
and cached, every relative import/export/dynamic-import specifier is
resolved against the original source directory and emitted as an
absolute file:// URL, which resolves identically regardless of where the
importing cache file lives. Bare specifiers and absolute URLs are left
untouched. Covers static `import`/`export … from` (incl. multi-line
binding lists and `export *`), bare side-effect `import "…"`, and dynamic
`import("…")` with a static string literal.
Relative imports that resolve to another .ts/.mts file are rewritten too
but still won't load — Node has no loader for those extensions; slothlet
wires TS modules together via self.* at runtime.
…xport The new rewriteRelativeSpecifiers export was tagged `@internal`, which tsc strips from `.d.mts` output under `stripInternal: true` — so the published declarations omitted it and still described relative imports as out-of-scope. Retag it `@private` (matching the exported-for-testing `formatDiagnostics` helper in the same module, which is not stripped) so runtime exports and type declarations stay in sync for TS consumers. Regenerate types/ via `npm run build:types`: - typescript.d.mts: adds rewriteRelativeSpecifiers; refreshes the writeTransformedToCache doc (relative imports are now anchored, not out-of-scope). - index.d.mts, unified-wrapper.d.mts: pre-existing drift the committed declarations had accumulated relative to source — corrected by the same regeneration. Validated with `npm run test:types` (43 exports).
- docs/changelog/v3/v3.5.1.md: new patch-release changelog covering the Buffer/TypedArray/DataView class-instance-wrapper exclusion and the relative-import anchoring for .ts/.mts modules. - README.md: promote v3.5.1 to "Latest"; move v3.5.0 into Recent Releases and drop v3.3.1 to keep the list at 4 entries. - MODULE-STRUCTURE.md / TYPESCRIPT.md: relative imports to plain .mjs/.cjs/.js files now resolve from TS modules; only relative imports targeting another .ts/.mts file remain unsupported. - CONTEXT-PROPAGATION.md: the built-in exclusion list now names ArrayBuffer, DataView, Buffer, and typed-array views explicitly.
Completes the relative-import fix from earlier in this release: a
.ts/.mts module can now relatively import another .ts/.mts module, not
just plain .mjs/.cjs/.js files.
writeTransformedToCache() follows the transitive graph of relative
.ts/.mts imports — each dependency is transpiled and cached, and the
importing specifier is rewritten to the dependency's cache file. Import
cycles are handled; each cache file is named by a content hash over its
whole relative-.ts/.mts closure, so editing any module in the graph
busts every importer's URL on reload. The TypeScript source-extension
convention is respected (a `./x.mjs` specifier may resolve to `x.mts`).
rewriteRelativeSpecifiers() now skips matches inside string literals and
comments (via the new maskStringsAndComments scanner), so import-shaped
text in string data — e.g. `const s = "import('./x')"` — is never
mutated.
The loader threads a transpiler callback through to the cache writer in
both fast and strict modes; strict-mode type errors in a relatively
imported module surface the same way as for the entry module.
…index signature
Two declaration-emit defects in the published types/, surfaced while
regenerating declarations for this release:
- index.mjs exports `slothlet` as both the default and a named alias,
but tsc emitted only the default — `import { slothlet }` failed type
checking despite working at runtime. Declaring the entry point as a
`const` (not `export default function`) makes tsc emit the named
`export { slothlet }` alongside the default.
- UnifiedWrapper's `util.inspect.custom` handler was a computed-key
class member, which tsc emits as a spurious `[x: number]` index
signature that makes the type look array-like. The handler is now an
ordinary named method wired to the symbol via a prototype assignment
after the class, so the generated declaration is clean.
Runtime behavior is unchanged; both fixes only affect declaration emit.
- changelog: relative imports now reach other .ts/.mts modules (not just plain .mjs/.cjs/.js); document the recursive transpile/link behavior, string/comment-skipping, and the two type-declaration fixes. - MODULE-STRUCTURE.md / TYPESCRIPT.md / README.md: relative imports of other .ts/.mts modules are transpiled and linked automatically.
…ents rewriteRelativeSpecifiers only allowed plain whitespace between the `from`/`import` keyword and the module string. JavaScript permits comments between those tokens, and the transpilers preserve them: tsc keeps comments by default, and esbuild deliberately retains magic comments inside `import()` (e.g. `import(/* webpackIgnore: true */ "./x.mjs")`). A comment in that gap defeated the match, so the relative specifier was left unrewritten — it then resolved against the `.slothlet-cache/` directory instead of the original source and failed at runtime with `Cannot find module`. Two agent reports flagged this: one for the static `import`/`export … from` pattern, one for the dynamic `import()` pattern. Both were accurate. The reports did not mention that a comment between the closing quote and `)` in a dynamic import has the same root cause; that case is also covered here. Introduce a `TOKEN_GAP` sub-pattern matching whitespace and/or line and block comments — every inter-token gap JavaScript allows — and use it in all three rewrite patterns wherever they previously hard-coded `\s*`. The patterns are hoisted to module-scope constants. String/comment masking still skips import-shaped text in string data and comments, so the broadened gap does not widen what gets mutated.
build-exports.mjs patches `types/index.d.mts` to add a named
`export { slothlet }` for source shapes where tsc emits `slothlet`
only as the default export. The guard checked solely for the literal
string `export { slothlet }`.
tsc renders the JSDoc-annotated entry point as `export function
slothlet(...)` — a declaration that already IS the named export. That
string does not contain `export { slothlet }`, so the patch fired and
appended a second named export of `slothlet`, producing a TS2484
declaration conflict that failed `build:types`/`test:types` and the
whole `build:dev` pipeline.
Detect an existing named `slothlet` export in any form — an
`export function`/`const`/`class slothlet` declaration or an
`export { slothlet }` statement — and skip the patch when one is
present. `export default slothlet` and `export { slothlet as default }`
are the default export and correctly do not count.
`npm run fix:headers` adds the standard project header to three external-module fixtures under api_tests/api_test_typescript_relative/ that were missing it. Committed so the header check no longer reports them as dirty.
writeTransformedToCache's Phase-3 rewrite callback handled a relative
`.ts`/`.mts` import that was followed (Case A → cache file) but its
fallback emitted `pathToFileURL(absoluteTarget)` — the specifier path
exactly as written. When `resolveModuleFile` had remapped the target
via the TS source-extension convention (specifier `./dep.js`, on-disk
source `dep.ts`), `absoluteTarget` is a non-existent `dep.js`, so the
fallback produced a `file://…/dep.js` URL pointing at nothing.
The agent report was accurate about the cause and the fix. Scope note:
in production `loader.mjs` always passes a `transform` callback, so
Phase 1 transpiles every relative `.ts`/`.mts` dependency into
`transformed` and Case A handles them all — the fallback is reached for
a TS target only in the no-`transform` mode (tests / a documented
degraded path the JSDoc already describes as non-loading). The fix is
still correct: it makes the code match its JSDoc ("left at its source
path") and emit a URL for a file that exists.
Use `resolved.path` instead of `absoluteTarget` in the fallback.
`resolveModuleFile` only ever returns `resolved.path !== absoluteTarget`
when it remapped to a `.ts`/`.mts` source (`isTS` true); for plain
`.mjs`/`.cjs`/`.js` targets `resolved.path === absoluteTarget`, so the
change is identical for them and only corrects the TS-remap case.
maskStringsAndComments treated every `//` and `/*` as a comment start
with no awareness of regular-expression literals. A regex whose body
contains comment-shaped text — e.g. `/\/\//` — was scanned character by
character, and the `//` inside it was mistaken for a line comment, so
the scanner masked the rest of the physical line. When a real dynamic
`import("./dep.mjs")` appeared later on that same line, its match offset
landed in the spuriously-masked region and `rewriteRelativeSpecifiers`
skipped it — leaving the relative specifier to resolve against the
`.slothlet-cache/` directory and fail at runtime.
The agent report was accurate. Fix: scan regex literals as first-class
tokens and mask them whole, so comment-shaped text in a regex body is
never re-interpreted. Telling a regex literal apart from the division
operator needs the preceding token, so the scanner now tracks whether
the last significant token expects an expression (a `/` then opens a
regex) or is a value (a `/` is then division), including a keyword set
for `return`/`typeof`/`await`/etc. The known imperfect case — a `/`
directly after the `)` of an `if`/`for`/`while` header — is documented;
a full tokenizer is deliberately not pulled in for this.
Adds unit tests for regex masking (incl. a `/` inside a `[...]` class)
and a rewrite test for the report's exact scenario: a regex containing
`//` followed by a relative `import()` on the same line.
UnifiedWrapper wires Node's `util.inspect.custom` hook by assigning
`UnifiedWrapper.prototype[util.inspect.custom] = …` after the class
body (kept off the class body so tsc does not emit a spurious numeric
index signature). A plain assignment creates the property as
enumerable, whereas a computed `[util.inspect.custom]()` method
declared in the class body would be non-enumerable — so the prototype
property diverged from the class-method semantics the surrounding code
documents it should match.
The agent report was accurate. Replace the assignment with
`Object.defineProperty` using `{ writable: true, enumerable: false,
configurable: true }` — the exact descriptor a class-body method
produces — so the hook is wired with identical runtime attributes while
still keeping the symbol off the class body.
formatDiagnostics is exported and consumed by loader.mjs in the same import as the @public transformTypeScriptStrict and writeTransformedToCache, yet it alone among the loader-facing exports was tagged @Private — an inconsistency flagged in review. Tag it @public to match the other functions that form this module's internal API surface. resolveModuleFile, maskStringsAndComments and rewriteRelativeSpecifiers stay @Private deliberately: they are exported only so unit tests can reach them, not as an API.
The identifier/keyword scan built its word with `word += code[i++]` per character. Slice the run out once with `code.slice(start, i)` instead, so scanning an identifier is linear in its length rather than relying on the engine to optimize repeated concatenation. maskStrings- AndComments runs over every transformed module before caching. Behavior is unchanged — the sliced string is the same word the concatenation produced; only the keyword-set lookup consumes it.
The Type Declarations section described two fixes in terms a later
commit on this branch superseded:
- The named `slothlet` export is emitted by tsc as `export function
slothlet(…)`, not an `export { slothlet }` statement. Document that,
and the accompanying `build-exports.mjs` correction that stopped it
appending a duplicate `export { slothlet }` (a TS2484 conflict).
- The `util.inspect.custom` handler is wired with `Object.defineProperty`
(non-enumerable), not a plain prototype assignment.
Also note the relative-specifier rewrite tolerates comments between
import tokens and skips regex-literal bodies, and list the matching new
test cases under Test Coverage.
Shinrai
approved these changes
May 18, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🚀 What's Changed
💥 Breaking Changes
No breaking changes
✨ Features
No new features
🐛 Bug Fixes
🔧 Other Changes
👥 Contributors
Avg: 100.0% ·
22a51c3· Node lts/*