Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upErlang binary additions + bugfixes related to Symbol === #387
Conversation
| result = Functions.map_to_object(map, []); | ||
| t.deepEqual(result, { s_key: 'value', s_anotherKey: 'value2' }); | ||
| });*/ |
This comment has been minimized.
This comment has been minimized.
| @@ -23,12 +23,28 @@ test('split_at', (t) => { | |||
| t.deepEqual(Functions.split_at('😀abélkm', 4).values, ['😀abé', 'lkm']); | |||
| }); | |||
|
|
|||
| //TODO: Fix these tests | |||
| /*test('map_to_object/1', (t) => { | |||
This comment has been minimized.
This comment has been minimized.
| @@ -23,12 +23,28 @@ test('split_at', (t) => { | |||
| t.deepEqual(Functions.split_at('😀abélkm', 4).values, ['😀abé', 'lkm']); | |||
| }); | |||
|
|
|||
| //TODO: Fix these tests | |||
This comment has been minimized.
This comment has been minimized.
| test('split/2', (t) => { | ||
| let result = Core.binary.split('abcd', 'b'); | ||
| t.deepEqual(result, ['a', 'cd']); | ||
| }); |
This comment has been minimized.
This comment has been minimized.
| }); | ||
|
|
||
| test('split/2', (t) => { | ||
| let result = Core.binary.split('abcd', 'b'); |
This comment has been minimized.
This comment has been minimized.
src/javascript/lib/core/functions.js
Outdated
| key = key.toString(); | ||
| } else if ( | ||
| (type_keys === Symbol('string') || symbols !== Symbol('undefined')) && | ||
| typeof key === 'symbol' | ||
| (opt_keys === Symbol.for('string') || opt_symbols !== Symbol.for('undefined')) |
This comment has been minimized.
This comment has been minimized.
| part, | ||
| replace, | ||
| split, | ||
| }; |
This comment has been minimized.
This comment has been minimized.
| //TODO: Support more options, global is implied | ||
| //TODO: pattern cannot be list of strings | ||
| function split(subject, pattern, options=[]) { | ||
| return subject.split(pattern) |
This comment has been minimized.
This comment has been minimized.
| //TODO: Support more options, global is implied | ||
| //TODO: pattern cannot be list of strings | ||
| function split(subject, pattern, options=[]) { | ||
| return subject.split(pattern) |
This comment has been minimized.
This comment has been minimized.
|
|
||
| //TODO: Support more options, global is implied | ||
| //TODO: pattern cannot be list of strings | ||
| function split(subject, pattern, options=[]) { |
This comment has been minimized.
This comment has been minimized.
| }); | ||
|
|
||
| test('is_defined/2', (t) => { | ||
| let result = Core.binary.at('abc', 0); |
This comment has been minimized.
This comment has been minimized.
| t.deepEqual(result, '123'); | ||
|
|
||
| result = Core.proplists.get_value('abcd', [new Core.Tuple('abc', '123')], "xyz"); | ||
| t.deepEqual(result, "xyz"); |
This comment has been minimized.
This comment has been minimized.
| let result = Core.proplists.get_value('abc', [new Core.Tuple('abc', '123')], "xyz"); | ||
| t.deepEqual(result, '123'); | ||
|
|
||
| result = Core.proplists.get_value('abcd', [new Core.Tuple('abc', '123')], "xyz"); |
This comment has been minimized.
This comment has been minimized.
| }); | ||
|
|
||
| test('get_value/3', (t) => { | ||
| let result = Core.proplists.get_value('abc', [new Core.Tuple('abc', '123')], "xyz"); |
This comment has been minimized.
This comment has been minimized.
| @@ -0,0 +1,26 @@ | |||
| import test from 'ava'; | |||
This comment has been minimized.
This comment has been minimized.
sourcelevel-bot
bot
Sep 6, 2017
'ava' should be listed in the project's dependencies, not devDependencies.
| @@ -1,10 +1,13 @@ | |||
| import ErlangTypes from 'erlang-types'; | |||
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| //TODO: Support more options, global is implied | ||
| //TODO: pattern cannot be list of strings |
This comment has been minimized.
This comment has been minimized.
| return subject.replace(regex, replacement); | ||
| } | ||
|
|
||
| //TODO: Support more options, global is implied |
This comment has been minimized.
This comment has been minimized.
| function replace(subject, pattern, replacement, options=[]) { | ||
| const opt_global = proplists.get_value(Symbol.for('global'), options); | ||
|
|
||
| var regex; |
This comment has been minimized.
This comment has been minimized.
|
|
||
| //TODO: Support more options | ||
| //TODO: pattern cannot be list of strings | ||
| function replace(subject, pattern, replacement, options=[]) { |
This comment has been minimized.
This comment has been minimized.
| var pos; | ||
| [pos, len] = posOrTuple.values; | ||
| return subject.substr(pos, len); | ||
| } else { |
This comment has been minimized.
This comment has been minimized.
| function part(subject, posOrTuple, len = null) { | ||
| if (len === null) { | ||
| var pos; | ||
| [pos, len] = posOrTuple.values; |
This comment has been minimized.
This comment has been minimized.
| function list_to_bin(bytelist) { | ||
| return erlang.list_to_binary(bytelist); | ||
| } | ||
|
|
||
| function part(subject, posOrTuple, len = null) { | ||
| if (len === null) { | ||
| var pos; |
This comment has been minimized.
This comment has been minimized.
| function list_to_bin(bytelist) { | ||
| return erlang.list_to_binary(bytelist); | ||
| } | ||
|
|
||
| function part(subject, posOrTuple, len = null) { | ||
| if (len === null) { | ||
| var pos; |
This comment has been minimized.
This comment has been minimized.
Closed
| new Map([[Symbol.for('nest1'), 'valuenest1']]), | ||
| new Map([[Symbol.for('nest2'), 'valuenest2']]) | ||
| ]]])); | ||
| }); |
This comment has been minimized.
This comment has been minimized.
| new Core.Tuple(Symbol.for('recurse_array'), true)]); | ||
| t.deepEqual(result, new Map([[Symbol.for('key'), [ | ||
| new Map([[Symbol.for('nest1'), 'valuenest1']]), | ||
| new Map([[Symbol.for('nest2'), 'valuenest2']]) |
This comment has been minimized.
This comment has been minimized.
| obj = {}; | ||
| obj[Symbol.for('key')] = [{nest1: 'valuenest1'},{nest2: 'valuenest2'}]; | ||
| result = Functions.object_to_map(obj, [ | ||
| new Core.Tuple(Symbol.for('keys'), Symbol.for('atom')), |
This comment has been minimized.
This comment has been minimized.
| t.deepEqual(result, new Map([[Symbol.for('key'), 'value']])); | ||
|
|
||
| obj = {}; | ||
| obj[Symbol.for('key')] = [{nest1: 'valuenest1'},{nest2: 'valuenest2'}]; |
This comment has been minimized.
This comment has been minimized.
| t.deepEqual(result, new Map([[Symbol.for('key'), 'value']])); | ||
|
|
||
| obj = {}; | ||
| obj[Symbol.for('key')] = [{nest1: 'valuenest1'},{nest2: 'valuenest2'}]; |
This comment has been minimized.
This comment has been minimized.
| return map; | ||
|
|
||
| } else if (object instanceof Array && opt_recurse_array) { | ||
| return object.map(function(ele) { |
This comment has been minimized.
This comment has been minimized.
| return map; | ||
|
|
||
| } else if (object instanceof Array && opt_recurse_array) { | ||
| return object.map(function(ele) { |
This comment has been minimized.
This comment has been minimized.
| }); | ||
| return map; | ||
|
|
||
| } else if (object instanceof Array && opt_recurse_array) { |
This comment has been minimized.
This comment has been minimized.
|
|
||
| if (object.constructor === Object) { | ||
| let map = new Map(); | ||
| Reflect.ownKeys(object).forEach(key => { |
This comment has been minimized.
This comment has been minimized.
sourcelevel-bot
bot
Sep 6, 2017
Expected parentheses around arrow function argument having a body with curly braces.
| const opt_recurse_array = proplists.get_value(Symbol.for('recurse_array'), options) === true; | ||
|
|
||
| if (object.constructor === Object) { | ||
| let map = new Map(); |
This comment has been minimized.
This comment has been minimized.
sourcelevel-bot
bot
commented
Sep 6, 2017
|
Ebert has finished reviewing this Pull Request and has found:
But beware that this branch is 2 commits behind the You can see more details about this review at https://ebertapp.io/github/elixirscript/elixirscript/pulls/387. |
| Takes the given object and returns a map | ||
| Options include [{:keys, :atom}, {:recurse_array, true}] | ||
This comment has been minimized.
This comment has been minimized.
|
|
||
| //TODO: Support more options, global is implied | ||
| //TODO: pattern cannot be list of strings | ||
| function split(subject, pattern, options = []) { |
This comment has been minimized.
This comment has been minimized.
| function replace(subject, pattern, replacement, options = []) { | ||
| const opt_global = proplists.get_value(Symbol.for('global'), options); | ||
|
|
||
| var regex; |
This comment has been minimized.
This comment has been minimized.
|
|
||
| function last(subject) { | ||
| if (subject.length == 0) { | ||
| throw new Error(`Binary is of length 0`); |
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| function last(subject) { | ||
| if (subject.length == 0) { |
This comment has been minimized.
This comment has been minimized.
|
|
||
| function copy(subject, n = 1) { | ||
| return subject.repeat(n); | ||
| } | ||
|
|
||
| function first(subject) { | ||
| if (subject.length == 0) { | ||
| throw new Error(`Binary is of length 0`); |
This comment has been minimized.
This comment has been minimized.
| @@ -91,27 +91,56 @@ defmodule ElixirScript.Translate.Forms.JS do | |||
| {ast, state} | |||
| end | |||
|
|
|||
| def compile({{:., _, [ElixirScript.JS, :map_to_object]}, _, [object]}, state) do | |||
| def compile({{:., _, [ElixirScript.JS, :map_to_object]}, _, [map]}, state) do | |||
This comment has been minimized.
This comment has been minimized.
| ] | ||
| ) | ||
|
|
||
| {ast, state} | ||
| end | ||
|
|
||
| def compile({{:., _, [ElixirScript.JS, :map_to_object]}, _, [object, options]}, state) do | ||
| def compile({{:., _, [ElixirScript.JS, :map_to_object]}, _, [map, options]}, state) do |
This comment has been minimized.
This comment has been minimized.
| {ast, state} | ||
| end | ||
|
|
||
| def compile({{:., _, [ElixirScript.JS, :object_to_map]}, _, [object]}, state) do |
This comment has been minimized.
This comment has been minimized.
| {ast, state} | ||
| end | ||
|
|
||
| def compile({{:., _, [ElixirScript.JS, :object_to_map]}, _, [object, options]}, state) do |
This comment has been minimized.
This comment has been minimized.
|
Thanks for all of the work here! |
This was referenced Sep 7, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
vans163 commentedSep 5, 2017
Knocks out some things here #306, note some functions are partially complete.