Skip to content

Instantly share code, notes, and snippets.

@hmdne
hmdne / movestubs.rb
Created August 17, 2020 02:15
Move all stubs from an opal file to a runtime call.
require 'set'
f = File.read(ARGV[0])
stubs = Set.new
f = f.gsub /^ Opal\.add_stubs\(\[(.*?)\]\)/ do
stubs += $1.gsub("'", '').split(', ')
""
end
@hmdne
hmdne / tree_shake.rb
Last active November 21, 2019 03:46 — forked from jgaskins/tree_shake.rb
Tree-shaking for compiled output from the Opal compiler
#!/usr/bin/env ruby
require 'set'
def get_stubs code
code
.scan(/\.add_stubs\(.*?\)/)
.map { |call| call.scan(/['"]\$(#{$method_re})['"]/) }
.flatten
.to_set
end