nav tabs on admin dashboard
This commit is contained in:
+67
-45
@@ -1,25 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) 2014, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
* Copyright (c) 2014-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* https://raw.github.com/facebook/regenerator/master/LICENSE file. An
|
||||
* additional grant of patent rights can be found in the PATENTS file in
|
||||
* the same directory.
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
import assert from "assert";
|
||||
import * as t from "babel-types";
|
||||
import { hoist } from "./hoist";
|
||||
import { Emitter } from "./emit";
|
||||
import replaceShorthandObjectMethod from "./replaceShorthandObjectMethod";
|
||||
import * as util from "./util";
|
||||
import { makeAccessor } from "private";
|
||||
|
||||
exports.visitor = {
|
||||
exports.getVisitor = ({ types: t }) => ({
|
||||
Function: {
|
||||
exit: function(path, state) {
|
||||
exit: util.wrapWithTypes(t, function(path, state) {
|
||||
let node = path.node;
|
||||
|
||||
if (node.generator) {
|
||||
@@ -93,14 +90,20 @@ exports.visitor = {
|
||||
// declarations with equivalent assignment expressions.
|
||||
let vars = hoist(path);
|
||||
|
||||
let didRenameArguments = renameArguments(path, argsId);
|
||||
if (didRenameArguments) {
|
||||
let context = {
|
||||
usesThis: false,
|
||||
usesArguments: false,
|
||||
getArgsId: () => t.clone(argsId),
|
||||
};
|
||||
path.traverse(argumentsThisVisitor, context);
|
||||
|
||||
if (context.usesArguments) {
|
||||
vars = vars || t.variableDeclaration("var", []);
|
||||
const argumentIdentifier = t.identifier("arguments");
|
||||
// we need to do this as otherwise arguments in arrow functions gets hoisted
|
||||
argumentIdentifier._shadowedFunctionLiteral = path;
|
||||
vars.declarations.push(t.variableDeclarator(
|
||||
argsId, argumentIdentifier
|
||||
t.clone(argsId), argumentIdentifier
|
||||
));
|
||||
}
|
||||
|
||||
@@ -111,16 +114,22 @@ exports.visitor = {
|
||||
outerBody.push(vars);
|
||||
}
|
||||
|
||||
let wrapArgs = [
|
||||
emitter.getContextFunction(innerFnId),
|
||||
let wrapArgs = [emitter.getContextFunction(innerFnId)];
|
||||
let tryLocsList = emitter.getTryLocsList();
|
||||
|
||||
if (node.generator) {
|
||||
wrapArgs.push(outerFnExpr);
|
||||
} else if (context.usesThis || tryLocsList) {
|
||||
// Async functions that are not generators don't care about the
|
||||
// outer function because they don't need it to be marked and don't
|
||||
// inherit from its .prototype.
|
||||
node.generator ? outerFnExpr : t.nullLiteral(),
|
||||
t.thisExpression()
|
||||
];
|
||||
|
||||
let tryLocsList = emitter.getTryLocsList();
|
||||
wrapArgs.push(t.nullLiteral());
|
||||
}
|
||||
if (context.usesThis) {
|
||||
wrapArgs.push(t.thisExpression());
|
||||
} else if (tryLocsList) {
|
||||
wrapArgs.push(t.nullLiteral());
|
||||
}
|
||||
if (tryLocsList) {
|
||||
wrapArgs.push(tryLocsList);
|
||||
}
|
||||
@@ -154,19 +163,32 @@ exports.visitor = {
|
||||
path.addComment("leading", "#__PURE__");
|
||||
}
|
||||
|
||||
const insertedLocs = emitter.getInsertedLocs();
|
||||
|
||||
path.traverse({
|
||||
NumericLiteral(path) {
|
||||
if (!insertedLocs.has(path.node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
path.replaceWith(t.numericLiteral(path.node.value));
|
||||
},
|
||||
})
|
||||
|
||||
// Generators are processed in 'exit' handlers so that regenerator only has to run on
|
||||
// an ES5 AST, but that means traversal will not pick up newly inserted references
|
||||
// to things like 'regeneratorRuntime'. To avoid this, we explicitly requeue.
|
||||
path.requeue();
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
// Given a NodePath for a Function, return an Expression node that can be
|
||||
// used to refer reliably to the function object from inside the function.
|
||||
// This expression is essentially a replacement for arguments.callee, with
|
||||
// the key advantage that it works in strict mode.
|
||||
function getOuterFnExpr(funPath) {
|
||||
const t = util.getTypes();
|
||||
let node = funPath.node;
|
||||
t.assertFunction(node);
|
||||
|
||||
@@ -182,12 +204,13 @@ function getOuterFnExpr(funPath) {
|
||||
return getMarkedFunctionId(funPath);
|
||||
}
|
||||
|
||||
return node.id;
|
||||
return t.clone(node.id);
|
||||
}
|
||||
|
||||
const getMarkInfo = require("private").makeAccessor();
|
||||
const getMarkInfo = makeAccessor();
|
||||
|
||||
function getMarkedFunctionId(funPath) {
|
||||
const t = util.getTypes();
|
||||
const node = funPath.node;
|
||||
t.assertIdentifier(node.id);
|
||||
|
||||
@@ -215,7 +238,7 @@ function getMarkedFunctionId(funPath) {
|
||||
const markedId = blockPath.scope.generateUidIdentifier("marked");
|
||||
const markCallExp = t.callExpression(
|
||||
util.runtimeProperty("mark"),
|
||||
[node.id]
|
||||
[t.clone(node.id)]
|
||||
);
|
||||
|
||||
const index = info.decl.declarations.push(
|
||||
@@ -229,34 +252,23 @@ function getMarkedFunctionId(funPath) {
|
||||
|
||||
markCallExpPath.addComment("leading", "#__PURE__");
|
||||
|
||||
return markedId;
|
||||
return t.clone(markedId);
|
||||
}
|
||||
|
||||
function renameArguments(funcPath, argsId) {
|
||||
let state = {
|
||||
didRenameArguments: false,
|
||||
argsId: argsId
|
||||
};
|
||||
|
||||
funcPath.traverse(argumentsVisitor, state);
|
||||
|
||||
// If the traversal replaced any arguments references, then we need to
|
||||
// alias the outer function's arguments binding (be it the implicit
|
||||
// arguments object or some other parameter or variable) to the variable
|
||||
// named by argsId.
|
||||
return state.didRenameArguments;
|
||||
}
|
||||
|
||||
let argumentsVisitor = {
|
||||
let argumentsThisVisitor = {
|
||||
"FunctionExpression|FunctionDeclaration": function(path) {
|
||||
path.skip();
|
||||
},
|
||||
|
||||
Identifier: function(path, state) {
|
||||
if (path.node.name === "arguments" && util.isReference(path)) {
|
||||
util.replaceWithOrRemove(path, state.argsId);
|
||||
state.didRenameArguments = true;
|
||||
util.replaceWithOrRemove(path, state.getArgsId());
|
||||
state.usesArguments = true;
|
||||
}
|
||||
},
|
||||
|
||||
ThisExpression: function(path, state) {
|
||||
state.usesThis = true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -264,8 +276,16 @@ let functionSentVisitor = {
|
||||
MetaProperty(path) {
|
||||
let { node } = path;
|
||||
|
||||
if (node.meta.name === "function" && node.property.name === "sent") {
|
||||
util.replaceWithOrRemove(path, t.memberExpression(this.context, t.identifier("_sent")));
|
||||
if (node.meta.name === "function" &&
|
||||
node.property.name === "sent") {
|
||||
const t = util.getTypes();
|
||||
util.replaceWithOrRemove(
|
||||
path,
|
||||
t.memberExpression(
|
||||
t.clone(this.context),
|
||||
t.identifier("_sent")
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -276,6 +296,8 @@ let awaitVisitor = {
|
||||
},
|
||||
|
||||
AwaitExpression: function(path) {
|
||||
const t = util.getTypes();
|
||||
|
||||
// Convert await expressions to yield expressions.
|
||||
let argument = path.node.argument;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user