Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitac28d88

Browse files
rubysclaude
andcommitted
Integrate transpiled Functions filter with selfhost tests
- Add _setup function to transpiled filters for binding module-level functions- Update FilterProcessor to call _setup on filters that support it- Load Functions filter automatically when running functions_spec- Add s()/S() node creation helpers with is_method() supportfunctions_spec now runs with the transpiled Functions filter:- Previously: 16 passed (base converter only, no filter)- Now: 70 passed (with transpiled Functions filter)🤖 Generated with [Claude Code](https://claude.com/claude-code)Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parentd595e62 commitac28d88

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

‎demo/selfhost/run_all_specs.mjs‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ async function ensurePrismInitialized() {
3434
}
3535
}
3636

37+
// Load transpiled filters on demand
38+
letfunctionsFilterLoaded=false;
39+
asyncfunctionloadFunctionsFilter(){
40+
if(functionsFilterLoaded)return;
41+
try{
42+
constfilterModule=awaitimport('./dist/functions_filter.mjs');
43+
// Register the filter in Ruby2JS.Filter namespace
44+
globalThis.Ruby2JS.Filter=globalThis.Ruby2JS.Filter||{};
45+
globalThis.Ruby2JS.Filter.Functions=filterModule.default;
46+
functionsFilterLoaded=true;
47+
console.log(' (Functions filter loaded)');
48+
}catch(e){
49+
console.log(` Warning: Could not load Functions filter:${e.message}`);
50+
}
51+
}
52+
3753
// Colors for output
3854
constcolors={
3955
green:'\x1b[32m',
@@ -79,6 +95,11 @@ async function runSpec(specName) {
7995
try{
8096
awaitensurePrismInitialized();
8197

98+
// Load Functions filter if running functions_spec
99+
if(specName==='functions_spec.rb'){
100+
awaitloadFunctionsFilter();
101+
}
102+
82103
// Reset test state before running each spec
83104
resetTests();
84105

‎demo/selfhost/scripts/transpile_filter.rb‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,34 @@
6969
ast_node: (obj) => typeof obj === 'object' && obj !== null && 'type' in obj && 'children' in obj
7070
};
7171
72+
// Filter infrastructure functions (these get bound by FilterProcessor at runtime)
73+
// Default implementations return false/do nothing
74+
let excluded = () => false;
75+
let included = () => false;
76+
let process = (node) => node;
77+
78+
// AST node creation helpers
79+
function s(type, ...children) {
80+
return {
81+
type,
82+
children,
83+
updated: function(newType, newChildren) {
84+
return s(newType ?? this.type, ...(newChildren ?? this.children));
85+
},
86+
is_method() {
87+
// Default to false for synthetic nodes
88+
return this._is_method ?? false;
89+
},
90+
get first() { return this.children[0]; },
91+
get last() { return this.children[this.children.length - 1]; }
92+
};
93+
}
94+
95+
function S(type, ...children) {
96+
// S updates the current node - same as s for our purposes
97+
return s(type, ...children);
98+
}
99+
72100
JS
73101

74102
# Fix issues in transpiled output:
@@ -97,6 +125,15 @@
97125
// Register the filter
98126
DEFAULTS.push(Functions);
99127
128+
// Setup function to bind filter infrastructure
129+
Functions._setup = function(opts) {
130+
if (opts.excluded) excluded = opts.excluded;
131+
if (opts.included) included = opts.included;
132+
if (opts.process) process = opts.process;
133+
if (opts.s) { /* s is already defined */ }
134+
if (opts.S) { /* S is already defined */ }
135+
};
136+
100137
// Export the filter for ES module usage
101138
export { Functions as default, Functions };
102139
JS

‎demo/selfhost/test_harness.mjs‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,21 @@ class FilterProcessor {
106106
filter.process=this.process.bind(this);
107107

108108
// Add excluded/included checkers
109-
filter.excluded=(method)=>Ruby2JS.Filter._excluded.has(method);
110-
filter.included=(method)=>Ruby2JS.Filter._included.has(method);
109+
constexcludedFn=(method)=>Ruby2JS.Filter._excluded.has(method);
110+
constincludedFn=(method)=>Ruby2JS.Filter._included.has(method);
111+
filter.excluded=excludedFn;
112+
filter.included=includedFn;
113+
114+
// Call _setup if filter has it (for transpiled filters with module-level functions)
115+
if(typeoffilter._setup==='function'){
116+
filter._setup({
117+
excluded:excludedFn,
118+
included:includedFn,
119+
process:this.process.bind(this),
120+
s:SEXP.s,
121+
S:SEXP.S.bind(this)
122+
});
123+
}
111124
}
112125

113126
process(node){

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp