Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Babel 7 #487

Merged
merged 28 commits into from
Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
61ab4ae
feat: upgrade to babel-7
boopathi Feb 15, 2018
42a8821
fix: getFunctionParent minify-builtins
boopathi Feb 15, 2018
9a196d9
fix: formatting minify-builtins
boopathi Feb 15, 2018
ad3004a
fix: formatting constant-folding
boopathi Feb 15, 2018
8c11d36
fix: formatting dead-code-elimination
boopathi Feb 15, 2018
027f5fd
fix: formatting flip-comparisons
boopathi Feb 15, 2018
473a49c
fix: formatting infinity
boopathi Feb 15, 2018
c0c712d
fix(mangler): formatting, tests->fixtures
boopathi Feb 20, 2018
55707aa
feat: add babel.json for fixture test-runner to override babel opts
boopathi Feb 20, 2018
f9b97e2
fix: formatting mangle-names-tests.js
boopathi Feb 20, 2018
c730f7b
fix: formatting of minify-simplify test cases
boopathi Feb 20, 2018
07712ab
fix: formatting of minify-type-constructors
boopathi Feb 20, 2018
9cd078e
fix: formatting of transform-inline-consecutive-adds
boopathi Feb 20, 2018
fadcb83
fix: formatting of transform-merge-sibling-variables
boopathi Feb 20, 2018
2f9b186
fix: formatting transform-property-literals
boopathi Feb 20, 2018
3041133
fix: formatting transform-remove-console
boopathi Feb 20, 2018
abfc6d7
fix: formatting transform-remove-debugger
boopathi Feb 20, 2018
48afce9
fix: formatting tests for transform-remove-undefined
boopathi Feb 20, 2018
4bbeb23
fix: formatting tests for transform-undefined-to-void
boopathi Feb 20, 2018
8de315f
fix: formatting for babel-preset-minify
boopathi Feb 20, 2018
0bf77a5
fix: gulp-util deprecations. use Vinyl
boopathi Feb 20, 2018
588ba00
fix: babel-minify package tests
boopathi Feb 20, 2018
8cf9f33
fix: formatting tests for minify-replace
boopathi Feb 20, 2018
337563f
Upgrade all dependencies to babel7
Feb 25, 2018
363f13c
fix: path & scope out of sync
Feb 28, 2018
7948a6c
Remove comments
Feb 28, 2018
50e49ac
fix lint errors
boopathi Feb 28, 2018
ea95a22
try fix windows ci
boopathi Feb 28, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"presets": [
[
"env",
"@babel/preset-env",
{
"targets": {
"node": 4
},
"include": ["transform-async-to-generator"],
"exclude": ["transform-regenerator"]
"include": [
"transform-async-to-generator"
],
"exclude": [
"transform-regenerator"
]
}
]
]
Expand Down
15 changes: 10 additions & 5 deletions gulpfile.babel.js → gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

const through = require("through2");
const chalk = require("chalk");
const newer = require("gulp-newer");
Expand All @@ -6,25 +8,28 @@ const log = require("fancy-log");
const gulp = require("gulp");
const path = require("path");

export const build = gulp.series(buildPackages, buildUtils);
const build = gulp.series(buildPackages, buildUtils);

export const watch = gulp.series(build, () => {
const watch = gulp.series(build, () => {
const scripts = [
getBuildConfig("packages").scripts,
getBuildConfig("utils").scripts
];
gulp.watch(scripts, { debounceDelay: 200 }, build).on("error", () => {});
});

export function buildPackages() {
function buildPackages() {
return getBuildTask(getBuildConfig("packages"));
}

export function buildUtils() {
function buildUtils() {
return getBuildTask(getBuildConfig("utils"));
}

export default build;
exports.build = build;
exports.watch = watch;
exports.buildPackages = buildPackages;
exports.buildUtils = buildUtils;

function getBuildTask({ scripts, dest }) {
return gulp
Expand Down
36 changes: 17 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,37 @@
"watch": "gulp watch"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-eslint": "^8.0.3",
"babel-jest": "^22.0.3",
"babel-plugin-transform-es2015-block-scoping": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-es2015": "^6.24.1",
"babel-traverse": "^6.26.0",
"@babel/core": "^7.0.0-beta.40",
"@babel/plugin-transform-block-scoping": "^7.0.0-beta.40",
"@babel/preset-env": "^7.0.0-beta.40",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^22.2.2",
"butternut": "^0.4.6",
"bytes": "^3.0.0",
"chalk": "^2.3.0",
"chalk": "^2.3.1",
"cli-table": "^0.3.1",
"closure-compiler": "^0.2.12",
"codecov": "^3.0.0",
"commander": "^2.12.2",
"eslint": "^4.13.1",
"eslint-plugin-prettier": "^2.4.0",
"commander": "^2.14.1",
"eslint": "^4.17.0",
"eslint-plugin-prettier": "^2.6.0",
"fancy-log": "^1.3.2",
"fs-readdir-recursive": "^1.1.0",
"google-closure-compiler-js": "^20171203.0.0",
"google-closure-compiler-js": "^20180204.0.0",
"gulp": "github:gulpjs/gulp#4.0",
"gulp-babel": "^7.0.0",
"gulp-newer": "^1.3.0",
"jest-cli": "^22.0.3",
"lerna": "^2.5.1",
"gulp-babel": "^8.0.0-beta.1",
"gulp-newer": "^1.4.0",
"jest-cli": "^22.3.0",
"lerna": "^2.9.0",
"lerna-changelog": "^0.7.0",
"lint-staged": "^6.0.1",
"lint-staged": "^6.1.0",
"markdown-table": "^1.1.1",
"minimist": "^1.2.0",
"prettier": "^1.9.2",
"prettier": "^1.10.2",
"request": "^2.83.0",
"rimraf": "^2.6.2",
"through2": "^2.0.3",
"uglify-js": "^3.2.2",
"uglify-js": "^3.3.10",
"util.promisify": "^1.0.0"
},
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-minify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
},
"repository": "https://github.com/babel/minify/tree/master/packages/babel-minify",
"dependencies": {
"babel-core": "^6.26.0",
"@babel/core": "^7.0.0-beta.40",
"babel-preset-minify": "^0.3.0",
"fs-readdir-recursive": "^1.1.0",
"mkdirp": "^0.5.1",
"util.promisify": "^1.0.0",
"yargs-parser": "^8.0.0"
"yargs-parser": "^9.0.2"
}
}
4 changes: 2 additions & 2 deletions packages/babel-minify/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const babelCore = require("babel-core");
const babelCore = require("@babel/core");
const babelPresetMinify = require("babel-preset-minify");

module.exports = function babelMinify(
Expand All @@ -9,7 +9,7 @@ module.exports = function babelMinify(
// overrides and other options
{
minified = true,
inputSourceMap = null,
inputSourceMap,
sourceMaps = false,

// to override the default babelCore used
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
function c() {
var _Mathmax = Math.max;

let a = 10;
const d = false;
_Mathmax(a, b) + _Mathmax(b, a);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
function a() {
var _MathPI = Math.PI;
var _NumberNAN = Number.NAN;

_NumberNAN + _NumberNAN;
return _MathPI + _MathPI + Number.EPSILON + _NumberNAN;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
function a() {
Math.max(c, a);

const b = () => {
var _Mathmin = Math.min;
var _Mathfloor = Math.floor;

const a = _Mathfloor(c);

_Mathmin(b, a) * _Mathfloor(b);

function c() {
_Mathfloor(c) + _Mathmin(b, a);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ class Test {
var _Mathmax = Math.max;

_Mathmax(a, d);

_Mathmax(a, d);

const c = function () {
var _Mathfloor = Math.floor;

_Mathmax(c, d);

_Mathfloor(m);

_Mathfloor(m);
};
}

bar() {
var _Mathmin = Math.min;

_Mathmin(c, d);

_Mathmin(c, d);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@ var a = () => {
var _Mathfloor = Math.floor;

_Mathfloor(b);

_Mathfloor(b);

c: () => {
_Mathfloor(d);

2;
};
};

A.b("asdas", function () {
var _Mathmax = Math.max;

Math.floor(d) + _Mathmax(d, e);

_Mathmax(e, d);
});
A.b("asdas1", function () {
var _Mathfloor2 = Math.floor;

_Mathfloor2(d) + _Mathfloor2(d, e);
Math.max(e, d);
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function a() {
var _Mathfloor = Math.floor;

_Mathfloor(a) + _Mathfloor(b) + Math.min(a, b);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Math.max(c, d);

function a() {
var _Mathmax = Math.max;

_Mathmax(b, a) + _Mathmax(c, d);
}

Math.max(e, f);
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,54 @@ function b() {
var _Mathfloor = Math.floor;

_Mathfloor(as, bb);

function d() {
_Mathfloor(as, bb);
}
}

const a = {
c: () => Math.floor(bbb) + Math.floor(bbb),
d: () => {
var _Mathabs = Math.abs;
var _Mathfloor2 = Math.floor;

_Mathabs(aa);

_Mathabs(aa);

_Mathfloor2(aa);

return () => {
_Mathfloor2(aa);
};
},
e: () => Math.abs(aa) + Math.abs(aa)
};

class A {
constructor() {
var _Mathfloor3 = Math.floor;

let a = _Mathfloor3(b, c) + _Mathfloor3(b, c);
}

c() {
var _Mathfloor4 = Math.floor;

_Mathfloor4(asdas);

_Mathfloor4(dasda);
}

d() {
var _Mathfloor5 = Math.floor;

var a = _Mathfloor5;
a(aa, bb);

_Mathfloor5(aa, bb);
}

}

new A();
14 changes: 11 additions & 3 deletions packages/babel-plugin-minify-builtins/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = function({ types: t }) {
if (
!isComputed(path) &&
isBuiltin(path) &&
!path.getFunctionParent().isProgram()
!getFunctionParent(path).isProgram()
) {
const expName = memberToString(path.node);
addToMap(context.pathsToUpdate, expName, path);
Expand All @@ -68,7 +68,7 @@ module.exports = function({ types: t }) {
// Math.floor(1) --> 1
if (result.confident && hasPureArgs(path)) {
path.replaceWith(t.valueToNode(result.value));
} else if (!callee.getFunctionParent().isProgram()) {
} else if (!getFunctionParent(callee).isProgram()) {
const expName = memberToString(callee.node);
addToMap(context.pathsToUpdate, expName, callee);
}
Expand Down Expand Up @@ -180,7 +180,7 @@ function getSegmentedSubPaths(paths) {
segments.set(lastCommon, paths);
return;
} else if (
!(fnParent = lastCommon.getFunctionParent()).isProgram() &&
!(fnParent = getFunctionParent(lastCommon)).isProgram() &&
fnParent.get("body").isBlockStatement()
) {
segments.set(fnParent, paths);
Expand Down Expand Up @@ -225,3 +225,11 @@ function isComputed(path) {
const { node } = path;
return node.computed;
}

/**
* Babel-7 returns null if there is no function parent
* and uses getProgramParent to get Program
*/
function getFunctionParent(path) {
return (path.scope.getFunctionParent() || path.scope.getProgramParent()).path;
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,30 @@
4;
4;

"1,2,3";
"a,b,c";
"a@b@c";
"/1";
[/xyz/im, true].join("abc");
[`a${xyz}`].join("1");
"abc";

3;
2;
2;
void 0;

void 0;
2;

[1, 2, 3];
[2, 3];
[1, 2];
[1, 2, 3].slice(0, -1);

3;
c;
void 0;

[c, b, a];
[3, 2, 1];

[2, 3];
[2, 3];
[2, 3]; // bad calls

// bad calls
[1, 2, 3][concat]([4, 5, 6]);
[a, "b", "c"].join();
["a", "b", "c"].join(a);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
7;
a(), b();
var x = 1;
foo(x);
foo(1);
"b" + a + "cd" + g + z + "fhz";
Loading