Skip to content

Commit

Permalink
Merge pull request #2074 from opal/elia/fix-parsing-unicode-v1.0
Browse files Browse the repository at this point in the history
Fix parsing unicode on v1.0
  • Loading branch information
elia committed Feb 1, 2020
2 parents 5a7561c + c92dfd9 commit 6ea8f2e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/opal/parser/patch.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# frozen_string_literal: true

if RUBY_ENGINE == 'opal'
class Parser::Lexer
def source_buffer=(source_buffer)
@source_buffer = source_buffer

if @source_buffer
source = @source_buffer.source
# Force UTF8 unpacking even if JS works with UTF-16/UCS-2
# See: https://mathiasbynens.be/notes/javascript-encoding
@source_pts = source.unpack('U*')
else
@source_pts = nil
end
end
end

class Parser::Lexer::Literal
undef :extend_string

Expand Down
10 changes: 10 additions & 0 deletions spec/opal/compiler/unicode_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'spec_helper'
require 'opal-parser'

describe Opal::Compiler do
describe "unicode support" do
it 'can compile code containing Unicode characters' do
-> { Opal::Compiler.new("'こんにちは'; p 1").compile }.should_not raise_error
end
end
end

0 comments on commit 6ea8f2e

Please sign in to comment.