From ede6d2262d3e6904b6a2f7ebfe995afb5c1af9e9 Mon Sep 17 00:00:00 2001 From: bplok20010 Date: Sun, 11 Oct 2020 09:02:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=EF=BC=9Ado-expressions,funct?= =?UTF-8?q?ion-bind=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/plugins.js | 4 ++- package.json | 4 +-- src/plugins.js | 4 +-- test/lib/babel.js | 73 ++++++++++++++++++++++++----------------------- test/src/babel.js | 48 +++++++++++++++---------------- 5 files changed, 68 insertions(+), 65 deletions(-) diff --git a/lib/plugins.js b/lib/plugins.js index 461efc6..c638220 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -46,7 +46,9 @@ function _default(api, opts) { loose: true }], [require.resolve("@babel/plugin-proposal-private-methods"), { loose: true - }], require.resolve("@babel/plugin-proposal-do-expressions"), require.resolve("@babel/plugin-proposal-export-default-from"), require.resolve("@babel/plugin-proposal-export-namespace-from"), require.resolve("@babel/plugin-proposal-function-bind"), require.resolve("@babel/plugin-proposal-function-sent"), require.resolve("@babel/plugin-proposal-nullish-coalescing-operator"), require.resolve("@babel/plugin-proposal-numeric-separator"), require.resolve("@babel/plugin-proposal-optional-chaining"), require.resolve("@babel/plugin-proposal-optional-catch-binding"), [require.resolve("@babel/plugin-proposal-object-rest-spread"), { + }], // require.resolve("@babel/plugin-proposal-do-expressions"), + require.resolve("@babel/plugin-proposal-export-default-from"), require.resolve("@babel/plugin-proposal-export-namespace-from"), // require.resolve("@babel/plugin-proposal-function-bind"), + require.resolve("@babel/plugin-proposal-function-sent"), require.resolve("@babel/plugin-proposal-nullish-coalescing-operator"), require.resolve("@babel/plugin-proposal-numeric-separator"), require.resolve("@babel/plugin-proposal-optional-chaining"), require.resolve("@babel/plugin-proposal-optional-catch-binding"), [require.resolve("@babel/plugin-proposal-object-rest-spread"), { // 使用Object.assign代替babel的helper方法 loose: true, useBuiltIns: true diff --git a/package.json b/package.json index ffdecde..7dc2dad 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "babel-preset-packez", - "version": "1.2.0", + "version": "1.3.0", "description": "", "main": "./lib/index.js", "scripts": { @@ -32,10 +32,8 @@ "@babel/plugin-proposal-async-generator-functions": "^7.10.1", "@babel/plugin-proposal-class-properties": "^7.10.1", "@babel/plugin-proposal-decorators": "^7.10.1", - "@babel/plugin-proposal-do-expressions": "^7.10.1", "@babel/plugin-proposal-export-default-from": "^7.10.1", "@babel/plugin-proposal-export-namespace-from": "^7.10.1", - "@babel/plugin-proposal-function-bind": "^7.10.1", "@babel/plugin-proposal-function-sent": "^7.10.1", "@babel/plugin-proposal-nullish-coalescing-operator": "^7.10.1", "@babel/plugin-proposal-numeric-separator": "^7.10.1", diff --git a/src/plugins.js b/src/plugins.js index 26ac6c3..8526bc8 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -74,10 +74,10 @@ export default function (api, opts) { loose: true, }, ], - require.resolve("@babel/plugin-proposal-do-expressions"), + // require.resolve("@babel/plugin-proposal-do-expressions"), require.resolve("@babel/plugin-proposal-export-default-from"), require.resolve("@babel/plugin-proposal-export-namespace-from"), - require.resolve("@babel/plugin-proposal-function-bind"), + // require.resolve("@babel/plugin-proposal-function-bind"), require.resolve("@babel/plugin-proposal-function-sent"), require.resolve("@babel/plugin-proposal-nullish-coalescing-operator"), require.resolve("@babel/plugin-proposal-numeric-separator"), diff --git a/test/lib/babel.js b/test/lib/babel.js index 11fa494..4244365 100644 --- a/test/lib/babel.js +++ b/test/lib/babel.js @@ -478,28 +478,31 @@ function f() {} target.annotated = true; } } //do-expressions - -{ - var _za = x > 10 ? "big" : "small"; // is equivalent to: - - - var zza = x > 10 ? "big" : "small"; -} //function-bind - -{ - var _context3; - - func.bind(obj); // is equivalent to: - - (_context3 = func.bind(obj), obj.func).bind(_context3); // is equivalent to: - - obj.func.bind(obj); - func.call(obj, val); // is equivalent to: - - (_context3 = func.call(obj, val), obj.func).call(_context3, val); // is equivalent to: - - obj.func.call(obj, val); -} //function-sent +// { +// let za = do { +// if (x > 10) { +// ("big"); +// } else { +// ("small"); +// } +// }; +// // is equivalent to: +// let zza = x > 10 ? "big" : "small"; +// } +//function-bind +// { +// obj::func; +// // is equivalent to: +// func.bind(obj)::obj.func; +// // is equivalent to: +// obj.func.bind(obj); +// obj::func(val); +// // is equivalent to: +// func.call(obj, val)::obj.func(val); +// // is equivalent to: +// obj.func.call(obj, val); +// } +//function-sent { function generator() { @@ -510,28 +513,28 @@ function f() {} _generator = (0, _skipFirstGeneratorNext2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() { var _functionSent; - return _regenerator.default.wrap(function _callee3$(_context4) { + return _regenerator.default.wrap(function _callee3$(_context3) { while (1) { - switch (_context4.prev = _context4.next) { + switch (_context3.prev = _context3.next) { case 0: - _context4.next = 2; + _context3.next = 2; return; case 2: - _functionSent = _context4.sent; + _functionSent = _context3.sent; console.log("Sent", _functionSent); - _context4.t0 = console; - _context4.next = 7; + _context3.t0 = console; + _context3.next = 7; return; case 7: - _context4.t1 = _functionSent = _context4.sent; + _context3.t1 = _functionSent = _context3.sent; - _context4.t0.log.call(_context4.t0, "Yield", _context4.t1); + _context3.t0.log.call(_context3.t0, "Yield", _context3.t1); case 9: case "end": - return _context4.stop(); + return _context3.stop(); } } }, _callee3); @@ -659,16 +662,16 @@ function f() {} var _marked = /*#__PURE__*/_regenerator.default.mark(_a6); function _a6() { - return _regenerator.default.wrap(function _a6$(_context5) { + return _regenerator.default.wrap(function _a6$(_context4) { while (1) { - switch (_context5.prev = _context5.next) { + switch (_context4.prev = _context4.next) { case 0: - _context5.next = 2; + _context4.next = 2; return 1; case 2: case "end": - return _context5.stop(); + return _context4.stop(); } } }, _marked); diff --git a/test/src/babel.js b/test/src/babel.js index a0c1f1f..859e63d 100644 --- a/test/src/babel.js +++ b/test/src/babel.js @@ -291,31 +291,31 @@ export { sv21 as v }; } } //do-expressions -{ - let za = do { - if (x > 10) { - ("big"); - } else { - ("small"); - } - }; - // is equivalent to: - let zza = x > 10 ? "big" : "small"; -} +// { +// let za = do { +// if (x > 10) { +// ("big"); +// } else { +// ("small"); +// } +// }; +// // is equivalent to: +// let zza = x > 10 ? "big" : "small"; +// } //function-bind -{ - obj::func; - // is equivalent to: - func.bind(obj)::obj.func; - // is equivalent to: - obj.func.bind(obj); - - obj::func(val); - // is equivalent to: - func.call(obj, val)::obj.func(val); - // is equivalent to: - obj.func.call(obj, val); -} +// { +// obj::func; +// // is equivalent to: +// func.bind(obj)::obj.func; +// // is equivalent to: +// obj.func.bind(obj); + +// obj::func(val); +// // is equivalent to: +// func.call(obj, val)::obj.func(val); +// // is equivalent to: +// obj.func.call(obj, val); +// } //function-sent { function* generator() {