source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | opal/opal | https://github.com/opal/opal | stdlib/bigdecimal.rb | Ruby | mit | 4,915 | master | 5,272 | # backtick_javascript: true
class BigDecimal < Numeric; end
require 'opal/raw'
require 'bigdecimal/bignumber'
module Kernel
def BigDecimal(initial, digits = 0)
bigdecimal = BigDecimal.allocate
bigdecimal.initialize(initial, digits)
bigdecimal
end
end
def BigDecimal.new(*args, **kwargs)
warn 'BigDe... |
github | opal/opal | https://github.com/opal/opal | stdlib/strscan.rb | Ruby | mit | 4,915 | master | 5,503 | # backtick_javascript: true
class StringScanner
attr_reader :pos, :matched
def initialize(string)
@string = string
@pos = 0
@matched = nil
@working = string
@match = []
end
attr_reader :string
def beginning_of_line?
`#{@pos} === 0 || #{@string}.charAt(#{@pos} - 1) === "\n"`
... |
github | opal/opal | https://github.com/opal/opal | stdlib/shellwords.rb | Ruby | mit | 4,915 | master | 7,326 | # frozen-string-literal: true
##
# == Manipulates strings like the UNIX Bourne shell
#
# This module manipulates strings according to the word parsing rules
# of the UNIX Bourne shell.
#
# The shellwords() function was originally a port of shellwords.pl,
# but modified to conform to the Shell & Utilities volume of the ... |
github | opal/opal | https://github.com/opal/opal | stdlib/matrix/lup_decomposition.rb | Ruby | mit | 4,915 | master | 5,531 | # frozen_string_literal: false
class Matrix
# Adapted from JAMA: http://math.nist.gov/javanumerics/jama/
#
# For an m-by-n matrix A with m >= n, the LU decomposition is an m-by-n
# unit lower triangular matrix L, an n-by-n upper triangular matrix U,
# and a m-by-m permutation matrix P so that L*U = P*A.
# ... |
github | opal/opal | https://github.com/opal/opal | stdlib/matrix/eigenvalue_decomposition.rb | Ruby | mit | 4,915 | master | 22,068 | # frozen_string_literal: false
class Matrix
# Adapted from JAMA: http://math.nist.gov/javanumerics/jama/
# Eigenvalues and eigenvectors of a real matrix.
#
# Computes the eigenvalues and eigenvectors of a matrix A.
#
# If A is diagonalizable, this provides matrices V and D
# such that A = V*D*V.inv, wher... |
github | opal/opal | https://github.com/opal/opal | stdlib/bun/base.rb | Ruby | mit | 4,915 | master | 717 | `/* global Bun */`
module Bun
VERSION = `Bun.version`
end
`Opal.exit = process.exit`
ARGV = `process.argv.slice(2)`
ARGV.shift if ARGV.first == '--'
$stdout.write_proc = ->(string) { `process.stdout.write(string)` }
$stderr.write_proc = ->(string) { `process.stderr.write(string)` }
`var __fs__ = require('fs')`
$... |
github | opal/opal | https://github.com/opal/opal | stdlib/quickjs/file.rb | Ruby | mit | 4,915 | master | 203 | class File
def self.read(path)
%x{
const body = std.loadFile(path);
if (body === null) {
throw new Error(`Unable to read "${path}"`);
}
return body;
}
end
end |
github | opal/opal | https://github.com/opal/opal | stdlib/quickjs/io.rb | Ruby | mit | 4,915 | master | 390 | # backtick_javascript: true
%x{
Opal.gvars.stdout.write_proc = function(s) {
std.out.printf("%s", s);
std.out.flush();
}
Opal.gvars.stderr.write_proc = function(s) {
std.err.printf("%s", s);
std.err.flush();
}
Opal.gvars.stdin.read_proc = function(s) {
if (std.in.eof()) {
return n... |
github | opal/opal | https://github.com/opal/opal | stdlib/deno/file.rb | Ruby | mit | 4,915 | master | 8,571 | # backtick_javascript: true
`/* global Deno */`
require 'corelib/file'
%x{
var warnings = {}, errno_codes = #{Errno.constants};
function handle_unsupported_feature(message) {
switch (Opal.config.unsupported_features_severity) {
case 'error':
#{Kernel.raise NotImplementedError, `message`}
brea... |
github | opal/opal | https://github.com/opal/opal | stdlib/deno/base.rb | Ruby | mit | 4,915 | master | 740 | # backtick_javascript: true
`/* global Deno */`
module Deno
VERSION = `Deno.version.deno`
end
`Opal.exit = Deno.exit`
ARGV = `Deno.args.slice(2)`
ARGV.shift if ARGV.first == '--'
STDOUT.write_proc = ->(string) { `Deno.stdout.write(new TextEncoder().encode(string))` }
STDERR.write_proc = ->(string) { `Deno.stderr... |
github | opal/opal | https://github.com/opal/opal | stdlib/date/formatters.rb | Ruby | mit | 4,915 | master | 720 | class Date
def self.def_formatter(*args, **kwargs)
Time.def_formatter(*args, **kwargs, on: self)
end
def_formatter :asctime, '%c'
alias ctime asctime
def_formatter :iso8601, '%F'
alias xmlschema iso8601
def_formatter :rfc3339, '%FT%T%:z'
def_formatter :rfc2822, '%a, %-d %b %Y %T %z'
alias rfc822 ... |
github | opal/opal | https://github.com/opal/opal | stdlib/date/infinity.rb | Ruby | mit | 4,915 | master | 941 | class Date
class Infinity < Numeric
include Comparable
def initialize(d = 1)
@d = d <=> 0
end
attr_reader :d
def zero?
false
end
def finite?
false
end
def infinite?
d.nonzero?
end
def nan?
d.zero?
end
def abs
self.class.new... |
github | opal/opal | https://github.com/opal/opal | stdlib/date/date_time.rb | Ruby | mit | 4,915 | master | 1,365 | # backtick_javascript: true
class DateTime < Date
class << self
def now
wrap Time.now
end
def parse(str)
wrap Time.parse(str)
end
end
def initialize(year = -4712, month = 1, day = 1, hours = 0, minutes = 0, seconds = 0, offset = 0, start = ITALY)
%x{
// Because of Gregoria... |
github | opal/opal | https://github.com/opal/opal | stdlib/optparse/version.rb | Ruby | mit | 4,915 | master | 2,018 | # frozen_string_literal: false
# OptionParser internal utility
class << OptionParser
def show_version(*pkgs)
progname = ARGV.options.program_name
result = false
show = proc do |klass, cname, version|
str = progname.to_s
unless (klass == ::Object) && (cname == :VERSION)
version = versi... |
github | opal/opal | https://github.com/opal/opal | stdlib/optparse/time.rb | Ruby | mit | 4,915 | master | 243 | # frozen_string_literal: false
require 'optparse'
require 'time'
OptionParser.accept(Time) do |s,|
if s
(begin
Time.httpdate(s)
rescue
Time.parse(s)
end)
end
rescue
raise OptionParser::InvalidArgument, s
end |
github | opal/opal | https://github.com/opal/opal | stdlib/optparse/date.rb | Ruby | mit | 4,915 | master | 316 | # frozen_string_literal: false
require 'optparse'
require 'date'
OptionParser.accept(DateTime) do |s,|
DateTime.parse(s) if s
rescue ArgumentError
raise OptionParser::InvalidArgument, s
end
OptionParser.accept(Date) do |s,|
Date.parse(s) if s
rescue ArgumentError
raise OptionParser::InvalidArgument, s
end |
github | opal/opal | https://github.com/opal/opal | stdlib/optparse/kwargs.rb | Ruby | mit | 4,915 | master | 534 | # frozen_string_literal: true
require 'optparse'
class OptionParser
# :call-seq:
# define_by_keywords(options, method, **params)
#
# :include: ../../doc/optparse/creates_option.rdoc
#
def define_by_keywords(options, meth, **opts)
meth.parameters.each do |type, name|
case type
when :key, :... |
github | opal/opal | https://github.com/opal/opal | stdlib/optparse/ac.rb | Ruby | mit | 4,915 | master | 1,556 | # frozen_string_literal: false
require 'optparse'
class OptionParser::AC < OptionParser
private
def _check_ac_args(name, block)
unless /\A\w[-\w]*\z/ =~ name
raise ArgumentError, name
end
unless block
raise ArgumentError, 'no block given', ParseError.filter_backtrace(caller)
end
end
... |
github | opal/opal | https://github.com/opal/opal | stdlib/buffer/view.rb | Ruby | mit | 4,915 | master | 2,673 | # backtick_javascript: true
class Buffer
class View
include Native::Wrapper
def self.supported?
!$$[:DataView].nil?
end
attr_reader :buffer, :offset
def initialize(buffer, offset = nil, length = nil)
if native?(buffer)
super(buffer)
elsif offset && length
supe... |
github | opal/opal | https://github.com/opal/opal | stdlib/buffer/array.rb | Ruby | mit | 4,915 | master | 1,218 | # backtick_javascript: true
class Buffer
class Array
include Native::Wrapper
def self.for(bits, type)
$$["#{Buffer.name_for bits, type}Array"]
end
include Enumerable
attr_reader :buffer, :type
def initialize(buffer, bits = nil, type = nil)
if Native == buffer
super(buf... |
github | opal/opal | https://github.com/opal/opal | stdlib/bigdecimal/util.rb | Ruby | mit | 4,915 | master | 3,027 | # frozen_string_literal: false
# backtick_javascript: true
#
#--
# bigdecimal/util extends various native classes to provide the #to_d method,
# and provides BigDecimal#to_d and BigDecimal#to_digits.
#++
require 'bigdecimal'
class Integer < Numeric
# call-seq:
# int.to_d -> bigdecimal
#
# Returns the val... |
github | opal/opal | https://github.com/opal/opal | stdlib/bigdecimal/bignumber.js.rb | Ruby | mit | 4,915 | master | 17,556 | # backtick_javascript: true
class BigDecimal < Numeric
%x{
var define = function (f) { Opal.const_set(self, 'BigNumber', f()); };
define.amd = true;
/* eslint-disable */
/* bignumber.js v2.1.4 https://github.com/MikeMcl/bignumber.js/LICENCE */
!function(e){"use strict";function n(e){function E(e... |
github | opal/opal | https://github.com/opal/opal | stdlib/gjs/io.rb | Ruby | mit | 4,915 | master | 869 | # backtick_javascript: true
`/* global imports */`
# Basic version, appends \n:
# $stdout.write_proc = `function(s){print(s)}`
# $stderr.write_proc = `function(s){printerr(s)}`
# Advanced version:
%x{
var GLib = imports.gi.GLib;
var ByteArray = imports.byteArray;
var stdin = GLib.IOChannel.unix_new(0);
var ... |
github | opal/opal | https://github.com/opal/opal | stdlib/opal/platform.rb | Ruby | mit | 4,915 | master | 475 | require 'opal-platform'
case OPAL_PLATFORM
when 'gjs' then require 'gjs'
when 'quickjs' then require 'quickjs'
when 'deno' then require 'deno/base'
when 'nodejs' then require 'nodejs/base'
when 'headless-chrome' then require 'headless_browser/base'
when 'headless-firefox' t... |
github | opal/opal | https://github.com/opal/opal | stdlib/opal/miniracer.rb | Ruby | mit | 4,915 | master | 208 | # backtick_javascript: true
`/* global opalminiracer */`
# Compatibility utilities for the API we provide in
# lib/opal/cli_runners/mini_racer
ARGV = `opalminiracer.argv`
`Opal.exit = opalminiracer.exit` |
github | opal/opal | https://github.com/opal/opal | stdlib/opal/raw.rb | Ruby | mit | 4,915 | master | 2,019 | # backtick_javascript: true
# The Opal::Raw module provides syntax sugar for calling native javascript
# operators (e.g. typeof, instanceof, new, delete) and global functions
# (e.g. parseFloat, parseInt).
module ::Opal
module Raw
# Use delete to remove a property from an object.
def delete(object, property)... |
github | opal/opal | https://github.com/opal/opal | stdlib/cgi/util.rb | Ruby | mit | 4,915 | master | 2,705 | # backtick_javascript: true
# This file contains parts of https://github.com/ruby/ruby/blob/master/lib/cgi/util.rb
# licensed under a Ruby license.
class CGI
module Util
# URL-encode a string into application/x-www-form-urlencoded.
# Space characters (+" "+) are encoded with plus signs (+"+"+)
# url_e... |
github | opal/opal | https://github.com/opal/opal | stdlib/headless_browser/file.rb | Ruby | mit | 4,915 | master | 497 | # frozen_string_literal: true
# backtick_javascript: true
class File
def self.write(path, data)
# This is only to enable CDP runners to write the benchmark results
%x{
var http = new XMLHttpRequest();
http.open("POST", "/File.write");
http.setRequestHeader("Content-Type", "application/json"... |
github | opal/opal | https://github.com/opal/opal | stdlib/headless_browser/base.rb | Ruby | mit | 4,915 | master | 462 | # backtick_javascript: true
%x{
// Inhibit the default exit behavior
window.OPAL_EXIT_CODE = "noexit";
Opal.exit = function(code) {
// The first call to Opal.exit should save an exit code.
// All next invocations must be ignored.
// Then we send an event to Chrome CDP Interface that we are finished
... |
github | opal/opal | https://github.com/opal/opal | stdlib/promise/v2.rb | Ruby | mit | 4,915 | master | 9,899 | # backtick_javascript: true
# {Promise} is used to help structure asynchronous code.
#
# It is available in the Opal standard library, and can be required in any Opal
# application:
#
# require 'promise/v2'
#
# ## Basic Usage
#
# Promises are created and returned as objects with the assumption that they
# will eve... |
github | opal/opal | https://github.com/opal/opal | stdlib/nodejs/dir.rb | Ruby | mit | 4,915 | master | 3,380 | # backtick_javascript: true
class Dir
@__pm__ = `require('picomatch')`
@__fs__ = `require('fs')`
@__path__ = `require('path')`
@__os__ = `require('os')`
`var __pm__ = #{@__pm__}`
`var __fs__ = #{@__fs__}`
`var __path__ = #{@__path__}`
`var __os__ = #{@__os__}`
%x{
function pwd() {
return p... |
github | opal/opal | https://github.com/opal/opal | stdlib/nodejs/file.rb | Ruby | mit | 4,915 | master | 9,495 | # backtick_javascript: true
require 'corelib/file'
%x{
var warnings = {}, errno_codes = #{Errno.constants};
function handle_unsupported_feature(message) {
switch (Opal.config.unsupported_features_severity) {
case 'error':
#{Kernel.raise NotImplementedError, `message`}
break;
case 'warning... |
github | opal/opal | https://github.com/opal/opal | stdlib/nodejs/env.rb | Ruby | mit | 4,915 | master | 994 | # backtick_javascript: true
ENV = Object.new
class << ENV
def [](name)
`process.env[#{name}] || nil`
end
def []=(name, value)
`process.env[#{name.to_s}] = #{value.to_s}`
end
def key?(name)
`process.env.hasOwnProperty(#{name})`
end
def empty?
`Object.keys(process.env).length === 0`
e... |
github | opal/opal | https://github.com/opal/opal | stdlib/nodejs/io.rb | Ruby | mit | 4,915 | master | 891 | # backtick_javascript: true
require 'nodejs/file'
%x{
function executeIOAction(action) {
try {
return action();
} catch (error) {
if (error.code === 'EACCES' ||
error.code === 'EISDIR' ||
error.code === 'EMFILE' ||
error.code === 'ENOENT' ||
error.code ===... |
github | opal/opal | https://github.com/opal/opal | stdlib/nodejs/tmpdir.rb | Ruby | mit | 4,915 | master | 458 | class Dir
def self.mktmpdir(prefix_suffix = nil, *_rest, **_options)
if `prefix_suffix.$$is_array`
prefix = prefix_suffix.join('')
elsif `prefix_suffix.$$is_string`
prefix = prefix_suffix
else
prefix = 'd'
end
path = `#@__fs__.mkdtempSync(prefix)`
if block_given?
res =... |
github | opal/opal | https://github.com/opal/opal | stdlib/nodejs/require.rb | Ruby | mit | 4,915 | master | 715 | # backtick_javascript: true
require 'opal-parser'
module Kernel
def __prepare_require__(path)
name = `Opal.normalize(#{path})`
full_path = name.end_with?('.rb') ? name : name + '.rb'
if `!Opal.modules[#{name}]`
ruby = File.read(full_path)
compiler = Opal::Compiler.new(ruby, requirable: true... |
github | opal/opal | https://github.com/opal/opal | stdlib/nodejs/base.rb | Ruby | mit | 4,915 | master | 723 | # backtick_javascript: true
module NodeJS
VERSION = `process.version`
end
`Opal.exit = process.exit`
ARGV = `process.argv.slice(2)`
ARGV.shift if ARGV.first == '--'
STDOUT.write_proc = ->(string) { `process.stdout.write(string)` }
STDERR.write_proc = ->(string) { `process.stderr.write(string)` }
`var __fs__ = re... |
github | opal/opal | https://github.com/opal/opal | stdlib/nodejs/yaml.rb | Ruby | mit | 4,915 | master | 379 | # backtick_javascript: true
require 'native'
require 'nodejs/js-yaml-3-6-1'
module YAML
@__yaml__ = `globalThis.jsyaml`
`var __yaml__ = #{@__yaml__}`
def self.load_path(path)
load(`#{File}.__fs__.readFileSync(#{path}, 'utf8')`)
end
def self.load(data)
loaded = `__yaml__.safeLoad(data)`
loaded ... |
github | opal/opal | https://github.com/opal/opal | stdlib/nodejs/pathname.rb | Ruby | mit | 4,915 | master | 289 | # backtick_javascript: true
require 'pathname'
class Pathname
include Comparable
@__path__ = `require('path')`
`var __path__ = #{@__path__}`
def absolute?
`__path__.isAbsolute(#{@path.to_str})`
end
def relative?
!absolute?
end
def to_path
@path
end
end |
github | opal/opal | https://github.com/opal/opal | stdlib/nodejs/argf.rb | Ruby | mit | 4,915 | master | 1,469 | ARGF = Object.new
class << ARGF
include Enumerable
def inspect
'ARGF'
end
def argv
ARGV
end
def file
fn = filename
if fn == '-'
$stdin
else
@file ||= File.open(fn, 'r')
end
end
def filename
return @filename if @filename
if argv == ['-']
'-'
elsi... |
github | opal/opal | https://github.com/opal/opal | stdlib/nodejs/fileutils.rb | Ruby | mit | 4,915 | master | 842 | # backtick_javascript: true
module FileUtils
extend self
`var __fs__ = #{File}.__fs__`
def chmod(mode, file_list)
raise NotImplementedError, 'symbolic mode is not supported, use numeric mode' if String === mode
Array(file_list).each do |file|
`__fs__.chmodSync(mode, file)`
end
end
def cp(... |
github | opal/opal | https://github.com/opal/opal | stdlib/nodejs/kernel.rb | Ruby | mit | 4,915 | master | 1,692 | # backtick_javascript: true
require 'buffer'
require 'corelib/process/status'
module Kernel
@__child_process__ = `require('node:child_process')`
@__cluster__ = `require('node:cluster')`
@__process__ = `require('node:process')`
`var __child_process__ = #{@__child_process__}`
`var __cluster__ = #{@__cluster_... |
github | opal/opal | https://github.com/opal/opal | stdlib/nodejs/open-uri.rb | Ruby | mit | 4,915 | master | 628 | # backtick_javascript: true
module OpenURI
@__xmlhttprequest__ = `require('unxhr')`
`var __XMLHttpRequest__ = #{@__xmlhttprequest__}.XMLHttpRequest`
def self.request(uri)
%x{
var xhr = new __XMLHttpRequest__();
xhr.open('GET', uri, false);
xhr.responseType = 'arraybuffer';
xhr.send()... |
github | opal/opal | https://github.com/opal/opal | stdlib/racc/parser.rb | Ruby | mit | 4,915 | master | 18,414 | # Opal port of racc/parser.rb.
#
# Original license:
#
# frozen_string_literal: false
#--
# $originalId: parser.rb,v 1.8 2006/07/06 11:42:07 aamine Exp $
#
# Copyright (c) 1999-2006 Minero Aoki
#
# This program is free software.
# You can distribute/modify this program under the same terms of ruby.
#
# As a special exc... |
github | opal/opal | https://github.com/opal/opal | stdlib/rbconfig/sizeof.rb | Ruby | mit | 4,915 | master | 1,549 | # This file is not intended for real checks,
# but just to make happy libraries needing it.
require_relative '../rbconfig'
RbConfig::SIZEOF = {
'clock_t' => 8,
'double _Complex' => 16,
'double' => 8,
'float _Complex' => 8,
'float' => 4,
'int' ... |
github | opal/opal | https://github.com/opal/opal | lib/opal/source_map.rb | Ruby | mit | 4,915 | master | 396 | # frozen_string_literal: true
module Opal
# To generate the source map for a single file use Opal::SourceMap::File.
# To combine multiple files the Opal::SourceMap::Index should be used.
module SourceMap
autoload :Map, 'opal/source_map/map'
autoload :File, 'opal/source_map/file'
autoload :Index, '... |
github | opal/opal | https://github.com/opal/opal | lib/opal/path_reader.rb | Ruby | mit | 4,915 | master | 1,196 | # frozen_string_literal: true
require 'opal/regexp_anchors'
require 'opal/hike'
module Opal
class PathReader
RELATIVE_PATH_REGEXP = /#{Opal::REGEXP_START}\.?\.#{Regexp.quote File::SEPARATOR}/.freeze
DEFAULT_EXTENSIONS = ['.js', '.js.rb', '.rb', '.opalerb'].freeze
def initialize(paths = Opal.paths, exte... |
github | opal/opal | https://github.com/opal/opal | lib/opal/cli_options.rb | Ruby | mit | 4,915 | master | 7,988 | # frozen_string_literal: true
require 'optparse'
require 'opal/cli_runners'
require 'opal/exe_compiler'
module Opal
class CLIOptions < OptionParser
def initialize
super
@options = {}
self.banner = 'Usage: opal [options] -- [programfile]'
separator ''
on('--repl', 'Run the Opal R... |
github | opal/opal | https://github.com/opal/opal | lib/opal/parser.rb | Ruby | mit | 4,915 | master | 222 | # frozen_string_literal: true
require 'opal/ast/builder'
require 'opal/rewriter'
require 'opal/parser/source_buffer'
require 'opal/parser/default_config'
require 'opal/parser/with_ruby_lexer'
require 'opal/parser/patch' |
github | opal/opal | https://github.com/opal/opal | lib/opal/paths.rb | Ruby | mit | 4,915 | master | 1,538 | # frozen_string_literal: true
require 'opal/project'
module Opal
def self.gem_dir
if defined? Opal::GEM_DIR
# This is for the case of opalopal. __FILE__ and __dir__ are unreliable
# in this case.
Opal::GEM_DIR
else
File.expand_path('..', __dir__)
end
end
# Add a file path to... |
github | opal/opal | https://github.com/opal/opal | lib/opal/regexp_anchors.rb | Ruby | mit | 4,915 | master | 3,504 | # frozen_string_literal: true
module Opal
# rubocop:disable Style/MutableConstant
self::REGEXP_START = '\A'
self::REGEXP_END = '\z'
# Unicode characters in ranges
# \u0001 - \u002F (blank unicode characters + space + !"#$%&'()*+,-./ chars)
# \u003A - \u0040 (:;<=>?@ chars)
# \u005B - \u005E ([\]^ chars)... |
github | opal/opal | https://github.com/opal/opal | lib/opal/eof_content.rb | Ruby | mit | 4,915 | master | 1,029 | # frozen_string_literal: true
module Opal
class EofContent
DATA_SEPARATOR = "__END__\n"
def initialize(tokens, source)
@tokens = tokens
@source = source
end
def eof
return nil if @tokens.empty?
eof_content = @source[last_token_position..-1]
return nil unless eof_conte... |
github | opal/opal | https://github.com/opal/opal | lib/opal/builder.rb | Ruby | mit | 4,915 | master | 8,975 | # frozen_string_literal: true
require 'opal/path_reader'
require 'opal/paths'
require 'opal/config'
require 'opal/cache'
require 'opal/builder/scheduler'
require 'opal/project'
require 'opal/builder/directory'
require 'opal/builder/post_processor'
require 'set'
module Opal
class Builder
# The registered process... |
github | opal/opal | https://github.com/opal/opal | lib/opal/requires.rb | Ruby | mit | 4,915 | master | 395 | # frozen_string_literal: true
require 'opal/config'
require 'opal/compiler'
require 'opal/builder'
require 'opal/builder/processor'
require 'opal/erb'
require 'opal/paths'
require 'opal/version'
require 'opal/errors'
require 'opal/source_map'
require 'opal/deprecations'
module Opal
autoload :Server, 'opal/server' i... |
github | opal/opal | https://github.com/opal/opal | lib/opal/config.rb | Ruby | mit | 4,915 | master | 5,184 | # frozen_string_literal: true
require 'set'
module Opal
module Config
extend self
private
def config_options
@config_options ||= {}
end
# Defines a new configuration option
#
# @param [String] name the option name
# @param [Object] default_value the option's default value
... |
github | opal/opal | https://github.com/opal/opal | lib/opal/exe_compiler.rb | Ruby | mit | 4,915 | master | 4,131 | # frozen_string_literal: true
require 'fileutils'
require 'tmpdir'
require 'opal/os'
module Opal
class ExeCompiler
RUNTIMES = -> {
types = %w[bun deno node quickjs]
types << 'osascript' if OS.macos?
types.freeze
}.call
def self.compile_exe(type, src_out)
new(type, src_out).compi... |
github | opal/opal | https://github.com/opal/opal | lib/opal/os.rb | Ruby | mit | 4,915 | master | 1,043 | # frozen_string_literal: true
require 'shellwords'
module Opal
module OS
module_function
def windows?
/bccwin|cygwin|djgpp|mingw|mswin|wince/.match?(RbConfig::CONFIG['host_os'])
end
def macos?
/darwin|mac os/.match?(RbConfig::CONFIG['host_os'])
end
def shellescape(str)
i... |
github | opal/opal | https://github.com/opal/opal | lib/opal/deprecations.rb | Ruby | mit | 4,915 | master | 392 | # frozen_string_literal: true
module Opal
module Deprecations
attr_accessor :raise_on_deprecation
def deprecation(message)
message = "DEPRECATION WARNING: #{message}"
if defined?(@raise_on_deprecation) && @raise_on_deprecation
raise message
else
warn message
end
e... |
github | opal/opal | https://github.com/opal/opal | lib/opal/simple_server.rb | Ruby | mit | 4,915 | master | 3,518 | # frozen_string_literal: true
require 'opal/deprecations'
# Opal::SimpleServer is a very basic Rack server for Opal assets, it relies on
# Opal::Builder and Ruby corelib/stdlib. It's meant to be used just for local
# development.
#
# For a more complete implementation see opal-sprockets (Rubygems) or
# opal-webpack (... |
github | opal/opal | https://github.com/opal/opal | lib/opal/cli.rb | Ruby | mit | 4,915 | master | 7,512 | # frozen_string_literal: true
require 'opal/requires'
require 'opal/builder'
require 'opal/cli_runners'
require 'opal/exe_compiler'
require 'stringio'
module Opal
class CLI
attr_reader :options, :file, :compiler_options, :evals, :load_paths, :argv,
:output, :requires, :rbrequires, :gems, :stubs, :verbose,... |
github | opal/opal | https://github.com/opal/opal | lib/opal/hike.rb | Ruby | mit | 4,915 | master | 10,093 | # frozen_string_literal: true
# Copyright (c) 2011 Sam Stephenson
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, cop... |
github | opal/opal | https://github.com/opal/opal | lib/opal/compiler.rb | Ruby | mit | 4,915 | master | 21,624 | # frozen_string_literal: true
if RUBY_ENGINE == 'opal'
require 'corelib/string/unpack'
end
require 'set'
require 'opal/parser'
require 'opal/fragment'
require 'opal/nodes'
require 'opal/eof_content'
require 'opal/errors'
require 'opal/magic_comments'
require 'opal/nodes/closure'
require 'opal/source_map'
module Opa... |
github | opal/opal | https://github.com/opal/opal | lib/opal/util.rb | Ruby | mit | 4,915 | master | 793 | # frozen_string_literal: true
require 'open3'
module Opal
module Util
extend self
ExitStatusError = Class.new(StandardError)
# Used for uglifying source to minify.
#
# Opal::Util.uglify("javascript contents")
#
# @param str [String] string to minify
# @return [String]
def u... |
github | opal/opal | https://github.com/opal/opal | lib/opal/fragment.rb | Ruby | mit | 4,915 | master | 3,430 | # frozen_string_literal: true
module Opal
# A fragment holds a string of generated javascript that will be written
# to the destination. It also keeps hold of the original sexp from which
# it was generated. Using this sexp, when writing fragments in order, a
# mapping can be created of the original location =... |
github | opal/opal | https://github.com/opal/opal | lib/opal/cache.rb | Ruby | mit | 4,915 | master | 1,534 | # frozen_string_literal: true
require 'opal/paths'
require 'digest/sha2' unless RUBY_ENGINE == 'opal'
if RUBY_ENGINE != 'opal'
require 'opal/cache/file_cache'
end
module Opal
# A Sprockets-compatible cache, for example an instance of
# Opal::Cache::FileCache or Opal::Cache::NullCache.
singleton_class.attr_wr... |
github | opal/opal | https://github.com/opal/opal | lib/opal/magic_comments.rb | Ruby | mit | 4,915 | master | 862 | # frozen_string_literal: true
module Opal::MagicComments
MAGIC_COMMENT_RE = /\A# *(\w+) *: *(\S+.*?) *\z/.freeze
EMACS_MAGIC_COMMENT_RE = /\A# *-\*- *(\w+) *: *(\S+.*?) *-\*- *\z/.freeze
def self.parse(sexp, comments)
flags = {}
# We have an upper limit at the first line of code
if sexp
first... |
github | opal/opal | https://github.com/opal/opal | lib/opal/nodes.rb | Ruby | mit | 4,915 | master | 1,053 | # frozen_string_literal: true
require 'opal/nodes/closure'
require 'opal/nodes/base'
require 'opal/nodes/literal'
require 'opal/nodes/variables'
require 'opal/nodes/constants'
require 'opal/nodes/call'
require 'opal/nodes/call/eval'
require 'opal/nodes/call/match3'
require 'opal/nodes/call/js_property'
require 'opal/n... |
github | opal/opal | https://github.com/opal/opal | lib/opal/project.rb | Ruby | mit | 4,915 | master | 5,970 | # frozen_string_literal: true
module Opal
# Opal::Project is a representation of an Opal project. In particular
# it's a directory containing Ruby files which is described by Opalfile.
class Project
# DSL for Opal::Project
class Opalfile
def initialize(project)
@project = project
yi... |
github | opal/opal | https://github.com/opal/opal | lib/opal/cli_runners.rb | Ruby | mit | 4,915 | master | 3,086 | # frozen_string_literal: true
require 'opal/os'
module Opal
# `Opal::CliRunners` is the register in which JavaScript runners can be
# defined for use by `Opal::CLI`. Runners will be called via the `#call`
# method and passed a Hash containing the following keys:
#
#
# - `options`: a hash of options for th... |
github | opal/opal | https://github.com/opal/opal | lib/opal/server.rb | Ruby | mit | 4,915 | master | 292 | # frozen_string_literal: true
Opal.deprecation "`require 'opal/server` and `Opal::Server` are deprecated in favor of `require 'opal/sprockets/server'` and `Opal::Sprockets::Server` (now part of the opal-sprockets gem)."
require 'opal/sprockets/server'
Opal::Server = Opal::Sprockets::Server |
github | opal/opal | https://github.com/opal/opal | lib/opal/errors.rb | Ruby | mit | 4,915 | master | 2,045 | # frozen_string_literal: true
module Opal
# Generic Opal error
class Error < StandardError
end
# raised if Gem not found in Opal#use_gem
class GemNotFound < Error
# name of gem that not found
attr_reader :gem_name
# @param gem_name [String] name of gem that not found
def initialize(gem_name... |
github | opal/opal | https://github.com/opal/opal | lib/opal/erb.rb | Ruby | mit | 4,915 | master | 2,431 | # frozen_string_literal: true
require 'opal/compiler'
module Opal
module ERB
# Compile ERB code into javascript.
#
# [Opal::ERB] can be used to compile [ERB] templates into javascript code.
# This module uses the [Opal::Compiler] internally.
#
# Compiled templates, when run in a javascript e... |
github | opal/opal | https://github.com/opal/opal | lib/opal/regexp_transpiler.rb | Ruby | mit | 4,915 | master | 6,649 | # frozen_string_literal: true
# backtick_javascript: true
# use_strict: true
module Opal
module RegexpTranspiler
module_function
# Transform a regular expression from Ruby syntax to JS syntax, as much
# as possible.
def transform_regexp(original_regexp, flags)
flags ||= ''
if include?(... |
github | opal/opal | https://github.com/opal/opal | lib/opal/version.rb | Ruby | mit | 4,915 | master | 279 | # frozen_string_literal: true
module Opal
# WHEN RELEASING:
# Remember to update RUBY_ENGINE_VERSION in opal/corelib/constants.rb too!
VERSION = '2.0.0dev'
# Only major and minor parts of version
VERSION_MAJOR_MINOR = VERSION.split('.').first(2).join('.').freeze
end |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriter.rb | Ruby | mit | 4,915 | master | 2,357 | # frozen_string_literal: true
require 'opal/rewriters/opal_engine_check'
require 'opal/rewriters/targeted_patches'
require 'opal/rewriters/for_rewriter'
require 'opal/rewriters/js_reserved_words'
require 'opal/rewriters/block_to_iter'
require 'opal/rewriters/dot_js_syntax'
require 'opal/rewriters/pattern_matching'
req... |
github | opal/opal | https://github.com/opal/opal | lib/opal/repl.rb | Ruby | mit | 4,915 | master | 4,756 | # frozen_string_literal: true
require 'opal'
require 'securerandom'
require 'stringio'
require 'fileutils'
require 'rbconfig'
module Opal
class REPL
HISTORY_PATH = File.expand_path('~/.opal-repl-history')
attr_accessor :colorize
def initialize(runner_type = nil)
@argv = []
@colorize = true... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/binary_operator_assignment.rb | Ruby | mit | 4,915 | master | 4,532 | # frozen_string_literal: true
require 'opal/rewriters/base'
module Opal
module Rewriters
class BinaryOperatorAssignment < Base
def self.reset_tmp_counter!
@@counter = 0
end
def self.new_temp
@@counter ||= 0
@@counter += 1
:"$binary_op_recvr_tmp_#{@@counter}"
... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/returnable_logic.rb | Ruby | mit | 4,915 | master | 4,202 | # frozen_string_literal: true
require 'opal/rewriters/base'
module Opal
module Rewriters
class ReturnableLogic < Base
def next_tmp
@counter ||= 0
@counter += 1
"$ret_or_#{@counter}"
end
def free_tmp
@counter -= 1
end
def reset_tmp_counter!
... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/block_to_iter.rb | Ruby | mit | 4,915 | master | 346 | # frozen_string_literal: true
require 'opal/rewriters/base'
module Opal
module Rewriters
class BlockToIter < Base
def on_block(node)
recvr, args, body = *node
iter_node = s(:iter, args, body)
process recvr.updated(
nil,
recvr.children + [iter_node],
)
... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/for_rewriter.rb | Ruby | mit | 4,915 | master | 3,503 | # frozen_string_literal: true
require 'opal/rewriters/base'
module Opal
module Rewriters
class ForRewriter < Base
def self.reset_tmp_counter!
@counter = 0
end
def self.next_tmp
@counter ||= 0
@counter += 1
:"$for_tmp#{@counter}"
end
# Handles
... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/pattern_matching.rb | Ruby | mit | 4,915 | master | 6,416 | # frozen_string_literal: true
require 'opal/rewriters/base'
module Opal
module Rewriters
class PatternMatching < Base
def initialize
@depth = 0
super
end
# a => b
def on_match_pattern(node)
from, pat = *node
s(:begin,
s(:lvasgn, :"$pmvar", from... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/mlhs_args.rb | Ruby | mit | 4,915 | master | 3,049 | # frozen_string_literal: true
require 'opal/rewriters/base'
module Opal
module Rewriters
# Rewrites
#
# def m( (a, b), (c, d) )
# body
# end
#
# To
#
# def m($mlhs_tmp1, $mlhs_tmp2)
# (a, b) = $mlhs_tmp1
# (c, d) = $mlhs_tmp2
# body
# end
#
class M... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/targeted_patches.rb | Ruby | mit | 4,915 | master | 3,269 | # frozen_string_literal: true
require 'opal/rewriters/base'
module Opal
module Rewriters
# This module attempts to run some optimizations or compatibility
# improvements against some libraries used with Opal.
#
# This should be a last resort and must not break functionality in
# existing applica... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/numblocks.rb | Ruby | mit | 4,915 | master | 585 | # frozen_string_literal: true
require 'opal/rewriters/base'
module Opal
module Rewriters
# This rewriter transforms the Ruby 2.7 numblocks to regular blocks:
#
# proc { _1 }
# v
# proc { |_1| _1 }
class Numblocks < Base
def on_numblock(node)
left, arg_count, right = node.c... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/base.rb | Ruby | mit | 4,915 | master | 3,309 | # frozen_string_literal: true
require 'parser'
require 'opal/ast/node'
module Opal
module Rewriters
class Base < ::Parser::AST::Processor
class DummyLocation
def node=(*)
# stub
end
def expression
self
end
def begin_pos
0
end
... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/thrower_finder.rb | Ruby | mit | 4,915 | master | 2,667 | # frozen_string_literal: true
# rubocop:disable Layout/EmptyLineBetweenDefs, Style/SingleLineMethods
module Opal
module Rewriters
# ThrowerFinder attempts to track the presence of throwers, like
# break, redo, so we can make an informed guess in the early
# compilation phase before traversing other nodes... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/logical_operator_assignment.rb | Ruby | mit | 4,915 | master | 5,277 | # frozen_string_literal: true
require 'opal/rewriters/base'
module Opal
module Rewriters
class LogicalOperatorAssignment < Base
def self.reset_tmp_counter!
@@counter = 0
end
def self.new_temp
@@counter ||= 0
@@counter += 1
:"$logical_op_recvr_tmp_#{@@counter}"
... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/forward_args.rb | Ruby | mit | 4,915 | master | 2,104 | # frozen_string_literal: true
require 'opal/rewriters/base'
module Opal
module Rewriters
class ForwardArgs < Base
def on_forward_args(_node)
process(
s(:args, s(:forward_arg, :"$"))
)
end
def on_forwarded_restarg(_node)
process(
s(:splat, s(:lvar, '... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/deduplicate_arg_name.rb | Ruby | mit | 4,915 | master | 1,409 | # frozen_string_literal: true
module Opal
module Rewriters
# Ruby allows for args with the same name, if the arg starts with a '_', like:
# def funny_method_name(_, _)
# puts _
# end
# but JavaScript in strict mode does not allow for args with the same name
# Ruby assigns the value of... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/arguments.rb | Ruby | mit | 4,915 | master | 1,493 | # frozen_string_literal: true
module Opal
module Rewriters
class Arguments
attr_reader :args, :optargs, :restarg, :postargs,
:kwargs, :kwoptargs, :kwrestarg, :kwnilarg,
:shadowargs, :blockarg
def initialize(args)
@args = []
@optargs = []
@restarg = nil
... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/dot_js_syntax.rb | Ruby | mit | 4,915 | master | 1,846 | # frozen_string_literal: true
require 'opal/rewriters/base'
module Opal
module Rewriters
class DotJsSyntax < Base
def on_send(node)
recv, meth, *args = *node
if recv && recv.type == :send
recv_of_recv, meth_of_recv, _ = *recv
if meth_of_recv == :JS
case meth... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/inline_args.rb | Ruby | mit | 4,915 | master | 5,777 | # frozen_string_literal: true
require 'opal/rewriters/base'
require 'opal/rewriters/arguments'
module Opal
module Rewriters
# Converts
#
# def m( a, b = 1, *c, d, e:, f: 1, **g, &blk )
# end
#
# To something like
#
# def m( a, <fake b>, <fake c>, <fake d>, <fake kwargs>)
# ... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/js_reserved_words.rb | Ruby | mit | 4,915 | master | 3,625 | # frozen_string_literal: true
require 'opal/rewriters/base'
require 'opal/regexp_anchors'
module Opal
module Rewriters
class JsReservedWords < Base
# Reserved javascript keywords - we cannot create variables with the
# same name (ref: http://stackoverflow.com/a/9337272/601782)
ES51_RESERVED_WO... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/opal_engine_check.rb | Ruby | mit | 4,915 | master | 1,391 | # frozen_string_literal: true
require 'opal/rewriters/base'
module Opal
module Rewriters
class OpalEngineCheck < Base
def on_if(node)
test, true_body, false_body = *node.children
if (values = engine_check?(test))
if positive_engine_check?(*values)
process(true_body |... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/dump_args.rb | Ruby | mit | 4,915 | master | 611 | # frozen_string_literal: true
require 'opal/rewriters/base'
module Opal
module Rewriters
class DumpArgs < Base
def on_def(node)
node = super(node)
_mid, args, _body = *node
node.updated(nil, nil, meta: { original_args: args })
end
def on_defs(node)
node = super... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/hashes/key_duplicates_rewriter.rb | Ruby | mit | 4,915 | master | 1,244 | # frozen_string_literal: true
require 'opal/rewriters/base'
require 'set'
module Opal
module Rewriters
module Hashes
class KeyDuplicatesRewriter < ::Opal::Rewriters::Base
def initialize
@keys = UniqKeysSet.new
end
def on_hash(node)
previous_keys, @keys = @keys,... |
github | opal/opal | https://github.com/opal/opal | lib/opal/rewriters/rubyspec/filters_rewriter.rb | Ruby | mit | 4,915 | master | 1,893 | # frozen_string_literal: true
require 'opal/rewriters/base'
module Opal
module Rubyspec
class FiltersRewriter < Opal::Rewriters::Base
class << self
def filters
@filters ||= []
end
def filter(spec_name)
filters << spec_name
end
alias fails filte... |
github | opal/opal | https://github.com/opal/opal | lib/opal/nodes/x_string.rb | Ruby | mit | 4,915 | master | 4,608 | # frozen_string_literal: true
module Opal
module Nodes
class XStringNode < Base
handle :xstr
def compile
if compiler.backtick_javascript_or_warn?
compile_javascript
else
compile_send
end
end
def compile_send
sexp = s(:send, nil, :`, s(... |
github | opal/opal | https://github.com/opal/opal | lib/opal/nodes/defs.rb | Ruby | mit | 4,915 | master | 450 | # frozen_string_literal: true
require 'opal/nodes/def'
module Opal
module Nodes
class DefsNode < DefNode
handle :defs
children :recvr, :mid, :inline_args, :stmts
def wrap_with_definition
if compiler.runtime_mode?
unshift "Opal.$#{mid} = Opal.#{mid} = "
else
... |
github | opal/opal | https://github.com/opal/opal | lib/opal/nodes/constants.rb | Ruby | mit | 4,915 | master | 2,446 | # frozen_string_literal: true
require 'opal/nodes/base'
module Opal
module Nodes
class ConstNode < Base
handle :const
children :const_scope, :name
def compile
push dce_use(name, type: :const)
if magical_data_const?
push('$__END__')
elsif optimized_access?
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.