Skip to content

Commit 2bfead1

Browse files
committed
Merge latest from master
2 parents 5b01f81 + 94d6e3d commit 2bfead1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3571
-2190
lines changed

.babelrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"plugins": ["transform-es2015-modules-commonjs"]
2+
"presets": [
3+
"env"
4+
]
35
}

.credo.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
{Credo.Check.Readability.ModuleAttributeNames},
7979
{Credo.Check.Readability.ModuleDoc},
8080
{Credo.Check.Readability.ModuleNames},
81-
{Credo.Check.Readability.NoParenthesesWhenZeroArity},
81+
{Credo.Check.Readability.ParenthesesOnZeroArityDefs},
8282
{Credo.Check.Readability.ParenthesesInCondition},
8383
{Credo.Check.Readability.PredicateFunctionNames},
8484
{Credo.Check.Readability.PreferImplicitTry},

.flowconfig

Lines changed: 0 additions & 12 deletions
This file was deleted.

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ elixir:
55
otp_release:
66
- 19.0
77
env:
8-
- TRAVIS_NODE_VERSION="6"
8+
- TRAVIS_NODE_VERSION="7"
99
install:
1010
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install $TRAVIS_NODE_VERSION
1111
- npm install -g yarn

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [0.28.0-dev]
8+
9+
### Added
10+
- `remove-unused` option that will remove all unused modules from output
11+
- reimplemented structs to avoid creating JavaScript classes
12+
713
## [0.27.0] - 2017-03-17
814

915
### Added

CONTRIBUTING.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,27 +64,26 @@ found in Elixir in ElixirScript.
6464
ElixirScript is broken up into the following parts:
6565

6666
* The compiler, written in Elixir
67-
* The standard library modules, mostly written in Elixir
67+
* The standard library modules, written in Elixir
6868
* The javascript core
6969

7070
The ElixirScript compiler is in the `lib` folder of the project.
7171
Here is where Elixir code is converted into JavaScript.
7272

73-
The standard library modules are in the `lib/std_lib` folder.
73+
The standard library modules are in the `priv/std_lib` folder.
7474

7575
The JavaScript code is in the `src/javascript`.
76-
This is where features such as pattern matching and the standard library are implemented.
76+
This is where features such as pattern matching and the special forms are implemented.
7777

7878
The ElixirScript tests can be run using `mix test`
7979

80-
The JavaScript tests can be run using `npm test`
80+
The JavaScript tests can be run using `yarn test`
8181

8282
Please make sure all tests pass after making changes. Also make sure to include tests for
8383
the changes you made.
8484

85-
Contributing to the JavaScript code may be the easiest and most rewarding changes.
86-
Don't see a feature, module or function from Elixir in ElixirScript yet? You can implement it
87-
in the JavaScript code.
85+
Contributing to the standard library may be the easiest and most rewarding changes.
86+
Don't see a module, function or macro from Elixir in ElixirScript yet? You can help by implementing it.
8887

8988
## Pull requests
9089

@@ -119,7 +118,7 @@ in order to craft an excellent pull request:
119118
# Navigate to the newly cloned directory
120119
cd elixirscript
121120
# Assign the original repo to a remote called "upstream"
122-
git remote add upstream https://github.com/bryanjos/elixirscript
121+
git remote add upstream https://github.com/elixirscript/elixirscript
123122
```
124123

125124
2. If you cloned a while ago, get the latest changes from upstream:
@@ -150,7 +149,7 @@ in order to craft an excellent pull request:
150149

151150
```sh
152151
mix test
153-
npm test
152+
yarn test
154153
```
155154

156155
This is needed to ensure your changes can

FAQ.md

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,83 +6,13 @@
66

77
# Q. How much is implemented?
88

9-
### A. Most of Kernel.SpecialForms as well as some modules in the Standard Library
10-
11-
The compiler to this point has been focused on translating Kernel.SpecialForms and Kernel. Below is a list of what is complete, incomplete, as well as missing
12-
13-
#### Kernel.SpecialForms
14-
15-
* Complete
16-
* `__DIR__`
17-
* `__MODULE__`
18-
* `^var`
19-
* `&expr`
20-
* `for`
21-
* `%{}`
22-
* `{args}`
23-
* `<<args>>`
24-
* `fn [clauses] end`
25-
* `cond(clauses)`
26-
* `__block__`
27-
* `__aliases__`
28-
* `unquote`
29-
* `unquote_splicing`
30-
* `%`
31-
* `left.right`
32-
* `quote`
33-
* `import`
34-
* `case`
35-
* `left = right`
36-
* `require`
37-
* `left :: right`
38-
* `alias`
39-
* `__CALLER__`
40-
* `__ENV__`
41-
* `super(args)`
42-
43-
* Missing
44-
* `receive`
45-
46-
* Caveats
47-
* `quote` - ignores `context` options
48-
* `left = right` does not support full unification yet.
49-
```elixir
50-
a = 1 # works as expected
51-
52-
1 = a # may not work currently, but in some cases it will
53-
```
54-
55-
56-
#### Completed Modules
57-
58-
* Tuple
59-
* List
60-
* Atom
61-
* Range
62-
* Map
63-
* MapSet
64-
65-
#### Incomplete Modules
66-
67-
* Kernel
68-
* Enum
69-
* Agent
70-
* Integer
71-
* Keyword
72-
* Base
73-
* String
74-
* Bitwise
75-
* Set
76-
77-
#### Missing Modules
78-
* Everything else
79-
9+
### A. Check out the [Supported Modules, Functions, and Macros](Supported.md)
8010

8111
## Q. Can I use it today?
8212

8313
### A. Yes, but realize this is not at 1.0 yet.
8414

85-
You **can** use ElixirScript on your front ends and have it work and interoperate with JavaScript modules. The problem is since most of the standard library is incomplete.
15+
You **can** use ElixirScript on your front ends and have it work and interoperate with JavaScript modules. The problem is that most of the standard library is incomplete.
8616

8717
## Q. Can I use pattern matching?
8818

GettingStarted.md

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -128,32 +128,7 @@ Elixirscript supports public macros. Private macros are currently unsupported.
128128

129129
### JavaScript Interop
130130

131-
Elixirscript has a couple of ways of interacting with JavaScript.
132-
133-
#### Globally scoped functions
134-
135-
Use the erlang module syntax, to call JavaScript functions in the global scope.
136-
137-
# Calling alert
138-
:window.alert("hi")
139-
140-
# console
141-
:console.log("hello")
142-
143-
# document
144-
:document.getElementById("main")
145-
146-
#### Globally scoped modules
147-
148-
You can call globally scoped modules you would an Elixir module
149-
150-
Date.now()
151-
152-
Only works if module begins with a captial letter
153-
154-
#### The JS module
155-
156-
The JS module has many other functions and macros. For more information, check out the docs.
131+
Check out the [JavaScript Interoperability](JavaScriptInterop.html) documentation
157132

158133
#### Frontend Project Boilerplate
159134

JavascriptInterop.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# JavaScript Interoperability
2+
3+
## ElixirScript Calling JavaScript
4+
5+
### JS module
6+
7+
The `JS` module has functions and macros that help with interacting with JavaScript.
8+
These mostly correspond to JavaScript keywords that may be useful.
9+
10+
```elixir
11+
# Calling the JavaScript Debugger
12+
JS.debugger()
13+
14+
# Getting the type of a value
15+
JS.typeof(my_value)
16+
17+
# Creating a new JavaScript Map
18+
map = JS.new(JS.Map, [])
19+
```
20+
21+
### Accessing Global Objects, Functions, and Properties
22+
23+
In order to interact with JavaScript things in the global scope, append "JS" to them. The global scope corresponds to whatever the global object is in the JavaScript environment you are in. For example, in a browser this would be `window` or `self`:
24+
25+
```elixir
26+
# Calling alert
27+
JS.alert("hello")
28+
29+
# Calling a method on Object
30+
JS.Object.keys(my_object)
31+
32+
# Creating a new JavaScript Date
33+
JS.new(JS.Date, [])
34+
35+
# Getting the outer width
36+
JS.outerWidth
37+
```
38+
39+
### JavaScript modules
40+
41+
ElixirScript can use JavaScript modules from the supported modules systems.
42+
In order to do so, you must tell ElixirScript about them upfront.
43+
44+
If using ElixirScript in a mix project, you can do so inside of the ElixirScript configuration keyword list
45+
46+
```elixir
47+
def project do
48+
[
49+
app: :my_project,
50+
elixir_script: [
51+
format: :es,
52+
js_modules: [
53+
{React, "react"},
54+
{ReactDOM, "react-dom"}
55+
]
56+
]
57+
]
58+
end
59+
```
60+
61+
Or if using the CLI, you can do so by passing each module via the `js-module` flag
62+
63+
```
64+
elixirscript "app/elixirscript" -o dist --js-module React:react --js-module ReactDOM:react-dom
65+
```
66+
67+
Interacting with these modules works the same as interacting with an ElixirScript module
68+
69+
```elixir
70+
React.createElement(...)
71+
```
72+
73+
## JavaScript Calling ElixirScript
74+
75+
In order to start an ElixirScript application, you must first import it using whichever JavaScript module system you are using and then call `Elixir.start`
76+
77+
```Elixir
78+
# Our ElixirScript module
79+
80+
defmodule Main do
81+
def start(:normal, args) do
82+
JS.console.log(args)
83+
end
84+
end
85+
86+
```
87+
88+
```javascript
89+
//ES module example
90+
import Elixir from './Elixir.App'
91+
Elixir.start(Elixir.Main, [1, 2, 3])
92+
```
93+
94+
In the above example, we have an ElixirScript module, `Main` with a `start/2` function. This function is the entry point into your ElixirScript application. when we call `Elixir.start`, we give it this module's name (All modules when compiled begin with `Elixir.`) and a list of the initial args.
95+
96+
97+
If you want to use an ElixirScript module inside of your JavaScript code, you can do so using `Elixir.load`.
98+
99+
```Elixir
100+
# Our ElixirScript module
101+
102+
defmodule MyModule do
103+
def hi() do
104+
JS.alert("hello")
105+
end
106+
end
107+
```
108+
109+
110+
```javascript
111+
const MyModule = Elixir.load(Elixir.MyModule);
112+
MyModule.hi()
113+
```

0 commit comments

Comments
 (0)