es6_module_transpiler-rails 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0396a7d9f2b2191ce7cb26673b02c24ff3dba5ad
4
- data.tar.gz: 6b82cc19fec563735804cc0410299ba1267d5493
3
+ metadata.gz: d5204862e43fbe6a62533854dc77da47cd1b4705
4
+ data.tar.gz: 27dfcdcaaee320e308a84c8c09529e2f660a1d29
5
5
  SHA512:
6
- metadata.gz: bb8969e1e230b35f3717ce5d2cc0441ef80cd183251090ea569fa275c92648c741f039e88017fadfbc791bf68f12be1fe56516959438b9b3b40437a25278e379
7
- data.tar.gz: 335cf0abe9116d67a2d40324b8ba13827f3a1106065157909601f2e99791309da2722b097eb676d0a26a81e8e2b24759673b02d84223322379fd83ded36e9f2a
6
+ metadata.gz: c7868d8bbee8d7c19b34eca346a65a4a477a565476b2619a6c80ab1176755c0836f7be426d106514a9a1dd11f32c6976c6a73fd76e66dd4ea55472c035cf6829
7
+ data.tar.gz: 1deb69616b1aa1c7136795146b45aeee0d52fb7129105c4a1b4cb0e8ffc371ad985a545468b42706aacab74aa4ebf9fb7897e5e18e5e4c2eda73686b1018c3aa
@@ -1,3 +1,8 @@
1
+ ## 0.4.0
2
+
3
+ * Added `ES6ModuleTranspiler.compiler_options` for passing options to the
4
+ module compiler.
5
+
1
6
  ## 0.3.0
2
7
 
3
8
  * Added ES6ModuleTranspiler.transform for custom transforming of the
data/Gemfile CHANGED
@@ -2,6 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in es6_module_transpiler-rails.gemspec
4
4
  gemspec
5
-
6
- gem 'byebug'
7
- gem 'm'
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 = fooController;
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
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
21
21
  spec.add_dependency 'execjs'
22
22
  spec.add_development_dependency 'rake'
23
23
  spec.add_development_dependency 'tilt'
24
- spec.add_development_dependency 'sprockets'
24
+ spec.add_development_dependency 'sprockets', '> 2.0.0'
25
25
  end
@@ -32,4 +32,8 @@ module ES6ModuleTranspiler
32
32
  def self.transform
33
33
  @transform
34
34
  end
35
+
36
+ def self.compiler_options
37
+ @compiler_options ||= {}
38
+ end
35
39
  end
@@ -1,5 +1,5 @@
1
1
  module ES6ModuleTranspiler
2
2
  module Rails
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
@@ -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(\"" + name + "\"));\n");
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
- source = <<-SOURCE
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
@@ -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
@@ -1,5 +1,4 @@
1
1
  require 'bundler/setup'
2
- require 'byebug'
3
2
  require 'es6_module_transpiler/rails'
4
3
 
5
4
  if defined?(M)
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.3.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: 2013-12-02 00:00:00.000000000 Z
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: '0'
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: '0'
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: