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

Commit34d9402

Browse files
rubysclaude
andcommitted
Unify selfhost browser demo to use bundled ruby2js.mjs
- Update browser_demo.html and docs selfhost index.html to use simple `import { convert } from './ruby2js.mjs'` pattern- Update docs/Rakefile to build and copy unified ruby2js.mjs bundle instead of separate walker.mjs, converter.mjs, runtime.mjs files- Add <base href="/demo/selfhost/"> to ensure relative paths work- Update package.json to output bundle to ruby2js.mjs (not dist/)- Add WASI warning suppression to bundle preamble- Update .gitignore and .dockerignore for new output location- Modify runtime.rb for conditional Prism loading (browser vs Node.js)- Modify cli.rb for conditional fs/url imports and guarded entry point- Add shared convert() function to bundle.rb used by both CLI and exportCLI, CI tests, and browser demo now all use the same ruby2js.mjs bundle.🤖 Generated with [Claude Code](https://claude.com/claude-code)Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent2f4e419 commit34d9402

File tree

11 files changed

+140
-708
lines changed

11 files changed

+140
-708
lines changed

‎.dockerignore‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ test/
3434

3535
# Plans/docs not needed for build
3636
plans/
37+
38+
# Selfhost generated outputs (regenerated via npm run build:*)
39+
demo/selfhost/dist/
40+
demo/selfhost/ruby2js.mjs

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ node_modules
77

88
# Selfhost generated outputs (regenerated via npm run build:*)
99
demo/selfhost/dist/
10+
demo/selfhost/ruby2js.mjs
1011

1112
# Editor swap files
1213
*.swp

‎demo/selfhost/browser_demo.html‎

Lines changed: 12 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -354,114 +354,22 @@ <h2 class="panel-title">JavaScript</h2>
354354

355355
<scripttype="module">
356356
// Self-hosted Ruby2JS demo
357-
// Uses@ruby/prism for parsing and the transpiled Ruby2JS converter
358-
//
359-
// All runtime classes are now transpiled from Ruby source files in
360-
// lib/ruby2js/selfhost/ - no more hand-written JavaScript!
361-
362-
// Import browser Prism loader (handles WASM loading)
363-
import{loadPrism}from'./prism_browser.mjs';
364-
365-
// Import runtime classes (transpiled from lib/ruby2js/selfhost/runtime.rb)
366-
import{
367-
PrismSourceBuffer,
368-
PrismSourceRange,
369-
PrismComment,
370-
CommentsMap,
371-
associateComments,
372-
Hash
373-
}from'./dist/runtime.mjs';
374-
375-
// Import Namespace (transpiled from lib/ruby2js/namespace.rb)
376-
import{Namespace}from'./dist/namespace.mjs';
377-
378-
// Set up globals before importing walker/converter
379-
globalThis.PrismSourceBuffer=PrismSourceBuffer;
380-
globalThis.PrismSourceRange=PrismSourceRange;
381-
globalThis.Hash=Hash;
382-
globalThis.Namespace=Namespace;
383-
384-
// Initialize
357+
// Prism WASM is loaded automatically when the module is imported
358+
359+
import{convert}from'./ruby2js.mjs';
360+
385361
constinput=document.getElementById('input');
386362
constoutput=document.getElementById('output');
387363
conststatus=document.getElementById('status');
388364

389-
letprismParse=null;
390-
letWalkerModule=null;
391-
letConverterModule=null;
392-
393-
asyncfunctioninit(){
394-
try{
395-
// Load Prism WASM
396-
status.textContent='Loading Prism WebAssembly...';
397-
prismParse=awaitloadPrism();
398-
399-
// Set up Prism global (walker needs it)
400-
// Note: For browser, we need to import from prism_browser which re-exports Prism
401-
constprismModule=awaitimport('./prism_browser.mjs');
402-
globalThis.Prism=prismModule;
403-
404-
// Load walker module
405-
status.textContent='Loading walker...';
406-
constwalkerImport=awaitimport('./dist/walker.mjs');
407-
WalkerModule=walkerImport.Ruby2JS;
408-
409-
// Set up Ruby2JS.Node before loading converter
410-
globalThis.Ruby2JS={
411-
Node:WalkerModule.Node,
412-
ast_node(obj){
413-
returntypeofobj==='object'&&obj!==null&&'type'inobj&&'children'inobj;
414-
}
415-
};
416-
417-
// Load converter module
418-
status.textContent='Loading converter...';
419-
constconverterImport=awaitimport('./dist/converter.mjs');
420-
ConverterModule=converterImport.Ruby2JS;
421-
422-
status.className='success';
423-
status.textContent='Ready! Edit the Ruby code to see the JavaScript output.';
424-
425-
// Initial conversion
426-
convert();
427-
}catch(e){
428-
status.className='error';
429-
status.textContent=`Error loading:${e.message}`;
430-
console.error(e);
431-
}
432-
}
433-
434-
functionconvert(){
435-
if(!prismParse||!WalkerModule||!ConverterModule){
436-
return;
437-
}
438-
439-
constsource=input.value;
365+
status.className='success';
366+
status.textContent='Ready! Edit the Ruby code to see the JavaScript output.';
440367

368+
functiondoConvert(){
441369
try{
442-
// Parse with Prism
443-
constparseResult=prismParse(source);
444-
445-
// Walk to create Parser-compatible AST
446-
constwalker=newWalkerModule.PrismWalker(source,null);
447-
constast=walker.visit(parseResult.value);
448-
449-
// Create converter
450-
constconverter=newConverterModule.Converter(ast,{},{});
451-
converter.namespace=newNamespace();
452-
453-
// Enable vertical whitespace if source has newlines
454-
if(source.includes("\n")){
455-
converter.enable_vertical_whitespace;
456-
}
457-
458-
// Convert (getter)
459-
converter.convert;
460-
461-
// Get output (to_s is a getter)
462-
output.value=converter.to_s;
370+
output.value=convert(input.value);
463371
}catch(e){
464-
output.value=`// Error:${e.message}\n//${e.stack?.split('\n').slice(0,3).join('\n// ')}`;
372+
output.value=`// Error:${e.message}`;
465373
console.error(e);
466374
}
467375
}
@@ -470,10 +378,11 @@ <h2 class="panel-title">JavaScript</h2>
470378
letdebounceTimer;
471379
input.addEventListener('input',()=>{
472380
clearTimeout(debounceTimer);
473-
debounceTimer=setTimeout(convert,150);
381+
debounceTimer=setTimeout(doConvert,150);
474382
});
475383

476-
init();
384+
// Initial conversion
385+
doConvert();
477386
</script>
478387
</body>
479388
</html>

‎demo/selfhost/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"build:namespace":"bundle exec ruby scripts/transpile_namespace.rb > dist/namespace.mjs",
1111
"build:walker":"bundle exec ruby scripts/transpile_walker.rb > dist/walker.mjs",
1212
"build:converter":"bundle exec ruby scripts/transpile_converter.rb > dist/converter.mjs",
13-
"build:bundle":"bundle exec ruby scripts/transpile_bundle.rb >dist/bundle.mjs",
13+
"build:bundle":"bundle exec ruby scripts/transpile_bundle.rb >ruby2js.mjs",
1414
"build:spec":"bundle exec ruby scripts/transpile_spec.rb ../../spec/transliteration_spec.rb > dist/transliteration_spec.mjs",
1515
"test":"npm run test:cli && npm run test:walker && npm run test:all-specs",
1616
"test:cli":"node test_cli.mjs",

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp