klenod-runtime 0.0.32 → 0.0.33

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f203f703da244fb7adbd823ded54aacc140a841e01bb5b325a615181ec62123
4
- data.tar.gz: 8cf9b3a31bc0c3b99438eda2a85a495d9f23833f65eafd01f63f8736fd71b525
3
+ metadata.gz: 5196a812b8794de88476339a6b580785c46d138fa507f3cf3130b37ef4821599
4
+ data.tar.gz: 3185076e03e4ab0e81dc706987b77f4fb223dee0b41b944f59ea62430a17e083
5
5
  SHA512:
6
- metadata.gz: 531484eb564da5470db83c22155af8b83179e7ab0a5ccd0e367a4412da2cacf4f1988bd3ac229139706d31df88ffa61e3f5d8a3ac37525e1464a11f76ea1cef6
7
- data.tar.gz: a01cd73c496775c7abbc8ee659d3f8d08dbb7c752478cb8f6ada6c48d780bedde34945f9a373e71e29e18305296334336353d524267845704b2c45a1e900491b
6
+ metadata.gz: fc01490e964b9e9e3e34a07cd9c70b131be33a2008d727027b009b257ac951fdfa4e82491b6c003420b13708ec263298382552021f3770cbcb3e855fa072006f
7
+ data.tar.gz: 2d372314dfa0c9271d02c5d969eac0b7344facda04f896659c7c754dba293cdbf2acf0cf04870c203a6c0dcbb48dcc28ceac0df115f3d61643dc0f5f0169f2f6
@@ -251,7 +251,14 @@ module Klenod
251
251
  end
252
252
  end
253
253
 
254
+ # Decoded values are deeply frozen, like the generated module literals
255
+ # they stand in for, so data imports behave the same in development
256
+ # and in a bundle.
254
257
  def decode_value(value)
258
+ decode_unfrozen_value(value).freeze
259
+ end
260
+
261
+ def decode_unfrozen_value(value)
255
262
  case value
256
263
  when nil, true, false, String, Integer, Float
257
264
  value
@@ -55,6 +55,9 @@ module Klenod
55
55
  end
56
56
  end
57
57
 
58
+ FROZEN_STRING_LITERAL_PREFIX = "# frozen_string_literal: true\n"
59
+ MAGIC_COMMENT_PATTERN = /\A#.*\b(?:frozen_string_literal|(?:en)?coding)\s*[:=]/i
60
+
58
61
  attr_reader :path, :source, :source_map, :version, :constant_name, :eval_path, :namespace
59
62
 
60
63
  def self.constant_name_for(path)
@@ -107,7 +110,27 @@ module Klenod
107
110
 
108
111
  exports = Exports.new(self, @imports)
109
112
  const_set(:Exports, exports)
110
- exports.module_eval(@source, @eval_path, 1)
113
+ exports.module_eval(*evaluated_source)
114
+ end
115
+
116
+ # Modules are evaluated with frozen string literals unless their leading
117
+ # comments set a magic comment themselves. The prefix is evaluated as
118
+ # line 0, so every line keeps its number in backtraces and coverage.
119
+ def evaluated_source
120
+ return [@source, @eval_path, 1] if leading_magic_comment?
121
+
122
+ [FROZEN_STRING_LITERAL_PREFIX + @source, @eval_path, 0]
123
+ end
124
+
125
+ def leading_magic_comment?
126
+ @source.each_line do |line|
127
+ stripped = line.strip
128
+ next if stripped.empty?
129
+ return false unless stripped.start_with?("#")
130
+ return true if stripped.match?(MAGIC_COMMENT_PATTERN)
131
+ end
132
+
133
+ false
111
134
  end
112
135
  end
113
136
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Klenod
4
4
  module Runtime
5
- VERSION = "0.0.32"
5
+ VERSION = "0.0.33"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klenod-runtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.32
4
+ version: 0.0.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrés Alin