babel-types
Advanced tools
Comparing version 6.13.0 to 6.14.0
@@ -12,4 +12,2 @@ "use strict"; | ||
/* eslint max-len: 0 */ | ||
var STATEMENT_OR_BLOCK_KEYS = exports.STATEMENT_OR_BLOCK_KEYS = ["consequent", "body", "alternate"]; | ||
@@ -16,0 +14,0 @@ var FLATTENABLE_KEYS = exports.FLATTENABLE_KEYS = ["body", "expressions"]; |
@@ -60,11 +60,2 @@ "use strict"; | ||
/** | ||
* Turn an array of statement `nodes` into a `SequenceExpression`. | ||
* | ||
* Variable declarations are turned into simple assignments and their | ||
* declarations hoisted to the top of the current scope. | ||
* | ||
* Expression statements are just resolved to their expression. | ||
*/ | ||
function toSequenceExpression(nodes, scope) { | ||
@@ -108,3 +99,3 @@ if (!nodes || !nodes.length) return; | ||
} else if (t.isVariableDeclaration(node)) { | ||
if (node.kind !== "var") return bailed = true; // bailed | ||
if (node.kind !== "var") return bailed = true; | ||
@@ -149,7 +140,5 @@ for (var _iterator2 = node.declarations, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator3.default)(_iterator2);;) { | ||
} else if (t.isEmptyStatement(node)) { | ||
// empty statement so ensure the last item is undefined if we're last | ||
ensureLastUndefined = true; | ||
continue; | ||
} else { | ||
// bailed, we can't turn this statement into an expression | ||
return bailed = true; | ||
@@ -165,4 +154,2 @@ } | ||
// | ||
if (exprs.length === 1) { | ||
@@ -176,5 +163,2 @@ return exprs[0]; | ||
// Can't use import because of cyclic dependency between babel-traverse | ||
// and this module (babel-types). This require needs to appear after | ||
// we export the TYPES constant, so we lazy-initialize it before use. | ||
var traverse = void 0; | ||
@@ -223,9 +207,6 @@ | ||
// replace all non-valid identifiers with dashes | ||
name = name.replace(/[^a-zA-Z0-9$_]/g, "-"); | ||
// remove all dashes and numbers from start of name | ||
name = name.replace(/^[-0-9]+/, ""); | ||
// camel case | ||
name = name.replace(/[-\s]+(.)?/g, function (match, c) { | ||
@@ -248,7 +229,2 @@ return c ? c.toUpperCase() : ""; | ||
/** | ||
* [Please add a description.] | ||
* @returns {Object|Boolean} | ||
*/ | ||
function toStatement(node, ignore) { | ||
@@ -332,3 +308,2 @@ if (t.isStatement(node)) { | ||
function valueToNode(value) { | ||
// undefined | ||
if (value === undefined) { | ||
@@ -338,3 +313,2 @@ return t.identifier("undefined"); | ||
// boolean | ||
if (value === true || value === false) { | ||
@@ -344,3 +318,2 @@ return t.booleanLiteral(value); | ||
// null | ||
if (value === null) { | ||
@@ -350,3 +323,2 @@ return t.nullLiteral(); | ||
// strings | ||
if ((0, _isString2.default)(value)) { | ||
@@ -356,3 +328,2 @@ return t.stringLiteral(value); | ||
// numbers | ||
if ((0, _isNumber2.default)(value)) { | ||
@@ -362,3 +333,2 @@ return t.numericLiteral(value); | ||
// regexes | ||
if ((0, _isRegExp2.default)(value)) { | ||
@@ -370,3 +340,2 @@ var pattern = value.source; | ||
// array | ||
if (Array.isArray(value)) { | ||
@@ -376,3 +345,2 @@ return t.arrayExpression(value.map(t.valueToNode)); | ||
// object | ||
if ((0, _isPlainObject2.default)(value)) { | ||
@@ -379,0 +347,0 @@ var props = []; |
@@ -26,3 +26,3 @@ "use strict"; | ||
aliases: ["Expression"] | ||
}); /* eslint max-len: 0 */ | ||
}); | ||
@@ -296,5 +296,3 @@ (0, _index3.default)("AssignmentExpression", { | ||
validate: function validate(node, key, val) { | ||
if (!t.isValidIdentifier(val)) { | ||
// todo | ||
} | ||
if (!t.isValidIdentifier(val)) {} | ||
} | ||
@@ -602,3 +600,2 @@ }, | ||
// todo: at least handler or finalizer should be set to be valid | ||
(0, _index3.default)("TryStatement", { | ||
@@ -605,0 +602,0 @@ visitor: ["block", "handler", "finalizer"], |
@@ -23,3 +23,3 @@ "use strict"; | ||
} | ||
}); /* eslint max-len: 0 */ | ||
}); | ||
@@ -225,3 +225,2 @@ (0, _index2.default)("ArrayPattern", { | ||
fields: { | ||
// todo: limit to new.target | ||
meta: { | ||
@@ -319,5 +318,3 @@ validate: (0, _index.assertValueType)("string") | ||
fields: { | ||
value: { | ||
// todo: flatten `raw` into main node | ||
}, | ||
value: {}, | ||
tail: { | ||
@@ -324,0 +321,0 @@ validate: (0, _index.assertValueType)("boolean"), |
@@ -23,5 +23,3 @@ "use strict"; | ||
aliases: ["Expression"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -28,0 +26,0 @@ |
@@ -11,5 +11,3 @@ "use strict"; | ||
aliases: ["Flow", "FlowBaseAnnotation"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -20,5 +18,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -28,5 +24,3 @@ | ||
aliases: ["Flow", "FlowBaseAnnotation"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -47,5 +41,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -56,5 +48,3 @@ | ||
aliases: ["Flow", "Property"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -65,5 +55,3 @@ | ||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -74,5 +62,3 @@ | ||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -83,5 +69,3 @@ | ||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -92,13 +76,15 @@ | ||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
(0, _index2.default)("DeclareModuleExports", { | ||
visitor: ["typeAnnotation"], | ||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], | ||
fields: {} | ||
}); | ||
(0, _index2.default)("DeclareTypeAlias", { | ||
visitor: ["id", "typeParameters", "right"], | ||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -109,5 +95,3 @@ | ||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -122,5 +106,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -131,5 +113,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -140,5 +120,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -149,5 +127,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -158,5 +134,3 @@ | ||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -167,5 +141,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -180,5 +152,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -188,5 +158,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -196,5 +164,3 @@ | ||
aliases: ["Flow", "FlowBaseAnnotation"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -204,5 +170,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -212,5 +176,3 @@ | ||
aliases: ["Flow", "FlowBaseAnnotation"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -226,5 +188,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -235,5 +195,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -244,5 +202,3 @@ | ||
aliases: ["Flow", "FlowDeclaration", "Statement", "Declaration"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -253,5 +209,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -262,5 +216,3 @@ | ||
aliases: ["Flow", "ExpressionWrapper", "Expression"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -271,5 +223,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -280,5 +230,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -289,5 +237,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -298,5 +244,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -307,5 +251,3 @@ | ||
aliases: ["Flow", "UserWhitespacable"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -316,5 +258,3 @@ | ||
aliases: ["Flow", "UserWhitespacable"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -325,5 +265,3 @@ | ||
aliases: ["Flow", "UserWhitespacable"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -334,5 +272,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -343,5 +279,3 @@ | ||
aliases: ["Flow"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); | ||
@@ -351,5 +285,3 @@ | ||
aliases: ["Flow", "FlowBaseAnnotation"], | ||
fields: { | ||
// todo | ||
} | ||
fields: {} | ||
}); |
@@ -211,3 +211,2 @@ "use strict"; | ||
// ensure all field keys are represented in `fields` | ||
for (var _iterator4 = opts.visitor.concat(opts.builder), _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : (0, _getIterator3.default)(_iterator4);;) { | ||
@@ -214,0 +213,0 @@ var _ref4; |
@@ -14,7 +14,2 @@ "use strict"; | ||
/** | ||
* Takes an array of `types` and flattens them, removing duplicates and | ||
* returns a `UnionTypeAnnotation` node containg them. | ||
*/ | ||
function createUnionTypeAnnotation(types) { | ||
@@ -30,6 +25,2 @@ var flattened = removeTypeDuplicates(types); | ||
/** | ||
* Dedupe type annotations. | ||
*/ | ||
function removeTypeDuplicates(nodes) { | ||
@@ -39,3 +30,2 @@ var generics = {}; | ||
// store union type groups to circular references | ||
var typeGroups = []; | ||
@@ -49,3 +39,2 @@ | ||
// detect duplicates | ||
if (types.indexOf(node) >= 0) { | ||
@@ -55,3 +44,2 @@ continue; | ||
// this type matches anything | ||
if (t.isAnyTypeAnnotation(node)) { | ||
@@ -61,3 +49,2 @@ return [node]; | ||
// | ||
if (t.isFlowBaseAnnotation(node)) { | ||
@@ -68,3 +55,2 @@ bases[node.type] = node; | ||
// | ||
if (t.isUnionTypeAnnotation(node)) { | ||
@@ -78,3 +64,2 @@ if (typeGroups.indexOf(node.types) < 0) { | ||
// find a matching generic type and merge and deduplicate the type parameters | ||
if (t.isGenericTypeAnnotation(node)) { | ||
@@ -102,3 +87,2 @@ var name = node.id.name; | ||
// add back in bases | ||
for (var type in bases) { | ||
@@ -108,3 +92,2 @@ types.push(bases[type]); | ||
// add back in generics | ||
for (var _name in generics) { | ||
@@ -117,6 +100,2 @@ types.push(generics[_name]); | ||
/** | ||
* Create a type anotation based on typeof expression. | ||
*/ | ||
function createTypeAnnotationBasedOnTypeof(type) { | ||
@@ -123,0 +102,0 @@ if (type === "string") { |
119
lib/index.js
@@ -338,7 +338,2 @@ "use strict"; | ||
/** | ||
* Registers `is[Type]` and `assert[Type]` generated functions for a given `type`. | ||
* Pass `skipAliasCheck` to force it to directly compare `node.type` with `type`. | ||
*/ | ||
function registerType(type) { | ||
@@ -360,4 +355,2 @@ var is = t["is" + type]; | ||
// | ||
exports.VISITOR_KEYS = _definitions.VISITOR_KEYS; | ||
@@ -370,5 +363,2 @@ exports.ALIAS_KEYS = _definitions.ALIAS_KEYS; | ||
/** | ||
* Registers `is[Type]` and `assert[Type]` for all types. | ||
*/ | ||
@@ -379,6 +369,2 @@ for (var type in t.VISITOR_KEYS) { | ||
/** | ||
* Flip `ALIAS_KEYS` for faster access in the reverse direction. | ||
*/ | ||
t.FLIPPED_ALIAS_KEYS = {}; | ||
@@ -393,6 +379,2 @@ | ||
/** | ||
* Registers `is[Alias]` and `assert[Alias]` functions for all aliases. | ||
*/ | ||
(0, _each2.default)(t.FLIPPED_ALIAS_KEYS, function (types, type) { | ||
@@ -405,9 +387,2 @@ t[type.toUpperCase() + "_TYPES"] = types; | ||
/** | ||
* Returns whether `node` is of given `type`. | ||
* | ||
* For better performance, use this instead of `is[Type]` when `type` is unknown. | ||
* Optionally, pass `skipAliasCheck` to directly compare `node.type` with `type`. | ||
*/ | ||
function is(type, node, opts) { | ||
@@ -426,11 +401,5 @@ if (!node) return false; | ||
/** | ||
* Test if a `nodeType` is a `targetType` or if `targetType` is an alias of `nodeType`. | ||
*/ | ||
function isType(nodeType, targetType) { | ||
if (nodeType === targetType) return true; | ||
// This is a fast-path. If the test above failed, but an alias key is found, then the | ||
// targetType was a primary node type, so there's no need to check the aliases. | ||
if (t.ALIAS_KEYS[targetType]) return false; | ||
@@ -463,6 +432,2 @@ | ||
/** | ||
* Description | ||
*/ | ||
(0, _each2.default)(t.BUILDER_KEYS, function (keys, type) { | ||
@@ -512,6 +477,2 @@ function builder() { | ||
/** | ||
* Description | ||
*/ | ||
var _loop = function _loop(_type) { | ||
@@ -536,6 +497,2 @@ var newType = t.DEPRECATED_KEYS[_type]; | ||
/** | ||
* Description | ||
*/ | ||
function validate(node, key, val) { | ||
@@ -554,6 +511,2 @@ if (!node) return; | ||
/** | ||
* Test if an object is shallowly equal. | ||
*/ | ||
function shallowEqual(actual, expected) { | ||
@@ -584,6 +537,2 @@ var keys = (0, _keys2.default)(expected); | ||
/** | ||
* Append a node to a member expression. | ||
*/ | ||
function appendToMemberExpression(member, append, computed) { | ||
@@ -596,6 +545,2 @@ member.object = t.memberExpression(member.object, member.property, member.computed); | ||
/** | ||
* Prepend a node to a member expression. | ||
*/ | ||
function prependToMemberExpression(member, prepend) { | ||
@@ -606,7 +551,2 @@ member.object = t.memberExpression(prepend, member.object); | ||
/** | ||
* Ensure the `key` (defaults to "body") of a `node` is a block. | ||
* Casting it to a block if it is not. | ||
*/ | ||
function ensureBlock(node) { | ||
@@ -618,6 +558,2 @@ var key = arguments.length <= 1 || arguments[1] === undefined ? "body" : arguments[1]; | ||
/** | ||
* Create a shallow clone of a `node` excluding `_private` properties. | ||
*/ | ||
function clone(node) { | ||
@@ -632,6 +568,2 @@ var newNode = {}; | ||
/** | ||
* Create a shallow clone of a `node` excluding `_private` and location properties. | ||
*/ | ||
function cloneWithoutLoc(node) { | ||
@@ -643,7 +575,2 @@ var newNode = clone(node); | ||
/** | ||
* Create a deep clone of a `node` and all of it's child nodes | ||
* exluding `_private` properties. | ||
*/ | ||
function cloneDeep(node) { | ||
@@ -671,10 +598,2 @@ var newNode = {}; | ||
/** | ||
* Build a function that when called will return whether or not the | ||
* input `node` `MemberExpression` matches the input `match`. | ||
* | ||
* For example, given the match `React.createClass` it would match the | ||
* parsed nodes of `React.createClass` and `React["createClass"]`. | ||
*/ | ||
function buildMatchMemberExpression(match, allowPartial) { | ||
@@ -684,3 +603,2 @@ var parts = match.split("."); | ||
return function (member) { | ||
// not a member expression | ||
if (!t.isMemberExpression(member)) return false; | ||
@@ -699,10 +617,7 @@ | ||
if (t.isIdentifier(node)) { | ||
// this part doesn't match | ||
if (parts[i] !== node.name) return false; | ||
} else if (t.isStringLiteral(node)) { | ||
// this part doesn't match | ||
if (parts[i] !== node.value) return false; | ||
} else if (t.isMemberExpression(node)) { | ||
if (node.computed && !t.isStringLiteral(node.property)) { | ||
// we can't deal with this | ||
return false; | ||
@@ -715,7 +630,5 @@ } else { | ||
} else { | ||
// we can't deal with this | ||
return false; | ||
} | ||
// too many parts | ||
if (++i > parts.length) { | ||
@@ -730,6 +643,2 @@ return false; | ||
/** | ||
* Remove comment properties from a node. | ||
*/ | ||
function removeComments(node) { | ||
@@ -755,6 +664,2 @@ for (var _iterator4 = t.COMMENT_KEYS, _isArray4 = Array.isArray(_iterator4), _i4 = 0, _iterator4 = _isArray4 ? _iterator4 : (0, _getIterator3.default)(_iterator4);;) { | ||
/** | ||
* Inherit all unique comments from `parent` node to `child` node. | ||
*/ | ||
function inheritsComments(child, parent) { | ||
@@ -785,11 +690,4 @@ inheritTrailingComments(child, parent); | ||
// Can't use import because of cyclic dependency between babel-traverse | ||
// and this module (babel-types). This require needs to appear after | ||
// we export the TYPES constant, so we lazy-initialize it before use. | ||
var traverse = void 0; | ||
/** | ||
* Inherit all contextual properties from `parent` node to `child` node. | ||
*/ | ||
function inherits(child, parent) { | ||
@@ -800,3 +698,2 @@ if (!traverse) traverse = require("babel-traverse").default; | ||
// optionally inherit specific properties if not null | ||
for (var _iterator5 = t.INHERIT_KEYS.optional, _isArray5 = Array.isArray(_iterator5), _i5 = 0, _iterator5 = _isArray5 ? _iterator5 : (0, _getIterator3.default)(_iterator5);;) { | ||
@@ -821,3 +718,2 @@ var _ref5; | ||
// force inherit "private" properties | ||
for (var key in parent) { | ||
@@ -827,3 +723,2 @@ if (key[0] === "_") child[key] = parent[key]; | ||
// force inherit select properties | ||
for (var _iterator6 = t.INHERIT_KEYS.force, _isArray6 = Array.isArray(_iterator6), _i6 = 0, _iterator6 = _isArray6 ? _iterator6 : (0, _getIterator3.default)(_iterator6);;) { | ||
@@ -852,9 +747,4 @@ var _ref6; | ||
/** | ||
* TODO | ||
*/ | ||
function assertNode(node) { | ||
if (!isNode(node)) { | ||
// $FlowFixMe | ||
throw new TypeError("Not a valid node " + (node && node.type)); | ||
@@ -864,6 +754,2 @@ } | ||
/** | ||
* TODO | ||
*/ | ||
function isNode(node) { | ||
@@ -873,6 +759,3 @@ return !!(node && _definitions.VISITOR_KEYS[node.type]); | ||
// Optimize property access. | ||
(0, _toFastProperties2.default)(t); | ||
(0, _toFastProperties2.default)(t.VISITOR_KEYS); | ||
// | ||
(0, _toFastProperties2.default)(t.VISITOR_KEYS); |
@@ -40,6 +40,4 @@ "use strict"; | ||
// replace rendered whitespace tabs with spaces | ||
var trimmedLine = line.replace(/\t/g, " "); | ||
// trim whitespace touching a newline | ||
if (!isFirstLine) { | ||
@@ -49,3 +47,2 @@ trimmedLine = trimmedLine.replace(/^[ ]+/, ""); | ||
// trim whitespace touching an endline | ||
if (!isLastLine) { | ||
@@ -52,0 +49,0 @@ trimmedLine = trimmedLine.replace(/[ ]+$/, ""); |
@@ -20,6 +20,2 @@ "use strict"; | ||
/** | ||
* Return a list of binding identifiers associated with the input `node`. | ||
*/ | ||
function getBindingIdentifiers(node, duplicates, outerOnly) { | ||
@@ -76,6 +72,2 @@ var search = [].concat(node); | ||
/** | ||
* Mapping of types to their identifier keys. | ||
*/ | ||
getBindingIdentifiers.keys = { | ||
@@ -82,0 +74,0 @@ DeclareClass: ["id"], |
@@ -35,8 +35,2 @@ "use strict"; | ||
/** | ||
* Check if the input `node` is a binding identifier. | ||
*/ | ||
/* eslint indent: 0 */ | ||
function isBinding(node, parent) { | ||
@@ -59,16 +53,7 @@ var keys = _retrievers.getBindingIdentifiers.keys[parent.type]; | ||
/** | ||
* Check if the input `node` is a reference to a bound variable. | ||
*/ | ||
function isReferenced(node, parent) { | ||
switch (parent.type) { | ||
// yes: object::NODE | ||
// yes: NODE::callee | ||
case "BindExpression": | ||
return parent.object === node || parent.callee === node; | ||
// yes: PARENT[NODE] | ||
// yes: NODE.child | ||
// no: parent.NODE | ||
case "MemberExpression": | ||
@@ -84,10 +69,5 @@ case "JSXMemberExpression": | ||
// no: new.NODE | ||
// no: NODE.target | ||
case "MetaProperty": | ||
return false; | ||
// yes: { [NODE]: "" } | ||
// yes: { NODE } | ||
// no: { NODE: "" } | ||
case "ObjectProperty": | ||
@@ -98,9 +78,5 @@ if (parent.key === node) { | ||
// no: let NODE = init; | ||
// yes: let id = NODE; | ||
case "VariableDeclarator": | ||
return parent.id !== node; | ||
// no: function NODE() {} | ||
// no: function foo(NODE) {} | ||
case "ArrowFunctionExpression": | ||
@@ -128,5 +104,2 @@ case "FunctionDeclaration": | ||
// no: export { foo as NODE }; | ||
// yes: export { NODE as foo }; | ||
// no: export { NODE as foo } from "foo"; | ||
case "ExportSpecifier": | ||
@@ -139,4 +112,2 @@ if (parent.source) { | ||
// no: export NODE from "foo"; | ||
// no: export * as NODE from "foo"; | ||
case "ExportNamespaceSpecifier": | ||
@@ -146,16 +117,8 @@ case "ExportDefaultSpecifier": | ||
// no: <div NODE="foo" /> | ||
case "JSXAttribute": | ||
return parent.name !== node; | ||
// no: class { NODE = value; } | ||
// yes: class { key = NODE; } | ||
case "ClassProperty": | ||
return parent.value === node; | ||
// no: import NODE from "foo"; | ||
// no: import * as NODE from "foo"; | ||
// no: import { NODE as foo } from "foo"; | ||
// no: import { foo as NODE } from "foo"; | ||
// no: import NODE from "bar"; | ||
case "ImportDefaultSpecifier": | ||
@@ -166,3 +129,2 @@ case "ImportNamespaceSpecifier": | ||
// no: class NODE {} | ||
case "ClassDeclaration": | ||
@@ -172,3 +134,2 @@ case "ClassExpression": | ||
// yes: class { [NODE]() {} } | ||
case "ClassMethod": | ||
@@ -178,26 +139,17 @@ case "ObjectMethod": | ||
// no: NODE: for (;;) {} | ||
case "LabeledStatement": | ||
return false; | ||
// no: try {} catch (NODE) {} | ||
case "CatchClause": | ||
return parent.param !== node; | ||
// no: function foo(...NODE) {} | ||
case "RestElement": | ||
return false; | ||
// yes: left = NODE; | ||
// no: NODE = right; | ||
case "AssignmentExpression": | ||
return parent.right === node; | ||
// no: [NODE = foo] = []; | ||
// yes: [foo = NODE] = []; | ||
case "AssignmentPattern": | ||
return parent.right === node; | ||
// no: [NODE] = []; | ||
// no: ({ NODE }) = []; | ||
case "ObjectPattern": | ||
@@ -211,7 +163,2 @@ case "ArrayPattern": | ||
/** | ||
* Check if the input `name` is a valid identifier name | ||
* and isn't a reserved word. | ||
*/ | ||
function isValidIdentifier(name) { | ||
@@ -225,6 +172,2 @@ if (typeof name !== "string" || _esutils2.default.keyword.isReservedWordES6(name, true)) { | ||
/** | ||
* Check if the input `node` is a `let` variable declaration. | ||
*/ | ||
function isLet(node) { | ||
@@ -234,6 +177,2 @@ return t.isVariableDeclaration(node) && (node.kind !== "var" || node[_constants.BLOCK_SCOPED_SYMBOL]); | ||
/** | ||
* Check if the input `node` is block scoped. | ||
*/ | ||
function isBlockScoped(node) { | ||
@@ -243,6 +182,2 @@ return t.isFunctionDeclaration(node) || t.isClassDeclaration(node) || t.isLet(node); | ||
/** | ||
* Check if the input `node` is a variable declaration. | ||
*/ | ||
function isVar(node) { | ||
@@ -252,6 +187,2 @@ return t.isVariableDeclaration(node, { kind: "var" }) && !node[_constants.BLOCK_SCOPED_SYMBOL]; | ||
/** | ||
* Check if the input `specifier` is a `default` import or export. | ||
*/ | ||
function isSpecifierDefault(specifier) { | ||
@@ -261,6 +192,2 @@ return t.isImportDefaultSpecifier(specifier) || t.isIdentifier(specifier.imported || specifier.exported, { name: "default" }); | ||
/** | ||
* Check if the input `node` is a scope. | ||
*/ | ||
function isScope(node, parent) { | ||
@@ -274,6 +201,2 @@ if (t.isBlockStatement(node) && t.isFunction(parent, { body: node })) { | ||
/** | ||
* Check if the input `node` is definitely immutable. | ||
*/ | ||
function isImmutable(node) { | ||
@@ -284,6 +207,4 @@ if (t.isType(node.type, "Immutable")) return true; | ||
if (node.name === "undefined") { | ||
// immutable! | ||
return true; | ||
} else { | ||
// no idea... | ||
return false; | ||
@@ -290,0 +211,0 @@ } |
{ | ||
"name": "babel-types", | ||
"version": "6.13.0", | ||
"version": "6.14.0", | ||
"description": "", | ||
@@ -12,3 +12,3 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>", | ||
"babel-runtime": "^6.9.1", | ||
"babel-traverse": "^6.13.0", | ||
"babel-traverse": "^6.14.0", | ||
"esutils": "^2.0.2", | ||
@@ -15,0 +15,0 @@ "lodash": "^4.2.0", |
@@ -295,2 +295,10 @@ # babel-types | ||
### t.declareModuleExports(typeAnnotation) | ||
See also `t.isDeclareModuleExports(node, opts)` and `t.assertDeclareModuleExports(node, opts)`. | ||
Aliases: `Flow`, `FlowDeclaration`, `Statement`, `Declaration` | ||
- `typeAnnotation` (required) | ||
### t.declareTypeAlias(id, typeParameters, right) | ||
@@ -297,0 +305,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1225
124884
2847
Updatedbabel-traverse@^6.14.0