es6_module_transpiler-rails 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile +0 -3
- data/README.md +13 -3
- data/es6_module_transpiler-rails.gemspec +1 -1
- data/lib/es6_module_transpiler/rails.rb +4 -0
- data/lib/es6_module_transpiler/rails/version.rb +1 -1
- data/lib/es6_module_transpiler/support/es6-module-transpiler.js +2 -2
- data/lib/es6_module_transpiler/tilt/es6_module_transpiler_template.rb +6 -2
- data/test/template_test.rb +56 -14
- data/test/test_helper.rb +0 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5204862e43fbe6a62533854dc77da47cd1b4705
|
4
|
+
data.tar.gz: 27dfcdcaaee320e308a84c8c09529e2f660a1d29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7868d8bbee8d7c19b34eca346a65a4a477a565476b2619a6c80ab1176755c0836f7be426d106514a9a1dd11f32c6976c6a73fd76e66dd4ea55472c035cf6829
|
7
|
+
data.tar.gz: 1deb69616b1aa1c7136795146b45aeee0d52fb7129105c4a1b4cb0e8ffc371ad985a545468b42706aacab74aa4ebf9fb7897e5e18e5e4c2eda73686b1018c3aa
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -24,10 +24,10 @@ For example, `app/assets/javascripts/controllers/fooController.js.es6`
|
|
24
24
|
|
25
25
|
```js
|
26
26
|
var fooController = function() {
|
27
|
-
console.log('fooController is in the house!')
|
27
|
+
console.log('fooController is in the house!');
|
28
28
|
};
|
29
29
|
|
30
|
-
export default
|
30
|
+
export default fooController;
|
31
31
|
```
|
32
32
|
|
33
33
|
will compile to `/assets/controllers/fooController.js`
|
@@ -38,7 +38,7 @@ define("controllers/fooController",
|
|
38
38
|
function(__exports__) {
|
39
39
|
"use strict";
|
40
40
|
var fooController = function() {
|
41
|
-
console.log('fooController is in the house!')
|
41
|
+
console.log('fooController is in the house!');
|
42
42
|
};
|
43
43
|
|
44
44
|
__exports__["default"] = fooController;
|
@@ -55,6 +55,16 @@ ES6ModuleTranspiler.compile_to = :globals
|
|
55
55
|
ES6ModuleTranspiler.compile_to = :cjs
|
56
56
|
```
|
57
57
|
|
58
|
+
You may modify the `options` that are passed to the module compiler (i.e.
|
59
|
+
[compatFix](https://github.com/square/es6-module-transpiler/blob/3e708b70dffeaf753307f9d5ecdf780fd6c7b74e/lib/amd_compiler.js#L68)) by
|
60
|
+
modifying the `compiler_options` hash:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
ES6ModuleTranspiler.compiler_options[:compatFix] = true;
|
64
|
+
```
|
65
|
+
|
66
|
+
The `compiler_options` hash is empty by default.
|
67
|
+
|
58
68
|
### Custom Module Prefix ###
|
59
69
|
|
60
70
|
You can match module names based upon a pattern to apply a prefix to the
|
@@ -6433,7 +6433,7 @@ var CJSCompiler = function($__super) {
|
|
6433
6433
|
},
|
6434
6434
|
doModuleImport: function(name, dependencyName, idx) {
|
6435
6435
|
this.ensureHasModuleObjectBuilder();
|
6436
|
-
return ("var " + name + " = " + MODULE_OBJECT_BUILDER_NAME + "(\"" + name + "\", require(\"" +
|
6436
|
+
return ("var " + name + " = " + MODULE_OBJECT_BUILDER_NAME + "(\"" + name + "\", require(\"" + dependencyName + "\"));\n");
|
6437
6437
|
},
|
6438
6438
|
ensureHasModuleObjectBuilder: function() {
|
6439
6439
|
this.ensureHasSafeWarn();
|
@@ -7188,4 +7188,4 @@ module.exports = YUICompiler;
|
|
7188
7188
|
},{"./abstract_compiler":2,"./source_modifier":10}]},{},[8])
|
7189
7189
|
(8)
|
7190
7190
|
});
|
7191
|
-
;
|
7191
|
+
;
|
@@ -27,10 +27,10 @@ module Tilt
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def generate_source(scope)
|
30
|
-
|
30
|
+
<<-SOURCE
|
31
31
|
var Compiler, compiler, output;
|
32
32
|
Compiler = require("#{transpiler_path}").Compiler;
|
33
|
-
compiler = new Compiler(#{::JSON.generate(data, quirks_mode: true)}, '#{module_name(scope.root_path, scope.logical_path)}');
|
33
|
+
compiler = new Compiler(#{::JSON.generate(data, quirks_mode: true)}, '#{module_name(scope.root_path, scope.logical_path)}', #{compiler_options});
|
34
34
|
return output = compiler.#{compiler_method}();
|
35
35
|
SOURCE
|
36
36
|
end
|
@@ -59,5 +59,9 @@ module Tilt
|
|
59
59
|
|
60
60
|
"to#{type}"
|
61
61
|
end
|
62
|
+
|
63
|
+
def compiler_options
|
64
|
+
::JSON.generate(ES6ModuleTranspiler.compiler_options, quirks_mode: true)
|
65
|
+
end
|
62
66
|
end
|
63
67
|
end
|
data/test/template_test.rb
CHANGED
@@ -7,6 +7,8 @@ Scope = Struct.new('Scope', :root_path, :logical_path)
|
|
7
7
|
describe Tilt::ES6ModuleTranspilerTemplate do
|
8
8
|
before do
|
9
9
|
@source = <<-JS
|
10
|
+
import dep from 'dep';
|
11
|
+
|
10
12
|
var foo = function() {
|
11
13
|
console.log('bar');
|
12
14
|
};
|
@@ -26,9 +28,11 @@ JS
|
|
26
28
|
it 'transpiles es6 into amd by default' do
|
27
29
|
expected = <<-JS
|
28
30
|
define("foo",
|
29
|
-
["exports"],
|
30
|
-
function(__exports__) {
|
31
|
+
["dep","exports"],
|
32
|
+
function(__dependency1__, __exports__) {
|
31
33
|
"use strict";
|
34
|
+
var dep = __dependency1__["default"];
|
35
|
+
|
32
36
|
var foo = function() {
|
33
37
|
console.log('bar');
|
34
38
|
};
|
@@ -46,14 +50,16 @@ JS
|
|
46
50
|
ES6ModuleTranspiler.compile_to = :globals
|
47
51
|
|
48
52
|
expected = <<-JS
|
49
|
-
(function(__exports__) {
|
53
|
+
(function(__exports__, __dependency1__) {
|
50
54
|
"use strict";
|
55
|
+
var dep = __dependency1__;
|
56
|
+
|
51
57
|
var foo = function() {
|
52
58
|
console.log('bar');
|
53
59
|
};
|
54
60
|
|
55
61
|
__exports__.foo = foo;
|
56
|
-
})(window);
|
62
|
+
})(window, window.dep);
|
57
63
|
JS
|
58
64
|
expected.rstrip!
|
59
65
|
|
@@ -66,6 +72,8 @@ JS
|
|
66
72
|
|
67
73
|
expected = <<-JS
|
68
74
|
"use strict";
|
75
|
+
var dep = require("dep")["default"];
|
76
|
+
|
69
77
|
var foo = function() {
|
70
78
|
console.log('bar');
|
71
79
|
};
|
@@ -83,9 +91,11 @@ JS
|
|
83
91
|
|
84
92
|
expected = <<-JS
|
85
93
|
define("app/controllers/foo",
|
86
|
-
["exports"],
|
87
|
-
function(__exports__) {
|
94
|
+
["dep","exports"],
|
95
|
+
function(__dependency1__, __exports__) {
|
88
96
|
"use strict";
|
97
|
+
var dep = __dependency1__["default"];
|
98
|
+
|
89
99
|
var foo = function() {
|
90
100
|
console.log('bar');
|
91
101
|
};
|
@@ -100,9 +110,11 @@ JS
|
|
100
110
|
|
101
111
|
expected = <<-JS
|
102
112
|
define("foo",
|
103
|
-
["exports"],
|
104
|
-
function(__exports__) {
|
113
|
+
["dep","exports"],
|
114
|
+
function(__dependency1__, __exports__) {
|
105
115
|
"use strict";
|
116
|
+
var dep = __dependency1__["default"];
|
117
|
+
|
106
118
|
var foo = function() {
|
107
119
|
console.log('bar');
|
108
120
|
};
|
@@ -122,9 +134,11 @@ JS
|
|
122
134
|
|
123
135
|
expected = <<-JS
|
124
136
|
define("app/models/foo",
|
125
|
-
["exports"],
|
126
|
-
function(__exports__) {
|
137
|
+
["dep","exports"],
|
138
|
+
function(__dependency1__, __exports__) {
|
127
139
|
"use strict";
|
140
|
+
var dep = __dependency1__["default"];
|
141
|
+
|
128
142
|
var foo = function() {
|
129
143
|
console.log('bar');
|
130
144
|
};
|
@@ -139,9 +153,11 @@ JS
|
|
139
153
|
|
140
154
|
expected = <<-JS
|
141
155
|
define("config/foo",
|
142
|
-
["exports"],
|
143
|
-
function(__exports__) {
|
156
|
+
["dep","exports"],
|
157
|
+
function(__dependency1__, __exports__) {
|
144
158
|
"use strict";
|
159
|
+
var dep = __dependency1__["default"];
|
160
|
+
|
145
161
|
var foo = function() {
|
146
162
|
console.log('bar');
|
147
163
|
};
|
@@ -158,9 +174,11 @@ JS
|
|
158
174
|
it 'transpiles es6 into amd by default' do
|
159
175
|
expected = <<-JS
|
160
176
|
define("FOO",
|
161
|
-
["exports"],
|
162
|
-
function(__exports__) {
|
177
|
+
["dep","exports"],
|
178
|
+
function(__dependency1__, __exports__) {
|
163
179
|
"use strict";
|
180
|
+
var dep = __dependency1__["default"];
|
181
|
+
|
164
182
|
var foo = function() {
|
165
183
|
console.log('bar');
|
166
184
|
};
|
@@ -174,4 +192,28 @@ JS
|
|
174
192
|
template = Tilt::ES6ModuleTranspilerTemplate.new { @source }
|
175
193
|
template.render(@scope).must_equal expected
|
176
194
|
end
|
195
|
+
|
196
|
+
it 'respects compiler_options' do
|
197
|
+
expected = <<-JS
|
198
|
+
define("FOO",
|
199
|
+
["dep","exports"],
|
200
|
+
function(__dependency1__, __exports__) {
|
201
|
+
"use strict";
|
202
|
+
var dep = __dependency1__["default"] || __dependency1__;
|
203
|
+
|
204
|
+
var foo = function() {
|
205
|
+
console.log('bar');
|
206
|
+
};
|
207
|
+
|
208
|
+
__exports__["default"] = foo;
|
209
|
+
});
|
210
|
+
JS
|
211
|
+
expected.rstrip!
|
212
|
+
|
213
|
+
ES6ModuleTranspiler.compiler_options[:compatFix] = true;
|
214
|
+
ES6ModuleTranspiler.transform = lambda { |name| name.upcase }
|
215
|
+
template = Tilt::ES6ModuleTranspilerTemplate.new { @source }
|
216
|
+
template.render(@scope).must_equal expected
|
217
|
+
ES6ModuleTranspiler.compiler_options[:compatFix] = false;
|
218
|
+
end
|
177
219
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: es6_module_transpiler-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Cardarella
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-04-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: execjs
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: sprockets
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - '
|
59
|
+
- - '>'
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 2.0.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - '
|
66
|
+
- - '>'
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 2.0.0
|
69
69
|
description: Compile ES6 modules in the asset pipeline
|
70
70
|
email:
|
71
71
|
- bcardarella@gmail.com
|
@@ -116,3 +116,4 @@ summary: ES6 Module Transpiler for Rails
|
|
116
116
|
test_files:
|
117
117
|
- test/template_test.rb
|
118
118
|
- test/test_helper.rb
|
119
|
+
has_rdoc:
|