summaryrefslogtreecommitdiff
path: root/chromium/third_party/node/node_modules/@babel/traverse/lib/path/lib
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/third_party/node/node_modules/@babel/traverse/lib/path/lib')
-rw-r--r--chromium/third_party/node/node_modules/@babel/traverse/lib/path/lib/hoister.js206
-rw-r--r--chromium/third_party/node/node_modules/@babel/traverse/lib/path/lib/removal-hooks.js38
-rw-r--r--chromium/third_party/node/node_modules/@babel/traverse/lib/path/lib/virtual-types.js230
3 files changed, 474 insertions, 0 deletions
diff --git a/chromium/third_party/node/node_modules/@babel/traverse/lib/path/lib/hoister.js b/chromium/third_party/node/node_modules/@babel/traverse/lib/path/lib/hoister.js
new file mode 100644
index 00000000000..536a3409741
--- /dev/null
+++ b/chromium/third_party/node/node_modules/@babel/traverse/lib/path/lib/hoister.js
@@ -0,0 +1,206 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.default = void 0;
+
+var _t = require("@babel/types");
+
+var _t2 = _t;
+const {
+ react
+} = _t;
+const {
+ cloneNode,
+ jsxExpressionContainer,
+ variableDeclaration,
+ variableDeclarator
+} = _t2;
+const referenceVisitor = {
+ ReferencedIdentifier(path, state) {
+ if (path.isJSXIdentifier() && react.isCompatTag(path.node.name) && !path.parentPath.isJSXMemberExpression()) {
+ return;
+ }
+
+ if (path.node.name === "this") {
+ let scope = path.scope;
+
+ do {
+ if (scope.path.isFunction() && !scope.path.isArrowFunctionExpression()) {
+ break;
+ }
+ } while (scope = scope.parent);
+
+ if (scope) state.breakOnScopePaths.push(scope.path);
+ }
+
+ const binding = path.scope.getBinding(path.node.name);
+ if (!binding) return;
+
+ for (const violation of binding.constantViolations) {
+ if (violation.scope !== binding.path.scope) {
+ state.mutableBinding = true;
+ path.stop();
+ return;
+ }
+ }
+
+ if (binding !== state.scope.getBinding(path.node.name)) return;
+ state.bindings[path.node.name] = binding;
+ }
+
+};
+
+class PathHoister {
+ constructor(path, scope) {
+ this.breakOnScopePaths = void 0;
+ this.bindings = void 0;
+ this.mutableBinding = void 0;
+ this.scopes = void 0;
+ this.scope = void 0;
+ this.path = void 0;
+ this.attachAfter = void 0;
+ this.breakOnScopePaths = [];
+ this.bindings = {};
+ this.mutableBinding = false;
+ this.scopes = [];
+ this.scope = scope;
+ this.path = path;
+ this.attachAfter = false;
+ }
+
+ isCompatibleScope(scope) {
+ for (const key of Object.keys(this.bindings)) {
+ const binding = this.bindings[key];
+
+ if (!scope.bindingIdentifierEquals(key, binding.identifier)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ getCompatibleScopes() {
+ let scope = this.path.scope;
+
+ do {
+ if (this.isCompatibleScope(scope)) {
+ this.scopes.push(scope);
+ } else {
+ break;
+ }
+
+ if (this.breakOnScopePaths.indexOf(scope.path) >= 0) {
+ break;
+ }
+ } while (scope = scope.parent);
+ }
+
+ getAttachmentPath() {
+ let path = this._getAttachmentPath();
+
+ if (!path) return;
+ let targetScope = path.scope;
+
+ if (targetScope.path === path) {
+ targetScope = path.scope.parent;
+ }
+
+ if (targetScope.path.isProgram() || targetScope.path.isFunction()) {
+ for (const name of Object.keys(this.bindings)) {
+ if (!targetScope.hasOwnBinding(name)) continue;
+ const binding = this.bindings[name];
+
+ if (binding.kind === "param" || binding.path.parentKey === "params") {
+ continue;
+ }
+
+ const bindingParentPath = this.getAttachmentParentForPath(binding.path);
+
+ if (bindingParentPath.key >= path.key) {
+ this.attachAfter = true;
+ path = binding.path;
+
+ for (const violationPath of binding.constantViolations) {
+ if (this.getAttachmentParentForPath(violationPath).key > path.key) {
+ path = violationPath;
+ }
+ }
+ }
+ }
+ }
+
+ return path;
+ }
+
+ _getAttachmentPath() {
+ const scopes = this.scopes;
+ const scope = scopes.pop();
+ if (!scope) return;
+
+ if (scope.path.isFunction()) {
+ if (this.hasOwnParamBindings(scope)) {
+ if (this.scope === scope) return;
+ const bodies = scope.path.get("body").get("body");
+
+ for (let i = 0; i < bodies.length; i++) {
+ if (bodies[i].node._blockHoist) continue;
+ return bodies[i];
+ }
+ } else {
+ return this.getNextScopeAttachmentParent();
+ }
+ } else if (scope.path.isProgram()) {
+ return this.getNextScopeAttachmentParent();
+ }
+ }
+
+ getNextScopeAttachmentParent() {
+ const scope = this.scopes.pop();
+ if (scope) return this.getAttachmentParentForPath(scope.path);
+ }
+
+ getAttachmentParentForPath(path) {
+ do {
+ if (!path.parentPath || Array.isArray(path.container) && path.isStatement()) {
+ return path;
+ }
+ } while (path = path.parentPath);
+ }
+
+ hasOwnParamBindings(scope) {
+ for (const name of Object.keys(this.bindings)) {
+ if (!scope.hasOwnBinding(name)) continue;
+ const binding = this.bindings[name];
+ if (binding.kind === "param" && binding.constant) return true;
+ }
+
+ return false;
+ }
+
+ run() {
+ this.path.traverse(referenceVisitor, this);
+ if (this.mutableBinding) return;
+ this.getCompatibleScopes();
+ const attachTo = this.getAttachmentPath();
+ if (!attachTo) return;
+ if (attachTo.getFunctionParent() === this.path.getFunctionParent()) return;
+ let uid = attachTo.scope.generateUidIdentifier("ref");
+ const declarator = variableDeclarator(uid, this.path.node);
+ const insertFn = this.attachAfter ? "insertAfter" : "insertBefore";
+ const [attached] = attachTo[insertFn]([attachTo.isVariableDeclarator() ? declarator : variableDeclaration("var", [declarator])]);
+ const parent = this.path.parentPath;
+
+ if (parent.isJSXElement() && this.path.container === parent.node.children) {
+ uid = jsxExpressionContainer(uid);
+ }
+
+ this.path.replaceWith(cloneNode(uid));
+ return attachTo.isVariableDeclarator() ? attached.get("init") : attached.get("declarations.0.init");
+ }
+
+}
+
+exports.default = PathHoister; \ No newline at end of file
diff --git a/chromium/third_party/node/node_modules/@babel/traverse/lib/path/lib/removal-hooks.js b/chromium/third_party/node/node_modules/@babel/traverse/lib/path/lib/removal-hooks.js
new file mode 100644
index 00000000000..23ec8fe6d7e
--- /dev/null
+++ b/chromium/third_party/node/node_modules/@babel/traverse/lib/path/lib/removal-hooks.js
@@ -0,0 +1,38 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.hooks = void 0;
+const hooks = [function (self, parent) {
+ const removeParent = self.key === "test" && (parent.isWhile() || parent.isSwitchCase()) || self.key === "declaration" && parent.isExportDeclaration() || self.key === "body" && parent.isLabeledStatement() || self.listKey === "declarations" && parent.isVariableDeclaration() && parent.node.declarations.length === 1 || self.key === "expression" && parent.isExpressionStatement();
+
+ if (removeParent) {
+ parent.remove();
+ return true;
+ }
+}, function (self, parent) {
+ if (parent.isSequenceExpression() && parent.node.expressions.length === 1) {
+ parent.replaceWith(parent.node.expressions[0]);
+ return true;
+ }
+}, function (self, parent) {
+ if (parent.isBinary()) {
+ if (self.key === "left") {
+ parent.replaceWith(parent.node.right);
+ } else {
+ parent.replaceWith(parent.node.left);
+ }
+
+ return true;
+ }
+}, function (self, parent) {
+ if (parent.isIfStatement() && (self.key === "consequent" || self.key === "alternate") || self.key === "body" && (parent.isLoop() || parent.isArrowFunctionExpression())) {
+ self.replaceWith({
+ type: "BlockStatement",
+ body: []
+ });
+ return true;
+ }
+}];
+exports.hooks = hooks; \ No newline at end of file
diff --git a/chromium/third_party/node/node_modules/@babel/traverse/lib/path/lib/virtual-types.js b/chromium/third_party/node/node_modules/@babel/traverse/lib/path/lib/virtual-types.js
new file mode 100644
index 00000000000..7dbda0b7ad8
--- /dev/null
+++ b/chromium/third_party/node/node_modules/@babel/traverse/lib/path/lib/virtual-types.js
@@ -0,0 +1,230 @@
+"use strict";
+
+Object.defineProperty(exports, "__esModule", {
+ value: true
+});
+exports.ForAwaitStatement = exports.NumericLiteralTypeAnnotation = exports.ExistentialTypeParam = exports.SpreadProperty = exports.RestProperty = exports.Flow = exports.Pure = exports.Generated = exports.User = exports.Var = exports.BlockScoped = exports.Referenced = exports.Scope = exports.Expression = exports.Statement = exports.BindingIdentifier = exports.ReferencedMemberExpression = exports.ReferencedIdentifier = void 0;
+
+var _t = require("@babel/types");
+
+const {
+ isBinding,
+ isBlockScoped,
+ isExportDeclaration,
+ isExpression,
+ isFlow,
+ isForStatement,
+ isForXStatement,
+ isIdentifier,
+ isImportDeclaration,
+ isImportSpecifier,
+ isJSXIdentifier,
+ isJSXMemberExpression,
+ isMemberExpression,
+ isReferenced,
+ isScope,
+ isStatement,
+ isVar,
+ isVariableDeclaration,
+ react
+} = _t;
+const {
+ isCompatTag
+} = react;
+const ReferencedIdentifier = {
+ types: ["Identifier", "JSXIdentifier"],
+
+ checkPath(path, opts) {
+ const {
+ node,
+ parent
+ } = path;
+
+ if (!isIdentifier(node, opts) && !isJSXMemberExpression(parent, opts)) {
+ if (isJSXIdentifier(node, opts)) {
+ if (isCompatTag(node.name)) return false;
+ } else {
+ return false;
+ }
+ }
+
+ return isReferenced(node, parent, path.parentPath.parent);
+ }
+
+};
+exports.ReferencedIdentifier = ReferencedIdentifier;
+const ReferencedMemberExpression = {
+ types: ["MemberExpression"],
+
+ checkPath({
+ node,
+ parent
+ }) {
+ return isMemberExpression(node) && isReferenced(node, parent);
+ }
+
+};
+exports.ReferencedMemberExpression = ReferencedMemberExpression;
+const BindingIdentifier = {
+ types: ["Identifier"],
+
+ checkPath(path) {
+ const {
+ node,
+ parent
+ } = path;
+ const grandparent = path.parentPath.parent;
+ return isIdentifier(node) && isBinding(node, parent, grandparent);
+ }
+
+};
+exports.BindingIdentifier = BindingIdentifier;
+const Statement = {
+ types: ["Statement"],
+
+ checkPath({
+ node,
+ parent
+ }) {
+ if (isStatement(node)) {
+ if (isVariableDeclaration(node)) {
+ if (isForXStatement(parent, {
+ left: node
+ })) return false;
+ if (isForStatement(parent, {
+ init: node
+ })) return false;
+ }
+
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+};
+exports.Statement = Statement;
+const Expression = {
+ types: ["Expression"],
+
+ checkPath(path) {
+ if (path.isIdentifier()) {
+ return path.isReferencedIdentifier();
+ } else {
+ return isExpression(path.node);
+ }
+ }
+
+};
+exports.Expression = Expression;
+const Scope = {
+ types: ["Scopable", "Pattern"],
+
+ checkPath(path) {
+ return isScope(path.node, path.parent);
+ }
+
+};
+exports.Scope = Scope;
+const Referenced = {
+ checkPath(path) {
+ return isReferenced(path.node, path.parent);
+ }
+
+};
+exports.Referenced = Referenced;
+const BlockScoped = {
+ checkPath(path) {
+ return isBlockScoped(path.node);
+ }
+
+};
+exports.BlockScoped = BlockScoped;
+const Var = {
+ types: ["VariableDeclaration"],
+
+ checkPath(path) {
+ return isVar(path.node);
+ }
+
+};
+exports.Var = Var;
+const User = {
+ checkPath(path) {
+ return path.node && !!path.node.loc;
+ }
+
+};
+exports.User = User;
+const Generated = {
+ checkPath(path) {
+ return !path.isUser();
+ }
+
+};
+exports.Generated = Generated;
+const Pure = {
+ checkPath(path, opts) {
+ return path.scope.isPure(path.node, opts);
+ }
+
+};
+exports.Pure = Pure;
+const Flow = {
+ types: ["Flow", "ImportDeclaration", "ExportDeclaration", "ImportSpecifier"],
+
+ checkPath({
+ node
+ }) {
+ if (isFlow(node)) {
+ return true;
+ } else if (isImportDeclaration(node)) {
+ return node.importKind === "type" || node.importKind === "typeof";
+ } else if (isExportDeclaration(node)) {
+ return node.exportKind === "type";
+ } else if (isImportSpecifier(node)) {
+ return node.importKind === "type" || node.importKind === "typeof";
+ } else {
+ return false;
+ }
+ }
+
+};
+exports.Flow = Flow;
+const RestProperty = {
+ types: ["RestElement"],
+
+ checkPath(path) {
+ return path.parentPath && path.parentPath.isObjectPattern();
+ }
+
+};
+exports.RestProperty = RestProperty;
+const SpreadProperty = {
+ types: ["RestElement"],
+
+ checkPath(path) {
+ return path.parentPath && path.parentPath.isObjectExpression();
+ }
+
+};
+exports.SpreadProperty = SpreadProperty;
+const ExistentialTypeParam = {
+ types: ["ExistsTypeAnnotation"]
+};
+exports.ExistentialTypeParam = ExistentialTypeParam;
+const NumericLiteralTypeAnnotation = {
+ types: ["NumberLiteralTypeAnnotation"]
+};
+exports.NumericLiteralTypeAnnotation = NumericLiteralTypeAnnotation;
+const ForAwaitStatement = {
+ types: ["ForOfStatement"],
+
+ checkPath({
+ node
+ }) {
+ return node.await === true;
+ }
+
+};
+exports.ForAwaitStatement = ForAwaitStatement; \ No newline at end of file