Skip to content

Commit d7b11c5

Browse files
author
drake.aren
committed
upgrade from babel-core^6.18 to @babel/core^7.2.3
1 parent 40c0f82 commit d7b11c5

File tree

25 files changed

+2187
-1072
lines changed

25 files changed

+2187
-1072
lines changed

.babelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"presets": ["es2015"],
2+
"presets": ["@babel/preset-env"],
33
"plugins": ["strict-equality"]
44
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ $ babel --plugins implicit-return script.js
130130
### Via Node API
131131

132132
```javascript
133-
require("babel-core").transform("code", {
133+
require("@babel/core").transform("code", {
134134
plugins: ["implicit-return"]
135135
});
136136
```

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"build": "babel src/index.js -o lib/index.js",
88
"watch-build": "npm run build -- -w",
9-
"test": "mocha --compilers js:babel-register",
9+
"test": "mocha --compilers js:@babel/register",
1010
"watch-test": "npm test -- -w",
1111
"lint": "eslint **/*.js --quiet"
1212
},
@@ -27,19 +27,19 @@
2727
},
2828
"homepage": "https://github.com/miraks/babel-plugin-implicit-return",
2929
"devDependencies": {
30-
"babel-cli": "^6.18.0",
31-
"babel-core": "^6.21.0",
30+
"@babel/cli": "^7.2.3",
31+
"@babel/core": "^7.2.2",
32+
"@babel/preset-env": "^7.3.1",
33+
"@babel/register": "^7.0.0",
3234
"babel-eslint": "^7.1.1",
3335
"babel-plugin-strict-equality": "^1.0.0",
3436
"babel-plugin-syntax-async-functions": "^6.13.0",
3537
"babel-plugin-syntax-async-generators": "^6.13.0",
3638
"babel-plugin-syntax-flow": "^6.18.0",
3739
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
3840
"babel-plugin-transform-react-jsx": "^6.8.0",
39-
"babel-preset-es2015": "^6.18.0",
40-
"babel-register": "^6.18.0",
4141
"chai": "^3.5.0",
4242
"eslint": "^3.12.2",
43-
"mocha": "^3.2.0"
43+
"mocha": "^5.2.0"
4444
}
4545
}

src/index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ export default ({ types: t }) => {
3636

3737
const { body, directives } = node.body
3838

39-
if (body.length == 0) {
40-
// empty function
41-
if (directives.length == 0) return
39+
try {
40+
if (body.length == 0) {
41+
// empty function
42+
if (directives.length == 0) return
4243

43-
// function with directives only
44-
const directive = directives.pop()
45-
body.push(t.returnStatement(t.stringLiteral(directive.value.value)))
44+
// function with directives only
45+
const directive = directives.pop()
46+
body.push(t.returnStatement(t.stringLiteral(directive.value.value)))
4647

48+
return
49+
}
50+
} catch (error) {
4751
return
4852
}
4953

@@ -52,7 +56,11 @@ export default ({ types: t }) => {
5256
const lastNode = body[lastIndex]
5357

5458
// skip unreturnable statements
55-
if (unreturnableStatements.has(lastNode.type)) return
59+
try {
60+
if (unreturnableStatements.has(lastNode.type)) return
61+
} catch (error) {
62+
return
63+
}
5664

5765
// convert returnable statements
5866
if (returnableStatements.has(lastNode.type)) {

test/fixtures/class-methods/expected.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ class Thing {
1010
static fn() {
1111
return 1;
1212
}
13+
1314
}

test/fixtures/object-properties/expected.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ const obj = {
66
return 2;
77
},
88
c: () => 3,
9+
910
d() {
1011
return 4;
1112
},
13+
1214
["a" + "b"]: () => {
1315
return 5;
1416
}

test/fixtures/return-class-with-methods/expected.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ function fn() {
33
constructor() {
44
return super();
55
}
6+
67
fn() {
78
return 1;
89
}
10+
911
};
1012
}

test/fixtures/return-do-while/expected.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ function fn() {
22
var _ret;
33

44
let n = 0;
5+
56
do {
67
_ret = n += 1;
78
} while (n < 5);
9+
810
return _ret;
911
}

test/fixtures/return-for-in/expected.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ function fn() {
22
var _ret;
33

44
const arr = [1, 2, 3];
5+
56
for (let n in arr) {
67
_ret = n + 1;
78
}
9+
810
return _ret;
911
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
function fn() {
22
var _ret;
33

4-
const obj = { a: 1, b: 2 };
4+
const obj = {
5+
a: 1,
6+
b: 2
7+
};
8+
59
for (let entry of obj) {
610
_ret = entry[0] + entry[1];
711
}
12+
813
return _ret;
914
}

0 commit comments

Comments
 (0)