21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/render/react/transpiler.rb', line 21
def babelify(filepath)
code = File.read(filepath)
component_name_match = code.match(/export default (\w+?);/)
raise "can't find component name in #{filepath}" unless component_name_match
component_name = component_name_match[1]
code.gsub!(/export[^;]+;/, '')
code.gsub!(/import[^;]+;/, '')
code.gsub!(/require[^;]+;/, '')
transormation = " var input = \#{JSON.dump(code)};\n Babel.transform(input, {\n \"presets\": ['stage-0', 'es2015', 'react'],\n \"plugins\": [\"transform-class-properties\"]\n }).code;\n EOF\n result = cxt.eval transormation\n result = 'var Component = React.Component;' + result\n\n [component_name, result]\nend\n"
|