feat(module-source): expose createModuleSourcePasses()#3159
feat(module-source): expose createModuleSourcePasses()#3159boneskull wants to merge 5 commits intoboneskull/ast-servicefrom
Conversation
|
Warning This PR is part of a stack and targets branch 📚 Pull Request Stack
Managed by gh-stack |
|
62012e4 to
7fbfdd1
Compare
c3239b5 to
0fb7919
Compare
0fb7919 to
93e7e2c
Compare
7fbfdd1 to
f54da12
Compare
There was a problem hiding this comment.
Pull request overview
This PR exposes a new public API, createModuleSourcePasses(), from @endo/module-source for consumption by @endo/parser-pipeline, while refactoring shared module-source logic (source-options + functor/record building) and tightening source map typing/flow between module-source, parser-pipeline, and compartment-mapper.
Changes:
- Added
createModuleSourcePasses()with analyzer/transform visitors +buildRecord()for parser-pipeline integration. - Refactored shared state + record construction into
createSourceOptions()andbuildFunctorSource()/buildModuleRecord(). - Updated source map hook flow so parser-pipeline receives raw source map objects (with compartment-mapper wrapping/stringifying for the public hook), plus added/updated public types and tests.
Reviewed changes
Copilot reviewed 18 out of 20 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| yarn.lock | Adds Babel-related type packages to the lockfile. |
| packages/parser-pipeline/src/composed-parser.js | Switches sourceMapHook callsite to pass raw source map objects. |
| packages/module-source/tsconfig.json | Adjusts include globs and excludes .d.ts files. |
| packages/module-source/test/visitor-passes.test.js | Adds tests for the new createModuleSourcePasses() API. |
| packages/module-source/test/module-source.test.js | Removes now-unneeded @ts-expect-error on source map hook details. |
| packages/module-source/test/_benchmark-babel-plugin.js | Reuses shared createSourceOptions() for benchmarks. |
| packages/module-source/src/visitor-passes.js | Implements createModuleSourcePasses() API. |
| packages/module-source/src/types/visitor-passes.ts | Adds exported TypeScript types for the new API. |
| packages/module-source/src/types/module-source.ts | Adds exported types for module-source options + source maps. |
| packages/module-source/src/transform-source.js | Refactors visitor extraction + improves source map emission gating. |
| packages/module-source/src/transform-analyze.js | Refactors to shared helpers for options + record construction. |
| packages/module-source/src/source-options.js | Introduces shared mutable state bag creation + visitor extraction. |
| packages/module-source/src/module-source.js | Simplifies ModuleSource construction by copying from frozen record. |
| packages/module-source/src/functor.js | Centralizes functor source + record assembly/freezing. |
| packages/module-source/src/external.types.js | Adds runtime-empty module for type-only re-exports. |
| packages/module-source/src/external.types.d.ts | Re-exports public types from the package. |
| packages/module-source/src/babel-plugin.js | Adds type imports/docs and a couple TS suppression annotations. |
| packages/module-source/package.json | Adds Babel generator/traverse type deps. |
| packages/module-source/index.js | Re-exports public types + createModuleSourcePasses(). |
| packages/compartment-mapper/src/types/external.ts | Introduces ParseSourceMapHook and updates parse option typing. |
Comments suppressed due to low confidence (1)
packages/module-source/src/transform-analyze.js:16
- This file still imports the JSDoc type
Optionsfrom./module-source.js, but that typedef was removed in this PR in favor ofModuleSourceOptionsfrom./types/module-source.js. WithcheckJsenabled, this will cause a broken type import and downstream type errors. Update the import and the@paramannotation to referenceModuleSourceOptions(or an equivalent exported type) instead.
/** @import {Options} from './module-source.js' */
const makeCreateStaticRecord = transformSource =>
/**
*
* @param {string} moduleSource
* @param {Options} options
*/
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
93e7e2c to
656bc39
Compare
f54da12 to
126fef3
Compare
7594c39 to
84dd4ee
Compare
b1c50eb to
59ff80d
Compare
This exposes a new function, `createModuleSourcePasses` for use with `@endo/parser-pipeline`. Changes to existing code should be considered a pure refactor (or at least that was the aim). - Refactored code for reuse between `createModuleSourcePasses` (see `functor.js`, `source-options.js`). - Fixes quite a few type problems, including incorrect types for `SourceMapHook` and `SourceMapDetails`. - Adds other types where things were obvious or involve public APIs
- Remove `extends SourceMapHookDetails` from `TransformSourceParams`; `source` is only available at the `sourceMapHook` call site, not in the options/state bag. Inline the optional `sourceUrl`/`sourceMapUrl` fields directly. - Add `allowHidden?: boolean` to `TransformSourceParams` to match runtime usage in `babel-plugin.js`, removing the `@ts-expect-error`. - Make `SourceMapObject.file` optional per Source Map v3 spec. - Use full tuple `[name, false, undefined]` for `hoistedDecls.push()` instead of short `[name]`, removing the `@ts-expect-error`. - Remove stale `@ts-expect-error` directives for `@babel/generator` options now recognized by `@types/babel__generator`.
a9fdc61 to
9abf181
Compare
59ff80d to
9d57d5e
Compare
This exposes a new function,
createModuleSourcePassesfor use with@endo/parser-pipeline.Changes to existing code should be considered a pure refactor (or at least that was the aim).
createModuleSourcePasses(seefunctor.js,source-options.js).SourceMapHookandSourceMapDetails.