opal-optimizer 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +63 -0
- data/.gitignore +2 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +11 -5
- data/README.md +7 -4
- data/bin/opal-optimizer +1 -5
- data/exe/opal-optimizer +6 -0
- data/lib/opal/optimizer/step/collapse_stubs.rb +7 -3
- data/lib/opal/optimizer/step/tree_shaking.rb +12 -3
- data/lib/opal/optimizer/version.rb +1 -1
- data/lib/opal/optimizer.rb +5 -1
- metadata +7 -4
- data/Gemfile.lock +0 -81
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 125dd4183eebeaf54651e1888dc9e662693e8f20c0b60f65a5f8dd132475033b
|
4
|
+
data.tar.gz: c8b571477260698fef8d6acbbf1914b2772dcb4c413916eeeff071d38fd3afd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64ca3cc44bce614557ae951e1b1b2d8bc57821d358ea6263a0cf9f587278af9c7150326706eb26f6194265814587c5b58899adf3a0a75f6af9d730611b3f70aa
|
7
|
+
data.tar.gz: ad54442d22a1a162e0d18371890c0dd7d1f15f80ecb1bc83741368b2c315eea3e657b5cae1960621923895c5ea9ae3046634cc7f62baf4a729c7616f26599a59
|
@@ -0,0 +1,63 @@
|
|
1
|
+
name: build
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
- "*-stable"
|
8
|
+
- "*/ci-check"
|
9
|
+
pull_request: {}
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
rake:
|
13
|
+
name: ${{ matrix.combo.name }}
|
14
|
+
strategy:
|
15
|
+
fail-fast: false
|
16
|
+
matrix:
|
17
|
+
combo:
|
18
|
+
- name: Opal-master
|
19
|
+
opal: master
|
20
|
+
- name: Opal-1.4
|
21
|
+
opal: 1.4
|
22
|
+
- name: Opal-1.3
|
23
|
+
opal: 1.3
|
24
|
+
- name: Opal-1.2
|
25
|
+
opal: 1.2
|
26
|
+
- name: Opal-1.1
|
27
|
+
opal: 1.1
|
28
|
+
- name: Opal-1.0
|
29
|
+
opal: '1.0'
|
30
|
+
- name: Ruby-head
|
31
|
+
ruby: head
|
32
|
+
- name: Windows
|
33
|
+
os: windows-latest
|
34
|
+
- name: macOS
|
35
|
+
os: macos-latest
|
36
|
+
|
37
|
+
runs-on: ${{ matrix.combo.os || 'ubuntu-latest' }}
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- uses: actions/checkout@v2
|
41
|
+
- name: set environment variables
|
42
|
+
run: |
|
43
|
+
echo "OPAL_VERSION=${{ matrix.combo.opal || '1.3' }}" >> $GITHUB_ENV
|
44
|
+
- uses: ruby/setup-ruby@v1
|
45
|
+
with:
|
46
|
+
ruby-version: ${{ matrix.combo.ruby || '3.0' }}
|
47
|
+
- run: bundle lock
|
48
|
+
- uses: actions/cache@v2
|
49
|
+
with:
|
50
|
+
path: ./vendor/bundle
|
51
|
+
key: ${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.3' }}-${{ github.ref }}-${{ hashFiles('**/Gemfile.lock') }}
|
52
|
+
restore-keys: |
|
53
|
+
${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.3' }}-${{ github.ref }}
|
54
|
+
${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.3' }}-master
|
55
|
+
${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-${{ matrix.combo.opal || '1.3' }}-
|
56
|
+
${{ runner.os }}-${{ matrix.combo.ruby || '3.0' }}-gems-
|
57
|
+
- name: bundle install
|
58
|
+
run: |
|
59
|
+
bundle config path $PWD/vendor/bundle
|
60
|
+
bundle install --jobs 4 --retry 3
|
61
|
+
bundle clean
|
62
|
+
- run: bundle exec rake
|
63
|
+
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
@@ -3,14 +3,20 @@ source "https://rubygems.org"
|
|
3
3
|
# Specify your gem's dependencies in opal-optimizer.gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
gem "rake"
|
7
|
-
gem "rspec"
|
6
|
+
gem "rake"
|
7
|
+
gem "rspec"
|
8
8
|
|
9
|
-
|
9
|
+
case ENV['OPAL_VERSION']
|
10
|
+
when nil
|
11
|
+
when /\A[0-9.]+\z/
|
12
|
+
gem 'opal', "~> #{ENV['OPAL_VERSION']}.0a"
|
13
|
+
else
|
14
|
+
gem 'opal', github: 'opal/opal', ref: ENV['OPAL_VERSION']
|
15
|
+
end
|
10
16
|
gem "opal-sprockets"
|
11
|
-
gem "opal-browser"
|
17
|
+
gem "opal-browser"
|
12
18
|
|
13
|
-
gem "rkelly-turbo"
|
19
|
+
gem "rkelly-turbo"
|
14
20
|
|
15
21
|
gem "ruby-prof"
|
16
22
|
gem "pry"
|
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# Opal::Optimizer
|
2
2
|
|
3
|
-
|
3
|
+
A utility to optimize the JavaScript output from Opal with a help of RKelly-Turbo JavaScript parser.
|
4
4
|
|
5
|
-
|
5
|
+
As of now it contains two steps:
|
6
|
+
|
7
|
+
* Tree shaking for Opal methods - if a named method is not called anywhere in the code, it's removed
|
8
|
+
* Collapsing stubs
|
6
9
|
|
7
10
|
## Installation
|
8
11
|
|
@@ -22,7 +25,7 @@ Or install it yourself as:
|
|
22
25
|
|
23
26
|
## Usage
|
24
27
|
|
25
|
-
|
28
|
+
For Sprockets environments, all you need is to `require "opal/optimizer/sprockets"` in your pipeline.
|
26
29
|
|
27
30
|
## Development
|
28
31
|
|
@@ -32,7 +35,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
35
|
|
33
36
|
## Contributing
|
34
37
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/hmdne/opal-optimizer.
|
36
39
|
|
37
40
|
|
38
41
|
## License
|
data/bin/opal-optimizer
CHANGED
data/exe/opal-optimizer
ADDED
@@ -11,8 +11,12 @@ class CollapseStubs < Step
|
|
11
11
|
|
12
12
|
nodes = corelib_calls["add_stubs"] || []
|
13
13
|
nodes.each do |node|
|
14
|
-
|
15
|
-
|
14
|
+
if opal_version >= 1.4
|
15
|
+
stubs += node.arguments.value.first.value[1..-2].split(',')
|
16
|
+
else
|
17
|
+
stubs += node.arguments.value.first.value.map do |i|
|
18
|
+
i.value.value.gsub(/['"]/, '')
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
node.destroy! "CollapseStubs"
|
@@ -26,7 +30,7 @@ class CollapseStubs < Step
|
|
26
30
|
stubs -= ["$respond_to_missing?"] if opal_version >= 1.1
|
27
31
|
|
28
32
|
new_stub_code = <<~end
|
29
|
-
var stubs = '#{stubs.to_a.join('
|
33
|
+
var stubs = '#{stubs.to_a.join(',')}'.split(','), stubs_obj = {};
|
30
34
|
for (var i = 0; i < stubs.length; i++)
|
31
35
|
stubs_obj[stubs[i]] = {value: Opal.stub_for(stubs[i]), enumerable: false, configurable: true, writable: true};
|
32
36
|
Object.defineProperties(Opal.BasicObject.$$prototype, stubs_obj);
|
@@ -24,7 +24,7 @@ class TreeShaking < Step
|
|
24
24
|
StringNode === i.value.accessor &&
|
25
25
|
i.value.accessor.value[1] == '$'
|
26
26
|
i.value.accessor.value[1..-2]
|
27
|
-
elsif i.value_path?(ResolveNode,
|
27
|
+
elsif i.value_path?(ResolveNode, ->(i) { %w[$send $send2 $refined_send].include? i })
|
28
28
|
old = i.arguments.value[1]
|
29
29
|
"$" + old.value[1..-2] if StringNode === old
|
30
30
|
end
|
@@ -77,8 +77,17 @@ class TreeShaking < Step
|
|
77
77
|
end
|
78
78
|
|
79
79
|
corelib_calls["add_stubs"].each do |stubcall|
|
80
|
-
|
81
|
-
|
80
|
+
if opal_version >= 1.4
|
81
|
+
stubs = stubcall.arguments.value.first.value
|
82
|
+
new_stubs = stubs[1..-2].split(",").reject do |i|
|
83
|
+
removed.include? i
|
84
|
+
end.join(',')
|
85
|
+
new_stubs = "'#{new_stubs}'"
|
86
|
+
stubs.replace(new_stubs)
|
87
|
+
else
|
88
|
+
stubcall.arguments.value.first.value.reject! do |i|
|
89
|
+
removed.include? i.value.value[1..-2]
|
90
|
+
end
|
82
91
|
end
|
83
92
|
end
|
84
93
|
|
data/lib/opal/optimizer.rb
CHANGED
@@ -26,7 +26,11 @@ module Opal
|
|
26
26
|
elsif es.start_with?("(function(global_object) {\n \"use strict\";\n\n // @note\n "\
|
27
27
|
"// A few conventions for the documentation of this file:") &&
|
28
28
|
es.end_with?("TypeError.$$super = Error;\n}).call(this);")
|
29
|
-
|
29
|
+
if es.include? 'function $prop(object,'
|
30
|
+
@opal_version = 1.4
|
31
|
+
else
|
32
|
+
@opal_version = 1.1
|
33
|
+
end
|
30
34
|
end
|
31
35
|
end
|
32
36
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-optimizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hmdne
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rkelly-turbo
|
@@ -40,21 +40,24 @@ dependencies:
|
|
40
40
|
version: 1.0.0
|
41
41
|
description:
|
42
42
|
email: []
|
43
|
-
executables:
|
43
|
+
executables:
|
44
|
+
- opal-optimizer
|
44
45
|
extensions: []
|
45
46
|
extra_rdoc_files: []
|
46
47
|
files:
|
48
|
+
- ".github/workflows/build.yml"
|
47
49
|
- ".gitignore"
|
48
50
|
- ".rspec"
|
49
51
|
- ".travis.yml"
|
52
|
+
- CHANGELOG.md
|
50
53
|
- Gemfile
|
51
|
-
- Gemfile.lock
|
52
54
|
- LICENSE.txt
|
53
55
|
- README.md
|
54
56
|
- Rakefile
|
55
57
|
- bin/console
|
56
58
|
- bin/opal-optimizer
|
57
59
|
- bin/setup
|
60
|
+
- exe/opal-optimizer
|
58
61
|
- lib/opal/optimizer.rb
|
59
62
|
- lib/opal/optimizer/helpers.rb
|
60
63
|
- lib/opal/optimizer/sprockets.rb
|
data/Gemfile.lock
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: ../opal-browser
|
3
|
-
specs:
|
4
|
-
opal-browser (0.2.0)
|
5
|
-
opal (>= 1.0, < 2.0)
|
6
|
-
paggio
|
7
|
-
|
8
|
-
PATH
|
9
|
-
remote: ../opal
|
10
|
-
specs:
|
11
|
-
opal (1.3.0.alpha1)
|
12
|
-
ast (>= 2.3.0)
|
13
|
-
parser (~> 3.0)
|
14
|
-
|
15
|
-
PATH
|
16
|
-
remote: ../rkelly-turbo
|
17
|
-
specs:
|
18
|
-
rkelly-turbo (0.1.1.20210526224136)
|
19
|
-
|
20
|
-
PATH
|
21
|
-
remote: .
|
22
|
-
specs:
|
23
|
-
opal-optimizer (0.1.4)
|
24
|
-
opal (>= 1.0.0)
|
25
|
-
rkelly-turbo
|
26
|
-
|
27
|
-
GEM
|
28
|
-
remote: https://rubygems.org/
|
29
|
-
specs:
|
30
|
-
ast (2.4.2)
|
31
|
-
coderay (1.1.3)
|
32
|
-
concurrent-ruby (1.1.9)
|
33
|
-
diff-lcs (1.4.4)
|
34
|
-
method_source (1.0.0)
|
35
|
-
opal-sprockets (1.0.1)
|
36
|
-
opal (>= 1.0, < 2.0)
|
37
|
-
sprockets (~> 4.0)
|
38
|
-
tilt (>= 1.4)
|
39
|
-
paggio (0.2.6)
|
40
|
-
parser (3.0.2.0)
|
41
|
-
ast (~> 2.4.1)
|
42
|
-
pry (0.14.1)
|
43
|
-
coderay (~> 1.1)
|
44
|
-
method_source (~> 1.0)
|
45
|
-
rack (2.2.3)
|
46
|
-
rake (12.3.3)
|
47
|
-
rspec (3.10.0)
|
48
|
-
rspec-core (~> 3.10.0)
|
49
|
-
rspec-expectations (~> 3.10.0)
|
50
|
-
rspec-mocks (~> 3.10.0)
|
51
|
-
rspec-core (3.10.1)
|
52
|
-
rspec-support (~> 3.10.0)
|
53
|
-
rspec-expectations (3.10.1)
|
54
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
-
rspec-support (~> 3.10.0)
|
56
|
-
rspec-mocks (3.10.2)
|
57
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
58
|
-
rspec-support (~> 3.10.0)
|
59
|
-
rspec-support (3.10.2)
|
60
|
-
ruby-prof (1.4.3)
|
61
|
-
sprockets (4.0.2)
|
62
|
-
concurrent-ruby (~> 1.0)
|
63
|
-
rack (> 1, < 3)
|
64
|
-
tilt (2.0.10)
|
65
|
-
|
66
|
-
PLATFORMS
|
67
|
-
ruby
|
68
|
-
|
69
|
-
DEPENDENCIES
|
70
|
-
opal!
|
71
|
-
opal-browser!
|
72
|
-
opal-optimizer!
|
73
|
-
opal-sprockets
|
74
|
-
pry
|
75
|
-
rake (~> 12.0)
|
76
|
-
rkelly-turbo!
|
77
|
-
rspec (~> 3.0)
|
78
|
-
ruby-prof
|
79
|
-
|
80
|
-
BUNDLED WITH
|
81
|
-
2.1.4
|