sprockets-babel-miniracer 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ // this is an empty file
2
+ // });
3
+ // blah blah blah
@@ -0,0 +1,7 @@
1
+ // foo
2
+ /**
3
+ * this is an empty file
4
+ * });
5
+ * blah blah blah
6
+ */
7
+ // blah
@@ -0,0 +1,7 @@
1
+ export default class Imported1 {
2
+
3
+ static foo() {
4
+ return 'foo';
5
+ }
6
+
7
+ }
@@ -0,0 +1,7 @@
1
+ export class Imported2 {
2
+
3
+ static bar() {
4
+ return 'bar';
5
+ }
6
+
7
+ }
@@ -0,0 +1,5 @@
1
+ import Imported1 from '../lib/Imported1';
2
+ import {Imported2} from '../lib/Imported2';
3
+
4
+ print(Imported1.foo());
5
+ print(Imported2.bar());
@@ -0,0 +1 @@
1
+ var square = (n) => n * n
@@ -0,0 +1,5 @@
1
+ import Imported1 from './lib/Imported1';
2
+ import {Imported2} from './lib/Imported2';
3
+
4
+ print(Imported1.foo());
5
+ print(Imported2.bar());
data/test/test_es6.rb ADDED
@@ -0,0 +1,101 @@
1
+ require 'minitest/autorun'
2
+ require 'sprockets/babel'
3
+
4
+ class Environment
5
+ def paths
6
+ []
7
+ end
8
+ end
9
+
10
+ class Scope
11
+ def environment
12
+ Environment.new
13
+ end
14
+ end
15
+
16
+ class TestES6 < MiniTest::Test
17
+ def test_transform_arrow_function
18
+ ctx = TestES6.create_js_context TestES6.compile_js_source('test/fixtures/math.js.es6')
19
+ square = ctx[:square]
20
+ assert_equal 4, square.call(2)
21
+ end
22
+
23
+ def test_transform_large_file
24
+ ctx = TestES6.create_js_context TestES6.compile_js_source('test/fixtures/Regions.js.es6')
25
+ regions = ctx[:Regions]
26
+ assert_equal 103, regions.keys.length
27
+ assert_equal 'Ontario', regions['CA'][7]['name']
28
+ end
29
+
30
+ def test_transform_empty_file
31
+ compiled = TestES6.compile_js_source 'test/fixtures/empty.js.es6', 'inline'
32
+ ctx = TestES6.create_js_context compiled
33
+ assert !ctx['$__empty__'].nil?
34
+ end
35
+
36
+ def test_transform_empty_file2
37
+ compiled = TestES6.compile_js_source 'test/fixtures/empty2.js.es6', 'inline'
38
+ ctx = TestES6.create_js_context compiled
39
+ assert !ctx['$__empty2__'].nil?
40
+ end
41
+
42
+ def test_import_export
43
+ ctx = TestES6.create_test_import_context
44
+ ctx.eval TestES6.compile_js_source 'test/fixtures/test-import.js.es6', 'inline'
45
+ assert_equal 'foobar', ctx[:output]
46
+ end
47
+
48
+ def test_relative_import
49
+ ctx = TestES6.create_test_import_context
50
+ ctx.eval TestES6.compile_js_source 'test/fixtures/lib2/test-relative-import.js.es6', 'inline',
51
+ 'lib2/test-relative-import'
52
+ assert_equal 'foobar', ctx[:output]
53
+ end
54
+
55
+ def test_js_inline_module_loader
56
+ ctx = TestES6.create_inline_module_loader_context
57
+ ctx.eval TestES6.compile_js_source 'test/fixtures/test-import.js.es6', 'inline'
58
+ assert_equal 'foobar', ctx[:output]
59
+ end
60
+
61
+ def test_js_inline_module_loader_relative_import
62
+ ctx = TestES6.create_inline_module_loader_context
63
+ ctx.eval TestES6.compile_js_source 'test/fixtures/lib2/test-relative-import.js.es6', 'inline',
64
+ 'lib2/test-relative-import'
65
+ assert_equal 'foobar', ctx[:output]
66
+ end
67
+
68
+ private
69
+
70
+ def self.create_inline_module_loader_context
71
+ inline_module_loader = File.read('lib/sprockets-babel-inline-module-loader.js')
72
+ TestES6.create_test_import_context inline_module_loader, 'amd'
73
+ end
74
+
75
+ def self.create_test_import_context(code = nil, module_format = 'inline')
76
+ ctx = TestES6.create_js_context code
77
+ ctx.eval <<-JS
78
+ var output = '', print = function(data) { output += data};
79
+ JS
80
+ ctx.eval TestES6.compile_js_source 'test/fixtures/lib/Imported1.js.es6', module_format,
81
+ 'lib/Imported1'
82
+ ctx.eval TestES6.compile_js_source 'test/fixtures/lib/Imported2.js.es6', module_format,
83
+ 'lib/Imported2'
84
+ ctx
85
+ end
86
+
87
+ def self.create_js_context(code = nil)
88
+ ctx = V8::Context.new
89
+ ctx.eval(code) unless code.nil?
90
+ ctx
91
+ end
92
+
93
+ def self.compile_js_source(path, modules = 'ignore', name = '')
94
+ es6_source = File.read(path)
95
+ Babel.options[:modules] = modules
96
+
97
+ name = name.empty? ? File.basename(path) : name
98
+ template = Sprockets::Babel::Template.new(name, 1) { es6_source }
99
+ template.render(Scope.new)
100
+ end
101
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sprockets-babel-miniracer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Kari Ikonen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-07-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sprockets
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: babel-transpiler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.7.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.7.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Transpile ES6 files with BabelJS.
70
+ email:
71
+ - mr.kari.ikonen@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/babel.rb
82
+ - lib/sprockets-babel-inline-module-loader.js
83
+ - lib/sprockets-babel.rb
84
+ - lib/sprockets/babel.rb
85
+ - lib/sprockets/babel/version.rb
86
+ - sprockets-babel-miniracer.gemspec
87
+ - test/fixtures/Regions.js.es6
88
+ - test/fixtures/empty.js.es6
89
+ - test/fixtures/empty2.js.es6
90
+ - test/fixtures/lib/Imported1.js.es6
91
+ - test/fixtures/lib/Imported2.js.es6
92
+ - test/fixtures/lib2/test-relative-import.js.es6
93
+ - test/fixtures/math.js.es6
94
+ - test/fixtures/test-import.js.es6
95
+ - test/test_es6.rb
96
+ homepage: https://github.com/kikonen/sprockets-babel-miniracer
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.2.2
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Sprockets 2.x plugin for BabelJS.
120
+ test_files:
121
+ - test/fixtures/Regions.js.es6
122
+ - test/fixtures/empty.js.es6
123
+ - test/fixtures/empty2.js.es6
124
+ - test/fixtures/lib/Imported1.js.es6
125
+ - test/fixtures/lib/Imported2.js.es6
126
+ - test/fixtures/lib2/test-relative-import.js.es6
127
+ - test/fixtures/math.js.es6
128
+ - test/fixtures/test-import.js.es6
129
+ - test/test_es6.rb