Skip to content

Commit c49051e

Browse files
Earlopainmatzbot
authored andcommitted
[ruby/prism] Enforce a minimum parser version for the parser translator
There hasn't been much that would actually affect parsers usage of it. But, when adding new node types, these usually appear in the `Parser::Meta::NODE_TYPES`. `itblock` was added, gets emitted by prism, and then `rubocop-ast` blindly delegates to `on_itblock`. These methods are dynamically created through `NODE_TYPES`, which means that it will error if it doesn't contain `itblock`. This is unfortunate because in `rubocop-ast` these methods are eagerly defined but the prism translator is lazily loaded on demand. The simplest solution is to add them on the `parser` side (even if they are not emitted directly), and require that a version that contains those be used. In summary when adding a new node type: * Add it to `Parser::Meta::PRISM_TRANSLATION_PARSER_NODE_TYPES` (gets included in `NODE_TYPES`) * Bump the minimum `parser` version used by `prism` to a version that contains the above change * Actually emit that node type in `prism` ruby/prism@d73783d065
1 parent 13e6f71 commit c49051e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/prism/translation/parser.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# frozen_string_literal: true
22

33
begin
4+
required_version = ">= 3.3.7.2"
5+
gem "parser", required_version
46
require "parser"
57
rescue LoadError
6-
warn(%q{Error: Unable to load parser. Add `gem "parser"` to your Gemfile.})
8+
warn(<<~MSG)
9+
Error: Unable to load parser #{required_version}. \
10+
Add `gem "parser"` to your Gemfile or run `bundle update parser`.
11+
MSG
712
exit(1)
813
end
914

0 commit comments

Comments
 (0)