ast_transform 2.1.1 → 2.1.4
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/Gemfile.lock +1 -1
- data/lib/ast_transform/instruction_sequence/mixin.rb +5 -2
- data/lib/ast_transform/instruction_sequence.rb +1 -1
- data/lib/ast_transform/kwargs_builder.rb +22 -0
- data/lib/ast_transform/source_map.rb +1 -0
- data/lib/ast_transform/transformer.rb +3 -4
- data/lib/ast_transform/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '02391c6a71f241da83617ab3dae2ff61a66c7a9ad3f9d154c6f6f3aee29e86ad'
|
|
4
|
+
data.tar.gz: 9b25a4ae5581efc378793af4b4d3d4fd697cc88104567610caf4dea77c2d4d64
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0e0c312499e1abdd8eea7f2c704cf3aaca4a06ed1b7c62c048bb6f4b350b85a89fc9170c8dc0d0cfd84d5b1e2c9822608a4767600350c097b1da1f4c98f5d759
|
|
7
|
+
data.tar.gz: d02faba1167586d4bb7aceb138b3452e3cb9ab7c2f294ae02803fb09a565d5ea884ec44568ec60efa1ab3b6600cc17fe911559c02afb6d8e5350bf37ce83ed04
|
data/Gemfile.lock
CHANGED
|
@@ -10,9 +10,12 @@ module ASTTransform
|
|
|
10
10
|
def load_iseq(source_path)
|
|
11
11
|
return ASTTransform::MixinUtils.try_super(self, :load_iseq, source_path) if source_path == __FILE__
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
# Binary read avoids encoding errors during the fast-path check below.
|
|
14
|
+
# Downstream (Prism, RubyVM::InstructionSequence) handle encoding natively
|
|
15
|
+
# via magic comments, so we never need to set it ourselves.
|
|
16
|
+
source = File.binread(source_path)
|
|
14
17
|
|
|
15
|
-
return ASTTransform::MixinUtils.try_super(self, :load_iseq, source_path) unless source
|
|
18
|
+
return ASTTransform::MixinUtils.try_super(self, :load_iseq, source_path) unless source.include?('transform!'.b)
|
|
16
19
|
|
|
17
20
|
ASTTransform::InstructionSequence.source_to_transformed_iseq(source, source_path)
|
|
18
21
|
end
|
|
@@ -16,7 +16,7 @@ module ASTTransform
|
|
|
16
16
|
rewritten_source = transformer.transform_file_source(source, source_path, rewritten_file_pathname.to_s)
|
|
17
17
|
write(rewritten_source, rewritten_file_pathname)
|
|
18
18
|
|
|
19
|
-
RubyVM::InstructionSequence.compile(rewritten_source,
|
|
19
|
+
RubyVM::InstructionSequence.compile(rewritten_source, source_path, source_path)
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def write_pathname(file_path)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'prism/translation/parser'
|
|
4
|
+
|
|
5
|
+
module ASTTransform
|
|
6
|
+
# Extends the default Prism parser builder to distinguish keyword arguments
|
|
7
|
+
# from hash literals in the AST.
|
|
8
|
+
#
|
|
9
|
+
# The upstream builder always emits :hash nodes for both `foo(bar: 1)` and
|
|
10
|
+
# `foo({ bar: 1 })`. Unparser uses the node type to decide whether to emit
|
|
11
|
+
# braces: :hash gets `{}`, :kwargs does not. Since Ruby 3.0+ treats these as
|
|
12
|
+
# semantically different (strict keyword/positional separation), we need the
|
|
13
|
+
# AST to preserve the distinction.
|
|
14
|
+
class KwargsBuilder < Prism::Translation::Parser::Builder
|
|
15
|
+
def associate(begin_t, pairs, end_t)
|
|
16
|
+
node = super
|
|
17
|
+
return node unless begin_t.nil? && end_t.nil?
|
|
18
|
+
|
|
19
|
+
node.updated(:kwargs)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
require 'prism'
|
|
3
3
|
require 'prism/translation/parser'
|
|
4
4
|
require 'unparser'
|
|
5
|
+
require 'ast_transform/kwargs_builder'
|
|
5
6
|
require 'ast_transform/source_map'
|
|
6
7
|
|
|
7
8
|
module ASTTransform
|
|
@@ -9,10 +10,8 @@ module ASTTransform
|
|
|
9
10
|
# Constructs a new Transformer instance.
|
|
10
11
|
#
|
|
11
12
|
# @param transformations [Array<ASTTransform::AbstractTransformation>] The transformations to be run.
|
|
12
|
-
|
|
13
|
-
def initialize(*transformations, builder: Prism::Translation::Parser::Builder.new)
|
|
13
|
+
def initialize(*transformations)
|
|
14
14
|
@transformations = transformations
|
|
15
|
-
@builder = builder
|
|
16
15
|
end
|
|
17
16
|
|
|
18
17
|
# Builds the AST for the given +source+.
|
|
@@ -100,7 +99,7 @@ module ASTTransform
|
|
|
100
99
|
|
|
101
100
|
def parser
|
|
102
101
|
@parser&.reset
|
|
103
|
-
@parser ||= Prism::Translation::Parser.new(
|
|
102
|
+
@parser ||= Prism::Translation::Parser.new(ASTTransform::KwargsBuilder.new)
|
|
104
103
|
end
|
|
105
104
|
|
|
106
105
|
def register_source_map(source_file_path, transformed_file_path, transformed_ast, transformed_source)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ast_transform
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.1.
|
|
4
|
+
version: 2.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jean-Philippe Duchesne
|
|
@@ -164,6 +164,7 @@ files:
|
|
|
164
164
|
- lib/ast_transform/instruction_sequence/bootsnap_mixin.rb
|
|
165
165
|
- lib/ast_transform/instruction_sequence/mixin.rb
|
|
166
166
|
- lib/ast_transform/instruction_sequence/mixin_utils.rb
|
|
167
|
+
- lib/ast_transform/kwargs_builder.rb
|
|
167
168
|
- lib/ast_transform/source_map.rb
|
|
168
169
|
- lib/ast_transform/transformation.rb
|
|
169
170
|
- lib/ast_transform/transformation_helper.rb
|