ruby_es6_module_transpiler 0.0.4 → 0.0.5

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: 2b2341121cb0424fd6fbdc64d96d5486cebb158f
4
- data.tar.gz: 70d02ee6953992ce1a6ee93fe0eb7423e085355c
3
+ metadata.gz: f0119a4cc3b3e9c36f7ce5e9490c0f6a5f8113e7
4
+ data.tar.gz: ed05f4f76c9e5eb6fcdf8332c5dae338c2a4b31d
5
5
  SHA512:
6
- metadata.gz: aed512061cce37f62d340fd6ccf7c979372cf99d984a68613ebaebcb921b4efd3e580c63893c28e0beb0193ab540923103cf6fefd101035333e7381a162ff905
7
- data.tar.gz: 6ab24bbaf872022e2aff30eddd5015b4b4048adeb36239492cfff1450681b28c09afaa5d3c1872dbba4a4fe946727bafe48806588bf8eb1d67821d00c1c1da3e
6
+ metadata.gz: 7bf70f76121b7925ec549aa9e5a2dabfb24089ec893e919c83f03f8190f1862a307040621056dfb06d1cdd4207e8ec39cb6d9aa3d17ef56ea415a49397dcf677
7
+ data.tar.gz: cd9d5b8876c5016dff2357e87b642ddb6609bd6cbb9fe439d531dd1b3943e4dab22ee4d1ad970c7d9fd159c77e400a90c3ee57f8eecdb8069def0cf8a8d01247
@@ -22,24 +22,44 @@ module RubyES6ModuleTranspiler
22
22
 
23
23
  private
24
24
  def transpiler_js_path
25
- File.expand_path('../support/es6-module-transpiler.js', __FILE__)
25
+ File.expand_path('../support/es6-module-transpiler.min.js', __FILE__)
26
26
  end
27
27
 
28
28
  def generate_source(options)
29
- type = options[:type] || :AMD
30
29
  source = <<-SOURCE
31
30
  var Compiler, compiler, output;
32
31
  Compiler = require("#{transpiler_js_path}").Compiler;
33
- compiler = new Compiler(#{::JSON.generate(@js_code, quirks_mode: true)});
34
- return output = compiler.to#{type}();
32
+ compiler = new Compiler(#{::JSON.generate(@js_code, quirks_mode: true)}, '#{module_name(options)}', #{options.to_json});
33
+ return output = compiler.#{compiler_type(options)}();
35
34
  SOURCE
36
35
  end
37
36
 
38
37
  def read_js_file(path)
39
- file = File.open(transpiler_js_path, "rb")
38
+ file = File.open(path, "rb")
40
39
  data = file.read
41
40
  file.close
42
41
  data
43
42
  end
43
+
44
+ def compiler_type(options)
45
+ available_types = {
46
+ amd: 'AMD',
47
+ cjs: 'CJS',
48
+ yui: 'YUI',
49
+ globals: 'Globals'
50
+ }
51
+
52
+ if options[:type]
53
+ type = available_types[options[:type].downcase.to_sym] || 'AMD'
54
+ else
55
+ type = 'AMD'
56
+ end
57
+
58
+ "to#{type}"
59
+ end
60
+
61
+ def module_name(options)
62
+ options[:moduleName]
63
+ end
44
64
  end
45
65
  end
@@ -1,3 +1,3 @@
1
1
  module RubyEs6ModuleTranspiler
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,7 @@
1
+ define("renamed",
2
+ ["ember"],
3
+ function(__dependency1__) {
4
+ "use strict";
5
+ var get = __dependency1__.get;
6
+ var set = __dependency1__.set;
7
+ });
@@ -0,0 +1,5 @@
1
+ (function(__dependency1__) {
2
+ "use strict";
3
+ var get = __dependency1__.get;
4
+ var set = __dependency1__.set;
5
+ })(renamed.ember);
@@ -0,0 +1 @@
1
+ import { get, set } from 'ember';
@@ -1,7 +1,7 @@
1
1
  define(
2
- ['exports'],
2
+ ["exports"],
3
3
  function(__exports__) {
4
- 'use strict';
4
+ "use strict";
5
5
  var get = function(obj, key) {
6
6
  return obj[key];
7
7
  };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var get = function(obj, key) {
3
+ return obj[key];
4
+ };
5
+
6
+ var set = function(obj, key, value) {
7
+ obj[key] = value;
8
+ return obj;
9
+ };
10
+
11
+ exports.get = get;
12
+ exports.set = set;
@@ -0,0 +1,14 @@
1
+ (function(__exports__) {
2
+ "use strict";
3
+ var get = function(obj, key) {
4
+ return obj[key];
5
+ };
6
+
7
+ var set = function(obj, key, value) {
8
+ obj[key] = value;
9
+ return obj;
10
+ };
11
+
12
+ __exports__.get = get;
13
+ __exports__.set = set;
14
+ })(window);
@@ -0,0 +1,15 @@
1
+ YUI.add("@NAME@", function(Y, NAME, __imports__, __exports__) {
2
+ "use strict";
3
+ var get = function(obj, key) {
4
+ return obj[key];
5
+ };
6
+
7
+ var set = function(obj, key, value) {
8
+ obj[key] = value;
9
+ return obj;
10
+ };
11
+
12
+ __exports__.get = get;
13
+ __exports__.set = set;
14
+ return __exports__;
15
+ }, "@VERSION@", {"es":true,"requires":[]});
@@ -1,5 +1,28 @@
1
1
  require 'spec_helper'
2
2
  describe RubyES6ModuleTranspiler do
3
+ let(:input) { read_file("default-es6.js") }
4
+
5
+ describe "for case sensitive cases" do
6
+ it "should not care whether AMD is capitalized or not" do
7
+ expect{ RubyES6ModuleTranspiler.transpile(input, { type: "Amd"}) }.to_not raise_error
8
+ end
9
+ end
10
+
11
+ describe "for passing in optional parameters" do
12
+ it "should allow for specifying module names" do
13
+ transpiled_file = RubyES6ModuleTranspiler.transpile(input, { type: "AMD", moduleName: "renamed" })
14
+ expected = read_file("default-amd-name.js")
15
+ expect(transpiled_file).to eq(expected)
16
+ end
17
+
18
+ it "should allow for optional parameter hash" do
19
+ # overrides default name of "window" with "renamed"
20
+ transpiled_file = RubyES6ModuleTranspiler.transpile(input, { type: "Globals", global: "renamed" })
21
+ expected = read_file("default-amd-options.js")
22
+ expect(transpiled_file).to eq(expected)
23
+ end
24
+ end
25
+
3
26
  describe "for importing es6" do
4
27
  let(:input) { read_file("import-es6.js") }
5
28
  it "should default to amd" do
@@ -26,4 +49,31 @@ describe RubyES6ModuleTranspiler do
26
49
  expect(transpiled_file).to eq(expected)
27
50
  end
28
51
  end
52
+
53
+ describe "for exporting es6" do
54
+ let(:input) { read_file("export-es6.js") }
55
+ it "should default to amd" do
56
+ transpiled_file = RubyES6ModuleTranspiler.transpile(input)
57
+ expected = read_file("export-amd.js")
58
+ expect(transpiled_file).to eq(expected)
59
+ end
60
+
61
+ it "should allow for cjs compile" do
62
+ transpiled_file = RubyES6ModuleTranspiler.transpile(input, { type: "CJS"})
63
+ expected = read_file("export-cjs.js")
64
+ expect(transpiled_file).to eq(expected)
65
+ end
66
+
67
+ it "should allow for yui compile" do
68
+ transpiled_file = RubyES6ModuleTranspiler.transpile(input, { type: "YUI"})
69
+ expected = read_file("export-yui.js")
70
+ expect(transpiled_file).to eq(expected)
71
+ end
72
+
73
+ it "should allow for globals compile" do
74
+ transpiled_file = RubyES6ModuleTranspiler.transpile(input, { type: "Globals"})
75
+ expected = read_file("export-globals.js")
76
+ expect(transpiled_file).to eq(expected)
77
+ end
78
+ end
29
79
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_es6_module_transpiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Irvin Zhan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-04 00:00:00.000000000 Z
11
+ date: 2014-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
@@ -81,11 +81,17 @@ files:
81
81
  - Rakefile
82
82
  - lib/ruby_es6_module_transpiler.rb
83
83
  - lib/ruby_es6_module_transpiler/version.rb
84
- - lib/support/es6-module-transpiler.js
84
+ - lib/support/es6-module-transpiler.min.js
85
85
  - lib/support/es6-node-runner.js
86
86
  - ruby_es6_module_transpiler.gemspec
87
+ - spec/js-tests/default-amd-name.js
88
+ - spec/js-tests/default-amd-options.js
89
+ - spec/js-tests/default-es6.js
87
90
  - spec/js-tests/export-amd.js
91
+ - spec/js-tests/export-cjs.js
88
92
  - spec/js-tests/export-es6.js
93
+ - spec/js-tests/export-globals.js
94
+ - spec/js-tests/export-yui.js
89
95
  - spec/js-tests/import-amd.js
90
96
  - spec/js-tests/import-cjs.js
91
97
  - spec/js-tests/import-es6.js
@@ -120,8 +126,14 @@ specification_version: 4
120
126
  summary: Preparing your JS for the next generation ES6. Uses Square's ES6 Module
121
127
  Transpiler (https://github.com/square/es6-module-transpiler)
122
128
  test_files:
129
+ - spec/js-tests/default-amd-name.js
130
+ - spec/js-tests/default-amd-options.js
131
+ - spec/js-tests/default-es6.js
123
132
  - spec/js-tests/export-amd.js
133
+ - spec/js-tests/export-cjs.js
124
134
  - spec/js-tests/export-es6.js
135
+ - spec/js-tests/export-globals.js
136
+ - spec/js-tests/export-yui.js
125
137
  - spec/js-tests/import-amd.js
126
138
  - spec/js-tests/import-cjs.js
127
139
  - spec/js-tests/import-es6.js