Skip to content

Commit 55e2618

Browse files
committed
Merge in master
2 parents 5d7776d + 97188b7 commit 55e2618

Some content is hidden

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

70 files changed

+1660
-1063
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ src/elixirscript
1919
priv/**/*.js
2020
stdlib_state.bin
2121
*.log
22+
test/app/build

.travis.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ env:
88
- TRAVIS_NODE_VERSION="6"
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
11-
- npm install
11+
- npm install -g yarn
12+
- yarn
1213
script:
1314
- mix local.hex --force
1415
- mix local.rebar --force
1516
- mix deps.get
1617
- mix compile
18+
- yarn build
1719
- mix test
18-
- npm test
20+
- yarn test
21+
- yarn test-app
1922
notifications:
2023
webhooks:
2124
urls:
2225
- https://webhooks.gitter.im/e/fbd8944d285c0696dc41
2326
on_success: always # options: [always|never|change] default: always
2427
on_failure: always # options: [always|never|change] default: always
25-
on_start: never # options: [always|never|change] default: always
28+
on_start: never # options: [always|never|change] default: always

CHANGELOG.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,33 @@ 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.27.0-dev]
7+
## [0.27.0] - 2017-03-17
88

99
### Added
1010
- `super`
1111
- `defoverridable`
12+
- `IO.inspect\1`, `IO.puts\1`, `IO.puts\2`, `IO.warn\1`
13+
- `Elixir.load` for loading generated JavaScript modules in bundled output.
14+
Unlike `Elixir.start`, this will only call `__load` on the module and return the functions on it
15+
16+
```javascript
17+
const exports = Elixir.load(Elixir.MyApp);
18+
exports.hello();
19+
```
1220

1321
### Changed
1422
- `-ex` alias is now `-e`
1523
- A filename can be specified for output
24+
- To access global JavaScript functions, modules, and properties, use the `JS` module
25+
```elixir
26+
JS.length # translates to 'length'
27+
JS.alert() # translates to 'alert()'
28+
JS.String.raw("hi") # translate to String.raw('hi')
29+
JS.console.log("hi") # translates to console.log('hi')
30+
```
31+
32+
### Fixed
33+
- Make sure mix compiler works in umbrella apps
1634

1735
## [0.26.1] - 2017-02-27
1836

@@ -46,7 +64,7 @@ elixirscript "app/elixirscript" -o dist --js-module React:react --js-module Reac
4664
- Now bundles all output, including the boostrap code.
4765
The exported object has Elixir modules in JavaScript namespaces that are lazily loaded when called.
4866

49-
To start your application import the bundle according to whichever module format was selected and
67+
To start your application import the bundle according to whichever module format was selected and
5068
then call start giving it the module and the initial args
5169

5270
```javascript
@@ -67,7 +85,7 @@ elixirscript "app/elixirscript" -o dist --js-module React:react --js-module Reac
6785
- Updated elixir_script mix compiler to support compiling elixir_script paths in dependencies if dependency has mix compiler defined as well
6886
- Add `Collectable` protocol implementations
6987
- Updated `for` implementation to use `Collectable`
70-
- `format` option. Can now specify the module format of output.
88+
- `format` option. Can now specify the module format of output.
7189
Choices are:
7290
* `:es` (default) for ES Modules
7391
* `:umd` for UMD

GettingStarted.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ This is the help output of elixirscript
3030
the elixir code string if passed the -e flag
3131
options:
3232
--js-module [<identifer>:<path>] A js module used in your code. ex: React:react
33-
Multiple can be defined
33+
Multiple can be defined
3434
-f --format [format] module format of output. options: es (default), common, umd
35-
-o --output [path] places output at the given path.
35+
-o --output [path] places output at the given path.
3636
Can be a directory or filename.
3737
-e --elixir read input as elixir code string
3838
--full-build informs the compiler to do a full build instead of an incremental one
@@ -49,10 +49,10 @@ elixirscript also takes a path to your `.ex` files as well:
4949

5050
If you look in the dist folder you'll see a file called `Elixir.App.js`
5151

52-
To start your application import the bundle according to whichever module format was selected and
52+
To start your application import the bundle according to whichever module format was selected and
5353
then call start giving it the module and the initial args.
5454

55-
Ex. If you have a module like so
55+
Ex. If you have a module like so
5656
```elixir
5757
defmodule Example do
5858
start(type, args) do
@@ -87,14 +87,15 @@ Add dependency to your deps in mix.exs:
8787
version: "0.1.0",
8888
elixir: "~> 1.0",
8989
deps: deps,
90-
elixir_script: [
91-
input: "lib/elixirscript",
92-
output: "priv/elixirscript/Elixir.App.js",
90+
elixir_script: [
91+
input: "lib/elixirscript",
92+
output: "priv/elixirscript/Elixir.App.js",
9393
format: :es,
9494
js_modules: [
9595
{React, "react"},
96-
{ReactDOM, "react-dom"}
97-
]
96+
{ReactDOM, "react-dom"},
97+
{Phoenix, "phoenix", default: false}
98+
]
9899
],
99100
compilers: [:elixir_script] ++ Mix.compilers
100101
]
@@ -117,7 +118,9 @@ Available options are:
117118

118119
* `:umd` - UMD
119120

120-
* `js_modules`: A list of JavaScript imports to add. Each item must be 2-tuple or a 3-tuple. The third element is an optional keyword list of options.
121+
* `js_modules`: A list of JavaScript imports to add. Each item must be 2-tuple or a 3-tuple. The third element is an optional keyword list of options:
122+
123+
* `default` - Defaults to true. Set to false if the imported module has no default export.
121124

122125
### Macros
123126

@@ -160,6 +163,6 @@ There is an [elixirscript frontend boilerplate project](https://github.com/elixi
160163

161164
There is an Brunch plugin, [elixirscript-brunch](https://www.npmjs.com/package/elixirscript-brunch).
162165

163-
####
166+
#### elixirscript-loader
164167

165-
There is also a webpack loader, [elixirscript-loader](https://www.npmjs.com/package/elixirscript-loader).
168+
There is also a webpack loader, [elixirscript-loader](https://www.npmjs.com/package/elixirscript-loader).

gulpfile.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
var gulp = require('gulp');
2-
var babel = require('gulp-babel');
3-
var sourcemaps = require('gulp-sourcemaps');
1+
const gulp = require('gulp');
2+
const babel = require('gulp-babel');
3+
const sourcemaps = require('gulp-sourcemaps');
44

5-
var path = './src/javascript';
5+
const path = './src/javascript';
66

7-
gulp.task('build', function() {
8-
return gulp.src([path + '/**/*.js', '!' + path + '/dist_build/**/*.js', '!' + path + '/tests/**/*.js'])
7+
gulp.task('build', () => gulp.src([`${path}/**/*.js`, `!${path}/dist_build/**/*.js`, `!${path}/tests/**/*.js`])
98
.pipe(sourcemaps.init())
10-
.pipe(babel({ presets: ["react", "stage-0"], babelrc: false }))
9+
.pipe(babel({ presets: ['react', 'stage-0'], babelrc: false }))
1110
.pipe(sourcemaps.write())
12-
.pipe(gulp.dest('./src/elixirscript'));
13-
});
11+
.pipe(gulp.dest('./src/elixirscript')));

lib/elixir_script/passes/create_js_modules.ex

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,18 @@ defmodule ElixirScript.Passes.CreateJSModules do
6565

6666
elixir = JS.variable_declaration([declarator], :const)
6767

68-
start = JS.assignment_expression(
68+
ast = opts.module_formatter.build(
69+
[],
70+
opts.js_modules,
71+
[elixir, start, load] ++ body,
72+
JS.identifier("Elixir")
73+
)
74+
75+
ast
76+
end
77+
78+
def start do
79+
JS.assignment_expression(
6980
:=,
7081
JS.member_expression(
7182
JS.identifier("Elixir"),
@@ -91,15 +102,30 @@ defmodule ElixirScript.Passes.CreateJSModules do
91102
])
92103
)
93104
)
105+
end
94106

95-
ast = opts.module_formatter.build(
96-
[],
97-
opts.js_modules,
98-
[elixir, start] ++ body,
99-
JS.identifier("Elixir")
107+
def load do
108+
JS.assignment_expression(
109+
:=,
110+
JS.member_expression(
111+
JS.identifier("Elixir"),
112+
JS.identifier("load")
113+
),
114+
JS.function_expression(
115+
[JS.identifier(:module)],
116+
[],
117+
JS.block_statement([
118+
JS.return_statement(
119+
JS.call_expression(
120+
JS.member_expression(
121+
JS.identifier(:module),
122+
JS.identifier("__load")
123+
),
124+
[JS.identifier("Elixir")]
125+
)
126+
)
127+
])
128+
)
100129
)
101-
102-
ast
103130
end
104-
105131
end

lib/elixir_script/passes/find_functions.ex

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
defmodule ElixirScript.Passes.FindFunctions do
2-
@moduledoc false
2+
@moduledoc false
33
@function_types [:def, :defp, :defgen, :defgenp, :defmacro, :defmacrop]
44

55
def execute(data, _) do
66
new_data = Enum.map(data.data, fn { module_name, module_data } ->
77

88
%{
9-
def: functions,
10-
defp: private_functions,
11-
defgen: generators,
12-
defgenp: private_generators,
13-
defmacro: macros,
9+
def: functions,
10+
defp: private_functions,
11+
defgen: generators,
12+
defgenp: private_generators,
13+
defmacro: macros,
1414
defmacrop: private_macros,
1515
defdelegate: delegates
1616
} = get_functions_from_module(module_data.ast)
@@ -54,7 +54,7 @@ defmodule ElixirScript.Passes.FindFunctions do
5454

5555
({:defdelegate, _, [{name, _, params}], _}, state) ->
5656
arity = length(params)
57-
add_function_to_map(state, :defdelegate, name, arity)
57+
add_function_to_map(state, :defdelegate, name, arity)
5858

5959
_, state ->
6060
state
@@ -63,12 +63,12 @@ defmodule ElixirScript.Passes.FindFunctions do
6363
end
6464

6565
defp new_function_map() do
66-
%{
67-
def: Keyword.new,
68-
defp: Keyword.new,
69-
defgen: Keyword.new,
70-
defgenp: Keyword.new,
71-
defmacro: Keyword.new,
66+
%{
67+
def: Keyword.new,
68+
defp: Keyword.new,
69+
defgen: Keyword.new,
70+
defgenp: Keyword.new,
71+
defmacro: Keyword.new,
7272
defmacrop: Keyword.new,
7373
defdelegate: Keyword.new
7474
}
@@ -89,4 +89,4 @@ defmodule ElixirScript.Passes.FindFunctions do
8989
end
9090

9191

92-
end
92+
end

0 commit comments

Comments
 (0)