ast_transform 2.1.0 → 2.1.2

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: 11aae5afaee14319577bb90868a9409f8b6eb7525731fcc9c61e64b7d638d5ff
4
- data.tar.gz: de05ce9d6d76f090dbe4530976b8614269084c8ea5196a6bc648a56b0e2280b9
3
+ metadata.gz: 3322dbf3c31a96df5ddea9892b60c40b785842500c13f178d1a9b11b5842bf12
4
+ data.tar.gz: aef4ed8d812275368ec5f22c61d9b3d049ecc42490c406d08e8afd4e34e589e7
5
5
  SHA512:
6
- metadata.gz: e60d5134197b6ce4c4c84bebb7d095c84dc7a369ec0d08d44a429a1b6e3df2e79895023f5780867896534808bcf1ffddba563d30751e92074f26acd7a2c40e4e
7
- data.tar.gz: 1d5ecf0ecaeab6b12ff8ffae425711d187693261c747bb1da2e0672b9ad0b12515318c7e3237b01b6efa4580f4d61d4acba046b2e538f7176a70fe88b9883dc1
6
+ metadata.gz: bfd3828a33d2668a854ed4d5b1c299615ca47e92232ccf6705b008437cdb43e6497b9ef517e2664f5cd68b9197f9cc78ef2bd50090152f7889490a18e28cf72a
7
+ data.tar.gz: 6f9647eaad1208d3cacb9ba038f8e63ff213d1ae7030bb96ec0a28386125096526f64bffa93100795427d67c2671b2638711c9ca891222beac01b0c046a07afc
data/.claude/CLAUDE.md ADDED
@@ -0,0 +1,2 @@
1
+ See @../.cursor/rules/base.mdc for information on your desired behavior.
2
+ See @../.cursor/rules/best-practices.mdc for our best practices (snapshot we own and evolve).
@@ -0,0 +1,35 @@
1
+ ---
2
+ description: Principal Engineer persona and code guidelines (stack-agnostic)
3
+ globs:
4
+ alwaysApply: true
5
+ ---
6
+ As a Principal Engineer, the highest ranking engineer at our company, you are tasked with creating clear, readable code. You use the latest version of the stack's technologies and follow their best practices and conventions, as well as this repo's and our org's best practices. Follow Shopify-style development philosophy and industry best practices where applicable.
7
+
8
+ When responding to questions, follow the Chain of Thought method. First, outline a detailed plan step by step in great detail, then outline that plan in pseudocode, then confirm it, then write the code, and rewrite the code for concision and readability.
9
+
10
+ You carefully provide accurate, factual, thoughtful answers, and are a genius at reasoning; but you always admit when you don't know the answer.
11
+
12
+ Remember the following important mindset when providing code, in the following order:
13
+ - Adherence to conventions and patterns in the rest of the codebase
14
+ - Simplicity
15
+ - Readability
16
+ - Testability
17
+ - Explicitness
18
+ - Beginner-friendly
19
+
20
+ Adhere to the following guidelines in your code:
21
+ - Follow the user's requirements carefully and to the letter.
22
+ - Fully implement all requested functionality.
23
+ - Leave no TODOs, FIXMEs, placeholders or missing pieces.
24
+ - Always consider the experience of a developer who will be reading your code.
25
+ - Use comments to explain why you are doing something in a certain way, if it is not obvious. If unsure, leave a comment.
26
+ - Employ descriptive, human-readable variable and function/const names.
27
+ - Prefer writing in a functional style where it fits, producing pure functions that do not cause side effects when practical.
28
+ - The codebase is strictly linted; follow the existing code style to ensure consistency.
29
+ - If the generated code would fail a lint check, refactor the code until it no longer fails the lint check.
30
+ - Search hard to find an existing function or pattern in the codebase where possible.
31
+ - Be sure to reference file names when relevant.
32
+ - Be concise. Minimize any prose other than code.
33
+ - If you think there might not be a correct answer, say so. If you do not know the answer, say so instead of guessing.
34
+ - In tests, always avoid mocking the filesystem. Use real files and directories, in temporary directories if needed.
35
+ - In tests, prefer to have as little shared state between tests as possible. Avoid beforeAll and afterAll.
@@ -0,0 +1,27 @@
1
+ ---
2
+ description: Our best practices (snapshot we own and evolve; often org-wide across repos)
3
+ globs:
4
+ alwaysApply: true
5
+ ---
6
+ # Best practices (d3mlabs snapshot)
7
+
8
+ We own this snapshot and evolve it as the org diverges. In practice these practices are often shared org-wide across repos for consistency.
9
+
10
+ ## Priorities
11
+
12
+ - **Conventions over configuration**: Follow existing patterns and tooling before introducing new ones.
13
+ - **Clarity and maintainability**: Code should be easy to read and change; prefer explicit over clever.
14
+ - **Testability**: Design so that behavior can be tested with real inputs and minimal mocks.
15
+ - **Explicitness**: Prefer clear, named steps and obvious control flow over brevity that hides intent.
16
+
17
+ ## Code and tests
18
+
19
+ - No TODOs, FIXMEs, or placeholders in committed code; finish or track elsewhere.
20
+ - In tests: use real files and temporary directories; avoid filesystem mocks.
21
+ - Minimal shared state between tests; avoid beforeAll/afterAll and global fixtures.
22
+ - Strict lint and existing code style; refactor until lint passes.
23
+ - Prefer existing helpers and patterns in the codebase; search before adding new abstractions.
24
+
25
+ ## Further reading
26
+
27
+ - [Shopify Engineering](https://shopify.engineering) — blog and engineering culture.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ast_transform (2.1.0)
4
+ ast_transform (2.1.2)
5
5
  parser (>= 3.0)
6
6
  prism (>= 1.5)
7
7
  unparser (>= 0.6)
@@ -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
@@ -66,7 +66,7 @@ module ASTTransform
66
66
  #
67
67
  # @return [Integer] The line count.
68
68
  def line_count
69
- @transformed_ranges_ast&.loc&.expression.last_line || 0
69
+ @transformed_ranges_ast&.loc&.expression&.last_line || 0
70
70
  end
71
71
 
72
72
  private
@@ -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
- # @param builder [Prism::Translation::Parser::Builder] The AST Node builder.
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(@builder)
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)
@@ -1,3 +1,3 @@
1
1
  module ASTTransform
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ast_transform
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Philippe Duchesne
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-02-21 00:00:00.000000000 Z
11
+ date: 2026-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -143,6 +143,9 @@ executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
+ - ".claude/CLAUDE.md"
147
+ - ".cursor/rules/base.mdc"
148
+ - ".cursor/rules/best-practices.mdc"
146
149
  - ".github/workflows/ci.yml"
147
150
  - ".github/workflows/release.yml"
148
151
  - ".gitignore"
@@ -161,6 +164,7 @@ files:
161
164
  - lib/ast_transform/instruction_sequence/bootsnap_mixin.rb
162
165
  - lib/ast_transform/instruction_sequence/mixin.rb
163
166
  - lib/ast_transform/instruction_sequence/mixin_utils.rb
167
+ - lib/ast_transform/kwargs_builder.rb
164
168
  - lib/ast_transform/source_map.rb
165
169
  - lib/ast_transform/transformation.rb
166
170
  - lib/ast_transform/transformation_helper.rb