Skip to content

Commit b86a573

Browse files
authored
Merge pull request #712 from jooby-project/babel
Babel 6.24.0 fix #711
2 parents 32cb5a7 + be61a6c commit b86a573

6 files changed

Lines changed: 55 additions & 83 deletions

File tree

jooby-assets-babel/src/main/java/org/jooby/assets/Babel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
* sourceMaps: inline
6464
* }
6565
*
66-
* blacklist: [react]
66+
* presets: [es2015, react]
6767
* }
6868
* }
6969
* </pre>

jooby-assets-babel/src/main/resources/babel.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
};
2121

2222
/**
23-
* Source: npm install babel, npm_modules/babel/npm_modules/babel-core/browser.min.js
23+
* Source: https://github.com/babel/babel-standalone
2424
*/
25-
assets.load('lib/babel-5.8.23.min.js');
25+
assets.load('lib/babel-6.24.0.min.js');
2626

2727
try {
28-
var result = babel.transform(source, options);
28+
var result = Babel.transform(source, options);
2929
return result.code;
3030
} catch (ex) {
3131
var loc = ex.loc || {}

jooby-assets-babel/src/main/resources/lib/babel-5.8.23.min.js

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

jooby-assets-babel/src/main/resources/lib/babel-6.24.0.min.js

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jooby-assets-babel/src/test/java/org/jooby/assets/BabelTest.java

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ public void name() throws Exception {
1717

1818
@Test
1919
public void defaults() throws Exception {
20-
assertEquals("\"use strict\";\n" +
21-
"\n" +
22-
"code();",
20+
assertEquals("code();",
2321
new Babel()
2422
.process("/x.js",
2523
"code();",
@@ -29,18 +27,20 @@ public void defaults() throws Exception {
2927
@Test
3028
public void imports() throws Exception {
3129
assertEquals("\"use strict\";\n" +
32-
"\n" +
33-
"function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj[\"default\"] = obj; return newObj; } }\n" +
3430
"\n" +
3531
"var _math = require(\"math\");\n" +
3632
"\n" +
3733
"var math = _interopRequireWildcard(_math);\n" +
3834
"\n" +
35+
"function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }\n"
36+
+
37+
"\n" +
3938
"alert(\"2 = \" + math.sum(math.pi, math.pi));",
4039
new Babel()
40+
.set("presets", Arrays.asList("es2015"))
4141
.process("/x.js",
4242
"import * as math from \"math\";\n" +
43-
"alert(\"2 = \" + math.sum(math.pi, math.pi));",
43+
"alert(\"2 = \" + math.sum(math.pi, math.pi));",
4444
ConfigFactory.empty()));
4545
}
4646

@@ -56,24 +56,22 @@ public void err() throws Exception {
5656
}
5757

5858
@Test
59-
public void simpleDom() throws Exception {
60-
assertEquals("\"use strict\";\n" +
61-
"\n" +
62-
"var myDivElement = React.createElement(\"div\", { className: \"foo\" });",
59+
public void react() throws Exception {
60+
assertEquals("var myDivElement = React.createElement(\"div\", { className: \"foo\" });",
6361
new Babel()
62+
.set("presets", Arrays.asList("react"))
6463
.process("/x.js",
6564
"var myDivElement = <div className=\"foo\" />;",
6665
ConfigFactory.empty()));
6766
}
6867

6968
@Test
7069
public void inlineSourceMaps() throws Exception {
71-
assertEquals("\"use strict\";\n" +
72-
"\n" +
73-
"var myDivElement = React.createElement(\"div\", { className: \"foo\" });\n" +
74-
"//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi94LmpzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsSUFBSSxZQUFZLEdBQUcsNkJBQUssU0FBUyxFQUFDLEtBQUssR0FBRyxDQUFDIiwiZmlsZSI6Ii94LmpzIiwic291cmNlc0NvbnRlbnQiOlsidmFyIG15RGl2RWxlbWVudCA9IDxkaXYgY2xhc3NOYW1lPVwiZm9vXCIgLz47Il19",
70+
assertEquals("var myDivElement = React.createElement(\"div\", { className: \"foo\" });\n" +
71+
"//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInguanMiXSwibmFtZXMiOlsibXlEaXZFbGVtZW50Il0sIm1hcHBpbmdzIjoiQUFBQSxJQUFJQSxlQUFlLDZCQUFLLFdBQVUsS0FBZixHQUFuQiIsImZpbGUiOiJ4LmpzIiwic291cmNlc0NvbnRlbnQiOlsidmFyIG15RGl2RWxlbWVudCA9IDxkaXYgY2xhc3NOYW1lPVwiZm9vXCIgLz47Il19",
7572
new Babel()
7673
.set("sourceMaps", "inline")
74+
.set("presets", Arrays.asList("react"))
7775
.process("/x.js",
7876
"var myDivElement = <div className=\"foo\" />;",
7977
ConfigFactory.empty()));
@@ -118,8 +116,8 @@ public void polyfill() throws Exception {
118116
" _iteratorError = err;\n" +
119117
"} finally {\n" +
120118
" try {\n" +
121-
" if (!_iteratorNormalCompletion && _iterator[\"return\"]) {\n" +
122-
" _iterator[\"return\"]();\n" +
119+
" if (!_iteratorNormalCompletion && _iterator.return) {\n" +
120+
" _iterator.return();\n" +
123121
" }\n" +
124122
" } finally {\n" +
125123
" if (_didIteratorError) {\n" +
@@ -128,6 +126,7 @@ public void polyfill() throws Exception {
128126
" }\n" +
129127
"}",
130128
new Babel()
129+
.set("presets", Arrays.asList("es2015"))
131130
.process("/x.js",
132131
"let fibonacci = {\n" +
133132
" [Symbol.iterator]() {\n" +
@@ -173,7 +172,8 @@ public void polyfillWithExternalHelpers() throws Exception {
173172
"var _iteratorError = undefined;\n" +
174173
"\n" +
175174
"try {\n" +
176-
" for (var _iterator = fibonacci[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n" +
175+
" for (var _iterator = fibonacci[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {\n"
176+
+
177177
" var n = _step.value;\n" +
178178
"\n" +
179179
" // truncate the sequence at 1000\n" +
@@ -185,8 +185,8 @@ public void polyfillWithExternalHelpers() throws Exception {
185185
" _iteratorError = err;\n" +
186186
"} finally {\n" +
187187
" try {\n" +
188-
" if (!_iteratorNormalCompletion && _iterator[\"return\"]) {\n" +
189-
" _iterator[\"return\"]();\n" +
188+
" if (!_iteratorNormalCompletion && _iterator.return) {\n" +
189+
" _iterator.return();\n" +
190190
" }\n" +
191191
" } finally {\n" +
192192
" if (_didIteratorError) {\n" +
@@ -195,7 +195,8 @@ public void polyfillWithExternalHelpers() throws Exception {
195195
" }\n" +
196196
"}",
197197
new Babel()
198-
.set("externalHelpers", true)
198+
.set("presets", Arrays.asList("es2015"))
199+
.set("plugins", Arrays.asList("external-helpers"))
199200
.process("/x.js",
200201
"let fibonacci = {\n" +
201202
" [Symbol.iterator]() {\n" +
@@ -218,18 +219,6 @@ public void polyfillWithExternalHelpers() throws Exception {
218219
ConfigFactory.empty()));
219220
}
220221

221-
@Test
222-
public void blacklist() throws Exception {
223-
assertEquals("\"use strict\";\n" +
224-
"\n" +
225-
"var myDivElement = <div className=\"foo\" />;",
226-
new Babel()
227-
.set("blacklist", Arrays.asList("react"))
228-
.process("/x.js",
229-
"var myDivElement = <div className=\"foo\" />;",
230-
ConfigFactory.empty()));
231-
}
232-
233222
@Test
234223
public void ecma6Arrow() throws Exception {
235224
assertEquals("\"use strict\";\n" +
@@ -238,6 +227,7 @@ public void ecma6Arrow() throws Exception {
238227
" return v + 1;\n" +
239228
"});",
240229
new Babel()
230+
.set("presets", Arrays.asList("es2015"))
241231
.process("/x.js",
242232
"var odds = evens.map(v => v + 1);",
243233
ConfigFactory.empty()));
@@ -251,6 +241,7 @@ public void ecma6TemplateStr() throws Exception {
251241
" time = \"today\";\n" +
252242
"\"Hello \" + name + \", how are you \" + time + \"?\";",
253243
new Babel()
244+
.set("presets", Arrays.asList("es2015"))
254245
.process("/x.js",
255246
"var name = \"Bob\", time = \"today\";\n" +
256247
"`Hello ${name}, how are you ${time}?`",
@@ -273,6 +264,7 @@ public void ecma6LexicalThis() throws Exception {
273264
" }\n" +
274265
"};",
275266
new Babel()
267+
.set("presets", Arrays.asList("es2015"))
276268
.process("/x.js",
277269
"var bob = {\n" +
278270
" _name: \"Bob\",\n" +
@@ -285,15 +277,14 @@ public void ecma6LexicalThis() throws Exception {
285277
ConfigFactory.empty()));
286278
}
287279

288-
@Test
289280
public void externalHelpers() throws Exception {
290281
assertEquals("\"use strict\";\n" +
291282
"\n" +
292283
"var odds = evens.map(function (v) {\n" +
293284
" return v + 1;\n" +
294285
"});",
295286
new Babel()
296-
.set("externalHelpers", true)
287+
.set("plugins", Arrays.asList("external-helpers"))
297288
.process("/x.js",
298289
"var odds = evens.map(v => v + 1);",
299290
ConfigFactory.empty()));

md/doc/assets-babel/babel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ assets {
5555
dev {
5656
sourceMaps: inline
5757
}
58-
blacklist: [react]
58+
presets: [es2015, react]
5959
}
6060
}
6161
```

0 commit comments

Comments
 (0)