Skip to content

Commit 750ea7b

Browse files
committed
Upgrade to Babel 7
1 parent 4644d07 commit 750ea7b

File tree

7 files changed

+35
-42
lines changed

7 files changed

+35
-42
lines changed

.babelrc

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
22
"presets": [
3-
"stage-0",
4-
"es2015"
3+
"@babel/preset-env"
54
],
65
"plugins": [
7-
"typecheck"
6+
"@babel/plugin-proposal-class-properties"
87
]
9-
}
8+
}

.travis.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@ sudo: false
22
language: node_js
33

44
node_js:
5-
- "0.12"
6-
- "iojs"
7-
- "4.2.1"
5+
- "6.17.1"

package.json

+13-17
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"description": "Design by Contract for JavaScript via a Babel plugin.",
55
"main": "lib/index.js",
66
"scripts": {
7-
"build": "babel --plugins syntax-flow,transform-flow-strip-types -d ./lib ./src",
8-
"build-typed": "npm run build && babel --plugins ./lib,syntax-flow,transform-flow-strip-types -d ./lib-checked ./src",
7+
"build": "babel --plugins @babel/plugin-syntax-flow,@babel/plugin-transform-flow-strip-types -d ./lib ./src",
8+
"build-typed": "npm run build && babel --plugins ./lib,@babel/plugin-syntax-flow,@babel/plugin-transform-flow-strip-types -d ./lib-checked ./src",
99
"prepublish": "npm run build",
1010
"pretest": "npm run build",
1111
"test": "mocha ./test/index.js",
@@ -33,22 +33,18 @@
3333
},
3434
"homepage": "https://github.com/codemix/babel-plugin-contracts",
3535
"dependencies": {
36-
"babel-generator": "^6.1.2"
36+
"@babel/generator": "^7.4.0"
3737
},
3838
"devDependencies": {
39-
"babel-cli": "^6.1.0",
40-
"babel-core": "^6.1.0",
41-
"babel-plugin-syntax-class-properties": "^6.1.18",
42-
"babel-plugin-syntax-flow": "^6.0.14",
43-
"babel-plugin-transform-es2015-modules-commonjs": "^6.1.3",
44-
"babel-plugin-transform-flow-strip-types": "^6.0.14",
45-
"babel-plugin-typecheck": "^3.9.0",
46-
"babel-polyfill": "^6.0.16",
47-
"babel-preset-es2015": "^6.1.0",
48-
"babel-preset-react": "^6.1.0",
49-
"babel-preset-stage-0": "^6.1.18",
50-
"babel-preset-stage-1": "^6.1.0",
51-
"mocha": "~2.2.4",
52-
"should": "^6.0.1"
39+
"@babel/cli": "^7.4.3",
40+
"@babel/core": "^7.4.3",
41+
"@babel/plugin-proposal-class-properties": "^7.4.0",
42+
"@babel/plugin-syntax-flow": "^7.2.0",
43+
"@babel/plugin-transform-flow-strip-types": "^7.4.0",
44+
"@babel/polyfill": "^7.4.3",
45+
"@babel/preset-env": "^7.4.3",
46+
"@babel/register": "^7.4.0",
47+
"mocha": "~6.1.2",
48+
"should": "^13.2.3"
5349
}
5450
}

src/index.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import generate from "babel-generator";
1+
import generate from "@babel/generator";
22

33
type Plugin = {
44
visitor: Visitors
@@ -55,15 +55,15 @@ export default function ({types: t, template, options}: PluginParams): Plugin {
5555
let NAMES = Object.assign({}, defaultNames);
5656

5757
const guard: (ids: {[key: string]: Node}) => Node = template(`
58-
if (!condition) {
59-
throw new Error(message);
58+
if (!%%condition%%) {
59+
throw new Error(%%message%%);
6060
}
6161
`);
6262

6363
const guardFn: (ids: {[key: string]: Node}) => Node = template(`
64-
const id = (it) => {
65-
conditions;
66-
return it;
64+
const %%id%% = (%%it%%) => {
65+
%%conditions%%;
66+
return %%it%%;
6767
}
6868
`);
6969

@@ -320,7 +320,7 @@ export default function ({types: t, template, options}: PluginParams): Plugin {
320320
throw expression.buildCodeFrameError(`Contract always fails.`);
321321
}
322322

323-
return expression;
323+
return expression.node;
324324
}
325325

326326
return {

test-polyfill.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
require("babel-core/register")({
2-
"presets": ["stage-1", "es2015"],
1+
require("@babel/register")({
2+
"presets": ["@babel/preset-env"],
33
"plugins": [
4-
//"syntax-flow",
5-
"transform-flow-strip-types"
4+
//"@babel/plugin-syntax-flow",
5+
"@babel/plugin-transform-flow-strip-types",
6+
"@babel/plugin-proposal-class-properties"
67
]
78
});

test/index.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fs from 'fs';
2-
import {parse, transform, traverse} from 'babel-core';
2+
import {transform} from '@babel/core';
33

44
if (process.env.NODE_WATCH) {
55
var contracts = require('../src').default;
@@ -105,17 +105,16 @@ function loadInternal (basename) {
105105
const transformed = transform(source, {
106106
filename: filename,
107107
presets: [
108-
"es2015",
109-
"stage-0",
108+
"@babel/preset-env"
110109
],
111110
plugins: [
112111
[contracts, {
113112
names: {
114113
return: 'retVal',
115114
}
116115
}],
117-
'transform-flow-strip-types',
118-
'syntax-class-properties'
116+
"@babel/plugin-transform-flow-strip-types",
117+
"@babel/plugin-proposal-class-properties"
119118
]
120119
});
121120
const context = {
@@ -213,4 +212,4 @@ function failStatic (basename, ...args) {
213212
throw new Error(`Test '${basename}' should have failed static verification but did not.`);
214213
}
215214
});
216-
}
215+
}

test/mocha.opts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
--reporter=spec
22
--require should
3-
--require babel-polyfill
3+
--require @babel/polyfill
44
--require ./test-polyfill.js

0 commit comments

Comments
 (0)