Skip to content

Commit

Permalink
移除:do-expressions,function-bind解析
Browse files Browse the repository at this point in the history
  • Loading branch information
bplok20010 committed Oct 11, 2020
1 parent 9afb046 commit ede6d22
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 65 deletions.
4 changes: 3 additions & 1 deletion lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "babel-preset-packez",
"version": "1.2.0",
"version": "1.3.0",
"description": "",
"main": "./lib/index.js",
"scripts": {
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
73 changes: 38 additions & 35 deletions test/lib/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
48 changes: 24 additions & 24 deletions test/src/babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit ede6d22

Please sign in to comment.