Skip to content

Commit 9350d23

Browse files
committed
Add __table to root object
1 parent 73313f2 commit 9350d23

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

mix.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ defmodule ElixirScript.Mixfile do
7979
File.rm_rf(dist_folder)
8080
end
8181

82+
System.cmd("npm", ["run", "build"])
83+
8284
File.mkdir_p(folder_name <> "/bin")
8385
File.cp!("elixirscript", "#{folder_name}/bin/elixirscript")
8486
if File.exists?("priv/.DS_Store") do

src/javascript/lib/core/functions.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import Protocol from "./protocol";
2-
import Core from "../core";
1+
import Protocol from './protocol';
2+
import Core from '../core';
33

44
function call_property(item, property) {
55
let prop = null;
66

77
if (
8-
typeof item === "number" ||
9-
typeof item === "symbol" ||
10-
typeof item === "boolean" ||
11-
typeof item === "string"
8+
typeof item === 'number' ||
9+
typeof item === 'symbol' ||
10+
typeof item === 'boolean' ||
11+
typeof item === 'string'
1212
) {
1313
if (item[property] !== undefined) {
1414
prop = property;
@@ -50,15 +50,15 @@ function contains(left, right) {
5050
}
5151

5252
function get_global() {
53-
if (typeof self !== "undefined") {
53+
if (typeof self !== 'undefined') {
5454
return self;
55-
} else if (typeof window !== "undefined") {
55+
} else if (typeof window !== 'undefined') {
5656
return window;
57-
} else if (typeof global !== "undefined") {
57+
} else if (typeof global !== 'undefined') {
5858
return global;
5959
}
6060

61-
throw new Error("No global state found");
61+
throw new Error('No global state found');
6262
}
6363

6464
function defstruct(defaults) {
@@ -78,15 +78,15 @@ function defstruct(defaults) {
7878
function defexception(defaults) {
7979
return class extends Error {
8080
constructor(update = {}) {
81-
const message = update.message || "";
81+
const message = update.message || '';
8282
super(message);
8383

8484
const the_values = Object.assign(defaults, update);
8585
Object.assign(this, the_values);
8686

8787
this.name = this.constructor.name;
8888
this.message = message;
89-
this[Symbol.for("__exception__")] = true;
89+
this[Symbol.for('__exception__')] = true;
9090
Error.captureStackTrace(this, this.constructor.name);
9191
}
9292

@@ -148,7 +148,7 @@ function update_map(map, property, value) {
148148
return add_property_to_map(map, property, value);
149149
}
150150

151-
throw "map does not have key";
151+
throw 'map does not have key';
152152
}
153153

154154
function bnot(expr) {
@@ -309,9 +309,9 @@ function reverse(list) {
309309

310310
function maps_find(key, map) {
311311
if (key in get_object_keys(map)) {
312-
return new Core.Tuple(Symbol.for("ok"), map[key]);
312+
return new Core.Tuple(Symbol.for('ok'), map[key]);
313313
}
314-
return Symbol.for("error");
314+
return Symbol.for('error');
315315
}
316316

317317
function flatten(list, tail = []) {
@@ -378,21 +378,25 @@ function maps_fold(fun, acc, map) {
378378
}
379379

380380
function build_namespace(ns, ns_string) {
381-
let parts = ns_string.split(".");
381+
let parts = ns_string.split('.');
382+
const root = ns;
382383
let parent = ns;
383384

384-
if (parts[0] === "Elixir") {
385+
if (parts[0] === 'Elixir') {
385386
parts = parts.slice(1);
386387
}
387388

388389
for (const part of parts) {
389-
if (typeof parent[part] === "undefined") {
390+
if (typeof parent[part] === 'undefined') {
390391
parent[part] = {};
391392
}
392393

393394
parent = parent[part];
394395
}
395396

397+
root.__table = ns.__table || {};
398+
root.__table[Symbol.for(ns_string)] = parent;
399+
396400
return parent;
397401
}
398402

0 commit comments

Comments
 (0)