Skip to content

Commit

Permalink
Parser::Builder::Default.check_lvar_name patch
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Apr 13, 2021
1 parent 0efa9ef commit ab16575
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions demo/nodetest.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ assert.strictEqual(
to_js('foo.empty?', {filters: ['functions']}),
'foo.length == 0');

assert.strictEqual(
to_js('1 => foo'),
'var foo = 1');

let ast = Ruby2JS.convert('String', {file: 'a.rb'}).ast
assert.strictEqual(ast.constructor, Ruby2JS.AST.Node)
assert.strictEqual(ast.type, "const")
Expand Down
13 changes: 13 additions & 0 deletions demo/patch.opal
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,16 @@ Opal.Ruby2JS.Token.$new = function(str, ast) {
if (ast) token.loc = ast.$location();
return token;
}`

# https://github.com/opal/opal/issues/2195
module Parser
class Builders::Default
def check_lvar_name(name, loc)
if name =~ /^[_a-z][_\w]*$/
# OK
else
diagnostic :error, :lvar_name, { name: name }, loc
end
end
end
end

0 comments on commit ab16575

Please sign in to comment.